2013-10-04 23:49:05 +02:00
|
|
|
package nautilus.game.arcade.kit.perks;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
import org.bukkit.Location;
|
2013-11-22 08:40:38 +01:00
|
|
|
import org.bukkit.Material;
|
2013-10-04 23:49:05 +02:00
|
|
|
import org.bukkit.Sound;
|
|
|
|
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftCreature;
|
2013-11-22 08:40:38 +01:00
|
|
|
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftSkeleton;
|
|
|
|
import org.bukkit.entity.Entity;
|
2013-10-04 23:49:05 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.entity.Skeleton;
|
2013-11-23 01:03:52 +01:00
|
|
|
import org.bukkit.entity.Wolf;
|
2013-10-04 23:49:05 +02:00
|
|
|
import org.bukkit.event.EventHandler;
|
2013-11-22 08:40:38 +01:00
|
|
|
import org.bukkit.event.entity.EntityCombustEvent;
|
2013-10-04 23:49:05 +02:00
|
|
|
import org.bukkit.event.entity.EntityTargetEvent;
|
2013-11-23 01:03:52 +01:00
|
|
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
2013-10-04 23:49:05 +02:00
|
|
|
|
|
|
|
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;
|
2013-11-22 08:40:38 +01:00
|
|
|
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
|
2013-10-04 23:49:05 +02:00
|
|
|
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;
|
2013-11-22 23:28:27 +01:00
|
|
|
private int _maxDist = 8;
|
2013-10-04 23:49:05 +02:00
|
|
|
|
|
|
|
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;
|
2013-11-22 08:40:38 +01:00
|
|
|
|
2013-10-04 23:49:05 +02:00
|
|
|
if (!(event.GetEvent().getEntity() instanceof Player))
|
|
|
|
return;
|
2013-11-22 08:40:38 +01:00
|
|
|
|
2013-10-04 23:49:05 +02:00
|
|
|
Player killer = UtilPlayer.searchExact(event.GetLog().GetKiller().GetName());
|
|
|
|
if (killer == null)
|
|
|
|
return;
|
2013-11-22 08:40:38 +01:00
|
|
|
|
2013-10-04 23:49:05 +02:00
|
|
|
if (!Kit.HasKit(killer))
|
|
|
|
return;
|
2013-11-22 08:40:38 +01:00
|
|
|
|
2013-10-04 23:49:05 +02:00
|
|
|
Player killed = (Player)event.GetEvent().getEntity();
|
2013-11-22 08:40:38 +01:00
|
|
|
|
2013-10-04 23:49:05 +02:00
|
|
|
Manager.GetGame().CreatureAllowOverride = true;
|
|
|
|
Skeleton skel = killer.getWorld().spawn(killed.getLocation(), Skeleton.class);
|
|
|
|
Manager.GetGame().CreatureAllowOverride = false;
|
|
|
|
|
2013-11-22 13:12:39 +01:00
|
|
|
UtilEnt.removeGoalSelectors(skel);
|
2013-11-22 23:28:27 +01:00
|
|
|
|
2013-10-04 23:49:05 +02:00
|
|
|
skel.setMaxHealth(30);
|
|
|
|
skel.setHealth(skel.getMaxHealth());
|
2013-11-22 08:40:38 +01:00
|
|
|
|
2013-10-04 23:49:05 +02:00
|
|
|
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());
|
2013-11-22 08:40:38 +01:00
|
|
|
|
2013-10-04 23:49:05 +02:00
|
|
|
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());
|
2013-11-22 23:28:27 +01:00
|
|
|
|
2013-11-22 08:40:38 +01:00
|
|
|
skel.getEquipment().setItemInHandDropChance(1f);
|
|
|
|
skel.getEquipment().setHelmetDropChance(1f);
|
|
|
|
skel.getEquipment().setChestplateDropChance(1f);
|
|
|
|
skel.getEquipment().setLeggingsDropChance(1f);
|
|
|
|
skel.getEquipment().setBootsDropChance(1f);
|
|
|
|
|
2013-10-04 23:49:05 +02:00
|
|
|
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);
|
|
|
|
}
|
2013-11-22 08:40:38 +01:00
|
|
|
|
2013-10-04 23:49:05 +02:00
|
|
|
@EventHandler
|
|
|
|
public void TargetCancel(EntityTargetEvent event)
|
|
|
|
{
|
|
|
|
if (!_minions.containsKey(event.getTarget()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (_minions.get(event.getTarget()).contains(event.getEntity()))
|
|
|
|
event.setCancelled(true);
|
2013-11-22 23:28:27 +01:00
|
|
|
|
|
|
|
for (Player player : _minions.keySet())
|
|
|
|
{
|
|
|
|
for (Skeleton skel : _minions.get(player))
|
|
|
|
{
|
|
|
|
if (event.getEntity().equals(skel))
|
|
|
|
{
|
|
|
|
if (UtilMath.offset(skel, player) > _maxDist)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-10-04 23:49:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
2013-11-22 08:40:38 +01:00
|
|
|
public void MinionUpdate(UpdateEvent event)
|
2013-10-04 23:49:05 +02:00
|
|
|
{
|
2013-11-22 08:40:38 +01:00
|
|
|
if (event.getType() != UpdateType.SEC)
|
2013-10-04 23:49:05 +02:00
|
|
|
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;
|
|
|
|
}
|
2013-11-22 08:40:38 +01:00
|
|
|
|
2013-10-04 23:49:05 +02:00
|
|
|
//Return to Owner
|
2013-11-22 08:40:38 +01:00
|
|
|
double range = 4;
|
2013-11-22 23:28:27 +01:00
|
|
|
if (skel.getTarget() != null || ((CraftSkeleton)skel).getHandle().getGoalTarget() != null)
|
2013-11-22 08:40:38 +01:00
|
|
|
{
|
2013-11-22 23:28:27 +01:00
|
|
|
range = _maxDist;
|
2013-11-22 08:40:38 +01:00
|
|
|
}
|
|
|
|
|
2013-10-04 23:49:05 +02:00
|
|
|
if (UtilMath.offset(skel, player) > range)
|
|
|
|
{
|
|
|
|
float speed = 1f;
|
|
|
|
if (player.isSprinting())
|
|
|
|
speed = 1.4f;
|
|
|
|
|
|
|
|
//Move
|
2013-11-22 23:28:27 +01:00
|
|
|
Location target = skel.getLocation().add(UtilAlg.getTrajectory(skel, player).multiply(3));
|
|
|
|
|
2013-10-04 23:49:05 +02:00
|
|
|
EntityCreature ec = ((CraftCreature)skel).getHandle();
|
|
|
|
Navigation nav = ec.getNavigation();
|
|
|
|
nav.a(target.getX(), target.getY(), target.getZ(), speed);
|
|
|
|
|
|
|
|
skel.setTarget(null);
|
2013-11-22 08:40:38 +01:00
|
|
|
((CraftSkeleton)skel).getHandle().setGoalTarget(null);
|
2013-10-04 23:49:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-22 08:40:38 +01:00
|
|
|
public boolean IsMinion(Entity ent)
|
|
|
|
{
|
|
|
|
for (ArrayList<Skeleton> skels : _minions.values())
|
|
|
|
{
|
|
|
|
for (Skeleton skel : skels)
|
|
|
|
{
|
|
|
|
if (ent.equals(skel))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void Combust(EntityCombustEvent event)
|
|
|
|
{
|
|
|
|
if (IsMinion(event.getEntity()))
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void Damage(CustomDamageEvent event)
|
|
|
|
{
|
|
|
|
if (event.GetDamagerEntity(true) == null)
|
|
|
|
return;
|
2013-11-22 23:28:27 +01:00
|
|
|
|
2013-11-22 08:40:38 +01:00
|
|
|
if (!IsMinion(event.GetDamagerEntity(true)))
|
|
|
|
return;
|
2013-11-22 23:28:27 +01:00
|
|
|
|
2013-11-22 08:40:38 +01:00
|
|
|
double damage = 4;
|
2013-11-22 23:28:27 +01:00
|
|
|
|
2013-11-22 08:40:38 +01:00
|
|
|
if (event.GetDamagerEntity(true) instanceof Skeleton)
|
|
|
|
{
|
|
|
|
Skeleton skel = (Skeleton)event.GetDamagerEntity(true);
|
2013-11-22 23:28:27 +01:00
|
|
|
|
2013-11-22 08:40:38 +01:00
|
|
|
if (skel.getEquipment().getItemInHand() != null)
|
|
|
|
{
|
|
|
|
if (skel.getEquipment().getItemInHand().getType() == Material.STONE_SWORD) damage = 5;
|
|
|
|
else if (skel.getEquipment().getItemInHand().getType() == Material.IRON_SWORD) damage = 6;
|
|
|
|
else if (skel.getEquipment().getItemInHand().getType() == Material.GOLD_SWORD) damage = 6;
|
|
|
|
else if (skel.getEquipment().getItemInHand().getType() == Material.DIAMOND_SWORD) damage = 7;
|
2013-11-22 23:28:27 +01:00
|
|
|
|
2013-11-22 08:40:38 +01:00
|
|
|
else if (skel.getEquipment().getItemInHand().getType() == Material.IRON_AXE) damage = 5;
|
|
|
|
else if (skel.getEquipment().getItemInHand().getType() == Material.GOLD_AXE) damage = 5;
|
|
|
|
else if (skel.getEquipment().getItemInHand().getType() == Material.DIAMOND_AXE) damage = 6;
|
|
|
|
}
|
|
|
|
}
|
2013-11-22 23:28:27 +01:00
|
|
|
|
2013-11-22 08:40:38 +01:00
|
|
|
if (event.GetProjectile() != null)
|
|
|
|
damage = 6;
|
2013-11-22 23:28:27 +01:00
|
|
|
|
2013-11-22 08:40:38 +01:00
|
|
|
event.AddMod("Skeleton Minion", "Negate", -event.GetDamageInitial(), false);
|
|
|
|
event.AddMod("Skeleton Minion", "Damage", damage, false);
|
|
|
|
}
|
2013-11-23 01:03:52 +01:00
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void PlayerDeath(PlayerDeathEvent event)
|
|
|
|
{
|
|
|
|
ArrayList<Skeleton> skels = _minions.remove(event.getEntity());
|
|
|
|
|
|
|
|
if (skels == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (Skeleton skel : skels)
|
|
|
|
skel.remove();
|
|
|
|
|
|
|
|
skels.clear();
|
|
|
|
}
|
2013-10-04 23:49:05 +02:00
|
|
|
}
|