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 @@ -124,6 +124,7 @@ public static String referencedPool(RewardEntry entry) {
}

private String guiTitle;
private volatile Map<String, String> poolDisplayNames = Map.of();

private volatile int barMax;
private volatile int dailyMax;
Expand Down Expand Up @@ -193,6 +194,7 @@ public void load() {
}

guiTitle = config.getString("gui.title", "&8Weekly Activity");
poolDisplayNames = loadPoolDisplayNames(config);

barLength = barLength(config.getInt("bar.length", 40));

Expand Down Expand Up @@ -1472,6 +1474,26 @@ public String guiTitle() {
return guiTitle;
}

/** The short name gui.pool-names gives a reward pool for the weekly icon, or null. */
public String poolDisplayName(String pool) {
return pool == null ? null : poolDisplayNames.get(poolName(pool));
}

private Map<String, String> loadPoolDisplayNames(ConfigurationSection config) {
ConfigurationSection names = section(config, "gui.pool-names");
if (names == null) {
return Map.of();
}
Map<String, String> loaded = new LinkedHashMap<>();
for (String key : keys(names)) {
String name = names.isString(key) ? names.getString(key) : null;
if (name != null && !name.isBlank()) {
loaded.put(poolName(key), name);
}
}
return Map.copyOf(loaded);
}

public int barMax() {
return barMax;
}
Expand Down
131 changes: 110 additions & 21 deletions src/main/java/net/tfminecraft/activitytf/gui/ActivityGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class ActivityGui implements Listener {

private static final int PROGRESS_BAR_LENGTH = 20;

/** Most reward options the weekly icon lists before it sums up the rest. */
static final int MAX_PREVIEW_LINES = 10;

private final ActivityManager manager;

private Consumer<Player> referralOpener;
Expand Down Expand Up @@ -150,7 +153,7 @@ private ItemStack barItem(ActivityConfiguration config, Messages messages, Playe
lore.add(Utils.colorize(bar));
lore.add(" ");
lore.addAll(weeklyRewardLore(messages, data, milestones, config.milestoneDrops(),
config.rewardMultiplier(), config.multiplierPools(), config::rewardPool));
config.rewardMultiplier(), config.multiplierPools(), config::rewardPool, config::poolDisplayName));

return item(Material.EXPERIENCE_BOTTLE,
messages.get("gui.bar-name", "%points%", data.points(), "%max%", config.barMax()),
Expand All @@ -159,7 +162,8 @@ private ItemStack barItem(ActivityConfiguration config, Messages messages, Playe

static List<String> weeklyRewardLore(Messages messages, PlayerData data, List<Integer> milestones,
Map<Integer, RewardEntry> drops, int multiplier, Set<String> multiplierPools,
Function<String, List<RewardEntry>> pools) {
Function<String, List<RewardEntry>> pools,
Function<String, String> poolNames) {
List<String> lore = new ArrayList<>();
int due = data.claimable(milestones);
Integer next = nextMilestone(data, milestones);
Expand All @@ -168,50 +172,135 @@ static List<String> weeklyRewardLore(Messages messages, PlayerData data, List<In
return lore;
}

RewardEntry drop = drops.get(next);
String pool = drop == null ? ActivityConfiguration.DEFAULT_POOL
: ActivityConfiguration.referencedPool(drop);
List<String> rewards = nextRewardDisplays(next, drops, multiplier, pools);
if (pool == null && rewards.size() == 1) {
boolean noteShown = false;
String pool = poolOf(drops.get(next));
if (pool == null) {
lore.add(messages.get("gui.bar-lore-reward", "%points%", next, "%reward%",
Utils.colorize(rewards.get(0))));
Utils.colorize(fixedDisplay(drops.get(next), multiplier))));
} else {
lore.add(messages.get("gui.bar-lore-next-options", "%points%", next));
RewardPreview.Preview preview = RewardPreview.preview(entries(pools, pool));
List<String> rewards = preview.lines();
if (rewards.isEmpty()) {
lore.add(messages.get("gui.reward-preview-unavailable"));
} else {
int draws = multiplierPools.contains(pool) ? multiplier : 1;
int draws = draws(pool, multiplier, multiplierPools);
lore.add(messages.get(draws == 1 ? "gui.reward-preview-one" : "gui.reward-preview-many",
"%count%", draws));
int shown = Math.min(4, rewards.size());
int shown = Math.min(MAX_PREVIEW_LINES, rewards.size());
for (String reward : rewards.subList(0, shown)) {
lore.add(Utils.colorize(reward));
}
if (shown < rewards.size()) {
lore.add(messages.get("gui.reward-preview-more", "%count%", rewards.size() - shown));
}
if (preview.ranged(shown)) {
lore.addAll(messages.lines("gui.reward-preview-ranges"));
noteShown = true;
}
}
}
lore.addAll(laterRewardLore(messages, next, milestones, drops, multiplier, multiplierPools, pools, poolNames,
noteShown));
if (due > 0) {
lore.add(messages.get("gui.reward-click", "%count%", due));
}
return lore;
}

static List<String> nextRewardDisplays(int milestone, Map<Integer, RewardEntry> drops, int multiplier,
Function<String, List<RewardEntry>> pools) {
RewardEntry drop = drops.get(milestone);
String pool = drop == null ? ActivityConfiguration.DEFAULT_POOL
: ActivityConfiguration.referencedPool(drop);
/**
* One line per later milestone this week naming its reward; neighbours with the same reward share a line.
* Adds the range note when a line shows a range and {@code noteShown} says it is not above already.
*/
static List<String> laterRewardLore(Messages messages, int next, List<Integer> milestones,
Map<Integer, RewardEntry> drops, int multiplier, Set<String> multiplierPools,
Function<String, List<RewardEntry>> pools,
Function<String, String> poolNames, boolean noteShown) {
List<String> points = new ArrayList<>();
List<String> names = new ArrayList<>();
boolean ranged = false;
String lastSource = null;
for (Integer milestone : milestones) {
if (milestone <= next) {
continue;
}
RewardEntry drop = drops.get(milestone);
Later later = laterReward(messages, drop, multiplier, multiplierPools, pools, poolNames);
if (later == null) {
continue;
}
String name = later.name();
ranged |= later.ranged();
// Neighbours join only when they pay from the same pool, or the same fixed reward.
String pool = poolOf(drop);
String source = pool != null ? "pool:" + pool : "fixed:" + name;
if (source.equals(lastSource)) {
int last = names.size() - 1;
points.set(last, points.get(last) + "/" + milestone);
} else {
points.add(Integer.toString(milestone));
names.add(name);
}
lastSource = source;
}
List<String> lore = new ArrayList<>();
if (names.isEmpty()) {
return lore;
}
lore.add(messages.get("gui.bar-lore-later"));
for (int i = 0; i < names.size(); i++) {
lore.add(messages.get("gui.bar-lore-later-line", "%points%", points.get(i), "%reward%", names.get(i)));
}
if (ranged && !noteShown) {
lore.addAll(messages.lines("gui.reward-preview-ranges"));
}
return lore;
}

// A later milestone's shown name, and whether that name is a generated range.
private record Later(String name, boolean ranged) {
}

// What a later milestone pays: a fixed drop, the pool's configured name, the pool's only option, or
// "a random reward". Null when there is nothing to pay (an empty pool).
private static Later laterReward(Messages messages, RewardEntry drop, int multiplier,
Set<String> multiplierPools, Function<String, List<RewardEntry>> pools,
Function<String, String> poolNames) {
String pool = poolOf(drop);
if (pool == null) {
RewardEntry.Item item = drop.items().get(0);
return List.of("#50d990x" + item.amount() * multiplier + " #b8906e" + drop.display());
return new Later(Utils.colorize(fixedDisplay(drop, multiplier)), false);
}
List<RewardEntry> entries = pools.apply(pool);
if (entries == null || entries.isEmpty()) {
return List.of();
RewardPreview.Preview preview = RewardPreview.preview(entries(pools, pool));
List<String> options = preview.lines();
if (options.isEmpty()) {
return null;
}
return RewardPreview.summarize(entries);
String configured = poolNames == null ? null : poolNames.apply(pool);
boolean onlyOption = (configured == null || configured.isBlank()) && options.size() == 1;
String name = configured != null && !configured.isBlank() ? Utils.colorize(configured)
: onlyOption ? Utils.colorize(options.get(0))
: messages.get("gui.bar-lore-later-random");
int draws = draws(pool, multiplier, multiplierPools);
return new Later(draws == 1 ? name : messages.get("gui.bar-lore-later-many", "%count%", draws, "%reward%", name),
onlyOption && preview.ranged());
}

private static List<RewardEntry> entries(Function<String, List<RewardEntry>> pools, String pool) {
List<RewardEntry> entries = pools.apply(pool);
return entries == null ? List.of() : entries;
}

private static String poolOf(RewardEntry drop) {
return drop == null ? ActivityConfiguration.DEFAULT_POOL : ActivityConfiguration.referencedPool(drop);
}

private static int draws(String pool, int multiplier, Set<String> multiplierPools) {
return multiplierPools.contains(pool) ? multiplier : 1;
}

private static String fixedDisplay(RewardEntry drop, int multiplier) {
RewardEntry.Item item = drop.items().get(0);
return "#50d990x" + item.amount() * multiplier + " #b8906e" + drop.display();
}

private static Integer nextMilestone(PlayerData data, List<Integer> milestones) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,13 @@ List<String> rewardLore(Reward reward) {
return lore;
}
lore.add(messages.get("gui.reward-preview-one"));
for (String option : RewardPreview.summarize(pool)) {
RewardPreview.Preview preview = RewardPreview.preview(pool);
for (String option : preview.lines()) {
lore.add(Utils.colorize(option));
}
if (preview.ranged()) {
lore.addAll(messages.lines("gui.reward-preview-ranges"));
}
return lore;
}

Expand Down
Loading
Loading