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 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 
    ConstructorDescription
    Attribute​(T initialValue)
    Initializes a new instance of the Attribute class.
  • Method Summary

    Modifier and TypeMethodDescription
    voidaddModifier​(AttributeModifier<T> modifier)
    Adds the specified modifier to this attribute.
    protected TapplyModifiers​(T baseValue)
    Apply modifiers.
    Tget()
    Gets the current value of this attribute, respecting all the registered AttributeModifiers.
    TgetBase()
    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.
    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.
    java.lang.StringtoString() 

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Attribute

      public Attribute​(T initialValue)
      Initializes a new instance of the Attribute class.
      Parameters:
      initialValue - The initial value
  • Method Details

    • addModifier

      public void addModifier​(AttributeModifier<T> modifier)
      Adds the specified modifier to this attribute.
      Parameters:
      modifier - The modifier to be added to this instance.
    • removeModifier

      public void removeModifier​(AttributeModifier<T> modifier)
      Removes the specified modifier from this attribute.
      Parameters:
      modifier - The modifier to be removed from this instance.
    • get

      public T get()
      Gets the current value of this attribute, respecting all the registered AttributeModifiers.
      Returns:
      The current value of this attribute.
    • getBase

      public T getBase()
      Gets the raw base value of this attribute without applying any modifications.
      Returns:
      The raw base value of this attribute.
    • getModifiers

      public java.util.List<AttributeModifier<T>> getModifiers()
      Gets all modifiers added to this instance.
      Returns:
      All modifiers added to this instance.
    • isModifierApplied

      public boolean isModifierApplied​(AttributeModifier<T> modifier)
      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

      public void modifyBaseValue​(AttributeModifier<T> modifier)
      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

      public void modifyBaseValue​(Modification modification, double value)
      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

      public void setBaseValue​(T baseValue)
      Sets the base value of this attribute.
      Parameters:
      baseValue - The base value to be set.
    • applyModifiers

      protected T applyModifiers​(T baseValue)
      Apply modifiers.
      Parameters:
      baseValue - the base value
      Returns:
      the t
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object