Fix consumables

This commit is contained in:
Sam 2017-06-15 23:26:29 +01:00
parent fe17a42724
commit a12564c8a9
5 changed files with 39 additions and 60 deletions

View File

@ -207,11 +207,18 @@ public class HeroKit extends Kit
// Keep moving left from the ammo slot until a free slot is available
for (int i = AMMO_SLOT - 1; i >= GetPerks().length - 1; i--)
{
if (inventory.getItem(i) == null)
ItemStack consumable = inventory.getItem(i);
if (consumable == null)
{
inventory.setItem(i, itemstack);
break;
}
else if (consumable.isSimilar(itemstack))
{
consumable.setAmount(consumable.getAmount() + 1);
break;
}
}
}
}

View File

@ -206,7 +206,6 @@ public class MobaShop implements Listener
player.sendMessage(F.main("Game", "Purchased " + F.greenElem(item.getItem().getItemMeta().getDisplayName()) + "."));
_host.getGoldManager().removeGold(player, item.getCost());
owned.add(item);
category.purchase(player);
// The respawn event needs to be called here so that effects like "Total Health Increase" will work straight away, instead of after the next respawn,
// Prevents infinite speed
@ -506,6 +505,11 @@ public class MobaShop implements Listener
Player player = (Player) entity;
List<MobaItem> items = _upgrades.get(player);
if (items == null)
{
return;
}
for (MobaItem item : items)
{
if (item.getEffects() == null)

View File

@ -1,12 +1,8 @@
package nautilus.game.arcade.game.games.moba.shop;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class MobaShopCategory
{
@ -14,17 +10,16 @@ public class MobaShopCategory
private final String _name;
private final List<MobaItem> _items;
private final ItemStack _menuItem;
private final Map<UUID, Integer> _purchased;
private int _max;
private boolean _dropOnDeath;
private boolean _allowMultiple;
private boolean _trackPurchases;
public MobaShopCategory(String name, List<MobaItem> items, ItemStack menuItem)
{
_name = name;
_items = items;
_menuItem = menuItem;
_max = Integer.MAX_VALUE;
_purchased = new HashMap<>();
_trackPurchases = true;
}
public String getName()
@ -42,44 +37,6 @@ public class MobaShopCategory
return _menuItem;
}
public void purchase(Player player)
{
UUID key = player.getUniqueId();
if (!_purchased.containsKey(key))
{
_purchased.put(key, 1);
}
else
{
_purchased.put(key, _purchased.get(key) + 1);
}
}
public void onDeath(Player player)
{
if (isDroppingOnDeath())
{
_purchased.remove(player.getUniqueId());
}
}
public int getPurchased(Player player)
{
return _purchased.getOrDefault(player.getUniqueId(), 0);
}
public MobaShopCategory setMax(int max)
{
_max = max;
return this;
}
public int getMax()
{
return _max;
}
public MobaShopCategory dropOnDeath()
{
_dropOnDeath = true;
@ -91,8 +48,25 @@ public class MobaShopCategory
return _dropOnDeath;
}
public MobaShopCategory allowMultiple()
{
_allowMultiple = true;
return this;
}
public boolean isAllowingMultiple()
{
return _max < Integer.MAX_VALUE;
return _allowMultiple;
}
public MobaShopCategory dontTrackPurchases()
{
_trackPurchases = false;
return this;
}
public boolean isTrackingPurchases()
{
return _trackPurchases;
}
}

View File

@ -45,9 +45,8 @@ public class MobaShopCategoryMenu extends Menu<ArcadeManager>
for (MobaItem item : _category.getItems())
{
ItemBuilder builder = new ItemBuilder(item.getItem());
boolean owns = _shop.ownsItem(player, item);
boolean owns = _shop.ownsItem(player, item) && _category.isTrackingPurchases();
boolean canPurchase = _host.getGoldManager().hasGold(player, item.getCost());
boolean maxed = _category.getPurchased(player) == _category.getMax();
int gold = _host.getGoldManager().getGold(player);
builder.setTitle((canPurchase ? C.cGreen : C.cRed) + item.getItem().getItemMeta().getDisplayName());
@ -62,11 +61,7 @@ public class MobaShopCategoryMenu extends Menu<ArcadeManager>
{
builder.addLore(C.cWhite + "Cost: " + C.cGold + item.getCost(), C.cWhite + "Your Gold: " + C.cGold + gold, "");
if (maxed)
{
builder.addLore(C.cRed + "You have already purchased the maximum amount", C.cRed + "of upgrades from this category.");
}
else if (canPurchase)
if (canPurchase)
{
builder.addLore(C.cGreen + "Click to purchase.");
}
@ -103,11 +98,10 @@ public class MobaShopCategoryMenu extends Menu<ArcadeManager>
@Override
public void onClick(Player player, ClickType clickType)
{
boolean owns = _shop.ownsItem(player, _item);
boolean owns = _shop.ownsItem(player, _item) && _category.isTrackingPurchases();
boolean canPurchase = _host.getGoldManager().hasGold(player, _item.getCost());
boolean maxed = _category.getPurchased(player) == _category.getMax();
if (!owns && canPurchase && !maxed)
if (!owns && canPurchase)
{
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1, 1.6F);
_shop.purchaseItem(player, _item);

View File

@ -42,7 +42,7 @@ public class MobaShopMenu extends Menu<ArcadeManager>
new MobaItem(new ItemBuilder(Material.ENDER_PEARL)
.setTitle(C.cYellowB + "Ender Pearl")
.build(), 750)
), new ItemStack(Material.POTION)).dropOnDeath().setMax(3);
), new ItemStack(Material.POTION)).dropOnDeath().allowMultiple().dontTrackPurchases();
private static final int SLOTS = 27;
private final Moba _host;