HitBox support for disguises

Squid hitbox added
Changed squid swimming!
This commit is contained in:
Chiss 2013-09-24 08:56:09 +10:00
parent ea5cc7161a
commit 064dd97d00
10 changed files with 109 additions and 46 deletions

View File

@ -284,8 +284,19 @@ public class UtilEnt
return ents;
}
public static boolean hitBox(Location loc, LivingEntity ent, double mult)
public static boolean hitBox(Location loc, LivingEntity ent, double mult, EntityType disguise)
{
if (disguise != null)
{
if (disguise == EntityType.SQUID)
{
if (UtilMath.offset(loc, ent.getLocation().add(0, 0.4, 0)) < 0.6 * mult)
return true;
return false;
}
}
if (ent instanceof Player)
{
Player player = (Player)ent;
@ -304,7 +315,7 @@ public class UtilEnt
}
else
if (loc.getY() > ent.getLocation().getY() && loc.getY() < ent.getLocation().getY() + 1)
if (UtilMath.offset2d(loc, ent.getLocation()) < 0.5)
if (UtilMath.offset2d(loc, ent.getLocation()) < 0.5 * mult)
return true;

View File

@ -4,6 +4,7 @@ import java.util.HashSet;
import java.util.WeakHashMap;
import mineplex.core.MiniPlugin;
import mineplex.core.disguise.DisguiseManager;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.updater.UpdateType;
@ -31,7 +32,15 @@ public class ProjectileManager extends MiniPlugin
{
_thrown.put(thrown, new ProjectileUser(this, thrown, thrower, callback,
expireTime, hitPlayer, hitBlock, idle, false,
null, 1f, 1f, null, 0, null, hitboxMult));
null, 1f, 1f, null, 0, null, hitboxMult, null));
}
public void AddThrow(Entity thrown, LivingEntity thrower, IThrown callback,
long expireTime, boolean hitPlayer, boolean hitBlock, boolean idle, double hitboxMult, DisguiseManager disguise)
{
_thrown.put(thrown, new ProjectileUser(this, thrown, thrower, callback,
expireTime, hitPlayer, hitBlock, idle, false,
null, 1f, 1f, null, 0, null, hitboxMult, disguise));
}
public void AddThrow(Entity thrown, LivingEntity thrower, IThrown callback,
@ -39,7 +48,7 @@ public class ProjectileManager extends MiniPlugin
{
_thrown.put(thrown, new ProjectileUser(this, thrown, thrower, callback,
expireTime, hitPlayer, hitBlock, idle, pickup,
null, 1f, 1f, null, 0, null, hitboxMult));
null, 1f, 1f, null, 0, null, hitboxMult, null));
}
public void AddThrow(Entity thrown, LivingEntity thrower, IThrown callback,
@ -48,7 +57,7 @@ public class ProjectileManager extends MiniPlugin
{
_thrown.put(thrown, new ProjectileUser(this, thrown, thrower, callback,
expireTime, hitPlayer, hitBlock, idle, false,
sound, soundVolume, soundPitch, effect, effectData, effectRate, hitboxMult));
sound, soundVolume, soundPitch, effect, effectData, effectRate, hitboxMult, null));
}
@EventHandler

View File

@ -4,6 +4,8 @@ import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.updater.UpdateType;
import mineplex.core.common.util.UtilBlock;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.disguise.DisguiseManager;
import mineplex.core.disguise.disguises.DisguiseSquid;
import org.bukkit.Effect;
import org.bukkit.GameMode;
@ -12,6 +14,7 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_6_R3.CraftWorld;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -37,11 +40,12 @@ public class ProjectileUser
private UpdateType _effectRate = UpdateType.TICK;
private double _hitboxMult = 1;
private DisguiseManager _disguise;
public ProjectileUser(ProjectileManager throwInput, Entity thrown, LivingEntity thrower, IThrown callback,
long expireTime, boolean hitPlayer, boolean hitBlock, boolean idle, boolean pickup,
Sound sound, float soundVolume, float soundPitch, Effect effect, int effectData, UpdateType effectRate,
double hitboxMult)
double hitboxMult, DisguiseManager disguise)
{
Throw = throwInput;
@ -63,6 +67,7 @@ public class ProjectileUser
_effectRate = effectRate;
_hitboxMult = hitboxMult;
_disguise = disguise;
}
public void Effect(UpdateEvent event)
@ -108,8 +113,15 @@ public class ProjectileUser
if (((Player)ent).getGameMode() == GameMode.CREATIVE)
continue;
EntityType disguise = null;
if (_disguise != null && _disguise.getDisguise(ent) != null)
{
if (_disguise.getDisguise(ent) instanceof DisguiseSquid)
disguise = EntityType.SQUID;
}
//Hit Player
if (UtilEnt.hitBox(_thrown.getLocation(), ent, _hitboxMult))
if (UtilEnt.hitBox(_thrown.getLocation(), ent, _hitboxMult, disguise))
{
_callback.Collide(ent, null, this);
return true;

View File

@ -80,7 +80,7 @@ public class Fire extends MiniPlugin
}
if (!UtilEnt.hitBox(fire.getLocation(), ent, 1.5))
if (!UtilEnt.hitBox(fire.getLocation(), ent, 1.5, null))
continue;
collided.put(fire, ent);
@ -120,7 +120,7 @@ public class Fire extends MiniPlugin
return;
}
if (!UtilEnt.hitBox(fire.getLocation(), player, 1.5))
if (!UtilEnt.hitBox(fire.getLocation(), player, 1.5, null))
return;
//Remove

View File

@ -88,10 +88,8 @@ public class PerkSquidRifle extends Perk implements IThrown
Firework fw = Manager.GetFirework().launchFirework(player.getEyeLocation().subtract(0, 0.5, 0).add(player.getLocation().getDirection()), effect, vel);
_fireworks.put(fw, vel);
Manager.GetProjectile().AddThrow(fw, player, this, -1, true, true, true,
null, 1f, 1f,
null, 1, UpdateType.SLOW,
2.5d);
//Projectile
Manager.GetProjectile().AddThrow(fw, player, this, -1, true, true, true, 2d, Manager.GetDisguise());
}
catch (Exception e)
{

View File

@ -95,10 +95,8 @@ public class PerkSquidShotgun extends Perk implements IThrown
Firework fw = Manager.GetFirework().launchFirework(player.getEyeLocation().subtract(0, 0.5, 0).add(player.getLocation().getDirection()), effect, vel);
_fireworks.put(fw, vel);
Manager.GetProjectile().AddThrow(fw, player, this, -1, true, true, true,
null, 1f, 1f,
null, 1, UpdateType.SLOW,
2.5d);
//Projectile
Manager.GetProjectile().AddThrow(fw, player, this, -1, true, true, true, 2d, Manager.GetDisguise());
}
catch (Exception e)
{

View File

@ -88,10 +88,8 @@ public class PerkSquidSniper extends Perk implements IThrown
Firework fw = Manager.GetFirework().launchFirework(player.getEyeLocation().subtract(0, 0.5, 0).add(player.getLocation().getDirection()), effect, vel);
_fireworks.put(fw, vel);
Manager.GetProjectile().AddThrow(fw, player, this, -1, true, true, true,
null, 1f, 1f,
null, 1, UpdateType.SLOW,
3d);
//Projectile
Manager.GetProjectile().AddThrow(fw, player, this, -1, true, true, true, 2d, Manager.GetDisguise());
}
catch (Exception e)
{

View File

@ -1,7 +1,6 @@
package nautilus.game.arcade.kit.perks;
import java.util.HashMap;
import java.util.Iterator;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
@ -18,16 +17,33 @@ import nautilus.game.arcade.kit.Perk;
public class PerkSquidSwim extends Perk
{
private HashMap<Player, Long> _push = new HashMap<Player, Long>();
private HashMap<Player, Long> _active = new HashMap<Player, Long>();
public PerkSquidSwim()
{
super("Swimming", new String[]
{
C.cYellow + "Tap Crouch" + C.cGray + " to use " + C.cGreen + "Squid Thrust"
C.cYellow + "Tap Crouch" + C.cGray + " to use " + C.cGreen + "Squid Thrust",
C.cYellow + "Hold Crouch" + C.cGray + " to use " + C.cGreen + "Squid Swim"
});
}
@EventHandler
public void EnergyUpdate(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
for (Player player : Manager.GetGame().GetPlayers(true))
{
if (!Kit.HasKit(player))
continue;
player.setExp((float) Math.min(0.999, player.getExp()+0.007));
}
}
@EventHandler
public void Use(PlayerToggleSneakEvent event)
{
@ -36,17 +52,30 @@ public class PerkSquidSwim extends Perk
Player player = event.getPlayer();
if (!Kit.HasKit(player))
//Store Push
if (!player.isSneaking())
{
_push.put(event.getPlayer(), System.currentTimeMillis());
return;
}
if (!_push.containsKey(player) || UtilTime.elapsed(_push.get(player), 500))
return;
event.setCancelled(true);
if (!Kit.HasKit(player))
return;
if (!player.getLocation().getBlock().isLiquid())
return;
if (player.getExp() < 0.5)
return;
if (!Recharge.Instance.use(player, GetName(), 500, false))
return;
player.setExp(player.getExp() - 0.5f);
//Velocity
UtilAction.velocity(player, 0.9, 0.2, 2, false);
@ -62,22 +91,30 @@ public class PerkSquidSwim extends Perk
if (event.getType() != UpdateType.TICK)
return;
Iterator<Player> swimIterator = _active.keySet().iterator();
while (swimIterator.hasNext())
for (Player player : Manager.GetGame().GetPlayers(true))
{
Player player = swimIterator.next();
if (UtilTime.elapsed(_active.get(player), 200))
{
swimIterator.remove();
continue;
}
if (!player.getLocation().getBlock().isLiquid())
continue;
UtilAction.velocity(player, 0.9, 0.2, 2, false);
//Fast Thrust
if (_active.containsKey(player))
{
if (!UtilTime.elapsed(_active.get(player), 200))
{
UtilAction.velocity(player, 1, 0.1, 2, false);
continue;
}
else
{
_active.remove(player);
}
}
//Swim
if (player.isSneaking())
{
UtilAction.velocity(player, 0.5, 0, 2, false);
}
}
}
}