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;publicItemAttributeParent() // Get the ItemAttribute scriptable objectpublic GameItemObject ParentItemObject // The GameItemObject this is attached topublic GameItemAttributeList ParentList // the List this is inpublic string Uid() // Uid of the parentpublic virtual string GameId(bool forceNew =false) // In game unique ID of this GameItemObjectpublic int NameOrder // Name order for this attributepublic 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.
publicGameItemAttribute(ItemAttribute parent, IHaveStats newOwner =null){ _parent = parent; // v3.6SetUid(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 ItemAttributepublicboolCompatibleWith(string itemAttributeUid)public bool CompatibleWith(ItemAttribute itemAttribute)public bool CompatibleWith(GameItemAttribute gameItemAttribute)// Returns true if it is not compatible with the provided uid or ItemAttributepublic bool IncompatibleWith(string itemAttributeUid)public bool IncompatibleWith(ItemAttribute itemAttribute)public bool IncompatibleWith(GameItemAttribute gameItemAttribute) // Returns true if the comparison is correctpublic bool IsHigherLevelThan(GameItemAttribute other) => Level >other.Level;publicboolIsLowerLevelThan(GameItemAttribute other) => Level <other.Level;publicboolIsSameLevelAs(GameItemAttribute other) => Level ==other.Level;publicboolIsHigherLevelThan(ItemAttribute other) => Level >other.level;publicboolIsLowerLevelThan(ItemAttribute other) => Level <other.level;publicboolIsSameLevelAs(ItemAttribute other) => Level ==other.level;
Additional Methods
// Sets the Owners stats dirty, any stat that the Owner has which are affected by this// GameItemAttribute.publicvoidSetDirty(bool dirtyValue =true)