Remove the previous upgrade when switching upgrades
This commit is contained in:
parent
d107c8d6f4
commit
50da713947
@ -13,6 +13,7 @@ import nautilus.game.arcade.game.games.moba.structure.point.CapturePoint;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@ -74,6 +75,12 @@ public class GoldManager implements Listener
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void playerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
_playerGold.remove(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void passiveGain(UpdateEvent event)
|
||||
{
|
||||
@ -105,6 +112,11 @@ public class GoldManager implements Listener
|
||||
}
|
||||
}
|
||||
|
||||
public int getGold(Player player)
|
||||
{
|
||||
return _playerGold.get(player);
|
||||
}
|
||||
|
||||
public void addGold(Player player, int amount)
|
||||
{
|
||||
_playerGold.put(player, _playerGold.get(player) + amount);
|
||||
|
@ -2,30 +2,22 @@ package nautilus.game.arcade.game.games.moba.kit;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilItem;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import mineplex.core.recharge.Recharge;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import nautilus.game.arcade.ArcadeManager;
|
||||
import nautilus.game.arcade.game.games.moba.Moba;
|
||||
import nautilus.game.arcade.game.games.moba.MobaRole;
|
||||
import nautilus.game.arcade.game.games.moba.kit.common.SkillBow;
|
||||
import nautilus.game.arcade.game.games.moba.kit.common.SkillSword;
|
||||
import nautilus.game.arcade.game.games.moba.shop.MobaItem;
|
||||
import nautilus.game.arcade.kit.Kit;
|
||||
import nautilus.game.arcade.kit.KitAvailability;
|
||||
import nautilus.game.arcade.kit.Perk;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class HeroKit extends Kit
|
||||
{
|
||||
|
||||
@ -147,10 +139,7 @@ public class HeroKit extends Kit
|
||||
inventory.setItem(AMMO_SLOT, _ammo);
|
||||
inventory.setItem(RECALL_SLOT, RECALL_ITEM);
|
||||
|
||||
Moba host = (Moba) Manager.GetGame();
|
||||
List<MobaItem> ownedItems = host.getShop().getOwnedItems(player);
|
||||
|
||||
perkLoop: for (Perk perk : GetPerks())
|
||||
for (Perk perk : GetPerks())
|
||||
{
|
||||
if (!(perk instanceof HeroSkill))
|
||||
{
|
||||
@ -159,31 +148,6 @@ public class HeroKit extends Kit
|
||||
|
||||
HeroSkill skill = (HeroSkill) perk;
|
||||
|
||||
// Sword upgrades
|
||||
if (skill instanceof SkillSword)
|
||||
{
|
||||
for (MobaItem item : ownedItems)
|
||||
{
|
||||
if (UtilItem.isSword(item.getItem()))
|
||||
{
|
||||
player.getInventory().setItem(skill.getSlot(), item.getItem());
|
||||
continue perkLoop;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Bow upgrades
|
||||
else if (skill instanceof SkillBow)
|
||||
{
|
||||
for (MobaItem item : ownedItems)
|
||||
{
|
||||
if (item.getItem().getType() == Material.BOW)
|
||||
{
|
||||
player.getInventory().setItem(skill.getSlot(), item.getItem());
|
||||
continue perkLoop;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (skill.isOnCooldown(player))
|
||||
{
|
||||
player.getInventory().setItem(skill.getSlot(), skill.getCooldownItem());
|
||||
|
@ -1,9 +1,14 @@
|
||||
package nautilus.game.arcade.game.games.moba.kit.common;
|
||||
|
||||
import nautilus.game.arcade.game.games.moba.Moba;
|
||||
import nautilus.game.arcade.game.games.moba.kit.HeroSkill;
|
||||
import nautilus.game.arcade.game.games.moba.shop.MobaItem;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SkillBow extends HeroSkill
|
||||
{
|
||||
|
||||
@ -17,4 +22,22 @@ public class SkillBow extends HeroSkill
|
||||
{
|
||||
super("Bow", DESCRIPTION, SKILL_ITEM, slot, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveItem(Player player)
|
||||
{
|
||||
Moba host = (Moba) Manager.GetGame();
|
||||
List<MobaItem> ownedItems = host.getShop().getOwnedItems(player);
|
||||
|
||||
for (MobaItem item : ownedItems)
|
||||
{
|
||||
if (item.getItem().getType() == Material.BOW)
|
||||
{
|
||||
player.getInventory().setItem(getSlot(), item.getItem());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
player.getInventory().setItem(getSlot(), SKILL_ITEM);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,18 @@
|
||||
package nautilus.game.arcade.game.games.moba.kit.common;
|
||||
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.UtilItem;
|
||||
import mineplex.core.itemstack.ItemBuilder;
|
||||
import nautilus.game.arcade.game.games.moba.Moba;
|
||||
import nautilus.game.arcade.game.games.moba.kit.HeroSkill;
|
||||
import nautilus.game.arcade.game.games.moba.shop.MobaItem;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SkillSword extends HeroSkill
|
||||
{
|
||||
|
||||
@ -23,4 +29,22 @@ public class SkillSword extends HeroSkill
|
||||
{
|
||||
super("Sword", DESCRIPTION, SKILL_ITEM, slot, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void giveItem(Player player)
|
||||
{
|
||||
Moba host = (Moba) Manager.GetGame();
|
||||
List<MobaItem> ownedItems = host.getShop().getOwnedItems(player);
|
||||
|
||||
for (MobaItem item : ownedItems)
|
||||
{
|
||||
if (UtilItem.isSword(item.getItem()))
|
||||
{
|
||||
player.getInventory().setItem(getSlot(), item.getItem());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
player.getInventory().setItem(getSlot(), SKILL_ITEM);
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,18 @@
|
||||
package nautilus.game.arcade.game.games.moba.shop;
|
||||
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.*;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.minecraft.game.core.combat.CombatComponent;
|
||||
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
|
||||
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
|
||||
import nautilus.game.arcade.events.GameStateChangeEvent;
|
||||
import nautilus.game.arcade.game.DebugCommand;
|
||||
import nautilus.game.arcade.game.Game.GameState;
|
||||
import nautilus.game.arcade.game.games.moba.Moba;
|
||||
import nautilus.game.arcade.game.games.moba.MobaPlayer;
|
||||
import nautilus.game.arcade.game.games.moba.MobaRole;
|
||||
import nautilus.game.arcade.game.games.moba.kit.CooldownCalculateEvent;
|
||||
import nautilus.game.arcade.game.games.moba.shop.MobaShopMenu.MobaCategoryButton;
|
||||
import nautilus.game.arcade.game.games.moba.shop.assassin.MobaAssassinShop;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.v1_8_R3.entity.CraftLivingEntity;
|
||||
@ -22,6 +22,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Villager;
|
||||
import org.bukkit.entity.Villager.Profession;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
@ -109,16 +110,14 @@ public class MobaShop implements Listener
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void npcDamage(EntityDamageEvent event)
|
||||
public void npcDamage(CustomDamageEvent event)
|
||||
{
|
||||
for (Entry<LivingEntity, Location> entry : _entities.entrySet())
|
||||
for (LivingEntity entity : _entities.keySet())
|
||||
{
|
||||
LivingEntity entity = entry.getKey();
|
||||
|
||||
if (entity.equals(event.getEntity()))
|
||||
if (entity.equals(event.GetDamageeEntity()))
|
||||
{
|
||||
entity.setFireTicks(0);
|
||||
event.setCancelled(true);
|
||||
event.SetCancelled("Shop NPC");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -165,9 +164,18 @@ public class MobaShop implements Listener
|
||||
|
||||
public void purchaseItem(Player player, MobaItem item)
|
||||
{
|
||||
List<MobaItem> owned = _upgrades.get(player);
|
||||
MobaShopCategory category = getCategory(item);
|
||||
|
||||
if (!category.isAllowingMultiple())
|
||||
{
|
||||
owned.removeIf(previousItem -> getCategory(previousItem) == category);
|
||||
}
|
||||
|
||||
player.sendMessage(F.main("Game", "Purchased " + F.greenElem(item.getItem().getItemMeta().getDisplayName()) + "."));
|
||||
_host.getGoldManager().removeGold(player, item.getCost());
|
||||
_upgrades.get(player).add(item);
|
||||
owned.add(item);
|
||||
_host.GetKit(player).ApplyKit(player);
|
||||
}
|
||||
|
||||
public boolean ownsItem(Player player, MobaItem item)
|
||||
@ -180,6 +188,22 @@ public class MobaShop implements Listener
|
||||
return _upgrades.get(player);
|
||||
}
|
||||
|
||||
private MobaShopCategory getCategory(MobaItem item)
|
||||
{
|
||||
for (MobaShopMenu menu : _roleMenus.values())
|
||||
{
|
||||
for (MobaShopCategory category : menu.getCategories())
|
||||
{
|
||||
if (category.getItems().contains(item))
|
||||
{
|
||||
return category;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
Handle MobaItem events
|
||||
*/
|
||||
|
@ -41,20 +41,22 @@ public class MobaShopCategoryMenu extends Menu<ArcadeManager>
|
||||
ItemBuilder builder = new ItemBuilder(item.getItem());
|
||||
boolean owns = _shop.ownsItem(player, item);
|
||||
boolean canPurchase = _host.getGoldManager().hasGold(player, item.getCost());
|
||||
int gold = _host.getGoldManager().getGold(player);
|
||||
|
||||
builder.setTitle((canPurchase ? C.cGreen : C.cRed) + item.getItem().getItemMeta().getDisplayName());
|
||||
builder.addLore("");
|
||||
|
||||
if (owns)
|
||||
{
|
||||
builder.addLore(C.cRed + "You already have purchased this upgrade");
|
||||
builder.addLore(C.cRed + "You already have purchased this upgrade.");
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.addLore("Cost: " + C.cGold + item.getCost());
|
||||
builder.addLore(C.cWhite + "Cost: " + C.cGold + item.getCost(), C.cWhite + "Your Gold: " + C.cGold + gold, "");
|
||||
|
||||
if (canPurchase)
|
||||
{
|
||||
builder.addLore(C.cGreen + "Click to purchase");
|
||||
builder.addLore(C.cGreen + "Click to purchase.");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -121,4 +121,9 @@ public class MobaShopMenu extends Menu<ArcadeManager>
|
||||
new MobaShopCategoryMenu(_host, _shop, _category, getPlugin()).open(player);
|
||||
}
|
||||
}
|
||||
|
||||
public List<MobaShopCategory> getCategories()
|
||||
{
|
||||
return _categories;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user