Mineplex2018-withcommit/Plugins/Mineplex.Minecraft.Game.ClassCombat/src/mineplex/minecraft/game/classcombat/Skill/Skill.java

259 lines
4.8 KiB
Java
Raw Normal View History

2013-08-27 17:14:08 +02:00
package mineplex.minecraft.game.classcombat.Skill;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
2013-08-27 17:14:08 +02:00
import mineplex.core.common.util.C;
import mineplex.core.common.util.NautHashMap;
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;
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<Integer, String[]> _descLevels = new HashMap<Integer, String[]>();
2013-08-27 17:14:08 +02:00
private ClassType _classType;
private SkillType _skillType;
private int _salesPackageId;
private int _cost = 1000;
private int _maxLevel = 1;
2013-08-27 17:14:08 +02:00
private boolean _free;
private NautHashMap<Player, Integer> _users;
2013-08-27 17:14:08 +02:00
public SkillFactory Factory;
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;
_users = new NautHashMap<Player, Integer>();
_maxLevel = maxLevel;
2013-08-27 17:14:08 +02:00
}
@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 GetCost()
{
return _cost;
}
@Override
public int getMaxLevel()
{
return _maxLevel;
}
public int getLevel(Entity ent)
2013-08-27 17:14:08 +02:00
{
if (!(ent instanceof Player))
return 0;
Player player = (Player)ent;
if (!_users.containsKey(player))
2013-08-27 17:14:08 +02:00
return 0;
return 1;
}
@Override
public String[] GetDesc(int curLevel)
2013-08-27 17:14:08 +02:00
{
//Desc of this level has already been generated
if (_descLevels.containsKey(curLevel))
{
return _descLevels.get(curLevel);
}
//Generate DESC
ArrayList<String> descOut = new ArrayList<String>();
2013-08-27 17:14:08 +02:00
//Parse Desc
2013-08-27 17:14:08 +02:00
for (String line : _desc)
{
String newLine = "";
//Check for Level Tokens
for (String token : line.split(" "))
{
if (token.length() <= 0)
continue;
//Parse Level Token
if (token.charAt(0) == '#')
{
String[] numberToks = token.split("#");
try
{
double base = Double.parseDouble(numberToks[0]);
double bonus = Double.parseDouble(numberToks[1]);
double levelValue = base + ((double)curLevel * bonus);
char plusMinus = '+';
if (bonus < 0)
plusMinus = '-';
token = C.cYellow + levelValue + C.cGray + " (" + C.cGreen + plusMinus + bonus + C.cGray + ")";
}
catch (Exception e)
{
token = C.cRed + token + C.cGray;
break;
}
}
newLine += token + " ";
}
//Remove Space
if (newLine.length() > 0)
newLine = newLine.substring(0, newLine.length()-1);
descOut.add(newLine);
}
//Append Energy & Recharge
if (GetEnergyString() != null || GetRechargeString() != null)
descOut.add("");
if (GetEnergyString() != null)
descOut.add(GetEnergyString());
if (GetRechargeString() != null)
descOut.add(GetRechargeString());
//Return
String[] out = new String[descOut.size()];
for (int i=0 ; i<descOut.size() ; i++)
out[i] = descOut.get(i);
//Store
_descLevels.put(curLevel, out);
return out;
2013-08-27 17:14:08 +02:00
}
public String GetEnergyString()
{
return null;
}
public String GetRechargeString()
{
return null;
}
@Override
public Set<Player> GetUsers()
2013-08-27 17:14:08 +02:00
{
_users.remove(null);
return _users.keySet();
2013-08-27 17:14:08 +02:00
}
public void AddUser(Player player, int level)
2013-08-27 17:14:08 +02: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;
}
public void Update(SkillToken skillToken)
{
_salesPackageId = skillToken.SalesPackage.GameSalesPackageId;
_free = skillToken.SalesPackage.Free;
_cost = skillToken.SalesPackage.Gems;
}
}