mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-10 14:26:45 +00:00
Cubot object id is no longer stored inside every CpuHardware in the database. Renamed some fields in the database to make them more readable
This commit is contained in:
parent
4cd58c86a5
commit
3368268924
@ -1,6 +1,7 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
public class CubotBattery extends CubotHardware {
|
||||
@ -19,8 +20,8 @@ public class CubotBattery extends CubotHardware {
|
||||
super(cubot);
|
||||
}
|
||||
|
||||
public CubotBattery(Document document) {
|
||||
super(document);
|
||||
public CubotBattery(Document document, ControllableUnit cubot) {
|
||||
super(document, cubot);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -33,6 +34,8 @@ public class CubotBattery extends CubotHardware {
|
||||
|
||||
} else if (a == BATTERY_GET_MAX_CAPACITY) {
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(cubot.getMaxEnergy());
|
||||
|
||||
//TODO: Remove debug action
|
||||
} else if (a == 0xFFFF) {
|
||||
cubot.setEnergy(cubot.getMaxEnergy());
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.objects.Programmable;
|
||||
import org.bson.Document;
|
||||
@ -23,8 +24,8 @@ public class CubotComPort extends CubotHardware {
|
||||
super(cubot);
|
||||
}
|
||||
|
||||
public CubotComPort(Document document) {
|
||||
super(document);
|
||||
public CubotComPort(Document document, ControllableUnit cubot) {
|
||||
super(document, cubot);
|
||||
}
|
||||
|
||||
private static final int MESSAGE_LENGTH = 8;
|
||||
@ -117,8 +118,6 @@ public class CubotComPort extends CubotHardware {
|
||||
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(0); //Failed
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
public class CubotCore extends CubotHardware {
|
||||
@ -19,8 +20,8 @@ public class CubotCore extends CubotHardware {
|
||||
super(cubot);
|
||||
}
|
||||
|
||||
public CubotCore(Document document) {
|
||||
super(document);
|
||||
public CubotCore(Document document, ControllableUnit cubot) {
|
||||
super(document, cubot);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,6 +2,7 @@ package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.Action;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.game.world.TileMap;
|
||||
import org.bson.Document;
|
||||
|
||||
@ -21,8 +22,8 @@ public class CubotDrill extends CubotHardware {
|
||||
super(cubot);
|
||||
}
|
||||
|
||||
public CubotDrill(Document document) {
|
||||
super(document);
|
||||
public CubotDrill(Document document, ControllableUnit cubot) {
|
||||
super(document, cubot);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
public class CubotFloppyDrive extends CubotHardware {
|
||||
@ -24,8 +25,8 @@ public class CubotFloppyDrive extends CubotHardware {
|
||||
floppyDisk = new FloppyDisk();
|
||||
}
|
||||
|
||||
public CubotFloppyDrive(Document document) {
|
||||
super(document);
|
||||
public CubotFloppyDrive(Document document, ControllableUnit cubot) {
|
||||
super(document, cubot);
|
||||
|
||||
if (document.containsKey("floppy")) {
|
||||
floppyDisk = new FloppyDisk((Document) document.get("floppy"));
|
||||
|
@ -1,15 +1,15 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.CpuHardware;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
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(Document document, ControllableUnit cubot) {
|
||||
this.cubot = (Cubot) cubot;
|
||||
}
|
||||
|
||||
public CubotHardware(Cubot cubot) {
|
||||
@ -21,7 +21,6 @@ public abstract class CubotHardware extends CpuHardware {
|
||||
Document document = new Document();
|
||||
|
||||
document.put("type", getClass().getCanonicalName());
|
||||
document.put("cubot", cubot.getObjectId());
|
||||
return document;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
public class CubotHologram extends CubotHardware {
|
||||
@ -25,8 +26,8 @@ public class CubotHologram extends CubotHardware {
|
||||
super(cubot);
|
||||
}
|
||||
|
||||
public CubotHologram(Document document) {
|
||||
super(document);
|
||||
public CubotHologram(Document document, ControllableUnit cubot) {
|
||||
super(document, cubot);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,6 +2,7 @@ package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
public class CubotInventory extends CubotHardware {
|
||||
@ -20,8 +21,8 @@ public class CubotInventory extends CubotHardware {
|
||||
super(cubot);
|
||||
}
|
||||
|
||||
public CubotInventory(Document document) {
|
||||
super(document);
|
||||
public CubotInventory(Document document, ControllableUnit cubot) {
|
||||
super(document, cubot);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
public class CubotKeyboard extends CubotHardware {
|
||||
@ -19,8 +20,8 @@ public class CubotKeyboard extends CubotHardware {
|
||||
super(cubot);
|
||||
}
|
||||
|
||||
public CubotKeyboard(Document document) {
|
||||
super(document);
|
||||
public CubotKeyboard(Document document, ControllableUnit cubot) {
|
||||
super(document, cubot);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,10 +1,7 @@
|
||||
package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.assembly.Status;
|
||||
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 net.simon987.server.game.objects.*;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.awt.*;
|
||||
@ -29,8 +26,8 @@ public class CubotLaser extends CubotHardware {
|
||||
super(cubot);
|
||||
}
|
||||
|
||||
public CubotLaser(Document document) {
|
||||
super(document);
|
||||
public CubotLaser(Document document, ControllableUnit cubot) {
|
||||
super(document, cubot);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,6 +2,7 @@ package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.Action;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.game.objects.Direction;
|
||||
import org.bson.Document;
|
||||
|
||||
@ -21,8 +22,8 @@ public class CubotLeg extends CubotHardware {
|
||||
super(cubot);
|
||||
}
|
||||
|
||||
public CubotLeg(Document document) {
|
||||
super(document);
|
||||
public CubotLeg(Document document, ControllableUnit cubot) {
|
||||
super(document, cubot);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,6 +2,7 @@ package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.assembly.Memory;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.game.pathfinding.Node;
|
||||
import net.simon987.server.game.pathfinding.Pathfinder;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
@ -30,8 +31,8 @@ public class CubotLidar extends CubotHardware {
|
||||
super(cubot);
|
||||
}
|
||||
|
||||
public CubotLidar(Document document) {
|
||||
super(document);
|
||||
public CubotLidar(Document document, ControllableUnit cubot) {
|
||||
super(document, cubot);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,6 +2,7 @@ package net.simon987.cubotplugin;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
public class CubotShield extends CubotHardware {
|
||||
@ -19,8 +20,8 @@ public class CubotShield extends CubotHardware {
|
||||
super(cubot);
|
||||
}
|
||||
|
||||
public CubotShield(Document document) {
|
||||
super(document);
|
||||
public CubotShield(Document document, ControllableUnit cubot) {
|
||||
super(document, cubot);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -29,7 +29,7 @@ public class FloppyDisk implements MongoSerializable {
|
||||
}
|
||||
|
||||
public FloppyDisk(Document document) {
|
||||
this.rwHeadTrack = (int) document.get("rwHeadTrack");
|
||||
this.rwHeadTrack = document.getInteger("rwHeadTrack");
|
||||
this.memory = new Memory((Document) document.get("memory"));
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.CpuHardware;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Util;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
/**
|
||||
@ -19,8 +20,8 @@ public class Clock extends CpuHardware {
|
||||
|
||||
}
|
||||
|
||||
public Clock(Document document) {
|
||||
super(document);
|
||||
public Clock(Document document, ControllableUnit unit) {
|
||||
super(document, unit);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,6 +2,7 @@ package net.simon987.mischwplugin;
|
||||
|
||||
import net.simon987.server.assembly.CpuHardware;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.Random;
|
||||
@ -21,8 +22,8 @@ public class RandomNumberGenerator extends CpuHardware {
|
||||
random = new Random();
|
||||
}
|
||||
|
||||
public RandomNumberGenerator(Document document) {
|
||||
super(document);
|
||||
public RandomNumberGenerator(Document document, ControllableUnit unit) {
|
||||
super(document, unit);
|
||||
random = new Random();
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class ElectricBox extends GameObject implements Updatable, Attackable {
|
||||
|
||||
public ElectricBox(Document document) {
|
||||
super(document);
|
||||
hp = (int) document.get("hp");
|
||||
hp = document.getInteger("hp");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -53,11 +53,7 @@ public class Factory extends GameObject implements Updatable {
|
||||
public Factory(Document document) {
|
||||
super(document);
|
||||
|
||||
setObjectId((long) document.get("i"));
|
||||
setX((int) document.get("x"));
|
||||
setY((int) document.get("y"));
|
||||
|
||||
tmpNpcArray = ((ArrayList) document.get("tmpNpcArray")).toArray();
|
||||
tmpNpcArray = ((ArrayList) document.get("npcs")).toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -78,13 +74,12 @@ public class Factory extends GameObject implements Updatable {
|
||||
|
||||
for (Object id : tmpNpcArray) {
|
||||
|
||||
NonPlayerCharacter npc = (NonPlayerCharacter) GameServer.INSTANCE.getGameUniverse().getObject((int) (long) id);
|
||||
NonPlayerCharacter npc = (NonPlayerCharacter) GameServer.INSTANCE.getGameUniverse().getObject((long) id);
|
||||
|
||||
if (npc != null) {
|
||||
npc.setFactory(this);
|
||||
npcs.add(npc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
tmpNpcArray = null;
|
||||
@ -139,7 +134,7 @@ public class Factory extends GameObject implements Updatable {
|
||||
tmpNpcArray.add(npc.getObjectId());
|
||||
}
|
||||
|
||||
dbObject.put("n", tmpNpcArray);
|
||||
dbObject.put("npcs", tmpNpcArray);
|
||||
|
||||
return dbObject;
|
||||
}
|
||||
|
@ -24,6 +24,8 @@ public class HarvesterNPC extends NonPlayerCharacter {
|
||||
public HarvesterNPC(Document document) {
|
||||
super(document);
|
||||
|
||||
setTask(new HarvestTask());
|
||||
|
||||
setDirection(Direction.getDirection(document.getInteger("direction")));
|
||||
}
|
||||
|
||||
|
@ -24,8 +24,8 @@ public class RadioReceiverHardware extends CpuHardware {
|
||||
this.cubot = cubot;
|
||||
}
|
||||
|
||||
public RadioReceiverHardware(Document document) {
|
||||
super(document);
|
||||
public RadioReceiverHardware(Document document, ControllableUnit unit) {
|
||||
super(document, unit);
|
||||
|
||||
this.cubot = (ControllableUnit) GameServer.INSTANCE.getGameUniverse().getObject((long) document.get("cubot"));
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ public class VaultDoor extends GameObject implements Programmable, Enterable, Up
|
||||
|
||||
dbObject.put("homeX", getHomeX());
|
||||
dbObject.put("homeY", getHomeY());
|
||||
dbObject.put("pw", new String(password));
|
||||
dbObject.put("password", new String(password));
|
||||
|
||||
return dbObject;
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ public class BiomassBlob extends GameObject implements InventoryHolder {
|
||||
public BiomassBlob(Document document) {
|
||||
super(document);
|
||||
|
||||
biomassCount = document.getInteger("b");
|
||||
biomassCount = document.getInteger("biomassCount");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -49,7 +49,7 @@ public class BiomassBlob extends GameObject implements InventoryHolder {
|
||||
|
||||
Document dbObject = super.mongoSerialise();
|
||||
|
||||
dbObject.put("b", biomassCount);
|
||||
dbObject.put("biomassCount", biomassCount);
|
||||
|
||||
return dbObject;
|
||||
|
||||
|
@ -376,14 +376,14 @@ public class CPU implements MongoSerializable {
|
||||
|
||||
CPU cpu = new CPU(GameServer.INSTANCE.getConfig(), user);
|
||||
|
||||
cpu.codeSectionOffset = (int) obj.get("codeSegmentOffset");
|
||||
cpu.codeSectionOffset = obj.getInteger("codeSegmentOffset");
|
||||
|
||||
ArrayList hardwareList = (ArrayList) obj.get("hardware");
|
||||
|
||||
for (Object serialisedHw : hardwareList) {
|
||||
CpuHardware hardware = GameServer.INSTANCE.getRegistry().deserializeHardware((Document) serialisedHw);
|
||||
CpuHardware hardware = GameServer.INSTANCE.getRegistry().deserializeHardware((Document) serialisedHw, user.getControlledUnit());
|
||||
hardware.setCpu(cpu);
|
||||
cpu.attachHardware(hardware, (int) ((Document) serialisedHw).get("address"));
|
||||
cpu.attachHardware(hardware, ((Document) serialisedHw).getInteger("address"));
|
||||
}
|
||||
|
||||
cpu.memory = new Memory((Document) obj.get("memory"));
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.simon987.server.assembly;
|
||||
|
||||
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.io.MongoSerializable;
|
||||
import org.bson.Document;
|
||||
|
||||
@ -13,7 +14,7 @@ public abstract class CpuHardware implements MongoSerializable {
|
||||
|
||||
}
|
||||
|
||||
public CpuHardware(Document document) {
|
||||
public CpuHardware(Document document, ControllableUnit unit) {
|
||||
|
||||
}
|
||||
|
||||
|
@ -171,9 +171,9 @@ public class RegisterSet implements Target, MongoSerializable {
|
||||
for (Object sRegister : registers) {
|
||||
|
||||
Register register = new Register((String) ((Document) sRegister).get("name"));
|
||||
register.setValue((int) ((Document) sRegister).get("value"));
|
||||
register.setValue(((Document) sRegister).getInteger("value"));
|
||||
|
||||
registerSet.registers.put((int) ((Document) sRegister).get("index"), register);
|
||||
registerSet.registers.put(((Document) sRegister).getInteger("index"), register);
|
||||
|
||||
}
|
||||
|
||||
|
@ -27,13 +27,13 @@ public class GameRegistry {
|
||||
}
|
||||
|
||||
|
||||
public CpuHardware deserializeHardware(Document document) {
|
||||
public CpuHardware deserializeHardware(Document document, ControllableUnit controllableUnit) {
|
||||
String type = document.getString("type");
|
||||
|
||||
if (hardware.containsKey(type)) {
|
||||
|
||||
try {
|
||||
return hardware.get(type).getConstructor(Document.class).newInstance(document);
|
||||
return hardware.get(type).getConstructor(Document.class, ControllableUnit.class).newInstance(document, controllableUnit);
|
||||
} catch (InstantiationException | IllegalAccessException |
|
||||
InvocationTargetException | NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
@ -53,10 +53,14 @@ public class GameRegistry {
|
||||
|
||||
try {
|
||||
return gameObjects.get(type).getConstructor(Document.class).newInstance(document);
|
||||
} catch (InstantiationException | IllegalAccessException |
|
||||
InvocationTargetException | NoSuchMethodException e) {
|
||||
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (InvocationTargetException e) {
|
||||
LogManager.LOGGER.severe("Error while trying to deserialize object of type " + type + ": " + e.getTargetException().getMessage());
|
||||
LogManager.LOGGER.severe(document.toJson());
|
||||
e.getTargetException().printStackTrace();
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
LogManager.LOGGER.severe("Trying to deserialize unknown GameObject type: " + type);
|
||||
|
@ -200,27 +200,27 @@ public class World implements MongoSerializable {
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
String str = "World (" + x + ", " + y + ")\n";
|
||||
StringBuilder str = new StringBuilder("World (" + x + ", " + y + ")\n");
|
||||
int[][] tileMap = this.tileMap.getTiles();
|
||||
|
||||
for (int x = 0; x < worldSize; x++) {
|
||||
for (int y = 0; y < worldSize; y++) {
|
||||
str += tileMap[x][y] + " ";
|
||||
str.append(tileMap[x][y]).append(" ");
|
||||
}
|
||||
str += "\n";
|
||||
str.append("\n");
|
||||
}
|
||||
|
||||
return str;
|
||||
return str.toString();
|
||||
|
||||
}
|
||||
|
||||
public static World deserialize(Document dbObject) {
|
||||
|
||||
World world = new World((int) dbObject.get("size"));
|
||||
world.x = (int) dbObject.get("x");
|
||||
world.y = (int) dbObject.get("y");
|
||||
world.dimension = (String) dbObject.get("dimension");
|
||||
world.updatable = (int) dbObject.get("updatable");
|
||||
World world = new World(dbObject.getInteger("size"));
|
||||
world.x = dbObject.getInteger("x");
|
||||
world.y = dbObject.getInteger("y");
|
||||
world.dimension = dbObject.getString("dimension");
|
||||
world.updatable = dbObject.getInteger("updatable");
|
||||
|
||||
world.tileMap = TileMap.deserialize((Document) dbObject.get("terrain"), world.getWorldSize());
|
||||
|
||||
@ -237,7 +237,6 @@ public class World implements MongoSerializable {
|
||||
}
|
||||
|
||||
return world;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -518,6 +517,5 @@ public class World implements MongoSerializable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user