From c6ec60700c76e3c34bae8bf4c3b1000895806f35 Mon Sep 17 00:00:00 2001 From: fooify Date: Tue, 11 Aug 2015 09:04:45 -0700 Subject: [PATCH] monster maze is really working now! :D --- .../arcade/game/games/monstermaze/Maze.java | 406 ++++++++++-------- .../games/monstermaze/MazeMobWaypoint.java | 4 +- .../game/games/monstermaze/MonsterMaze.java | 20 +- 3 files changed, 241 insertions(+), 189 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/monstermaze/Maze.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/monstermaze/Maze.java index e3e7c559e..5733437e7 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/monstermaze/Maze.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/monstermaze/Maze.java @@ -11,6 +11,7 @@ import org.bukkit.Color; import org.bukkit.FireworkEffect; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.entity.Creeper; @@ -27,14 +28,14 @@ import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilAction; import mineplex.core.common.util.UtilAlg; +import mineplex.core.common.util.UtilBlock; import mineplex.core.common.util.UtilEnt; import mineplex.core.common.util.UtilFirework; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilPlayer; +import mineplex.core.common.util.UtilTextMiddle; import mineplex.core.common.util.UtilTextTop; import mineplex.core.common.util.UtilTime; -import mineplex.core.hologram.Hologram; -import mineplex.core.hologram.Hologram.HologramTarget; import mineplex.core.recharge.Recharge; import nautilus.game.arcade.game.games.monstermaze.MazeMobWaypoint.CardinalDirection; @@ -45,20 +46,16 @@ public class Maze implements Listener private ArrayList _map; private ArrayList _goals; private HashSet _waypoints; - private HashSet _disabledWaypoints; // TODO x) + private HashSet _disabledWaypoints; private ArrayList _borders; private SafePad _safePad = null; private SafePad _oldSafePad = null; - private Hologram _holo; + private ArrayList _playersOnPad = new ArrayList(); - //private ArrayList _goalPlayers = new ArrayList(); // players who got the goal - - private int _phaseTimer = -1; // counts down - /* - * 10-0 - get to the goal... - */ + private int _phaseTimer = -1; + private int _padDecayTimer = -1; private HashMap _ents = new HashMap(); @@ -69,9 +66,9 @@ public class Maze implements Listener _map = map; _spawns = spawns; _goals = goals; - //_borders = borders; _waypoints = new HashSet(); + _disabledWaypoints = new HashSet(); for (Location loc : _map) { @@ -92,14 +89,31 @@ public class Maze implements Listener } } - public void Update() + public void update() { if (Host.IsLive()) { //checkGoal(); - UtilTextTop.display(C.cAqua + C.Bold + "Get to the safe pad or you'll take damage!", Host.GetPlayers(false).toArray(new Player[Host.GetPlayers(false).size()])); + checkPlayersOnSafePad(); move(); bump(); + if(_phaseTimer <= -1) + { + UtilTextTop.display(C.cAqua + C.Bold + "Be the first player to get to the safe pad!", Host.GetPlayers(true).toArray(new Player[Host.GetPlayers(false).size()])); + } + else + { + for(Player p : Host.GetPlayers(true)) + { + if(_safePad.isOn(p)) + { + UtilTextTop.display(C.cGreen + C.Bold + "Stay on the safe pad for " + _phaseTimer + " more seconds!", p); + } + else { + UtilTextTop.display(C.cRed + C.Bold + "You have " + _phaseTimer + " seconds to get to the safe pad!", p); + } + } + } } } @@ -143,7 +157,7 @@ public class Maze implements Listener //New or Fallen if (data.getValue().Target == null || data.getKey().getLocation().getY() < data.getValue().Target.getBlockY()) { - Location loc = UtilAlg.findClosest(data.getKey().getLocation(), _spawns); + Location loc = UtilAlg.findClosest(data.getKey().getLocation(), _map); data.getKey().teleport(loc); data.getValue().Target = loc; @@ -164,7 +178,14 @@ public class Maze implements Listener if (east != null) nextBlock.add(east); if (west != null) nextBlock.add(west); - if(nextBlock.size() > 1 && data.getValue().Direction != null) // they can do a uturn if they're stuck + if(nextBlock.size() == 0) + { + System.err.println("ENTITY HAS NO DIRECTION TO GO, removing entity"); + entIterator.remove(); + + } + + if(nextBlock.size() > 1 && data.getValue().Direction != CardinalDirection.NULL) // they can do a uturn if they're stuck { if(data.getValue().Direction == CardinalDirection.NORTH) { @@ -207,11 +228,6 @@ public class Maze implements Listener } -// if(_safePad != null && _safePad.isOn(data.getKey())) -// { -// UtilAction.velocity(data.getKey(), UtilAlg.getTrajectory(data.getKey().getLocation(), _safePad.getLocation()), 1, false, 0, 0.5, 1.2, true); -// } - //Timeout Move if (UtilMath.offset(data.getKey().getLocation(), data.getValue().Last) > 0.1) data.getValue().Time = System.currentTimeMillis(); @@ -247,200 +263,238 @@ public class Maze implements Listener return cur; } - - /* - * [11:28:29 ERROR]: Could not pass event UpdateEvent to Arcade v0.1 -org.bukkit.event.EventException - at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-gb748d57] - at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-gb748d57] - at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:514) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-gb748d57] - at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:499) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-gb748d57] - at mineplex.core.updater.Updater.run(Updater.java:24) [Arcade.jar:?] - at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftTask.run(CraftTask.java:71) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-gb748d57] - at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-gb748d57] - at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:641) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-gb748d57] - at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:275) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-gb748d57] - at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-gb748d57] - at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-gb748d57] - at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-205-gb748d57] -Caused by: java.lang.NullPointerException - - */ - public void spawn() + public void fillSpawn(int numToSpawn) { - //Spawn - //if (Host.IsLive()) - - if(_ents.size() >= 100) return; + System.out.println("spawning " + numToSpawn + " entities on map"); - Location loc = UtilAlg.Random(_spawns); - - Host.CreatureAllowOverride = true; - Entity ent; - //Snowman ent = loc.getWorld().spawn(loc, Snowman.class); - if(Host.getMonsterType() == EntityType.ZOMBIE) - { - ent = loc.getWorld().spawn(loc, Zombie.class); - } - else if(Host.getMonsterType() == EntityType.SNOWMAN) - { - ent = loc.getWorld().spawn(loc, Snowman.class); - } - else if(Host.getMonsterType() == EntityType.CREEPER) - { - ent = loc.getWorld().spawn(loc, Creeper.class); - } - else - { - ent = loc.getWorld().spawn(loc, Zombie.class); - } + int spawned = 0; - Host.CreatureAllowOverride = false; - - UtilEnt.Vegetate(ent); - UtilEnt.ghost(ent, true, false); - _ents.put(ent, new MazeMobWaypoint(ent.getLocation())); + while(spawned <= numToSpawn) + { + Location loc = UtilAlg.Random(_map); + Host.CreatureAllowOverride = true; + Entity ent = null; + if(Host.getMonsterType() == EntityType.ZOMBIE) + { + ent = loc.getWorld().spawn(loc, Zombie.class); + } + else if(Host.getMonsterType() == EntityType.SNOWMAN) + { + ent = loc.getWorld().spawn(loc, Snowman.class); + } + else if(Host.getMonsterType() == EntityType.CREEPER) + { + ent = loc.getWorld().spawn(loc, Creeper.class); + } + else + { + ent = loc.getWorld().spawn(loc, Zombie.class); + } + + Host.CreatureAllowOverride = false; + + UtilEnt.Vegetate(ent); + UtilEnt.ghost(ent, true, false); + _ents.put(ent, new MazeMobWaypoint(ent.getLocation())); + spawned++; + } } - + + public void spawn(int numToSpawn) + { + System.out.println("spawning " + numToSpawn + " entities at spawnpoints"); + Location loc = UtilAlg.Random(_spawns); + + int spawned = 0; + + while(spawned <= numToSpawn) + { + Host.CreatureAllowOverride = true; + Entity ent = null; + if(Host.getMonsterType() == EntityType.ZOMBIE) + { + ent = loc.getWorld().spawn(loc, Zombie.class); + } + else if(Host.getMonsterType() == EntityType.SNOWMAN) + { + ent = loc.getWorld().spawn(loc, Snowman.class); + } + else if(Host.getMonsterType() == EntityType.CREEPER) + { + ent = loc.getWorld().spawn(loc, Creeper.class); + } + else + { + ent = loc.getWorld().spawn(loc, Zombie.class); + } + + Host.CreatureAllowOverride = false; + + UtilEnt.Vegetate(ent); + UtilEnt.ghost(ent, true, false); + _ents.put(ent, new MazeMobWaypoint(ent.getLocation())); + spawned++; + } + } + + public void spawnSafePad() + { + System.out.println("creating safe pad"); + if(_safePad != null) + { + _oldSafePad = _safePad; + _oldSafePad.turnOffBeacon(); + _padDecayTimer = 5; + } + ArrayList goals = new ArrayList(_goals); + if(_oldSafePad != null) goals.remove(_oldSafePad.getLocation()); + + if(_disabledWaypoints.size() > 0) + { + for(Block b : _disabledWaypoints) + { + System.out.println("remove"); + _waypoints.add(b); + } + _disabledWaypoints.clear(); + } + + _safePad = new SafePad(Host, this, UtilAlg.Random(goals).clone().subtract(0,1,0)); // maybe don't need to clone() + _safePad.build(); + UtilFirework.playFirework(_safePad.getLocation(), FireworkEffect.builder().withColor(Color.LIME).build()); + + Iterator iter = _waypoints.iterator(); + while (iter.hasNext()) { + Block b = iter.next(); + if(UtilBlock.getInBoundingBox(_safePad.getLocation().clone().add(2, 0, 2), _safePad.getLocation().clone().add(-2, 0, -2)).contains(b.getRelative(BlockFace.DOWN))) + { + System.out.println("block"); + _disabledWaypoints.add(b); + iter.remove(); + } + } + + Iterator it = _ents.keySet().iterator(); + while (it.hasNext()) { + Entity e = it.next(); + if(_safePad.isOn(e)) + { + System.out.println("ent"); + _ents.remove(_ents.get(e)); + it.remove(); + e.remove(); + } + } + } + + public void decrementSafePadTime() + { + if(_padDecayTimer == -1) return; + + _padDecayTimer--; + + if(_oldSafePad != null) + { + if(_padDecayTimer == 4) + { + _oldSafePad.setGlassData((byte)4); + _oldSafePad.turnOffBeacon(); + } + else if(_padDecayTimer == 3) + { + _oldSafePad.setGlassData((byte)1); + } + else if(_padDecayTimer == 2) + { + _oldSafePad.setGlassData((byte)14); + } + else if(_padDecayTimer == 1) + { + _oldSafePad.destroy(); + _oldSafePad = null; + } + } + if(_padDecayTimer == 1) + { + _padDecayTimer = -1; + } + } + public void decrementPhaseTime() { - if(_phaseTimer == -1) + if(_phaseTimer == -1) return; + /*if(_phaseTimer == -1) { _safePad = new SafePad(Host, this, UtilAlg.Random(_goals).clone().subtract(0,1,0)); _safePad.build(); UtilFirework.playFirework(_safePad.getLocation(), FireworkEffect.builder().withColor(Color.LIME).build()); -// Location holoLoc = _safePad.getLocation().clone(); -// holoLoc.add(0, 2, 0); -// _holo = new Hologram(Host.getArcadeManager().getHologramManager(), holoLoc, C.cAqua + C.Bold + "SAFE PAD!"); -// _holo.setHologramTarget(HologramTarget.BLACKLIST); -// _holo.start(); + + Iterator iter = _waypoints.iterator(); + while (iter.hasNext()) { + Block b = iter.next(); + if(UtilBlock.getInBoundingBox(_safePad.getLocation().clone().add(2, 0, 2), _safePad.getLocation().clone().add(-2, 0, -2)).contains(b.getRelative(BlockFace.DOWN))) + { + System.out.println("block"); + _disabledWaypoints.add(b); + iter.remove(); + } + } + _phaseTimer = 11; return; - } + }*/ _phaseTimer--; - - if(_phaseTimer == 10) - { - if(_oldSafePad != null) - { - _oldSafePad.setGlassData((byte)4); - _oldSafePad.turnOffBeacon(); - } - } - if(_phaseTimer == 9) - { - if(_oldSafePad != null) _oldSafePad.setGlassData((byte)1); - } - if(_phaseTimer == 8) - { - if(_oldSafePad != null) _oldSafePad.setGlassData((byte)14); - } - if(_phaseTimer == 7) - { - if(_oldSafePad != null) _oldSafePad.destroy(); - _oldSafePad = null; - } if(_phaseTimer == 0) { for(Player p : Host.GetPlayers(true)) { if(_safePad.isOn(p)) { + // maybe send them a happy message? =) + UtilPlayer.message(p, F.main("Game", C.cGreen + "Since you were on the safe pad, you didn't die!")); } else { Host.Manager.GetDamage().NewDamageEvent(p, null, null, - DamageCause.CUSTOM, 10, false, false, false, + DamageCause.CUSTOM, 500, false, false, false, "Game", "Map damage"); - //UtilPlayer.message(p, C.cRed + C.Bold + "Oh no! You didn't get to the safe pad in time."); - UtilPlayer.message(p, F.main("Game", C.cRed + "You took damage because you weren't on the safe pad!")); + UtilPlayer.message(p, F.main("Game", C.cRed + "You died because you weren't on the safe pad!")); } } - //_goalPlayers.clear(); -// if(_holo != null) -// { -// _holo.stop(); -// _holo = null; -// } - - _oldSafePad = _safePad; - _oldSafePad.turnOffBeacon(); - ArrayList goals = new ArrayList(_goals); - goals.remove(_oldSafePad.getLocation()); - - _safePad = new SafePad(Host, this, UtilAlg.Random(_goals).clone().subtract(0,1,0)); - _safePad.build(); - UtilFirework.playFirework(_safePad.getLocation(), FireworkEffect.builder().withColor(Color.LIME).build()); -// Location holoLoc = _safePad.getLocation().clone(); -// holoLoc.add(0, 2, 0); -// _holo = new Hologram(Host.getArcadeManager().getHologramManager(), holoLoc, C.cAqua + C.Bold + "SAFE PAD!"); -// _holo.setHologramTarget(HologramTarget.BLACKLIST); -// _holo.start(); -// for(Block b : _waypoints) -// { -// if(b.getRelative(BlockFace.DOWN).getType().equals(Material.QUARTZ_BLOCK)) -// { -// MapUtil.QuickChangeBlockAt(b.getLocation(), Material.CARPET.getId(), (byte)14); -// } -// } - _phaseTimer = 11; + spawn(15); + spawnSafePad(); + _playersOnPad.clear(); + _phaseTimer = -1; } -// if(_phaseTimer == 0) -// { -//// for(Block b : _waypoints) -//// { -//// if(b.getType().equals(Material.CARPET) && b.getData() == (byte)14) -//// { -//// MapUtil.QuickChangeBlockAt(b.getLocation(), Material.AIR); -//// } -//// } -// _phaseTimer = 11; -// } } - /*public void checkGoal() + public void checkPlayersOnSafePad() { if(_safePad == null) return; - for(Player pl : Host.GetPlayers(true)) + for(Player p : Host.GetPlayers(true)) { - if(_goalPlayers.contains(pl)) continue; - if(_safePad.isStandingOn(pl)) + if(_safePad.isOn(p) && !_playersOnPad.contains(p)) { - // TODO add sounds - _goalPlayers.add(pl); + _playersOnPad.add(p); + if(_playersOnPad.size() == 1) // first player + { + UtilTextMiddle.display(C.cGold + C.Bold + "AWESOME!", C.cGold + "You were the first to make it to the safe pad!", p); + p.playSound(p.getLocation(), Sound.SUCCESSFUL_HIT, 1.0f, 1.0f); + _phaseTimer = 21; + Host.Announce(C.cRed + C.Bold + p.getName() + " was the first to make it to the safe pad! Everyone not on the safe pad in 20 seconds will die!"); + } else // not the first + { + p.playSound(p.getLocation(), Sound.SUCCESSFUL_HIT, 1.0f, 1.0f); + UtilTextMiddle.display(C.cGreen + C.Bold + "Great!", C.cGreen + "You made it to the safe pad!"); + } } } - }*/ + } -// @EventHandler -// public void carpetDamage(UpdateEvent event) -// { -// if(event.getType() != UpdateType.SEC) return; -// if(!Host.IsLive()) return; -// for(Player p : Host.GetPlayers(true)) -// { -// Block pb = p.getLocation().getBlock(); -// boolean isTouchingCarpet = false; -// for(Block b : UtilBlock.getInRadius(pb, 0.66).keySet()) -// { -// if(b.getType().equals(Material.CARPET) && b.getData() == (byte)14) -// { -// isTouchingCarpet = true; -// } -// } -// if(isTouchingCarpet) -// { -// UtilPlayer.message(p, F.main("Game", "Get back onto the safe pad!")); -// Host.Manager.GetDamage().NewDamageEvent(p, null, null, -// DamageCause.CUSTOM, 5, false, false, false, -// "Red Carpet", "Exposure to Red Carpet"); -// } -// } -// } - - public Set getMonsters() { + public Set getMonsters() + { return _ents.keySet(); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/monstermaze/MazeMobWaypoint.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/monstermaze/MazeMobWaypoint.java index 4688e9b6b..4238ebba2 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/monstermaze/MazeMobWaypoint.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/monstermaze/MazeMobWaypoint.java @@ -7,7 +7,7 @@ public class MazeMobWaypoint public Location Last; public Location Target; public long Time; - public CardinalDirection Direction; + public CardinalDirection Direction = CardinalDirection.NULL; public MazeMobWaypoint(Location last) { @@ -18,6 +18,6 @@ public class MazeMobWaypoint public enum CardinalDirection { - NORTH, SOUTH, EAST, WEST // such order much not care + NORTH, SOUTH, EAST, WEST, NULL // such order much not care } } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/monstermaze/MonsterMaze.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/monstermaze/MonsterMaze.java index 7cfb118ee..4a8552223 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/monstermaze/MonsterMaze.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/monstermaze/MonsterMaze.java @@ -57,7 +57,7 @@ public class MonsterMaze extends SoloGame { if(event.getType() != UpdateType.TICK) return; if(_maze == null) return; - _maze.Update(); + _maze.update(); } @EventHandler @@ -65,10 +65,15 @@ public class MonsterMaze extends SoloGame { if(event.GetState() == GameState.Prepare) { - if(WorldData.MapName.contains("MonsterTest")) _monsterType = EntityType.CREEPER; - _monsterType = EntityType.SNOWMAN; + //if(WorldData.MapName.contains("MonsterTest")) _monsterType = EntityType.CREEPER; + _monsterType = EntityType.SNOWMAN; // TODO map-specific monster type _maze = new Maze(this, WorldData.GetDataLocs("GRAY"), WorldData.GetDataLocs("YELLOW"), WorldData.GetDataLocs("RED")); UtilServer.getServer().getPluginManager().registerEvents(_maze, getArcadeManager().getPlugin()); + _maze.fillSpawn(150); + } else if(event.GetState() == GameState.Live) + { + + _maze.spawnSafePad(); } } @@ -87,14 +92,7 @@ public class MonsterMaze extends SoloGame if(event.getType() != UpdateType.SEC) return; if(!IsLive()) return; _maze.decrementPhaseTime(); - } - - @EventHandler - public void SpawnMob(UpdateEvent event) - { - if(event.getType() != UpdateType.SEC) return; - if(GetState() != GameState.Live) return; - _maze.spawn(); + _maze.decrementSafePadTime(); } @EventHandler