package uulm.teamname.marvelous.gamelibrary.entities; import java.util.Objects; /** Represents a stat property of a {@link Character}. */ public class Stat { /** The {@link StatType} of the stat */ public final StatType type; /** The maximum value of the stat */ private int max; /** The current value of the stat */ private int value; /** * Constructs a new {@link Stat} with the initial value set to the maximum value. * @param type The {@link StatType} of the stat * @param max The maximum value of the stat */ public Stat(StatType type, int max) { this.type = type; this.max = max; this.value = max; } /** * Constructs a new {@link Stat} with the given values. * @param type The {@link StatType} of the stat * @param value The value of the stat * @param max The maximum value of the stat */ public Stat(StatType type, int value, int max) { this.type = type; this.max = max; this.value = value; } /** * Constructs a new {@link Stat} with the same values as the * given {@link Stat} * @param toCopy is the {@link Stat} to copy */ public Stat(Stat toCopy) { this(toCopy.type, toCopy.value, toCopy.max); } public int getValue() { return value; } public void setValue(int value) { this.value = value; } public void increaseValue(int value) { this.value = Math.min(this.max, this.value + value); } public void decreaseValue(int value) { this.value = Math.max(0, this.value - value); } public int getMax() { return max; } public void setMax(int max) { this.max = max; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Stat stat = (Stat) o; return getMax() == stat.getMax() && value == stat.value && type == stat.type; } @Override public int hashCode() { return Objects.hash(type, getMax(), value); } @Override public String toString() { return "Stat{" + "type=" + type + ", max=" + getMax() + ", value=" + value + '}'; } }