Wizards Game Progress. Now workable

This commit is contained in:
libraryaddict 2014-12-28 18:35:49 +13:00
parent 0648276720
commit d232bab051
11 changed files with 518 additions and 154 deletions

View File

@ -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;
}

View File

@ -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();
}
}

View File

@ -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());
}
}
}

View File

@ -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);
}

View File

@ -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);
}
}
}

View File

@ -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<WizardSpellMenu, WizardSpellMenuShop>
{
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;
}
}

View File

@ -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<? extends Spell> 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<? extends Spell> 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<SpellElement, Integer> elements = new HashMap<SpellElement, Integer>();
private ItemStack item;
private int slot;
private Class<? extends Spell> 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<? extends Spell> 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<? extends Spell> 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();
}
}

View File

@ -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<Spells, Integer> knownSpells = new NautHashMap<Spells, Integer>();
NautHashMap<Spells, Integer> cooldowns = new NautHashMap<Spells, Integer>();
NautHashMap<Spells, Long> cooldowns = new NautHashMap<Spells, Long>();
SpellElement selectedPage = SpellElement.ATTACK;
}
NautHashMap<String, Wizard> wizards = new NautHashMap<String, Wizard>();
private NautHashMap<String, Wizard> wizards = new NautHashMap<String, Wizard>();
private NautHashMap<Spells, Spell> spells = new NautHashMap<Spells, Spell>();
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<Entry<String, Wizard>> 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<Entry<Spells, Integer>> itel2 = wizard.cooldowns.entrySet().iterator();
Iterator<Entry<Spells, Long>> itel2 = wizard.cooldowns.entrySet().iterator();
while (itel2.hasNext())
{
Entry<Spells, Integer> entry2 = itel2.next();
if (entry2.getValue() > 1)
{
wizard.cooldowns.put(entry2.getKey(), entry2.getValue() - 1);
}
else
Entry<Spells, Long> 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> spells = new ArrayList<Spells>();
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());
}
}

View File

@ -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);
}
}
}
}
}
}

View File

@ -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<WizardSpellMenu>
{
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<WizardSpellMenu, ? extends ShopBase<WizardSpellMenu>> BuildPagesFor(Player player)
{
return new SpellMenuPage(Plugin, this, ClientManager, DonationManager, player, _wizards);
}
public void update()
{
for (ShopPageBase<WizardSpellMenu, ? extends ShopBase<WizardSpellMenu>> shopPage : PlayerPageMap.values())
{
shopPage.Refresh();
}
}
}

View File

@ -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);
}
}