Fixed hardware deserialization issues

This commit is contained in:
simon 2018-03-10 11:51:31 -05:00
parent 9cac665101
commit e4269b83c4
7 changed files with 34 additions and 10 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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

View File

@ -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;
}

View File

@ -42,4 +42,8 @@ public abstract class CpuHardware implements MongoSerialisable {
return null;
}
@Override
public String toString() {
return String.format("<%04X>", (int) getId());
}
}