Fix buying in bulk

This commit is contained in:
Sam 2018-07-18 13:29:01 +01:00 committed by Alexander Meech
parent e45deb127c
commit f29b855667
8 changed files with 31 additions and 23 deletions

View File

@ -24,7 +24,6 @@ public class CakeDeployPlatform extends CakeSpecialItem
public static final ItemStack ITEM_STACK = new ItemBuilder(Material.INK_SACK)
.setTitle(C.cYellowB + "Deploy Platform")
.addLore("", "Creates a platform of wool next to", "any block you click!", "Uses: " + C.cRed + "1")
.setUnbreakable(true)
.build();
private static final int PLATFORM_DELTA = 1;

View File

@ -28,7 +28,6 @@ public class CakeIceBridge extends CakeSpecialItem
public static final ItemStack ITEM_STACK = new ItemBuilder(Material.ICE)
.setTitle(C.cYellowB + "Ice Bridge")
.addLore("", "Creates a huge bridge of ice", "Warning! Ice Bridges have a", C.cRed + "20 second" + C.cGray + " cooldown between uses ", "and only last for " + C.cRed + "7 Seconds" + C.cGray + "!", "Uses: " + C.cRed + "1")
.setUnbreakable(true)
.build();
private static final int MAX_DISTANCE = 30;
private static final long BRIDGE_TIME = TimeUnit.SECONDS.toMillis(7);

View File

@ -35,7 +35,6 @@ public class CakeSafeTeleport extends CakeSpecialItem implements Listener
public static final ItemStack ITEM_STACK = new ItemBuilder(Material.EYE_OF_ENDER)
.setTitle(C.cYellowB + "Safe Teleport")
.addLore("", "Teleports you have to a safe location", "if you fall into the void.", "Warning! Safe Teleport has a", C.cRed + "20 second" + C.cGray + " cooldown between uses.", "Uses: " + C.cRed + "1")
.setUnbreakable(true)
.build();
private final Map<Player, Location> _safeLocations;

View File

@ -53,7 +53,6 @@ public class CakeSheep extends CakeSpecialItem implements Listener
"If she is killed she does not explode.",
"Warning! Polly has a", C.cRed + "20 second" + C.cGray + " cooldown between uses."
)
.setUnbreakable(true)
.build();
private static final long EXPLOSION_TIME = TimeUnit.SECONDS.toMillis(4);
private static final int EXPLOSION_RADIUS = 7;

View File

@ -32,7 +32,6 @@ public class CakeWall extends CakeSpecialItem
public static final ItemStack ITEM_STACK = new ItemBuilder(Material.STAINED_GLASS)
.setTitle(C.cYellowB + "Wool Wall")
.addLore("", "Creates a wall of wool above", "any block you click!", "Uses: " + C.cRed + "1")
.setUnbreakable(true)
.build();
private static final int PLATFORM_DELTA = 1;
private static final int WALL_WARMUP_TICKS = 40;

View File

@ -244,7 +244,7 @@ public class OPCakeWars extends CakeWars
{
if (resource == CakeResource.STAR)
{
return new CakeResourcePage(getArcadeManager(), getCakeShopModule().getShop(), player, 36, CakeResource.STAR, Collections.emptyList())
return new CakeResourcePage(getArcadeManager(), getCakeShopModule().getShop(), player, 27, CakeResource.STAR, Collections.emptyList())
{
@Override
protected void buildPage()

View File

@ -40,7 +40,7 @@ public class CakeResourcePage extends ShopPageBase<ArcadeManager, CakeResourceSh
final CakeResource _resource;
final List<CakeItem> _items;
final GameTeam _team;
int _multiplier;
private int _multiplier;
public CakeResourcePage(ArcadeManager plugin, CakeResourceShop shop, Player player, CakeResource resource, List<CakeItem> items)
{
@ -90,11 +90,16 @@ public class CakeResourcePage extends ShopPageBase<ArcadeManager, CakeResourceSh
private void buildMultiItem(int slot, Material material, int multiplier)
{
addButton(slot, new ItemBuilder(material)
.setTitle(C.cGray + "x" + C.cYellow + multiplier + C.cGray + " Multiplier")
.addLore("", "Click to set the item multiplier", ".")
.setTitle(C.cYellow + "x" + multiplier + C.cGold + " Multiplier")
.addLore("", "Click to set the item multiplier.", "Allows you to buy in bulk!")
.setGlow(_multiplier == multiplier)
.build(), (player, clickType) ->
{
if (!Recharge.Instance.use(player, "Change Multipler", 250, false, false))
{
return;
}
_multiplier = multiplier;
playAcceptSound(player);
refresh();
@ -161,14 +166,19 @@ public class CakeResourcePage extends ShopPageBase<ArcadeManager, CakeResourceSh
builder.setTitle(getItemName(itemStack));
builder.addLore("");
if (itemStack.getAmount() > 1)
if (shouldScale(item))
{
builder.setAmount(itemStack.getAmount() * _multiplier);
builder.addLore("Amount: " + _resource.getChatColor() + itemStack.getAmount());
int newAmount = itemStack.getAmount() * _multiplier;
builder.setAmount(newAmount);
if (_multiplier > 1)
{
builder.addLore("Amount: " + _resource.getChatColor() + newAmount);
}
}
builder.addLore(
"Cost: " + _resource.getChatColor() + (item.getCost() * _multiplier) + " " + _resource.getName() + "s",
"Cost: " + _resource.getChatColor() + getCost(item) + " " + _resource.getName() + "s",
"",
result.getColour() + result.getFeedback()
);
@ -206,7 +216,12 @@ public class CakeResourcePage extends ShopPageBase<ArcadeManager, CakeResourceSh
private int getCost(CakeItem item)
{
return item.getItemStack().getItemMeta().spigot().isUnbreakable() ? item.getCost() : item.getCost() * _multiplier
return shouldScale(item) ? item.getCost() * _multiplier : item.getCost();
}
private boolean shouldScale(CakeItem item)
{
return item.getItemStack().getType().getMaxDurability() == 0;
}
protected enum CakeShopResult
@ -272,19 +287,17 @@ public class CakeResourcePage extends ShopPageBase<ArcadeManager, CakeResourceSh
ItemStack resource = _resource.getItemStack();
ItemStack itemStack = _item.getItemStack();
ItemBuilder give = new ItemBuilder(itemStack);
Material material = give.getType();
if (itemStack.getAmount() > 1)
{
give.setAmount(_item.getItemStack().getAmount() * _multiplier);
}
if (UtilItem.isWeapon(material) || UtilItem.isTool(material) || UtilItem.isArmor(material) || material == Material.BOW || material == Material.SHEARS)
if (!shouldScale(_item))
{
give.setUnbreakable(true);
}
else
{
give.setAmount(itemStack.getAmount() * _multiplier);
}
UtilInv.remove(player, resource.getType(), resource.getData().getData(), _item.getCost() * _multiplier);
UtilInv.remove(player, resource.getType(), resource.getData().getData(), getCost(_item));
handleTeamColours(give);
ItemStack giveItem = give.build();

View File

@ -30,7 +30,7 @@ public class CakeResourceStarPage extends CakeResourcePage
public CakeResourceStarPage(ArcadeManager plugin, CakeResourceShop shop, Player player, List<CakeItem> items)
{
super(plugin, shop, player, 36, CakeResource.STAR, items);
super(plugin, shop, player, 27, CakeResource.STAR, items);
_cakeTeam = _game.getCakeTeamModule().getCakeTeam(_game.GetTeam(player));
}