297 lines
6.1 KiB
Java
297 lines
6.1 KiB
Java
|
package mineplex.minecraft.game.classcombat.Skill;
|
||
|
|
||
|
import mineplex.core.common.util.NautHashMap;
|
||
|
import mineplex.core.common.util.UtilBlock;
|
||
|
import mineplex.core.common.util.UtilEnt;
|
||
|
import mineplex.core.common.util.UtilEvent;
|
||
|
import mineplex.core.common.util.UtilGear;
|
||
|
import mineplex.core.common.util.UtilEvent.ActionType;
|
||
|
import mineplex.core.recharge.Recharge;
|
||
|
import mineplex.core.updater.UpdateType;
|
||
|
import mineplex.core.updater.event.UpdateEvent;
|
||
|
import mineplex.minecraft.game.classcombat.Class.IPvpClass.ClassType;
|
||
|
|
||
|
import org.bukkit.Material;
|
||
|
import org.bukkit.entity.Arrow;
|
||
|
import org.bukkit.entity.Player;
|
||
|
import org.bukkit.event.EventHandler;
|
||
|
import org.bukkit.event.Listener;
|
||
|
import org.bukkit.event.entity.EntityShootBowEvent;
|
||
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||
|
|
||
|
public abstract class SkillCharge extends Skill implements Listener
|
||
|
{
|
||
|
public enum ChargeType
|
||
|
{
|
||
|
Sword,
|
||
|
Bow,
|
||
|
Sneak
|
||
|
}
|
||
|
|
||
|
protected NautHashMap<Player, Float> _charge = new NautHashMap<Player, Float>();
|
||
|
|
||
|
protected float _rateBase;
|
||
|
protected float _rateBoost;
|
||
|
|
||
|
protected boolean _canChargeInWater;
|
||
|
protected boolean _canChargeInAir;
|
||
|
protected boolean _autoFire;
|
||
|
|
||
|
protected ChargeType _type;
|
||
|
|
||
|
public SkillCharge(SkillFactory skills, String name, ClassType classType,
|
||
|
SkillType skillType, int cost, int maxLevel,
|
||
|
ChargeType type, float base, float boost, boolean inWater, boolean inAir, boolean autoFire)
|
||
|
{
|
||
|
super(skills, name, classType, skillType, cost, maxLevel);
|
||
|
|
||
|
_rateBase = base;
|
||
|
_rateBoost = boost;
|
||
|
_canChargeInWater = inWater;
|
||
|
_canChargeInAir = inAir;
|
||
|
_autoFire = autoFire;
|
||
|
_type = type;
|
||
|
}
|
||
|
|
||
|
@EventHandler
|
||
|
public void ChargeSneak(UpdateEvent event)
|
||
|
{
|
||
|
if (_type != ChargeType.Sneak)
|
||
|
return;
|
||
|
|
||
|
if (event.getType() != UpdateType.TICK)
|
||
|
return;
|
||
|
|
||
|
for (Player cur : GetUsers())
|
||
|
{
|
||
|
//Level
|
||
|
int level = getLevel(cur);
|
||
|
if (level == 0) continue;
|
||
|
|
||
|
//Charge
|
||
|
if (cur.isSneaking())
|
||
|
{
|
||
|
//Flags
|
||
|
if (_canChargeInAir && !UtilEnt.isGrounded(cur))
|
||
|
continue;
|
||
|
|
||
|
if (_canChargeInWater && cur.getLocation().getBlock().isLiquid())
|
||
|
continue;
|
||
|
|
||
|
//Add & Recharge
|
||
|
if (!_charge.containsKey(cur))
|
||
|
{
|
||
|
if (!Recharge.Instance.use(cur, GetName(level), 1000, false))
|
||
|
{
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
_charge.put(cur, 0f);
|
||
|
}
|
||
|
|
||
|
float charge = _charge.get(cur);
|
||
|
|
||
|
//Increase Charge
|
||
|
charge = Math.min(1f, charge + _rateBase + (_rateBoost * level));
|
||
|
_charge.put(cur, charge);
|
||
|
|
||
|
//Display
|
||
|
DisplayProgress(cur, GetName(), charge);
|
||
|
|
||
|
//Auto
|
||
|
if (_autoFire && charge >= 1f)
|
||
|
{
|
||
|
DoSkill(cur, charge, null);
|
||
|
}
|
||
|
}
|
||
|
//Release Charge
|
||
|
else if (_charge.containsKey(cur))
|
||
|
{
|
||
|
float charge = _charge.remove(cur);
|
||
|
|
||
|
DoSkill(cur, charge, null);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@EventHandler
|
||
|
public void ChargeBlock(UpdateEvent event)
|
||
|
{
|
||
|
if (_type != ChargeType.Sword)
|
||
|
return;
|
||
|
|
||
|
if (event.getType() != UpdateType.TICK)
|
||
|
return;
|
||
|
|
||
|
for (Player cur : GetUsers())
|
||
|
{
|
||
|
//Level
|
||
|
int level = getLevel(cur);
|
||
|
if (level == 0) continue;
|
||
|
|
||
|
//Charge
|
||
|
if (cur.isBlocking())
|
||
|
{
|
||
|
//Flags
|
||
|
if (_canChargeInAir && !UtilEnt.isGrounded(cur))
|
||
|
continue;
|
||
|
|
||
|
if (_canChargeInWater && cur.getLocation().getBlock().isLiquid())
|
||
|
continue;
|
||
|
|
||
|
//Add & Recharge
|
||
|
if (!_charge.containsKey(cur))
|
||
|
{
|
||
|
if (!Recharge.Instance.use(cur, GetName(level), 1000, false))
|
||
|
{
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
_charge.put(cur, 0f);
|
||
|
}
|
||
|
|
||
|
|
||
|
float charge = _charge.get(cur);
|
||
|
|
||
|
//Increase Charge
|
||
|
charge = Math.min(1f, charge + _rateBase + (_rateBoost * level));
|
||
|
|
||
|
//Display
|
||
|
DisplayProgress(cur, GetName(), charge);
|
||
|
|
||
|
//Auto
|
||
|
if (_autoFire && charge >= 1f)
|
||
|
{
|
||
|
_charge.remove(cur);
|
||
|
DoSkill(cur, charge, null);
|
||
|
}
|
||
|
}
|
||
|
//Release Charge
|
||
|
else if (_charge.containsKey(cur))
|
||
|
{
|
||
|
//Action
|
||
|
float charge = _charge.remove(cur);
|
||
|
|
||
|
DoSkill(cur, charge, null);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@EventHandler
|
||
|
public void ChargeBowInit(PlayerInteractEvent event)
|
||
|
{
|
||
|
if (_type != ChargeType.Bow)
|
||
|
return;
|
||
|
|
||
|
Player player = event.getPlayer();
|
||
|
|
||
|
if (!UtilGear.isMat(event.getItem(), Material.BOW))
|
||
|
return;
|
||
|
|
||
|
if (!UtilEvent.isAction(event, ActionType.R))
|
||
|
return;
|
||
|
|
||
|
if (!player.getInventory().contains(Material.ARROW))
|
||
|
return;
|
||
|
|
||
|
//Flags
|
||
|
if (_canChargeInAir && !UtilEnt.isGrounded(player))
|
||
|
return;
|
||
|
|
||
|
if (_canChargeInWater && player.getLocation().getBlock().isLiquid())
|
||
|
return;
|
||
|
|
||
|
if (UtilBlock.usable(event.getClickedBlock()))
|
||
|
return;
|
||
|
|
||
|
//Level
|
||
|
int level = getLevel(player);
|
||
|
if (level == 0) return;
|
||
|
|
||
|
//Start Charge
|
||
|
_charge.put(player, 0f);
|
||
|
}
|
||
|
|
||
|
@EventHandler
|
||
|
public void ChargeBow(UpdateEvent event)
|
||
|
{
|
||
|
if (_type != ChargeType.Bow)
|
||
|
return;
|
||
|
|
||
|
if (event.getType() != UpdateType.TICK)
|
||
|
return;
|
||
|
|
||
|
for (Player cur : GetUsers())
|
||
|
{
|
||
|
//Not Charging
|
||
|
if (!_charge.containsKey(cur))
|
||
|
continue;
|
||
|
|
||
|
//Level
|
||
|
int level = getLevel(cur);
|
||
|
if (level == 0)
|
||
|
{
|
||
|
_charge.remove(cur);
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
//No Longer Holding Bow
|
||
|
if (!UtilGear.isMat(cur.getItemInHand(), Material.BOW))
|
||
|
{
|
||
|
_charge.remove(cur);
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
//Flags
|
||
|
if (_canChargeInAir && !UtilEnt.isGrounded(cur))
|
||
|
continue;
|
||
|
|
||
|
if (_canChargeInWater && cur.getLocation().getBlock().isLiquid())
|
||
|
continue;
|
||
|
|
||
|
float charge = _charge.get(cur);
|
||
|
|
||
|
//Increase Charge
|
||
|
charge = Math.min(1f, charge + _rateBase + (_rateBoost * level));
|
||
|
|
||
|
//Display
|
||
|
DisplayProgress(cur, GetName(), charge);
|
||
|
|
||
|
//Auto
|
||
|
if (_autoFire && charge >= 1f)
|
||
|
{
|
||
|
_charge.remove(cur);
|
||
|
DoSkill(cur, charge, null);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@EventHandler
|
||
|
public void TriggerBow(EntityShootBowEvent event)
|
||
|
{
|
||
|
if (_type != ChargeType.Bow)
|
||
|
return;
|
||
|
|
||
|
if (!(event.getEntity() instanceof Player))
|
||
|
return;
|
||
|
|
||
|
if (!(event.getProjectile() instanceof Arrow))
|
||
|
return;
|
||
|
|
||
|
Player player = (Player)event.getEntity();
|
||
|
|
||
|
if (!_charge.containsKey(player))
|
||
|
return;
|
||
|
|
||
|
DoSkill(player, _charge.remove(player), (Arrow)event.getProjectile());
|
||
|
}
|
||
|
|
||
|
public abstract void DoSkill(Player player, float charge, Arrow arrow);
|
||
|
|
||
|
@Override
|
||
|
public void Reset(Player player)
|
||
|
{
|
||
|
_charge.remove(player);
|
||
|
}
|
||
|
}
|