From c7da764505c5109e71c6f762304b7c375eec7583 Mon Sep 17 00:00:00 2001 From: Dylan Sheehy Date: Tue, 2 Jan 2018 07:04:14 -0600 Subject: [PATCH 1/8] Added entries to .gitignore to ignore files that vscode's java extension generates --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 9fd1df3..b534ce4 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ Server/Server.iml target/* Server/Server.iml Server/src/main/java/META-INF/MANIFEST.MF +.settings +.project +.classpath \ No newline at end of file From 7e773699b6ee240997b40799116f5eb5acfe3b82 Mon Sep 17 00:00:00 2001 From: Dylan Sheehy Date: Fri, 5 Jan 2018 11:04:05 -0600 Subject: [PATCH 2/8] Created Shield hardware --- .../java/net/simon987/cubotplugin/Cubot.java | 42 ++++++++++++++++ .../net/simon987/cubotplugin/CubotPlugin.java | 2 + .../net/simon987/cubotplugin/CubotShield.java | 48 +++++++++++++++++++ Server/src/main/resources/config.properties | 4 ++ 4 files changed, 96 insertions(+) create mode 100644 Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotShield.java diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java index 8693776..8c1b84f 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java @@ -27,6 +27,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr * Hit points */ private int hp; + private int shield; + private int maxShield; private int heldItem; private Action currentAction = Action.IDLE; @@ -102,6 +104,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr json.put("direction", getDirection().ordinal()); json.put("heldItem", heldItem); json.put("hp", hp); + json.put("shield", shield); json.put("action", lastAction.ordinal()); json.put("holo", hologram); json.put("holoStr", hologramString); @@ -127,6 +130,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr dbObject.put("direction", getDirection().ordinal()); dbObject.put("heldItem", heldItem); dbObject.put("hp", hp); + dbObject.put("shield", shield); dbObject.put("action", lastAction.ordinal()); dbObject.put("holo", hologram); dbObject.put("holoStr", hologramString); @@ -148,6 +152,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr 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.maxShield = GameServer.INSTANCE.getConfig().getInt("max_shield"); cubot.setDirection(Direction.getDirection((int) obj.get("direction"))); cubot.heldItem = (int) obj.get("heldItem"); cubot.energy = (int) obj.get("energy"); @@ -240,6 +246,42 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr return maxEnergy; } + // shield methods are modeled after energy methods + public int getShield() { + return shield; + } + + public void setShield(int shield) { + this.shield = shield; + } + + public boolean chargeShield(int qty) { + qty = Math.min(qty, maxShield - shield); + int cost = GameServer.INSTANCE.getConfig().getInt("shield_energy_cost"); + int energySpent = qty * cost; + if(spendEnergy(energySpent)) { + shield += qty; + return true; + } else { + return false; + } + } + + /** + * Damages shield by qty. + * + * Return damage that broke through the shield. + */ + public int damageShield(int qty) { + int after = shield - qty; + if(after < 0) { + shield = 0; + return -after; + } + shield = after; + return 0; + } + @Override public Memory getFloppyData() { 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 abbe674..c4ac143 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotPlugin.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotPlugin.java @@ -60,6 +60,8 @@ public class CubotPlugin extends ServerPlugin implements GameObjectDeserializer, return CubotFloppyDrive.deserialize(obj); case CubotComPort.HWID: return CubotComPort.deserialize(obj); + case CubotShield.HWID: + return CubotShield.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 new file mode 100644 index 0000000..d5f4ccd --- /dev/null +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotShield.java @@ -0,0 +1,48 @@ +package net.simon987.cubotplugin; + +import com.mongodb.BasicDBObject; +import com.mongodb.DBObject; +import net.simon987.server.GameServer; +import net.simon987.server.assembly.CpuHardware; +import net.simon987.server.assembly.Status; + +public class CubotShield extends CpuHardware { + static final char HWID = 0x000E; + + private static final int SHIELD_CHARGE = 1; + private static final int SHIELD_QUERY = 2; + private Cubot cubot; + + public CubotShield(Cubot cubot) { + this.cubot = cubot; + } + + @Override + public char getId() { + return HWID; + } + + @Override + public BasicDBObject mongoSerialise() { + BasicDBObject dbObject = new BasicDBObject(); + + return dbObject; + } + + @Override + public void handleInterrupt(Status status) { + int a = getCpu().getRegisterSet().getRegister("A").getValue(); + // b = amount to charge + if(a == SHIELD_CHARGE) { + int b = getCpu().getRegisterSet().getRegister("B").getValue(); + cubot.chargeShield(b); + } else if(a == SHIELD_QUERY) { + int shield = cubot.getShield(); + getCpu().getRegisterSet().getRegister("B").setValue(shield); + } + } + + public static CubotShield deserialize(DBObject obj) { + return new CubotShield((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); + } +} \ No newline at end of file diff --git a/Server/src/main/resources/config.properties b/Server/src/main/resources/config.properties index 1c925dc..22f2a5e 100644 --- a/Server/src/main/resources/config.properties +++ b/Server/src/main/resources/config.properties @@ -48,6 +48,10 @@ maxBiomassRespawnCount=6 biomassEnergyValue=4000 # Maximum energy of the battery hardware in kJ battery_max_energy=60000 +# Maximum shield power +max_shield=100 +# Energy cost per unit to charge shield +shield_energy_cost=50 # Time for biomass respawn in ticks biomassRespawnTime=64 # Respawn timer will start when biomass count is below this number From 1da894959e16cebe21207012455e9d7508942154 Mon Sep 17 00:00:00 2001 From: Dylan Sheehy Date: Fri, 5 Jan 2018 11:20:52 -0600 Subject: [PATCH 3/8] fixed serialization code for CubotShield --- .../src/main/java/net/simon987/cubotplugin/CubotShield.java | 3 +++ 1 file changed, 3 insertions(+) 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 d5f4ccd..670634b 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotShield.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotShield.java @@ -26,6 +26,9 @@ public class CubotShield extends CpuHardware { public BasicDBObject mongoSerialise() { BasicDBObject dbObject = new BasicDBObject(); + dbObject.put("hwid", HWID); + dbObject.put("cubot", cubot.getObjectId()); + return dbObject; } From c772abe0bf6c423586a9895e02dee550663c0be4 Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 20 Jan 2018 12:33:01 -0500 Subject: [PATCH 4/8] Fixed opcode clash for PUSHF instruction --- .../simon987/server/assembly/instruction/PushfInstruction.java | 2 +- .../net/simon987/server/webserver/TerrainRequestHandler.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Server/src/main/java/net/simon987/server/assembly/instruction/PushfInstruction.java b/Server/src/main/java/net/simon987/server/assembly/instruction/PushfInstruction.java index efa54ca..9049b1d 100644 --- a/Server/src/main/java/net/simon987/server/assembly/instruction/PushfInstruction.java +++ b/Server/src/main/java/net/simon987/server/assembly/instruction/PushfInstruction.java @@ -13,7 +13,7 @@ public class PushfInstruction extends Instruction { /** * Opcode of the instruction */ - public static final int OPCODE = 43; + public static final int OPCODE = 45; private CPU cpu; diff --git a/Server/src/main/java/net/simon987/server/webserver/TerrainRequestHandler.java b/Server/src/main/java/net/simon987/server/webserver/TerrainRequestHandler.java index e566e96..702ed20 100644 --- a/Server/src/main/java/net/simon987/server/webserver/TerrainRequestHandler.java +++ b/Server/src/main/java/net/simon987/server/webserver/TerrainRequestHandler.java @@ -17,7 +17,7 @@ public class TerrainRequestHandler implements MessageHandler { try { world = GameServer.INSTANCE.getGameUniverse().getWorld( Long.valueOf((long) json.get("x")).intValue(), - Long.valueOf((long) json.get("y")).intValue(), true); + Long.valueOf((long) json.get("y")).intValue(), false); } catch (NullPointerException e) { LogManager.LOGGER.severe("FIXME: handle TerrainRequestHandler"); return; From 8d961ce57232fde2ea59e35900329c188a9fbf1a Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 20 Jan 2018 14:18:44 -0500 Subject: [PATCH 5/8] Added JA and JNA Instructions --- .../net/simon987/server/assembly/CPU.java | 2 + .../assembly/instruction/JaInstruction.java | 38 +++++++++++++++++++ .../assembly/instruction/JnaInstruction.java | 38 +++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 Server/src/main/java/net/simon987/server/assembly/instruction/JaInstruction.java create mode 100644 Server/src/main/java/net/simon987/server/assembly/instruction/JnaInstruction.java 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 873907f..1643ed6 100755 --- a/Server/src/main/java/net/simon987/server/assembly/CPU.java +++ b/Server/src/main/java/net/simon987/server/assembly/CPU.java @@ -99,6 +99,8 @@ public class CPU implements MongoSerialisable { instructionSet.add(new JoInstruction(this)); instructionSet.add(new PushfInstruction(this)); instructionSet.add(new PopfInstruction(this)); + instructionSet.add(new JnaInstruction(this)); + instructionSet.add(new JaInstruction(this)); status = new Status(); memory = new Memory(config.getInt("memory_size")); diff --git a/Server/src/main/java/net/simon987/server/assembly/instruction/JaInstruction.java b/Server/src/main/java/net/simon987/server/assembly/instruction/JaInstruction.java new file mode 100644 index 0000000..20dca0f --- /dev/null +++ b/Server/src/main/java/net/simon987/server/assembly/instruction/JaInstruction.java @@ -0,0 +1,38 @@ +package net.simon987.server.assembly.instruction; + +import net.simon987.server.assembly.CPU; +import net.simon987.server.assembly.Instruction; +import net.simon987.server.assembly.Status; +import net.simon987.server.assembly.Target; + +/** + * Jump if above + */ +public class JaInstruction extends Instruction { + + public static final int OPCODE = 46; + + private CPU cpu; + + public JaInstruction(CPU cpu) { + super("ja", OPCODE); + + this.cpu = cpu; + } + + @Override + public Status execute(Target src, int srcIndex, Status status) { + if (!status.isCarryFlag() && !status.isZeroFlag()) { + cpu.setIp((char) src.get(srcIndex)); + } + return status; + } + + @Override + public Status execute(int src, Status status) { + if (!status.isCarryFlag() && !status.isZeroFlag()) { + cpu.setIp((char) src); + } + return status; + } +} diff --git a/Server/src/main/java/net/simon987/server/assembly/instruction/JnaInstruction.java b/Server/src/main/java/net/simon987/server/assembly/instruction/JnaInstruction.java new file mode 100644 index 0000000..e143f7e --- /dev/null +++ b/Server/src/main/java/net/simon987/server/assembly/instruction/JnaInstruction.java @@ -0,0 +1,38 @@ +package net.simon987.server.assembly.instruction; + +import net.simon987.server.assembly.CPU; +import net.simon987.server.assembly.Instruction; +import net.simon987.server.assembly.Status; +import net.simon987.server.assembly.Target; + +/** + * Jump if not above + */ +public class JnaInstruction extends Instruction { + + public static final int OPCODE = 47; + + private CPU cpu; + + public JnaInstruction(CPU cpu) { + super("jna", OPCODE); + + this.cpu = cpu; + } + + @Override + public Status execute(Target src, int srcIndex, Status status) { + if (status.isCarryFlag() || status.isZeroFlag()) { + cpu.setIp((char) src.get(srcIndex)); + } + return status; + } + + @Override + public Status execute(int src, Status status) { + if (status.isCarryFlag() || status.isZeroFlag()) { + cpu.setIp((char) src); + } + return status; + } +} \ No newline at end of file From a7d1a00ae814dd46ddd6158e4f3521b4181b98f2 Mon Sep 17 00:00:00 2001 From: simon Date: Sun, 25 Feb 2018 08:51:03 -0500 Subject: [PATCH 6/8] Fixes #27 --- Server/src/main/java/net/simon987/server/Main.java | 4 ++-- .../java/net/simon987/server/logging/LogManager.java | 9 +++++++-- Server/src/main/resources/config.properties | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Server/src/main/java/net/simon987/server/Main.java b/Server/src/main/java/net/simon987/server/Main.java index 2b93634..cab15d0 100644 --- a/Server/src/main/java/net/simon987/server/Main.java +++ b/Server/src/main/java/net/simon987/server/Main.java @@ -9,9 +9,9 @@ import java.net.InetSocketAddress; public class Main { public static void main(String[] args) { - - LogManager.initialize(); ServerConfiguration config = new ServerConfiguration("config.properties"); + LogManager.initialize(config); + //Load GameServer.INSTANCE.load(); diff --git a/Server/src/main/java/net/simon987/server/logging/LogManager.java b/Server/src/main/java/net/simon987/server/logging/LogManager.java index 47b11e3..33cc974 100755 --- a/Server/src/main/java/net/simon987/server/logging/LogManager.java +++ b/Server/src/main/java/net/simon987/server/logging/LogManager.java @@ -1,5 +1,7 @@ package net.simon987.server.logging; +import net.simon987.server.ServerConfiguration; + import java.io.IOException; import java.util.logging.*; @@ -16,7 +18,7 @@ public class LogManager { /** * Initialises the logger */ - public static void initialize() { + public static void initialize(ServerConfiguration config) { LOGGER.setUseParentHandlers(false); /* @@ -45,15 +47,18 @@ public class LogManager { handler.setLevel(Level.ALL); try { - Handler fileHandler = new FileHandler("mar.log"); + Handler fileHandler = new FileHandler("mar-%g.log", config.getInt("log_limit"), + config.getInt("log_count")); fileHandler.setLevel(Level.ALL); fileHandler.setFormatter(new GenericFormatter()); + LOGGER.addHandler(handler); LOGGER.addHandler(errHandler); LOGGER.addHandler(fileHandler); LOGGER.setLevel(Level.ALL); + } catch (IOException e) { e.printStackTrace(); } diff --git a/Server/src/main/resources/config.properties b/Server/src/main/resources/config.properties index 1c925dc..05bdd6f 100644 --- a/Server/src/main/resources/config.properties +++ b/Server/src/main/resources/config.properties @@ -6,8 +6,8 @@ mysql_pass=mar mysql_url=jdbc:mysql://localhost:3306/mar?useSSL=false # File management save_interval=5 -clean_interval=10 -history_size=10 +log_limit=2000000 +log_count=10 # Web server port webSocket_port=8887 webSocket_host=0.0.0.0 From 156deb8f4eb4cdf8180fcebce1e4094029bdc114 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 27 Feb 2018 16:51:18 -0500 Subject: [PATCH 7/8] NPCs decrement World.updatable on death. Fixes problem making Worlds stay loaded forever in RAM --- .../src/main/java/net/simon987/npcplugin/HarvesterNPC.java | 2 ++ 1 file changed, 2 insertions(+) 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..b6d8979 100644 --- a/Plugin NPC/src/main/java/net/simon987/npcplugin/HarvesterNPC.java +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/HarvesterNPC.java @@ -48,6 +48,8 @@ public class HarvesterNPC extends NonPlayerCharacter { @Override public void onDeadCallback() { + getWorld().decUpdatable(); + if (getFactory() != null && getFactory().getNpcs() != null) { getFactory().getNpcs().remove(this); } From 8ed192f8d02e0d222fa29c514739e5cd8f829ba1 Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 10 Mar 2018 09:49:34 -0500 Subject: [PATCH 8/8] Cubot implements Attackable (untested) --- .../java/net/simon987/cubotplugin/Cubot.java | 70 +++++++++++++++++-- .../net/simon987/cubotplugin/CubotCore.java | 59 ++++++++++++++++ .../net/simon987/cubotplugin/CubotShield.java | 6 +- .../net/simon987/cubotplugin/CubotStatus.java | 18 +++++ .../net/simon987/npcplugin/HarvesterNPC.java | 4 +- .../net/simon987/server/game/GameObject.java | 5 +- .../java/net/simon987/server/game/World.java | 9 ++- 7 files changed, 157 insertions(+), 14 deletions(-) create mode 100644 Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotCore.java create mode 100644 Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotStatus.java diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java index 8c1b84f..9d573f9 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/Cubot.java @@ -10,13 +10,11 @@ import org.json.simple.JSONObject; import java.util.ArrayList; -public class Cubot extends GameObject implements Updatable, ControllableUnit, Programmable { +public class Cubot extends GameObject implements Updatable, ControllableUnit, Programmable, Attackable { private static final char MAP_INFO = 0x0080; public static final int ID = 1; - public static int TYPE_ID = 2; - private int hologram = 0; private String hologramString = ""; private HologramMode hologramMode = HologramMode.CLEARED; @@ -34,6 +32,9 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr private Action currentAction = Action.IDLE; private Action lastAction = Action.IDLE; + private char currentStatus; + private char lastStatus; + private ArrayList keyboardBuffer = new ArrayList<>(); private ArrayList consoleMessagesBuffer = new ArrayList<>(CONSOLE_BUFFER_MAX_SIZE); @@ -92,6 +93,10 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr lastConsoleMessagesBuffer = new ArrayList<>(consoleMessagesBuffer); consoleMessagesBuffer.clear(); + + //And the status.. + lastStatus = currentStatus; + currentStatus = 0; } @Override @@ -152,8 +157,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr 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.maxShield = GameServer.INSTANCE.getConfig().getInt("max_shield"); +// cubot.shield = (int) obj.get("shield"); +// cubot.maxShield = GameServer.INSTANCE.getConfig().getInt("max_shield"); cubot.setDirection(Direction.getDirection((int) obj.get("direction"))); cubot.heldItem = (int) obj.get("heldItem"); cubot.energy = (int) obj.get("energy"); @@ -246,7 +251,6 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr return maxEnergy; } - // shield methods are modeled after energy methods public int getShield() { return shield; } @@ -347,4 +351,58 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr public void setHologramColor(int hologramColor) { this.hologramColor = hologramColor; } + + public void addStatus(CubotStatus status) { + + currentStatus |= status.val; + } + + public void removeStatus(CubotStatus status) { + + currentStatus &= (~status.val); + } + + public char getStatus() { + return lastStatus; + } + + @Override + public void setHealRate(int hp) { + + } + + @Override + public int getHp() { + return 0; + } + + @Override + public void setHp(int hp) { + + } + + @Override + public int getMaxHp() { + return 0; + } + + @Override + public void setMaxHp(int hp) { + + } + + @Override + public void heal(int amount) { + + } + + @Override + public void damage(int amount) { + + } + + @Override + public boolean onDeadCallback() { + return true; //always cancelled + } } diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotCore.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotCore.java new file mode 100644 index 0000000..021dc62 --- /dev/null +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotCore.java @@ -0,0 +1,59 @@ +package net.simon987.cubotplugin; + +import com.mongodb.BasicDBObject; +import com.mongodb.DBObject; +import net.simon987.server.GameServer; +import net.simon987.server.assembly.CpuHardware; +import net.simon987.server.assembly.Status; + +public class CubotCore extends CpuHardware { + + public static final int DEFAULT_ADDRESS = 0x000E; + + /** + * Hardware ID (Should be unique) + */ + public static final char HWID = 0x000E; + + 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; + } + + @Override + public void handleInterrupt(Status status) { + + int a = getCpu().getRegisterSet().getRegister("A").getValue(); + + if (a == CORE_STATUS_POLL) { + getCpu().getRegisterSet().getRegister("B").setValue(cubot.getStatus()); + } else if (a == CORE_HULL_POLL) { + getCpu().getRegisterSet().getRegister("B").setValue(cubot.getHp()); + } + } + + @Override + public char getId() { + return HWID; + } + + @Override + public BasicDBObject mongoSerialise() { + + BasicDBObject dbObject = new BasicDBObject(); + + dbObject.put("hwid", (int) HWID); + dbObject.put("cubot", cubot.getObjectId()); + + return dbObject; + } + + + public static CubotCore deserialize(DBObject obj) { + return new CubotCore((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot"))); + } +} 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 670634b..0491b35 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotShield.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotShield.java @@ -7,10 +7,10 @@ import net.simon987.server.assembly.CpuHardware; import net.simon987.server.assembly.Status; public class CubotShield extends CpuHardware { - static final char HWID = 0x000E; + static final char HWID = 0x000F; private static final int SHIELD_CHARGE = 1; - private static final int SHIELD_QUERY = 2; + private static final int SHIELD_POLL = 2; private Cubot cubot; public CubotShield(Cubot cubot) { @@ -39,7 +39,7 @@ public class CubotShield extends CpuHardware { if(a == SHIELD_CHARGE) { int b = getCpu().getRegisterSet().getRegister("B").getValue(); cubot.chargeShield(b); - } else if(a == SHIELD_QUERY) { + } else if (a == SHIELD_POLL) { int shield = cubot.getShield(); getCpu().getRegisterSet().getRegister("B").setValue(shield); } diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotStatus.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotStatus.java new file mode 100644 index 0000000..bb16666 --- /dev/null +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotStatus.java @@ -0,0 +1,18 @@ +package net.simon987.cubotplugin; + +/** + * Status of a Cubot (Special buff or debuff) + */ +public enum CubotStatus { + + DEFAULT(0), + RADIATED(1), + DAMAGED(2); + + public char val; + + CubotStatus(int val) { + this.val = (char) val; + } + +} 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 b6d8979..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,7 @@ public class HarvesterNPC extends NonPlayerCharacter { } @Override - public void onDeadCallback() { + public boolean onDeadCallback() { getWorld().decUpdatable(); @@ -56,6 +56,8 @@ public class HarvesterNPC extends NonPlayerCharacter { GameServer.INSTANCE.getEventDispatcher().dispatch( new ObjectDeathEvent(this, ID)); + + return false; } @Override 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 a176129..cde0d20 100755 --- a/Server/src/main/java/net/simon987/server/game/GameObject.java +++ b/Server/src/main/java/net/simon987/server/game/GameObject.java @@ -257,6 +257,9 @@ public abstract class GameObject implements JSONSerialisable, MongoSerialisable /** * Called before this GameObject is removed from the world - defaults to doing nothing + * @return true if 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/World.java b/Server/src/main/java/net/simon987/server/game/World.java index be7ea1f..ce9c9d4 100644 --- a/Server/src/main/java/net/simon987/server/game/World.java +++ b/Server/src/main/java/net/simon987/server/game/World.java @@ -147,9 +147,12 @@ 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); + //LogManager.LOGGER.fine("Removed object " + object + " id: " + object.getObjectId()); + } + } else if (object instanceof Updatable) { ((Updatable) object).update(); }