From ac0f0500714da3bc724f6e5fe2f8122faa682820 Mon Sep 17 00:00:00 2001 From: Teriuihi Date: Wed, 12 Jan 2022 03:26:54 +0100 Subject: [PATCH] Added current multiplier to points command --- .../alttd/commands/subcommands/CommandPoints.java | 8 ++++++-- src/main/java/com/alttd/config/Config.java | 4 +++- src/main/java/com/alttd/objects/Price.java | 14 +++++++++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/alttd/commands/subcommands/CommandPoints.java b/src/main/java/com/alttd/commands/subcommands/CommandPoints.java index 9cac561..7aff619 100644 --- a/src/main/java/com/alttd/commands/subcommands/CommandPoints.java +++ b/src/main/java/com/alttd/commands/subcommands/CommandPoints.java @@ -3,6 +3,7 @@ package com.alttd.commands.subcommands; import com.alttd.commands.SubCommand; import com.alttd.config.Config; import com.alttd.objects.EconUser; +import com.alttd.objects.Price; import com.alttd.objects.VillagerType; import com.alttd.util.Logger; import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; @@ -40,10 +41,13 @@ public class CommandPoints extends SubCommand { Logger.warning("Player % has unused villager type % in their point list.", player.getName(), key); return; } + int currentPoints = pointsMap.getOrDefault(key, 0); ref.message = ref.message.append(miniMessage.deserialize("\n", TemplateResolver.resolving())); ref.message = ref.message.append(miniMessage.deserialize(Config.POINTS_CONTENT, TemplateResolver.resolving( - Template.template("villager_type", VillagerType.getVillagerType(key).getDisplayName()), - Template.template("points", String.valueOf(pointsMap.getOrDefault(key, 0))) + Template.template("villager_type", VillagerType.getVillagerType(key).getDisplayName()), + Template.template("points", String.valueOf(currentPoints)), + Template.template("buy_multiplier", String.valueOf(Price.getCurrentMultiplier(currentPoints, true))), + Template.template("sell_multiplier", String.valueOf(Price.getCurrentMultiplier(currentPoints, true))) ))); }); } else if (args.length == 2){ diff --git a/src/main/java/com/alttd/config/Config.java b/src/main/java/com/alttd/config/Config.java index 21a5d3b..879f054 100644 --- a/src/main/java/com/alttd/config/Config.java +++ b/src/main/java/com/alttd/config/Config.java @@ -108,7 +108,9 @@ public final class Config extends AbstractConfig { " for !"; public static String REMOVED_VILLAGER = "Removed villager with uuid "; public static String POINTS_HEADER = "Villager points for : "; - public static String POINTS_CONTENT = ": "; + public static String POINTS_CONTENT = ": points: " + + "buy:x " + + "sell:x"; public static String BUY_ITEM_MESSAGE = " can be bought at spawn at the villager for $ and points per item " + "at your current amount of points ()."; public static String NO_BUY_AT_SPAWN = " can not be bought at spawn, try a player shop!"; diff --git a/src/main/java/com/alttd/objects/Price.java b/src/main/java/com/alttd/objects/Price.java index 8c6ce0c..60562d2 100644 --- a/src/main/java/com/alttd/objects/Price.java +++ b/src/main/java/com/alttd/objects/Price.java @@ -7,9 +7,9 @@ public final class Price { private final double price; private final int points; - private static final double[] xMult = {Integer.MIN_VALUE, -4000, -2000, -500, 500, 2000, 4000, Integer.MAX_VALUE}; - private static final double[] yMultBuy = {0.6, 0.75, 0.9, 1, 1.5, 2.5, 5}; - private static final double[] yMultSell = {0.2, 0.4, 0.7, 1, 1.25, 1.75, 2.5}; + private static final double[] xMult = {Integer.MIN_VALUE, -6000, -4000, -2000, -500, 500, 2000, 4000, 6000, Integer.MAX_VALUE}; + private static final double[] yMultBuy = {0.5, 0.6, 0.75, 0.9, 1, 1.5, 2.5, 5, 10}; + private static final double[] yMultSell = {0.1, 0.2, 0.4, 0.7, 1, 1.25, 1.75, 2.5, 3}; public Price(double price) { this.price = price; @@ -20,6 +20,14 @@ public final class Price { return (new Price(Utilities.round(one.getPrice(1) + two.getPrice(1), 2))); } + public static double getCurrentMultiplier(int points, boolean buy) { + for (int i = 1; i < xMult.length; i++) { + if (points <= xMult[i]) + return buy ? yMultBuy[i - 1] : yMultSell[i - 1]; + } + return 0; + } + public double getPrice(int multiplier) { return (Utilities.round(price * multiplier, 2)); }