Push golem changes, snakes code and rename bossability thingy

This commit is contained in:
libraryaddict 2015-08-29 12:04:53 -07:00
parent 249ecdd381
commit e7f861a6c2
22 changed files with 683 additions and 81 deletions

View File

@ -42,7 +42,7 @@ public class UtilAlg
public static Vector getTrajectory(Vector from, Vector to)
{
return to.subtract(from).normalize();
return to.clone().subtract(from).normalize();
}
public static Vector getTrajectory2d(Entity from, Entity to)
@ -57,7 +57,7 @@ public class UtilAlg
public static Vector getTrajectory2d(Vector from, Vector to)
{
return to.subtract(from).setY(0).normalize();
return to.clone().subtract(from).setY(0).normalize();
}
public static boolean HasSight(Location from, Player to)

View File

@ -56,7 +56,7 @@ public abstract class EventCreature<T extends LivingEntity> implements Listener
return getEvent().getDifficulty();
}
protected final void spawnEntity()
protected void spawnEntity()
{
Location spawnLocation = _entity == null ? _spawnLocation : _entity.getLocation();
T entity = _spawnLocation.getWorld().spawn(spawnLocation, getEntityClass());

View File

@ -279,6 +279,11 @@ public abstract class WorldEvent implements Listener
_lastActive = System.currentTimeMillis();
}
public EventMap getEventMap()
{
return _map;
}
public void setMap(EventMap map, final Runnable onComplete)
{
_map = map;

View File

@ -16,7 +16,7 @@ import mineplex.core.common.util.UtilTime;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.boss.EventCreature;
import mineplex.minecraft.game.core.boss.ironwizard.abilities.GolemAbility;
import mineplex.minecraft.game.core.boss.ironwizard.abilities.BossAbility;
import mineplex.minecraft.game.core.boss.ironwizard.abilities.GolemBlockHail;
import mineplex.minecraft.game.core.boss.ironwizard.abilities.GolemBlockShot;
import mineplex.minecraft.game.core.boss.ironwizard.abilities.GolemCaveIn;
@ -35,6 +35,7 @@ import org.bukkit.entity.IronGolem;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.util.Vector;
public class GolemCreature extends EventCreature<IronGolem>
@ -49,7 +50,7 @@ public class GolemCreature extends EventCreature<IronGolem>
private HashMap<Class, Class[]> _preferedCombos = new HashMap<Class, Class[]>();
private Class _lastAttack;
private boolean _usedFinalAttack;
private ArrayList<GolemAbility> _currentAbilities = new ArrayList<GolemAbility>();
private ArrayList<BossAbility> _currentAbilities = new ArrayList<BossAbility>();
private double _canCaveIn = 450;
private Vector _afkWalk = new Vector();
private long _lastSlam;
@ -108,12 +109,12 @@ public class GolemCreature extends EventCreature<IronGolem>
// if (_currentAbility == null || _currentAbility.hasFinished())
// {
Iterator<GolemAbility> itel = _currentAbilities.iterator();
Iterator<BossAbility> itel = _currentAbilities.iterator();
boolean canDoNew = _currentAbilities.size() < 3;
while (itel.hasNext())
{
GolemAbility ability = itel.next();
BossAbility ability = itel.next();
if (ability.hasFinished())
{
@ -179,9 +180,9 @@ public class GolemCreature extends EventCreature<IronGolem>
}
{ // Wall explode
if (!getPlayers(dist, 12).isEmpty() && getPlayers(dist, 4).isEmpty())
if (!getPlayers(dist, 13).isEmpty() && getPlayers(dist, 4).isEmpty())
{
weight.put(GolemWallExplode.class, 5);
weight.put(GolemWallExplode.class, 8);
}
}
@ -220,7 +221,7 @@ public class GolemCreature extends EventCreature<IronGolem>
{
ArrayList<Player> players = getPlayers(dist, 30);
for (GolemAbility ability : _currentAbilities)
for (BossAbility ability : _currentAbilities)
{
if (ability instanceof GolemExplodingAura)
{
@ -270,12 +271,12 @@ public class GolemCreature extends EventCreature<IronGolem>
}
}
for (GolemAbility ability : _currentAbilities)
for (BossAbility ability : _currentAbilities)
{
weight.remove(ability.getClass());
}
GolemAbility ability = null;
BossAbility ability = null;
if (!weight.isEmpty())
{
@ -298,7 +299,7 @@ public class GolemCreature extends EventCreature<IronGolem>
{
try
{
ability = (GolemAbility) entry.getKey().getConstructor(GolemCreature.class).newInstance(this);
ability = (BossAbility) entry.getKey().getConstructor(GolemCreature.class).newInstance(this);
if (ability.getTarget() == null)
{
@ -350,7 +351,7 @@ public class GolemCreature extends EventCreature<IronGolem>
boolean canMove = true;
for (GolemAbility ability : _currentAbilities)
for (BossAbility ability : _currentAbilities)
{
ability.tick();
@ -527,7 +528,7 @@ public class GolemCreature extends EventCreature<IronGolem>
private void endAbility()
{
for (GolemAbility ability : _currentAbilities)
for (BossAbility ability : _currentAbilities)
{
ability.setFinished();
HandlerList.unregisterAll(ability);
@ -548,4 +549,25 @@ public class GolemCreature extends EventCreature<IronGolem>
endAbility();
}
}
@EventHandler
public void onPlayerDamage(CustomDamageEvent event)
{
if (!(event.GetDamageeEntity() instanceof Player))
{
return;
}
if (event.GetCause() != DamageCause.FALL)
{
return;
}
if (!getEvent().getEventMap().isInMap(event.GetDamageeEntity().getLocation()))
{
return;
}
event.AddMod("Fall negation", 0.5);
}
}

View File

@ -6,6 +6,7 @@ import java.util.UUID;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTime;
import mineplex.minecraft.game.core.boss.EventCreature;
import mineplex.minecraft.game.core.boss.ironwizard.GolemCreature;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
@ -16,9 +17,9 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public abstract class GolemAbility implements Listener
public abstract class BossAbility<T extends EventCreature, Y extends Entity> implements Listener
{
private GolemCreature _creature;
private T _creature;
private HashMap<UUID, Long> _damaged = new HashMap<UUID, Long>();
public boolean canDamage(Entity player)
@ -36,7 +37,7 @@ public abstract class GolemAbility implements Listener
return true;
}
public GolemAbility(GolemCreature creature)
public BossAbility(T creature)
{
_creature = creature;
}
@ -50,12 +51,12 @@ public abstract class GolemAbility implements Listener
return 60;
}
public IronGolem getEntity()
public Y getEntity()
{
return getGolem().getEntity();
return (Y) getGolem().getEntity();
}
public GolemCreature getGolem()
public T getGolem()
{
return _creature;
}

View File

@ -46,7 +46,7 @@ import org.bukkit.util.Vector;
* Rumble is where the golem picks a target then starts playing a animation for a second where its obviously preparing to use it.
* Copy this from Wizards
*/
public class GolemBlockHail extends GolemAbility
public class GolemBlockHail extends BossAbility<GolemCreature, IronGolem>
{
private int _currentBlock;
private int _currentLevel;
@ -222,7 +222,7 @@ public class GolemBlockHail extends GolemAbility
// if (canDamage(victim))
{
getGolem().getEvent().getDamageManager().NewDamageEvent((LivingEntity) victim, getEntity(), null,
DamageCause.CONTACT, 6 * getGolem().getDifficulty(), true, true, false, "Iron Wizard Block Hail",
DamageCause.CONTACT, 10 * getGolem().getDifficulty(), true, true, false, "Iron Wizard Block Hail",
"Iron Wizard Block Hail");
}
@ -305,7 +305,7 @@ public class GolemBlockHail extends GolemAbility
if (canDamage(player))
{
getGolem().getEvent().getDamageManager().NewDamageEvent(player, getEntity(), null,
DamageCause.CONTACT, 6 * getGolem().getDifficulty(), true, true, false,
DamageCause.CONTACT, 10 * getGolem().getDifficulty(), true, true, false,
"Iron Wizard Protection", "Iron Wizard Protection");
loc.getWorld().playEffect(player.getLocation(), Effect.STEP_SOUND, Material.OBSIDIAN.getId());

View File

@ -43,13 +43,14 @@ import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftIronGolem;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.util.Vector;
public class GolemBlockShot extends GolemAbility
public class GolemBlockShot extends BossAbility<GolemCreature, IronGolem>
{
private HashMap<Integer, Location> _blockLoc = new HashMap<Integer, Location>();
private HashMap<Integer, Material> _blockType = new HashMap<Integer, Material>();
@ -226,7 +227,7 @@ public class GolemBlockShot extends GolemAbility
cur.getWorld().playEffect(victim.getEyeLocation().subtract(0, 0.5, 0), Effect.STEP_SOUND, cur.getBlockId());
getGolem().getEvent().getDamageManager().NewDamageEvent((LivingEntity) victim, getEntity(), null,
DamageCause.CONTACT, 6 * getGolem().getDifficulty(), true, true, false, "Iron Wizard Block Shot",
DamageCause.CONTACT, 10 * getGolem().getDifficulty(), true, true, false, "Iron Wizard Block Shot",
"Iron Wizard Block Shot");
cur.remove();

View File

@ -27,10 +27,12 @@ import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -38,7 +40,7 @@ import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.util.Vector;
public class GolemCaveIn extends GolemAbility
public class GolemCaveIn extends BossAbility<GolemCreature, IronGolem>
{
private ArrayList<Block> _blocks = new ArrayList<Block>();
private ArrayList<FallingBlock> _fallingBlocks = new ArrayList<FallingBlock>();
@ -166,7 +168,7 @@ public class GolemCaveIn extends GolemAbility
if (canDamage(victim))
{
getGolem().getEvent().getDamageManager().NewDamageEvent((LivingEntity) victim, getEntity(), null,
DamageCause.CONTACT, 6 * getGolem().getDifficulty(), true, true, false, "Iron Wizard Cave In",
DamageCause.CONTACT, 10 * getGolem().getDifficulty(), true, true, false, "Iron Wizard Cave In",
"Iron Wizard Cave In");
}
@ -216,15 +218,6 @@ public class GolemCaveIn extends GolemAbility
block.setType(Material.AIR);
}
}
@EventHandler
public void onPhysics(BlockPhysicsEvent event)
{
if (_blocks.contains(event.getBlock()))
{
event.setCancelled(true);
}
}
@Override
public void tick()
@ -289,7 +282,7 @@ public class GolemCaveIn extends GolemAbility
List<Player> players = UtilPlayer.getNearby(getLocation(), 50, true);
for (int i = 0; i < players.size(); i++)
for (int i = 0; i < players.size() * 4; i++)
{
int dist = UtilMath.r(10);
@ -317,7 +310,7 @@ public class GolemCaveIn extends GolemAbility
{
if (l.getBlock().getType() == Material.AIR)
{
if (UtilAlg.HasSight(l, getLocation().add(0, 8, 0)))
if (UtilAlg.HasSight(l, getLocation().add(0, 4, 0)))
{
FallingBlock block = b.getWorld().spawnFallingBlock(b.getLocation().add(0.5, -1, 0.5), b.getTypeId(),
b.getData());

View File

@ -17,12 +17,13 @@ import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Entity;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.util.Vector;
public class GolemEarthquake extends GolemAbility
public class GolemEarthquake extends BossAbility<GolemCreature, IronGolem>
{
private Location _center;
private float _range;
@ -139,7 +140,7 @@ public class GolemEarthquake extends GolemAbility
_damaged.add(player.getUniqueId());
getGolem().getEvent().getDamageManager().NewDamageEvent((LivingEntity) player, getEntity(), null,
DamageCause.CONTACT, 12 * getGolem().getDifficulty(), false, true, false, "Iron Wizard Earthquake",
DamageCause.CONTACT, 14 * getGolem().getDifficulty(), false, true, false, "Iron Wizard Earthquake",
"Iron Wizard Earthquake");
getGolem().getEvent().getCondition().Factory().Slow("Earthquake", (LivingEntity) player, getEntity(), 3, 1, false,

View File

@ -27,6 +27,7 @@ import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -47,7 +48,7 @@ import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.boss.ironwizard.GolemCreature;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public class GolemExplodingAura extends GolemAbility
public class GolemExplodingAura extends BossAbility<GolemCreature, IronGolem>
{
private HashMap<Integer, Integer> _blocks = new HashMap<Integer, Integer>();
@ -118,7 +119,7 @@ public class GolemExplodingAura extends GolemAbility
for (Player player : UtilPlayer.getNearby(getLocation(), 3, true))
{
getGolem().getEvent().getDamageManager().NewDamageEvent(player, getEntity(), null, DamageCause.CONTACT,
2 * getGolem().getDifficulty(), true, true, false, "Iron Wizard Protection", "Iron Wizard Protection");
6 * getGolem().getDifficulty(), true, true, false, "Iron Wizard Protection", "Iron Wizard Protection");
UtilAction.velocity(player, UtilAlg.getTrajectory(getEntity(), player), 1, true, 0.3, 0, 0.3, false);
}
}
@ -351,12 +352,6 @@ public class GolemExplodingAura extends GolemAbility
"Blocky Iron Wizard Aura");
}
if (victim instanceof Player)
{
getGolem().getEvent().getCondition().Factory().Slow("Blocky Iron Wizard Aura", (LivingEntity) victim,
getEntity(), 3, 2, false, false, false, false);
}
fallingIterator.remove();
cur.remove();

View File

@ -52,7 +52,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.util.Vector;
public class GolemExplosiveBlock extends GolemAbility
public class GolemExplosiveBlock extends BossAbility<GolemCreature, IronGolem>
{
private HashMap<Integer, Vector> _blocksLocation = new HashMap<Integer, Vector>();
private Location _center;

View File

@ -8,11 +8,12 @@ import net.minecraft.server.v1_7_R4.EntityIronGolem;
import org.bukkit.Sound;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftIronGolem;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.util.Vector;
public class GolemMeleeAttack extends GolemAbility
public class GolemMeleeAttack extends BossAbility<GolemCreature, IronGolem>
{
private boolean _attacked;
@ -65,7 +66,7 @@ public class GolemMeleeAttack extends GolemAbility
UtilEnt.CreatureLook(getEntity(), target);
getGolem().getEvent().getDamageManager().NewDamageEvent(target, getEntity(), null, DamageCause.ENTITY_ATTACK,
6 * getGolem().getDifficulty(), false, true, false, "Iron Wizard Melee Attack", "Iron Wizard Melee Attack");
10 * getGolem().getDifficulty(), false, true, false, "Iron Wizard Melee Attack", "Iron Wizard Melee Attack");
Vector vec = getLocation().getDirection();
vec.setY(0).normalize().setY(0.5).multiply(2.4);

View File

@ -28,7 +28,7 @@ import org.bukkit.util.Vector;
* Rumble is where the golem picks a target then starts playing a animation for a second where its obviously preparing to use it.
* Copy this from Wizards
*/
public class GolemRumble extends GolemAbility
public class GolemRumble extends BossAbility<GolemCreature, IronGolem>
{
private Location _loc;
private int _ticks;
@ -186,7 +186,7 @@ public class GolemRumble extends GolemAbility
if (canDamage(entity))
{
getGolem().getEvent().getDamageManager().NewDamageEvent((LivingEntity) entity, getEntity(), null,
DamageCause.CONTACT, 4 * getGolem().getDifficulty(), false, true, false, "Iron Wizard Rumble",
DamageCause.CONTACT, 8 * getGolem().getDifficulty(), false, true, false, "Iron Wizard Rumble",
"Iron Wizard Rumble");
}

View File

@ -13,6 +13,7 @@ import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftIronGolem;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -39,7 +40,7 @@ import mineplex.core.common.util.UtilTime;
import mineplex.minecraft.game.core.boss.ironwizard.GolemCreature;
import net.minecraft.server.v1_7_R4.EntityIronGolem;
public class GolemRupture extends GolemAbility
public class GolemRupture extends BossAbility<GolemCreature, IronGolem>
{
private ArrayList<Entry<Location, Location>> _ruptures = new ArrayList<Entry<Location, Location>>();
private HashMap<Location, Long> _ruptureTime = new HashMap<Location, Long>();
@ -291,7 +292,7 @@ public class GolemRupture extends GolemAbility
// Damage Event
getGolem().getEvent().getDamageManager().NewDamageEvent(cur, getEntity(), null, DamageCause.CUSTOM,
4 * getGolem().getDifficulty(), false, true, false, "Iron Wizard", "Rupture");
8 * getGolem().getDifficulty(), false, true, false, "Iron Wizard", "Rupture");
}
ArrayList<Block> blocks = new ArrayList<Block>();

View File

@ -19,6 +19,7 @@ import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.Item;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
@ -28,7 +29,7 @@ import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
public class GolemSlam extends GolemAbility
public class GolemSlam extends BossAbility<GolemCreature, IronGolem>
{
private ArrayList<Item> _items = new ArrayList<Item>();
private int _ticksFinished;
@ -194,7 +195,7 @@ public class GolemSlam extends GolemAbility
// Damage Event
getGolem().getEvent().getDamageManager().NewDamageEvent(cur, getEntity(), null, DamageCause.CUSTOM,
4 * getGolem().getDifficulty(), false, true, false, "Iron Wizard", "Rupture");
8 * getGolem().getDifficulty(), false, true, false, "Iron Wizard", "Rupture");
}
ArrayList<Block> blocks = new ArrayList<Block>();

View File

@ -34,13 +34,14 @@ import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
import org.bukkit.craftbukkit.v1_7_R4.entity.CraftEntity;
import org.bukkit.entity.Entity;
import org.bukkit.entity.FallingBlock;
import org.bukkit.entity.IronGolem;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.util.Vector;
public class GolemWallExplode extends GolemAbility
public class GolemWallExplode extends BossAbility<GolemCreature, IronGolem>
{
private HashMap<BlockFace, ArrayList<Block>> _blockWalls = new HashMap<BlockFace, ArrayList<Block>>();
private ArrayList<String> _dontTarget = new ArrayList<String>();
@ -193,7 +194,7 @@ public class GolemWallExplode extends GolemAbility
if (canDamage(victim))
{
getGolem().getEvent().getDamageManager().NewDamageEvent((LivingEntity) victim, getEntity(), null,
DamageCause.CONTACT, 6 * getGolem().getDifficulty(), true, true, false, "Iron Wizard Wall Explosion",
DamageCause.CONTACT, 10 * getGolem().getDifficulty(), true, true, false, "Iron Wizard Wall Explosion",
"Iron Wizard Wall Explosion");
}

View File

@ -0,0 +1,61 @@
package mineplex.minecraft.game.core.boss.snake;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import mineplex.core.blockrestore.BlockRestore;
import mineplex.minecraft.game.core.boss.EventCreature;
import mineplex.minecraft.game.core.boss.EventState;
import mineplex.minecraft.game.core.boss.WorldEvent;
import mineplex.minecraft.game.core.condition.ConditionManager;
import mineplex.minecraft.game.core.damage.DamageManager;
public class SnakeBoss extends WorldEvent
{
public SnakeBoss(DamageManager damageManager, BlockRestore blockRestore, ConditionManager conditionManager, String name,
Location cornerLocation)
{
super(damageManager, blockRestore, conditionManager, name, cornerLocation);
}
@Override
protected void customStart()
{
Bukkit.broadcastMessage("Custom Start");
spawnGolem(getCenterLocation());
setState(EventState.LIVE);
announceStart();
}
/**
* Check if this slime boss has been defeated
*/
private void checkDeath()
{
if (getCreatures().size() == 0)
{
setState(EventState.COMPLETE);
Bukkit.broadcastMessage("FINISHED!");
}
}
@Override
public void removeCreature(EventCreature creature)
{
super.removeCreature(creature);
if (creature instanceof SnakeCreature)
{
checkDeath();
}
}
private SnakeCreature spawnGolem(Location location)
{
SnakeCreature slimeCreature = new SnakeCreature(this, location);
registerCreature(slimeCreature);
return slimeCreature;
}
}

View File

@ -0,0 +1,166 @@
package mineplex.minecraft.game.core.boss.snake;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.entity.Silverfish;
import org.bukkit.event.EventHandler;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.boss.EventCreature;
import mineplex.minecraft.game.core.boss.WorldEvent;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy;
public class SnakeCreature extends EventCreature<Silverfish>
{
private ArrayList<SnakeTail> _snakeTail = new ArrayList<SnakeTail>();
private HashMap<SnakeTail, Vector> _direction = new HashMap<SnakeTail, Vector>();
private double _seperator = 0.5;
private ArrayList<Player> _canSee = new ArrayList<Player>();
public SnakeCreature(WorldEvent event, Location spawnLocation)
{
super(event, spawnLocation, "Serpent Lord", false, 2000, Silverfish.class);
}
@Override
protected void spawnCustom()
{
getEntity().addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 10000, 0));
UtilEnt.Vegetate(getEntity());
Vector dir = new Vector(UtilMath.rr(1, true), 0, UtilMath.rr(1, true)).normalize().multiply(_seperator);
for (int i = 0; i < getHealth() / 50; i++)
{
SnakeTail tail = new SnakeTail(getSpawnLocation().toVector().subtract(dir.clone().multiply(-i)),
new ItemStack(i == 0 ? Material.COBBLESTONE : Material.STONE));
_direction.put(tail, dir);
_snakeTail.add(tail);
}
}
@EventHandler
public void onSecond(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
{
return;
}
Location loc = _snakeTail.get(0).getLocation().toLocation(getSpawnLocation().getWorld());
ArrayList<Player> canSee = new ArrayList<Player>();
for (Player player : loc.getWorld().getPlayers())
{
if (player.getLocation().distance(loc) < 120)
{
canSee.add(player);
}
}
Iterator<Player> itel2 = _canSee.iterator();
int[] ids = new int[_snakeTail.size()];
for (int a = 0; a < _snakeTail.size(); a++)
{
ids[a] = _snakeTail.get(a).getId();
}
Packet destroy = new PacketPlayOutEntityDestroy(ids);
while (itel2.hasNext())
{
Player player = itel2.next();
if (!canSee.contains(player))
{
itel2.remove();
UtilPlayer.sendPacket(player, destroy);
}
}
for (Player player : canSee)
{
if (!_canSee.contains(player))
{
_canSee.add(player);
for (SnakeTail tail : _snakeTail)
{
UtilPlayer.sendPacket(player, tail.getSpawn());
}
}
}
}
@Override
public void dieCustom()
{
int[] ids = new int[_snakeTail.size()];
for (int a = 0; a < _snakeTail.size(); a++)
{
ids[a] = _snakeTail.get(a).getId();
}
Packet destroy = new PacketPlayOutEntityDestroy(ids);
for (Player player : _canSee)
{
UtilPlayer.sendPacket(player, destroy);
}
}
@EventHandler
public void onTick(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
Packet[] packets = new Packet[_snakeTail.size()];
for (int i = 0; i < _snakeTail.size(); i++)
{
SnakeTail tail = _snakeTail.get(i);
Vector vec = _direction.get(tail);
if (i == 0)
{
vec.add(new Vector(0.01, 0, 0));
// TODO
}
else
{
vec.add(_direction.get(_snakeTail.get(i - 1)).multiply(0.9));
}
vec.normalize().multiply(0.6);
packets[i] = tail.moveEntity(vec);
}
for (Player player : _canSee)
{
UtilPlayer.sendPacket(player, packets);
}
}
}

View File

@ -0,0 +1,118 @@
package mineplex.minecraft.game.core.boss.snake;
import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack;
import org.bukkit.inventory.ItemStack;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilEnt;
import net.minecraft.server.v1_7_R4.DataWatcher;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityEquipment;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityTeleport;
import net.minecraft.server.v1_7_R4.PacketPlayOutRelEntityMoveLook;
import net.minecraft.server.v1_7_R4.PacketPlayOutSpawnEntityLiving;
public class SnakeTail
{
private int _entityId = UtilEnt.getNewEntityId();
private Vector _entityLocation;
private ItemStack _item;
private Vector _previous;
public SnakeTail(Vector location, ItemStack item)
{
_entityLocation = location.clone();
_item = item;
}
public int getId()
{
return _entityId;
}
public Vector getPrevious()
{
return _previous;
}
public Packet moveEntity(Vector toMove)
{
int x = (int) Math.floor(32 * toMove.getX());
int y = (int) Math.floor(32 * toMove.getY());
int z = (int) Math.floor(32 * toMove.getZ());
if (x >= -128 && x <= 127 && y >= -128 && y <= 127 && z >= -128 && z <= 127)
{
_entityLocation.add(new Vector(x / 32D, y / 32D, z / 32D));
PacketPlayOutRelEntityMoveLook relMove = new PacketPlayOutRelEntityMoveLook();
relMove.a = getId();
relMove.b = (byte) x;
relMove.c = (byte) y;
relMove.d = (byte) z;
relMove.e = (byte) (int) (UtilAlg.GetYaw(toMove) * 256.0F / 360.0F);
relMove.f = (byte) (int) (UtilAlg.GetPitch(toMove) * 256.0F / 360.0F);
return relMove;
}
else
{
_entityLocation.add(toMove);
x = (int) Math.floor(_entityLocation.getX() * 32);
y = (int) Math.floor(_entityLocation.getY() * 32);
z = (int) Math.floor(_entityLocation.getZ() * 32);
PacketPlayOutEntityTeleport teleportPacket = new PacketPlayOutEntityTeleport();
teleportPacket.a = getId();
teleportPacket.b = x;
teleportPacket.c = y;
teleportPacket.d = z;
teleportPacket.e = (byte) (int) (UtilAlg.GetYaw(toMove) * 256.0F / 360.0F);
teleportPacket.f = (byte) (int) (UtilAlg.GetPitch(toMove) * 256.0F / 360.0F);
return teleportPacket;
}
}
public Vector getLocation()
{
return _entityLocation;
}
public Packet[] getSpawn()
{
PacketPlayOutSpawnEntityLiving packet = new PacketPlayOutSpawnEntityLiving();
DataWatcher watcher = new DataWatcher(null);
watcher.a(0, (byte) 0);
watcher.a(1, 0);
watcher.a(10, (byte) 0);
for (int i = 11; i < 17; i++)
{
watcher.a(i, new Vector(0, 0, 0));
}
packet.a = getId();
packet.b = 30;
packet.c = (int) Math.floor(_entityLocation.getX() * 32);
packet.d = (int) Math.floor(_entityLocation.getY() * 32);
packet.e = (int) Math.floor(_entityLocation.getZ() * 32);
packet.l = watcher;
PacketPlayOutEntityEquipment packet2 = new PacketPlayOutEntityEquipment();
packet2.a = getId();
packet2.b = 4;
packet2.c = CraftItemStack.asNMSCopy(_item);
return new Packet[]
{
packet, packet2
};
}
}

View File

@ -2,30 +2,27 @@ package nautilus.game.arcade.game.games.bossbattles;
import mineplex.minecraft.game.core.boss.ironwizard.GolemBoss;
import mineplex.minecraft.game.core.boss.slimeking.SlimeBoss;
import nautilus.game.arcade.game.games.bossbattles.displays.BossDisplay;
import nautilus.game.arcade.game.games.bossbattles.displays.IronWizardDisplay;
import nautilus.game.arcade.game.games.bossbattles.displays.SlimeKingDisplay;
import mineplex.minecraft.game.core.boss.snake.SnakeBoss;
import nautilus.game.arcade.game.games.bossbattles.displays.*;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
public enum BattleBoss
{
GOLEM(GolemBoss.class, IronWizardDisplay.class, new ItemStack(
Material.IRON_BLOCK)),
GOLEM(GolemBoss.class, IronWizardDisplay.class),
SLIME(SlimeBoss.class, SlimeKingDisplay.class, new ItemStack(
Material.EMERALD_BLOCK));
SNAKE(SnakeBoss.class, SnakeDisplay.class),
SLIME(SlimeBoss.class, SlimeKingDisplay.class);
private Class _bossClass;
private ItemStack _bossHead;
private Class<? extends BossDisplay> _bossDisplay;
private BattleBoss(Class bossClass,
Class<? extends BossDisplay> displayClass, ItemStack bossHead)
Class<? extends BossDisplay> displayClass)
{
_bossClass = bossClass;
_bossHead = bossHead;
_bossDisplay = displayClass;
}
@ -39,8 +36,4 @@ public enum BattleBoss
return _bossDisplay;
}
public ItemStack getItem()
{
return _bossHead;
}
}

View File

@ -52,6 +52,8 @@ public class BossBattles extends TeamGame
{
"Fight some bosses"
});
HungerSet = 20;
}
@Override
@ -110,12 +112,10 @@ public class BossBattles extends TeamGame
return;
}
CreatureAllowOverride = false;
HandlerList.unregisterAll(_currentBoss);
// If the event was cancelled, we don't need to run a cleanup
if (_currentBoss.getState() == EventState.COMPLETE)
if (_currentBoss.getState() != EventState.CANCELLED)
_currentBoss.cleanup();
}
@ -224,7 +224,7 @@ public class BossBattles extends TeamGame
int i = 0;
ArrayList<Location> locations = UtilShapes.getPointsInCircle(
new Location(UtilWorld.getWorld("world"), 0, 104, 0),
BattleBoss.values().length, 5);
BattleBoss.values().length, 4.5);
for (BattleBoss boss : BattleBoss.values())
{
@ -242,12 +242,12 @@ public class BossBattles extends TeamGame
BossDisplay bossDisplay = constructor.newInstance(this,
BattleBoss.values()[i], loc);
Bukkit.getPluginManager().registerEvents(bossDisplay,
getArcadeManager().getPlugin());
bossDisplay.start();
bossDisplay.spawnHologram();
Bukkit.getPluginManager().registerEvents(bossDisplay,
getArcadeManager().getPlugin());
_displays.add(bossDisplay);
System.out.print(

View File

@ -0,0 +1,242 @@
package nautilus.game.arcade.game.games.bossbattles.displays;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.NumberConversions;
import org.bukkit.util.Vector;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilMath;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.minecraft.game.core.boss.snake.SnakeTail;
import nautilus.game.arcade.game.games.bossbattles.BattleBoss;
import nautilus.game.arcade.game.games.bossbattles.BossBattles;
import net.minecraft.server.v1_7_R4.Packet;
import net.minecraft.server.v1_7_R4.PacketPlayOutEntityDestroy;
public class SnakeDisplay extends BossDisplay
{
private ArrayList<SnakeTail> _snakeTail = new ArrayList<SnakeTail>();
private double _seperator = 0.5;
private ArrayList<Player> _canSee = new ArrayList<Player>();
private Entity _entity;
private float _yaw;
private float _pitch;
public SnakeDisplay(BossBattles plugin, BattleBoss boss, Location location)
{
super(plugin, boss, location);
}
@Override
public String getDisplayName()
{
return C.cDGreen + "Snake";
}
@Override
public void removeBoss()
{
int[] ids = new int[_snakeTail.size()];
for (int a = 0; a < _snakeTail.size(); a++)
{
ids[a] = _snakeTail.get(a).getId();
}
Packet destroy = new PacketPlayOutEntityDestroy(ids);
for (Player player : _canSee)
{
UtilPlayer.sendPacket(player, destroy);
}
_entity.remove();
}
@Override
public void start()
{
Vector dir = new Vector(UtilMath.rr(1, true), 0, UtilMath.rr(1, true))
.normalize().multiply(_seperator);
for (int i = 0; i < 20; i++)
{
Vector loc = getLocation().toVector()
.subtract(dir.clone().multiply(-i));
SnakeTail tail = new SnakeTail(loc, new ItemStack(
i == 0 ? Material.COBBLESTONE : Material.STONE));
_snakeTail.add(tail);
}
Plugin.CreatureAllowOverride = true;
_entity = getLocation().getWorld().spawnEntity(getLocation(),
EntityType.IRON_GOLEM);
UtilEnt.Vegetate(_entity);
((LivingEntity) _entity).addPotionEffect(
new PotionEffect(PotionEffectType.INVISIBILITY, 10000, 0));
Plugin.CreatureAllowOverride = false;
addEntity(_entity);
}
@EventHandler
public void onSecond(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC)
{
return;
}
ArrayList<Player> canSee = new ArrayList<Player>();
for (Player player : getLocation().getWorld().getPlayers())
{
if (player.getLocation().distance(getLocation()) < 120)
{
canSee.add(player);
}
}
Iterator<Player> itel2 = _canSee.iterator();
int[] ids = new int[_snakeTail.size()];
for (int a = 0; a < _snakeTail.size(); a++)
{
ids[a] = _snakeTail.get(a).getId();
}
Packet destroy = new PacketPlayOutEntityDestroy(ids);
while (itel2.hasNext())
{
Player player = itel2.next();
if (!canSee.contains(player))
{
itel2.remove();
UtilPlayer.sendPacket(player, destroy);
}
}
for (Player player : canSee)
{
if (!_canSee.contains(player))
{
_canSee.add(player);
for (SnakeTail tail : _snakeTail)
{
UtilPlayer.sendPacket(player, tail.getSpawn());
}
}
}
}
@EventHandler
public void onInteract(PlayerInteractEntityEvent event)
{
if (!event.getRightClicked().equals(_entity))
{
return;
}
setChosen(event.getPlayer());
}
public void setYaw(float yaw)
{
_yaw = (yaw + 720) % 360;
}
public void setPitch(float pitch)
{
_pitch = (pitch + 720) % 360;
}
public float getPitch()
{
return _pitch;
}
public float getYaw()
{
return _yaw;
}
@EventHandler
public void onTick(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
{
return;
}
Packet[] packets = new Packet[_snakeTail.size()];
for (int i = 0; i < _snakeTail.size(); i++)
{
SnakeTail tail = _snakeTail.get(i);
Vector vector = new Vector();
if (i == 0)
{
setPitch(getPitch() + 3);
double rotX = getYaw();
double rotY = getPitch();
vector.setY(-Math.sin(Math.toRadians(rotY)));
double xz = Math.cos(Math.toRadians(rotY));
vector.setX(-xz * Math.sin(Math.toRadians(rotX)));
vector.setZ(xz * Math.cos(Math.toRadians(rotX)));
vector.normalize().multiply(0.2);
}
else
{
SnakeTail t = _snakeTail.get(i - 1);
vector = t.getPrevious().clone().subtract(tail.getLocation());
}
packets[i] = tail
.moveEntity(tail.getLocation().clone().add(vector));
}
for (Player player : _canSee)
{
UtilPlayer.sendPacket(player, packets);
}
}
@Override
public Location getHologramLocation()
{
return getLocation().clone().add(0, 3, 0);
}
}