166 lines
4.4 KiB
Java
166 lines
4.4 KiB
Java
|
package nautilus.game.arcade.kit.perks;
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.HashMap;
|
||
|
import java.util.Iterator;
|
||
|
|
||
|
import org.bukkit.Location;
|
||
|
import org.bukkit.Sound;
|
||
|
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftCreature;
|
||
|
import org.bukkit.entity.Player;
|
||
|
import org.bukkit.entity.Skeleton;
|
||
|
import org.bukkit.event.EventHandler;
|
||
|
import org.bukkit.event.entity.EntityTargetEvent;
|
||
|
|
||
|
import mineplex.core.common.util.C;
|
||
|
import mineplex.core.common.util.UtilAlg;
|
||
|
import mineplex.core.common.util.UtilEnt;
|
||
|
import mineplex.core.common.util.UtilMath;
|
||
|
import mineplex.core.common.util.UtilPlayer;
|
||
|
import mineplex.core.updater.event.UpdateEvent;
|
||
|
import mineplex.core.updater.UpdateType;
|
||
|
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
|
||
|
import nautilus.game.arcade.kit.Perk;
|
||
|
import net.minecraft.server.v1_6_R3.EntityCreature;
|
||
|
import net.minecraft.server.v1_6_R3.Navigation;
|
||
|
|
||
|
public class PerkSkeletons extends Perk
|
||
|
{
|
||
|
private HashMap<Player, ArrayList<Skeleton>> _minions = new HashMap<Player, ArrayList<Skeleton>>();
|
||
|
|
||
|
private boolean _name;
|
||
|
|
||
|
public PerkSkeletons(boolean name)
|
||
|
{
|
||
|
super("Skeleton Minons", new String[]
|
||
|
{
|
||
|
C.cGray + "Killing an opponent summons a skeletal minion."
|
||
|
});
|
||
|
|
||
|
_name = name;
|
||
|
}
|
||
|
|
||
|
@EventHandler
|
||
|
public void MinionSpawn(CombatDeathEvent event)
|
||
|
{
|
||
|
if (event.GetLog().GetKiller() == null)
|
||
|
return;
|
||
|
|
||
|
if (!(event.GetEvent().getEntity() instanceof Player))
|
||
|
return;
|
||
|
|
||
|
Player killer = UtilPlayer.searchExact(event.GetLog().GetKiller().GetName());
|
||
|
if (killer == null)
|
||
|
return;
|
||
|
|
||
|
if (!Kit.HasKit(killer))
|
||
|
return;
|
||
|
|
||
|
Player killed = (Player)event.GetEvent().getEntity();
|
||
|
|
||
|
Manager.GetGame().CreatureAllowOverride = true;
|
||
|
Skeleton skel = killer.getWorld().spawn(killed.getLocation(), Skeleton.class);
|
||
|
Manager.GetGame().CreatureAllowOverride = false;
|
||
|
|
||
|
skel.setMaxHealth(30);
|
||
|
skel.setHealth(skel.getMaxHealth());
|
||
|
|
||
|
skel.getEquipment().setItemInHand(killed.getItemInHand());
|
||
|
skel.getEquipment().setHelmet(killed.getInventory().getHelmet());
|
||
|
skel.getEquipment().setChestplate(killed.getInventory().getChestplate());
|
||
|
skel.getEquipment().setLeggings(killed.getInventory().getLeggings());
|
||
|
skel.getEquipment().setBoots(killed.getInventory().getBoots());
|
||
|
|
||
|
event.GetEvent().getDrops().remove(killed.getItemInHand());
|
||
|
event.GetEvent().getDrops().remove(killed.getInventory().getHelmet());
|
||
|
event.GetEvent().getDrops().remove(killed.getInventory().getChestplate());
|
||
|
event.GetEvent().getDrops().remove(killed.getInventory().getLeggings());
|
||
|
event.GetEvent().getDrops().remove(killed.getInventory().getBoots());
|
||
|
|
||
|
|
||
|
if (_name)
|
||
|
{
|
||
|
skel.setCustomName("Skeletal " + UtilEnt.getName(event.GetEvent().getEntity()));
|
||
|
skel.setCustomNameVisible(true);
|
||
|
}
|
||
|
|
||
|
if (!_minions.containsKey(killer))
|
||
|
_minions.put(killer, new ArrayList<Skeleton>());
|
||
|
|
||
|
_minions.get(killer).add(skel);
|
||
|
|
||
|
killer.playSound(killer.getLocation(), Sound.SKELETON_HURT, 1f, 1f);
|
||
|
}
|
||
|
|
||
|
@EventHandler
|
||
|
public void TargetCancel(EntityTargetEvent event)
|
||
|
{
|
||
|
if (!_minions.containsKey(event.getTarget()))
|
||
|
return;
|
||
|
|
||
|
if (_minions.get(event.getTarget()).contains(event.getEntity()))
|
||
|
event.setCancelled(true);
|
||
|
}
|
||
|
|
||
|
@EventHandler
|
||
|
public void WolfUpdate(UpdateEvent event)
|
||
|
{
|
||
|
if (event.getType() != UpdateType.FAST)
|
||
|
return;
|
||
|
|
||
|
for (Player player : _minions.keySet())
|
||
|
{
|
||
|
Iterator<Skeleton> skelIterator = _minions.get(player).iterator();
|
||
|
|
||
|
while (skelIterator.hasNext())
|
||
|
{
|
||
|
Skeleton skel = skelIterator.next();
|
||
|
|
||
|
//Dead
|
||
|
if (!skel.isValid())
|
||
|
{
|
||
|
skelIterator.remove();
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
//Return to Owner
|
||
|
double range = 3;
|
||
|
if (skel.getTarget() != null)
|
||
|
range = 12;
|
||
|
|
||
|
if (UtilMath.offset(skel, player) > range)
|
||
|
{
|
||
|
float speed = 1f;
|
||
|
if (player.isSprinting())
|
||
|
speed = 1.4f;
|
||
|
|
||
|
//Move
|
||
|
EntityCreature ec = ((CraftCreature)skel).getHandle();
|
||
|
Navigation nav = ec.getNavigation();
|
||
|
Location target = player.getLocation().add(UtilAlg.getTrajectory(player, skel));
|
||
|
nav.a(target.getX(), target.getY(), target.getZ(), speed);
|
||
|
|
||
|
skel.setTarget(null);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@EventHandler
|
||
|
public void Heal(UpdateEvent event)
|
||
|
{
|
||
|
if (event.getType() != UpdateType.SEC)
|
||
|
return;
|
||
|
|
||
|
for (ArrayList<Skeleton> skels : _minions.values())
|
||
|
{
|
||
|
for (Skeleton skel : skels)
|
||
|
{
|
||
|
if (skel.getHealth() > 0)
|
||
|
skel.setHealth(Math.min(skel.getMaxHealth(), skel.getHealth()+1));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|