King of the hill work
This commit is contained in:
parent
68b708e32e
commit
5d431a586a
@ -1,6 +1,7 @@
|
||||
package mineplex.core.common.schematic;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.craftbukkit.v1_7_R4.CraftWorld;
|
||||
import net.minecraft.server.v1_7_R4.World;
|
||||
@ -37,7 +38,17 @@ public class Schematic
|
||||
{
|
||||
int index = y * _width * _length + z * _width + x;
|
||||
Block block = originLocation.getWorld().getBlockAt(startX + x, startY + y, startZ + z);
|
||||
block.setTypeIdAndData(_blocks[index], _blockData[index], false);
|
||||
// some blocks were giving me negative id's in the schematic (like stairs)
|
||||
// not sure why but the math.abs is my simple fix
|
||||
int materialId = Math.abs(_blocks[index]);
|
||||
|
||||
Material material = Material.getMaterial(materialId);
|
||||
if (material == null)
|
||||
{
|
||||
System.out.println(materialId + " data: " + _blockData[index]);
|
||||
continue;
|
||||
}
|
||||
block.setTypeIdAndData(materialId, _blockData[index], false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ 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.boss.slime.SlimeBoss;
|
||||
import mineplex.game.clans.clans.worldevent.event.kinghill.KingHill;
|
||||
|
||||
public class ConcreteWorldEventFactory implements WorldEventFactory
|
||||
{
|
||||
@ -17,8 +18,18 @@ public class ConcreteWorldEventFactory implements WorldEventFactory
|
||||
|
||||
@Override
|
||||
public AbstractWorldEvent fromName(Location location, String name)
|
||||
{
|
||||
if (name.equalsIgnoreCase("slime"))
|
||||
{
|
||||
return new SlimeBoss(_eventManager, _eventManager.getDamage(), location);
|
||||
} else if (name.equalsIgnoreCase("kinghill"))
|
||||
{
|
||||
return new KingHill(_eventManager, _eventManager.getDamage(), location);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,7 +26,7 @@ public abstract class AbstractBoss extends AbstractWorldEvent
|
||||
|
||||
public AbstractBoss(WorldEventManager eventManager, DamageManager damageManager, String name, Location center, float radius, double maxHealth)
|
||||
{
|
||||
super(eventManager, damageManager, name);
|
||||
super(eventManager, damageManager, name, center);
|
||||
_center = center;
|
||||
_health = maxHealth;
|
||||
_maxHealth = maxHealth;
|
||||
@ -34,10 +34,8 @@ public abstract class AbstractBoss extends AbstractWorldEvent
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick()
|
||||
protected void customTick()
|
||||
{
|
||||
super.tick();
|
||||
|
||||
if (_lastHealth != _health || getTicks() % 20 == 0)
|
||||
{
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers())
|
||||
|
@ -10,6 +10,7 @@ import org.bukkit.entity.Slime;
|
||||
import org.bukkit.entity.Spider;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityTargetEvent;
|
||||
|
||||
import mineplex.game.clans.clans.worldevent.WorldEventManager;
|
||||
import mineplex.game.clans.clans.worldevent.event.boss.AbstractBoss;
|
||||
@ -43,9 +44,9 @@ public class SlimeBoss extends AbstractBoss
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick()
|
||||
protected void customTick()
|
||||
{
|
||||
super.tick();
|
||||
super.customTick();
|
||||
|
||||
if (!inRange(_slimeEntity.getLocation()))
|
||||
{
|
||||
|
@ -0,0 +1,58 @@
|
||||
package mineplex.game.clans.clans.worldevent.event.kinghill;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import mineplex.core.common.schematic.Schematic;
|
||||
import mineplex.core.common.schematic.UtilSchematic;
|
||||
|
||||
public class HillData
|
||||
{
|
||||
private Schematic _schematic;
|
||||
private int _hillX;
|
||||
private int _hillY;
|
||||
private int _hillZ;
|
||||
private int _lengthX;
|
||||
private int _lengthY;
|
||||
private int _lengthZ;
|
||||
|
||||
public HillData(String fileName, int hillX, int hillY, int hillZ, int lengthX, int lengthY, int lengthZ) throws IOException
|
||||
{
|
||||
File file = new File("schematic" + File.separator + fileName);
|
||||
System.out.println(file.getAbsolutePath());
|
||||
_schematic = UtilSchematic.loadSchematic(file);
|
||||
_hillX = hillX;
|
||||
_hillY = hillY;
|
||||
_hillZ = hillZ;
|
||||
_lengthX = lengthX;
|
||||
_lengthY = lengthY;
|
||||
_lengthZ = lengthZ;
|
||||
}
|
||||
|
||||
public Schematic getSchematic()
|
||||
{
|
||||
return _schematic;
|
||||
}
|
||||
|
||||
public boolean isOnHill(Location location, Location eventLocation)
|
||||
{
|
||||
if (!location.getWorld().equals(eventLocation.getWorld())) return false;
|
||||
|
||||
int minX = eventLocation.getBlockX() + _hillX;
|
||||
int minY = eventLocation.getBlockY() + _hillY;
|
||||
int minZ = eventLocation.getBlockZ() + _hillZ;
|
||||
int maxX = minX + _lengthX;
|
||||
int maxY = minY + _lengthY;
|
||||
int maxZ = minZ + _lengthZ;
|
||||
|
||||
double x = location.getX();
|
||||
double y = location.getY();
|
||||
double z = location.getZ();
|
||||
|
||||
return x > minX && y > minY && z > minZ && x < maxX && y < maxY && z < maxZ;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,9 +1,16 @@
|
||||
package mineplex.game.clans.clans.worldevent.event.kinghill;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
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;
|
||||
@ -12,20 +19,40 @@ import mineplex.minecraft.game.core.damage.DamageManager;
|
||||
|
||||
public class KingHill extends AbstractWorldEvent
|
||||
{
|
||||
private static List<HillData> LOADED_HILLS = new ArrayList<HillData>();
|
||||
|
||||
static
|
||||
{
|
||||
// TODO load hills from schematic folder with extra hill data from a config file?
|
||||
try
|
||||
{
|
||||
LOADED_HILLS.add(new HillData("hill.schematic", 28, 28, 28, 5, 5, 5));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private ClansManager _clansManager;
|
||||
private HashMap<ClanInfo, HillData> _scoreMap;
|
||||
private HashMap<ClanInfo, CaptureData> _scoreMap;
|
||||
private HillData _hill;
|
||||
|
||||
public KingHill(WorldEventManager eventManager, DamageManager damageManager, Location centerLocation)
|
||||
{
|
||||
super(eventManager, damageManager, "King of the Hill", centerLocation);
|
||||
_clansManager = eventManager.getClans();
|
||||
_scoreMap = new HashMap<ClanInfo, HillData>();
|
||||
_scoreMap = new HashMap<ClanInfo, CaptureData>();
|
||||
_hill = LOADED_HILLS.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customStart()
|
||||
{
|
||||
|
||||
Bukkit.broadcastMessage("attempting to spawn in hill... please wait!");
|
||||
_hill.getSchematic().paste(getCenterLocation());
|
||||
Bukkit.broadcastMessage("PASTED");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -37,13 +64,42 @@ public class KingHill extends AbstractWorldEvent
|
||||
@Override
|
||||
protected void customTick()
|
||||
{
|
||||
// Tick Hill
|
||||
// Check if a clan won
|
||||
|
||||
if (getTicks() % 5 == 0)
|
||||
tickHill();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static class HillData
|
||||
private void tickHill()
|
||||
{
|
||||
int clanCount = 0;
|
||||
ClanInfo lastClan = null;
|
||||
|
||||
for (Player player : UtilServer.getPlayers())
|
||||
{
|
||||
if (_hill.isOnHill(player.getLocation(), getCenterLocation()))
|
||||
{
|
||||
ClanInfo playerClan = _clansManager.getClan(player);
|
||||
if (playerClan != null)
|
||||
{
|
||||
clanCount++;
|
||||
lastClan = playerClan;
|
||||
}
|
||||
|
||||
// Bukkit.broadcastMessage(player.getName() + " IS ON THE HILL");
|
||||
}
|
||||
}
|
||||
|
||||
if (clanCount == 1 && lastClan != null)
|
||||
{
|
||||
Bukkit.broadcastMessage(lastClan.getName() + " owns the hill!");
|
||||
}
|
||||
}
|
||||
|
||||
private static class CaptureData
|
||||
{
|
||||
public int Score;
|
||||
public int
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,11 @@ 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;
|
||||
@ -19,18 +23,19 @@ import mineplex.game.clans.clans.worldevent.event.boss.state.BossState;
|
||||
public class AbsorbState extends BossState
|
||||
{
|
||||
private Slime _entity;
|
||||
private boolean _hasRider;
|
||||
private Player _rider;
|
||||
private int _riderTickCount;
|
||||
private int _ticksPerPulse;
|
||||
private int _pulseCount;
|
||||
private int _maxPulses;
|
||||
private int _slimeSize;
|
||||
|
||||
public AbsorbState(AbstractBoss boss, Slime entity, int ticksPerPulse)
|
||||
{
|
||||
super(boss);
|
||||
_entity = entity;
|
||||
_pulseCount = 10;
|
||||
_hasRider = false;
|
||||
_pulseCount = 0;
|
||||
_maxPulses = 10;
|
||||
_riderTickCount = 0;
|
||||
_ticksPerPulse = ticksPerPulse;
|
||||
_slimeSize = entity.getSize();
|
||||
@ -39,10 +44,12 @@ public class AbsorbState extends BossState
|
||||
@Override
|
||||
public void onTick()
|
||||
{
|
||||
if (!_hasRider)
|
||||
if (_rider == null)
|
||||
{
|
||||
int mod = getTicks() % _ticksPerPulse;
|
||||
|
||||
if (_pulseCount < _maxPulses)
|
||||
{
|
||||
if (mod == 0)
|
||||
{
|
||||
pulse();
|
||||
@ -68,6 +75,7 @@ public class AbsorbState extends BossState
|
||||
UtilParticle.PlayParticle(UtilParticle.ParticleType.SLIME, loc, 0.5F, 0.5F, 0.5F, 0, 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check rider
|
||||
if (getTicks() % 5 == 0)
|
||||
@ -79,14 +87,29 @@ public class AbsorbState extends BossState
|
||||
if (dist < 5)
|
||||
{
|
||||
_entity.setPassenger(closest);
|
||||
_hasRider = true;
|
||||
_rider = closest;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check for rider
|
||||
_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;
|
||||
getBoss().setState(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,6 +128,35 @@ public class AbsorbState extends BossState
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user