GameItemAttribute.cs

v4.0

The ItemAttribute Scriptable Object will not be serialized at runtime, and is intended to store permenent data, rather than mutable data that may change during the game. The GameItemAttribute is used for runtime use instead. It implements IHaveStats.

GameItemAttribute.cs
// Owner will be the owner of the GameItemObject this is attached to. If it is not, 
// then owner will be the GameItemAttributeList this is in. If it is not in a
// List, then it will be the value of _owner. The Owner is the IHaveStats objects
// which is affected by the stat effects on these objects.
public IHaveStats Owner => ParentList == null ? _owner : ParentList.Owner;
public ItemAttribute Parent() // Get the ItemAttribute scriptable object
public GameItemObject ParentItemObject // The GameItemObject this is attached to
public GameItemAttributeList ParentList // the List this is in
public string Uid() // Uid of the parent
public virtual string GameId(bool forceNew = false) // In game unique ID of this GameItemObject

public int NameOrder // Name order for this attribute
public string HumanName // Human name

Constructor

Pass in the ItemAttribute and the owner. The owner can be null, but is required if this ItemAttribute is meant to affect the stats of the owner. ItemAttribute can be null as well, if you are creating a container for a future ItemAttribute. Generally that is unlikely I think.

public GameItemAttribute(ItemAttribute parent, IHaveStats newOwner = null)
{
    _parent = parent; // v3.6
    SetUid(parent.Uid()); // v3.6 -- set the uid with this method now
    objectName = parent.objectName;
    objectType = parent.objectType;
    dictionaries = parent.dictionaries.Clone(); // Clone the dictionaries object, so we don't overwrite our Scriptable Object data!

    GameId();
    SetOwner(newOwner); // Will set null if value is default. Owner is first taken from Parents before reverting to _owner
}

Methods

// Returns true if it is compatible with the provided uid or ItemAttribute
public bool CompatibleWith(string itemAttributeUid)
public bool CompatibleWith(ItemAttribute itemAttribute)
public bool CompatibleWith(GameItemAttribute gameItemAttribute)

// Returns true if it is not compatible with the provided uid or ItemAttribute
public bool IncompatibleWith(string itemAttributeUid)
public bool IncompatibleWith(ItemAttribute itemAttribute)
public bool IncompatibleWith(GameItemAttribute gameItemAttribute) 

Additional Methods

// Sets the Owners stats dirty, any stat that the Owner has which are affected by this
// GameItemAttribute.
public void SetDirty(bool dirtyValue = true)

Last updated