More work on events

This commit is contained in:
Shaun Bennett 2015-06-09 22:58:52 -05:00
parent d1a7d16810
commit 9cdf69b19d
20 changed files with 338 additions and 614 deletions

View File

@ -2,8 +2,7 @@ package mineplex.game.clans.clans.worldevent;
import org.bukkit.Location;
import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent;
import mineplex.game.clans.clans.worldevent.event.WorldEventType;
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
import mineplex.game.clans.clans.worldevent.event.boss.slime.SlimeBoss;
import mineplex.game.clans.clans.worldevent.event.kinghill.KingHill;
@ -17,7 +16,7 @@ public class ConcreteWorldEventFactory implements WorldEventFactory
}
@Override
public AbstractWorldEvent fromName(Location location, String name)
public WorldEvent fromName(Location location, String name)
{
if (name.equalsIgnoreCase("slime"))
{
@ -33,13 +32,13 @@ public class ConcreteWorldEventFactory implements WorldEventFactory
}
@Override
public AbstractWorldEvent random(Location location)
public WorldEvent random(Location location)
{
return null;
}
@Override
public AbstractWorldEvent randomFromType(Location locationm, WorldEventType type)
public WorldEvent randomFromType(Location locationm, WorldEventType type)
{
return null;
}

View File

@ -2,14 +2,11 @@ package mineplex.game.clans.clans.worldevent;
import org.bukkit.Location;
import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent;
import mineplex.game.clans.clans.worldevent.event.WorldEventType;
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
public interface WorldEventFactory
{
public AbstractWorldEvent fromName(Location location, String name);
public WorldEvent fromName(Location location, String name);
public AbstractWorldEvent random(Location location);
public AbstractWorldEvent randomFromType(Location locationm, WorldEventType type);
public WorldEvent random(Location location);
}

View File

@ -1,8 +1,8 @@
package mineplex.game.clans.clans.worldevent;
import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent;
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
public interface WorldEventListener
{
public void onComplete(AbstractWorldEvent event);
public void onComplete(WorldEvent event);
}

View File

@ -1,6 +1,7 @@
package mineplex.game.clans.clans.worldevent;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.bukkit.Bukkit;
@ -14,13 +15,13 @@ import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.worldevent.command.WorldEventCommand;
import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent;
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
import mineplex.minecraft.game.core.damage.DamageManager;
public class WorldEventManager extends MiniPlugin implements WorldEventListener
{
private final WorldEventFactory _factory;
private final Set<AbstractWorldEvent> _events;
private final Set<WorldEvent> _events;
private ClansManager _clansManager;
private DamageManager _damageManager;
@ -32,19 +33,19 @@ public class WorldEventManager extends MiniPlugin implements WorldEventListener
_clansManager = clansManager;
_damageManager = damageManager;
_factory = new ConcreteWorldEventFactory(this);
_events = new HashSet<AbstractWorldEvent>();
_events = new HashSet<WorldEvent>();
}
@Override
public void disable()
{
for (AbstractWorldEvent event : _events)
for (WorldEvent event : _events)
{
event.cancel();
}
}
private void initializeEvent(AbstractWorldEvent event)
private void initializeEvent(WorldEvent event)
{
assert(event != null);
@ -54,13 +55,25 @@ public class WorldEventManager extends MiniPlugin implements WorldEventListener
_events.add(event);
}
public AbstractWorldEvent startEventFromName(Location location, String name)
public WorldEvent startEventFromName(Location location, String name)
{
AbstractWorldEvent event = _factory.fromName(location, name);
WorldEvent event = _factory.fromName(location, name);
if (event != null) initializeEvent(event);
return event;
}
public void clearEvents()
{
Iterator<WorldEvent> iterator = _events.iterator();
while (iterator.hasNext())
{
WorldEvent event = iterator.next();
if (event.isRunning()) event.cancel();
HandlerList.unregisterAll(event);
iterator.remove();
}
}
public ClansManager getClans()
{
return _clansManager;
@ -72,7 +85,7 @@ public class WorldEventManager extends MiniPlugin implements WorldEventListener
}
@Override
public void onComplete(AbstractWorldEvent event)
public void onComplete(WorldEvent event)
{
// TODO
Bukkit.broadcastMessage("World Event Manager On Complete");
@ -85,7 +98,7 @@ public class WorldEventManager extends MiniPlugin implements WorldEventListener
{
if (event.getType() != UpdateType.TICK) return;
for (AbstractWorldEvent e : _events)
for (WorldEvent e : _events)
{
e.tick();
}

View File

@ -0,0 +1,30 @@
package mineplex.game.clans.clans.worldevent.command;
import org.bukkit.entity.Player;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.worldevent.WorldEventManager;
/**
* ClearCommand
*
* @author Shaun Bennett
* @since 6/9/2015
*/
public class ClearCommand extends CommandBase<WorldEventManager>
{
public ClearCommand(WorldEventManager plugin)
{
super(plugin, Rank.DEVELOPER, "clear");
}
@Override
public void Execute(Player caller, String[] args)
{
Plugin.clearEvents();
UtilPlayer.message(caller, F.main("Clans", "All world events cleared!"));
}
}

View File

@ -6,7 +6,7 @@ import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent;
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
import mineplex.game.clans.clans.worldevent.WorldEventManager;
public class StartCommand extends CommandBase<WorldEventManager>
@ -22,7 +22,7 @@ public class StartCommand extends CommandBase<WorldEventManager>
// start specific world event type
if (args != null && args.length == 1)
{
AbstractWorldEvent event = Plugin.startEventFromName(caller.getLocation(), args[0]);
WorldEvent event = Plugin.startEventFromName(caller.getLocation(), args[0]);
if (event == null)
UtilPlayer.message(caller, F.main("WorldEvent", "Could not find a WorldEvent with the name " + F.elem(args[0])));
else

View File

@ -13,6 +13,7 @@ public class WorldEventCommand extends MultiCommandBase<WorldEventManager>
super(plugin, Rank.DEVELOPER, "worldevent", "we", "event");
AddCommand(new StartCommand(Plugin));
AddCommand(new ClearCommand(Plugin));
}
@Override

View File

@ -1,26 +1,230 @@
package mineplex.game.clans.clans.worldevent.creature;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkUnloadEvent;
import mineplex.core.common.util.C;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
public abstract class EventCreature<T extends LivingEntity> implements Listener
{
private WorldEvent _event;
// Spawn Data
private T _entity;
private Class<T> _entityClass;
private Location _spawnLocation;
// Creature Data
private String _name;
private boolean _useName;
private double _health;
private double _maxHealth;
private boolean _showHealthName;
// Fight Data
private long _lastDamaged;
private UUID _lastDamager;
public EventCreature(Location spawnLocation, Class<T> clazz)
public EventCreature(WorldEvent event, Location spawnLocation, String name, boolean useName, double health, Class<T> entityClass)
{
_event = event;
_entityClass = entityClass;
_spawnLocation = spawnLocation;
_entity = spawnLocation.getWorld().spawn(spawnLocation, clazz);
_name = name;
_useName = useName;
_health = health;
_maxHealth = health;
_showHealthName = true;
spawnEntity();
}
protected void spawnEntity()
{
_entity = _spawnLocation.getWorld().spawn(_spawnLocation, _entityClass);
updateEntityHealth();
updateName();
_entity.setRemoveWhenFarAway(false);
}
protected void updateEntityHealth()
{
_entity.setMaxHealth(10000d);
_entity.setHealth(10000d);
}
protected void updateName()
{
String name = _name;
if (_showHealthName)
{
String healthString = (int) _health + "/" + (int) _maxHealth;
double per =_health / _maxHealth;
if (per > 0.5) healthString = C.cGreen + healthString;
if (per > 0.2) healthString = C.cYellow + healthString;
else healthString = C.cRed + healthString;
name += " " + C.cWhite + "(" + healthString + C.cWhite + ")";
}
_entity.setCustomName(name);
_entity.setCustomNameVisible(_useName);
}
protected void remove()
{
if (_entity != null)
_entity.remove();
_event.removeCreature(this);
}
protected final void die()
{
dieCustom();
remove();
}
public abstract void dieCustom();
public WorldEvent getEvent()
{
return _event;
}
public void setEvent(WorldEvent event)
{
_event = event;
}
public T getEntity()
{
return _entity;
}
public void setEntity(T entity)
{
_entity = entity;
}
public Location getSpawnLocation()
{
return _spawnLocation;
}
public void setSpawnLocation(Location spawnLocation)
{
_spawnLocation = spawnLocation;
}
public String getName()
{
return _name;
}
public void setName(String name)
{
_name = name;
updateName();
}
public boolean isUseName()
{
return _useName;
}
public void setUseName(boolean useName)
{
_useName = useName;
updateName();
}
public void applyDamage(double damage)
{
setHealth(getHealth() - damage);
}
public double getHealth()
{
return _health;
}
public void setHealth(double health)
{
_health = health;
if (_health <= 0)
die();
else
updateName();
}
public double getMaxHealth()
{
return _maxHealth;
}
public void setMaxHealth(double maxHealth)
{
_maxHealth = maxHealth;
}
public void setShowHealthName(boolean showHealthName)
{
_showHealthName = showHealthName;
updateName();
}
/**
* Events
*/
@EventHandler
public void onChunkUnload(ChunkUnloadEvent event)
{
if (event.getChunk().equals(_entity.getLocation().getChunk()))
event.setCancelled(true);
}
@EventHandler
public void update(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
if (_entity == null || _entity.isDead())
{
System.out.println("Respawning " + getName() + " because it is null or dead");
spawnEntity();
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onDamage(CustomDamageEvent event)
{
if (_entity == null)
return;
if (!event.GetDamageeEntity().equals(_entity))
return;
updateEntityHealth();
applyDamage(event.GetDamage());
}
}

View File

@ -1,39 +1,8 @@
package mineplex.game.clans.clans.worldevent.event;
import org.bukkit.event.Listener;
import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent;
public abstract class EventState implements Listener
public enum EventState
{
private AbstractWorldEvent _event;
private int _ticks;
public EventState(AbstractWorldEvent event)
{
_event = event;
_ticks = 0;
}
public AbstractWorldEvent getEvent()
{
return _event;
}
public final void tick()
{
_ticks++;
onTick();
}
public int getTicks()
{
return _ticks;
}
public abstract void onTick();
public abstract void onStateStart();
public abstract void onStateStop();
}
PREPARE,
LIVE,
END
}

View File

@ -1,19 +1,26 @@
package mineplex.game.clans.clans.worldevent.event;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import mineplex.core.common.util.UtilServer;
import mineplex.core.data.BlockData;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.game.clans.clans.worldevent.WorldEventListener;
import mineplex.game.clans.clans.worldevent.WorldEventManager;
import mineplex.game.clans.clans.worldevent.creature.EventCreature;
import mineplex.minecraft.game.core.damage.DamageManager;
public abstract class AbstractWorldEvent implements Listener
public abstract class WorldEvent implements Listener
{
private WorldEventManager _eventManager;
private DamageManager _damageManager;
@ -21,16 +28,19 @@ public abstract class AbstractWorldEvent implements Listener
private List<WorldEventListener> _listeners;
private String _name;
private EventState _state;
private Location _centerLocation;
private boolean _running;
private int _ticks;
private Random _random;
private int _ticks;
// Event States
private EventState _currentState;
// Creatures
private List<EventCreature> _creatures;
public AbstractWorldEvent(WorldEventManager eventManager, DamageManager damageManager, String name, Location centerLocation)
// Block Restore
private HashMap<Block, BlockData> _blocks;
public WorldEvent(WorldEventManager eventManager, DamageManager damageManager, String name, Location centerLocation)
{
_eventManager = eventManager;
_damageManager = damageManager;
@ -38,11 +48,13 @@ public abstract class AbstractWorldEvent implements Listener
_centerLocation = centerLocation;
_listeners = new ArrayList<WorldEventListener>();
_random = new Random();
_creatures = new ArrayList<EventCreature>();
_blocks = new HashMap<Block, BlockData>();
_state = EventState.PREPARE;
}
public final void start()
{
_running = true;
customStart();
}
@ -50,7 +62,7 @@ public abstract class AbstractWorldEvent implements Listener
public final void cancel()
{
_running = false;
setState(EventState.END);
customCancel();
}
@ -58,16 +70,14 @@ public abstract class AbstractWorldEvent implements Listener
protected abstract void customTick();
public final void tick()
protected void setState(EventState state)
{
_ticks++;
customTick();
if (_currentState != null) _currentState.tick();
_state = state;
}
public boolean isRunning()
public EventState getState()
{
return _running;
return _state;
}
public void addListener(WorldEventListener listener)
@ -105,32 +115,6 @@ public abstract class AbstractWorldEvent implements Listener
return _damageManager;
}
public void setState(EventState state)
{
JavaPlugin plugin = _eventManager.getPlugin();
if (_currentState != null)
{
// Unregister old state listener
HandlerList.unregisterAll(_currentState);
_currentState.onStateStop();
}
if (state != null)
{
// Register new state listener
plugin.getServer().getPluginManager().registerEvents(state, plugin);
state.onStateStart();
}
_currentState = state;
}
public EventState getState()
{
return _currentState;
}
public String getName()
{
return _name;
@ -146,4 +130,33 @@ public abstract class AbstractWorldEvent implements Listener
return _centerLocation;
}
public void registerCreature(EventCreature creature)
{
UtilServer.getServer().getPluginManager().registerEvents(creature, _eventManager.getPlugin());
_creatures.add(creature);
}
public void removeCreature(EventCreature creature)
{
HandlerList.unregisterAll(creature);
_creatures.remove(creature);
}
public void setBlock(Block block, int id, byte data)
{
if (!_blocks.containsKey(block))
_blocks.put(block, new BlockData(block));
block.setTypeIdAndData(id, data, true);
}
@EventHandler
public void tick(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
return;
_ticks++;
customTick();
}
}

View File

@ -1,6 +0,0 @@
package mineplex.game.clans.clans.worldevent.event;
public enum WorldEventType
{
BOSS_FIGHT;
}

View File

@ -6,11 +6,11 @@ import org.bukkit.entity.Player;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.game.clans.clans.worldevent.WorldEventManager;
import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent;
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
import mineplex.game.clans.clans.worldevent.WorldEventListener;
import mineplex.minecraft.game.core.damage.DamageManager;
public abstract class AbstractBoss extends AbstractWorldEvent
public abstract class BossEvent extends WorldEvent
{
private double _maxHealth;
private double _health;
@ -19,7 +19,7 @@ public abstract class AbstractBoss extends AbstractWorldEvent
// Action Bar Messages
private float _radiusSquared;
public AbstractBoss(WorldEventManager eventManager, DamageManager damageManager, String name, Location center, float radius, double maxHealth)
public BossEvent(WorldEventManager eventManager, DamageManager damageManager, String name, Location center, float radius, double maxHealth)
{
super(eventManager, damageManager, name, center);
_health = maxHealth;

View File

@ -1,20 +0,0 @@
package mineplex.game.clans.clans.worldevent.event.boss;
import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss;
import mineplex.game.clans.clans.worldevent.event.EventState;
public abstract class BossState extends EventState
{
private AbstractBoss _boss;
public BossState(AbstractBoss boss)
{
super(boss);
_boss = boss;
}
public AbstractBoss getBoss()
{
return _boss;
}
}

View File

@ -1,27 +0,0 @@
package mineplex.game.clans.clans.worldevent.event.boss;
public class IdleState extends BossState
{
public IdleState(AbstractBoss boss)
{
super(boss);
}
@Override
public void onTick()
{
}
@Override
public void onStateStart()
{
}
@Override
public void onStateStop()
{
}
}

View File

@ -13,10 +13,10 @@ import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.SlimeSplitEvent;
import mineplex.game.clans.clans.worldevent.WorldEventManager;
import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss;
import mineplex.game.clans.clans.worldevent.event.boss.BossEvent;
import mineplex.minecraft.game.core.damage.DamageManager;
public class SlimeBoss extends AbstractBoss
public class SlimeBoss extends BossEvent
{
private static final int MAX_SIZE = 10;
private static final int MIN_SIZE = 1;
@ -142,7 +142,7 @@ public class SlimeBoss extends AbstractBoss
private int getEnrageTicks(int slimeSize)
{
return 20 * slimeSize;
return 40 * slimeSize;
}
private void splitSlime(SlimePart slime)

View File

@ -1,172 +0,0 @@
package mineplex.game.clans.clans.worldevent.event.boss.slime.state;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.entity.Slime;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.vehicle.VehicleExitEvent;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss;
import mineplex.game.clans.clans.worldevent.event.boss.BossState;
import mineplex.game.clans.clans.worldevent.event.boss.slime.SlimeBoss;
public class AbsorbState extends BossState
{
private Slime _entity;
private Player _rider;
private int _riderTickCount;
private int _ticksPerPulse;
private int _pulseCount;
private int _maxPulses;
private int _slimeSize;
public AbsorbState(SlimeBoss boss, Slime entity, int ticksPerPulse)
{
super(boss);
_entity = entity;
_pulseCount = 0;
_maxPulses = 10;
_riderTickCount = 0;
_ticksPerPulse = ticksPerPulse;
_slimeSize = entity.getSize();
}
@Override
public void onTick()
{
if (_rider == null)
{
int mod = getTicks() % _ticksPerPulse;
if (_pulseCount < _maxPulses)
{
if (mod == 0)
{
pulse();
_pulseCount++;
_entity.setSize(_slimeSize);
UtilParticle.PlayParticle(UtilParticle.ParticleType.SLIME, _entity.getLocation(), 2F, 2F, 2F, 0, 50, UtilParticle.ViewDist.LONG, UtilServer.getPlayers());
_entity.getWorld().playSound(_entity.getLocation(), Sound.SLIME_WALK, 0.5F, 1);
}
else if (mod > _ticksPerPulse - 10)
{
int ticksLeft = _ticksPerPulse - mod;
_entity.setSize(_entity.getSize() + 1);
int count = 20 + (10 - ticksLeft);
for (int i = 0; i < count; i++)
{
double radius = (10 - ticksLeft) * 2;
double q = i / 10.0 * Math.PI;
double x = radius * Math.sin(q);
double z = radius * Math.cos(q);
Location loc = _entity.getLocation().clone();
loc.add(x, 0.2, z);
UtilParticle.PlayParticle(UtilParticle.ParticleType.SLIME, loc, 0.5F, 0.5F, 0.5F, 0, 10, UtilParticle.ViewDist.LONG, UtilServer.getPlayers());
}
}
}
// Check rider
if (getTicks() % 5 == 0)
{
Player closest = UtilPlayer.getClosest(_entity.getLocation());
if (closest != null)
{
double dist = closest.getLocation().distance(_entity.getLocation());
if (dist < 5)
{
_entity.setPassenger(closest);
_rider = closest;
}
}
}
}
else
{
_riderTickCount++;
if (_riderTickCount % 20 == 0)
{
getBoss().getDamageManager().NewDamageEvent(_rider, _entity, null, EntityDamageEvent.DamageCause.MAGIC, 2.0,
false, false, false, getBoss().getName(), "Absorb");
}
if (shouldEjectRider())
{
Vector dir = _entity.getLocation().getDirection().normalize();
_entity.eject();
_rider.setVelocity(dir.add(new Vector(0, 0.5, 0)));
_rider = null;
}
}
}
private void pulse()
{
Bukkit.broadcastMessage("Pulse");
List<Player> nearby = UtilPlayer.getNearby(_entity.getLocation(), 20);
for (Player player : nearby)
{
Vector dir = UtilAlg.getTrajectory2d(player, _entity);
dir.setY(0.4);
player.setVelocity(dir);
getBoss().getDamageManager().NewDamageEvent(player, _entity, null, EntityDamageEvent.DamageCause.MAGIC, 1.0,
false, false, false, getBoss().getName(), "Absorb");
}
}
private boolean shouldEjectRider()
{
return _riderTickCount >= 20 * 10;
}
@EventHandler
public void onTarget(EntityTargetEvent event)
{
if (_rider != null)
{
if (event.getEntity().equals(_entity) && event.getTarget().equals(_rider))
event.setCancelled(true);
}
}
@EventHandler
public void onQuit(PlayerQuitEvent event)
{
if (event.getPlayer().equals(_rider))
_rider = null;
}
@EventHandler
public void onLeave(VehicleExitEvent event)
{
if (event.getExited().equals(_rider) && event.getVehicle().equals(_entity) && !shouldEjectRider())
event.setCancelled(true);
}
@Override
public void onStateStart()
{
}
@Override
public void onStateStop()
{
}
}

View File

@ -1,124 +0,0 @@
package mineplex.game.clans.clans.worldevent.event.boss.slime.state;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.entity.Slime;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilServer;
import mineplex.core.projectile.IThrown;
import mineplex.core.projectile.ProjectileManager;
import mineplex.core.projectile.ProjectileUser;
import mineplex.core.updater.UpdateType;
import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss;
import mineplex.game.clans.clans.worldevent.event.boss.BossState;
public class RocketState extends BossState implements IThrown
{
private Slime _shooter;
private LinkedList<ShotData> _shots;
private int _projectilesHit;
public RocketState(AbstractBoss boss, Slime shooter)
{
super(boss);
_shooter = shooter;
_shots = new LinkedList<ShotData>();
}
@Override
public void onTick()
{
if (getTicks() % 20 == 0 && getTicks() / 20 < 6)
{
List<Entity> entities = _shooter.getNearbyEntities(20, 20, 20);
for (Entity e : entities)
{
if (e instanceof Player)
{
// Vector v = UtilAlg.getTrajectory(_shooter.getEyeLocation(), e.getLocation());
fireProjectile(((Player) e));
}
}
// fireProjectile(new Vector(x, y, z));
}
if (_projectilesHit == 6)
{
// getBoss().setState(new AbsorbState(getBoss(), ((Slime) _shooter), 20 * 2));
}
}
@Override
public void onStateStart()
{
}
@Override
public void onStateStop()
{
}
private void fireProjectile(LivingEntity target)
{
}
@Override
public void Collide(LivingEntity target, Block block, ProjectileUser data)
{
Bukkit.broadcastMessage("COLLIDE " + target);
UtilParticle.PlayParticle(UtilParticle.ParticleType.LARGE_EXPLODE, data.GetThrown().getLocation(), 0, 0, 0, 0, 1, UtilParticle.ViewDist.LONG, UtilServer.getPlayers());
data.GetThrown().remove();
_projectilesHit++;
}
@Override
public void Idle(ProjectileUser data)
{
}
@Override
public void Expire(ProjectileUser data)
{
}
private static class ShotData
{
private LivingEntity _entity;
private LivingEntity _target;
public ShotData(LivingEntity entity, LivingEntity target)
{
_entity = entity;
_target = target;
}
public LivingEntity getEntity()
{
return _entity;
}
public LivingEntity getTarget()
{
return _target;
}
}
}

View File

@ -1,101 +0,0 @@
package mineplex.game.clans.clans.worldevent.event.boss.slime.state;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.entity.Creature;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.util.Vector;
import mineplex.core.common.util.UtilAlg;
import mineplex.core.common.util.UtilParticle;
import mineplex.core.common.util.UtilServer;
import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss;
import mineplex.game.clans.clans.worldevent.event.boss.BossState;
public class SlamState extends BossState
{
private static final int FOLLOW_TICKS = 60;
private static final int JUMP_TICKS = 80;
private static final int DIVE_TICKS = 20 * 5;
private LivingEntity _entity;
private Player _target;
private Location _targetLocation;
public SlamState(AbstractBoss boss, LivingEntity entity, Player target)
{
super(boss);
_entity = entity;
_target = target;
}
@Override
public void onTick()
{
if (getTicks() < FOLLOW_TICKS)
{
_targetLocation = _target.getLocation();
}
else if (getTicks() == FOLLOW_TICKS)
{
Bukkit.broadcastMessage("TARGET LOCKED");
}
else if (getTicks() == JUMP_TICKS)
{
Bukkit.broadcastMessage("SLIME BOSS JUMPED INTO THE AIR");
}
else if (getTicks() > JUMP_TICKS && getTicks() < DIVE_TICKS)
{
Location loc = _entity.getLocation();
loc.setDirection(loc.toVector().add(_targetLocation.toVector()).normalize());
Vector direction = UtilAlg.getTrajectory2d(_entity.getLocation(), _targetLocation);
direction.multiply(0.4);
direction.setY(2 * (1 - ((getTicks() - 100.0) / 60.0)));
_entity.setVelocity(direction);
}
else if (getTicks() == DIVE_TICKS)
{
_entity.setVelocity(new Vector(0, -3, 0));
}
if (_entity instanceof Creature) ((Creature) _entity).setTarget(_target);
// display particles X
double x = 0.5 * Math.sin(getTicks() / 10.0 * 2 * Math.PI);
double z = 0.5 * Math.cos(getTicks() / 10.0 * 2 * Math.PI);
Location loc = _targetLocation.clone().add(x, 0.1, z);
UtilParticle.PlayParticle(UtilParticle.ParticleType.FIREWORKS_SPARK, loc, 0, 0, 0, 0, 1, UtilParticle.ViewDist.LONG, UtilServer.getPlayers());
}
@Override
public void onStateStart()
{
Bukkit.broadcastMessage("Target placed on " + _target.getName());
}
@EventHandler
public void onDamage(EntityDamageEvent event)
{
if (event.getEntity().equals(_entity) && event.getCause() == EntityDamageEvent.DamageCause.FALL)
{
event.setCancelled(true);
}
}
@Override
public void onStateStop()
{
}
}

View File

@ -1,51 +0,0 @@
package mineplex.game.clans.clans.worldevent.event.boss.slime.state;
import mineplex.game.clans.clans.worldevent.event.boss.slime.SlimePart;
public abstract class SlimeState
{
private SlimePart _slime;
private boolean _idle;
private int _ticks;
private int _idleTicks;
public SlimeState(SlimePart slime)
{
_slime = slime;
}
public final void tick()
{
if (isIdle())
{
_idleTicks++;
}
else
{
_ticks++;
tickCustom();
}
}
public int getTicks()
{
return _ticks;
}
public int getIdleTicks()
{
return _idleTicks;
}
public boolean isIdle()
{
return _idle;
}
public abstract void tickCustom();
protected void setIdle(boolean idle)
{
_idle = idle;
}
}

View File

@ -9,16 +9,15 @@ import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import mineplex.core.common.schematic.Schematic;
import mineplex.core.common.util.UtilServer;
import mineplex.game.clans.clans.ClanInfo;
import mineplex.game.clans.clans.ClansManager;
import mineplex.game.clans.clans.worldevent.WorldEventManager;
import mineplex.game.clans.clans.worldevent.event.AbstractWorldEvent;
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
import mineplex.game.clans.economy.GoldManager;
import mineplex.minecraft.game.core.damage.DamageManager;
public class KingHill extends AbstractWorldEvent
public class KingHill extends WorldEvent
{
private static List<HillData> LOADED_HILLS = new ArrayList<HillData>();