package mineplex.minecraft.game.classcombat.Skill; import java.util.ArrayList; import java.util.HashMap; import java.util.Set; import mineplex.core.common.util.C; import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.UtilDisplay; import mineplex.core.common.util.UtilGear; import mineplex.core.recharge.Recharge; import mineplex.minecraft.game.classcombat.Class.IPvpClass.ClassType; import mineplex.minecraft.game.classcombat.Skill.repository.token.SkillToken; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerQuitEvent; public abstract class Skill implements ISkill, Listener { //Properties private String _name; private String[] _desc; private HashMap _descLevels = new HashMap(); private ClassType _classType; private SkillType _skillType; private int _salesPackageId; private int _gemCost = 1000; private int _tokenCost = 0; private int _maxLevel = 1; private boolean _free; private NautHashMap _users; public SkillFactory Factory; public Skill(SkillFactory skills, String name, ClassType classType, SkillType skillType, int cost, int maxLevel) { Factory = skills; _name = name; _desc = new String[] { "" }; _classType = classType; _skillType = skillType; _users = new NautHashMap(); _maxLevel = maxLevel; _tokenCost = cost; } @Override public String GetName() { return _name; } public String GetName(int level) { if (level <= 1) return GetName(); return _name + " " + level; } public String GetName(String type) { return _name + " (" + type + ")"; } @Override public Integer GetSalesPackageId() { return _salesPackageId; } @Override public ClassType GetClassType() { return _classType; } @Override public SkillType GetSkillType() { return _skillType; } @Override public int GetGemCost() { return _gemCost; } @Override public int GetTokenCost() { return _tokenCost; } @Override public int getMaxLevel() { return _maxLevel; } public int getLevel(Entity ent) { if (!(ent instanceof Player)) return 0; Player player = (Player)ent; if (!_users.containsKey(player)) return 0; int level = _users.get(player); if (GetSkillType() == SkillType.Sword) if (UtilGear.isMat(player.getItemInHand(), Material.GOLD_SWORD)) level++; if (GetSkillType() == SkillType.Axe) if (UtilGear.isMat(player.getItemInHand(), Material.GOLD_AXE)) level++; return level; } @Override public String[] GetDesc(int curLevel) { //Desc of this level has already been generated if (_descLevels.containsKey(curLevel)) { return _descLevels.get(curLevel); } //Generate DESC ArrayList descOut = new ArrayList(); //Parse Desc for (String line : _desc) descOut.add(ModifyLineToLevel(line, curLevel)); //Append Energy & Recharge if (GetEnergyString() != null || GetRechargeString() != null) descOut.add(""); if (GetEnergyString() != null) descOut.add(ModifyLineToLevel(GetEnergyString(), curLevel)); if (GetRechargeString() != null) descOut.add(ModifyLineToLevel(GetRechargeString(), curLevel)); //Return String[] out = new String[descOut.size()]; for (int i=0 ; i 0) newLine = newLine.substring(0, newLine.length()-1); return newLine; } public String GetEnergyString() { return null; } public String GetRechargeString() { return null; } @Override public Set GetUsers() { _users.remove(null); return _users.keySet(); } public void AddUser(Player player, int level) { _users.put(player, level); OnPlayerAdd(player); } public void OnPlayerAdd(Player player) { //Null Default } @Override public void RemoveUser(Player player) { _users.remove(player); Reset(player); } public void SetDesc(String[] desc) { _desc = desc; } @EventHandler public final void Death(PlayerDeathEvent event) { Reset(event.getEntity()); } @EventHandler public final void Quit(PlayerQuitEvent event) { Reset(event.getPlayer()); _users.remove(event.getPlayer()); } @Override public boolean IsFree() { return _free; } public void Update(SkillToken skillToken) { _salesPackageId = skillToken.SalesPackage.GameSalesPackageId; _free = skillToken.SalesPackage.Free; _gemCost = skillToken.SalesPackage.Gems; } public void DisplayProgress(Player player, String ability, float amount) { player.setExp(amount); UtilDisplay.displayTextBar(Factory.GetPlugin(), player, amount, C.cYellow + C.Bold + ability + ChatColor.RESET + " - " + C.cGreen + C.Bold + (int)(amount*100) + "%"); player.playSound(player.getLocation(), Sound.NOTE_PIANO, 0.5f, 0.5f + (amount * 1.5f)); } public void ResetProgress(Player player) { player.setExp(0f); } }