Class Attribute<T extends Number>
java.lang.Object
de.gurkenlabs.litiengine.attributes.Attribute<T>
- Type Parameters:
T- The type of the attribute value.
- Direct Known Subclasses:
RangeAttribute
An attribute is a numerical representation of a property that can be adjusted using
AttributeModifiers.
It typically doesn't adjust the raw base value (unless explicitly requested) and instead adjusts the value by registered modifications. This is e.g. useful when a property might only be changed for a certain period of time or we need to know the original value of a property.
An example use-case are player stats that might be affected throughout the game (e.g. via certain skills, upgrades or level-ups).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddModifier(AttributeModifier<T> modifier) Adds the specified modifier to this attribute.protected TapplyModifiers(T baseValue) Apply modifiers.get()Gets the current value of this attribute, respecting all the registeredAttributeModifiers.getBase()Gets the raw base value of this attribute without applying any modifications.Gets all modifiers added to this instance.booleanisModifierApplied(AttributeModifier<T> modifier) Determines whether the specified modifier instance is added to this attribute instance.voidmodifyBaseValue(AttributeModifier<T> modifier) Adjusts the base value of this attribute once with the specified modifier.voidmodifyBaseValue(Modification modification, double value) Adjusts the base value of this attribute once with the specified modifier.voidremoveModifier(AttributeModifier<T> modifier) Removes the specified modifier from this attribute.voidsetBaseValue(T baseValue) Sets the base value of this attribute.toString()
-
Constructor Details
-
Attribute
Initializes a new instance of theAttributeclass.- Parameters:
initialValue- The initial value
-
-
Method Details
-
addModifier
Adds the specified modifier to this attribute.- Parameters:
modifier- The modifier to be added to this instance.
-
removeModifier
Removes the specified modifier from this attribute.- Parameters:
modifier- The modifier to be removed from this instance.
-
get
Gets the current value of this attribute, respecting all the registeredAttributeModifiers.- Returns:
- The current value of this attribute.
-
getBase
Gets the raw base value of this attribute without applying any modifications.- Returns:
- The raw base value of this attribute.
-
getModifiers
Gets all modifiers added to this instance.- Returns:
- All modifiers added to this instance.
-
isModifierApplied
Determines whether the specified modifier instance is added to this attribute instance.- Parameters:
modifier- The modifier to check for.- Returns:
- True if the modifier was added to this attribute instance; otherwise false.
-
modifyBaseValue
Adjusts the base value of this attribute once with the specified modifier.- Parameters:
modifier- The modifier used to adjust this attribute's base value.- See Also:
-
modifyBaseValue
Adjusts the base value of this attribute once with the specified modifier.- Parameters:
modification- The modification type.value- The modification value to be applied.
-
setBaseValue
Sets the base value of this attribute.- Parameters:
baseValue- The base value to be set.
-
applyModifiers
-
toString
-