From e4269b83c46f799ddf76b281957dc6e6892429b6 Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 10 Mar 2018 11:51:31 -0500 Subject: [PATCH] Fixed hardware deserialization issues --- .../net/simon987/cubotplugin/CubotPlugin.java | 2 ++ .../net/simon987/cubotplugin/CubotShield.java | 7 +++++-- .../event/CpuInitialisationListener.java | 6 ++++++ .../event/UserCreationListener.java | 18 +++++++++++------- .../npcplugin/event/WorldCreationListener.java | 1 + .../java/net/simon987/server/assembly/CPU.java | 6 +++++- .../simon987/server/assembly/CpuHardware.java | 4 ++++ 7 files changed, 34 insertions(+), 10 deletions(-) diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotPlugin.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotPlugin.java index c4ac143..f0939cc 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotPlugin.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotPlugin.java @@ -62,6 +62,8 @@ public class CubotPlugin extends ServerPlugin implements GameObjectDeserializer, return CubotComPort.deserialize(obj); case CubotShield.HWID: return CubotShield.deserialize(obj); + case CubotCore.HWID: + return CubotCore.deserialize(obj); } return null; diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotShield.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotShield.java index 0491b35..c003652 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotShield.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotShield.java @@ -7,6 +7,9 @@ import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.Status; public class CubotShield extends CpuHardware { + + public static final char DEFAULT_ADDRESS = 0x000F; + static final char HWID = 0x000F; private static final int SHIELD_CHARGE = 1; @@ -25,8 +28,8 @@ public class CubotShield extends CpuHardware { @Override public BasicDBObject mongoSerialise() { BasicDBObject dbObject = new BasicDBObject(); - - dbObject.put("hwid", HWID); + + dbObject.put("hwid", (int) HWID); dbObject.put("cubot", cubot.getObjectId()); return dbObject; diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/CpuInitialisationListener.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/CpuInitialisationListener.java index 622aa6e..efa2428 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/CpuInitialisationListener.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/CpuInitialisationListener.java @@ -40,6 +40,10 @@ public class CpuInitialisationListener implements GameEventListener { floppyHw.setCpu(cpu); CubotComPort comPortHw = new CubotComPort((Cubot) user.getControlledUnit()); comPortHw.setCpu(cpu); + CubotCore coreHw = new CubotCore((Cubot) user.getControlledUnit()); + coreHw.setCpu(cpu); + CubotShield shieldHw = new CubotShield((Cubot) user.getControlledUnit()); + shieldHw.setCpu(cpu); cpu.attachHardware(legHw, CubotLeg.DEFAULT_ADDRESS); cpu.attachHardware(laserHw, CubotLaser.DEFAULT_ADDRESS); @@ -52,5 +56,7 @@ public class CpuInitialisationListener implements GameEventListener { cpu.attachHardware(batteryHw, CubotBattery.DEFAULT_ADDRESS); cpu.attachHardware(floppyHw, CubotFloppyDrive.DEFAULT_ADDRESS); cpu.attachHardware(comPortHw, CubotComPort.DEFAULT_ADDRESS); + cpu.attachHardware(coreHw, CubotCore.DEFAULT_ADDRESS); + cpu.attachHardware(shieldHw, CubotShield.DEFAULT_ADDRESS); } } diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/UserCreationListener.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/UserCreationListener.java index fd2508a..6e64be2 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/UserCreationListener.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/UserCreationListener.java @@ -2,6 +2,7 @@ package net.simon987.cubotplugin.event; import net.simon987.cubotplugin.Cubot; 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.UserCreationEvent; @@ -25,12 +26,13 @@ public class UserCreationListener implements GameEventListener { User user = (User) event.getSource(); Cubot cubot = new Cubot(); cubot.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId()); - + ServerConfiguration config = GameServer.INSTANCE.getConfig(); + Point point = null; while (point == null || cubot.getWorld() == null) { - int spawnX = GameServer.INSTANCE.getConfig().getInt("new_user_worldX") + random.nextInt(5); - int spawnY = GameServer.INSTANCE.getConfig().getInt("new_user_worldY") + random.nextInt(5); - String dimension = GameServer.INSTANCE.getConfig().getString("new_user_dimension"); + int spawnX = config.getInt("new_user_worldX") + random.nextInt(5); + int spawnY = config.getInt("new_user_worldY") + random.nextInt(5); + String dimension = config.getString("new_user_dimension"); cubot.setWorld(GameServer.INSTANCE.getGameUniverse().getWorld(spawnX, spawnY, true, dimension)); point = cubot.getWorld().getRandomPassableTile(); @@ -41,9 +43,11 @@ public class UserCreationListener implements GameEventListener { cubot.getWorld().addObject(cubot); cubot.getWorld().incUpdatable(); - cubot.setHeldItem(GameServer.INSTANCE.getConfig().getInt("new_user_item")); - cubot.setEnergy(GameServer.INSTANCE.getConfig().getInt("battery_max_energy")); - cubot.setMaxEnergy(GameServer.INSTANCE.getConfig().getInt("battery_max_energy")); + cubot.setHeldItem(config.getInt("new_user_item")); + cubot.setEnergy(config.getInt("battery_max_energy")); + cubot.setMaxEnergy(config.getInt("battery_max_energy")); + + cubot.setHp(config.getInt("cubot_max_hp")); cubot.setParent(user); user.setControlledUnit(cubot); diff --git a/Plugin NPC/src/main/java/net/simon987/npcplugin/event/WorldCreationListener.java b/Plugin NPC/src/main/java/net/simon987/npcplugin/event/WorldCreationListener.java index 49caf6b..8a89772 100644 --- a/Plugin NPC/src/main/java/net/simon987/npcplugin/event/WorldCreationListener.java +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/event/WorldCreationListener.java @@ -100,6 +100,7 @@ public class WorldCreationListener implements GameEventListener { if (p != null) { VaultDoor vaultDoor = new VaultDoor(0); //todo cypherId ? + vaultDoor.setWorld(world); int counter = 700; while (p.x == 0 || p.x == world.getWorldSize() - 1 || p.y == world.getWorldSize() - 1 || p.y == 0 diff --git a/Server/src/main/java/net/simon987/server/assembly/CPU.java b/Server/src/main/java/net/simon987/server/assembly/CPU.java index 1643ed6..e9dfeff 100755 --- a/Server/src/main/java/net/simon987/server/assembly/CPU.java +++ b/Server/src/main/java/net/simon987/server/assembly/CPU.java @@ -458,7 +458,11 @@ public class CPU implements MongoSerialisable { String str = "------------------------\n"; str += registerSet.toString(); str += status.toString(); - str += "------------------------\n"; + str += "HW: "; + for (CpuHardware hw : attachedHardware.values()) { + str += hw + ", "; + } + str += "\n------------------------\n"; return str; } diff --git a/Server/src/main/java/net/simon987/server/assembly/CpuHardware.java b/Server/src/main/java/net/simon987/server/assembly/CpuHardware.java index b954b3c..6c2283e 100644 --- a/Server/src/main/java/net/simon987/server/assembly/CpuHardware.java +++ b/Server/src/main/java/net/simon987/server/assembly/CpuHardware.java @@ -42,4 +42,8 @@ public abstract class CpuHardware implements MongoSerialisable { return null; } + @Override + public String toString() { + return String.format("<%04X>", (int) getId()); + } }