2013-08-29 08:13:05 +02:00
|
|
|
package nautilus.game.arcade.kit.perks;
|
|
|
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
import org.bukkit.Color;
|
|
|
|
import org.bukkit.FireworkEffect;
|
|
|
|
import org.bukkit.FireworkEffect.Type;
|
|
|
|
import org.bukkit.Sound;
|
2013-09-02 06:40:06 +02:00
|
|
|
import org.bukkit.entity.Arrow;
|
2013-08-29 08:13:05 +02:00
|
|
|
import org.bukkit.entity.Chicken;
|
2013-09-01 04:18:48 +02:00
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
2013-08-29 08:13:05 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.block.Action;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
|
|
|
import org.bukkit.event.player.PlayerInteractEvent;
|
|
|
|
|
|
|
|
import mineplex.core.common.util.C;
|
2013-08-31 05:15:16 +02:00
|
|
|
import mineplex.core.common.util.F;
|
2013-08-29 08:13:05 +02:00
|
|
|
import mineplex.core.common.util.UtilAction;
|
|
|
|
import mineplex.core.common.util.UtilAlg;
|
|
|
|
import mineplex.core.common.util.UtilBlock;
|
|
|
|
import mineplex.core.common.util.UtilEnt;
|
2014-10-25 02:03:45 +02:00
|
|
|
import mineplex.core.common.util.UtilFirework;
|
2013-08-29 08:13:05 +02:00
|
|
|
import mineplex.core.common.util.UtilMath;
|
2015-01-29 01:54:59 +01:00
|
|
|
import mineplex.core.common.util.UtilParticle;
|
2013-08-29 08:13:05 +02:00
|
|
|
import mineplex.core.common.util.UtilPlayer;
|
|
|
|
import mineplex.core.common.util.UtilTime;
|
2015-01-29 01:54:59 +01:00
|
|
|
import mineplex.core.common.util.UtilParticle.ParticleType;
|
2013-08-29 08:13:05 +02:00
|
|
|
import mineplex.core.recharge.Recharge;
|
|
|
|
import mineplex.core.updater.UpdateType;
|
|
|
|
import mineplex.core.updater.event.UpdateEvent;
|
|
|
|
import nautilus.game.arcade.kit.Perk;
|
2015-01-29 01:54:59 +01:00
|
|
|
import nautilus.game.arcade.kit.SmashPerk;
|
2013-08-29 08:13:05 +02:00
|
|
|
import nautilus.game.arcade.kit.perks.data.ChickenMissileData;
|
|
|
|
|
2015-01-29 01:54:59 +01:00
|
|
|
public class PerkChickenRocket extends SmashPerk
|
2013-08-29 08:13:05 +02:00
|
|
|
{
|
|
|
|
private HashSet<ChickenMissileData> _data = new HashSet<ChickenMissileData>();
|
|
|
|
|
|
|
|
public PerkChickenRocket()
|
|
|
|
{
|
|
|
|
super("Chicken Missile", new String[]
|
|
|
|
{
|
|
|
|
C.cYellow + "Right-Click" + C.cGray + " with Axe to " + C.cGreen + "Chicken Missile",
|
|
|
|
C.cGreen + "Chicken Missile" + C.cGray + " instantly recharges if you hit a player."
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void Missile(PlayerInteractEvent event)
|
|
|
|
{
|
|
|
|
if (event.isCancelled())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (event.getAction() != Action.RIGHT_CLICK_AIR && event.getAction() != Action.RIGHT_CLICK_BLOCK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (UtilBlock.usable(event.getClickedBlock()))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (event.getPlayer().getItemInHand() == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!event.getPlayer().getItemInHand().getType().toString().contains("_AXE"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
Player player = event.getPlayer();
|
2015-01-29 01:54:59 +01:00
|
|
|
|
|
|
|
if (isSuperActive(player))
|
|
|
|
return;
|
2013-08-29 08:13:05 +02:00
|
|
|
|
|
|
|
if (!Kit.HasKit(player))
|
|
|
|
return;
|
|
|
|
|
2014-04-03 06:48:58 +02:00
|
|
|
if (!Recharge.Instance.use(player, GetName(), 7000, true, true))
|
2013-08-29 08:13:05 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
Manager.GetGame().CreatureAllowOverride = true;
|
|
|
|
Chicken ent = player.getWorld().spawn(player.getEyeLocation().add(player.getLocation().getDirection()), Chicken.class);
|
|
|
|
ent.getLocation().setPitch(0);
|
|
|
|
ent.getLocation().setYaw(player.getLocation().getYaw());
|
|
|
|
ent.setBaby();
|
|
|
|
ent.setAgeLock(true);
|
|
|
|
UtilEnt.Vegetate(ent);
|
|
|
|
Manager.GetGame().CreatureAllowOverride = false;
|
|
|
|
|
|
|
|
_data.add(new ChickenMissileData(player, ent));
|
2013-08-31 05:15:16 +02:00
|
|
|
|
|
|
|
//Inform
|
|
|
|
UtilPlayer.message(player, F.main("Game", "You used " + F.skill(GetName()) + "."));
|
2013-08-29 08:13:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void Update(UpdateEvent event)
|
|
|
|
{
|
|
|
|
if (event.getType() != UpdateType.TICK)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Iterator<ChickenMissileData> dataIterator = _data.iterator();
|
|
|
|
|
|
|
|
while (dataIterator.hasNext())
|
|
|
|
{
|
|
|
|
ChickenMissileData data = dataIterator.next();
|
|
|
|
|
|
|
|
data.Chicken.setVelocity(data.Direction);
|
|
|
|
data.Chicken.getWorld().playSound(data.Chicken.getLocation(), Sound.CHICKEN_HURT, 0.3f, 1.5f);
|
|
|
|
|
2013-09-01 04:18:48 +02:00
|
|
|
if (!UtilTime.elapsed(data.Time, 200))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-08-29 08:13:05 +02:00
|
|
|
boolean detonate = false;
|
|
|
|
|
|
|
|
if (UtilTime.elapsed(data.Time, 4000))
|
|
|
|
{
|
|
|
|
detonate = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-01 04:18:48 +02:00
|
|
|
//Hit Entity
|
|
|
|
for (Entity ent : data.Player.getWorld().getEntities())
|
2013-08-29 08:13:05 +02:00
|
|
|
{
|
2013-09-02 06:40:06 +02:00
|
|
|
if (ent instanceof Arrow)
|
|
|
|
if (((Arrow)ent).isOnGround())
|
|
|
|
continue;
|
|
|
|
|
2013-09-01 04:18:48 +02:00
|
|
|
if (ent.equals(data.Player))
|
2013-08-29 08:13:05 +02:00
|
|
|
continue;
|
2013-09-01 04:18:48 +02:00
|
|
|
|
|
|
|
if (ent.equals(data.Chicken))
|
2013-08-29 08:13:05 +02:00
|
|
|
continue;
|
|
|
|
|
2013-09-01 04:18:48 +02:00
|
|
|
if (UtilMath.offset(data.Chicken.getLocation(), ent.getLocation().add(0, 0.5, 0)) > 2)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ent instanceof Player)
|
|
|
|
if (!Manager.GetGame().IsAlive((Player)ent))
|
|
|
|
continue;
|
|
|
|
|
2013-08-29 08:13:05 +02:00
|
|
|
//Recharge
|
|
|
|
Recharge.Instance.useForce(data.Player, GetName(), -1);
|
|
|
|
|
|
|
|
detonate = true;
|
|
|
|
break;
|
|
|
|
}
|
2013-09-01 04:18:48 +02:00
|
|
|
|
2013-08-29 08:13:05 +02:00
|
|
|
//Hit Block
|
|
|
|
if (!detonate && data.HasHitBlock())
|
|
|
|
{
|
|
|
|
detonate = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (detonate)
|
|
|
|
{
|
|
|
|
//Damage
|
2013-09-01 04:18:48 +02:00
|
|
|
for (Entity ent : data.Player.getWorld().getEntities())
|
2013-08-29 08:13:05 +02:00
|
|
|
{
|
2013-09-01 04:18:48 +02:00
|
|
|
if (!(ent instanceof LivingEntity))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ent.equals(data.Player))
|
2013-08-29 08:13:05 +02:00
|
|
|
continue;
|
2013-09-01 04:18:48 +02:00
|
|
|
|
|
|
|
if (UtilMath.offset(data.Chicken.getLocation(), ent.getLocation().add(0, 0.5, 0)) > 3)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (ent instanceof Player)
|
|
|
|
if (!Manager.GetGame().IsAlive((Player)ent))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
LivingEntity livingEnt = (LivingEntity)ent;
|
2013-08-29 08:13:05 +02:00
|
|
|
|
|
|
|
//Damage Event
|
2013-09-01 04:18:48 +02:00
|
|
|
Manager.GetDamage().NewDamageEvent(livingEnt, data.Player, null,
|
2013-09-02 00:16:35 +02:00
|
|
|
DamageCause.PROJECTILE, 8, false, true, false,
|
2013-08-29 08:13:05 +02:00
|
|
|
data.Player.getName(), GetName());
|
|
|
|
|
2013-09-01 04:18:48 +02:00
|
|
|
UtilAction.velocity(livingEnt, UtilAlg.getTrajectory2d(data.Chicken, livingEnt), 1.6, true, 0.8, 0, 10, true);
|
2013-08-29 08:13:05 +02:00
|
|
|
}
|
|
|
|
|
2015-01-29 01:54:59 +01:00
|
|
|
//Effect
|
|
|
|
UtilParticle.PlayParticle(ParticleType.HUGE_EXPLOSION, data.Chicken.getLocation(), 0, 0, 0, 0, 1);
|
|
|
|
data.Chicken.getWorld().playSound(data.Chicken.getLocation(), Sound.EXPLODE, 2f, 1.2f);
|
2013-08-29 08:13:05 +02:00
|
|
|
|
|
|
|
//Firework
|
2014-10-25 02:03:45 +02:00
|
|
|
UtilFirework.playFirework(data.Chicken.getLocation().add(0, 0.6, 0), Type.BALL, Color.WHITE, false, false);
|
|
|
|
|
2013-08-29 08:13:05 +02:00
|
|
|
|
|
|
|
data.Chicken.remove();
|
|
|
|
dataIterator.remove();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|