From 039088ac005d202ed2c2814257c674647da47f56 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 27 Feb 2018 16:49:32 -0500 Subject: [PATCH] Added electric boxes, debug command to teleport objects across Worlds. --- .../net/simon987/npcplugin/ElectricBox.java | 30 ++++ .../net/simon987/npcplugin/HarvesterNPC.java | 6 +- .../npcplugin/NonPlayerCharacter.java | 1 + .../net/simon987/npcplugin/NpcPlugin.java | 4 + .../java/net/simon987/npcplugin/Obstacle.java | 129 ++++++++++++++++++ .../simon987/npcplugin/VaultDimension.java | 22 +-- .../simon987/npcplugin/VaultWorldUtils.java | 75 ++++++++++ .../event/VaultWorldUpdateListener.java | 70 ++++++++++ .../simon987/biomassplugin/WorldUtils.java | 7 +- .../event/WorldUpdateListener.java | 37 ++--- .../net/simon987/server/game/GameObject.java | 5 +- .../net/simon987/server/game/TileMap.java | 6 +- .../java/net/simon987/server/game/World.java | 14 +- .../simon987/server/game/WorldGenerator.java | 4 +- .../server/webserver/DebugHandler.java | 49 ++++++- Server/src/main/resources/config.properties | 9 +- 16 files changed, 426 insertions(+), 42 deletions(-) create mode 100644 Plugin NPC/src/main/java/net/simon987/npcplugin/ElectricBox.java create mode 100644 Plugin NPC/src/main/java/net/simon987/npcplugin/Obstacle.java create mode 100644 Plugin NPC/src/main/java/net/simon987/npcplugin/VaultWorldUtils.java create mode 100644 Plugin NPC/src/main/java/net/simon987/npcplugin/event/VaultWorldUpdateListener.java diff --git a/Plugin NPC/src/main/java/net/simon987/npcplugin/ElectricBox.java b/Plugin NPC/src/main/java/net/simon987/npcplugin/ElectricBox.java new file mode 100644 index 0000000..1115dca --- /dev/null +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/ElectricBox.java @@ -0,0 +1,30 @@ +package net.simon987.npcplugin; + +import net.simon987.server.GameServer; +import net.simon987.server.game.Updatable; + +public class ElectricBox extends Obstacle implements Updatable { + + public static final int STYLE = 1; + + private static final int maxHp = GameServer.INSTANCE.getConfig().getInt("electric_box_hp"); + private static final int damage = GameServer.INSTANCE.getConfig().getInt("electric_box_damage"); + private static final int energyGiven = GameServer.INSTANCE.getConfig().getInt("electric_box_energy_given"); + + public ElectricBox() { + super(maxHp); + + setStyle(STYLE); + } + + @Override + public void update() { + + } + + @Override + public boolean onDeadCallback() { + getWorld().decUpdatable(); + return false; + } +} diff --git a/Plugin NPC/src/main/java/net/simon987/npcplugin/HarvesterNPC.java b/Plugin NPC/src/main/java/net/simon987/npcplugin/HarvesterNPC.java index e40d0b6..89c58f4 100644 --- a/Plugin NPC/src/main/java/net/simon987/npcplugin/HarvesterNPC.java +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/HarvesterNPC.java @@ -46,7 +46,9 @@ public class HarvesterNPC extends NonPlayerCharacter { } @Override - public void onDeadCallback() { + public boolean onDeadCallback() { + + getWorld().decUpdatable(); if (getFactory() != null && getFactory().getNpcs() != null) { getFactory().getNpcs().remove(this); @@ -54,6 +56,8 @@ public class HarvesterNPC extends NonPlayerCharacter { GameServer.INSTANCE.getEventDispatcher().dispatch( new ObjectDeathEvent(this, ID)); + + return false; } @Override diff --git a/Plugin NPC/src/main/java/net/simon987/npcplugin/NonPlayerCharacter.java b/Plugin NPC/src/main/java/net/simon987/npcplugin/NonPlayerCharacter.java index c35c4be..794e2da 100644 --- a/Plugin NPC/src/main/java/net/simon987/npcplugin/NonPlayerCharacter.java +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/NonPlayerCharacter.java @@ -245,4 +245,5 @@ public abstract class NonPlayerCharacter extends GameObject implements Updatable public int getAge() { return age; } + } diff --git a/Plugin NPC/src/main/java/net/simon987/npcplugin/NpcPlugin.java b/Plugin NPC/src/main/java/net/simon987/npcplugin/NpcPlugin.java index 2315624..964c921 100644 --- a/Plugin NPC/src/main/java/net/simon987/npcplugin/NpcPlugin.java +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/NpcPlugin.java @@ -2,6 +2,7 @@ package net.simon987.npcplugin; import com.mongodb.DBObject; import net.simon987.npcplugin.event.CpuInitialisationListener; +import net.simon987.npcplugin.event.VaultWorldUpdateListener; import net.simon987.npcplugin.event.WorldCreationListener; import net.simon987.server.ServerConfiguration; import net.simon987.server.assembly.CpuHardware; @@ -25,6 +26,7 @@ public class NpcPlugin extends ServerPlugin implements GameObjectDeserializer, C listeners.add(new WorldCreationListener()); listeners.add(new CpuInitialisationListener()); + listeners.add(new VaultWorldUpdateListener(configuration)); radioTowers = new ArrayList<>(32); @@ -44,6 +46,8 @@ public class NpcPlugin extends ServerPlugin implements GameObjectDeserializer, C return RadioTower.deserialize(obj); } else if (objType == VaultDoor.ID) { return VaultDoor.deserialize(obj); + } else if (objType == Obstacle.ID) { + return Obstacle.deserialize(obj); } return null; diff --git a/Plugin NPC/src/main/java/net/simon987/npcplugin/Obstacle.java b/Plugin NPC/src/main/java/net/simon987/npcplugin/Obstacle.java new file mode 100644 index 0000000..2df67a2 --- /dev/null +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/Obstacle.java @@ -0,0 +1,129 @@ +package net.simon987.npcplugin; + +import com.mongodb.BasicDBObject; +import com.mongodb.DBObject; +import net.simon987.server.game.Attackable; +import net.simon987.server.game.GameObject; +import org.json.simple.JSONObject; + +/** + * Generic game object that blocks the path. + * Some types of obstacles might have some more interesting features (see ElectricBox) + */ +public class Obstacle extends GameObject implements Attackable { + + public static final int ID = 6; + + /** + * Style of the obstacle. Will tell the client which sprite to display + */ + private int style = 0; + + /** + * Current health of the npc + */ + private int hp; + + /** + * Maximum health of the npc + */ + private int maxHp; + + public Obstacle(int hp) { + this.hp = hp; + this.maxHp = hp; + } + + @Override + public void setHealRate(int hp) { + //No op + } + + @Override + public void heal(int amount) { + //No op + } + + @Override + public int getHp() { + return hp; + } + + @Override + public void setHp(int hp) { + this.hp = hp; + } + + @Override + public int getMaxHp() { + return maxHp; + } + + @Override + public void setMaxHp(int hp) { + this.maxHp = hp; + this.hp = hp; + } + + @Override + public void damage(int amount) { + hp -= amount; + + //YOU ARE DEAD + if (hp <= 0) { + setDead(true); + } + } + + @Override + public char getMapInfo() { + return 0x0400; + } + + public int getStyle() { + return style; + } + + public void setStyle(int style) { + this.style = style; + } + + @Override + public BasicDBObject mongoSerialise() { + BasicDBObject dbObject = new BasicDBObject(); + + dbObject.put("i", getObjectId()); + dbObject.put("x", getX()); + dbObject.put("y", getY()); + dbObject.put("t", ID); + dbObject.put("style", style); + + return dbObject; + } + + @Override + public JSONObject serialise() { + JSONObject json = new JSONObject(); + + json.put("i", getObjectId()); + json.put("x", getX()); + json.put("y", getY()); + json.put("t", ID); + json.put("hp", hp); + json.put("style", style); + + return json; + } + + public static Obstacle deserialize(DBObject obj) { + + //Doesn't matter if we don't store maxHP, since obstacles can't be healed + Obstacle obstacle = new Obstacle((int) obj.get("hp")); + obstacle.setObjectId((long) obj.get("i")); + obstacle.setX((int) obj.get("x")); + obstacle.setY((int) obj.get("y")); + obstacle.setStyle((int) obj.get("style")); + + return obstacle; + } +} diff --git a/Plugin NPC/src/main/java/net/simon987/npcplugin/VaultDimension.java b/Plugin NPC/src/main/java/net/simon987/npcplugin/VaultDimension.java index 24c0bb3..1ca6338 100644 --- a/Plugin NPC/src/main/java/net/simon987/npcplugin/VaultDimension.java +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/VaultDimension.java @@ -72,18 +72,18 @@ public class VaultDimension { for (int j = 0; j < attachedWorlds; j++) { - int rDirIndex = random.nextInt(4); + int randDirIndex = random.nextInt(4); //Try 4 directions (wrap around 0..3) for (int attemptCount = 0; attemptCount < 4; attemptCount++) { - Direction rDir = Direction.getDirection(rDirIndex); + Direction randomDirection = Direction.getDirection(randDirIndex); //Don't attach a world at the same spot twice - if (!worldExists(world.coordinatesOf(rDir), worldLayers)) { - WorldBluePrint attachedWorld = world.attachWorld(rDir); + if (!worldExists(world.coordinatesOf(randomDirection), worldLayers)) { + WorldBluePrint attachedWorld = world.attachWorld(randomDirection); worldLayers.get(i).add(attachedWorld); } - rDirIndex = (rDirIndex + 1) % 4; + randDirIndex = (randDirIndex + 1) % 4; } } } @@ -117,11 +117,17 @@ public class VaultDimension { return worldLayers.values().stream().flatMap(Collection::stream).anyMatch(bp -> bp.coords.equals(coords)); } + /** + * Helper class to plan the layout of a vault dimension + */ private class WorldBluePrint { - public ArrayList openings = new ArrayList<>(4); + ArrayList openings = new ArrayList<>(4); - public Point coords = new Point(); + /** + * Coordinates of the world + */ + Point coords = new Point(); /** * Update the blueprint's openings to allow traveling to the newly attached world @@ -129,7 +135,7 @@ public class VaultDimension { * @param direction direction of the world to attach (relative to this one) * @return The blueprint of the attached world */ - public WorldBluePrint attachWorld(Direction direction) { + WorldBluePrint attachWorld(Direction direction) { WorldBluePrint attachedWorld = new WorldBluePrint(); diff --git a/Plugin NPC/src/main/java/net/simon987/npcplugin/VaultWorldUtils.java b/Plugin NPC/src/main/java/net/simon987/npcplugin/VaultWorldUtils.java new file mode 100644 index 0000000..6c06c25 --- /dev/null +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/VaultWorldUtils.java @@ -0,0 +1,75 @@ +package net.simon987.npcplugin; + +import net.simon987.server.GameServer; +import net.simon987.server.game.TileMap; +import net.simon987.server.game.World; + +import java.awt.*; +import java.util.ArrayList; +import java.util.Random; + +public class VaultWorldUtils { + + + public static ArrayList generateElectricBoxes(World world, int minCount, int maxCount) { + + Random random = new Random(); + int boxesCount = random.nextInt(maxCount - minCount) + minCount; + ArrayList electricBoxes = new ArrayList<>(boxesCount); + + //Count number of floor tiles. If there is less plain tiles than desired amount of boxes, + //set the desired amount of blobs to the plain tile count + int[][] tiles = world.getTileMap().getTiles(); + int floorCount = 0; + for (int y = 0; y < world.getWorldSize(); y++) { + for (int x = 0; x < world.getWorldSize(); x++) { + + if (tiles[x][y] == TileMap.VAULT_FLOOR) { + floorCount++; + } + } + } + + if (boxesCount > floorCount) { + boxesCount = floorCount; + } + + outerLoop: + for (int i = 0; i < boxesCount; i++) { + + Point p = world.getTileMap().getRandomTile(TileMap.VAULT_FLOOR); + if (p != null) { + + //Don't block worlds + int counter = 0; + while (p.x == 0 || p.y == 0 || p.x == world.getWorldSize() - 1 || p.y == world.getWorldSize() - 1 || + world.getGameObjectsAt(p.x, p.y).size() != 0) { + p = world.getTileMap().getRandomTile(TileMap.VAULT_FLOOR); + counter++; + + if (counter > 25) { + continue outerLoop; + } + } + + for (ElectricBox box : electricBoxes) { + if (box.getX() == p.x && box.getY() == p.y) { + //There is already a box here + continue outerLoop; + } + } + + ElectricBox box = new ElectricBox(); + box.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId()); + box.setX(p.x); + box.setY(p.y); + box.setWorld(world); + + electricBoxes.add(box); + } + } + + return electricBoxes; + + } +} diff --git a/Plugin NPC/src/main/java/net/simon987/npcplugin/event/VaultWorldUpdateListener.java b/Plugin NPC/src/main/java/net/simon987/npcplugin/event/VaultWorldUpdateListener.java new file mode 100644 index 0000000..31db1e3 --- /dev/null +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/event/VaultWorldUpdateListener.java @@ -0,0 +1,70 @@ +package net.simon987.npcplugin.event; + +import net.simon987.npcplugin.ElectricBox; +import net.simon987.npcplugin.VaultWorldUtils; +import net.simon987.server.GameServer; +import net.simon987.server.ServerConfiguration; +import net.simon987.server.event.GameEvent; +import net.simon987.server.event.GameEventListener; +import net.simon987.server.event.WorldUpdateEvent; +import net.simon987.server.game.World; + +import java.util.ArrayList; +import java.util.HashMap; + +public class VaultWorldUpdateListener implements GameEventListener { + + private HashMap worldWaitMap = new HashMap<>(200); + + private static int minElectricBoxCount; + private static int maxElectricBoxCount; + private static int waitTime; + private static int electricBoxThreshold; + + public VaultWorldUpdateListener(ServerConfiguration config) { + + minElectricBoxCount = config.getInt("min_electric_box_respawn_count"); + maxElectricBoxCount = config.getInt("max_electric_box_respawn_count"); + waitTime = config.getInt("electric_box_respawnTime"); + electricBoxThreshold = config.getInt("min_electric_box_count"); + } + + @Override + public Class getListenedEventType() { + return WorldUpdateEvent.class; + } + + @Override + public void handle(GameEvent event) { + + World world = ((WorldUpdateEvent) event).getWorld(); + + if (world.getDimension().startsWith("v")) { + //If there is less than the respawn threshold, + if (world.findObjects(ElectricBox.class).size() < electricBoxThreshold) { + + //Set a timer for respawn_time ticks + if (!worldWaitMap.containsKey(world) || worldWaitMap.get(world) == 0L) { + worldWaitMap.put(world, GameServer.INSTANCE.getGameUniverse().getTime() + waitTime); + } else { + + long waitUntil = worldWaitMap.get(world); + + if (GameServer.INSTANCE.getGameUniverse().getTime() >= waitUntil) { + + //If the timer was set less than respawn_time ticks ago, respawn the blobs + ArrayList newBlobs = VaultWorldUtils.generateElectricBoxes(world, minElectricBoxCount, + maxElectricBoxCount); + for (ElectricBox blob : newBlobs) { + world.addObject(blob); + } + + //Set the 'waitUntil' time to 0 to indicate that we are not waiting + worldWaitMap.replace(world, 0L); + } + } + } + } + + } +} diff --git a/Plugin Plant/src/main/java/net/simon987/biomassplugin/WorldUtils.java b/Plugin Plant/src/main/java/net/simon987/biomassplugin/WorldUtils.java index e7b16bf..6f4c05c 100644 --- a/Plugin Plant/src/main/java/net/simon987/biomassplugin/WorldUtils.java +++ b/Plugin Plant/src/main/java/net/simon987/biomassplugin/WorldUtils.java @@ -1,6 +1,7 @@ package net.simon987.biomassplugin; import net.simon987.server.GameServer; +import net.simon987.server.game.TileMap; import net.simon987.server.game.World; import net.simon987.server.logging.LogManager; @@ -26,7 +27,7 @@ public class WorldUtils { for (int y = 0; y < world.getWorldSize(); y++) { for (int x = 0; x < world.getWorldSize(); x++) { - if (tiles[x][y] == 0) { + if (tiles[x][y] == TileMap.PLAIN_TILE) { plainCount++; } } @@ -39,14 +40,14 @@ public class WorldUtils { outerLoop: for (int i = 0; i < blobCount; i++) { - Point p = world.getTileMap().getRandomPlainTile(); + Point p = world.getTileMap().getRandomTile(TileMap.PLAIN_TILE); if (p != null) { //Don't block worlds int counter = 0; while (p.x == 0 || p.y == 0 || p.x == world.getWorldSize() - 1 || p.y == world.getWorldSize() - 1 || world.getGameObjectsAt(p.x, p.y).size() != 0) { - p = world.getTileMap().getRandomPlainTile(); + p = world.getTileMap().getRandomTile(TileMap.PLAIN_TILE); counter++; if (counter > 25) { diff --git a/Plugin Plant/src/main/java/net/simon987/biomassplugin/event/WorldUpdateListener.java b/Plugin Plant/src/main/java/net/simon987/biomassplugin/event/WorldUpdateListener.java index afd9d9b..ae4868e 100644 --- a/Plugin Plant/src/main/java/net/simon987/biomassplugin/event/WorldUpdateListener.java +++ b/Plugin Plant/src/main/java/net/simon987/biomassplugin/event/WorldUpdateListener.java @@ -44,31 +44,32 @@ public class WorldUpdateListener implements GameEventListener { World world = ((WorldUpdateEvent) event).getWorld(); - //If there is less than the respawn threshold, - if (world.findObjects(BiomassBlob.class).size() < blobThreshold) { + if (world.getDimension().startsWith("w")) { + //If there is less than the respawn threshold, + if (world.findObjects(BiomassBlob.class).size() < blobThreshold) { - //Set a timer for respawn_time ticks - if (!worldWaitMap.containsKey(world) || worldWaitMap.get(world) == 0L) { - worldWaitMap.put(world, GameServer.INSTANCE.getGameUniverse().getTime() + waitTime); - } else { + //Set a timer for respawn_time ticks + if (!worldWaitMap.containsKey(world) || worldWaitMap.get(world) == 0L) { + worldWaitMap.put(world, GameServer.INSTANCE.getGameUniverse().getTime() + waitTime); + } else { - long waitUntil = worldWaitMap.get(world); + long waitUntil = worldWaitMap.get(world); - if (GameServer.INSTANCE.getGameUniverse().getTime() >= waitUntil) { + if (GameServer.INSTANCE.getGameUniverse().getTime() >= waitUntil) { - //If the timer was set less than respawn_time ticks ago, respawn the blobs - ArrayList newBlobs = WorldUtils.generateBlobs(world, minBlobCount, - maxBlobCount, blobYield); - for (BiomassBlob blob : newBlobs) { - world.addObject(blob); + //If the timer was set less than respawn_time ticks ago, respawn the blobs + ArrayList newBlobs = WorldUtils.generateBlobs(world, minBlobCount, + maxBlobCount, blobYield); + for (BiomassBlob blob : newBlobs) { + world.addObject(blob); + world.incUpdatable(); + } + + //Set the 'waitUntil' time to 0 to indicate that we are not waiting + worldWaitMap.replace(world, 0L); } - - //Set the 'waitUntil' time to 0 to indicate that we are not waiting - worldWaitMap.replace(world, 0L); } } - } - } } \ No newline at end of file diff --git a/Server/src/main/java/net/simon987/server/game/GameObject.java b/Server/src/main/java/net/simon987/server/game/GameObject.java index 88f4317..4567a50 100755 --- a/Server/src/main/java/net/simon987/server/game/GameObject.java +++ b/Server/src/main/java/net/simon987/server/game/GameObject.java @@ -254,6 +254,9 @@ public abstract class GameObject implements JSONSerialisable, MongoSerialisable /** * Called before this GameObject is removed from the world - defaults to doing nothing + * @return cancelled */ - public void onDeadCallback() { } + public boolean onDeadCallback() { + return false; + } } \ No newline at end of file diff --git a/Server/src/main/java/net/simon987/server/game/TileMap.java b/Server/src/main/java/net/simon987/server/game/TileMap.java index 1a1e6aa..4bf0990 100755 --- a/Server/src/main/java/net/simon987/server/game/TileMap.java +++ b/Server/src/main/java/net/simon987/server/game/TileMap.java @@ -25,6 +25,8 @@ public class TileMap implements JSONSerialisable, MongoSerialisable { public static final int WALL_TILE = 1; public static final int IRON_TILE = 2; public static final int COPPER_TILE = 3; + public static final int VAULT_FLOOR = 4; + public static final int VAULT_WALL = 5; public static final int ITEM_IRON = 3; public static final int ITEM_COPPER = 4; @@ -164,7 +166,7 @@ public class TileMap implements JSONSerialisable, MongoSerialisable { } - public Point getRandomPlainTile() { + public Point getRandomTile(int tile) { Random random = new Random(); @@ -180,7 +182,7 @@ public class TileMap implements JSONSerialisable, MongoSerialisable { int rx = random.nextInt(width); int ry = random.nextInt(height); - if (tiles[rx][ry] == TileMap.PLAIN_TILE) { + if (tiles[rx][ry] == tile) { return new Point(rx, ry); } } diff --git a/Server/src/main/java/net/simon987/server/game/World.java b/Server/src/main/java/net/simon987/server/game/World.java index 19f3db7..9778159 100644 --- a/Server/src/main/java/net/simon987/server/game/World.java +++ b/Server/src/main/java/net/simon987/server/game/World.java @@ -66,7 +66,10 @@ public class World implements MongoSerialisable { */ public boolean isTileBlocked(int x, int y) { - return getGameObjectsBlockingAt(x, y).size() > 0 || tileMap.getTileAt(x, y) == TileMap.WALL_TILE; + int tile = tileMap.getTileAt(x, y); + + return getGameObjectsBlockingAt(x, y).size() > 0 || tile == TileMap.WALL_TILE || + tile == TileMap.VAULT_WALL; } /** @@ -154,9 +157,10 @@ public class World implements MongoSerialisable { for (GameObject object : gameObjects.values()) { //Clean up dead objects if (object.isDead()) { - object.onDeadCallback(); - removeObject(object); - //LogManager.LOGGER.fine("Removed object " + object + " id: " + object.getObjectId()); + if (!object.onDeadCallback()) { + removeObject(object); + } + } else if (object instanceof Updatable) { ((Updatable) object).update(); } @@ -249,7 +253,7 @@ public class World implements MongoSerialisable { if (tiles[x][y] == TileMap.PLAIN_TILE) { mapInfo[x][y] = 0; - } else if (tiles[x][y] == TileMap.WALL_TILE) { + } else if (tiles[x][y] == TileMap.WALL_TILE || tiles[x][y] == TileMap.VAULT_WALL) { mapInfo[x][y] = INFO_BLOCKED; } else if (tiles[x][y] == TileMap.COPPER_TILE) { diff --git a/Server/src/main/java/net/simon987/server/game/WorldGenerator.java b/Server/src/main/java/net/simon987/server/game/WorldGenerator.java index be669ba..0a5b7ec 100755 --- a/Server/src/main/java/net/simon987/server/game/WorldGenerator.java +++ b/Server/src/main/java/net/simon987/server/game/WorldGenerator.java @@ -169,7 +169,7 @@ public class WorldGenerator { for (int i = 0; i < ironCount; i++) { - Point p = world.getTileMap().getRandomPlainTile(); + Point p = world.getTileMap().getRandomTile(TileMap.PLAIN_TILE); if (p != null) { world.getTileMap().getTiles()[p.x][p.y] = TileMap.IRON_TILE; @@ -177,7 +177,7 @@ public class WorldGenerator { } for (int i = 0; i < copperCount; i++) { - Point p = world.getTileMap().getRandomPlainTile(); + Point p = world.getTileMap().getRandomTile(TileMap.PLAIN_TILE); if (p != null) { world.getTileMap().getTiles()[p.x][p.y] = TileMap.COPPER_TILE; diff --git a/Server/src/main/java/net/simon987/server/webserver/DebugHandler.java b/Server/src/main/java/net/simon987/server/webserver/DebugHandler.java index 204aea8..6d4107d 100644 --- a/Server/src/main/java/net/simon987/server/webserver/DebugHandler.java +++ b/Server/src/main/java/net/simon987/server/webserver/DebugHandler.java @@ -5,6 +5,7 @@ import com.mongodb.util.JSON; import net.simon987.server.GameServer; import net.simon987.server.game.ControllableUnit; import net.simon987.server.game.GameObject; +import net.simon987.server.game.Updatable; import net.simon987.server.game.World; import net.simon987.server.logging.LogManager; import net.simon987.server.user.User; @@ -88,6 +89,15 @@ public class DebugHandler implements MessageHandler { (String) json.get("data"), (String) json.get("dimension"))); break; + case "tpObj": + response.put("message", moveObj( + (long) json.get("objectId"), + (int) (long) json.get("x"), + (int) (long) json.get("y"), + (int) (long) json.get("worldX"), + (int) (long) json.get("worldY"), + (String) json.get("dimension"))); + break; default: LogManager.LOGGER.severe("Unknown command: " + command); @@ -213,12 +223,48 @@ public class DebugHandler implements MessageHandler { object.setX(x); object.setY(y); - return "Sucess"; + return "Success"; } else { return "Object not found: " + objectId; } } + private String moveObj(long objectId, int x, int y, int worldX, int worldY, String dimension) { + + GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(objectId); + World world = GameServer.INSTANCE.getGameUniverse().getWorld(worldX, worldY, false, dimension); + + if (object != null) { + + if (world != null) { + + if (object instanceof Updatable) { + object.getWorld().decUpdatable(); + } + + object.getWorld().removeObject(object); + object.setWorld(world); + world.addObject(object); + + if (object instanceof Updatable) { + world.incUpdatable(); + } + + object.setX(x); + object.setY(y); + + return "Success"; + + } else { + return "World not found: " + World.idFromCoordinates(worldX, worldY, dimension); + } + } else { + return "Object not found: " + objectId; + } + + + } + private String userInfo(String username) { User user = GameServer.INSTANCE.getGameUniverse().getUser(username); @@ -243,4 +289,5 @@ public class DebugHandler implements MessageHandler { } } + } diff --git a/Server/src/main/resources/config.properties b/Server/src/main/resources/config.properties index 1886d91..ed7e637 100644 --- a/Server/src/main/resources/config.properties +++ b/Server/src/main/resources/config.properties @@ -88,4 +88,11 @@ user_timeout=100 # ---------------------------------------------- -vault_door_open_time=4 \ No newline at end of file +vault_door_open_time=4 +electric_box_hp=250 +min_electric_box_count=3 +min_electric_box_respawn_count=3 +max_electric_box_respawn_count=5 +electric_box_respawnTime=64 +electric_box_damage=5 +electric_box_energy_given=70 \ No newline at end of file