Fix consumables
This commit is contained in:
parent
fe17a42724
commit
a12564c8a9
@ -207,11 +207,18 @@ public class HeroKit extends Kit
|
|||||||
// Keep moving left from the ammo slot until a free slot is available
|
// Keep moving left from the ammo slot until a free slot is available
|
||||||
for (int i = AMMO_SLOT - 1; i >= GetPerks().length - 1; i--)
|
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);
|
inventory.setItem(i, itemstack);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
else if (consumable.isSimilar(itemstack))
|
||||||
|
{
|
||||||
|
consumable.setAmount(consumable.getAmount() + 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -206,7 +206,6 @@ public class MobaShop implements Listener
|
|||||||
player.sendMessage(F.main("Game", "Purchased " + F.greenElem(item.getItem().getItemMeta().getDisplayName()) + "."));
|
player.sendMessage(F.main("Game", "Purchased " + F.greenElem(item.getItem().getItemMeta().getDisplayName()) + "."));
|
||||||
_host.getGoldManager().removeGold(player, item.getCost());
|
_host.getGoldManager().removeGold(player, item.getCost());
|
||||||
owned.add(item);
|
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,
|
// 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
|
// Prevents infinite speed
|
||||||
@ -506,6 +505,11 @@ public class MobaShop implements Listener
|
|||||||
Player player = (Player) entity;
|
Player player = (Player) entity;
|
||||||
List<MobaItem> items = _upgrades.get(player);
|
List<MobaItem> items = _upgrades.get(player);
|
||||||
|
|
||||||
|
if (items == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (MobaItem item : items)
|
for (MobaItem item : items)
|
||||||
{
|
{
|
||||||
if (item.getEffects() == null)
|
if (item.getEffects() == null)
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
package nautilus.game.arcade.game.games.moba.shop;
|
package nautilus.game.arcade.game.games.moba.shop;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class MobaShopCategory
|
public class MobaShopCategory
|
||||||
{
|
{
|
||||||
@ -14,17 +10,16 @@ public class MobaShopCategory
|
|||||||
private final String _name;
|
private final String _name;
|
||||||
private final List<MobaItem> _items;
|
private final List<MobaItem> _items;
|
||||||
private final ItemStack _menuItem;
|
private final ItemStack _menuItem;
|
||||||
private final Map<UUID, Integer> _purchased;
|
|
||||||
private int _max;
|
|
||||||
private boolean _dropOnDeath;
|
private boolean _dropOnDeath;
|
||||||
|
private boolean _allowMultiple;
|
||||||
|
private boolean _trackPurchases;
|
||||||
|
|
||||||
public MobaShopCategory(String name, List<MobaItem> items, ItemStack menuItem)
|
public MobaShopCategory(String name, List<MobaItem> items, ItemStack menuItem)
|
||||||
{
|
{
|
||||||
_name = name;
|
_name = name;
|
||||||
_items = items;
|
_items = items;
|
||||||
_menuItem = menuItem;
|
_menuItem = menuItem;
|
||||||
_max = Integer.MAX_VALUE;
|
_trackPurchases = true;
|
||||||
_purchased = new HashMap<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName()
|
public String getName()
|
||||||
@ -42,44 +37,6 @@ public class MobaShopCategory
|
|||||||
return _menuItem;
|
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()
|
public MobaShopCategory dropOnDeath()
|
||||||
{
|
{
|
||||||
_dropOnDeath = true;
|
_dropOnDeath = true;
|
||||||
@ -91,8 +48,25 @@ public class MobaShopCategory
|
|||||||
return _dropOnDeath;
|
return _dropOnDeath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MobaShopCategory allowMultiple()
|
||||||
|
{
|
||||||
|
_allowMultiple = true;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isAllowingMultiple()
|
public boolean isAllowingMultiple()
|
||||||
{
|
{
|
||||||
return _max < Integer.MAX_VALUE;
|
return _allowMultiple;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MobaShopCategory dontTrackPurchases()
|
||||||
|
{
|
||||||
|
_trackPurchases = false;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isTrackingPurchases()
|
||||||
|
{
|
||||||
|
return _trackPurchases;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,9 +45,8 @@ public class MobaShopCategoryMenu extends Menu<ArcadeManager>
|
|||||||
for (MobaItem item : _category.getItems())
|
for (MobaItem item : _category.getItems())
|
||||||
{
|
{
|
||||||
ItemBuilder builder = new ItemBuilder(item.getItem());
|
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 canPurchase = _host.getGoldManager().hasGold(player, item.getCost());
|
||||||
boolean maxed = _category.getPurchased(player) == _category.getMax();
|
|
||||||
int gold = _host.getGoldManager().getGold(player);
|
int gold = _host.getGoldManager().getGold(player);
|
||||||
|
|
||||||
builder.setTitle((canPurchase ? C.cGreen : C.cRed) + item.getItem().getItemMeta().getDisplayName());
|
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, "");
|
builder.addLore(C.cWhite + "Cost: " + C.cGold + item.getCost(), C.cWhite + "Your Gold: " + C.cGold + gold, "");
|
||||||
|
|
||||||
if (maxed)
|
if (canPurchase)
|
||||||
{
|
|
||||||
builder.addLore(C.cRed + "You have already purchased the maximum amount", C.cRed + "of upgrades from this category.");
|
|
||||||
}
|
|
||||||
else if (canPurchase)
|
|
||||||
{
|
{
|
||||||
builder.addLore(C.cGreen + "Click to purchase.");
|
builder.addLore(C.cGreen + "Click to purchase.");
|
||||||
}
|
}
|
||||||
@ -103,11 +98,10 @@ public class MobaShopCategoryMenu extends Menu<ArcadeManager>
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(Player player, ClickType clickType)
|
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 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);
|
player.playSound(player.getLocation(), Sound.NOTE_PLING, 1, 1.6F);
|
||||||
_shop.purchaseItem(player, _item);
|
_shop.purchaseItem(player, _item);
|
||||||
|
@ -42,7 +42,7 @@ public class MobaShopMenu extends Menu<ArcadeManager>
|
|||||||
new MobaItem(new ItemBuilder(Material.ENDER_PEARL)
|
new MobaItem(new ItemBuilder(Material.ENDER_PEARL)
|
||||||
.setTitle(C.cYellowB + "Ender Pearl")
|
.setTitle(C.cYellowB + "Ender Pearl")
|
||||||
.build(), 750)
|
.build(), 750)
|
||||||
), new ItemStack(Material.POTION)).dropOnDeath().setMax(3);
|
), new ItemStack(Material.POTION)).dropOnDeath().allowMultiple().dontTrackPurchases();
|
||||||
private static final int SLOTS = 27;
|
private static final int SLOTS = 27;
|
||||||
|
|
||||||
private final Moba _host;
|
private final Moba _host;
|
||||||
|
Loading…
Reference in New Issue
Block a user