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.Chicken;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
import org.bukkit.event.block.Action;
|
|
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
|
|
|
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.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;
|
|
|
|
|
|
|
|
if (!Recharge.Instance.use(player, GetName(), 6000, true))
|
|
|
|
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);
|
|
|
|
|
|
|
|
boolean detonate = false;
|
|
|
|
|
|
|
|
if (UtilTime.elapsed(data.Time, 4000))
|
|
|
|
{
|
|
|
|
detonate = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//Hit Player
|
|
|
|
for (Player other : Manager.GetGame().GetPlayers(true))
|
|
|
|
{
|
|
|
|
if (other.equals(data.Player))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (UtilMath.offset(data.Chicken.getLocation(), other.getLocation().add(0, 0.5, 0)) > 2)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
//Recharge
|
|
|
|
Recharge.Instance.useForce(data.Player, GetName(), -1);
|
|
|
|
|
|
|
|
detonate = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Hit Block
|
|
|
|
if (!detonate && data.HasHitBlock())
|
|
|
|
{
|
|
|
|
detonate = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (detonate)
|
|
|
|
{
|
|
|
|
//Damage
|
|
|
|
for (Player other : UtilPlayer.getNearby(data.Chicken.getLocation(), 3))
|
|
|
|
{
|
|
|
|
if (!Manager.GetGame().IsAlive(other))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
//Damage Event
|
|
|
|
Manager.GetDamage().NewDamageEvent(other, data.Player, null,
|
|
|
|
DamageCause.PROJECTILE, 10, false, true, false,
|
|
|
|
data.Player.getName(), GetName());
|
|
|
|
|
|
|
|
UtilAction.velocity(other, UtilAlg.getTrajectory2d(data.Chicken, other), 1.6, true, 0.8, 0, 10, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
//Explosion
|
|
|
|
data.Chicken.getWorld().createExplosion(data.Chicken.getLocation(), 1.8f);
|
|
|
|
|
|
|
|
//Firework
|
|
|
|
FireworkEffect effect = FireworkEffect.builder().flicker(false).withColor(Color.WHITE).with(Type.BALL).trail(false).build();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Manager.GetFirework().playFirework(data.Chicken.getLocation().add(0, 0.6, 0), effect);
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
data.Chicken.remove();
|
|
|
|
dataIterator.remove();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void ExplosionDamageCancel(EntityDamageEvent event)
|
|
|
|
{
|
|
|
|
if (event.getCause() == DamageCause.ENTITY_EXPLOSION || event.getCause() == DamageCause.BLOCK_EXPLOSION)
|
|
|
|
{
|
|
|
|
for (ChickenMissileData data : _data)
|
|
|
|
{
|
|
|
|
if (UtilMath.offset(data.Chicken, event.getEntity()) < 8)
|
|
|
|
{
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|