Add ability to convert Gems into Gold daily to Bank Shop, including redis-based system for tracking most recent transfers. Fix bug with item attributes that reference potions not properly displaying potion value effects (uses roman numerals). Prepare for custom textured Legendary items by modifying over to record-based materials. Add base for organic produce / farming shop.
This commit is contained in:
parent
971612a538
commit
4dd1cf43de
@ -135,7 +135,6 @@ public abstract class ShopPageBase<PluginType extends MiniPlugin, ShopType exten
|
||||
|
||||
public void playerClicked(InventoryClickEvent event)
|
||||
{
|
||||
System.out.println("Clicked " + event.getRawSlot() + " --- vs " + event.getSlot() + " --- " + event.getInventory().getSize() + " --- " + inventory.getSize() + event.getInventory().getName());
|
||||
if (_buttonMap.containsKey(event.getRawSlot()))
|
||||
{
|
||||
_buttonMap.get(event.getRawSlot()).onClick(_player, event.getClick());
|
||||
|
@ -0,0 +1,51 @@
|
||||
package mineplex.game.clans.economy;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.serverdata.data.Data;
|
||||
|
||||
public class GemTransfer implements Data
|
||||
{
|
||||
private static DateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy");
|
||||
|
||||
private String _playerName;
|
||||
private Date _date;
|
||||
|
||||
public GemTransfer(String playerName)
|
||||
{
|
||||
_playerName = playerName;
|
||||
_date = new Date();
|
||||
}
|
||||
|
||||
public boolean transferWasToday()
|
||||
{
|
||||
return currentDate().before(_date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDataId()
|
||||
{
|
||||
return _playerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the current date, with hours/minutes/seconds defaulted to 00:00, 12:00am of the
|
||||
* current day.
|
||||
*/
|
||||
public static Date currentDate()
|
||||
{
|
||||
Date current = new Date();
|
||||
|
||||
try
|
||||
{
|
||||
return dateFormatter.parse(dateFormatter.format(current));
|
||||
}
|
||||
catch (Exception exception) { }
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -36,12 +36,14 @@ import mineplex.minecraft.game.core.condition.ConditionManager;
|
||||
|
||||
public class GoldManager extends MiniPlugin
|
||||
{
|
||||
public static final int GEM_CONVERSION_RATE = 50; // The number of gold coins when converted from a single gem
|
||||
public static final double DEATH_TAX = 0.04d; // Percentage of gold lost on death
|
||||
|
||||
private static GoldManager _instance;
|
||||
public static GoldManager getInstance() { return _instance; }
|
||||
|
||||
private DonationManager _donationManager;
|
||||
private TransferTracker _transferTracker;
|
||||
private BankShop _bankShop;
|
||||
|
||||
public GoldManager(ClansManager plugin, CoreClientManager clientManager, DonationManager donationManager)
|
||||
@ -50,6 +52,7 @@ public class GoldManager extends MiniPlugin
|
||||
|
||||
_instance = this;
|
||||
_donationManager = donationManager;
|
||||
_transferTracker = new TransferTracker();
|
||||
_bankShop = new BankShop(plugin, clientManager, donationManager);
|
||||
}
|
||||
|
||||
@ -91,9 +94,37 @@ public class GoldManager extends MiniPlugin
|
||||
return getDonor(player).getGold();
|
||||
}
|
||||
|
||||
public int getGems(Player player)
|
||||
{
|
||||
return getDonor(player).GetGems();
|
||||
}
|
||||
|
||||
public void transferGemsToCoins(Player player, int gemAmount)
|
||||
{
|
||||
int gemCount = getGems(player);
|
||||
int goldCount = gemAmount * GEM_CONVERSION_RATE;
|
||||
|
||||
if (gemCount >= 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());
|
||||
|
@ -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<GemTransfer> _repository;
|
||||
|
||||
public TransferTracker()
|
||||
{
|
||||
_repository = new RedisDataRepository<GemTransfer>(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();
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import mineplex.game.clans.shop.building.BuildingPage;
|
||||
|
||||
public class BankPage extends ShopPageBase<ClansManager, BankShop>
|
||||
{
|
||||
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<ClansManager, BankShop>
|
||||
{
|
||||
buildTokenUnpurchasable();
|
||||
}
|
||||
|
||||
if (GoldManager.getInstance().canTransferGems(getPlayer()))
|
||||
{
|
||||
buildTransferGems();
|
||||
}
|
||||
else
|
||||
{
|
||||
buildTransferGemsCooldown();
|
||||
}
|
||||
}
|
||||
|
||||
private void buildCashIn()
|
||||
@ -59,6 +69,31 @@ public class BankPage extends ShopPageBase<ClansManager, BankShop>
|
||||
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()
|
||||
{
|
||||
int playerGold = getPlayerGold();
|
||||
@ -96,6 +131,11 @@ public class BankPage extends ShopPageBase<ClansManager, BankShop>
|
||||
return getPlayerGold() >= TOKEN_VALUE;
|
||||
}
|
||||
|
||||
private int getPlayerGems()
|
||||
{
|
||||
return GoldManager.getInstance().getGems(getPlayer());
|
||||
}
|
||||
|
||||
private int getPlayerGold()
|
||||
{
|
||||
return GoldManager.getInstance().getGold(getPlayer());
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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<ClansManager, FarmingShop>
|
||||
{
|
||||
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<FarmingPage>(this, item));
|
||||
}
|
||||
}
|
@ -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<ClansManager>
|
||||
{
|
||||
public FarmingShop(ClansManager plugin, CoreClientManager clientManager, mineplex.core.donation.DonationManager donationManager)
|
||||
{
|
||||
super(plugin, clientManager, donationManager, "Organic Produce");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ShopPageBase<ClansManager, ? extends ShopBase<ClansManager>> buildPagesFor(Player player)
|
||||
{
|
||||
return new FarmingPage(getPlugin(), this, getClientManager(), getDonationManager(), player);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user