2021-04-29 14:45:18 +00:00
|
|
|
package uulm.teamname.marvelous.gamelibrary.entities;
|
2021-04-29 14:40:23 +00:00
|
|
|
|
2021-05-11 19:17:06 +00:00
|
|
|
import java.util.Objects;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** Represents a stat property of a {@link Character}. */
|
2021-04-29 14:40:23 +00:00
|
|
|
public class Stat {
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The {@link StatType} of the stat */
|
2021-04-29 14:40:23 +00:00
|
|
|
public final StatType type;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The maximum value of the stat */
|
2021-05-31 20:54:13 +00:00
|
|
|
private int max;
|
2021-04-29 14:40:23 +00:00
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/** The current value of the stat */
|
2021-04-29 14:40:23 +00:00
|
|
|
private int value;
|
|
|
|
|
2021-04-30 18:54:34 +00:00
|
|
|
/**
|
|
|
|
* 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
|
2021-04-29 14:40:23 +00:00
|
|
|
*/
|
|
|
|
public Stat(StatType type, int max) {
|
|
|
|
this.type = type;
|
|
|
|
this.max = max;
|
|
|
|
this.value = max;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getValue() {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setValue(int value) {
|
|
|
|
this.value = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void increaseValue(int value) {
|
2021-06-03 01:05:59 +00:00
|
|
|
this.value = Math.min(this.max, this.value + value);
|
2021-04-29 14:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void decreaseValue(int value) {
|
2021-06-03 01:05:59 +00:00
|
|
|
this.value = Math.max(0, this.value - value);
|
2021-04-29 14:40:23 +00:00
|
|
|
}
|
2021-05-11 19:17:06 +00:00
|
|
|
|
2021-05-31 20:54:13 +00:00
|
|
|
public int getMax() {
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setMax(int max) {
|
|
|
|
this.max = max;
|
|
|
|
}
|
|
|
|
|
2021-05-11 19:17:06 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object o) {
|
|
|
|
if (this == o) return true;
|
|
|
|
if (o == null || getClass() != o.getClass()) return false;
|
|
|
|
Stat stat = (Stat) o;
|
2021-05-31 20:54:13 +00:00
|
|
|
return getMax() == stat.getMax() && value == stat.value && type == stat.type;
|
2021-05-11 19:17:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
2021-05-31 20:54:13 +00:00
|
|
|
return Objects.hash(type, getMax(), value);
|
2021-05-11 19:17:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "Stat{" +
|
|
|
|
"type=" + type +
|
2021-05-31 20:54:13 +00:00
|
|
|
", max=" + getMax() +
|
2021-05-11 19:17:06 +00:00
|
|
|
", value=" + value +
|
|
|
|
'}';
|
|
|
|
}
|
2021-04-29 14:40:23 +00:00
|
|
|
}
|