2013-08-27 17:14:08 +02:00
|
|
|
package mineplex.minecraft.game.classcombat.Skill;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2014-03-28 08:50:38 +01:00
|
|
|
import java.util.HashMap;
|
2014-03-28 03:17:31 +01:00
|
|
|
import java.util.Set;
|
2013-08-27 17:14:08 +02:00
|
|
|
|
2014-03-28 08:50:38 +01:00
|
|
|
import mineplex.core.common.util.C;
|
2014-03-28 03:17:31 +01:00
|
|
|
import mineplex.core.common.util.NautHashMap;
|
2014-04-02 06:19:58 +02:00
|
|
|
import mineplex.core.common.util.UtilDisplay;
|
2014-04-02 12:22:21 +02:00
|
|
|
import mineplex.core.common.util.UtilGear;
|
2013-08-27 17:14:08 +02:00
|
|
|
import mineplex.minecraft.game.classcombat.Class.IPvpClass.ClassType;
|
|
|
|
import mineplex.minecraft.game.classcombat.Skill.repository.token.SkillToken;
|
|
|
|
|
2014-04-02 12:22:21 +02:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Material;
|
2014-04-02 06:19:58 +02:00
|
|
|
import org.bukkit.Sound;
|
2013-08-27 17:14:08 +02:00
|
|
|
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;
|
2014-03-28 08:50:38 +01:00
|
|
|
private HashMap<Integer, String[]> _descLevels = new HashMap<Integer, String[]>();
|
2013-08-27 17:14:08 +02:00
|
|
|
|
|
|
|
private ClassType _classType;
|
|
|
|
private SkillType _skillType;
|
|
|
|
|
|
|
|
private int _salesPackageId;
|
2014-03-29 23:45:53 +01:00
|
|
|
private int _gemCost = 1000;
|
|
|
|
private int _tokenCost = 0;
|
2014-03-28 03:17:31 +01:00
|
|
|
private int _maxLevel = 1;
|
2014-03-29 07:07:07 +01:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
private boolean _free;
|
2014-03-28 03:17:31 +01:00
|
|
|
private NautHashMap<Player, Integer> _users;
|
2014-03-29 07:07:07 +01:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
public SkillFactory Factory;
|
|
|
|
|
2014-03-28 03:17:31 +01:00
|
|
|
public Skill(SkillFactory skills, String name, ClassType classType, SkillType skillType, int cost, int maxLevel)
|
2013-08-27 17:14:08 +02:00
|
|
|
{
|
|
|
|
Factory = skills;
|
|
|
|
_name = name;
|
|
|
|
_desc = new String[] { "<Skill Description>" };
|
|
|
|
_classType = classType;
|
|
|
|
_skillType = skillType;
|
2014-03-28 03:17:31 +01:00
|
|
|
_users = new NautHashMap<Player, Integer>();
|
|
|
|
_maxLevel = maxLevel;
|
2014-03-29 23:45:53 +01:00
|
|
|
_tokenCost = cost;
|
2013-08-27 17:14:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String GetName()
|
|
|
|
{
|
|
|
|
return _name;
|
|
|
|
}
|
2014-03-29 07:07:07 +01:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
public String GetName(int level)
|
|
|
|
{
|
|
|
|
if (level <= 1)
|
|
|
|
return GetName();
|
2014-03-29 07:07:07 +01:00
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
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
|
2014-03-29 23:45:53 +01:00
|
|
|
public int GetGemCost()
|
2013-08-27 17:14:08 +02:00
|
|
|
{
|
2014-03-29 23:45:53 +01:00
|
|
|
return _gemCost;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int GetTokenCost()
|
|
|
|
{
|
|
|
|
return _tokenCost;
|
2013-08-27 17:14:08 +02:00
|
|
|
}
|
2014-03-29 07:07:07 +01:00
|
|
|
|
2014-03-28 03:17:31 +01:00
|
|
|
@Override
|
|
|
|
public int getMaxLevel()
|
|
|
|
{
|
|
|
|
return _maxLevel;
|
|
|
|
}
|
2014-03-29 07:07:07 +01:00
|
|
|
|
2014-03-28 03:17:31 +01:00
|
|
|
public int getLevel(Entity ent)
|
2013-08-27 17:14:08 +02:00
|
|
|
{
|
|
|
|
if (!(ent instanceof Player))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
Player player = (Player)ent;
|
|
|
|
|
2014-03-28 03:17:31 +01:00
|
|
|
if (!_users.containsKey(player))
|
2013-08-27 17:14:08 +02:00
|
|
|
return 0;
|
2014-04-02 12:22:21 +02:00
|
|
|
|
|
|
|
int level = _users.get(player);
|
|
|
|
|
|
|
|
if (GetSkillType() == SkillType.Sword)
|
|
|
|
if (UtilGear.isMat(player.getItemInHand(), Material.GOLD_SWORD))
|
|
|
|
level++;
|
2013-08-27 17:14:08 +02:00
|
|
|
|
2014-04-02 12:22:21 +02:00
|
|
|
if (GetSkillType() == SkillType.Axe)
|
|
|
|
if (UtilGear.isMat(player.getItemInHand(), Material.GOLD_AXE))
|
|
|
|
level++;
|
|
|
|
|
|
|
|
return level;
|
2013-08-27 17:14:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-03-28 08:50:38 +01:00
|
|
|
public String[] GetDesc(int curLevel)
|
2013-08-27 17:14:08 +02:00
|
|
|
{
|
2014-03-28 08:50:38 +01:00
|
|
|
//Desc of this level has already been generated
|
|
|
|
if (_descLevels.containsKey(curLevel))
|
|
|
|
{
|
|
|
|
return _descLevels.get(curLevel);
|
|
|
|
}
|
2014-03-29 07:07:07 +01:00
|
|
|
|
2014-03-28 08:50:38 +01:00
|
|
|
//Generate DESC
|
2014-03-29 07:07:07 +01:00
|
|
|
|
|
|
|
|
2014-03-28 08:50:38 +01:00
|
|
|
ArrayList<String> descOut = new ArrayList<String>();
|
2013-08-27 17:14:08 +02:00
|
|
|
|
2014-03-28 08:50:38 +01:00
|
|
|
//Parse Desc
|
2013-08-27 17:14:08 +02:00
|
|
|
for (String line : _desc)
|
2014-03-29 07:07:07 +01:00
|
|
|
descOut.add(ModifyLineToLevel(line, curLevel));
|
|
|
|
|
2014-03-28 08:50:38 +01:00
|
|
|
//Append Energy & Recharge
|
|
|
|
if (GetEnergyString() != null || GetRechargeString() != null)
|
|
|
|
descOut.add("");
|
|
|
|
|
|
|
|
if (GetEnergyString() != null)
|
2014-03-29 07:07:07 +01:00
|
|
|
descOut.add(ModifyLineToLevel(GetEnergyString(), curLevel));
|
2014-03-28 08:50:38 +01:00
|
|
|
|
|
|
|
if (GetRechargeString() != null)
|
2014-03-29 07:07:07 +01:00
|
|
|
descOut.add(ModifyLineToLevel(GetRechargeString(), curLevel));
|
2014-03-29 23:45:53 +01:00
|
|
|
|
2014-03-28 08:50:38 +01:00
|
|
|
//Return
|
|
|
|
String[] out = new String[descOut.size()];
|
2014-03-29 07:07:07 +01:00
|
|
|
|
2014-03-28 08:50:38 +01:00
|
|
|
for (int i=0 ; i<descOut.size() ; i++)
|
|
|
|
out[i] = descOut.get(i);
|
2014-03-29 07:07:07 +01:00
|
|
|
|
2014-03-28 08:50:38 +01:00
|
|
|
//Store
|
|
|
|
_descLevels.put(curLevel, out);
|
2014-03-29 07:07:07 +01:00
|
|
|
|
2014-03-28 08:50:38 +01:00
|
|
|
return out;
|
2013-08-27 17:14:08 +02:00
|
|
|
}
|
|
|
|
|
2014-03-29 07:07:07 +01:00
|
|
|
public String ModifyLineToLevel(String line, int level)
|
|
|
|
{
|
|
|
|
String newLine = "";
|
|
|
|
|
|
|
|
//Check for Level Tokens
|
|
|
|
for (String token : line.split(" "))
|
|
|
|
{
|
|
|
|
if (token.length() <= 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
//Parse Level Token
|
|
|
|
if (token.charAt(0) == '#')
|
|
|
|
{
|
|
|
|
token = token.substring(1, token.length());
|
|
|
|
String[] numberToks = token.split("\\#");
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2014-04-08 02:53:41 +02:00
|
|
|
float base = Float.parseFloat(numberToks[0]);
|
|
|
|
float bonus = Float.parseFloat(numberToks[1]);
|
2014-03-29 07:07:07 +01:00
|
|
|
|
2014-04-08 02:53:41 +02:00
|
|
|
float levelValue = base + (level * bonus);
|
2014-03-29 07:07:07 +01:00
|
|
|
|
2014-03-29 23:45:53 +01:00
|
|
|
String plusMinus = "+";
|
2014-03-29 07:07:07 +01:00
|
|
|
if (bonus < 0)
|
2014-03-29 23:45:53 +01:00
|
|
|
plusMinus = "";
|
|
|
|
|
|
|
|
//Round off 0's
|
|
|
|
String bonusString = bonus + "";
|
|
|
|
if (bonus % 1 == 0)
|
|
|
|
bonusString = (int)bonus + "";
|
|
|
|
|
|
|
|
String totalString = levelValue + "";
|
|
|
|
if (levelValue % 1 == 0)
|
|
|
|
totalString = (int)levelValue + "";
|
|
|
|
|
2014-03-29 07:07:07 +01:00
|
|
|
//Only display what you'd get with level 1
|
2014-03-29 23:05:29 +01:00
|
|
|
if (level == 0 )
|
2014-03-29 07:07:07 +01:00
|
|
|
{
|
2014-04-08 02:53:41 +02:00
|
|
|
levelValue = base + (1f * bonus);
|
2014-03-29 23:45:53 +01:00
|
|
|
|
|
|
|
totalString = levelValue + "";
|
|
|
|
if (levelValue % 1 == 0)
|
|
|
|
totalString = (int)levelValue + "";
|
|
|
|
|
2014-04-02 06:19:58 +02:00
|
|
|
token = C.cGreen + totalString + C.cGray;
|
2014-03-29 07:07:07 +01:00
|
|
|
}
|
2014-03-29 23:05:29 +01:00
|
|
|
//Maxed
|
|
|
|
else if (level == getMaxLevel())
|
|
|
|
{
|
2014-03-29 23:45:53 +01:00
|
|
|
token = C.cYellow + totalString + C.cGray;
|
2014-03-29 23:05:29 +01:00
|
|
|
}
|
2014-03-29 07:07:07 +01:00
|
|
|
else
|
|
|
|
{
|
2014-03-29 23:45:53 +01:00
|
|
|
token = C.cYellow + totalString + C.cGray + " (" + C.cGreen + plusMinus + bonusString + C.cGray + ")";
|
2014-03-29 07:07:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
token = C.cRed + token + C.cGray;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
newLine += token + " ";
|
|
|
|
}
|
|
|
|
|
|
|
|
//Remove Space
|
|
|
|
if (newLine.length() > 0)
|
|
|
|
newLine = newLine.substring(0, newLine.length()-1);
|
|
|
|
|
|
|
|
return newLine;
|
|
|
|
}
|
|
|
|
|
2013-08-27 17:14:08 +02:00
|
|
|
public String GetEnergyString()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String GetRechargeString()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-03-28 03:17:31 +01:00
|
|
|
public Set<Player> GetUsers()
|
2013-08-27 17:14:08 +02:00
|
|
|
{
|
|
|
|
_users.remove(null);
|
2014-03-28 03:17:31 +01:00
|
|
|
return _users.keySet();
|
2013-08-27 17:14:08 +02:00
|
|
|
}
|
|
|
|
|
2014-03-28 03:17:31 +01:00
|
|
|
public void AddUser(Player player, int level)
|
2013-08-27 17:14:08 +02:00
|
|
|
{
|
2014-03-28 03:17:31 +01:00
|
|
|
_users.put(player, level);
|
2013-08-27 17:14:08 +02:00
|
|
|
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;
|
|
|
|
}
|
2014-04-13 13:24:22 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setFree(boolean free)
|
|
|
|
{
|
|
|
|
_free = free;
|
|
|
|
}
|
2013-08-27 17:14:08 +02:00
|
|
|
|
|
|
|
public void Update(SkillToken skillToken)
|
|
|
|
{
|
|
|
|
_salesPackageId = skillToken.SalesPackage.GameSalesPackageId;
|
|
|
|
}
|
2014-04-02 06:19:58 +02:00
|
|
|
|
|
|
|
public void DisplayProgress(Player player, String ability, float amount)
|
|
|
|
{
|
2014-04-04 04:26:00 +02:00
|
|
|
//player.setExp(amount);
|
|
|
|
UtilDisplay.displayTextBar(Factory.GetPlugin(), player, amount, C.cYellow + C.Bold + ability + ChatColor.RESET + " - " + C.cGreen + C.Bold + (int)(amount*100) + "%");
|
2014-04-02 06:19:58 +02:00
|
|
|
|
2014-04-15 09:53:24 +02:00
|
|
|
if (amount < 1)
|
|
|
|
player.playSound(player.getLocation(), Sound.NOTE_PIANO, 0.5f, 0.5f + (amount * 1.5f));
|
2014-04-02 06:19:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void ResetProgress(Player player)
|
|
|
|
{
|
2014-04-04 04:26:00 +02:00
|
|
|
//player.setExp(0f);
|
2014-04-02 06:19:58 +02:00
|
|
|
}
|
2013-08-27 17:14:08 +02:00
|
|
|
}
|