Refactor: changed the way game objects and cpu hardware are saved/loaded from the database #151

This commit is contained in:
simon
2018-05-12 15:32:41 -04:00
parent 8d029cf621
commit 4cd58c86a5
96 changed files with 628 additions and 1221 deletions

View File

@@ -3,7 +3,7 @@ package net.simon987.cubotplugin;
import net.simon987.server.GameServer;
import net.simon987.server.ServerConfiguration;
import net.simon987.server.assembly.Memory;
import net.simon987.server.game.*;
import net.simon987.server.game.objects.*;
import net.simon987.server.logging.LogManager;
import net.simon987.server.user.User;
import org.bson.Document;
@@ -16,7 +16,6 @@ import java.util.Random;
public class Cubot extends GameObject implements Updatable, ControllableUnit, Programmable, Attackable, Rechargeable {
private static final char MAP_INFO = 0x0080;
public static final int ID = 1;
/**
* Hologram value that is displayed
@@ -171,11 +170,25 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
NORMAL
}
public Cubot() {
}
public Cubot(Document document) {
super(document);
hp = document.getInteger("hp");
shield = document.getInteger("shield");
setDirection(Direction.getDirection(document.getInteger("direction")));
heldItem = document.getInteger("heldItem");
energy = document.getInteger("energy");
ServerConfiguration config = GameServer.INSTANCE.getConfig();
maxEnergy = config.getInt("battery_max_energy");
maxHp = config.getInt("cubot_max_hp");
maxShield = config.getInt("cubot_max_shield");
}
@Override
public char getMapInfo() {
return MAP_INFO;
@@ -225,12 +238,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
}
@Override
public JSONObject serialise() {
JSONObject json = new JSONObject();
json.put("i", getObjectId());
json.put("t", ID);
json.put("x", getX());
json.put("y", getY());
public JSONObject jsonSerialise() {
JSONObject json = super.jsonSerialise();
json.put("direction", getDirection().ordinal());
json.put("heldItem", heldItem);
json.put("hp", hp);
@@ -251,12 +260,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
@Override
public Document mongoSerialise() {
Document dbObject = new Document();
Document dbObject = super.mongoSerialise();
dbObject.put("i", getObjectId());
dbObject.put("t", ID);
dbObject.put("x", getX());
dbObject.put("y", getY());
dbObject.put("direction", getDirection().ordinal());
dbObject.put("heldItem", heldItem);
dbObject.put("hp", hp);
@@ -275,26 +280,6 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
return dbObject;
}
public static Cubot deserialize(Document obj) {
Cubot cubot = new Cubot();
cubot.setObjectId((long) obj.get("i"));
cubot.setX((int) obj.get("x"));
cubot.setY((int) obj.get("y"));
cubot.hp = (int) obj.get("hp");
cubot.shield = (int) obj.get("shield");
cubot.setDirection(Direction.getDirection((int) obj.get("direction")));
cubot.heldItem = (int) obj.get("heldItem");
cubot.energy = (int) obj.get("energy");
ServerConfiguration config = GameServer.INSTANCE.getConfig();
cubot.maxEnergy = config.getInt("battery_max_energy");
cubot.maxHp = config.getInt("cubot_max_hp");
cubot.maxShield = config.getInt("cubot_max_shield");
return cubot;
}
/**
* Reset to 'factory settings', as it were when it was first created
*/

View File

@@ -1,11 +1,9 @@
package net.simon987.cubotplugin;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import org.bson.Document;
public class CubotBattery extends CpuHardware {
public class CubotBattery extends CubotHardware {
public static final int DEFAULT_ADDRESS = 0x000A;
@@ -14,12 +12,15 @@ public class CubotBattery extends CpuHardware {
*/
public static final char HWID = 0x000A;
private Cubot cubot;
private static final int BATTERY_POLL = 1;
private static final int BATTERY_GET_MAX_CAPACITY = 2;
public CubotBattery(Cubot cubot) {
this.cubot = cubot;
super(cubot);
}
public CubotBattery(Document document) {
super(document);
}
@Override
@@ -43,20 +44,4 @@ public class CubotBattery extends CpuHardware {
return HWID;
}
@Override
public Document mongoSerialise() {
Document dbObject = new Document();
dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId());
return dbObject;
}
public static CubotBattery deserialize(Document obj) {
return new CubotBattery((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
}
}

View File

@@ -1,22 +1,18 @@
package net.simon987.cubotplugin;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import net.simon987.server.game.GameObject;
import net.simon987.server.game.Programmable;
import net.simon987.server.game.objects.GameObject;
import net.simon987.server.game.objects.Programmable;
import org.bson.Document;
import java.awt.*;
import java.util.ArrayList;
public class CubotComPort extends CpuHardware {
public class CubotComPort extends CubotHardware {
public static final char HWID = 0xD;
public static final int DEFAULT_ADDRESS = 0xD;
private Cubot cubot;
private static final int COMPORT_BUFFER_CLEAR = 0;
private static final int COMPORT_POLL = 1;
private static final int COMPORT_FRONT_PORT_OUT = 2;
@@ -24,7 +20,11 @@ public class CubotComPort extends CpuHardware {
private static final int COMPORT_CONSOLE_CLEAR = 4;
public CubotComPort(Cubot cubot) {
this.cubot = cubot;
super(cubot);
}
public CubotComPort(Document document) {
super(document);
}
private static final int MESSAGE_LENGTH = 8;
@@ -125,19 +125,4 @@ public class CubotComPort extends CpuHardware {
public char getId() {
return HWID;
}
@Override
public Document mongoSerialise() {
Document dbObject = new Document();
dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId());
return dbObject;
}
public static CubotComPort deserialize(Document obj) {
return new CubotComPort((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
}
}

View File

@@ -1,11 +1,9 @@
package net.simon987.cubotplugin;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import org.bson.Document;
public class CubotCore extends CpuHardware {
public class CubotCore extends CubotHardware {
public static final int DEFAULT_ADDRESS = 0x000E;
@@ -17,10 +15,12 @@ public class CubotCore extends CpuHardware {
private static final int CORE_STATUS_POLL = 1;
private static final int CORE_HULL_POLL = 2;
private Cubot cubot;
public CubotCore(Cubot cubot) {
this.cubot = cubot;
super(cubot);
}
public CubotCore(Document document) {
super(document);
}
@Override
@@ -39,20 +39,4 @@ public class CubotCore extends CpuHardware {
public char getId() {
return HWID;
}
@Override
public Document mongoSerialise() {
Document dbObject = new Document();
dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId());
return dbObject;
}
public static CubotCore deserialize(Document obj) {
return new CubotCore((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
}
}

View File

@@ -1,13 +1,11 @@
package net.simon987.cubotplugin;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import net.simon987.server.game.Action;
import net.simon987.server.game.TileMap;
import net.simon987.server.game.objects.Action;
import net.simon987.server.game.world.TileMap;
import org.bson.Document;
public class CubotDrill extends CpuHardware {
public class CubotDrill extends CubotHardware {
/**
* Hardware ID (Should be unique)
@@ -19,10 +17,12 @@ public class CubotDrill extends CpuHardware {
private static final int DRILL_POLL = 1;
private static final int DRILL_GATHER = 2; // simplified gather
private Cubot cubot;
public CubotDrill(Cubot cubot) {
this.cubot = cubot;
super(cubot);
}
public CubotDrill(Document document) {
super(document);
}
@Override
@@ -55,23 +55,6 @@ public class CubotDrill extends CpuHardware {
}
}
}
}
}
@Override
public Document mongoSerialise() {
Document dbObject = new Document();
dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId());
return dbObject;
}
public static CubotDrill deserialize(Document obj) {
return new CubotDrill((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
}
}

View File

@@ -1,11 +1,9 @@
package net.simon987.cubotplugin;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import org.bson.Document;
public class CubotFloppyDrive extends CpuHardware {
public class CubotFloppyDrive extends CubotHardware {
/**
* Hardware ID (Should be unique)
@@ -18,15 +16,24 @@ public class CubotFloppyDrive extends CpuHardware {
private static final int FLOPPY_READ_SECTOR = 2;
private static final int FLOPPY_WRITE_SECTOR = 3;
private Cubot cubot;
private FloppyDisk floppyDisk;
public CubotFloppyDrive(Cubot cubot) {
this.cubot = cubot;
super(cubot);
floppyDisk = new FloppyDisk();
}
public CubotFloppyDrive(Document document) {
super(document);
if (document.containsKey("floppy")) {
floppyDisk = new FloppyDisk((Document) document.get("floppy"));
} else {
floppyDisk = new FloppyDisk();
}
}
@Override
public void handleInterrupt(Status status) {
int a = getCpu().getRegisterSet().getRegister("A").getValue();
@@ -77,31 +84,6 @@ public class CubotFloppyDrive extends CpuHardware {
return HWID;
}
@Override
public Document mongoSerialise() {
Document dbObject = new Document();
dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId());
if (floppyDisk != null) {
dbObject.put("floppy", floppyDisk.mongoSerialise());
}
return dbObject;
}
public static CubotFloppyDrive deserialize(Document obj) {
CubotFloppyDrive drive = new CubotFloppyDrive((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
if (obj.containsKey("floppy")) {
drive.floppyDisk = FloppyDisk.deserialise((Document) obj.get("floppy"));
}
return drive;
}
public FloppyDisk getFloppy() {
return floppyDisk;

View File

@@ -0,0 +1,27 @@
package net.simon987.cubotplugin;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware;
import org.bson.Document;
public abstract class CubotHardware extends CpuHardware {
protected Cubot cubot;
public CubotHardware(Document document) {
this.cubot = (Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) document.get("cubot"));
}
public CubotHardware(Cubot cubot) {
this.cubot = cubot;
}
@Override
public Document mongoSerialise() {
Document document = new Document();
document.put("type", getClass().getCanonicalName());
document.put("cubot", cubot.getObjectId());
return document;
}
}

View File

@@ -1,11 +1,9 @@
package net.simon987.cubotplugin;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import org.bson.Document;
public class CubotHologram extends CpuHardware {
public class CubotHologram extends CubotHardware {
/**
@@ -15,8 +13,6 @@ public class CubotHologram extends CpuHardware {
public static final int DEFAULT_ADDRESS = 9;
private Cubot cubot;
private static final int HOLO_CLEAR = 0;
private static final int HOLO_DISPLAY_HEX = 1;
private static final int HOLO_DISPLAY_STRING = 2;
@@ -26,7 +22,11 @@ public class CubotHologram extends CpuHardware {
private static final int STR_MAX_LEN = 8;
public CubotHologram(Cubot cubot) {
this.cubot = cubot;
super(cubot);
}
public CubotHologram(Document document) {
super(document);
}
@Override
@@ -82,19 +82,4 @@ public class CubotHologram extends CpuHardware {
return HWID;
}
public static CubotHologram deserialize(Document obj) {
return new CubotHologram((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
}
@Override
public Document mongoSerialise() {
Document dbObject = new Document();
dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId());
return dbObject;
}
}

View File

@@ -1,11 +1,10 @@
package net.simon987.cubotplugin;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import org.bson.Document;
public class CubotInventory extends CpuHardware {
public class CubotInventory extends CubotHardware {
/**
* Hardware ID (Should be unique)
@@ -14,13 +13,15 @@ public class CubotInventory extends CpuHardware {
public static final int DEFAULT_ADDRESS = 6;
private Cubot cubot;
private static final int INV_CLEAR = 0;
private static final int INV_POLL = 1;
public CubotInventory(Cubot cubot) {
this.cubot = cubot;
super(cubot);
}
public CubotInventory(Document document) {
super(document);
}
@Override
@@ -48,20 +49,4 @@ public class CubotInventory extends CpuHardware {
}
}
@Override
public Document mongoSerialise() {
Document dbObject = new Document();
dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId());
return dbObject;
}
public static CubotInventory deserialize(Document obj) {
return new CubotInventory((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
}
}

View File

@@ -1,11 +1,9 @@
package net.simon987.cubotplugin;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import org.bson.Document;
public class CubotKeyboard extends CpuHardware {
public class CubotKeyboard extends CubotHardware {
public static final int DEFAULT_ADDRESS = 4;
@@ -17,10 +15,12 @@ public class CubotKeyboard extends CpuHardware {
*/
public static final char HWID = 0x0004;
private Cubot cubot;
public CubotKeyboard(Cubot cubot) {
this.cubot = cubot;
super(cubot);
}
public CubotKeyboard(Document document) {
super(document);
}
@Override
@@ -50,19 +50,4 @@ public class CubotKeyboard extends CpuHardware {
}
}
@Override
public Document mongoSerialise() {
Document dbObject = new Document();
dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId());
return dbObject;
}
public static CubotKeyboard deserialize(Document obj) {
return new CubotKeyboard((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
}
}

View File

@@ -1,18 +1,16 @@
package net.simon987.cubotplugin;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import net.simon987.server.game.Action;
import net.simon987.server.game.Attackable;
import net.simon987.server.game.GameObject;
import net.simon987.server.game.InventoryHolder;
import net.simon987.server.game.objects.Action;
import net.simon987.server.game.objects.Attackable;
import net.simon987.server.game.objects.GameObject;
import net.simon987.server.game.objects.InventoryHolder;
import org.bson.Document;
import java.awt.*;
import java.util.ArrayList;
public class CubotLaser extends CpuHardware {
public class CubotLaser extends CubotHardware {
/**
* Hardware ID (Should be unique)
@@ -21,8 +19,6 @@ public class CubotLaser extends CpuHardware {
public static final int DEFAULT_ADDRESS = 2;
private Cubot cubot;
private static final int LASER_WITHDRAW = 1;
private static final int LASER_DEPOSIT = 2;
private static final int LASER_ATTACK = 3;
@@ -30,7 +26,11 @@ public class CubotLaser extends CpuHardware {
private static final int LASER_DAMAGE = 25;
public CubotLaser(Cubot cubot) {
this.cubot = cubot;
super(cubot);
}
public CubotLaser(Document document) {
super(document);
}
@Override
@@ -90,19 +90,4 @@ public class CubotLaser extends CpuHardware {
}
}
@Override
public Document mongoSerialise() {
Document dbObject = new Document();
dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId());
return dbObject;
}
public static CubotLaser deserialize(Document obj) {
return new CubotLaser((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
}
}

View File

@@ -1,20 +1,14 @@
package net.simon987.cubotplugin;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import net.simon987.server.game.Action;
import net.simon987.server.game.Direction;
import net.simon987.server.io.JSONSerialisable;
import net.simon987.server.game.objects.Action;
import net.simon987.server.game.objects.Direction;
import org.bson.Document;
import org.json.simple.JSONObject;
public class CubotLeg extends CpuHardware implements JSONSerialisable {
public class CubotLeg extends CubotHardware {
public static final int DEFAULT_ADDRESS = 1;
public static final String NAME = "Cubot Leg";
private static final int LEGS_SET_DIR = 1;
private static final int LEGS_SET_DIR_AND_WALK = 2;
@@ -23,10 +17,12 @@ public class CubotLeg extends CpuHardware implements JSONSerialisable {
*/
static final char HWID = 0x0001;
private Cubot cubot;
public CubotLeg(Cubot cubot) {
this.cubot = cubot;
super(cubot);
}
public CubotLeg(Document document) {
super(document);
}
@Override
@@ -73,31 +69,4 @@ public class CubotLeg extends CpuHardware implements JSONSerialisable {
}
}
}
@Override
public JSONObject serialise() {
JSONObject json = new JSONObject();
json.put("hwid", (int) HWID);
json.put("cubot", cubot.getObjectId());
return json;
}
@Override
public Document mongoSerialise() {
Document dbObject = new Document();
dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId());
return dbObject;
}
public static CubotLeg deserialize(Document obj) {
return new CubotLeg((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
}
}

View File

@@ -1,19 +1,15 @@
package net.simon987.cubotplugin;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Memory;
import net.simon987.server.assembly.Status;
import net.simon987.server.game.pathfinding.Node;
import net.simon987.server.game.pathfinding.Pathfinder;
import net.simon987.server.io.JSONSerialisable;
import net.simon987.server.logging.LogManager;
import org.bson.Document;
import org.json.simple.JSONObject;
import java.util.ArrayList;
public class CubotLidar extends CpuHardware implements JSONSerialisable {
public class CubotLidar extends CubotHardware {
/**
* Hardware ID (Should be unique)
@@ -22,8 +18,6 @@ public class CubotLidar extends CpuHardware implements JSONSerialisable {
public static final int DEFAULT_ADDRESS = 3;
private Cubot cubot;
private static final int LIDAR_GET_POS = 1;
private static final int LIDAR_GET_PATH = 2;
private static final int LIDAR_GET_MAP = 3;
@@ -33,9 +27,12 @@ public class CubotLidar extends CpuHardware implements JSONSerialisable {
private static final int MEMORY_PATH_START = 0x0000;
public CubotLidar(Cubot cubot) {
this.cubot = cubot;
super(cubot);
}
public CubotLidar(Document document) {
super(document);
}
@Override
public char getId() {
@@ -134,32 +131,5 @@ public class CubotLidar extends CpuHardware implements JSONSerialisable {
break;
}
}
@Override
public JSONObject serialise() {
JSONObject json = new JSONObject();
json.put("hwid", (int) HWID);
json.put("cubot", cubot.getObjectId());
return json;
}
@Override
public Document mongoSerialise() {
Document dbObject = new Document();
dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId());
return dbObject;
}
public static CubotLidar deserialize(Document obj) {
return new CubotLidar((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
}
}

View File

@@ -4,70 +4,34 @@ import net.simon987.cubotplugin.event.ChargeShieldCommandListener;
import net.simon987.cubotplugin.event.CpuInitialisationListener;
import net.simon987.cubotplugin.event.UserCreationListener;
import net.simon987.server.ServerConfiguration;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.game.GameObject;
import net.simon987.server.io.CpuHardwareDeserializer;
import net.simon987.server.io.GameObjectDeserializer;
import net.simon987.server.game.objects.GameRegistry;
import net.simon987.server.logging.LogManager;
import net.simon987.server.plugin.ServerPlugin;
import org.bson.Document;
public class CubotPlugin extends ServerPlugin implements GameObjectDeserializer, CpuHardwareDeserializer {
public class CubotPlugin extends ServerPlugin {
@Override
public void init(ServerConfiguration config) {
public void init(ServerConfiguration config, GameRegistry registry) {
listeners.add(new CpuInitialisationListener());
listeners.add(new UserCreationListener());
listeners.add(new ChargeShieldCommandListener());
registry.registerGameObject(Cubot.class);
registry.registerHardware(CubotLeg.class);
registry.registerHardware(CubotLaser.class);
registry.registerHardware(CubotLidar.class);
registry.registerHardware(CubotDrill.class);
registry.registerHardware(CubotInventory.class);
registry.registerHardware(CubotKeyboard.class);
registry.registerHardware(CubotHologram.class);
registry.registerHardware(CubotBattery.class);
registry.registerHardware(CubotFloppyDrive.class);
registry.registerHardware(CubotComPort.class);
registry.registerHardware(CubotShield.class);
registry.registerHardware(CubotCore.class);
LogManager.LOGGER.info("Initialised Cubot plugin");
}
@Override
public GameObject deserializeObject(Document object) {
int objType = (int) object.get("t");
if (objType == Cubot.ID) {
return Cubot.deserialize(object);
}
return null;
}
@Override
public CpuHardware deserializeHardware(Document obj) {
int hwid = (int) obj.get("hwid");
switch (hwid) {
case CubotLeg.HWID:
return CubotLeg.deserialize(obj);
case CubotLaser.HWID:
return CubotLaser.deserialize(obj);
case CubotLidar.HWID:
return CubotLidar.deserialize(obj);
case CubotDrill.HWID:
return CubotDrill.deserialize(obj);
case CubotInventory.HWID:
return CubotInventory.deserialize(obj);
case CubotKeyboard.HWID:
return CubotKeyboard.deserialize(obj);
case CubotHologram.HWID:
return CubotHologram.deserialize(obj);
case CubotBattery.HWID:
return CubotBattery.deserialize(obj);
case CubotFloppyDrive.HWID:
return CubotFloppyDrive.deserialize(obj);
case CubotComPort.HWID:
return CubotComPort.deserialize(obj);
case CubotShield.HWID:
return CubotShield.deserialize(obj);
case CubotCore.HWID:
return CubotCore.deserialize(obj);
}
return null;
}
}

View File

@@ -1,11 +1,10 @@
package net.simon987.cubotplugin;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import org.bson.Document;
public class CubotShield extends CpuHardware {
public class CubotShield extends CubotHardware {
public static final char DEFAULT_ADDRESS = 0x000F;
@@ -13,12 +12,15 @@ public class CubotShield extends CpuHardware {
private static final int SHIELD_CHARGE = 1;
private static final int SHIELD_POLL = 2;
private Cubot cubot;
public static final int COST = GameServer.INSTANCE.getConfig().getInt("shield_energy_cost");
public CubotShield(Cubot cubot) {
this.cubot = cubot;
super(cubot);
}
public CubotShield(Document document) {
super(document);
}
@Override
@@ -26,16 +28,6 @@ public class CubotShield extends CpuHardware {
return HWID;
}
@Override
public Document mongoSerialise() {
Document dbObject = new Document();
dbObject.put("hwid", (int) HWID);
dbObject.put("cubot", cubot.getObjectId());
return dbObject;
}
@Override
public void handleInterrupt(Status status) {
int a = getCpu().getRegisterSet().getRegister("A").getValue();
@@ -48,8 +40,4 @@ public class CubotShield extends CpuHardware {
getCpu().getRegisterSet().getRegister("B").setValue(shield);
}
}
public static CubotShield deserialize(Document obj) {
return new CubotShield((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
}
}

View File

@@ -28,6 +28,11 @@ public class FloppyDisk implements MongoSerializable {
this.memory = new Memory(512 * 1440);
}
public FloppyDisk(Document document) {
this.rwHeadTrack = (int) document.get("rwHeadTrack");
this.memory = new Memory((Document) document.get("memory"));
}
/**
* Read 512 words from the specified sector to cpu memory at specified address
*
@@ -92,16 +97,6 @@ public class FloppyDisk implements MongoSerializable {
return dbObject;
}
public static FloppyDisk deserialise(Document obj) {
FloppyDisk floppyDisk = new FloppyDisk();
floppyDisk.rwHeadTrack = (int) obj.get("rwHeadTrack");
floppyDisk.memory = Memory.deserialize((Document) obj.get("memory"));
return floppyDisk;
}
public Memory getMemory() {
return memory;
}

View File

@@ -5,7 +5,7 @@ import net.simon987.server.GameServer;
import net.simon987.server.event.DebugCommandEvent;
import net.simon987.server.event.GameEvent;
import net.simon987.server.event.GameEventListener;
import net.simon987.server.game.GameObject;
import net.simon987.server.game.objects.GameObject;
/**
* Debug command to add shield points to a Cubot