diff --git a/src/main/java/net/tfminecraft/infestations/infestation/InfestationManager.java b/src/main/java/net/tfminecraft/infestations/infestation/InfestationManager.java index bcc2b7c..e22ca9e 100644 --- a/src/main/java/net/tfminecraft/infestations/infestation/InfestationManager.java +++ b/src/main/java/net/tfminecraft/infestations/infestation/InfestationManager.java @@ -1188,7 +1188,8 @@ public void onDeath(EntityDeathEvent event) { infestation.setEnemiesAlive(infestation.getEnemiesAlive() - 1); } infestation.setLureRemaining(infestation.getLureRemaining() - 1); - if (killer != null) { + // Lure kills are paid per kill at victory, so summoned worms count no more than ambient ones. + if (killer != null && !Keys.isSummoned(entity.getPersistentDataContainer())) { infestation.addLureKill(killer.getUniqueId()); } } diff --git a/src/main/java/net/tfminecraft/infestations/reward/RewardConfig.java b/src/main/java/net/tfminecraft/infestations/reward/RewardConfig.java index 3a9a1eb..28c1974 100644 --- a/src/main/java/net/tfminecraft/infestations/reward/RewardConfig.java +++ b/src/main/java/net/tfminecraft/infestations/reward/RewardConfig.java @@ -23,6 +23,7 @@ public final class RewardConfig { public static final String OUTSIDE = "outside"; + static final int MAX_LURE_MULTIPLIER = 100; public static boolean enabled; public static Set groups = Set.of(); @@ -31,6 +32,8 @@ public final class RewardConfig { public static int keyCapPerHour; public static Map ambient = Map.of(); public static int lureMinKills = 3; + /** Ambient rolls each lure kill pays at victory. 0 turns the per-kill payout off. */ + public static int lureMultiplier; public static RewardRoller.Keep lureKeep = new RewardRoller.Keep(1, Map.of()); public static Map lure = Map.of(); @@ -73,6 +76,7 @@ public static boolean loadSafe(File file) { ambient = Map.copyOf(ambientTables); lureMinKills = Math.max(0, config.getInt("lure.min-kills", 3)); + lureMultiplier = Math.clamp(config.getInt("lure.multiplier", 0), 0, MAX_LURE_MULTIPLIER); Map keepItems = new HashMap<>(); for (Map row : config.getMapList("lure.outside-zone.keep-items")) { String item = string(row.get("item")); diff --git a/src/main/java/net/tfminecraft/infestations/reward/RewardDrops.java b/src/main/java/net/tfminecraft/infestations/reward/RewardDrops.java index 9ea68b1..a27cd70 100644 --- a/src/main/java/net/tfminecraft/infestations/reward/RewardDrops.java +++ b/src/main/java/net/tfminecraft/infestations/reward/RewardDrops.java @@ -32,6 +32,8 @@ public final class RewardDrops { static final int BURST_TICKS = 30; /** Most entities one rolled stack is split into during a burst. */ static final int MAX_PIECES = 3; + /** Most ambient rolls one player's lure payout makes. */ + static final int MAX_LURE_ROLLS = 10_000; static final String LURE_REWARD_FALLBACK = "{prefix}#c9a44aThe lure bursts open. Your spoils are marked for you."; static Random random = new Random(); @@ -66,24 +68,32 @@ public static void ambientKill(Infestation infestation, Player killer, Location } /** - * Gives each player with enough lure kills a burst of their own items from the lure. Outside a permadeath - * zone each item only survives with its keep chance. + * Gives each player with enough lure kills a burst of their own items from the lure. Each lure kill pays + * the ambient table for the lure's place {@code lure.multiplier} times (key items excluded), and the + * severity's lure table adds a flat bonus. Outside a permadeath zone each bonus item only survives with + * its keep chance. */ public static void lureVictory(Infestation infestation, Location location, Collection players) { if (location == null || !RewardConfig.appliesTo(infestation.getGroupId())) { return; } - RewardTable table = RewardConfig.lure(infestation.getSeverity()); - if (table == null) { + boolean inZone = PermadeathZones.inZone(location); + RewardTable perKill = RewardConfig.lureMultiplier > 0 + ? RewardConfig.ambient(infestation.getSeverity(), inZone) : null; + RewardTable bonus = RewardConfig.lure(infestation.getSeverity()); + if (perKill == null && bonus == null) { return; } - RewardRoller.Keep keep = PermadeathZones.inZone(location) ? null : RewardConfig.lureKeep; + RewardRoller.Keep keep = inZone ? null : RewardConfig.lureKeep; for (Player player : players) { - if (infestation.lureKills(player.getUniqueId()) < RewardConfig.lureMinKills) { + int kills = infestation.lureKills(player.getUniqueId()); + if (kills < RewardConfig.lureMinKills) { continue; } + int rolls = (int) Math.min(MAX_LURE_ROLLS, (long) kills * RewardConfig.lureMultiplier); List items = new ArrayList<>(); - for (RewardRoller.Drop drop : roller.roll(table, RewardConfig.coins, keep)) { + for (RewardRoller.Drop drop : roller.lurePayout(perKill, rolls, RewardConfig.keyItem, bonus, keep, + RewardConfig.coins)) { items.addAll(stacks(drop.item(), drop.amount())); } if (items.isEmpty()) { diff --git a/src/main/java/net/tfminecraft/infestations/reward/RewardRoller.java b/src/main/java/net/tfminecraft/infestations/reward/RewardRoller.java index e0e6329..4e3ab0e 100644 --- a/src/main/java/net/tfminecraft/infestations/reward/RewardRoller.java +++ b/src/main/java/net/tfminecraft/infestations/reward/RewardRoller.java @@ -41,10 +41,55 @@ public RewardRoller(Random random) { * denars are thinned before they are turned into coins. */ public List roll(RewardTable table, List coins, Keep keep) { + return roll(table, coins, keep, 1, null); + } + + /** + * Rolls the table {@code times} times and adds the results together. Entries for {@code skip} never roll. + * Denars from every roll are summed before they are turned into coins. + */ + public List roll(RewardTable table, List coins, Keep keep, int times, String skip) { Map out = new LinkedHashMap<>(); + int denars = 0; + for (int n = 0; n < times; n++) { + denars += rollOnce(table, keep, skip, out); + } + return finish(out, denars, coins); + } + + /** + * One player's lure payout: {@code perKill} rolled {@code times} times without {@code skip} and unthinned, + * plus {@code bonus} rolled once with {@code keep}. Either table may be null. Denars from both are summed + * before they are turned into coins. + */ + public List lurePayout(RewardTable perKill, int times, String skip, RewardTable bonus, Keep keep, + List coins) { + Map out = new LinkedHashMap<>(); + int denars = 0; + for (int n = 0; perKill != null && n < times; n++) { + denars += rollOnce(perKill, null, skip, out); + } + if (bonus != null) { + denars += rollOnce(bonus, keep, null, out); + } + return finish(out, denars, coins); + } + + /** Turns the summed denars into coins and returns everything as drops. */ + private static List finish(Map out, int denars, List coins) { + for (Drop coin : coins(denars, coins)) { + add(out, coin.item(), coin.amount()); + } + List drops = new ArrayList<>(); + out.forEach((item, amount) -> drops.add(new Drop(item, amount))); + return drops; + } + + /** Rolls every entry once into {@code out} and returns the denars rolled. */ + private int rollOnce(RewardTable table, Keep keep, String skip, Map out) { int denars = 0; for (RewardTable.Entry entry : table.drops()) { - if (!hit(entry.chance())) { + if (entry.item().equals(skip) || !hit(entry.chance())) { continue; } int amount = amount(entry.min(), entry.max()); @@ -61,12 +106,7 @@ public List roll(RewardTable table, List coins, Keep kee add(out, entry.item(), kept(entry.item(), amount, keep)); } } - for (Drop coin : coins(denars, coins)) { - add(out, coin.item(), coin.amount()); - } - List drops = new ArrayList<>(); - out.forEach((item, amount) -> drops.add(new Drop(item, amount))); - return drops; + return denars; } /** Splits denars into coins, largest value first. Remainders smaller than the smallest coin are lost. */ diff --git a/src/main/resources/rewards.yml b/src/main/resources/rewards.yml index c8b71e6..60b68c9 100644 --- a/src/main/resources/rewards.yml +++ b/src/main/resources/rewards.yml @@ -1,5 +1,6 @@ -# Bonus loot for infestation kills and cleared lures. -# These drops come on top of the mob's own MythicMobs drop table. +# Loot for infestation kills and cleared lures. Since the TFMC Act System +# (2026-11-15) these are the only infestation drops: the mobs' MythicMobs +# drop table is gone. # # Items are TLibs item paths (m.. for MMOItems). # Two special item names exist: @@ -11,6 +12,13 @@ # # Permadeath zones come from RPCharacters. When RPCharacters is missing, every # location counts as outside a zone. +# +# Balance (ACT-SYSTEM.md, 2026-11-15): an average player (388 kills an active +# hour) at extreme in a zone earns what an average lucky miner earns in an +# hour, 25.9 Ignitium. The other severities pay 1/3, 1/2 and 3/4 of extreme; +# outside a zone pays half of mild. Tin, abyssalite fragments and dust are +# Ignitium / 40 (the act's trickle ratio). Gems and denars fill the rest of a +# miner's hour. Unknown Keys are unchanged. enabled: true @@ -41,14 +49,12 @@ ambient: - {item: m.loot.polished_gemstone_pouch, weight: 10} drops: - {item: m.loot.trial_key, percent: 0.1} - - {item: gem, percent: 0.025} - - {item: denars, percent: 0.5} - - {item: m.currency.enchanted_dust, percent: 0.25} - - {item: m.materials.ignitium, percent: 0.05} - - {item: m.materials.raw_tin, percent: 0.005} - - {item: m.materials.abyssalite_fragment, percent: 0.005} - - {item: m.materials.mythril_fragment, percent: 0.0005} - - {item: m.materials.mythrilite, percent: 0.00025} + - {item: gem, percent: 0.3125} + - {item: denars, percent: 4.35} + - {item: m.currency.enchanted_dust, percent: 0.0275} + - {item: m.materials.ignitium, percent: 1.1} + - {item: m.materials.raw_tin, percent: 0.0275} + - {item: m.materials.abyssalite_fragment, percent: 0.0275} mild: gems: @@ -57,13 +63,11 @@ ambient: drops: - {item: m.loot.trial_key, percent: 2} - {item: gem, percent: 0.625} - - {item: denars, percent: 10} - - {item: m.currency.enchanted_dust, percent: 5} - - {item: m.materials.ignitium, percent: 1} - - {item: m.materials.raw_tin, percent: 0.1} - - {item: m.materials.abyssalite_fragment, percent: 0.1} - - {item: m.materials.mythril_fragment, percent: 0.01} - - {item: m.materials.mythrilite, percent: 0.005} + - {item: denars, percent: 8.7} + - {item: m.currency.enchanted_dust, percent: 0.055} + - {item: m.materials.ignitium, percent: 2.2} + - {item: m.materials.raw_tin, percent: 0.055} + - {item: m.materials.abyssalite_fragment, percent: 0.055} worrying: gems: @@ -73,13 +77,11 @@ ambient: drops: - {item: m.loot.trial_key, percent: 3} - {item: gem, percent: 1} - - {item: denars, percent: 15} - - {item: m.currency.enchanted_dust, percent: 7.5} - - {item: m.materials.ignitium, percent: 1.5} - - {item: m.materials.raw_tin, percent: 0.15} - - {item: m.materials.abyssalite_fragment, percent: 0.15} - - {item: m.materials.mythril_fragment, percent: 0.015} - - {item: m.materials.mythrilite, percent: 0.0075} + - {item: denars, percent: 13} + - {item: m.currency.enchanted_dust, percent: 0.08375} + - {item: m.materials.ignitium, percent: 3.35} + - {item: m.materials.raw_tin, percent: 0.08375} + - {item: m.materials.abyssalite_fragment, percent: 0.08375} severe: gems: @@ -90,13 +92,11 @@ ambient: drops: - {item: m.loot.trial_key, percent: 4.5} - {item: gem, percent: 1.5} - - {item: denars, percent: 22.5} - - {item: m.currency.enchanted_dust, percent: 11.25} - - {item: m.materials.ignitium, percent: 2.25} - - {item: m.materials.raw_tin, percent: 0.225} - - {item: m.materials.abyssalite_fragment, percent: 0.225} - - {item: m.materials.mythril_fragment, percent: 0.0225} - - {item: m.materials.mythrilite, percent: 0.01125} + - {item: denars, percent: 19.5} + - {item: m.currency.enchanted_dust, percent: 0.125} + - {item: m.materials.ignitium, percent: 5} + - {item: m.materials.raw_tin, percent: 0.125} + - {item: m.materials.abyssalite_fragment, percent: 0.125} extreme: gems: @@ -107,13 +107,11 @@ ambient: drops: - {item: m.loot.trial_key, percent: 6} - {item: gem, percent: 2} - - {item: denars, percent: 30} - - {item: m.currency.enchanted_dust, percent: 15} - - {item: m.materials.ignitium, percent: 3} - - {item: m.materials.raw_tin, percent: 0.3} - - {item: m.materials.abyssalite_fragment, percent: 0.3} - - {item: m.materials.mythril_fragment, percent: 0.03} - - {item: m.materials.mythrilite, percent: 0.015} + - {item: denars, percent: 26} + - {item: m.currency.enchanted_dust, percent: 0.1675} + - {item: m.materials.ignitium, percent: 6.7} + - {item: m.materials.raw_tin, percent: 0.1675} + - {item: m.materials.abyssalite_fragment, percent: 0.1675} # When a lure clears, each committed player who is alive and online and made at # least min-kills lure kills gets their own burst of items from the lure. Only @@ -121,72 +119,30 @@ ambient: lure: min-kills: 3 - # Lures outside a permadeath zone roll the same table, then each item survives - # with keep-percent. keep-items overrides it per item. + # Each lure kill a player made rolls the ambient table for the lure's place + # (its zone severity, or outside) this many times. Key items are left out of + # these rolls; the tables below pay the lure's keys. Lures run out and are + # risky, so they pay more than ambient kills. 0 turns this off. + multiplier: 5 + + # Lures outside a permadeath zone roll the tables below, then each item + # survives with keep-percent. keep-items overrides it per item. outside-zone: - keep-percent: 10 - keep-items: - - {item: m.loot.trial_key, keep-percent: 5} - - {item: m.materials.raw_tin, keep-percent: 5} - - {item: m.materials.abyssalite_fragment, keep-percent: 5} - - {item: m.materials.mythril_fragment, keep-percent: 5} - - {item: m.materials.mythrilite, keep-percent: 5} - - {item: m.loot.radiant_gemstone_pouch, keep-percent: 0} - - {item: m.loot.mythical_gemstone_pouch, keep-percent: 0} + keep-percent: 5 + # A flat bonus for each player, on top of the per-kill rolls. mild: drops: - {item: m.loot.trial_key, amount: 4-6} - - {item: denars, amount: 30-50} - - {item: m.currency.enchanted_dust, amount: 6-10} - - {item: m.loot.basic_gemstone_pouch, amount: 3-4} - - {item: m.loot.polished_gemstone_pouch, percent: 25} - - {item: m.materials.ignitium, amount: 3-5} - - {item: m.materials.raw_tin, amount: 1} - - {item: m.materials.abyssalite_fragment, amount: 1} - - {item: m.materials.mythril_fragment, percent: 2} - - {item: m.materials.mythrilite, percent: 1} worrying: drops: - {item: m.loot.trial_key, amount: 7-10} - - {item: denars, amount: 60-100} - - {item: m.currency.enchanted_dust, amount: 12-18} - - {item: m.loot.basic_gemstone_pouch, amount: 4-6} - - {item: m.loot.polished_gemstone_pouch, amount: 1-2} - - {item: m.loot.radiant_gemstone_pouch, percent: 10} - - {item: m.materials.ignitium, amount: 6-9} - - {item: m.materials.raw_tin, amount: 1-2} - - {item: m.materials.abyssalite_fragment, amount: 1-2} - - {item: m.materials.mythril_fragment, percent: 4} - - {item: m.materials.mythrilite, percent: 2} severe: drops: - {item: m.loot.trial_key, amount: 10-14} - - {item: denars, amount: 120-180} - - {item: m.currency.enchanted_dust, amount: 20-28} - - {item: m.loot.basic_gemstone_pouch, amount: 5-7} - - {item: m.loot.polished_gemstone_pouch, amount: 2-3} - - {item: m.loot.radiant_gemstone_pouch, percent: 50} - - {item: m.loot.mythical_gemstone_pouch, percent: 3} - - {item: m.materials.ignitium, amount: 10-14} - - {item: m.materials.raw_tin, amount: 2-3} - - {item: m.materials.abyssalite_fragment, amount: 2-3} - - {item: m.materials.mythril_fragment, percent: 7} - - {item: m.materials.mythrilite, percent: 3.5} extreme: drops: - {item: m.loot.trial_key, amount: 14-20} - - {item: denars, amount: 200-300} - - {item: m.currency.enchanted_dust, amount: 30-40} - - {item: m.loot.basic_gemstone_pouch, amount: 6-8} - - {item: m.loot.polished_gemstone_pouch, amount: 3-4} - - {item: m.loot.radiant_gemstone_pouch, amount: 1-2} - - {item: m.loot.mythical_gemstone_pouch, percent: 12} - - {item: m.materials.ignitium, amount: 15-20} - - {item: m.materials.raw_tin, amount: 3-5} - - {item: m.materials.abyssalite_fragment, amount: 3-5} - - {item: m.materials.mythril_fragment, percent: 10} - - {item: m.materials.mythrilite, percent: 5} diff --git a/src/test/java/net/tfminecraft/infestations/infestation/InfestationManagerTest.java b/src/test/java/net/tfminecraft/infestations/infestation/InfestationManagerTest.java index a065922..bf650c9 100644 --- a/src/test/java/net/tfminecraft/infestations/infestation/InfestationManagerTest.java +++ b/src/test/java/net/tfminecraft/infestations/infestation/InfestationManagerTest.java @@ -856,6 +856,9 @@ void waterAndSeaSpreadLogTheirRoutes(boolean sea) throws Exception { LivingEntity lureMob = mob(1, Keys.KIND_LURE); when(lureMob.getKiller()).thenReturn(killer); when(death.getEntity()).thenReturn(lureMob); manager.onDeath(death); doReturn(mob(1, Keys.KIND_LURE)).when(death).getEntity(); manager.onDeath(death); + LivingEntity lureWorm = mob(1, Keys.KIND_LURE); when(lureWorm.getKiller()).thenReturn(killer); + summoned.add(lureWorm.getPersistentDataContainer()); + when(death.getEntity()).thenReturn(lureWorm); manager.onDeath(death); assertEquals(1, state.lureKills(killer.getUniqueId())); assertEquals(Map.of(killer.getUniqueId(), 1), state.getLureKills()); } diff --git a/src/test/java/net/tfminecraft/infestations/reward/RewardConfigTest.java b/src/test/java/net/tfminecraft/infestations/reward/RewardConfigTest.java index 0b112e2..af47b18 100644 --- a/src/test/java/net/tfminecraft/infestations/reward/RewardConfigTest.java +++ b/src/test/java/net/tfminecraft/infestations/reward/RewardConfigTest.java @@ -53,9 +53,8 @@ private File write(String yaml) throws Exception { assertEquals("m.loot.trial_key", RewardConfig.keyItem); assertEquals(40, RewardConfig.keyCapPerHour); assertEquals(3, RewardConfig.lureMinKills); + assertEquals(5, RewardConfig.lureMultiplier); assertEquals(0.05, RewardConfig.lureKeep.of("m.loot.trial_key"), 1e-9); - assertEquals(0.0, RewardConfig.lureKeep.of("m.loot.mythical_gemstone_pouch")); - assertEquals(0.1, RewardConfig.lureKeep.of("m.currency.enchanted_dust"), 1e-9); for (Severity severity : Severity.values()) { assertNotNull(RewardConfig.ambient(severity, true)); assertNotNull(RewardConfig.lure(severity)); @@ -63,6 +62,16 @@ private File write(String yaml) throws Exception { } assertEquals(new Entry("m.loot.trial_key", 0.06, 1, 1), RewardConfig.ambient(Severity.EXTREME, true).drops().get(0)); assertEquals(new Entry("m.loot.trial_key", 1, 14, 20), RewardConfig.lure(Severity.EXTREME).drops().get(0)); + // Tin, fragments and dust are Ignitium / 40 in every ambient table, and no table pays mythril. + for (RewardTable table : RewardConfig.ambient.values()) { + Map chance = new java.util.HashMap<>(); + table.drops().forEach(e -> chance.put(e.item(), e.chance())); + double ignitium = chance.get("m.materials.ignitium"); + for (String trickle : List.of("m.materials.raw_tin", "m.materials.abyssalite_fragment", "m.currency.enchanted_dust")) { + assertEquals(ignitium / 40, chance.get(trickle), 1e-9, trickle); + } + assertFalse(chance.keySet().stream().anyMatch(item -> item.contains("mythril"))); + } assertTrue(RewardConfig.appliesTo("SWAMP_MOBS")); assertFalse(RewardConfig.appliesTo("crypt")); assertFalse(RewardConfig.appliesTo(null)); @@ -104,12 +113,22 @@ private File write(String yaml) throws Exception { List.of(new Weighted("fine", 2)))), RewardConfig.ambient); assertNull(RewardConfig.ambient(Severity.MILD, false)); assertEquals(0, RewardConfig.lureMinKills); + assertEquals(0, RewardConfig.lureMultiplier); assertEquals(1.0, RewardConfig.lureKeep.of("key")); assertEquals(1.0, RewardConfig.lureKeep.of("other")); assertEquals(Set.of(Severity.SEVERE.id()), RewardConfig.lure.keySet()); assertNull(RewardConfig.lure(Severity.MILD)); } + @Test void lureMultiplierIsClampedToZeroToOneHundred() throws Exception { + assertTrue(RewardConfig.loadSafe(write("lure:\n multiplier: -2\n"))); + assertEquals(0, RewardConfig.lureMultiplier); + assertTrue(RewardConfig.loadSafe(write("lure:\n multiplier: 500\n"))); + assertEquals(100, RewardConfig.lureMultiplier); + assertTrue(RewardConfig.loadSafe(write("lure:\n multiplier: 7\n"))); + assertEquals(7, RewardConfig.lureMultiplier); + } + @Test void emptyGroupsApplyEverywhereUnlessDisabled() throws Exception { assertTrue(RewardConfig.loadSafe(write("groups: []\n"))); assertTrue(RewardConfig.appliesTo(null)); diff --git a/src/test/java/net/tfminecraft/infestations/reward/RewardDropsTest.java b/src/test/java/net/tfminecraft/infestations/reward/RewardDropsTest.java index 8bfda19..471b004 100644 --- a/src/test/java/net/tfminecraft/infestations/reward/RewardDropsTest.java +++ b/src/test/java/net/tfminecraft/infestations/reward/RewardDropsTest.java @@ -96,9 +96,67 @@ class RewardDropsTest { RewardConfig.keyItem = "key"; RewardConfig.keyCapPerHour = 3; RewardConfig.lureMinKills = 3; + RewardConfig.lureMultiplier = 0; + RewardConfig.ambient = Map.of(); RewardConfig.lureKeep = new RewardRoller.Keep(0, Map.of()); } + private List thrownItems() { + List thrown = new ArrayList<>(); + Item entity = mock(Item.class); + when(world.dropItem(any(Location.class), any(ItemStack.class), any())).thenAnswer(i -> { + thrown.add(i.getArgument(1)); + i.>getArgument(2).accept(entity); + return entity; + }); + return thrown; + } + + @Test void lureVictoryPaysTheAmbientTablePerKillTimesTheMultiplierWithoutKeys() { + RewardConfig.lureMultiplier = 5; + RewardConfig.ambient = Map.of( + Severity.SEVERE.id(), table(new Entry("key", 1, 1, 1), new Entry("stone", 1, 1, 1)), + RewardConfig.OUTSIDE, table(new Entry("stone", 1, 2, 2))); + RewardConfig.lure = Map.of(Severity.SEVERE.id(), table(new Entry("key", 1, 4, 4))); + Player fighter = mock(Player.class); + UUID id = UUID.randomUUID(); + when(fighter.getUniqueId()).thenReturn(id); + when(infestation.lureKills(id)).thenReturn(3); + List thrown = thrownItems(); + + // In a zone: 3 kills x 5 rolls of the severe table, its key left out, plus the flat 4 keys. + zones.when(() -> PermadeathZones.inZone(location)).thenReturn(true); + RewardDrops.lureVictory(infestation, location, List.of(fighter)); + later.forEach(Runnable::run); + assertEquals(15, total(thrown, Material.STONE)); + assertEquals(4, total(thrown, Material.TRIAL_KEY)); + + // Outside: the outside table per kill, and the keep chance (0 here) only thins the flat bonus. + thrown.clear(); later.clear(); + zones.when(() -> PermadeathZones.inZone(location)).thenReturn(false); + RewardDrops.lureVictory(infestation, location, List.of(fighter)); + later.forEach(Runnable::run); + assertEquals(30, total(thrown, Material.STONE)); + assertEquals(0, total(thrown, Material.TRIAL_KEY)); + + // Rolls are capped per player. + thrown.clear(); later.clear(); + when(infestation.lureKills(id)).thenReturn(5_000); + RewardConfig.lure = Map.of(); + RewardDrops.lureVictory(infestation, location, List.of(fighter)); + later.forEach(Runnable::run); + assertEquals(2 * RewardDrops.MAX_LURE_ROLLS, total(thrown, Material.STONE)); + } + + @Test void lureVictoryWithAMultiplierButNoTablesPaysNothing() { + RewardConfig.lureMultiplier = 5; + RewardConfig.lure = Map.of(); + Player fighter = mock(Player.class); + RewardDrops.lureVictory(infestation, location, List.of(fighter)); + verifyNoInteractions(fighter); + assertEquals(List.of(), later); + } + @AfterEach void restore() throws Exception { for (int i = mocks.size() - 1; i >= 0; i--) mocks.get(i).close(); RewardDrops.warnedPaths.clear(); diff --git a/src/test/java/net/tfminecraft/infestations/reward/RewardRollerTest.java b/src/test/java/net/tfminecraft/infestations/reward/RewardRollerTest.java index 1cce469..8ec98e4 100644 --- a/src/test/java/net/tfminecraft/infestations/reward/RewardRollerTest.java +++ b/src/test/java/net/tfminecraft/infestations/reward/RewardRollerTest.java @@ -69,6 +69,34 @@ static final class Script extends Random { assertEquals(1.0, keep.of("whole")); } + @Test void manyRollsSkipOneItemAndSumDenarsBeforeCoins() { + RewardTable table = new RewardTable(List.of( + new Entry("key", 0.5, 1, 1), + new Entry("stone", 1, 2, 2), + new Entry("denars", 1, 3, 3)), List.of()); + List fives = List.of(new Coin("five", 5)); + // The skipped key never draws a random number; 3 + 3 denars make one coin, though 3 alone makes none. + assertEquals(List.of(new Drop("stone", 4), new Drop("five", 1)), + new RewardRoller(new Script()).roll(table, fives, null, 2, "key")); + assertEquals(List.of(new Drop("stone", 2)), new RewardRoller(new Script()).roll(table, fives, null, 1, "key")); + assertEquals(List.of(), new RewardRoller(new Script()).roll(table, fives, null, 0, "key")); + } + + @Test void lurePayoutSumsDenarsFromRollsAndBonusAndThinsOnlyTheBonus() { + RewardTable perKill = new RewardTable(List.of(new Entry("key", 1, 1, 1), new Entry("denars", 1, 1, 1)), List.of()); + RewardTable bonus = new RewardTable(List.of(new Entry("denars", 1, 3, 3), new Entry("stone", 1, 2, 2)), List.of()); + List fives = List.of(new Coin("five", 5)); + Keep keepAll = new Keep(1, Map.of("stone", 0.0)); + // 3 rolls give 3 denars, the bonus 3 more: 6 make one five-coin, though neither part alone does. + // The bonus stone is thinned to nothing; the per-kill rolls are never thinned and skip the key. + assertEquals(List.of(new Drop("five", 1)), + new RewardRoller(new Script()).lurePayout(perKill, 3, "key", bonus, keepAll, fives)); + assertEquals(List.of(new Drop("key", 5), new Drop("five", 1)), + new RewardRoller(new Script()).lurePayout(perKill, 5, null, null, new Keep(0, Map.of()), fives)); + assertEquals(List.of(new Drop("stone", 2)), + new RewardRoller(new Script()).lurePayout(null, 9, "key", bonus, null, fives)); + } + @Test void coinsUseLargestFirstAndSkipBadValues() { assertEquals(List.of(), RewardRoller.coins(0, COINS)); assertEquals(List.of(), RewardRoller.coins(-5, COINS));