diff --git a/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ShopPageBase.java b/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ShopPageBase.java index 48d9f0ff1..cf6a5061b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ShopPageBase.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/shop/page/ShopPageBase.java @@ -135,7 +135,6 @@ public abstract class ShopPageBase= gemAmount) + { + deductGems(player, gemAmount); + addGold(player, goldCount); + notify(player, String.format("You have transferred %d gems into %d gold coins!", gemCount, goldCount)); + } + } + + /** + * @param player - the player to be checked for whether they can transfer gems into coins + * @return true, if the player has not converted gems into coins within the + * last day, false otherwise. + */ + public boolean canTransferGems(Player player) + { + return !_transferTracker.hasTransferredToday(player); + } + public void addGold(Player player, int amount) { - getDonor(player).addGold(amount); + _donationManager.RewardGoldLater("GoldManager", player, amount); } public void deductGold(Player player, int amount) @@ -116,6 +147,16 @@ public class GoldManager extends MiniPlugin notify(player, String.format("You have purchased a gold token worth %dg!", tokenValue)); } + public void addGems(Player player, int amount) + { + _donationManager.RewardGemsLater("GoldManager", player, amount); + } + + public void deductGems(Player player, int amount) + { + addGems(player, -amount); + } + private Donor getDonor(Player player) { return _donationManager.Get(player.getName()); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/TransferTracker.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/TransferTracker.java new file mode 100644 index 000000000..140a2872e --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/economy/TransferTracker.java @@ -0,0 +1,37 @@ +package mineplex.game.clans.economy; + +import org.bukkit.entity.Player; + +import mineplex.serverdata.Region; +import mineplex.serverdata.data.DataRepository; +import mineplex.serverdata.redis.RedisDataRepository; +import mineplex.serverdata.servers.ServerManager; + +/** + * Tracks when a player last converted gems into coins. + * @author MrTwiggy + * + */ +public class TransferTracker +{ + public static final int TRANSFER_TIMEOUT = 24 * 60 * 60; // Time before transfer entry expires from DB (in seconds) + private DataRepository _repository; + + public TransferTracker() + { + _repository = new RedisDataRepository(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(), + Region.currentRegion(), GemTransfer.class, "GemTransfers"); + } + + public void insertTransfer(Player player) + { + GemTransfer transfer = new GemTransfer(player.getName()); + _repository.addElement(transfer, TRANSFER_TIMEOUT); + } + + public boolean hasTransferredToday(Player player) + { + GemTransfer transfer = _repository.getElement(player.getName()); + return transfer != null && transfer.transferWasToday(); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/attributes/ItemAttribute.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/attributes/ItemAttribute.java index 540918364..e136ca42c 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/attributes/ItemAttribute.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/attributes/ItemAttribute.java @@ -50,4 +50,72 @@ public abstract class ItemAttribute { return new ValueDistribution(minValue, maxValue); } + + /** + * @param amplifier - the amplifier for a potion effect intensity + * @return the roman-numeral properly representing the amplifier + */ + public static String amplifierToRoman(int amplifier) + { + return integerToRomanNumeral(amplifier + 1); // Add one because amplifiers are zero-based + } + + // Ugly int-to-roman numeral conversion found online. Don't judge! + public static String integerToRomanNumeral(int input) { + if (input < 1 || input > 3999) + return "???"; + String s = ""; + while (input >= 1000) { + s += "M"; + input -= 1000; } + while (input >= 900) { + s += "CM"; + input -= 900; + } + while (input >= 500) { + s += "D"; + input -= 500; + } + while (input >= 400) { + s += "CD"; + input -= 400; + } + while (input >= 100) { + s += "C"; + input -= 100; + } + while (input >= 90) { + s += "XC"; + input -= 90; + } + while (input >= 50) { + s += "L"; + input -= 50; + } + while (input >= 40) { + s += "XL"; + input -= 40; + } + while (input >= 10) { + s += "X"; + input -= 10; + } + while (input >= 9) { + s += "IX"; + input -= 9; + } + while (input >= 5) { + s += "V"; + input -= 5; + } + while (input >= 4) { + s += "IV"; + input -= 4; + } + while (input >= 1) { + s += "I"; + input -= 1; + } + return s; + } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/attributes/armor/ReinforcedAttribute.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/attributes/armor/ReinforcedAttribute.java index 36f385e73..17763f8af 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/attributes/armor/ReinforcedAttribute.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/attributes/armor/ReinforcedAttribute.java @@ -23,6 +23,6 @@ public class ReinforcedAttribute extends FlatReductionAttribute @Override public String getDescription() { - return String.format("Reduce incoming enemy attacks by %.2f half-hearts.", getFlatReduction()); + return String.format("Reduce incoming attacks by enemies by %.2f half-hearts.", getFlatReduction()); } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/attributes/weapon/FrostedAttribute.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/attributes/weapon/FrostedAttribute.java index 6109b9cee..790806b7b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/attributes/weapon/FrostedAttribute.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/attributes/weapon/FrostedAttribute.java @@ -41,7 +41,7 @@ public class FrostedAttribute extends ItemAttribute @Override public String getDescription() { - return String.format("Apply slowness %d for %d ticks to enemies.", _slowAmount, _slowDuration); + return String.format("Apply slowness %s for %d ticks to enemies.", amplifierToRoman(_slowAmount), _slowDuration); } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/attributes/weapon/HasteAttribute.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/attributes/weapon/HasteAttribute.java index 0c2cd3adf..d0f88c06f 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/attributes/weapon/HasteAttribute.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/attributes/weapon/HasteAttribute.java @@ -34,7 +34,7 @@ public class HasteAttribute extends AttackAttribute @Override public String getDescription() { - return String.format("Gain speed %d for %d ticks every %d attacks.", _speedAmount, _speedDuration, getAttackLimit()); + return String.format("Gain speed %s for %d ticks every %d attacks.", amplifierToRoman(_speedAmount), _speedDuration, getAttackLimit()); } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/AlligatorsTooth.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/AlligatorsTooth.java index e43868f99..568240b4b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/AlligatorsTooth.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/AlligatorsTooth.java @@ -20,7 +20,7 @@ public class AlligatorsTooth extends LegendaryItem public AlligatorsTooth() { - super("Alligators Tooth", "Grants bonus damage in water and special ability to swim fast!", Material.RAW_FISH); + super("Alligators Tooth", "Grants bonus damage in water and special ability to swim fast!", Material.RECORD_3); _damageBonus = damageGen.generateValue(); _swimSpeed = boostGen.generateValue(); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/GiantsBroadsword.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/GiantsBroadsword.java index 2835846cb..05621969e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/GiantsBroadsword.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/GiantsBroadsword.java @@ -16,7 +16,7 @@ public class GiantsBroadsword extends LegendaryItem public GiantsBroadsword() { - super("Giants Broadsword", "Deal huge damage and block to gain defensive abilities!", Material.PAPER); + super("Giants Broadsword", "Deal huge damage and block to gain defensive abilities!", Material.RECORD_4); } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/HyperBlade.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/HyperBlade.java index 92e103bb3..e6376ea5d 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/HyperBlade.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/HyperBlade.java @@ -23,7 +23,7 @@ public class HyperBlade extends LegendaryItem public HyperBlade() { - super("Hyper Blade", "Increased attack speed!", Material.STICK); + super("Hyper Blade", "Increased attack speed!", Material.RECORD_5); _speedAmount = amountGen.generateIntValue(); _speedDuration = durationGen.generateIntValue(); _lastAttack = 0; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/MagneticBlade.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/MagneticBlade.java index 7934f5de2..a368a99ae 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/MagneticBlade.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/MagneticBlade.java @@ -18,7 +18,7 @@ public class MagneticBlade extends LegendaryItem public MagneticBlade() { - super("Magnetic Blade", "Pull enemies closer with special abilities!", Material.STICK); + super("Magnetic Blade", "Pull enemies closer with special abilities!", Material.RECORD_6); } @Override diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/WindBlade.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/WindBlade.java index 47fd1bee3..95a5a4c7b 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/WindBlade.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/items/legendaries/WindBlade.java @@ -19,7 +19,7 @@ public class WindBlade extends LegendaryItem public WindBlade() { - super("Wind Blade", "Activate flying ability to take flight for 80 ticks before landing!", Material.STICK); // TODO: Configurable? + super("Wind Blade", "Activate flying ability to take flight for 80 ticks before landing!", Material.RECORD_8); // TODO: Configurable? _flightTime = 0; } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/bank/BankPage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/bank/BankPage.java index 5d2624605..8023e6763 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/bank/BankPage.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/bank/BankPage.java @@ -21,6 +21,7 @@ import mineplex.game.clans.shop.building.BuildingPage; public class BankPage extends ShopPageBase { + public static final int GEM_CONVERSION = 1000; // The number of gems that can be converted into gold public static final int TOKEN_VALUE = 50000; // Value of a GoldToken (in gold) that can be stored/cashed in here private ClanInfo _clanInfo; @@ -45,6 +46,15 @@ public class BankPage extends ShopPageBase { buildTokenUnpurchasable(); } + + if (GoldManager.getInstance().canTransferGems(getPlayer())) + { + buildTransferGems(); + } + else + { + buildTransferGemsCooldown(); + } } private void buildCashIn() @@ -58,6 +68,31 @@ public class BankPage extends ShopPageBase ShopItem shopItem = new ShopItem(Material.FURNACE, title, new String[] {" ", playerGoldString, description}, 0, true, true); addButton(5, shopItem, button); } + + private void buildTransferGems() + { + int playerGold = getPlayerGold(); + int playerGems = getPlayerGems(); + int conversionCount = GEM_CONVERSION * GoldManager.GEM_CONVERSION_RATE; + + GemTransferButton button = new GemTransferButton(this, GEM_CONVERSION); + String title = ChatColor.GOLD + C.Bold + "Convert Gems To Gold!"; + String playerGoldString = ChatColor.RESET + F.value("Your Gold", playerGold + "g"); + String playerGemString = ChatColor.RESET + F.value("Your Gems", playerGems + " gems"); + String purchaseString = ChatColor.RESET + F.value("Conversion Rate", GEM_CONVERSION + " gems for " + conversionCount + " gold"); + String goldString = ChatColor.RESET + C.cWhite + "Convert gems into gold coins once per day!"; + ShopItem shopItem = new ShopItem(Material.EMERALD, title, new String[] {" ", playerGoldString, playerGemString, purchaseString, goldString}, 0, true, true); + addButton(4, shopItem, button); + } + + private void buildTransferGemsCooldown() + { + StoreGoldButton button = new StoreGoldButton(this); + String title = ChatColor.RED + C.Bold + "Conversion Cooldown!"; + String purchaseString = ChatColor.RESET + C.cWhite + "You have already converted gems into coins today"; + ShopItem shopItem = new ShopItem(Material.REDSTONE_BLOCK, title, new String[] {" ", purchaseString, " "}, 0, true, true); + addButton(4, shopItem, button); + } private void buildTokenPurchasable() { @@ -95,6 +130,11 @@ public class BankPage extends ShopPageBase { return getPlayerGold() >= TOKEN_VALUE; } + + private int getPlayerGems() + { + return GoldManager.getInstance().getGems(getPlayer()); + } private int getPlayerGold() { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/bank/GemTransferButton.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/bank/GemTransferButton.java new file mode 100644 index 000000000..cd5a969b2 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/bank/GemTransferButton.java @@ -0,0 +1,41 @@ +package mineplex.game.clans.shop.bank; + +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.Callback; +import mineplex.core.donation.DonationManager; +import mineplex.core.shop.item.IButton; +import mineplex.game.clans.clans.ClanInfo; +import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.economy.GoldManager; +import mineplex.game.clans.items.CustomItem; +import mineplex.game.clans.items.GearManager; +import mineplex.game.clans.items.economy.GoldToken; + +public class GemTransferButton implements IButton +{ + private BankPage _page; + private int _gemAmount; + + public GemTransferButton(BankPage page, int gemAmount) + { + _page = page; + _gemAmount = gemAmount; + } + + @Override + public void onClick(Player player, ClickType clickType) + { + if (clickType != ClickType.LEFT) return; + + if (GoldManager.getInstance().canTransferGems(player)) + { + GoldManager.getInstance().transferGemsToCoins(player, _gemAmount); + _page.refresh(); + } + } + +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/farming/FarmingPage.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/farming/FarmingPage.java new file mode 100644 index 000000000..c4586db2b --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/farming/FarmingPage.java @@ -0,0 +1,34 @@ +package mineplex.game.clans.shop.farming; + +import org.bukkit.Material; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.donation.DonationManager; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.game.clans.clans.ClansManager; +import mineplex.game.clans.shop.PvpItem; +import mineplex.game.clans.shop.PvpShopButton; + +public class FarmingPage extends ShopPageBase +{ + public FarmingPage(ClansManager plugin, FarmingShop shop, CoreClientManager clientManager, DonationManager donationManager, org.bukkit.entity.Player player) + { + super(plugin, shop, clientManager, donationManager, "Organic Produce", player); + + buildPage(); + } + + @Override + protected void buildPage() + { + addPvpItem(1, new PvpItem(Material.STONE, (byte)0, 1, "Stone", 25, 64)); + addPvpItem(2, new PvpItem(Material.WOOD, (byte)0, 1, "Wood", 15, 64)); + addPvpItem(3, new PvpItem(Material.BRICK, (byte)0, 1, "Bricks", 30, 64)); + addPvpItem(4, new PvpItem(Material.SANDSTONE, (byte)0, 1, "Sandstone", 30, 64)); + } + + public void addPvpItem(int slot, PvpItem item) + { + addButton(slot, item, new PvpShopButton(this, item)); + } +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/farming/FarmingShop.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/farming/FarmingShop.java new file mode 100644 index 000000000..375dff0af --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/shop/farming/FarmingShop.java @@ -0,0 +1,27 @@ +package mineplex.game.clans.shop.farming; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.util.C; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.shop.ShopBase; +import mineplex.core.shop.page.ShopPageBase; +import mineplex.game.clans.clans.ClansManager; + +public class FarmingShop extends ShopBase +{ + public FarmingShop(ClansManager plugin, CoreClientManager clientManager, mineplex.core.donation.DonationManager donationManager) + { + super(plugin, clientManager, donationManager, "Organic Produce"); + } + + @Override + protected ShopPageBase> buildPagesFor(Player player) + { + return new FarmingPage(getPlugin(), this, getClientManager(), getDonationManager(), player); + } +}