GameItemObject.cs
v4.0
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.
// 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;
public ItemObject Parent() // Get the ItemObject scriptable objcet
public string Uid() // Uid of the parent
public virtual string GameId(bool forceNew = false) // In game unique ID of this GameItemObject
public bool QuestItem // Returns true if the ItemObject this is based on is marked quest item.
public Dictionaries dictionaries // The dictionaries for this GameItemObject
public List<GameItemAttribute> Attributes // The GameItemAttributes attached to this.
public string FullName(bool recompute = false) // The full name of this, including all attributes
public string ObjectName() // The name of this
public string ObjectType() // The type this is
public GameItemAttributeList attributes // All the attributes on this GameItemObject
public ModificationLevel ModificationLevel // Returns the modification level for the object
public List<ModificationLevel> ModificationLevels // Modificaiton levels for this + all attributesConstructor
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.
Methods
Is and Is Not
This is helpful to know whether the GameItemObject "is" or "is not" one of a specific ItemAttribute. Example: "Is the Flaming Sword of Magic 'Rare' and 'Armor'?"
If the itemAttributeType is not provided, it will return true if attributes contains the attribute by the name or uid provided -- the method will check both.
Otherwise, the gameItemObject must also have ANY ItemAttribute by the itemAttributeType as well. Note: The itemAttributeType does NOT have to be the type of the itemAttribute checked.
Has
Manage Attributes
Add Attribute
Add an attribute via a uid, or the itemAttribute or gameItemAttribute. Any Required Attributes will be added if they do not already exist.
distinct: when true, the only one of the same attribute can be added. [Default true]
recomputeHumanName: when true, the human name returned with FullName() will be recomputed. [Default true]
resetModificationLevel: when true, the modification level for the object wil lbe reset and recomputed [Default true]
setAffectedStatsDirty: When true, any affected stats will be set dirty [Default true]
Remove Attribute
Removes the attribute from the GameItemAttribute. Optionally will check and remove required attributes as well.
recomputeHumanName: when true, the human name returned with FullName() will be recomputed. [Default true]
resetModificationLevel: when true, the modification level for the object wil lbe reset and recomputed [Default true]
Remove Attribute And Requirements
You can also use RemoveAttributeAndRequirements() to more quickly remove everything. There are still options for recomputeHumanName and resetModificationLevel (both true by default), but otherwise, it will not ignore requirements and will remove any that exist.
Remove Attribute If Not Required
This option will remove the attribute only if it is not required by another attribute in the list.
sameTypeBlocksRemoval is an option (true by default), which will handle situations where something requires an attribute of this type, but not this specific attribute.
For example, lets say a "Flaming" attribute requires the "Rare" attribute, but "of The Gods" requires "Legendary" -- and Legendary replaces Rare automatically. At some point, if "of The Gods" is removed, the object will now have "Flaming" and "Legendary" attributes.
If we attempt to remove "Legendary", we may want to block the removal since "Flaming" requires an attribute that is of the same type as "Legendary" ("Rare").
There is a lot of various ways you may want to handle the logic of required attributes. In the example above, you may wish to replace "Legendary" with "Rare" when "of The Gods" is removed, for example.
Since there are so many possible ways to handle this kind of logic, it is expected that anything beyond the scope of the provided methods would be handled by your own scripts.
Check if an Attribute can be used
This method will return true if the GameItemObject can use the attribute provided.
Get Effect On IHaveStats Target
IHaveStats TargetOften 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.
Additional Methods
Last updated
Was this helpful?