feat(potions): add restoration potion for default player size
This commit is contained in:
1 parent
a06d6480fe
commit
fd601961eb
13 files changed
+155
-9
No files matched your search
@@ -20,6 +20,20 @@ class HeightMathTest {
|
||||
assertEquals(1.1, HeightMath.grow(1.0, SETTINGS), 0.000001);
|
||||
}
|
||||
|
||||
@Test
|
||||
void savedDefaultSizeSurvivesRangesThatExcludeIt() {
|
||||
for (HeightSettings settings : new HeightSettings[] {
|
||||
new HeightSettings(0.2, 0.8, 0.1, 0.5, 1.5, 20),
|
||||
new HeightSettings(1.2, 2.0, 0.1, 1.5, 1.5, 20)}) {
|
||||
assertEquals(1.0, HeightMath.safeStoredScale(1.0, settings));
|
||||
assertEquals(settings.minimum(), HeightMath.safeStoredScale(0.1, settings));
|
||||
assertEquals(settings.maximum(), HeightMath.safeStoredScale(3.0, settings));
|
||||
double fallback = HeightMath.clamp(1.0, settings);
|
||||
assertEquals(fallback, HeightMath.safeStoredScale(null, settings));
|
||||
assertEquals(fallback, HeightMath.safeStoredScale(Double.NaN, settings));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingAndStoredValuesAreSafelyClamped() {
|
||||
assertEquals(1.0, HeightMath.safeStoredScale(null, SETTINGS), 0.000001);
|
||||
|
||||
@@ -12,6 +12,19 @@ class HeightStoreTest {
|
||||
@TempDir
|
||||
Path temporaryDirectory;
|
||||
|
||||
@Test
|
||||
void restorationReplacesPreviousSizeAndSurvivesReloadOutsideLimits() throws Exception {
|
||||
UUID playerId = UUID.randomUUID();
|
||||
HeightSettings settings = new HeightSettings(0.2, 0.8, 0.1, 0.5, 1.5, 20);
|
||||
HeightStore store = new HeightStore(temporaryDirectory.toFile());
|
||||
store.save(playerId, 0.4);
|
||||
store.save(playerId, StaturePotion.RESTORATION.scaleAfterDrinking(0.4, settings, bound -> 0));
|
||||
|
||||
HeightStore reloaded = new HeightStore(temporaryDirectory.toFile());
|
||||
assertEquals(1.0, reloaded.find(playerId));
|
||||
assertEquals(1.0, HeightMath.safeStoredScale(reloaded.find(playerId), settings));
|
||||
}
|
||||
|
||||
@Test
|
||||
void storesByUuidAndPreservesUnknownYamlFields() throws Exception {
|
||||
UUID playerId = UUID.randomUUID();
|
||||
|
||||
@@ -2,6 +2,7 @@ package games.dmg.spigotheights;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -13,6 +14,17 @@ class PotionRecipesTest {
|
||||
assertArrayEquals(new String[] {"GAG", "ASA", "GFG"}, PotionRecipes.DIMINUTION_SHAPE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void restorationUsesApprovedShapeAndDistinctIdentity() {
|
||||
assertArrayEquals(new String[] {"GAG", "ASA", "GUG"}, PotionRecipes.RESTORATION_SHAPE);
|
||||
assertEquals("RESTORATION", StaturePotion.RESTORATION.name());
|
||||
for (StaturePotion kind : StaturePotion.values()) {
|
||||
if (kind != StaturePotion.RESTORATION) {
|
||||
assertNotEquals(kind.name(), StaturePotion.RESTORATION.name());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void everyPotionHasASeparatePersistentIdentity() {
|
||||
assertNotEquals(StaturePotion.SHIFTING.name(), StaturePotion.GROWTH.name());
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package games.dmg.spigotheights;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class StaturePotionTest {
|
||||
@Test
|
||||
void existingPotionsKeepTheirScaleRules() {
|
||||
HeightSettings settings = new HeightSettings(0.4, 2.0, 0.1, 0.5, 1.5, 20);
|
||||
assertEquals(0.4, StaturePotion.SHIFTING.scaleAfterDrinking(1.0, settings, bound -> 0));
|
||||
assertEquals(2.0, StaturePotion.SHIFTING.scaleAfterDrinking(1.0, settings, bound -> bound - 1));
|
||||
assertEquals(1.1, StaturePotion.GROWTH.scaleAfterDrinking(1.0, settings, bound -> 0));
|
||||
assertEquals(0.9, StaturePotion.DIMINUTION.scaleAfterDrinking(1.0, settings, bound -> 0));
|
||||
assertEquals(2.0, StaturePotion.GROWTH.scaleAfterDrinking(2.0, settings, bound -> 0));
|
||||
assertEquals(0.4, StaturePotion.DIMINUTION.scaleAfterDrinking(0.4, settings, bound -> 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void restorationAlwaysReturnsNormalSizeWithoutRandomness() {
|
||||
for (HeightSettings settings : new HeightSettings[] {
|
||||
new HeightSettings(0.4, 2.0, 0.1, 0.5, 1.5, 20),
|
||||
new HeightSettings(0.2, 0.8, 0.1, 0.5, 1.5, 20),
|
||||
new HeightSettings(1.2, 2.0, 0.1, 1.5, 1.5, 20)}) {
|
||||
for (double current : new double[] {0.2, 1.0, 2.0}) {
|
||||
assertEquals(1.0, StaturePotion.RESTORATION.scaleAfterDrinking(current, settings,
|
||||
bound -> { throw new AssertionError("Restoration must not roll a random size"); }));
|
||||
}
|
||||
}
|
||||
assertEquals("Potion of Restoration", StaturePotion.RESTORATION.displayName());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user