This commit is contained in:
1 parent
d8bbe78a08
commit
87024bfd24
6 files changed
+35
-20
No files matched your search
@@ -30,7 +30,7 @@ public final class OutOfCombatRecoverySettings implements AutoCloseable {
|
|||||||
public static final String INTERVAL = "out-of-combat-healing-interval-seconds";
|
public static final String INTERVAL = "out-of-combat-healing-interval-seconds";
|
||||||
public static final String AMOUNT = "out-of-combat-healing-amount";
|
public static final String AMOUNT = "out-of-combat-healing-amount";
|
||||||
private static final List<String> KEYS = List.of(DELAY, INTERVAL, AMOUNT);
|
private static final List<String> KEYS = List.of(DELAY, INTERVAL, AMOUNT);
|
||||||
private static final Map<String, String> DEFAULTS = Map.of(DELAY, "30", INTERVAL, "10", AMOUNT, "1");
|
private static final Map<String, String> DEFAULTS = Map.of(DELAY, "10", INTERVAL, "10", AMOUNT, "1");
|
||||||
private static final int MAX_BYTES = 1_048_576;
|
private static final int MAX_BYTES = 1_048_576;
|
||||||
private static final long MAX_SECONDS = 31_536_000L;
|
private static final long MAX_SECONDS = 31_536_000L;
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public final class OutOfCombatRecovery implements Listener, AutoCloseable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static Settings defaults() {
|
public static Settings defaults() {
|
||||||
return new Settings(Duration.ofSeconds(30), Duration.ofSeconds(10), BigInteger.ONE);
|
return new Settings(Duration.ofSeconds(10), Duration.ofSeconds(10), BigInteger.ONE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ sheet-resource-pack-sha1: ''
|
|||||||
|
|
||||||
# Active-session recovery after actual accepted damage has stopped.
|
# Active-session recovery after actual accepted damage has stopped.
|
||||||
# Admin command: /fantasystick config <key> [value]
|
# Admin command: /fantasystick config <key> [value]
|
||||||
out-of-combat-healing-delay-seconds: 30
|
out-of-combat-healing-delay-seconds: 10
|
||||||
out-of-combat-healing-interval-seconds: 10
|
out-of-combat-healing-interval-seconds: 10
|
||||||
out-of-combat-healing-amount: 1
|
out-of-combat-healing-amount: 1
|
||||||
quicker-regeneration-i-bonus-healing: 1
|
quicker-regeneration-i-bonus-healing: 1
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class OutOfCombatRecoveryNativeTest {
|
|||||||
@Test void exactDelayRepeatedIntervalsAndLargeClockJumpsPersistOnePulseBeforeNativePublication() {
|
@Test void exactDelayRepeatedIntervalsAndLargeClockJumpsPersistOnePulseBeforeNativePublication() {
|
||||||
var f = new Direct();
|
var f = new Direct();
|
||||||
f.recovery.sweep();
|
f.recovery.sweep();
|
||||||
f.clock.advance(Duration.ofSeconds(29)); f.recovery.sweep();
|
f.clock.advance(Duration.ofSeconds(9)); f.recovery.sweep();
|
||||||
assertTrue(f.events.isEmpty());
|
assertTrue(f.events.isEmpty());
|
||||||
|
|
||||||
f.clock.advance(Duration.ofSeconds(1)); f.recovery.sweep();
|
f.clock.advance(Duration.ofSeconds(1)); f.recovery.sweep();
|
||||||
@@ -72,12 +72,12 @@ class OutOfCombatRecoveryNativeTest {
|
|||||||
|
|
||||||
@Test void acceptedEnvironmentalAndDealtDamageResetWhileCancelledAndZeroAttemptsDoNot() {
|
@Test void acceptedEnvironmentalAndDealtDamageResetWhileCancelledAndZeroAttemptsDoNot() {
|
||||||
var f = new Direct(); f.recovery.sweep();
|
var f = new Direct(); f.recovery.sweep();
|
||||||
f.clock.advance(Duration.ofSeconds(29));
|
f.clock.advance(Duration.ofSeconds(9));
|
||||||
f.recovery.acceptedDamage(damage(f.player, 2));
|
f.recovery.acceptedDamage(damage(f.player, 2));
|
||||||
f.clock.advance(Duration.ofSeconds(29)); f.recovery.sweep(); assertTrue(f.events.isEmpty());
|
f.clock.advance(Duration.ofSeconds(9)); f.recovery.sweep(); assertTrue(f.events.isEmpty());
|
||||||
f.clock.advance(Duration.ofSeconds(1)); f.recovery.sweep(); f.runNext(); assertEquals(5, f.health.get());
|
f.clock.advance(Duration.ofSeconds(1)); f.recovery.sweep(); f.runNext(); assertEquals(5, f.health.get());
|
||||||
|
|
||||||
var noReset = new Direct(); noReset.recovery.sweep(); noReset.clock.advance(Duration.ofSeconds(29));
|
var noReset = new Direct(); noReset.recovery.sweep(); noReset.clock.advance(Duration.ofSeconds(9));
|
||||||
var cancelled = damage(noReset.player, 2); cancelled.setCancelled(true); noReset.recovery.acceptedDamage(cancelled);
|
var cancelled = damage(noReset.player, 2); cancelled.setCancelled(true); noReset.recovery.acceptedDamage(cancelled);
|
||||||
noReset.recovery.acceptedDamage(damage(noReset.player, 0));
|
noReset.recovery.acceptedDamage(damage(noReset.player, 0));
|
||||||
noReset.clock.advance(Duration.ofSeconds(1)); noReset.recovery.sweep(); noReset.runNext();
|
noReset.clock.advance(Duration.ofSeconds(1)); noReset.recovery.sweep(); noReset.runNext();
|
||||||
@@ -85,58 +85,58 @@ class OutOfCombatRecoveryNativeTest {
|
|||||||
|
|
||||||
var dealt = new Direct();
|
var dealt = new Direct();
|
||||||
var target = mock(Player.class); when(target.getUniqueId()).thenReturn(java.util.UUID.randomUUID());
|
var target = mock(Player.class); when(target.getUniqueId()).thenReturn(java.util.UUID.randomUUID());
|
||||||
dealt.recovery.sweep(); dealt.clock.advance(Duration.ofSeconds(29));
|
dealt.recovery.sweep(); dealt.clock.advance(Duration.ofSeconds(9));
|
||||||
var source = DamageSource.builder(org.bukkit.damage.DamageType.PLAYER_ATTACK)
|
var source = DamageSource.builder(org.bukkit.damage.DamageType.PLAYER_ATTACK)
|
||||||
.withCausingEntity(dealt.player).withDirectEntity(dealt.player).build();
|
.withCausingEntity(dealt.player).withDirectEntity(dealt.player).build();
|
||||||
dealt.recovery.acceptedDamage(new EntityDamageByEntityEvent(dealt.player, target,
|
dealt.recovery.acceptedDamage(new EntityDamageByEntityEvent(dealt.player, target,
|
||||||
EntityDamageEvent.DamageCause.ENTITY_ATTACK, source, 2));
|
EntityDamageEvent.DamageCause.ENTITY_ATTACK, source, 2));
|
||||||
dealt.clock.advance(Duration.ofSeconds(29)); dealt.recovery.sweep(); assertTrue(dealt.events.isEmpty());
|
dealt.clock.advance(Duration.ofSeconds(9)); dealt.recovery.sweep(); assertTrue(dealt.events.isEmpty());
|
||||||
dealt.clock.advance(Duration.ofSeconds(1)); dealt.recovery.sweep(); dealt.runNext();
|
dealt.clock.advance(Duration.ofSeconds(1)); dealt.recovery.sweep(); dealt.runNext();
|
||||||
assertEquals(5, dealt.health.get(), "Accepted outgoing damage starts a fresh delay for its source character");
|
assertEquals(5, dealt.health.get(), "Accepted outgoing damage starts a fresh delay for its source character");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test void cancellationFailureAndDamageDuringPersistenceNeverPublishOrCatchUp() {
|
@Test void cancellationFailureAndDamageDuringPersistenceNeverPublishOrCatchUp() {
|
||||||
var cancelled = new Direct(); cancelled.veto = true; cancelled.recovery.sweep();
|
var cancelled = new Direct(); cancelled.veto = true; cancelled.recovery.sweep();
|
||||||
cancelled.clock.advance(Duration.ofSeconds(30)); cancelled.recovery.sweep();
|
cancelled.clock.advance(Duration.ofSeconds(10)); cancelled.recovery.sweep();
|
||||||
assertEquals(1, cancelled.events.size()); assertTrue(cancelled.callbacks.isEmpty()); assertEquals(4, cancelled.health.get());
|
assertEquals(1, cancelled.events.size()); assertTrue(cancelled.callbacks.isEmpty()); assertEquals(4, cancelled.health.get());
|
||||||
cancelled.clock.advance(Duration.ofSeconds(9)); cancelled.recovery.sweep(); assertEquals(1, cancelled.events.size());
|
cancelled.clock.advance(Duration.ofSeconds(9)); cancelled.recovery.sweep(); assertEquals(1, cancelled.events.size());
|
||||||
|
|
||||||
var failed = new Direct(); failed.automatic = false; failed.recovery.sweep(); failed.clock.advance(Duration.ofSeconds(30));
|
var failed = new Direct(); failed.automatic = false; failed.recovery.sweep(); failed.clock.advance(Duration.ofSeconds(10));
|
||||||
failed.recovery.sweep(); assertNotNull(failed.pending);
|
failed.recovery.sweep(); assertNotNull(failed.pending);
|
||||||
failed.pending.completeExceptionally(new java.io.IOException("simulated")); failed.runNext();
|
failed.pending.completeExceptionally(new java.io.IOException("simulated")); failed.runNext();
|
||||||
assertEquals(4, failed.health.get());
|
assertEquals(4, failed.health.get());
|
||||||
failed.clock.advance(Duration.ofSeconds(9)); failed.recovery.sweep();
|
failed.clock.advance(Duration.ofSeconds(9)); failed.recovery.sweep();
|
||||||
assertEquals(1, failed.events.size(), "Failed persistence does not immediately replay a missed pulse");
|
assertEquals(1, failed.events.size(), "Failed persistence does not immediately replay a missed pulse");
|
||||||
|
|
||||||
var stale = new Direct(); stale.automatic = false; stale.recovery.sweep(); stale.clock.advance(Duration.ofSeconds(30));
|
var stale = new Direct(); stale.automatic = false; stale.recovery.sweep(); stale.clock.advance(Duration.ofSeconds(10));
|
||||||
stale.recovery.sweep();
|
stale.recovery.sweep();
|
||||||
stale.recovery.acceptedDamage(damage(stale.player, 1));
|
stale.recovery.acceptedDamage(damage(stale.player, 1));
|
||||||
stale.pending.complete(Optional.of(stale.saved(BigDecimal.valueOf(5)))); stale.runNext();
|
stale.pending.complete(Optional.of(stale.saved(BigDecimal.valueOf(5)))); stale.runNext();
|
||||||
assertEquals(4, stale.health.get(), "Damage during the save invalidates native publication");
|
assertEquals(4, stale.health.get(), "Damage during the save invalidates native publication");
|
||||||
stale.clock.advance(Duration.ofSeconds(29)); stale.recovery.sweep(); assertEquals(1, stale.events.size());
|
stale.clock.advance(Duration.ofSeconds(9)); stale.recovery.sweep(); assertEquals(1, stale.events.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test void passiveBonusZeroCancellationAndFullHealthStayInTheBasePulseTransaction() {
|
@Test void passiveBonusZeroCancellationAndFullHealthStayInTheBasePulseTransaction() {
|
||||||
var zero = new Direct(); zero.recovery.attachBonusHealing(ignored -> BigInteger.ZERO);
|
var zero = new Direct(); zero.recovery.attachBonusHealing(ignored -> BigInteger.ZERO);
|
||||||
zero.recovery.sweep(); zero.clock.advance(Duration.ofSeconds(30)); zero.recovery.sweep(); zero.runNext();
|
zero.recovery.sweep(); zero.clock.advance(Duration.ofSeconds(10)); zero.recovery.sweep(); zero.runNext();
|
||||||
assertEquals(5, zero.health.get(), "A zero passive bonus leaves the base pulse unchanged");
|
assertEquals(5, zero.health.get(), "A zero passive bonus leaves the base pulse unchanged");
|
||||||
|
|
||||||
var cancelled = new Direct(); cancelled.recovery.attachBonusHealing(ignored -> BigInteger.valueOf(3)); cancelled.veto = true;
|
var cancelled = new Direct(); cancelled.recovery.attachBonusHealing(ignored -> BigInteger.valueOf(3)); cancelled.veto = true;
|
||||||
var cancelledRevision = cancelled.record.get().revision();
|
var cancelledRevision = cancelled.record.get().revision();
|
||||||
cancelled.recovery.sweep(); cancelled.clock.advance(Duration.ofSeconds(30)); cancelled.recovery.sweep();
|
cancelled.recovery.sweep(); cancelled.clock.advance(Duration.ofSeconds(10)); cancelled.recovery.sweep();
|
||||||
assertEquals(4, cancelled.events.getFirst().getAmount());
|
assertEquals(4, cancelled.events.getFirst().getAmount());
|
||||||
assertEquals(4, cancelled.health.get()); assertEquals(cancelledRevision, cancelled.record.get().revision());
|
assertEquals(4, cancelled.health.get()); assertEquals(cancelledRevision, cancelled.record.get().revision());
|
||||||
|
|
||||||
var full = new Direct(); full.health.set(10d); full.record.set(full.saved(BigDecimal.TEN));
|
var full = new Direct(); full.health.set(10d); full.record.set(full.saved(BigDecimal.TEN));
|
||||||
full.recovery.attachBonusHealing(ignored -> BigInteger.valueOf(3)); var fullRevision = full.record.get().revision();
|
full.recovery.attachBonusHealing(ignored -> BigInteger.valueOf(3)); var fullRevision = full.record.get().revision();
|
||||||
full.recovery.sweep(); full.clock.advance(Duration.ofSeconds(30)); full.recovery.sweep();
|
full.recovery.sweep(); full.clock.advance(Duration.ofSeconds(10)); full.recovery.sweep();
|
||||||
assertTrue(full.events.isEmpty()); assertEquals(fullRevision, full.record.get().revision());
|
assertTrue(full.events.isEmpty()); assertEquals(fullRevision, full.record.get().revision());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test void stackedRegenerationBonusProducesOneMaximumCappedNativeAndPersistedPulse() {
|
@Test void stackedRegenerationBonusProducesOneMaximumCappedNativeAndPersistedPulse() {
|
||||||
var f = new Direct(); f.health.set(9d); f.record.set(f.saved(BigDecimal.valueOf(9)));
|
var f = new Direct(); f.health.set(9d); f.record.set(f.saved(BigDecimal.valueOf(9)));
|
||||||
f.recovery.attachBonusHealing(ignored -> BigInteger.valueOf(3));
|
f.recovery.attachBonusHealing(ignored -> BigInteger.valueOf(3));
|
||||||
f.recovery.sweep(); f.clock.advance(Duration.ofSeconds(30)); f.recovery.sweep();
|
f.recovery.sweep(); f.clock.advance(Duration.ofSeconds(10)); f.recovery.sweep();
|
||||||
assertEquals(1, f.events.size()); assertEquals(1, f.events.getFirst().getAmount());
|
assertEquals(1, f.events.size()); assertEquals(1, f.events.getFirst().getAmount());
|
||||||
f.runNext(); assertEquals(10, f.health.get()); assertEquals(0, BigDecimal.TEN.compareTo(f.record.get().health()));
|
f.runNext(); assertEquals(10, f.health.get()); assertEquals(0, BigDecimal.TEN.compareTo(f.record.get().health()));
|
||||||
}
|
}
|
||||||
@@ -151,6 +151,21 @@ class OutOfCombatRecoveryNativeTest {
|
|||||||
assertEquals(5, f.health.get(), "The new delay evaluates from the retained activity timestamp");
|
assertEquals(5, f.health.get(), "The new delay evaluates from the retained activity timestamp");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test void retainedThirtySecondDelayRemainsEffectiveWithoutRewritingConfiguration() throws Exception {
|
||||||
|
String retained = "out-of-combat-healing-delay-seconds: 30\n";
|
||||||
|
java.nio.file.Files.writeString(data.resolve("config.yml"), retained);
|
||||||
|
try (var f = new FantasyStickLifecycleNativeTest.Fixture(data)) {
|
||||||
|
f.plugin.setEnabled(true);
|
||||||
|
var settings = (games.dmg.fantasystick.persistence.OutOfCombatRecoverySettings)
|
||||||
|
FantasyStickLifecycleNativeTest.Fixture.field(f.plugin, "outOfCombatRecoverySettings");
|
||||||
|
assertEquals("30", settings.value(games.dmg.fantasystick.persistence.OutOfCombatRecoverySettings.DELAY));
|
||||||
|
assertEquals(retained, java.nio.file.Files.readString(data.resolve("config.yml")));
|
||||||
|
var sender = new EquipmentAdminCommandNativeTest.Sender();
|
||||||
|
assertEquals(List.of("10", "30"), f.command.tabComplete(sender.port, "fantasystick",
|
||||||
|
new String[]{"config", "out-of-combat-healing-delay-seconds", ""}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test void packagedPluginConnectsZeroDelayRecoveryConfigurationAndRestart() throws Exception {
|
@Test void packagedPluginConnectsZeroDelayRecoveryConfigurationAndRestart() throws Exception {
|
||||||
java.nio.file.Files.writeString(data.resolve("config.yml"),
|
java.nio.file.Files.writeString(data.resolve("config.yml"),
|
||||||
"out-of-combat-healing-delay-seconds: 0\nout-of-combat-healing-interval-seconds: 10\nout-of-combat-healing-amount: 1\n");
|
"out-of-combat-healing-delay-seconds: 0\nout-of-combat-healing-interval-seconds: 10\nout-of-combat-healing-amount: 1\n");
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ class DistributionTest {
|
|||||||
}
|
}
|
||||||
assertTrue(defaults.contains("sheet-resource-pack-url: ''"));
|
assertTrue(defaults.contains("sheet-resource-pack-url: ''"));
|
||||||
assertTrue(defaults.contains("sheet-resource-pack-sha1: ''"));
|
assertTrue(defaults.contains("sheet-resource-pack-sha1: ''"));
|
||||||
for (String setting : java.util.List.of("out-of-combat-healing-delay-seconds: 30",
|
for (String setting : java.util.List.of("out-of-combat-healing-delay-seconds: 10",
|
||||||
"out-of-combat-healing-interval-seconds: 10", "out-of-combat-healing-amount: 1",
|
"out-of-combat-healing-interval-seconds: 10", "out-of-combat-healing-amount: 1",
|
||||||
"quicker-regeneration-i-bonus-healing: 1", "quicker-regeneration-ii-bonus-healing: 2",
|
"quicker-regeneration-i-bonus-healing: 1", "quicker-regeneration-ii-bonus-healing: 2",
|
||||||
"health-steal-healing-per-kill: 1")) {
|
"health-steal-healing-per-kill: 1")) {
|
||||||
|
|||||||
+2
-2
@@ -18,7 +18,7 @@ class OutOfCombatRecoverySettingsTest {
|
|||||||
@Test void parsesReviewedWholeNumberBoundaries() {
|
@Test void parsesReviewedWholeNumberBoundaries() {
|
||||||
var defaults = defaults();
|
var defaults = defaults();
|
||||||
var parsed = OutOfCombatRecoverySettings.parse(defaults);
|
var parsed = OutOfCombatRecoverySettings.parse(defaults);
|
||||||
assertEquals(Duration.ofSeconds(30), parsed.delay());
|
assertEquals(Duration.ofSeconds(10), parsed.delay());
|
||||||
assertEquals(Duration.ofSeconds(10), parsed.interval());
|
assertEquals(Duration.ofSeconds(10), parsed.interval());
|
||||||
assertEquals(java.math.BigInteger.ONE, parsed.amount());
|
assertEquals(java.math.BigInteger.ONE, parsed.amount());
|
||||||
|
|
||||||
@@ -52,7 +52,7 @@ class OutOfCombatRecoverySettingsTest {
|
|||||||
var delay = settings.set(OutOfCombatRecoverySettings.DELAY, "45").toCompletableFuture();
|
var delay = settings.set(OutOfCombatRecoverySettings.DELAY, "45").toCompletableFuture();
|
||||||
var amount = settings.set(OutOfCombatRecoverySettings.AMOUNT, "3").toCompletableFuture();
|
var amount = settings.set(OutOfCombatRecoverySettings.AMOUNT, "3").toCompletableFuture();
|
||||||
var d = delay.get(5, TimeUnit.SECONDS); var a = amount.get(5, TimeUnit.SECONDS);
|
var d = delay.get(5, TimeUnit.SECONDS); var a = amount.get(5, TimeUnit.SECONDS);
|
||||||
assertEquals("30", settings.value(OutOfCombatRecoverySettings.DELAY));
|
assertEquals("10", settings.value(OutOfCombatRecoverySettings.DELAY));
|
||||||
settings.publish(a); settings.publish(d);
|
settings.publish(a); settings.publish(d);
|
||||||
assertEquals("45", settings.value(OutOfCombatRecoverySettings.DELAY));
|
assertEquals("45", settings.value(OutOfCombatRecoverySettings.DELAY));
|
||||||
assertEquals("3", settings.value(OutOfCombatRecoverySettings.AMOUNT));
|
assertEquals("3", settings.value(OutOfCombatRecoverySettings.AMOUNT));
|
||||||
|
|||||||
Reference in new issue
Block a user