Class Attribute<T extends java.lang.Number>
java.lang.Object
de.gurkenlabs.litiengine.attributes.Attribute<T>
- Type Parameters:
T
- The type of the attribute value.
- Direct Known Subclasses:
RangeAttribute
public class Attribute<T extends java.lang.Number>
extends java.lang.Object
An attribute is a numerical representation of a property that can be adjusted using
AttributeModifier
s.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
Method Summary
Modifier and Type Method Description void
addModifier(AttributeModifier<T> modifier)
Adds the specified modifier to this attribute.protected T
applyModifiers(T baseValue)
Apply modifiers.T
get()
Gets the current value of this attribute, respecting all the registeredAttributeModifier
s.T
getBase()
Gets the raw base value of this attribute without applying any modifications.java.util.List<AttributeModifier<T>>
getModifiers()
Gets all modifiers added to this instance.boolean
isModifierApplied(AttributeModifier<T> modifier)
Determines whether the specified modifier instance is added to this attribute instance.void
modifyBaseValue(AttributeModifier<T> modifier)
Adjusts the base value of this attribute once with the specified modifier.void
modifyBaseValue(Modification modification, double value)
Adjusts the base value of this attribute once with the specified modifier.void
removeModifier(AttributeModifier<T> modifier)
Removes the specified modifier from this attribute.void
setBaseValue(T baseValue)
Sets the base value of this attribute.java.lang.String
toString()
Constructor Details
Attribute
Initializes a new instance of theAttribute
class.- 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 registeredAttributeModifier
s.- 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:
getBase()
,setBaseValue(Number)
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
Apply modifiers.- Parameters:
baseValue
- the base value- Returns:
- the t
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object