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

194 lines
5.1 KiB
Java
Raw Normal View History

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;
import org.bukkit.entity.Arrow;
2013-08-29 08:13:05 +02:00
import org.bukkit.entity.Chicken;
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;
import mineplex.core.common.util.UtilFirework;
2013-08-29 08:13:05 +02:00
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.recharge.Recharge;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.kit.Perk;
import nautilus.game.arcade.kit.perks.data.ChickenMissileData;
public class PerkChickenRocket extends Perk
{
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();
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);
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
{
//Hit Entity
for (Entity ent : data.Player.getWorld().getEntities())
2013-08-29 08:13:05 +02:00
{
if (ent instanceof Arrow)
if (((Arrow)ent).isOnGround())
continue;
if (ent.equals(data.Player))
2013-08-29 08:13:05 +02:00
continue;
if (ent.equals(data.Chicken))
2013-08-29 08:13:05 +02:00
continue;
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-08-29 08:13:05 +02:00
//Hit Block
if (!detonate && data.HasHitBlock())
{
detonate = true;
}
}
if (detonate)
{
//Damage
for (Entity ent : data.Player.getWorld().getEntities())
2013-08-29 08:13:05 +02:00
{
if (!(ent instanceof LivingEntity))
continue;
if (ent.equals(data.Player))
2013-08-29 08:13:05 +02:00
continue;
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
Manager.GetDamage().NewDamageEvent(livingEnt, data.Player, null,
DamageCause.PROJECTILE, 8, false, true, false,
2013-08-29 08:13:05 +02:00
data.Player.getName(), GetName());
UtilAction.velocity(livingEnt, UtilAlg.getTrajectory2d(data.Chicken, livingEnt), 1.6, true, 0.8, 0, 10, true);
2013-08-29 08:13:05 +02:00
}
//Explosion
data.Chicken.getWorld().createExplosion(data.Chicken.getLocation(), 1.8f);
//Firework
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;
}
}
}
}