Merge pull request #66 from jtara1/master

HarvesterNPC should spawn a biomass in-place after they die. Fixes #33
This commit is contained in:
Simon Fortier
2018-01-03 19:00:55 -05:00
committed by GitHub
6 changed files with 97 additions and 1 deletions

View File

@@ -19,4 +19,4 @@
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" />
</component>
</module>
</module>

View File

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

View File

@@ -254,4 +254,9 @@ public abstract class GameObject implements JSONSerialisable, MongoSerialisable
public void setDead(boolean dead) {
this.dead = dead;
}
/**
* Called before this GameObject is removed from the world - defaults to doing nothing
*/
public void onDeadCallback() { }
}

View File

@@ -104,6 +104,7 @@ public class World implements MongoSerialisable {
for (GameObject object : gameObjects_) {
//Clean up dead objects
if (object.isDead()) {
object.onDeadCallback();
gameObjects.remove(object);
//LogManager.LOGGER.fine("Removed object " + object + " id: " + object.getObjectId());
} else if (object instanceof Updatable) {