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
.
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
.
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.
The RemoveAttribute
and RemoveAttributeAndRequirements
methods will return a bool
. If you try to remove an attribute but can't, it will return false
. This only happens when you are not ignoring the requirements, and also not removing requirements.
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?