768f57ae5e
Compass: no longer teleports if not holding compass (on click) SSM: various balance changes.
195 lines
4.7 KiB
Java
195 lines
4.7 KiB
Java
package nautilus.game.arcade.kit.perks;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
|
|
import org.bukkit.Sound;
|
|
import org.bukkit.entity.Entity;
|
|
import org.bukkit.entity.LivingEntity;
|
|
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 org.bukkit.util.Vector;
|
|
|
|
import mineplex.core.common.util.C;
|
|
import mineplex.core.common.util.F;
|
|
import mineplex.core.common.util.UtilAction;
|
|
import mineplex.core.common.util.UtilBlock;
|
|
import mineplex.core.common.util.UtilMath;
|
|
import mineplex.core.common.util.UtilPlayer;
|
|
import mineplex.core.disguise.disguises.DisguiseBase;
|
|
import mineplex.core.disguise.disguises.DisguiseCreeper;
|
|
import mineplex.core.recharge.Recharge;
|
|
import mineplex.core.updater.UpdateType;
|
|
import mineplex.core.updater.event.UpdateEvent;
|
|
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
|
|
import nautilus.game.arcade.kit.Perk;
|
|
|
|
public class PerkCreeperExplode extends Perk
|
|
{
|
|
private HashMap<Player, Long> _active = new HashMap<Player, Long>();
|
|
|
|
public PerkCreeperExplode()
|
|
{
|
|
super("Explode", new String[]
|
|
{
|
|
C.cYellow + "Right-Click" + C.cGray + " with Shovel use " + C.cGreen + "Explosive Leap"
|
|
});
|
|
}
|
|
|
|
@EventHandler
|
|
public void Activate(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().getType().toString().contains("_SPADE"))
|
|
return;
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
if (!Kit.HasKit(player))
|
|
return;
|
|
|
|
if (!Recharge.Instance.use(player, GetName(), 8000, true))
|
|
return;
|
|
|
|
_active.put(player, System.currentTimeMillis());
|
|
|
|
IncreaseSize(player);
|
|
|
|
UtilPlayer.message(player, F.main("Skill", "You are charging " + F.skill(GetName()) + "."));
|
|
}
|
|
|
|
@EventHandler
|
|
public void Update(UpdateEvent event)
|
|
{
|
|
if (event.getType() != UpdateType.TICK)
|
|
return;
|
|
|
|
Iterator<Player> chargeIterator = _active.keySet().iterator();
|
|
|
|
while (chargeIterator.hasNext())
|
|
{
|
|
Player player = chargeIterator.next();
|
|
|
|
double elapsed = (System.currentTimeMillis() - _active.get(player))/1000d;
|
|
|
|
//Idle in Air
|
|
player.setVelocity(new Vector(0,0,0));
|
|
|
|
//Sound
|
|
player.getWorld().playSound(player.getLocation(), Sound.CREEPER_HISS, (float)(0.5 + elapsed), (float)(0.5 + elapsed));
|
|
|
|
IncreaseSize(player);
|
|
|
|
player.setExp(Math.min(0.99f, (float)(elapsed/1.5)));
|
|
|
|
//Not Detonated
|
|
if (elapsed < 1.5)
|
|
continue;
|
|
|
|
chargeIterator.remove();
|
|
|
|
//Unpower
|
|
DecreaseSize(player);
|
|
|
|
//Explode
|
|
player.getWorld().createExplosion(player.getLocation(), (float) 2.0);
|
|
|
|
//Damage
|
|
for (Entity ent : player.getWorld().getEntities())
|
|
{
|
|
if (!(ent instanceof LivingEntity))
|
|
continue;
|
|
|
|
if (ent.equals(player))
|
|
continue;
|
|
|
|
double dist = UtilMath.offset(player.getLocation(), ent.getLocation());
|
|
|
|
double maxRange = 8;
|
|
|
|
if (dist > maxRange)
|
|
continue;
|
|
|
|
if (ent instanceof Player)
|
|
if (!Manager.GetGame().IsAlive((Player)ent))
|
|
continue;
|
|
|
|
LivingEntity livingEnt = (LivingEntity)ent;
|
|
|
|
double scale = 0.4 + 0.6 * ((maxRange-dist)/maxRange);
|
|
|
|
//Damage Event
|
|
Manager.GetDamage().NewDamageEvent(livingEnt, player, null,
|
|
DamageCause.CUSTOM, 20 * scale, true, true, false,
|
|
player.getName(), GetName());
|
|
}
|
|
|
|
//Velocity
|
|
UtilAction.velocity(player, 1.8, 0.2, 1.4, true);
|
|
|
|
//Inform
|
|
UtilPlayer.message(player, F.main("Skill", "You used " + F.skill(GetName()) + "."));
|
|
}
|
|
}
|
|
|
|
public DisguiseCreeper GetDisguise(Player player)
|
|
{
|
|
DisguiseBase disguise = Manager.GetDisguise().getDisguise(player);
|
|
if (disguise == null)
|
|
return null;
|
|
|
|
if (!(disguise instanceof DisguiseCreeper))
|
|
return null;
|
|
|
|
return (DisguiseCreeper)disguise;
|
|
}
|
|
|
|
public int GetSize(Player player)
|
|
{
|
|
DisguiseCreeper creeper = GetDisguise(player);
|
|
if (creeper == null) return 0;
|
|
|
|
return creeper.bV();
|
|
}
|
|
|
|
public void DecreaseSize(Player player)
|
|
{
|
|
DisguiseCreeper creeper = GetDisguise(player);
|
|
if (creeper == null) return;
|
|
|
|
creeper.a(-1);
|
|
|
|
Manager.GetDisguise().updateDisguise(creeper);
|
|
}
|
|
|
|
public void IncreaseSize(Player player)
|
|
{
|
|
DisguiseCreeper creeper = GetDisguise(player);
|
|
if (creeper == null) return;
|
|
|
|
creeper.a(1);
|
|
|
|
Manager.GetDisguise().updateDisguise(creeper);
|
|
}
|
|
|
|
@EventHandler
|
|
public void Knockback(CustomDamageEvent event)
|
|
{
|
|
if (event.GetReason() == null || !event.GetReason().contains(GetName()))
|
|
return;
|
|
|
|
event.AddKnockback(GetName(), 2.5);
|
|
}
|
|
}
|