Undead Camp
This commit is contained in:
parent
7f530f6593
commit
1865e41144
@ -1,66 +0,0 @@
|
||||
package mineplex.game.clans.clans.worldevent;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import net.minecraft.server.v1_7_R4.World;
|
||||
|
||||
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;
|
||||
|
||||
public class ConcreteWorldEventFactory implements WorldEventFactory
|
||||
{
|
||||
private WorldEventManager _eventManager;
|
||||
private List<Class<? extends WorldEvent>> _eventClasses;
|
||||
private Random _random;
|
||||
|
||||
public ConcreteWorldEventFactory(WorldEventManager eventManager)
|
||||
{
|
||||
_eventManager = eventManager;
|
||||
_random = new Random();
|
||||
|
||||
_eventClasses = new ArrayList<Class<? extends WorldEvent>>();
|
||||
_eventClasses.add(SlimeBoss.class);
|
||||
_eventClasses.add(KingHill.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldEvent fromName(Location location, String name)
|
||||
{
|
||||
if (name.equalsIgnoreCase("slime"))
|
||||
{
|
||||
return new SlimeBoss(_eventManager, location);
|
||||
} else if (name.equalsIgnoreCase("kinghill"))
|
||||
{
|
||||
return new KingHill(_eventManager, location);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public WorldEvent random(Location location)
|
||||
{
|
||||
WorldEvent worldEvent = null;
|
||||
Class<? extends WorldEvent> clazz = _eventClasses.get(_random.nextInt(_eventClasses.size()));
|
||||
|
||||
try
|
||||
{
|
||||
worldEvent = clazz.getConstructor(WorldEventManager.class, Location.class).newInstance(_eventManager, location);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return worldEvent;
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package mineplex.game.clans.clans.worldevent;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
|
||||
|
||||
public interface WorldEventFactory
|
||||
{
|
||||
public WorldEvent fromName(Location location, String name);
|
||||
|
||||
public WorldEvent random(Location location);
|
||||
}
|
@ -36,7 +36,6 @@ import mineplex.minecraft.game.core.damage.DamageManager;
|
||||
|
||||
public class WorldEventManager extends MiniPlugin implements ScoreboardElement
|
||||
{
|
||||
private final WorldEventFactory _factory;
|
||||
private final List<WorldEvent> _events;
|
||||
|
||||
private Random _random;
|
||||
@ -55,7 +54,6 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
|
||||
_terrainFinder = new EventTerrainFinder(this, clansManager);
|
||||
_clansManager = clansManager;
|
||||
_damageManager = damageManager;
|
||||
_factory = new ConcreteWorldEventFactory(this);
|
||||
_events = new LinkedList<WorldEvent>();
|
||||
_lastEventEnd = System.currentTimeMillis();
|
||||
updateNextEventTime();
|
||||
@ -124,8 +122,9 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
|
||||
Location location = _terrainFinder.findArea(Bukkit.getWorlds().get(0), 30, 30);
|
||||
if (location != null)
|
||||
{
|
||||
WorldEvent event = _factory.random(location);
|
||||
initializeEvent(event);
|
||||
WorldEventType[] types = WorldEventType.values();
|
||||
WorldEvent worldEvent = types[_random.nextInt(types.length)].createInstance(this, location);
|
||||
initializeEvent(worldEvent);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -145,9 +144,15 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
|
||||
|
||||
public WorldEvent startEventFromName(Location location, String name)
|
||||
{
|
||||
WorldEvent event = _factory.fromName(location, name);
|
||||
if (event != null) initializeEvent(event);
|
||||
return event;
|
||||
WorldEventType eventType = WorldEventType.valueOf(name);
|
||||
if (eventType != null)
|
||||
{
|
||||
WorldEvent event = eventType.createInstance(this, location);
|
||||
initializeEvent(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void clearEvents()
|
||||
@ -174,6 +179,11 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement
|
||||
return _damageManager;
|
||||
}
|
||||
|
||||
public EventTerrainFinder getTerrainFinder()
|
||||
{
|
||||
return _terrainFinder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCommands()
|
||||
{
|
||||
|
@ -0,0 +1,40 @@
|
||||
package mineplex.game.clans.clans.worldevent;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
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;
|
||||
import mineplex.game.clans.clans.worldevent.event.undead.UndeadCamp;
|
||||
|
||||
public enum WorldEventType
|
||||
{
|
||||
SLIME_KING("Slime King", SlimeBoss.class),
|
||||
KING_OF_THE_HILL("King of The Hill", KingHill.class),
|
||||
UNDEAD_CAMP("Undead Camp", UndeadCamp.class);
|
||||
|
||||
private String _name;
|
||||
private Class<? extends WorldEvent> _clazz;
|
||||
|
||||
WorldEventType(String name, Class<? extends WorldEvent> clazz)
|
||||
{
|
||||
_name = name;
|
||||
_clazz = clazz;
|
||||
}
|
||||
|
||||
public WorldEvent createInstance(WorldEventManager eventManager, Location centerLocation)
|
||||
{
|
||||
WorldEvent worldEvent = null;
|
||||
|
||||
try
|
||||
{
|
||||
worldEvent = _clazz.getConstructor(WorldEventManager.class, Location.class).newInstance(eventManager, centerLocation);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return worldEvent;
|
||||
}
|
||||
}
|
@ -213,6 +213,11 @@ public abstract class WorldEvent implements Listener
|
||||
task.start();
|
||||
}
|
||||
|
||||
protected HashMap<Block, BlockData> getBlocks()
|
||||
{
|
||||
return _blocks;
|
||||
}
|
||||
|
||||
public void setBlock(Block block, int id, byte data)
|
||||
{
|
||||
if (!_blocks.containsKey(block))
|
||||
|
@ -0,0 +1,31 @@
|
||||
package mineplex.game.clans.clans.worldevent.event.undead;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
public enum CampType
|
||||
{
|
||||
OAK(new MaterialData(Material.LOG, (byte) 0), new MaterialData(Material.WOOD, (byte) 0)),
|
||||
SPRUCE(new MaterialData(Material.LOG, (byte) 1), new MaterialData(Material.WOOD, (byte) 1)),
|
||||
BIRCH(new MaterialData(Material.LOG, (byte) 2), new MaterialData(Material.WOOD, (byte) 2)),
|
||||
JUNGLE(new MaterialData(Material.LOG, (byte) 3), new MaterialData(Material.WOOD, (byte) 3));
|
||||
|
||||
private MaterialData _log;
|
||||
private MaterialData _wood;
|
||||
|
||||
CampType(MaterialData log, MaterialData wood)
|
||||
{
|
||||
_log = log;
|
||||
_wood = wood;
|
||||
}
|
||||
|
||||
public MaterialData getLog()
|
||||
{
|
||||
return _log;
|
||||
}
|
||||
|
||||
public MaterialData getWood()
|
||||
{
|
||||
return _wood;
|
||||
}
|
||||
}
|
@ -0,0 +1,327 @@
|
||||
package mineplex.game.clans.clans.worldevent.event.undead;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
||||
import mineplex.core.common.util.UtilBlock;
|
||||
import mineplex.core.common.util.UtilMath;
|
||||
import mineplex.core.common.util.UtilWorld;
|
||||
import mineplex.game.clans.clans.worldevent.WorldEventManager;
|
||||
import mineplex.game.clans.clans.worldevent.event.EventState;
|
||||
import mineplex.game.clans.clans.worldevent.event.WorldEvent;
|
||||
|
||||
public class UndeadCamp extends WorldEvent
|
||||
{
|
||||
private int _mod = 4;
|
||||
private int _areaSize = 18;
|
||||
|
||||
private int _hutCur = 0;
|
||||
private int _poleCur = 0;
|
||||
private int _towerCur = 0;
|
||||
|
||||
private int _hutMax = 0;
|
||||
private int _poleMax = 0;
|
||||
private int _towerMax = 0;
|
||||
|
||||
private int _minZombie = 0;
|
||||
|
||||
private CampType _campType;
|
||||
|
||||
public UndeadCamp(WorldEventManager eventManager, Location centerLocation)
|
||||
{
|
||||
super(eventManager, "Undead Camp", centerLocation);
|
||||
|
||||
_areaSize = (int) (8 * _mod);
|
||||
|
||||
_hutMax = (int) (_mod * _mod * (UtilMath.r(4) + 1));
|
||||
_towerMax = (int) (_mod * _mod * (UtilMath.r(4) + 3));
|
||||
_poleMax = (int) (_mod * _mod * (UtilMath.r(11) + 10));
|
||||
_minZombie = (int) (_mod * (UtilMath.r(9) + 8));
|
||||
|
||||
_campType = CampType.JUNGLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customStart()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customTick()
|
||||
{
|
||||
System.out.println("tick");
|
||||
if (getState() == EventState.PREPARE)
|
||||
{
|
||||
System.out.println("prep");
|
||||
if (_hutCur < _hutMax) createHut();
|
||||
// else if (getCreatures().size() < _minZombie) createZombie();
|
||||
else if (_towerCur < _towerMax) createTower();
|
||||
else if (_poleCur < _poleMax) createLamp();
|
||||
|
||||
else
|
||||
{
|
||||
System.out.println("Constructed " + getName() + " at " + UtilWorld.locToStrClean(getCenterLocation()) + ".");
|
||||
setState(EventState.LIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createHut()
|
||||
{
|
||||
int hutX = UtilMath.r(4) + 2;
|
||||
int hutZ = UtilMath.r(4) + 2;
|
||||
int hutY = UtilMath.r(2) + 3;
|
||||
|
||||
int buffer = Math.max(hutX, hutZ)/2 + 1;
|
||||
|
||||
Location loc = getEventManager().getTerrainFinder().locateSpace(getCenterLocation(), _areaSize-buffer, hutX, hutY+2, hutZ, true, false, getBlocks().keySet());
|
||||
|
||||
if (loc == null)
|
||||
return;
|
||||
|
||||
boolean xWall = (Math.random() > 0.5);
|
||||
boolean zWall = (Math.random() > 0.5);
|
||||
|
||||
//Base
|
||||
for (int x = -hutX; x <= hutX; x++)
|
||||
for (int z = -hutZ; z <=hutZ ; z++)
|
||||
{
|
||||
Block block = loc.getBlock().getRelative(x, -1, z);
|
||||
|
||||
//Space
|
||||
for (int y=0 ; y<=hutY ; y++)
|
||||
setBlock(loc.getBlock().getRelative(x, y, z), 0, (byte) 0);
|
||||
|
||||
//Walls
|
||||
if (!xWall && x == -hutX || xWall && x == hutX || !zWall && z == -hutZ || zWall && z == hutZ)
|
||||
for (int y = 0; y <=hutY ; y++)
|
||||
setBlock(loc.getBlock().getRelative(x, y, z), _campType.getWood().getItemTypeId(), _campType.getWood().getData());
|
||||
|
||||
//Corners
|
||||
if (Math.abs(x) == hutX && Math.abs(z) == hutZ)
|
||||
{
|
||||
setBlock(block, _campType.getLog().getItemTypeId(), _campType.getLog().getData());
|
||||
for (int y=0 ; y<=hutY ; y++)
|
||||
setBlock(loc.getBlock().getRelative(x, y, z), _campType.getLog().getItemTypeId(), _campType.getLog().getData());
|
||||
|
||||
//Support Stands
|
||||
boolean support = true;
|
||||
Block below = block;
|
||||
while (support)
|
||||
{
|
||||
below = below.getRelative(BlockFace.DOWN);
|
||||
|
||||
if (!UtilBlock.fullSolid(below) || below.isLiquid())
|
||||
setBlock(below, _campType.getLog().getItemTypeId(), _campType.getLog().getData());
|
||||
|
||||
else
|
||||
support = false;
|
||||
}
|
||||
}
|
||||
|
||||
//Floor & Roof
|
||||
else
|
||||
{
|
||||
setBlock(block, _campType.getWood().getItemTypeId(), _campType.getWood().getData());
|
||||
setBlock(loc.getBlock().getRelative(x, hutY-1, z), 126, (byte)8);
|
||||
}
|
||||
|
||||
//Insides
|
||||
if (Math.abs(x) != hutX && Math.abs(z) != hutZ)
|
||||
{
|
||||
if (Math.random() > 0.90)
|
||||
addChest(block.getRelative(BlockFace.UP));
|
||||
|
||||
else if (Math.random() > 0.95)
|
||||
addFurnace(block.getRelative(BlockFace.UP));
|
||||
|
||||
// else if (Math.random() > 0.95)
|
||||
// CreatureRegister(new UndeadWarrior(this, block.getRelative(BlockFace.UP).getLocation().add(0.5, 0.5, 0.5)));
|
||||
}
|
||||
}
|
||||
|
||||
_hutCur++;
|
||||
}
|
||||
|
||||
private void addChest(Block chest)
|
||||
{
|
||||
Block side;
|
||||
int adj = 0;
|
||||
|
||||
side = chest.getRelative(BlockFace.NORTH);
|
||||
if (side.getType() == Material.CHEST)
|
||||
{
|
||||
adj++;
|
||||
if (side.getRelative(BlockFace.NORTH).getType() == Material.CHEST) return;
|
||||
if (side.getRelative(BlockFace.SOUTH).getType() == Material.CHEST) return;
|
||||
if (side.getRelative(BlockFace.EAST).getType() == Material.CHEST) return;
|
||||
if (side.getRelative(BlockFace.WEST).getType() == Material.CHEST) return;
|
||||
}
|
||||
|
||||
side = chest.getRelative(BlockFace.SOUTH);
|
||||
if (side.getType() == Material.CHEST)
|
||||
{
|
||||
adj++;
|
||||
if (side.getRelative(BlockFace.NORTH).getType() == Material.CHEST) return;
|
||||
if (side.getRelative(BlockFace.SOUTH).getType() == Material.CHEST) return;
|
||||
if (side.getRelative(BlockFace.EAST).getType() == Material.CHEST) return;
|
||||
if (side.getRelative(BlockFace.WEST).getType() == Material.CHEST) return;
|
||||
}
|
||||
|
||||
side = chest.getRelative(BlockFace.EAST);
|
||||
if (side.getType() == Material.CHEST)
|
||||
{
|
||||
adj++;
|
||||
if (side.getRelative(BlockFace.NORTH).getType() == Material.CHEST) return;
|
||||
if (side.getRelative(BlockFace.SOUTH).getType() == Material.CHEST) return;
|
||||
if (side.getRelative(BlockFace.EAST).getType() == Material.CHEST) return;
|
||||
if (side.getRelative(BlockFace.WEST).getType() == Material.CHEST) return;
|
||||
}
|
||||
|
||||
side = chest.getRelative(BlockFace.WEST);
|
||||
if (side.getType() == Material.CHEST)
|
||||
{
|
||||
adj++;
|
||||
if (side.getRelative(BlockFace.NORTH).getType() == Material.CHEST) return;
|
||||
if (side.getRelative(BlockFace.SOUTH).getType() == Material.CHEST) return;
|
||||
if (side.getRelative(BlockFace.EAST).getType() == Material.CHEST) return;
|
||||
if (side.getRelative(BlockFace.WEST).getType() == Material.CHEST) return;
|
||||
}
|
||||
|
||||
if (adj > 1)
|
||||
return;
|
||||
|
||||
setBlock(chest, 130, (byte)(UtilMath.r(4) + 2));
|
||||
// _chests.add(chest);
|
||||
}
|
||||
|
||||
|
||||
private void addFurnace(Block chest)
|
||||
{
|
||||
setBlock(chest, 61, (byte) (UtilMath.r(4) + 2));
|
||||
// _chests.add(chest);
|
||||
}
|
||||
|
||||
private void createZombie()
|
||||
{
|
||||
|
||||
Location loc = getEventManager().getTerrainFinder().locateSpace(getCenterLocation(), _areaSize, 0, 3, 0, false, true, getBlocks().keySet());
|
||||
|
||||
if (loc == null)
|
||||
return;
|
||||
|
||||
// CreatureRegister(new UndeadWarrior(this, loc.add(0.5, 0.5, 0.5)));
|
||||
|
||||
_poleCur++;
|
||||
// ResetIdleTicks();
|
||||
}
|
||||
|
||||
private void createTower()
|
||||
{
|
||||
int towerX = UtilMath.r(3) + 1;
|
||||
int towerZ = UtilMath.r(3) + 1;
|
||||
int towerY = UtilMath.r(4) + 3;
|
||||
|
||||
int buffer = Math.max(towerX, towerZ)/2 + 1;
|
||||
|
||||
Location loc = getEventManager().getTerrainFinder().locateSpace(getCenterLocation(), _areaSize - buffer, towerX, towerY + 2, towerZ, false, true, getBlocks().keySet());
|
||||
|
||||
if (loc == null)
|
||||
return;
|
||||
|
||||
int ladder = UtilMath.r(4);
|
||||
|
||||
|
||||
//Base
|
||||
for (int x=-towerX ; x<=towerX ; x++)
|
||||
for (int z=-towerZ ; z<=towerZ ; z++)
|
||||
{
|
||||
Block block = loc.getBlock().getRelative(x, towerY, z);
|
||||
|
||||
//Space
|
||||
for (int y=0 ; y<=towerY ; y++)
|
||||
setBlock(loc.getBlock().getRelative(x, y, z), 0, (byte) 0);
|
||||
|
||||
//Corner
|
||||
if (Math.abs(x) == towerX && Math.abs(z) == towerZ)
|
||||
{
|
||||
setBlock(block, _campType.getWood().getItemTypeId(), _campType.getWood().getData());
|
||||
setBlock(block.getRelative(BlockFace.UP), 85, (byte) 0);
|
||||
|
||||
//Support Stands
|
||||
boolean support = true;
|
||||
Block below = block;
|
||||
while (support)
|
||||
{
|
||||
below = below.getRelative(BlockFace.DOWN);
|
||||
|
||||
if (!UtilBlock.fullSolid(below) && !below.isLiquid())
|
||||
setBlock(below, 85, (byte) 0);
|
||||
|
||||
else if (below.isLiquid())
|
||||
setBlock(below, _campType.getLog().getItemTypeId(), _campType.getLog().getData());
|
||||
|
||||
else
|
||||
support = false;
|
||||
}
|
||||
|
||||
//Ladder
|
||||
if (ladder == 0 && x == -towerX && z == -towerZ ||
|
||||
ladder == 1 && x == -towerX && z == towerZ ||
|
||||
ladder == 2 && x == towerX && z == -towerZ ||
|
||||
ladder == 3 && x == towerX && z == towerZ)
|
||||
{
|
||||
boolean laddering = true;
|
||||
below = block;
|
||||
while (laddering)
|
||||
{
|
||||
below = below.getRelative(BlockFace.DOWN);
|
||||
|
||||
if (!UtilBlock.fullSolid(below))
|
||||
{
|
||||
setBlock(below, _campType.getWood().getItemTypeId(), _campType.getWood().getData());
|
||||
|
||||
if (ladder == 0) setBlock(below.getRelative(-1, 0, 0), 65, (byte) 4);
|
||||
else if (ladder == 1) setBlock(below.getRelative(-1, 0, 0), 65, (byte) 4);
|
||||
else if (ladder == 2) setBlock(below.getRelative(1, 0, 0), 65, (byte) 5);
|
||||
else if (ladder == 3) setBlock(below.getRelative(1, 0, 0), 65, (byte) 5);
|
||||
}
|
||||
|
||||
else
|
||||
laddering = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Platform
|
||||
else
|
||||
setBlock(block, 126, (byte) 8);
|
||||
|
||||
//Features
|
||||
if (Math.random() > 0.95)
|
||||
addChest(block.getRelative(BlockFace.UP));
|
||||
|
||||
// else if (Math.random() > 0.95)
|
||||
// CreatureRegister(new UndeadArcher(this, block.getRelative(BlockFace.UP).getLocation().add(0.5, 0.5, 0.5)));
|
||||
}
|
||||
|
||||
_towerCur++;
|
||||
}
|
||||
|
||||
private void createLamp()
|
||||
{
|
||||
Location loc = getEventManager().getTerrainFinder().locateSpace(getCenterLocation(), _areaSize, 0, 4, 0, false, true, getBlocks().keySet());
|
||||
|
||||
if (loc == null)
|
||||
return;
|
||||
|
||||
setBlock(loc.getBlock(), 85, (byte) 0);
|
||||
setBlock(loc.getBlock().getRelative(BlockFace.UP), 85, (byte) 0);
|
||||
setBlock(loc.getBlock().getRelative(BlockFace.UP).getRelative(BlockFace.UP), 50, (byte)0);
|
||||
|
||||
_poleCur++;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user