Implement xp-less and crown kit upgrading and slightly modify kit progression gui
This commit is contained in:
parent
39f997faf1
commit
6684e812d1
@ -1,6 +1,6 @@
|
||||
package mineplex.core.progression.data;
|
||||
|
||||
import mineplex.core.server.util.TransactionResponse;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -11,6 +11,7 @@ import mineplex.core.common.util.F;
|
||||
import mineplex.core.progression.KitProgressionManager;
|
||||
import mineplex.core.progression.ProgressiveKit;
|
||||
import mineplex.core.progression.math.Calculations;
|
||||
import mineplex.core.server.util.TransactionResponse;
|
||||
import mineplex.core.shop.confirmation.ConfirmationCallback;
|
||||
import mineplex.core.shop.confirmation.ConfirmationProcessor;
|
||||
|
||||
@ -39,11 +40,14 @@ public class KitUpgradeProcessor implements ConfirmationProcessor
|
||||
{
|
||||
String packageName = _kit.getInternalName() + "." + _upgradeLevel;
|
||||
int cost = Calculations.getGemsCost(_upgradeLevel);
|
||||
// Use UnknownPackages for this right now as it handles overspending gems properly
|
||||
_manager.getDonationManager().purchaseUnknownSalesPackage(_player, packageName, GlobalCurrency.GEM, cost, false,
|
||||
data ->
|
||||
if (!_kit.usesXp())
|
||||
{
|
||||
if (data == TransactionResponse.Success)
|
||||
cost = Calculations.getGemsCostXpLess(_upgradeLevel);
|
||||
}
|
||||
|
||||
Consumer<TransactionResponse> handler = response ->
|
||||
{
|
||||
if (response == TransactionResponse.Success)
|
||||
{
|
||||
_kit.upgrade(_upgradeLevel, _player.getUniqueId());
|
||||
|
||||
@ -52,7 +56,7 @@ public class KitUpgradeProcessor implements ConfirmationProcessor
|
||||
|
||||
callback.resolve("Success! You now own this upgrade!");
|
||||
}
|
||||
else if (data == TransactionResponse.InsufficientFunds)
|
||||
else if (response == TransactionResponse.InsufficientFunds)
|
||||
{
|
||||
callback.reject("Insufficient funds!");
|
||||
}
|
||||
@ -60,6 +64,16 @@ public class KitUpgradeProcessor implements ConfirmationProcessor
|
||||
{
|
||||
callback.reject("There was an error processing your transaction. Try again later");
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// Use UnknownPackages for this right now as it handles overspending gems properly
|
||||
if (_kit.crownsEnabled())
|
||||
{
|
||||
_manager.getDonationManager().purchaseUnknownSalesPackageCrown(_player, packageName, cost, false, handler);
|
||||
}
|
||||
else
|
||||
{
|
||||
_manager.getDonationManager().purchaseUnknownSalesPackage(_player, packageName, GlobalCurrency.GEM, cost, false, handler);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +1,18 @@
|
||||
package mineplex.core.progression.gui.buttons;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.menu.IconButton;
|
||||
import mineplex.core.progression.ProgressiveKit;
|
||||
import mineplex.core.progression.math.Calculations;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Representing this kits Abilities in a GUI
|
||||
@ -18,11 +22,13 @@ public class KitUpgradeDetailsButton extends IconButton
|
||||
|
||||
private ItemStack _item;
|
||||
|
||||
public KitUpgradeDetailsButton(int level, List<String> details)
|
||||
public KitUpgradeDetailsButton(ProgressiveKit kit, Player player, int level, List<String> details)
|
||||
{
|
||||
super(null);
|
||||
|
||||
ItemBuilder builder = new ItemBuilder(Material.SLIME_BALL);
|
||||
int current = kit.getUpgradeLevel(player.getUniqueId());
|
||||
|
||||
ItemBuilder builder = new ItemBuilder(Material.STAINED_CLAY).setData((current >= level) ? (short)5 : (short)14);
|
||||
|
||||
builder.setTitle(C.cYellow + "Level " + level + " upgrades");
|
||||
|
||||
@ -34,7 +40,19 @@ public class KitUpgradeDetailsButton extends IconButton
|
||||
}
|
||||
|
||||
lore.add("");
|
||||
if (kit.usesXp())
|
||||
{
|
||||
lore.add(C.cGray + "Unlocks at kit level " + C.cGreen + Calculations.getLevelRequiredFor(level));
|
||||
}
|
||||
else
|
||||
{
|
||||
String currency = C.cGreen + "%cost% Gems";
|
||||
if (kit.crownsEnabled())
|
||||
{
|
||||
currency = C.cGold + "%cost% Crowns";
|
||||
}
|
||||
lore.add(C.cGray + "Unlocks with " + currency.replace("%cost%", Calculations.getGemsCostXpLess(level) + ""));
|
||||
}
|
||||
builder.setLore(lore.toArray(new String[lore.size()]));
|
||||
|
||||
_item = builder.build();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package mineplex.core.progression.gui.buttons;
|
||||
|
||||
import mineplex.core.common.currency.GlobalCurrency;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.progression.KitProgressionManager;
|
||||
@ -47,14 +48,20 @@ public class KitUpgradeMenuButton extends KitButton
|
||||
//The difference between the players current level, and the next upgrade level
|
||||
int diff = nextUpgradeLevelPlayer - level;
|
||||
|
||||
int balance = plugin.getDonationManager().Get(player).getBalance(GlobalCurrency.GEM);
|
||||
if (kit.crownsEnabled())
|
||||
{
|
||||
balance = plugin.getDonationManager().getCrowns(player);
|
||||
}
|
||||
|
||||
//This ONLY flashes if their next upgrade level isn't their same one.
|
||||
_flash = Calculations.isUpgradeLevelEligible(level) && (nextUpgradeLevel > upgradeLevel);
|
||||
_flash = (kit.usesXp() ? (Calculations.isUpgradeLevelEligible(level) && (nextUpgradeLevel > upgradeLevel)) : (Calculations.isUpgradeLevelEligibleXpLess(balance) && upgradeLevel < Calculations.getNextUpgradeLevelXpLess(upgradeLevel)));
|
||||
|
||||
ChatColor color = Calculations.getColor(level, nextUpgradeLevelPlayer);
|
||||
|
||||
if(kit.showUpgrades())
|
||||
if (kit.showUpgrades())
|
||||
{
|
||||
ItemBuilder builder = lore(new ItemBuilder(Material.ENCHANTMENT_TABLE), upgradeLevel, color, diff);
|
||||
ItemBuilder builder = kit.usesXp() ? lore(new ItemBuilder(Material.ENCHANTMENT_TABLE), upgradeLevel, color, diff) : lore(new ItemBuilder(Material.ENCHANTMENT_TABLE), upgradeLevel);
|
||||
builder.setTitle(C.cYellow + "Upgrade Level " + upgradeLevel);
|
||||
_item = builder.build();
|
||||
}
|
||||
@ -138,4 +145,13 @@ public class KitUpgradeMenuButton extends KitButton
|
||||
ChatColor.WHITE + "Click to view Upgrade and XP tracking");
|
||||
return builder;
|
||||
}
|
||||
|
||||
private ItemBuilder lore(ItemBuilder builder, int upgradeLevel)
|
||||
{
|
||||
builder.setLore(" ",
|
||||
ChatColor.WHITE + "Upgrade Level: " + ChatColor.GREEN + upgradeLevel + " out of 5",
|
||||
"",
|
||||
ChatColor.WHITE + "Click to view Upgrades");
|
||||
return builder;
|
||||
}
|
||||
}
|
@ -62,9 +62,12 @@ public class KitDisplayMenu extends KitMenu
|
||||
* @param player The player whose data we'll be using
|
||||
*/
|
||||
private void setUpNextMenuButtons(Button[] buttons, Player player)
|
||||
{
|
||||
if (getKit().usesXp())
|
||||
{
|
||||
buttons[48] = new KitXPButton(getKit(), player, getPlugin());
|
||||
buttons[50] = new KitUpgradeMenuButton(getKit(), player, getPlugin());
|
||||
}
|
||||
buttons[getKit().usesXp() ? 50 : 49] = new KitUpgradeMenuButton(getKit(), player, getPlugin());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,7 +93,7 @@ public class KitDisplayMenu extends KitMenu
|
||||
int index = 0;
|
||||
for(int i : UPGRADE_SLOTS)
|
||||
{
|
||||
buttons[i] = new KitUpgradeDetailsButton(index + 1, details.get(index++));
|
||||
buttons[i] = new KitUpgradeDetailsButton(getKit(), player, index + 1, details.get(index++));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -60,9 +60,11 @@ public class KitInformationTrackerMenu extends KitMenu
|
||||
|
||||
buttons[0] = new BackButton(new KitDisplayMenu(getKit(), getPlugin()));
|
||||
|
||||
if (getKit().usesXp())
|
||||
{
|
||||
setUpXP(buttons, player);
|
||||
|
||||
setUpLevel(buttons, player);
|
||||
}
|
||||
|
||||
setUpUpgrade(buttons, player);
|
||||
|
||||
@ -155,10 +157,10 @@ public class KitInformationTrackerMenu extends KitMenu
|
||||
Map<Integer, List<String>> details = getKit().getUpgradeDetails();
|
||||
|
||||
int index = 0;
|
||||
for(int i : UPGRADE_SLOTS)
|
||||
for (int i : (getKit().usesXp() ? UPGRADE_SLOTS : LEVEL_SLOTS))
|
||||
{
|
||||
List<String> list = details.get(index++);
|
||||
KitUpgradeDetailsButton detailsButton = new KitUpgradeDetailsButton(index, list);
|
||||
KitUpgradeDetailsButton detailsButton = new KitUpgradeDetailsButton(getKit(), player, index, list);
|
||||
ItemBuilder itemStack = new ItemBuilder(detailsButton.getItemStack());
|
||||
|
||||
if (getKit().ownsUpgrade(player.getUniqueId(), index))
|
||||
@ -168,12 +170,18 @@ public class KitInformationTrackerMenu extends KitMenu
|
||||
else if (getKit().canPurchaseUpgrade(player.getUniqueId(), index))
|
||||
{
|
||||
itemStack.setGlow(true);
|
||||
itemStack.addLore("Costs " + C.cGreen + Calculations.getGemsCost(index) + C.cGray + " gems");
|
||||
if (getKit().usesXp())
|
||||
{
|
||||
itemStack.addLore("Costs " + (getKit().crownsEnabled() ? C.cGold : C.cGreen) + Calculations.getGemsCost(index) + C.cGray + (getKit().crownsEnabled() ? " crowns" : " gems"));
|
||||
}
|
||||
itemStack.addLore(C.cGreen + "Click to purchase this upgrade!");
|
||||
}
|
||||
else
|
||||
{
|
||||
itemStack.addLore("Costs " + C.cGreen + Calculations.getGemsCost(index) + C.cGray + " gems");
|
||||
if (getKit().usesXp())
|
||||
{
|
||||
itemStack.addLore("Costs " + (getKit().crownsEnabled() ? C.cGold : C.cGreen) + Calculations.getGemsCost(index) + C.cGray + (getKit().crownsEnabled() ? " crowns" : " gems"));
|
||||
}
|
||||
itemStack.addLore(C.cRed + "You cannot purchase this upgrade!");
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,12 @@
|
||||
package mineplex.core.progression.math;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
|
||||
/**
|
||||
* This class handles all the math and static fields needed for Kit Progressions
|
||||
* You can find some util methods in here as well that relate to numbers
|
||||
@ -15,6 +17,7 @@ public class Calculations
|
||||
private static final int[] LEVELS = new int[100];
|
||||
private static final int[] UPGRADE_LEVELS = {5, 10, 30, 75, 100};
|
||||
private static final Map<Integer, Integer> GEMS_FOR_UPGRADE = Maps.newHashMap();
|
||||
private static final Map<Integer, Integer> GEMS_FOR_XPLESS_UPGRADE = new HashMap<>();
|
||||
|
||||
static
|
||||
{
|
||||
@ -23,6 +26,11 @@ public class Calculations
|
||||
{
|
||||
GEMS_FOR_UPGRADE.put(level, level * 1000);
|
||||
}
|
||||
GEMS_FOR_XPLESS_UPGRADE.put(1, 1000);
|
||||
GEMS_FOR_XPLESS_UPGRADE.put(2, 5000);
|
||||
GEMS_FOR_XPLESS_UPGRADE.put(3, 15000);
|
||||
GEMS_FOR_XPLESS_UPGRADE.put(4, 30000);
|
||||
GEMS_FOR_XPLESS_UPGRADE.put(5, 60000);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -80,6 +88,20 @@ public class Calculations
|
||||
return GEMS_FOR_UPGRADE.containsKey(currentLevel);
|
||||
}
|
||||
|
||||
public static boolean isUpgradeLevelEligibleXpLess(int gems)
|
||||
{
|
||||
boolean afford = false;
|
||||
|
||||
for (int cost : GEMS_FOR_XPLESS_UPGRADE.values())
|
||||
{
|
||||
if (cost <= gems)
|
||||
{
|
||||
afford = true;
|
||||
}
|
||||
}
|
||||
return afford;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the players current level, and his gems, are what he needs to level up this upgrade
|
||||
*
|
||||
@ -92,6 +114,11 @@ public class Calculations
|
||||
return GEMS_FOR_UPGRADE.containsKey(currentLevel) && GEMS_FOR_UPGRADE.get(currentLevel) <= gems;
|
||||
}
|
||||
|
||||
public static boolean canUpgradeXpLess(int upgradeLevel, int gems)
|
||||
{
|
||||
return GEMS_FOR_XPLESS_UPGRADE.containsKey(upgradeLevel) && GEMS_FOR_XPLESS_UPGRADE.get(upgradeLevel) <= gems;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the XP required for the next level
|
||||
*
|
||||
@ -155,7 +182,7 @@ public class Calculations
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next integer upgrade level based of the players current leve;
|
||||
* Get the next integer upgrade level based of the players current level
|
||||
*
|
||||
* @param currentLevel The players current level
|
||||
* @return The next upgrade level
|
||||
@ -170,6 +197,20 @@ public class Calculations
|
||||
return 5;
|
||||
}
|
||||
|
||||
public static int getNextUpgradeLevelXpLess(int currentLevel)
|
||||
{
|
||||
int current = 5;
|
||||
for (int level : GEMS_FOR_XPLESS_UPGRADE.keySet())
|
||||
{
|
||||
if (level < current && level > currentLevel)
|
||||
{
|
||||
current = level;
|
||||
}
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the next level the player needs to reach to unlock an upgrade
|
||||
*
|
||||
@ -215,4 +256,9 @@ public class Calculations
|
||||
{
|
||||
return GEMS_FOR_UPGRADE.get(getLevelRequiredFor(upgradeLevel));
|
||||
}
|
||||
|
||||
public static int getGemsCostXpLess(int upgradeLevel)
|
||||
{
|
||||
return GEMS_FOR_XPLESS_UPGRADE.get(upgradeLevel);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user