This commit is contained in:
1 parent
e3bc854481
commit
228de3d08f
6 files changed
+145
-23
No files matched your search
@@ -99,6 +99,45 @@ class FrostNovaNativeTest {
|
||||
assertEquals(60L, fixture.delayedTicks.getLast()); fixture.delayed.getLast().run();
|
||||
assertFalse(enemyEffects.containsKey(PotionEffectType.SLOWNESS)); assertFalse(opponentEffects.containsKey(PotionEffectType.SLOWNESS));
|
||||
}
|
||||
var records = events(data);
|
||||
for (var type : List.of("ability.learned", "ability.assigned", "ability.cast", "ability.resolved"))
|
||||
assertEquals(1, abilityEvents(records, type).size(), type);
|
||||
assertEquals(2, abilityEvents(records, "combat.damage").size(), "One accepted record per eligible target");
|
||||
for (var type : List.of("effect.applied", "effect.ended"))
|
||||
assertEquals(2, abilityEvents(records, type).size(), "Only the two owned Slowness layers: " + type);
|
||||
var damageEvents = abilityEvents(records, "combat.damage");
|
||||
assertEquals(2, records.stream().filter(event -> event.get("type").getAsString().endsWith("combat.damage")).count(),
|
||||
"The generic native observer cannot duplicate either owned burst hit");
|
||||
assertEquals(2, damageEvents.stream().map(event -> event.getAsJsonObject("data").get("application_id").getAsString()).distinct().count());
|
||||
assertTrue(damageEvents.stream().allMatch(event -> event.getAsJsonObject("data").has("target_location")
|
||||
&& event.getAsJsonObject("data").get("actual_amount").getAsDouble() == 8
|
||||
&& event.getAsJsonObject("data").get("damage_kind").getAsString().equals("owned_area_burst")));
|
||||
var applied = abilityEvents(records, "effect.applied");
|
||||
assertEquals(2, applied.stream().map(event -> event.getAsJsonObject("data").get("application_id").getAsString()).distinct().count());
|
||||
assertTrue(applied.stream().allMatch(event -> event.getAsJsonObject("data").get("amplifier").getAsInt() == 1));
|
||||
assertEquals(2, abilityEvents(records, "effect.ended").stream()
|
||||
.filter(event -> event.getAsJsonObject("data").get("reason").getAsString().equals("expired")).count());
|
||||
var outcome = abilityEvents(records, "ability.resolved").getFirst().getAsJsonObject("data");
|
||||
assertEquals("hit", outcome.get("outcome").getAsString());
|
||||
assertEquals(2, outcome.get("accepted_count").getAsInt());
|
||||
assertEquals(3, outcome.get("attempt_count").getAsInt());
|
||||
assertEquals(5, outcome.get("candidate_count").getAsInt(), "Duplicate nearby references are deduplicated");
|
||||
assertTrue(outcome.getAsJsonObject("burst_location").has("world_id"));
|
||||
}
|
||||
|
||||
private static List<com.google.gson.JsonObject> events(Path root) throws Exception {
|
||||
var values = new ArrayList<com.google.gson.JsonObject>();
|
||||
try (var files = java.nio.file.Files.walk(root.resolve("events"))) {
|
||||
for (var file : files.filter(path -> path.toString().endsWith(".jsonl")).toList())
|
||||
for (var line : java.nio.file.Files.readAllLines(file))
|
||||
if (!line.isBlank()) values.add(com.google.gson.JsonParser.parseString(line).getAsJsonObject());
|
||||
}
|
||||
return values;
|
||||
}
|
||||
private static List<com.google.gson.JsonObject> abilityEvents(List<com.google.gson.JsonObject> events, String suffix) {
|
||||
return events.stream().filter(event -> event.get("type").getAsString().endsWith(suffix)
|
||||
&& event.getAsJsonObject("data").has("ability_id")
|
||||
&& event.getAsJsonObject("data").get("ability_id").getAsString().equals("frost_nova")).toList();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -274,6 +313,18 @@ class FrostNovaNativeTest {
|
||||
var enemyEffects = effects(enemy); var applied = new HashMap<UUID, Double>(); damage(fixture, enemy, applied);
|
||||
use(fixture, caster); drain(fixture, 2); assertEquals(12, applied.get(enemy.getUniqueId()), 1.0e-9);
|
||||
assertEquals(3, enemyEffects.get(PotionEffectType.SLOWNESS).getAmplifier()); assertEquals(120L, fixture.delayedTicks.getLast());
|
||||
try (var channel = java.nio.channels.FileChannel.open(data.resolve(".config.lock"),
|
||||
java.nio.file.StandardOpenOption.CREATE, java.nio.file.StandardOpenOption.WRITE);
|
||||
var lock = channel.lock()) {
|
||||
assertTrue(lock.isValid());
|
||||
fixture.command.execute(sender.port, "fstickadmin",
|
||||
new String[]{"config", "frost-nova-radius-blocks", "11"});
|
||||
var failed = fixture.tasks.poll(5, TimeUnit.SECONDS); assertNotNull(failed); failed.run();
|
||||
}
|
||||
assertEquals("10", ((games.dmg.fantasystick.persistence.FrostNovaSettings)
|
||||
FantasyStickLifecycleNativeTest.Fixture.field(fixture.plugin, "frostNovaSettings"))
|
||||
.value("frost-nova-radius-blocks"));
|
||||
assertTrue(sender.messages.getLast().contains("save failed"));
|
||||
fixture.command.execute(sender.port, "fantasystick", new String[]{"config", "frost-nova-radius-blocks", "0"});
|
||||
assertTrue(sender.messages.getLast().contains("invalid"));
|
||||
fixture.command.execute(sender.port, "fantasystick", new String[]{"config", "frost-nova-radius-blocks", "10", "extra"});
|
||||
@@ -286,6 +337,12 @@ class FrostNovaNativeTest {
|
||||
assertEquals(java.time.Duration.ofSeconds(3), saved.cooldown());
|
||||
assertEquals(0, new BigDecimal("6").compareTo(saved.parameters().get("slowness-duration-seconds")));
|
||||
}
|
||||
var config = events(data).stream().filter(event -> event.get("type").getAsString().endsWith("config.read")
|
||||
|| event.get("type").getAsString().endsWith("config.changed"))
|
||||
.filter(event -> event.getAsJsonObject("data").has("key")
|
||||
&& event.getAsJsonObject("data").get("key").getAsString().startsWith("frost-nova-")).toList();
|
||||
assertEquals(6, config.size(), "One authorized read and five acknowledged saves, no denied/invalid successes");
|
||||
assertEquals("8", config.getFirst().getAsJsonObject("data").get("after").getAsString());
|
||||
for (String invalid : List.of("frost-nova-base-damage: -1\n", "frost-nova-cooldown-seconds: -1\n",
|
||||
"frost-nova-radius-blocks: 0\n", "frost-nova-slowness-amplifier: -1\n", "frost-nova-slowness-duration-seconds: 0\n")) {
|
||||
var directory = data.resolve(Integer.toHexString(invalid.hashCode())); java.nio.file.Files.createDirectories(directory);
|
||||
|
||||
Reference in new issue
Block a user