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.Material; import org.bukkit.Sound; import org.bukkit.craftbukkit.v1_6_R3.entity.CraftCreature; import org.bukkit.craftbukkit.v1_6_R3.entity.CraftSkeleton; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.entity.Skeleton; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityCombustEvent; 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 mineplex.minecraft.game.core.damage.CustomDamageEvent; 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> _minions = new HashMap>(); 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; UtilEnt.removeGoalSelectors(skel); 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()); skel.getEquipment().setItemInHandDropChance(1f); skel.getEquipment().setHelmetDropChance(1f); skel.getEquipment().setChestplateDropChance(1f); skel.getEquipment().setLeggingsDropChance(1f); skel.getEquipment().setBootsDropChance(1f); if (_name) { skel.setCustomName("Skeletal " + UtilEnt.getName(event.GetEvent().getEntity())); skel.setCustomNameVisible(true); } if (!_minions.containsKey(killer)) _minions.put(killer, new ArrayList()); _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 MinionUpdate(UpdateEvent event) { if (event.getType() != UpdateType.SEC) return; for (Player player : _minions.keySet()) { Iterator skelIterator = _minions.get(player).iterator(); while (skelIterator.hasNext()) { Skeleton skel = skelIterator.next(); //Dead if (!skel.isValid()) { skelIterator.remove(); continue; } //Return to Owner double range = 4; if (skel.getTarget() != null) { range = 8; System.out.println("A: " + UtilEnt.getName(skel.getTarget())); } if (((CraftSkeleton)skel).getHandle().getGoalTarget() != null) { range = 8; System.out.println("B: " + ((CraftSkeleton)skel).getHandle().getGoalTarget()); } 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); ((CraftSkeleton)skel).getHandle().setGoalTarget(null); System.out.println("OUT OF RANGE! RETURN HOME MY FRIEND"); } } } } @EventHandler public void Heal(UpdateEvent event) { if (event.getType() != UpdateType.SEC) return; for (ArrayList skels : _minions.values()) { for (Skeleton skel : skels) { if (skel.getHealth() > 0) skel.setHealth(Math.min(skel.getMaxHealth(), skel.getHealth()+1)); } } } public boolean IsMinion(Entity ent) { for (ArrayList 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; if (!IsMinion(event.GetDamagerEntity(true))) return; double damage = 4; if (event.GetDamagerEntity(true) instanceof Skeleton) { Skeleton skel = (Skeleton)event.GetDamagerEntity(true); 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; 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; } } if (event.GetProjectile() != null) damage = 6; event.AddMod("Skeleton Minion", "Negate", -event.GetDamageInitial(), false); event.AddMod("Skeleton Minion", "Damage", damage, false); } }