From be974bfaac98f584c84d739dcb349e5a241b7c49 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Tue, 30 Jun 2015 14:02:39 -0500 Subject: [PATCH] Work from laptop --- .../mineplex/core/common/util/UtilMath.java | 5 ++ .../clans/worldevent/WorldEventManager.java | 8 +- .../clans/worldevent/WorldEventType.java | 5 ++ .../worldevent/event/undead/CampSize.java | 84 +++++++++++++++++++ .../worldevent/event/undead/UndeadCamp.java | 62 +++++++------- 5 files changed, 126 insertions(+), 38 deletions(-) create mode 100644 Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/undead/CampSize.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java index 2ba63686b..2a6dab3a9 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilMath.java @@ -26,6 +26,11 @@ public class UtilMath { return random.nextInt(i); } + + public static int rRange(int min, int max) + { + return min + r(max - min); + } public static double offset2d(Entity a, Entity b) { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java index adc702eca..8ac75af64 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventManager.java @@ -119,12 +119,12 @@ public class WorldEventManager extends MiniPlugin implements ScoreboardElement private void startRandomEvent() { - Location location = _terrainFinder.findArea(Bukkit.getWorlds().get(0), 30, 30); + WorldEventType[] types = WorldEventType.values(); + WorldEventType type = types[_random.nextInt(types.length)]; + Location location = _terrainFinder.findArea(Bukkit.getWorlds().get(0), type.getAreaNeeded(), type.getAreaNeeded()); if (location != null) { - WorldEventType[] types = WorldEventType.values(); - WorldEvent worldEvent = types[_random.nextInt(types.length)].createInstance(this, location); - initializeEvent(worldEvent); + initializeEvent(type.createInstance(this, location)); } else { diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventType.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventType.java index b1e22f96b..d2a50e064 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventType.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/WorldEventType.java @@ -24,6 +24,11 @@ public enum WorldEventType _areaNeeded = areaNeeded; } + public int getAreaNeeded() + { + return _areaNeeded; + } + public WorldEvent createInstance(WorldEventManager eventManager, Location centerLocation) { WorldEvent worldEvent = null; diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/undead/CampSize.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/undead/CampSize.java new file mode 100644 index 000000000..797b1d730 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/undead/CampSize.java @@ -0,0 +1,84 @@ +package mineplex.game.clans.clans.worldevent.event.undead; + +import mineplex.core.common.util.UtilMath; + +public enum CampSize +{ + SMALL("Small Camp", 10, 0, 1), + + MEDIUM("Medium Camp", 20, 10, 2), + + LARGE("Large Camp", 30, 20, 3); + + // Base Values + private static final int HUT_MIN = 4; + private static final int HUT_MAX = 8; + private static final int TOWER_MIN = 4; + private static final int TOWER_MAX = 8; + private static final int POLE_MIN = 10; + private static final int POLE_MAX = 20; + private static final int UNDEAD_MIN = 10; + private static final int UNDEAD_MAX = 20; + + private String _name; + private int _areaNeeded; + private int _playersNeeded; + private int _modValue; + + CampSize(String name, int areaNeeded, int playersNeeded, int modValue) + { + _name = name; + _areaNeeded = areaNeeded; + _playersNeeded = playersNeeded; + _modValue = modValue; + } + + public String getName() + { + return _name; + } + + public int getAreaNeeded() + { + return _areaNeeded; + } + + public int getPlayersNeeded() + { + return _playersNeeded; + } + + public int generateHutCount() + { + return _modValue * UtilMath.rRange(HUT_MIN, HUT_MAX); + } + + public int generateTowerCount() + { + return _modValue * UtilMath.rRange(TOWER_MIN, TOWER_MAX); + } + + public int generatePoleCount() + { + return _modValue * UtilMath.rRange(POLE_MIN, POLE_MAX); + } + + public int generateUndeadCount() + { + return _modValue * UtilMath.rRange(UNDEAD_MIN, UNDEAD_MAX); + } + + public static CampSize getCampSize(int playerCount) + { + CampSize campSize = CampSize.SMALL; + + for (CampSize c : values()) + { + if (playerCount >= c.getPlayersNeeded() && (campSize == null || c.getPlayersNeeded() > campSize.getPlayersNeeded())) + campSize = c; + } + + return campSize; + } + +} diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/undead/UndeadCamp.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/undead/UndeadCamp.java index cf9959078..49f9ca6b4 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/undead/UndeadCamp.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/worldevent/event/undead/UndeadCamp.java @@ -11,6 +11,8 @@ import org.bukkit.event.entity.EntityInteractEvent; import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilServer; import mineplex.core.common.util.UtilWorld; import mineplex.game.clans.clans.worldevent.WorldEventManager; import mineplex.game.clans.clans.worldevent.event.EventState; @@ -20,35 +22,29 @@ import mineplex.game.clans.clans.worldevent.event.undead.creature.UndeadWarrior; public class UndeadCamp extends WorldEvent { - private int _mod = 4; - private int _areaSize = 30; - - 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 int _hutLeft = 0; + private int _poleLeft = 0; + private int _towerLeft = 0; + private int _undeadCount = 0; private CampType _campType; + private CampSize _campSize; private HashSet _chests; 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)); - + _campSize = CampSize.getCampSize(UtilServer.getPlayers().length); _campType = CampType.JUNGLE; _chests = new HashSet(); + + _hutLeft = _campSize.generateHutCount(); + _poleLeft = _campSize.generatePoleCount(); + _towerLeft = _campSize.generateTowerCount(); + _undeadCount = _campSize.generateUndeadCount(); + + setName(_campSize.getName()); } @Override @@ -60,14 +56,12 @@ public class UndeadCamp extends WorldEvent @Override protected void customTick() { - System.out.println("tick"); if (getState() == EventState.PREPARE) { - if (_hutCur < _hutMax) createHut(); - else if (getCreatures().size() < _minZombie) createZombie(); - else if (_towerCur < _towerMax) createTower(); - else if (_poleCur < _poleMax) createLamp(); - + if (_hutLeft > 0) createHut(); + else if (_towerLeft > 0) createTower(); + else if (_poleLeft > 0) createLamp(); + else if (getCreatures().size() < _undeadCount) createUndead(); else { System.out.println("Constructed " + getName() + " at " + UtilWorld.locToStrClean(getCenterLocation()) + "."); @@ -84,7 +78,7 @@ public class UndeadCamp extends WorldEvent int buffer = Math.max(hutX, hutZ)/2 + 1; - Location loc = getEventManager().getTerrainFinder().locateSpace(getCenterLocation(), _areaSize-buffer, hutX, hutY+2, hutZ, true, false, getBlocks().getChangedBlocks()); + Location loc = getEventManager().getTerrainFinder().locateSpace(getCenterLocation(), _campSize.getAreaNeeded()-buffer, hutX, hutY+2, hutZ, true, false, getBlocks().getChangedBlocks()); if (loc == null) return; @@ -150,7 +144,7 @@ public class UndeadCamp extends WorldEvent } } - _hutCur++; + _hutLeft--; } private void addChest(Block chest) @@ -212,17 +206,17 @@ public class UndeadCamp extends WorldEvent // _chests.add(chest); } - private void createZombie() + private void createUndead() { - Location loc = getEventManager().getTerrainFinder().locateSpace(getCenterLocation(), _areaSize, 0, 3, 0, false, true, getBlocks().getChangedBlocks()); + Location loc = getEventManager().getTerrainFinder().locateSpace(getCenterLocation(), _campSize.getAreaNeeded(), 0, 3, 0, false, true, getBlocks().getChangedBlocks()); if (loc == null) return; registerCreature(new UndeadWarrior(this, loc.add(0.5, 0.5, 0.5))); - _poleCur++; + _poleLeft--; // ResetIdleTicks(); } @@ -234,7 +228,7 @@ public class UndeadCamp extends WorldEvent int buffer = Math.max(towerX, towerZ)/2 + 1; - Location loc = getEventManager().getTerrainFinder().locateSpace(getCenterLocation(), _areaSize - buffer, towerX, towerY + 2, towerZ, false, true, getBlocks().getChangedBlocks()); + Location loc = getEventManager().getTerrainFinder().locateSpace(getCenterLocation(), _campSize.getAreaNeeded() - buffer, towerX, towerY + 2, towerZ, false, true, getBlocks().getChangedBlocks()); if (loc == null) return; @@ -315,12 +309,12 @@ public class UndeadCamp extends WorldEvent registerCreature(new UndeadArcher(this, block.getRelative(BlockFace.UP).getLocation().add(0.5, 0.5, 0.5))); } - _towerCur++; + _towerLeft--; } private void createLamp() { - Location loc = getEventManager().getTerrainFinder().locateSpace(getCenterLocation(), _areaSize, 0, 4, 0, false, true, getBlocks().getChangedBlocks()); + Location loc = getEventManager().getTerrainFinder().locateSpace(getCenterLocation(), _campSize.getAreaNeeded(), 0, 4, 0, false, true, getBlocks().getChangedBlocks()); if (loc == null) return; @@ -329,7 +323,7 @@ public class UndeadCamp extends WorldEvent setBlock(loc.getBlock().getRelative(BlockFace.UP), 85, (byte) 0); setBlock(loc.getBlock().getRelative(BlockFace.UP).getRelative(BlockFace.UP), 50, (byte)0); - _poleCur++; + _poleLeft--; } @EventHandler