Mineplex2018-withcommit/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/kit/perks/PerkSkeletons.java

295 lines
7.2 KiB
Java
Raw Normal View History

package nautilus.game.arcade.kit.perks;
2014-08-18 22:41:16 +02:00
import mineplex.core.common.util.*;
import mineplex.core.updater.*;
import mineplex.core.updater.event.*;
import mineplex.minecraft.game.core.combat.event.*;
import mineplex.minecraft.game.core.damage.*;
import nautilus.game.arcade.kit.*;
import net.minecraft.server.v1_7_R4.*;
import org.bukkit.*;
2013-11-22 08:40:38 +01:00
import org.bukkit.Material;
2014-08-18 22:41:16 +02:00
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.v1_7_R4.entity.*;
2013-11-22 08:40:38 +01:00
import org.bukkit.entity.Entity;
2014-08-18 22:41:16 +02:00
import org.bukkit.entity.*;
import org.bukkit.event.*;
import org.bukkit.event.entity.*;
import org.bukkit.event.player.*;
import java.util.*;
public class PerkSkeletons extends Perk
{
2014-08-18 22:41:16 +02:00
public static class MinionSpawnEvent extends PlayerEvent
{
private static final HandlerList handlers = new HandlerList();
public static HandlerList getHandlerList()
{
return handlers;
}
private final PerkSkeletons _perkSkeletons;
public MinionSpawnEvent(Player who, PerkSkeletons perkSkeletons)
{
super(who);
_perkSkeletons = perkSkeletons;
}
@Override
public HandlerList getHandlers()
{
return getHandlerList();
}
public PerkSkeletons getPerkSkeletons()
{
return _perkSkeletons;
}
}
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;
2014-08-18 22:41:16 +02:00
public PerkSkeletons(boolean name)
{
2014-08-18 22:41:16 +02:00
super("Skeleton Minons", new String[]
{
2014-08-18 22:41:16 +02:00
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
if (!(event.GetEvent().getEntity() instanceof Player))
return;
2013-11-22 08:40:38 +01:00
Player killer = UtilPlayer.searchExact(event.GetLog().GetKiller().GetName());
if (killer == null)
return;
2013-11-22 08:40:38 +01:00
if (!Kit.HasKit(killer))
return;
2013-11-22 08:40:38 +01:00
2014-08-18 22:41:16 +02:00
Player killed = (Player) event.GetEvent().getEntity();
2013-11-22 08:40:38 +01: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
skel.setMaxHealth(30);
skel.setHealth(skel.getMaxHealth());
2013-11-22 08:40:38 +01: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
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);
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);
2014-08-18 22:41:16 +02:00
Bukkit.getPluginManager().callEvent(new MinionSpawnEvent(killer, this));
}
2013-11-22 08:40:38 +01: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)
{
2014-08-18 22:41:16 +02:00
2013-11-22 23:28:27 +01:00
}
}
}
}
}
@EventHandler
2013-11-22 08:40:38 +01:00
public void MinionUpdate(UpdateEvent event)
{
2013-11-22 08:40:38 +01:00
if (event.getType() != UpdateType.SEC)
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;
2014-08-18 22:41:16 +02:00
}
2013-11-22 08:40:38 +01:00
//Return to Owner
2013-11-22 08:40:38 +01:00
double range = 4;
2014-08-18 22:41:16 +02: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
}
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));
2014-08-18 22:41:16 +02:00
EntityCreature ec = ((CraftCreature) skel).getHandle();
Navigation nav = ec.getNavigation();
nav.a(target.getX(), target.getY(), target.getZ(), speed);
skel.setTarget(null);
2014-08-18 22:41:16 +02:00
((CraftSkeleton) skel).getHandle().setGoalTarget(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)
2014-08-18 22:41:16 +02:00
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)
{
2014-08-18 22:41:16 +02:00
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)
{
2014-08-18 22:41:16 +02:00
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;
2013-11-22 08:40:38 +01:00
}
}
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);
}
2014-08-18 22:41:16 +02:00
2013-11-23 01:03:52 +01:00
@EventHandler
public void PlayerDeath(PlayerDeathEvent event)
{
ArrayList<Skeleton> skels = _minions.remove(event.getEntity());
2014-08-18 22:41:16 +02:00
2013-11-23 01:03:52 +01:00
if (skels == null)
return;
2014-08-18 22:41:16 +02:00
2013-11-23 01:03:52 +01:00
for (Skeleton skel : skels)
skel.remove();
2014-08-18 22:41:16 +02:00
2013-11-23 01:03:52 +01:00
skels.clear();
}
2014-08-18 22:41:16 +02:00
public List<Skeleton> getSkeletons(Player player)
{
return _minions.get(player);
}
}