From eea9420192127437eb36ea97c128ce8ba03515b3 Mon Sep 17 00:00:00 2001 From: James T Date: Fri, 29 Dec 2017 22:35:02 -0800 Subject: [PATCH 01/12] HarvesterNPC should spawn a biomass in-place after they die (#33) --- .../net/simon987/npcplugin/HarvesterNPC.java | 35 +++++++++++++++++++ .../event/ObjectDeathListener.java | 22 ++++++++++++ Server/Server.iml | 19 ---------- .../server/event/ObjectDeathEvent.java | 18 ++++++++++ .../net/simon987/server/game/GameObject.java | 5 +++ .../java/net/simon987/server/game/World.java | 1 + 6 files changed, 81 insertions(+), 19 deletions(-) create mode 100644 Plugin Plant/src/main/java/net/simon987/biomassplugin/event/ObjectDeathListener.java delete mode 100644 Server/Server.iml create mode 100644 Server/src/main/java/net/simon987/server/event/ObjectDeathEvent.java 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 cccef1f..7ae17fb 100644 --- a/Plugin NPC/src/main/java/net/simon987/npcplugin/HarvesterNPC.java +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/HarvesterNPC.java @@ -1,9 +1,14 @@ package net.simon987.npcplugin; import net.simon987.server.GameServer; +import net.simon987.server.event.ObjectDeathEvent; import net.simon987.server.game.Direction; +import net.simon987.biomassplugin.BiomassBlob; +import net.simon987.server.logging.LogManager; import org.json.simple.JSONObject; +import java.lang.util.Random; + public class HarvesterNPC extends NonPlayerCharacter { public static final int ID = 10; @@ -36,6 +41,36 @@ public class HarvesterNPC extends NonPlayerCharacter { } } + @Override + public void setDead(boolean dead) { + super.setDead(dead); +// GameServer.INSTANCE.getEventDispatcher().dispatch( +// new ObjectDeathEvent((Object)this, ID)); + } + + @Override + public void onDeadCallback() { + GameServer.INSTANCE.getEventDispatcher().dispatch( + new ObjectDeathEvent((Object)this, ID)); + } + + public BiomassBlob createBiomassBlobInPlace() { + Random random = new Random(); + // random integer in range [2, 4] + int yield = random.nextInt(2) + 2; + + BiomassBlob biomassBlob = new BiomassBlob(); + biomassBlob.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId()); + // biomassBlob.setStyle(0); //TODO: set style depending on difficulty level? or random? from config? + biomassBlob.setBiomassCount(yield); + biomassBlob.setX(getX()); + biomassBlob.setY(getY()); + biomassBlob.setWorld(getWorld()); + LogManager.LOGGER.info("HarvesterNPC spawned biomass in its place"); + + return biomassBlob; + } + @Override public JSONObject serialise() { JSONObject json = super.serialise(); diff --git a/Plugin Plant/src/main/java/net/simon987/biomassplugin/event/ObjectDeathListener.java b/Plugin Plant/src/main/java/net/simon987/biomassplugin/event/ObjectDeathListener.java new file mode 100644 index 0000000..7b789a3 --- /dev/null +++ b/Plugin Plant/src/main/java/net/simon987/biomassplugin/event/ObjectDeathListener.java @@ -0,0 +1,22 @@ +package net.simon987.biomassplugin.event; + +import net.simon987.server.event.GameEvent; +import net.simon987.server.event.GameEventListener; +import net.simon987.server.event.ObjectDeathEvent; +import net.simon987.npcplugin.HarvesterNPC; + +public class ObjectDeathListener implements GameEventListener { + @Override + public Class getListenedEventType() { + return ObjectDeathEvent.getClass(); + } + + @Override + public void handle(GameEvent event) { + // a HarvesterNPC ObjectDeathEvent is received + if (((ObjectDeathEvent)event).getSourceObjectId().equals(HarvesterNPC.ID)) { + HarvesterNPC dyingHarvesterNPC = (HarvesterNPC)event.getSource(); + dyingHarvesterNPC.getWorld().getGameObjects.add(dyingHarvesterNPC.createBiomassBlobInPlace()); + } + } +} diff --git a/Server/Server.iml b/Server/Server.iml deleted file mode 100644 index 6da8947..0000000 --- a/Server/Server.iml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Server/src/main/java/net/simon987/server/event/ObjectDeathEvent.java b/Server/src/main/java/net/simon987/server/event/ObjectDeathEvent.java new file mode 100644 index 0000000..8fddae3 --- /dev/null +++ b/Server/src/main/java/net/simon987/server/event/ObjectDeathEvent.java @@ -0,0 +1,18 @@ +package net.simon987.server.event; + +/** + * Event dispatched by a GameObject who has needed callbacks on death + */ +public class ObjectDeathEvent extends GameEvent { + /** + * The GameObject type ID of object that init this event + */ + private int sourceObjectId; + + public ObjectDeathEvent(Object source, int sourceObjectId) { + setSource(source); + this.sourceObjectId = sourceObjectId; + } + + public int getSourceObjectId() { return sourceObjectId; } +} 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 20679dc..9f7fa86 100755 --- a/Server/src/main/java/net/simon987/server/game/GameObject.java +++ b/Server/src/main/java/net/simon987/server/game/GameObject.java @@ -251,4 +251,9 @@ public abstract class GameObject implements JSONSerialisable { public void setDead(boolean dead) { this.dead = dead; } + + /** + * Called before this GameObject is removed from the world - defaults to doing nothing + */ + public void onDeadCallback() { } } \ 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 60b939a..2765f2e 100644 --- a/Server/src/main/java/net/simon987/server/game/World.java +++ b/Server/src/main/java/net/simon987/server/game/World.java @@ -103,6 +103,7 @@ public class World implements JSONSerialisable { //Clean up dead objects if (object.isDead()) { gameObjects.remove(object); + object.onDeadCallback(); //LogManager.LOGGER.fine("Removed object " + object + " id: " + object.getObjectId()); } else if (object instanceof Updatable) { ((Updatable) object).update(); From 81767ed5cf6703b2a239b805421352ba295d8e3f Mon Sep 17 00:00:00 2001 From: James T Date: Sat, 30 Dec 2017 09:01:58 -0800 Subject: [PATCH 02/12] Updates for #66: reorganize and relocate some methods and calls --- .../net/simon987/npcplugin/HarvesterNPC.java | 25 ----------- .../event/ObjectDeathListener.java | 41 ++++++++++++++++++- .../java/net/simon987/server/game/World.java | 2 +- 3 files changed, 41 insertions(+), 27 deletions(-) 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 7ae17fb..eb911ab 100644 --- a/Plugin NPC/src/main/java/net/simon987/npcplugin/HarvesterNPC.java +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/HarvesterNPC.java @@ -3,7 +3,6 @@ package net.simon987.npcplugin; import net.simon987.server.GameServer; import net.simon987.server.event.ObjectDeathEvent; import net.simon987.server.game.Direction; -import net.simon987.biomassplugin.BiomassBlob; import net.simon987.server.logging.LogManager; import org.json.simple.JSONObject; @@ -41,36 +40,12 @@ public class HarvesterNPC extends NonPlayerCharacter { } } - @Override - public void setDead(boolean dead) { - super.setDead(dead); -// GameServer.INSTANCE.getEventDispatcher().dispatch( -// new ObjectDeathEvent((Object)this, ID)); - } - @Override public void onDeadCallback() { GameServer.INSTANCE.getEventDispatcher().dispatch( new ObjectDeathEvent((Object)this, ID)); } - public BiomassBlob createBiomassBlobInPlace() { - Random random = new Random(); - // random integer in range [2, 4] - int yield = random.nextInt(2) + 2; - - BiomassBlob biomassBlob = new BiomassBlob(); - biomassBlob.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId()); - // biomassBlob.setStyle(0); //TODO: set style depending on difficulty level? or random? from config? - biomassBlob.setBiomassCount(yield); - biomassBlob.setX(getX()); - biomassBlob.setY(getY()); - biomassBlob.setWorld(getWorld()); - LogManager.LOGGER.info("HarvesterNPC spawned biomass in its place"); - - return biomassBlob; - } - @Override public JSONObject serialise() { JSONObject json = super.serialise(); diff --git a/Plugin Plant/src/main/java/net/simon987/biomassplugin/event/ObjectDeathListener.java b/Plugin Plant/src/main/java/net/simon987/biomassplugin/event/ObjectDeathListener.java index 7b789a3..de20d32 100644 --- a/Plugin Plant/src/main/java/net/simon987/biomassplugin/event/ObjectDeathListener.java +++ b/Plugin Plant/src/main/java/net/simon987/biomassplugin/event/ObjectDeathListener.java @@ -1,10 +1,19 @@ package net.simon987.biomassplugin.event; +import net.simon987.server.GameServer; import net.simon987.server.event.GameEvent; import net.simon987.server.event.GameEventListener; import net.simon987.server.event.ObjectDeathEvent; import net.simon987.npcplugin.HarvesterNPC; +import net.simon987.biomassplugin.BiomassBlob; +import net.simon987.server.game.World; +import net.simon987.server.logging.LogManager; +import java.lang.Random; + +/** + * Handles ObjectDeathEvent events + */ public class ObjectDeathListener implements GameEventListener { @Override public Class getListenedEventType() { @@ -16,7 +25,37 @@ public class ObjectDeathListener implements GameEventListener { // a HarvesterNPC ObjectDeathEvent is received if (((ObjectDeathEvent)event).getSourceObjectId().equals(HarvesterNPC.ID)) { HarvesterNPC dyingHarvesterNPC = (HarvesterNPC)event.getSource(); - dyingHarvesterNPC.getWorld().getGameObjects.add(dyingHarvesterNPC.createBiomassBlobInPlace()); + + // create a new biomass + BiomassBlob newBiomassBlob = createBiomassBlobAt( + dyingHarvesterNPC.getX(), dyingHarvesterNPC.getY(), dyingHarvesterNPC.getWorld()); + // add it to the world game objects + dyingHarvesterNPC.getWorld().getGameObjects.add(newBiomassBlob); + LogManager.LOGGER.fine("Spawned biomass at (%d, %d)".format( + newBiomassBlob.getX(),newBiomassBlob.getY())); } } + + /** + * Create and return a biomass at the given x, y coordinates and in the world + * @param x x coord of biomass location + * @param y y coord of biomass location + * @param world world in which the biomass will be created in + * @return the new BiomassBlob created + */ + private BiomassBlob createBiomassBlobAt(int x, int y, World world) { + Random random = new Random(); + // random integer in range [2, 4] + int yield = random.nextInt(2) + 2; + + BiomassBlob biomassBlob = new BiomassBlob(); + biomassBlob.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId()); + // biomassBlob.setStyle(0); //TODO: set style depending on difficulty level? or random? from config? + biomassBlob.setBiomassCount(yield); + biomassBlob.setX(x); + biomassBlob.setY(y); + biomassBlob.setWorld(world); + + return biomassBlob; + } } 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 2765f2e..9f3cb5b 100644 --- a/Server/src/main/java/net/simon987/server/game/World.java +++ b/Server/src/main/java/net/simon987/server/game/World.java @@ -102,8 +102,8 @@ public class World implements JSONSerialisable { for (GameObject object : gameObjects_) { //Clean up dead objects if (object.isDead()) { - gameObjects.remove(object); object.onDeadCallback(); + gameObjects.remove(object); //LogManager.LOGGER.fine("Removed object " + object + " id: " + object.getObjectId()); } else if (object instanceof Updatable) { ((Updatable) object).update(); From 2398219fab31e860aab5b7214824abac84ddc438 Mon Sep 17 00:00:00 2001 From: James T Date: Sat, 30 Dec 2017 11:08:43 -0800 Subject: [PATCH 03/12] Update #66: rm npc plugin dependency from plant.event plugin --- .../simon987/biomassplugin/event/ObjectDeathListener.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Plugin Plant/src/main/java/net/simon987/biomassplugin/event/ObjectDeathListener.java b/Plugin Plant/src/main/java/net/simon987/biomassplugin/event/ObjectDeathListener.java index de20d32..a1dfd12 100644 --- a/Plugin Plant/src/main/java/net/simon987/biomassplugin/event/ObjectDeathListener.java +++ b/Plugin Plant/src/main/java/net/simon987/biomassplugin/event/ObjectDeathListener.java @@ -4,8 +4,8 @@ import net.simon987.server.GameServer; import net.simon987.server.event.GameEvent; import net.simon987.server.event.GameEventListener; import net.simon987.server.event.ObjectDeathEvent; -import net.simon987.npcplugin.HarvesterNPC; import net.simon987.biomassplugin.BiomassBlob; +import net.simon987.server.game.GameObject; import net.simon987.server.game.World; import net.simon987.server.logging.LogManager; @@ -23,8 +23,9 @@ public class ObjectDeathListener implements GameEventListener { @Override public void handle(GameEvent event) { // a HarvesterNPC ObjectDeathEvent is received - if (((ObjectDeathEvent)event).getSourceObjectId().equals(HarvesterNPC.ID)) { - HarvesterNPC dyingHarvesterNPC = (HarvesterNPC)event.getSource(); + // TODO: setup enum with all GameObject type IDs + if (((ObjectDeathEvent)event).getSourceObjectId().equals(10)) { + GameObject dyingHarvesterNPC = (GameObject)event.getSource(); // create a new biomass BiomassBlob newBiomassBlob = createBiomassBlobAt( From 3ded64cb16e6b2f6684002b09561a8614765d4ea Mon Sep 17 00:00:00 2001 From: James T Date: Tue, 2 Jan 2018 15:29:14 -0800 Subject: [PATCH 04/12] Update #66: add newest Server/Server.iml file --- Server/Server.iml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Server/Server.iml diff --git a/Server/Server.iml b/Server/Server.iml new file mode 100644 index 0000000..52af955 --- /dev/null +++ b/Server/Server.iml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + From 5a994fe43715c1cfcbffac4a8baf41cb68b31fe3 Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 3 Jan 2018 18:36:18 +1100 Subject: [PATCH 05/12] Update to address issue #101 --- .../java/net/simon987/cubotplugin/CubotComPort.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotComPort.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotComPort.java index 237da0d..b62cb68 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotComPort.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotComPort.java @@ -18,10 +18,11 @@ public class CubotComPort extends CpuHardware { private Cubot cubot; - private static final int COMPORT_SELF_CLEAR = 0; + private static final int COMPORT_BUFFER_CLEAR = 0; private static final int COMPORT_POLL = 1; private static final int COMPORT_FRONT_PORT_OUT = 2; private static final int COMPORT_SELF_OUT = 3; + private static final int COMPORT_CONSOLE_CLEAR = 4; public CubotComPort(Cubot cubot) { this.cubot = cubot; @@ -34,11 +35,14 @@ public class CubotComPort extends CpuHardware { int a = getCpu().getRegisterSet().getRegister("A").getValue(); - if (a == COMPORT_SELF_CLEAR) { + if (a == COMPORT_BUFFER_CLEAR) { cubot.getConsoleMessagesBuffer().clear(); + + } else if (a == COMPORT_CONSOLE_CLEAR) { + cubot.setConsoleMode(Cubot.ConsoleMode.CLEAR); - + } else if (a == COMPORT_POLL) { if (cubot.spendEnergy(4)) { From 7bb5f68ff24c18653a68f4c52e64f90605e0cbd2 Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 3 Jan 2018 22:24:32 +1100 Subject: [PATCH 06/12] Edited for style conformance --- .../src/main/java/net/simon987/cubotplugin/CubotComPort.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotComPort.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotComPort.java index b62cb68..459ac77 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotComPort.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotComPort.java @@ -42,7 +42,7 @@ public class CubotComPort extends CpuHardware { } else if (a == COMPORT_CONSOLE_CLEAR) { cubot.setConsoleMode(Cubot.ConsoleMode.CLEAR); - + } else if (a == COMPORT_POLL) { if (cubot.spendEnergy(4)) { From cfaf46ad5212de2e20798371b8c7c0fa8e343fe0 Mon Sep 17 00:00:00 2001 From: sg495 Date: Wed, 3 Jan 2018 17:59:46 +0100 Subject: [PATCH 07/12] Added installation instructions for Windows (tested on Windows 10). --- README.md | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fb75a06..96dea1f 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,38 @@ cd target java -jar server-1.2a.jar ``` -## Windows -Coming eventually... +## Windows (tested on 10) + +Installation instructions: +1. Download the JDK from [here](http://www.oracle.com/technetwork/java/javase/downloads/index.html). +Install the JDK and update your PATH and JAVA_HOME enviroment variables. +2. Download Maven from [here](https://maven.apache.org/). +Install Maven (following the README) and update your PATH enviroment variable. +3. Download Mongo DB Community from [here](https://www.mongodb.com/download-center#community). +Install Mongo DB following the instructions [here](https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/). +Update your PATH enviroment variable. + +Building instructions: +```batch +:: Builds the server +cd Much-Assembly-Required +mvn package +``` + +Running instructions: +1. In one Command Prompt window, run Mongo DB: +```batch +:: Runs Mongo DB +mongod +``` +2. In a second Command Prompt window, run the MAR server: +```batch +:: Runs the MAR server +cd Much-Assembly-Required\target +java -jar server-1.2a.jar +``` + + ## Docker ### Requirements From 58a378d77fcd5099ad83d049b0870ae39e9132ad Mon Sep 17 00:00:00 2001 From: sg495 Date: Wed, 3 Jan 2018 20:14:31 +0100 Subject: [PATCH 08/12] Updated instructions for Windows installation and running. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 96dea1f..0affdd2 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ cd target java -jar server-1.2a.jar ``` -## Windows (tested on 10) +## Windows (tested on Windows 10) Installation instructions: 1. Download the JDK from [here](http://www.oracle.com/technetwork/java/javase/downloads/index.html). @@ -63,7 +63,7 @@ mongod cd Much-Assembly-Required\target java -jar server-1.2a.jar ``` - +3. Run the frontend, following the instructions that you can find [here](https://github.com/simon987/Much-Assembly-Required-Frontend). ## Docker From 9b908a5310045336bdcd810d98a3324aca4f496f Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 3 Jan 2018 19:19:19 -0500 Subject: [PATCH 09/12] Biomass count on NPC death is loaded from config --- .../net/simon987/npcplugin/HarvesterNPC.java | 2 -- .../simon987/biomassplugin/BiomassPlugin.java | 2 ++ .../event/ObjectDeathListener.java | 28 +++++++++++-------- Server/src/main/resources/config.properties | 2 ++ 4 files changed, 20 insertions(+), 14 deletions(-) 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 2723ad7..fc01e42 100644 --- a/Plugin NPC/src/main/java/net/simon987/npcplugin/HarvesterNPC.java +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/HarvesterNPC.java @@ -5,10 +5,8 @@ import com.mongodb.DBObject; import net.simon987.server.GameServer; import net.simon987.server.event.ObjectDeathEvent; import net.simon987.server.game.Direction; -import net.simon987.server.logging.LogManager; import org.json.simple.JSONObject; -import java.lang.util.Random; public class HarvesterNPC extends NonPlayerCharacter { diff --git a/Plugin Plant/src/main/java/net/simon987/biomassplugin/BiomassPlugin.java b/Plugin Plant/src/main/java/net/simon987/biomassplugin/BiomassPlugin.java index 6465720..fe5ab0a 100644 --- a/Plugin Plant/src/main/java/net/simon987/biomassplugin/BiomassPlugin.java +++ b/Plugin Plant/src/main/java/net/simon987/biomassplugin/BiomassPlugin.java @@ -1,6 +1,7 @@ package net.simon987.biomassplugin; import com.mongodb.DBObject; +import net.simon987.biomassplugin.event.ObjectDeathListener; import net.simon987.biomassplugin.event.WorldCreationListener; import net.simon987.biomassplugin.event.WorldUpdateListener; import net.simon987.server.ServerConfiguration; @@ -16,6 +17,7 @@ public class BiomassPlugin extends ServerPlugin implements GameObjectDeserialize public void init(ServerConfiguration config) { listeners.add(new WorldCreationListener()); listeners.add(new WorldUpdateListener(config)); + listeners.add(new ObjectDeathListener(config)); LogManager.LOGGER.info("Initialised Biomass plugin"); } diff --git a/Plugin Plant/src/main/java/net/simon987/biomassplugin/event/ObjectDeathListener.java b/Plugin Plant/src/main/java/net/simon987/biomassplugin/event/ObjectDeathListener.java index a1dfd12..036352e 100644 --- a/Plugin Plant/src/main/java/net/simon987/biomassplugin/event/ObjectDeathListener.java +++ b/Plugin Plant/src/main/java/net/simon987/biomassplugin/event/ObjectDeathListener.java @@ -1,39 +1,46 @@ package net.simon987.biomassplugin.event; +import net.simon987.biomassplugin.BiomassBlob; 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.ObjectDeathEvent; -import net.simon987.biomassplugin.BiomassBlob; import net.simon987.server.game.GameObject; import net.simon987.server.game.World; import net.simon987.server.logging.LogManager; -import java.lang.Random; - /** * Handles ObjectDeathEvent events */ public class ObjectDeathListener implements GameEventListener { + + private int biomassDropCount; + + public ObjectDeathListener(ServerConfiguration config) { + biomassDropCount = config.getInt("harvester_biomass_drop_count"); + + } + @Override public Class getListenedEventType() { - return ObjectDeathEvent.getClass(); + return ObjectDeathEvent.class; } @Override public void handle(GameEvent event) { // a HarvesterNPC ObjectDeathEvent is received // TODO: setup enum with all GameObject type IDs - if (((ObjectDeathEvent)event).getSourceObjectId().equals(10)) { + if (((ObjectDeathEvent) event).getSourceObjectId() == 10) { GameObject dyingHarvesterNPC = (GameObject)event.getSource(); // create a new biomass BiomassBlob newBiomassBlob = createBiomassBlobAt( dyingHarvesterNPC.getX(), dyingHarvesterNPC.getY(), dyingHarvesterNPC.getWorld()); // add it to the world game objects - dyingHarvesterNPC.getWorld().getGameObjects.add(newBiomassBlob); - LogManager.LOGGER.fine("Spawned biomass at (%d, %d)".format( - newBiomassBlob.getX(),newBiomassBlob.getY())); + dyingHarvesterNPC.getWorld().getGameObjects().add(newBiomassBlob); + LogManager.LOGGER.fine("Spawned biomass at (" + newBiomassBlob.getX() + + ", " + newBiomassBlob.getY() + ")"); } } @@ -45,14 +52,11 @@ public class ObjectDeathListener implements GameEventListener { * @return the new BiomassBlob created */ private BiomassBlob createBiomassBlobAt(int x, int y, World world) { - Random random = new Random(); - // random integer in range [2, 4] - int yield = random.nextInt(2) + 2; BiomassBlob biomassBlob = new BiomassBlob(); biomassBlob.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId()); // biomassBlob.setStyle(0); //TODO: set style depending on difficulty level? or random? from config? - biomassBlob.setBiomassCount(yield); + biomassBlob.setBiomassCount(biomassDropCount); biomassBlob.setX(x); biomassBlob.setY(y); biomassBlob.setWorld(world); diff --git a/Server/src/main/resources/config.properties b/Server/src/main/resources/config.properties index c26b4d3..1c925dc 100644 --- a/Server/src/main/resources/config.properties +++ b/Server/src/main/resources/config.properties @@ -62,6 +62,8 @@ factory_max_npc_count=16 harvester_hp_max=100 # Harvester hp regeneration per tick harvester_regen=5 +# Number of biomass units dropped on death +harvester_biomass_drop_count=8 # ---------------------------------------------- # Minimum center point count for the WorldGenerator wg_centerPointCountMin=5 From 9bc3cbf4ceabe47bcfe46ab58d83e1d4609efbce Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 3 Jan 2018 19:22:45 -0500 Subject: [PATCH 10/12] Remove NPC reference to Factory on death --- .../src/main/java/net/simon987/npcplugin/HarvesterNPC.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 fc01e42..396a8e1 100644 --- a/Plugin NPC/src/main/java/net/simon987/npcplugin/HarvesterNPC.java +++ b/Plugin NPC/src/main/java/net/simon987/npcplugin/HarvesterNPC.java @@ -41,15 +41,17 @@ public class HarvesterNPC extends NonPlayerCharacter { //Self-destroy when age limit is reached if (getAge() >= NonPlayerCharacter.LIFETIME) { setDead(true); - getFactory().getNpcs().remove(this); } } } @Override public void onDeadCallback() { + + getFactory().getNpcs().remove(this); + GameServer.INSTANCE.getEventDispatcher().dispatch( - new ObjectDeathEvent((Object)this, ID)); + new ObjectDeathEvent(this, ID)); } @Override From 1a39cf845483e5601fb22ff8882045e7fd9b20a0 Mon Sep 17 00:00:00 2001 From: Simon Fortier Date: Wed, 3 Jan 2018 20:07:48 -0500 Subject: [PATCH 11/12] Create CONTRIBUTING.md --- CONTRIBUTING.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..ba30ee1 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,19 @@ +## General guide + +[Collaboration guide](https://github.com/simon987/Much-Assembly-Required/wiki/Collaboration-Guide) + +## Before creating a pull request + +Here small unordered list of guidelines to read before creating a pull request +- Use java <= 1.8 features +- Please follow [Google's Java style guide](https://google.github.io/styleguide/javaguide.html) +- Constants (e.g. the energy cost of an in-game action) should be loaded from config.properties +- The project is separated into multiple modules, the `Server` module and its plugins. Plugins should +not depend on another plugin to compile or to run. +(e.g. NPC plugin shouldn't import `net.simon987.biomassplugin` ) +- Use `Logmanager.LOGGER` to log messages to the console. Use `.fine()` for debugging messages and `.info()` for +info for more important messages +that are not too frequently used. +- Do not submit a pull request for a new feature that has not been approved +by [simon987](https://github.com/simon987) in an Issue beforehand +- Please state what tests have been performed in the pull request From 17359161fd10f082de4922fe5fdefea6b2701f6a Mon Sep 17 00:00:00 2001 From: Josh Date: Thu, 4 Jan 2018 17:49:02 +1100 Subject: [PATCH 12/12] Update for issue #10 Removes slow and fast gather and retains gather for 1 tick. --- .../src/main/java/net/simon987/cubotplugin/CubotDrill.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotDrill.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotDrill.java index e8e749f..975deab 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotDrill.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/CubotDrill.java @@ -18,8 +18,7 @@ public class CubotDrill extends CpuHardware { public static final int DEFAULT_ADDRESS = 5; private static final int DRILL_POLL = 1; - private static final int DRILL_GATHER_SLOW = 2; - private static final int DRILL_GATHER_FAST = 3; + private static final int DRILL_GATHER = 2; // simplified gather private Cubot cubot; @@ -40,7 +39,7 @@ public class CubotDrill extends CpuHardware { getCpu().getRegisterSet().getRegister("B").setValue(0); - } else if (a == DRILL_GATHER_SLOW || a == DRILL_GATHER_FAST) { + } else if (a == DRILL_GATHER) { if (cubot.spendEnergy(1400)) { if (cubot.getCurrentAction() == Action.IDLE) {