The ItemObject 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 GameItemObject is used for runtime use instead. It implements IAmGameModulesObject, and IFitInInventory.
GameItemObject.cs
// Owner will be the owner of the GameItemObjectList 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;publicItemObjectParent() // Get the ItemObject scriptable objcetpublic string Uid() // Uid of the parentpublic virtual string GameId(bool forceNew =false) // In game unique ID of this GameItemObjectpublic bool QuestItem // Returns true if the ItemObject this is based on is marked quest item.public Dictionaries dictionaries // The dictionaries for this GameItemObjectpublic List<GameItemAttribute> Attributes // The GameItemAttributes attached to this.public string FullName(bool recompute =false) // The full name of this, including all attributespublic string ObjectName() // The name of thispublic string ObjectType() // The type this ispublic GameItemAttributeList attributes // All the attributes on this GameItemObjectpublic ModificationLevel ModificationLevel // Returns the modification level for the objectpublic List<ModificationLevel> ModificationLevels // Modificaiton levels for this + all attributes
Constructor
Pass in the ItemObject and the owner. The owner can be null, but is required if this ItemObject is meant to affect the stats of the owner. ItemObject can be null as well, if you are creating a container for a future ItemObject.
If ItemObject is not null, the script will create a Clone() of the Dictionaries from the ItemObject Scriptable Object. This way changes to the GameItemObject dictionaries will not affect the Scriptable Object dictionaries.
The Inventory values will also be copied into this new GameItemObject.
publicGameItemObject(ItemObject itemObject, IHaveStats newOwner){ owner = newOwner; // Set the owner _itemObject = itemObject; // Set the Item Objectif (!itemObject) return; // Return if we do not have an ItemObject attached yet dictionaries = itemObject.dictionaries.Clone(); // Clone the dictionaries object, so we don't overwrite our Scriptable Object data!
_uid =itemObject.uid; // Set the uid to match the Item Object objectName =itemObject.objectName; // Set the name objectType =itemObject.objectType; // Set the type // Set the Inventory module values inventoryHeight =itemObject.inventoryHeight; inventoryWidth =itemObject.inventoryWidth; prefabInventory =itemObject.prefabInventory; prefabWorld =itemObject.prefabWorld;}
Methods
Is and Is Not
// If itemAttributeType is not provided, returns true if attributes contains the // attribute by the name provided// If itemAttributeType is provided, then it must also have at least one itemAttribute// of that type. // Note: The itemAttributeType does not need to be the same as the objectType of the// itemAttributeName provided.publicboolIs(string itemAttributeName,string itemAttributeType ="")// Returns true if the attributes list does not contain the itemAttributeName providedpublic bool IsNot(string itemAttributeName)
Has
// Returns true if the attributeList contains an attribute with this uidpublicboolHasAttribute(string uid)// Returns true if the attributeList contains at least one attribute of this typepublic bool Has(string itemAttributeType)// If the attributeList contains at least one attribute of this type, returns the // objectName of the first one found. Otherwise, returns "None".public string ValueNameOf(string itemAttributeType,string noValueResult ="None")// ExampleuiText.text = $"Enchantment: {gameItemObject.ValueNameOf("Enchantment")}";
Manage Attributes
// Add a GameItemAttribute to this GameItemObject// attributeUid: The uid of the ItemAttribute to add// distinct: If true, only one attribute of each uid can be added// recomputeHumanName: If true, the human name returned with FullName() will be recomputed// resetModifictionLevel: If true, the modificaiton level for the object will be reset, and recomputed// setAffectedStatsDirty: If true, the owner will have affected stats set dirty, so they recomputepublicGameItemAttributeAddAttribute(string attributeUid,bool distinct =true,bool recomputeHumanName =true,bool resetModificationLevel =true,bool setAffectedStatsDirty =true)// Remove a GameItemAttribute from this GameItemObject// attributeUid: The uid of hte ItemAttribute to rmeove// recomputeHumanName: If true, the human name returned with FullName() will be recomputed// resetModifictionLevel: If true, the modificaiton level for the object will be reset, and recomputedpublic void RemoveAttribute(string attributeUid,bool recomputeHumanName =true,bool resetModificationLevel =true)// Returns true if the "Allowed Item Attributes" on the ItemObject scriptable object// have the ItemAttribute of the provided attributeUid toggled on.public bool CanUseAttribute(string attributeUid)
Get Effect On IHaveStats Target
Often you might want to display or otherwise know the effect a specific GameItemObject will have on an IHaveStats target. The final impact is dependent on both the GameItemObject and the target.
This method will return float values for the impact on "value" and the impact on "proficiency". Optionally, you can exlcude the attributes attached to the object, which would allow you to show the "vanilla" objects effects, or even calculate the impact the attributes are having, and display those differently.
public (float,float) GetEffectOn(string targetStatUid,bool includeAttributes =true)
Additional Methods
// Sets the Owners stats dirty, any stat that the Owner has which are affected by this// GameItemObject or any of the GameItemAttributes attached to it.publicvoidSetDirty(bool dirtyValue =true)