Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> groups = Set.of();
Expand All @@ -31,6 +32,8 @@ public final class RewardConfig {
public static int keyCapPerHour;
public static Map<String, RewardTable> 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<String, RewardTable> lure = Map.of();

Expand Down Expand Up @@ -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<String, Double> keepItems = new HashMap<>();
for (Map<?, ?> row : config.getMapList("lure.outside-zone.keep-items")) {
String item = string(row.get("item"));
Expand Down
24 changes: 17 additions & 7 deletions src/main/java/net/tfminecraft/infestations/reward/RewardDrops.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<Player> 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<ItemStack> 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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,55 @@ public RewardRoller(Random random) {
* denars are thinned before they are turned into coins.
*/
public List<Drop> roll(RewardTable table, List<RewardTable.Coin> 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<Drop> roll(RewardTable table, List<RewardTable.Coin> coins, Keep keep, int times, String skip) {
Map<String, Integer> 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<Drop> lurePayout(RewardTable perKill, int times, String skip, RewardTable bonus, Keep keep,
List<RewardTable.Coin> coins) {
Map<String, Integer> 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<Drop> finish(Map<String, Integer> out, int denars, List<RewardTable.Coin> coins) {
for (Drop coin : coins(denars, coins)) {
add(out, coin.item(), coin.amount());
}
List<Drop> 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<String, Integer> 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());
Expand All @@ -61,12 +106,7 @@ public List<Drop> roll(RewardTable table, List<RewardTable.Coin> 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<Drop> 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. */
Expand Down
136 changes: 46 additions & 90 deletions src/main/resources/rewards.yml
Original file line number Diff line number Diff line change
@@ -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.<type>.<id> for MMOItems).
# Two special item names exist:
Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -107,86 +107,42 @@ 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
# that player can pick their items up.
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}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
Loading