feat(health): honor native ceilings without capping CON
This commit is contained in:
1 parent
9771d1e7c3
commit
db87505142
5 files changed
+165
-2
No files matched your search
@@ -0,0 +1,67 @@
|
||||
package games.dmg.fantasystick;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import games.dmg.fantasystick.progression.CharacterProgress;
|
||||
import games.dmg.fantasystick.progression.ProgressionRules;
|
||||
import games.dmg.fantasystick.progression.Stat;
|
||||
import games.dmg.fantasystick.session.NativeHealthLimit;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.UUID;
|
||||
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||
import net.minecraft.world.entity.ai.attributes.RangedAttribute;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.craftbukkit.attribute.CraftAttributeInstance;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class NativeHealthLimitTest {
|
||||
@BeforeAll static void bootstrap() throws Exception { NativeRuntime.bootstrap(); }
|
||||
|
||||
@Test
|
||||
void invalidNativeRangesFailExplicitlyRatherThanGuessingOrChangingTheRuntime() {
|
||||
var range = (RangedAttribute) Attributes.MAX_HEALTH.value();
|
||||
double original = range.getMaxValue();
|
||||
try {
|
||||
for (double invalid : new double[] {0, -1, Double.NaN, Double.POSITIVE_INFINITY,
|
||||
Double.NEGATIVE_INFINITY, Double.MAX_VALUE, Double.MIN_VALUE}) {
|
||||
range.maxValue = invalid;
|
||||
assertThrows(IllegalStateException.class, NativeHealthLimit::read);
|
||||
assertEquals(invalid, range.getMaxValue());
|
||||
}
|
||||
} finally { range.maxValue = original; }
|
||||
assertEquals(0, BigDecimal.valueOf(original).compareTo(NativeHealthLimit.read()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void readsTheActualNativeCeilingRatherThanGuessingTheDefaultAndFeedsCappedProgression() {
|
||||
var range = (RangedAttribute) Attributes.MAX_HEALTH.value();
|
||||
double original = range.getMaxValue();
|
||||
try {
|
||||
// Isolated non-listening test runtime only. Never write an operator's config file.
|
||||
for (double ceiling : new double[] {10.5, 1024, 2048}) {
|
||||
range.maxValue = ceiling;
|
||||
BigDecimal limit = NativeHealthLimit.read();
|
||||
assertEquals(0, BigDecimal.valueOf(ceiling).compareTo(limit));
|
||||
assertEquals(ceiling, range.getMaxValue(), "Reading does not modify the native range");
|
||||
var progress = new CharacterProgress(UUID.randomUUID(),
|
||||
new ProgressionRules(BigInteger.valueOf(3000), BigInteger.valueOf(100), 30), limit);
|
||||
progress.recordHealth(new BigDecimal("6.25"));
|
||||
var handle = new net.minecraft.world.entity.ai.attributes.AttributeInstance(Attributes.MAX_HEALTH, ignored -> { });
|
||||
var attribute = new CraftAttributeInstance(handle, Attribute.MAX_HEALTH);
|
||||
for (int index = 0; index < 2100; index++) {
|
||||
var before = progress.snapshot();
|
||||
assertEquals(CharacterProgress.Purchase.APPLIED,
|
||||
progress.buyStat(before.characterId(), before.revision(), Stat.CON));
|
||||
var after = progress.snapshot();
|
||||
attribute.setBaseValue(after.maximumHealth().doubleValue());
|
||||
assertEquals(after.maximumHealth().doubleValue(), attribute.getValue());
|
||||
assertEquals(0, new BigDecimal("3.75").compareTo(after.maximumHealth().subtract(after.currentHealth())));
|
||||
}
|
||||
assertEquals(BigInteger.valueOf(2100), progress.snapshot().stats().get(Stat.CON));
|
||||
assertEquals(0, limit.compareTo(progress.snapshot().maximumHealth()));
|
||||
}
|
||||
} finally { range.maxValue = original; }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user