From d232bab051783c93c331aa29185f66e28864e5c8 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sun, 28 Dec 2014 18:35:49 +1300 Subject: [PATCH] Wizards Game Progress. Now workable --- .../src/nautilus/game/arcade/GameFactory.java | 2 + .../game/games/wizards/ElementButton.java | 28 ++ .../arcade/game/games/wizards/KitWizard.java | 40 +++ .../game/arcade/game/games/wizards/Spell.java | 4 +- .../game/games/wizards/SpellButton.java | 37 +++ .../game/games/wizards/SpellMenuPage.java | 72 +++++ .../arcade/game/games/wizards/Spells.java | 150 ++++++++--- .../game/games/wizards/WizardBattles.java | 254 ++++++++++-------- .../game/games/wizards/WizardSpellMenu.java | 47 ++++ .../games/wizards/WizardSpellMenuShop.java | 37 +++ .../game/games/wizards/spells/DumbSpell.java | 1 + 11 files changed, 518 insertions(+), 154 deletions(-) create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/ElementButton.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/KitWizard.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/SpellButton.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/SpellMenuPage.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/WizardSpellMenu.java create mode 100644 Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/WizardSpellMenuShop.java diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameFactory.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameFactory.java index ea33ee5b9..de7f9c3df 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameFactory.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/GameFactory.java @@ -50,6 +50,7 @@ import nautilus.game.arcade.game.games.tug.Tug; import nautilus.game.arcade.game.games.turfforts.TurfForts; import nautilus.game.arcade.game.games.uhc.UHC; import nautilus.game.arcade.game.games.wither.WitherGame; +import nautilus.game.arcade.game.games.wizards.WizardBattles; import nautilus.game.arcade.game.games.zombiesurvival.ZombieSurvival; public class GameFactory @@ -107,6 +108,7 @@ public class GameFactory else if (gameType == GameType.TurfWars) return new TurfForts(_manager); else if (gameType == GameType.UHC) return new UHC(_manager); else if (gameType == GameType.WitherAssault) return new WitherGame(_manager); + else if (gameType == GameType.WizardBattles) return new WizardBattles(_manager); else if (gameType == GameType.ZombieSurvival) return new ZombieSurvival(_manager); else return null; } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/ElementButton.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/ElementButton.java new file mode 100644 index 000000000..569194bec --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/ElementButton.java @@ -0,0 +1,28 @@ +package nautilus.game.arcade.game.games.wizards; + +import nautilus.game.arcade.game.games.wizards.Spells.SpellElement; + +import org.bukkit.entity.Player; + +import mineplex.core.shop.item.SingleButton; + +public class ElementButton extends SingleButton +{ + + private SpellElement element; + private SpellMenuPage spellPage; + + public ElementButton(SpellMenuPage spellPage, SpellElement element) + { + this.element = element; + this.spellPage = spellPage; + } + + @Override + public void Clicked(Player player) + { + spellPage.getWizards().getWizard(player).selectedPage = element; + spellPage.BuildPage(); + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/KitWizard.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/KitWizard.java new file mode 100644 index 000000000..f2eb8e8b6 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/KitWizard.java @@ -0,0 +1,40 @@ +package nautilus.game.arcade.game.games.wizards; + +import mineplex.core.itemstack.ItemBuilder; +import nautilus.game.arcade.ArcadeManager; +import nautilus.game.arcade.kit.Kit; +import nautilus.game.arcade.kit.KitAvailability; +import nautilus.game.arcade.kit.Perk; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class KitWizard extends Kit +{ + public KitWizard(ArcadeManager manager) + { + super(manager, "Wizard", KitAvailability.Free, new String[] + { + "The basic kit all wizards start with" + }, new Perk[0], EntityType.WITCH, new ItemStack(Material.BLAZE_ROD)); + } + + @Override + public void GiveItems(Player player) + { + for (int i = 0; i < 4; i++) + { + ItemBuilder builder = new ItemBuilder(Material.BLAZE_ROD); + String s = ""; + for (char c : ("" + System.nanoTime()).toCharArray()) + { + s += "§" + c; + } + builder.setTitle(ChatColor.WHITE + "Unused Wand" + s); + player.getInventory().addItem(builder.build()); + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/Spell.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/Spell.java index 8feb604e5..3d50e9108 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/Spell.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/Spell.java @@ -30,9 +30,9 @@ public abstract class Spell implements Listener */ public void charge(Player player) { - WizardBattles.Wizard wizard = wizards.wizards.get(player.getName()); + WizardBattles.Wizard wizard = wizards.getWizard(player); wizard.mana -= spell.getManaCost(wizard.knownSpells.get(spell)); - wizard.cooldowns.put(spell, spell.getSpellCooldown(wizard.knownSpells.get(spell))); + wizard.cooldowns.put(spell, System.currentTimeMillis() + (1000L * spell.getSpellCooldown(wizard.knownSpells.get(spell)))); wizards.displayBossbar(player); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/SpellButton.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/SpellButton.java new file mode 100644 index 000000000..ff24113b3 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/SpellButton.java @@ -0,0 +1,37 @@ +package nautilus.game.arcade.game.games.wizards; + +import mineplex.core.common.util.C; +import mineplex.core.shop.item.SingleButton; +import nautilus.game.arcade.game.games.wizards.Spells.SpellElement; + +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class SpellButton extends SingleButton +{ + + private Spells spell; + private SpellMenuPage spellPage; + + public SpellButton(SpellMenuPage spellPage, Spells spell) + { + this.spell = spell; + this.spellPage = spellPage; + } + + @Override + public void Clicked(Player player) + { + ItemStack item = player.getItemInHand(); + if (item != null && item.getType() == Material.BLAZE_ROD) + { + item = spell.makeSpell(spellPage.getWizards(), item); + player.setItemInHand(item); + player.sendMessage(C.cBlue + "Set spell on wand to " + spell.getElement().getColor() + spell.getSpellName()); + player.playSound(player.getLocation(), Sound.ORB_PICKUP, 10, 1); + } + } + +} \ No newline at end of file diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/SpellMenuPage.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/SpellMenuPage.java new file mode 100644 index 000000000..be316aac6 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/SpellMenuPage.java @@ -0,0 +1,72 @@ +package nautilus.game.arcade.game.games.wizards; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.donation.DonationManager; +import mineplex.core.itemstack.ItemBuilder; +import mineplex.core.shop.item.ShopItem; +import mineplex.core.shop.page.ShopPageBase; +import nautilus.game.arcade.game.games.wizards.Spells.SpellElement; +import nautilus.game.arcade.game.games.wizards.WizardBattles.Wizard; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class SpellMenuPage extends ShopPageBase +{ + private WizardBattles _wizard; + + public SpellMenuPage(WizardSpellMenu plugin, WizardSpellMenuShop shop, CoreClientManager clientManager, + DonationManager donationManager, Player player, WizardBattles wizard) + { + super(plugin, shop, clientManager, donationManager, "Spell Menu", player); + _wizard = wizard; + BuildPage(); + } + + @Override + protected void BuildPage() + { + Wizard wizard = getWizards().getWizard(Player); + for (int i = 0; i < SpellElement.values().length; i++) + { + SpellElement ele = SpellElement.values()[i]; + AddButton(i, new ShopItem(ele.getIcon(), ele.name(), ele.name(), 1, true, true), new ElementButton(this, ele)); + } + + for (int i = 9; i < 54; i++) + { + Spells spell = null; + for (Spells spells : Spells.values()) + { + if (spells.getElement() == wizard.selectedPage && spells.getSlot() == i) + { + spell = spells; + break; + } + } + if (spell == null) + { + RemoveButton(i); + } + else + { + if (wizard.knownSpells.containsKey(spell)) + AddButton(i, new ShopItem(spell.getSpellItem(), spell.name(), spell.name(), 1, true, true), new SpellButton( + this, spell)); + else + { + AddItem(i, + new ShopItem(new ItemBuilder(Material.THIN_GLASS, 1, (byte) 7).setTitle( + ChatColor.RED + "Unknown Spell").build(), "Unknown Spell", "Unknown Spell", 1, true, true)); + } + } + } + } + + public WizardBattles getWizards() + { + return _wizard; + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/Spells.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/Spells.java index 589646744..af2415e42 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/Spells.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/Spells.java @@ -1,5 +1,9 @@ package nautilus.game.arcade.game.games.wizards; +import java.util.HashMap; +import java.util.Random; + +import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -11,25 +15,34 @@ import nautilus.game.arcade.game.games.wizards.spells.*; public enum Spells { - DUMB_SPELL(SpellElement.ATTACK, "Dumb spell", new ItemStack(Material.STONE), DumbSpell.class, 10, 10); - private Class spellClass; - private String spellName; - private int spellCooldown; - private int spellCost; - private SpellElement type; - private String[] desc; - private ItemStack item; - - private enum SpellElement + DUMB_SPELL(SpellElement.ATTACK, "Dumb spell", new ItemStack(Material.STONE), DumbSpell.class, 3, 10, 10, 1, 1, 3, + "A dumb spell that shouldn't be in the final release as this is just for testing"); + enum SpellElement { - ATTACK(C.cRed), DEFENSE(C.cGray), HEAL(C.cGreen); - String chatColor; + ATTACK(new ItemBuilder(Material.IRON_SWORD).setTitle(ChatColor.RED + "Attack Spells").build(), C.cRed), - private SpellElement(String color) + DEFENSE(new ItemBuilder(Material.IRON_CHESTPLATE).setTitle(ChatColor.GRAY + "Defense Spells").build(), C.cGray), + + HEAL(new ItemBuilder(Material.IRON_BOOTS).setTitle(ChatColor.GREEN + "Buff Spells").build(), C.cGreen); + private String chatColor; + private ItemStack icon; + + private SpellElement(ItemStack icon, String color) { + this.icon = icon; this.chatColor = color; } + public String getColor() + { + return chatColor; + } + + public ItemStack getIcon() + { + return icon; + } + @Override public String toString() { @@ -37,23 +50,6 @@ public enum Spells } } - private Spells(SpellElement type, String spellName, ItemStack spellItem, Class spell, int spellCost, - int spellCooldown, String... desc) - { - this.item = spellItem; - this.desc = desc; - this.type = type; - this.spellClass = spell; - this.spellName = spellName; - this.spellCost = spellCost; - this.spellCooldown = spellCooldown; - } - - public String getSpellName() - { - return spellName; - } - public static Spells getSpell(String spellName) { for (Spells spell : values()) @@ -66,12 +62,56 @@ public enum Spells return null; } - public ItemStack getSpellBook(WizardBattles wizards) + private String[] desc; + private HashMap elements = new HashMap(); + private ItemStack item; + private int slot; + private Class spellClass; + private int spellCooldown; + private int spellCost; + private String spellName; + private SpellElement type; + private int _manaChangePerLevel; + private int _cooldownChangePerLevel; + private int chanceInWhat; + private int maxLevel; + + public int getMaxLevel() { - ItemBuilder builder = new ItemBuilder(Material.ENCHANTED_BOOK); - builder.setTitle(C.cDBlue + C.Bold + "Spell: " + type.chatColor + this.getSpellName()); - builder.addLore(desc); - return wizards.setNonStack(builder.build()); + return maxLevel; + } + + public boolean hasChanceToFind() + { + return chanceInWhat <= 0 || new Random().nextInt(chanceInWhat) == 0; + } + + private Spells(SpellElement type, String spellName, ItemStack spellItem, Class spell, int maxLevel, + int spellCost, int spellCooldown, int manaChangePerLevel, int cooldownChangePerLevel, int oneChanceInWhatToFind, + String... desc) + { + this.maxLevel = maxLevel; + this.item = new ItemBuilder(spellItem).setTitle(ChatColor.LIGHT_PURPLE + "Spell: " + type.getColor() + spellName) + .addLores(desc, 40).build(); + this.desc = desc; + this.type = type; + this.spellClass = spell; + this.spellName = spellName; + this.spellCost = spellCost; + this.spellCooldown = spellCooldown; + this._cooldownChangePerLevel = cooldownChangePerLevel; + this._manaChangePerLevel = manaChangePerLevel; + if (!elements.containsKey(type)) + { + elements.put(type, 9); + } + slot = elements.get(type); + elements.put(type, slot + 1); + } + + public String[] getDesc() + { + return desc; } public SpellElement getElement() @@ -79,24 +119,46 @@ public enum Spells return this.type; } - /** - * TODO Make it cost less as you levelup - **/ public int getManaCost(int level) { - return this.spellCost; + return Math.max(0, (_manaChangePerLevel * level) + this.spellCost); } - /** - * TODO Make it cost less as you levelup - **/ - public int getSpellCooldown(int level) + public int getSlot() { - return this.spellCooldown; + return slot; } public Class getSpellClass() { return spellClass; } + + public int getSpellCooldown(int level) + { + return Math.max(0, (_cooldownChangePerLevel * level) + this.spellCooldown); + } + + public ItemStack getSpellItem() + { + return item; + } + + public String getSpellName() + { + return spellName; + } + + public ItemStack makeSpell(WizardBattles wizards, ItemStack item) + { + ItemBuilder builder = new ItemBuilder(item); + String s = ""; + for (char c : ("" + System.nanoTime()).toCharArray()) + { + s += "§" + c; + } + + builder.setTitle(C.cDBlue + C.Bold + "Spell: " + type.chatColor + this.getSpellName() + s); + return builder.build(); + } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/WizardBattles.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/WizardBattles.java index ee4c00384..ef4f82027 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/WizardBattles.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/WizardBattles.java @@ -1,6 +1,6 @@ package nautilus.game.arcade.game.games.wizards; -import java.util.HashMap; +import java.util.ArrayList; import java.util.Iterator; import java.util.Map.Entry; import java.util.Random; @@ -12,23 +12,22 @@ import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.block.BlockState; +import org.bukkit.block.Chest; +import org.bukkit.block.DoubleChest; import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerItemHeldEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; - import mineplex.core.common.util.C; import mineplex.core.common.util.NautHashMap; -import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilTextTop; import mineplex.core.common.util.UtilTime; import mineplex.core.common.util.UtilTime.TimeUnit; @@ -42,62 +41,65 @@ import nautilus.game.arcade.game.SoloGame; import nautilus.game.arcade.game.games.wizards.Spell.SpellRightClick; import nautilus.game.arcade.game.games.wizards.Spell.SpellRightClickBlock; import nautilus.game.arcade.game.games.wizards.Spell.SpellRightClickEntity; +import nautilus.game.arcade.game.games.wizards.Spells.SpellElement; import nautilus.game.arcade.kit.Kit; -import nautilus.game.arcade.kit.KitAvailability; -import nautilus.game.arcade.kit.Perk; public class WizardBattles extends SoloGame { - private int code = 1000; class Wizard { float manaPerSecond = 2.5F; float mana; NautHashMap knownSpells = new NautHashMap(); - NautHashMap cooldowns = new NautHashMap(); + NautHashMap cooldowns = new NautHashMap(); + SpellElement selectedPage = SpellElement.ATTACK; } - NautHashMap wizards = new NautHashMap(); + private NautHashMap wizards = new NautHashMap(); private NautHashMap spells = new NautHashMap(); + private WizardSpellMenu _wizard; - public WizardBattles(ArcadeManager manager, GameType gameType, Kit[] kits, String[] gameDesc) + public WizardBattles(ArcadeManager manager) { - super(manager, GameType.WizardBattles, new Kit[] - { - new Kit(manager, "Wizard", KitAvailability.Free, new String[] - { - "The basic kit all wizards start with" - }, new Perk[0], EntityType.WITCH, new ItemStack(Material.BLAZE_ROD)) - { - private int code; - - @Override - public void GiveItems(Player player) - { - for (int i = 0; i < 4; i++) - { - ItemBuilder item = new ItemBuilder(Material.BLAZE_ROD); - String s = "" + code++; - for (char c : ("" + code).toCharArray()) - { - s += ChatColor.COLOR_CHAR + c; - } - item.setTitle((item.getType() == Material.BLAZE_ROD ? C.cWhite + "Unused Wand" : "Unknown Item") + s); - player.getInventory().addItem(item.build()); - } - } - } - }, new String[] + super(manager, GameType.WizardBattles, new Kit[0], new String[] { "Wizard Battles" }); + setKits(new Kit[] + { + new KitWizard(manager) + }); + this._wizard = new WizardSpellMenu("Wizard Spell Menu", this.getArcadeManager().GetPlugin(), this); + BlockBreak = true; + BlockPlace = true; + ItemPickup = true; + ItemDrop = true; + InventoryOpenBlock = true; + InventoryOpenChest = true; + InventoryClick = true; + DeathDropItems = true; + QuitDropItems = true; + WorldBlockBurn = true; + RepairWeapons = false; + DisableKillCommand = false; + SoupEnabled = false; + AllowParticles = false; + } + + @EventHandler + public void onGameEnd(GameStateChangeEvent event) + { + if (event.GetState() == GameState.End || event.GetState() == GameState.Dead) + { + HandlerList.unregisterAll(_wizard); + } } @EventHandler public void onSecond(UpdateEvent event) { - if ((event.getType() == UpdateType.FASTEST || event.getType() == UpdateType.SEC) && GetState() == GameState.Live) + if ((event.getType() == UpdateType.TICK || event.getType() == UpdateType.SEC) && GetState() == GameState.Live) { Iterator> itel = wizards.entrySet().iterator(); while (itel.hasNext()) @@ -114,15 +116,11 @@ public class WizardBattles extends SoloGame } Wizard wizard = wizards.get(player.getName()); wizard.mana += wizard.manaPerSecond; - Iterator> itel2 = wizard.cooldowns.entrySet().iterator(); + Iterator> itel2 = wizard.cooldowns.entrySet().iterator(); while (itel2.hasNext()) { - Entry entry2 = itel2.next(); - if (entry2.getValue() > 1) - { - wizard.cooldowns.put(entry2.getKey(), entry2.getValue() - 1); - } - else + Entry entry2 = itel2.next(); + if (entry2.getValue() <= System.currentTimeMillis()) { itel2.remove(); } @@ -150,34 +148,39 @@ public class WizardBattles extends SoloGame if (item != null && item.getType() == Material.BLAZE_ROD && item.getItemMeta().hasDisplayName()) { Spells type = this.getSpell(item.getItemMeta().getDisplayName()); - Wizard wizard = wizards.get(player.getName()); - int spellLevel = wizard.knownSpells.get(type); + if (type != null) + { + Wizard wizard = wizards.get(player.getName()); + int spellLevel = wizard.knownSpells.get(type); - String display = ChatColor.DARK_PURPLE + "Spell: " + ChatColor.RESET + type.getElement() + type.getSpellName() - + ChatColor.RESET + ChatColor.BOLD + " :" + ChatColor.RESET + ChatColor.DARK_AQUA + " Mana: " - + ChatColor.RESET + type.getManaCost(spellLevel) + ChatColor.RESET + ChatColor.BOLD + " :"; - double usableTime = 0;// Time in seconds till usable - if (wizard.mana < type.getManaCost(spellLevel)) - { - usableTime = (type.getManaCost(spellLevel) - wizard.mana) / wizard.manaPerSecond; + String display = ChatColor.DARK_PURPLE + "Spell: " + ChatColor.RESET + type.getElement().getColor() + + type.getSpellName() + ChatColor.RESET + ChatColor.BOLD + " :" + ChatColor.RESET + ChatColor.DARK_AQUA + + " Mana: " + ChatColor.RESET + type.getManaCost(spellLevel) + ChatColor.RESET + ChatColor.BOLD + " :"; + double usableTime = 0;// Time in seconds till usable + if (wizard.mana < type.getManaCost(spellLevel)) + { + usableTime = (type.getManaCost(spellLevel) - wizard.mana) / wizard.manaPerSecond; + } + double cooldown = wizard.cooldowns.containsKey(type) ? (double) (wizard.cooldowns.get(type) - System + .currentTimeMillis()) / 1000D : 0; + if (cooldown > 0 && cooldown > usableTime) + { + usableTime = cooldown; + } + if (usableTime > 0) + { + display += ChatColor.RED + " Usable in " + + UtilTime.convertString((long) (usableTime * 1000), 1, TimeUnit.FIT); + } + else + { + display += ChatColor.RED + " Cooldown: " + ChatColor.RESET + + UtilTime.convertString((long) (type.getSpellCooldown(spellLevel) * 1000), 0, TimeUnit.FIT); + } + double maxSeconds = Math.max(type.getSpellCooldown(spellLevel), type.getManaCost(spellLevel) + / wizard.manaPerSecond); + UtilTextTop.displayTextBar(player, 1f - (usableTime / maxSeconds), display); } - int cooldown = wizard.cooldowns.containsKey(type) ? wizard.cooldowns.get(type) : 0; - if (cooldown > 0 && cooldown > usableTime) - { - usableTime = cooldown; - } - if (usableTime > 0) - { - display += ChatColor.RED + " Usable in " - + UtilTime.convertString((long) (Math.ceil(usableTime) * 1000), 0, TimeUnit.FIT); - } - else - { - display += ChatColor.RED + " Cooldown: " + ChatColor.RESET - + UtilTime.convertString((long) (type.getSpellCooldown(spellLevel) * 1000), 0, TimeUnit.FIT); - } - double maxSeconds = Math.max(type.getSpellCooldown(spellLevel), type.getManaCost(spellLevel) / wizard.manaPerSecond); - UtilTextTop.displayTextBar(player, (float) (300D - ((usableTime / maxSeconds) * 300)), display); } } @@ -230,29 +233,6 @@ public class WizardBattles extends SoloGame } } - public ItemStack setNonStack(ItemStack item) - { - ItemMeta meta = item.getItemMeta(); - - String s = "" + code++; - for (char c : ("" + code).toCharArray()) - { - s += ChatColor.COLOR_CHAR + c; - } - - if (meta.hasDisplayName()) - { - meta.setDisplayName(meta.getDisplayName() + s); - } - else - { - meta.setDisplayName((item.getType() == Material.BLAZE_ROD ? C.cWhite + "Unused Wand" : "Unknown Item") + s); - } - item.setItemMeta(meta); - - return item; - } - private Spells getSpell(String title) { title = ChatColor.stripColor(title.substring(title.split(" ")[0].length() + 1)); @@ -284,7 +264,7 @@ public class WizardBattles extends SoloGame int spellLevel = wizard.knownSpells.get(spell); if (wizard.mana >= spell.getManaCost(spellLevel)) { - if (!wizard.cooldowns.containsKey(spell)) + if ((wizard.cooldowns.containsKey(spell) ? wizard.cooldowns.get(spell) : 0) < System.currentTimeMillis()) { Spell sp = spells.get(spell); if (obj instanceof Block && sp instanceof SpellRightClickBlock) @@ -299,12 +279,6 @@ public class WizardBattles extends SoloGame { ((SpellRightClick) sp).castSpell(player); } - else - { - return; - } - wizard.cooldowns.put(spell, spell.getSpellCooldown(spellLevel)); - wizard.mana -= spell.getManaCost(spellLevel); } else { @@ -348,16 +322,59 @@ public class WizardBattles extends SoloGame Spells spell = getSpell(item.getItemMeta().getDisplayName()); if (spell != null) { - Wizard wiz = wizards.get(p.getName()); - wiz.knownSpells.put(spell, (wiz.knownSpells.containsKey(spell) ? wiz.knownSpells.get(spell) : 0) + 1); + if (onSpellLearn(p, spell)) + { + p.setItemInHand(new ItemStack(Material.AIR)); + } } } } - else if (event.getAction().name().contains("LEFT")) + } + } + + private boolean onSpellLearn(Player p, Spells spell) + { + Wizard wiz = wizards.get(p.getName()); + if (!wiz.knownSpells.containsKey(spell) || wiz.knownSpells.get(spell) < spell.getMaxLevel()) + { + if (!wiz.knownSpells.containsKey(spell)) { - if (item.getType() == Material.BLAZE_ROD) + p.sendMessage(ChatColor.BLUE + "You have learned the spell " + spell.getElement().getColor() + + spell.getSpellName()); + } + else + { + p.sendMessage(ChatColor.BLUE + "You have leveled up the spell " + spell.getElement().getColor() + + spell.getSpellName() + ChatColor.BLUE + " to level " + ChatColor.BOLD + + (wiz.knownSpells.get(spell) + 1)); + } + wiz.knownSpells.put(spell, (wiz.knownSpells.containsKey(spell) ? wiz.knownSpells.get(spell) : 0) + 1); + if (wiz.knownSpells.get(spell) >= spell.getMaxLevel()) + { + p.sendMessage(ChatColor.BLUE + "You have fully leveled up the spell " + spell.getElement().getColor() + + spell.getSpellName()); + } + return true; + } + return false; + } + + @EventHandler + public void onClick(InventoryClickEvent event) + { + if (event.getInventory().getHolder() instanceof Chest || event.getInventory().getHolder() instanceof DoubleChest) + { + ItemStack item = event.getCurrentItem(); + Player p = (Player) event.getWhoClicked(); + if (item != null && item.getType() == Material.ENCHANTED_BOOK && item.getItemMeta().hasDisplayName()) + { + Spells spell = getSpell(item.getItemMeta().getDisplayName()); + if (spell != null) { - // TODO Open menu to set spell + if (onSpellLearn(p, spell)) + { + event.setCurrentItem(new ItemStack(Material.AIR)); + } } } } @@ -377,8 +394,24 @@ public class WizardBattles extends SoloGame Inventory inv = holder.getInventory(); for (int i = 0; i < 5; i++) { - inv.setItem(new Random().nextInt(inv.getSize()), new ItemBuilder(Material.STICK).setTitle("Loot TODO") - .build()); + ArrayList spells = new ArrayList(); + for (Spells spell : Spells.values()) + { + if (spell.hasChanceToFind()) + { + spells.add(spell); + } + } + if (!spells.isEmpty()) + { + Spells spell = spells.get(new Random().nextInt(spells.size())); + inv.setItem( + new Random().nextInt(inv.getSize()), + spell.makeSpell( + this, + new ItemBuilder(Material.ENCHANTED_BOOK).addLore( + C.cGreen + C.Italics + "Learn the spell " + spell.getSpellName()).build())); + } } state.update(); } @@ -386,4 +419,9 @@ public class WizardBattles extends SoloGame } } + public Wizard getWizard(org.bukkit.entity.Player player) + { + return wizards.get(player.getName()); + } + } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/WizardSpellMenu.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/WizardSpellMenu.java new file mode 100644 index 000000000..652034d1d --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/WizardSpellMenu.java @@ -0,0 +1,47 @@ +package nautilus.game.arcade.game.games.wizards; + +import nautilus.game.arcade.game.Game.GameState; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniPlugin; + +public class WizardSpellMenu extends MiniPlugin +{ + private WizardSpellMenuShop wizardShop; + private WizardBattles wizards; + + public WizardSpellMenu(String moduleName, JavaPlugin plugin, WizardBattles wizards) + { + super("Wizard Spell Menu", plugin); + wizardShop = new WizardSpellMenuShop(this, wizards.getArcadeManager().GetClients(), wizards.getArcadeManager() + .GetDonation(), wizards); + this.wizards = wizards; + } + + @EventHandler + public void onInteract(PlayerInteractEvent event) + { + if (wizards.GetState() == GameState.Live && wizards.IsAlive(event.getPlayer())) + { + ItemStack item = event.getItem(); + if (item != null) + { + Player p = event.getPlayer(); + if (event.getAction().name().contains("LEFT")) + { + if (item.getType() == Material.BLAZE_ROD) + { + wizardShop.attemptShopOpen(p); + } + } + } + } + } + +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/WizardSpellMenuShop.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/WizardSpellMenuShop.java new file mode 100644 index 000000000..af4f99267 --- /dev/null +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/WizardSpellMenuShop.java @@ -0,0 +1,37 @@ +package nautilus.game.arcade.game.games.wizards; + +import mineplex.core.account.CoreClientManager; +import mineplex.core.common.CurrencyType; +import mineplex.core.common.util.NautHashMap; +import mineplex.core.donation.DonationManager; +import mineplex.core.shop.ShopBase; +import mineplex.core.shop.page.ShopPageBase; +import nautilus.game.arcade.game.games.wizards.WizardBattles.Wizard; + +import org.bukkit.entity.Player; + +public class WizardSpellMenuShop extends ShopBase +{ + private WizardBattles _wizards; + + public WizardSpellMenuShop(WizardSpellMenu plugin, CoreClientManager clientManager, DonationManager donationManager, + WizardBattles wizard, CurrencyType... currencyTypes) + { + super(plugin, clientManager, donationManager, "Kit Evolve Menu", currencyTypes); + this._wizards = wizard; + } + + @Override + protected ShopPageBase> BuildPagesFor(Player player) + { + return new SpellMenuPage(Plugin, this, ClientManager, DonationManager, player, _wizards); + } + + public void update() + { + for (ShopPageBase> shopPage : PlayerPageMap.values()) + { + shopPage.Refresh(); + } + } +} diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/spells/DumbSpell.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/spells/DumbSpell.java index f580453fb..b0263231f 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/spells/DumbSpell.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/wizards/spells/DumbSpell.java @@ -13,6 +13,7 @@ public class DumbSpell extends Spell implements SpellRightClick public void castSpell(Player player) { Bukkit.broadcastMessage(player.getName() + " has just cast a dumb spell!"); + charge(player); } }