mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-19 18:46:43 +00:00
Biomass count on NPC death is loaded from config
This commit is contained in:
parent
8ceeca564a
commit
9b908a5310
@ -5,10 +5,8 @@ import com.mongodb.DBObject;
|
|||||||
import net.simon987.server.GameServer;
|
import net.simon987.server.GameServer;
|
||||||
import net.simon987.server.event.ObjectDeathEvent;
|
import net.simon987.server.event.ObjectDeathEvent;
|
||||||
import net.simon987.server.game.Direction;
|
import net.simon987.server.game.Direction;
|
||||||
import net.simon987.server.logging.LogManager;
|
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
import java.lang.util.Random;
|
|
||||||
|
|
||||||
public class HarvesterNPC extends NonPlayerCharacter {
|
public class HarvesterNPC extends NonPlayerCharacter {
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.simon987.biomassplugin;
|
package net.simon987.biomassplugin;
|
||||||
|
|
||||||
import com.mongodb.DBObject;
|
import com.mongodb.DBObject;
|
||||||
|
import net.simon987.biomassplugin.event.ObjectDeathListener;
|
||||||
import net.simon987.biomassplugin.event.WorldCreationListener;
|
import net.simon987.biomassplugin.event.WorldCreationListener;
|
||||||
import net.simon987.biomassplugin.event.WorldUpdateListener;
|
import net.simon987.biomassplugin.event.WorldUpdateListener;
|
||||||
import net.simon987.server.ServerConfiguration;
|
import net.simon987.server.ServerConfiguration;
|
||||||
@ -16,6 +17,7 @@ public class BiomassPlugin extends ServerPlugin implements GameObjectDeserialize
|
|||||||
public void init(ServerConfiguration config) {
|
public void init(ServerConfiguration config) {
|
||||||
listeners.add(new WorldCreationListener());
|
listeners.add(new WorldCreationListener());
|
||||||
listeners.add(new WorldUpdateListener(config));
|
listeners.add(new WorldUpdateListener(config));
|
||||||
|
listeners.add(new ObjectDeathListener(config));
|
||||||
|
|
||||||
LogManager.LOGGER.info("Initialised Biomass plugin");
|
LogManager.LOGGER.info("Initialised Biomass plugin");
|
||||||
}
|
}
|
||||||
|
@ -1,39 +1,46 @@
|
|||||||
package net.simon987.biomassplugin.event;
|
package net.simon987.biomassplugin.event;
|
||||||
|
|
||||||
|
import net.simon987.biomassplugin.BiomassBlob;
|
||||||
import net.simon987.server.GameServer;
|
import net.simon987.server.GameServer;
|
||||||
|
import net.simon987.server.ServerConfiguration;
|
||||||
import net.simon987.server.event.GameEvent;
|
import net.simon987.server.event.GameEvent;
|
||||||
import net.simon987.server.event.GameEventListener;
|
import net.simon987.server.event.GameEventListener;
|
||||||
import net.simon987.server.event.ObjectDeathEvent;
|
import net.simon987.server.event.ObjectDeathEvent;
|
||||||
import net.simon987.biomassplugin.BiomassBlob;
|
|
||||||
import net.simon987.server.game.GameObject;
|
import net.simon987.server.game.GameObject;
|
||||||
import net.simon987.server.game.World;
|
import net.simon987.server.game.World;
|
||||||
import net.simon987.server.logging.LogManager;
|
import net.simon987.server.logging.LogManager;
|
||||||
|
|
||||||
import java.lang.Random;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles ObjectDeathEvent events
|
* Handles ObjectDeathEvent events
|
||||||
*/
|
*/
|
||||||
public class ObjectDeathListener implements GameEventListener {
|
public class ObjectDeathListener implements GameEventListener {
|
||||||
|
|
||||||
|
private int biomassDropCount;
|
||||||
|
|
||||||
|
public ObjectDeathListener(ServerConfiguration config) {
|
||||||
|
biomassDropCount = config.getInt("harvester_biomass_drop_count");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class getListenedEventType() {
|
public Class getListenedEventType() {
|
||||||
return ObjectDeathEvent.getClass();
|
return ObjectDeathEvent.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(GameEvent event) {
|
public void handle(GameEvent event) {
|
||||||
// a HarvesterNPC ObjectDeathEvent is received
|
// a HarvesterNPC ObjectDeathEvent is received
|
||||||
// TODO: setup enum with all GameObject type IDs
|
// TODO: setup enum with all GameObject type IDs
|
||||||
if (((ObjectDeathEvent)event).getSourceObjectId().equals(10)) {
|
if (((ObjectDeathEvent) event).getSourceObjectId() == 10) {
|
||||||
GameObject dyingHarvesterNPC = (GameObject)event.getSource();
|
GameObject dyingHarvesterNPC = (GameObject)event.getSource();
|
||||||
|
|
||||||
// create a new biomass
|
// create a new biomass
|
||||||
BiomassBlob newBiomassBlob = createBiomassBlobAt(
|
BiomassBlob newBiomassBlob = createBiomassBlobAt(
|
||||||
dyingHarvesterNPC.getX(), dyingHarvesterNPC.getY(), dyingHarvesterNPC.getWorld());
|
dyingHarvesterNPC.getX(), dyingHarvesterNPC.getY(), dyingHarvesterNPC.getWorld());
|
||||||
// add it to the world game objects
|
// add it to the world game objects
|
||||||
dyingHarvesterNPC.getWorld().getGameObjects.add(newBiomassBlob);
|
dyingHarvesterNPC.getWorld().getGameObjects().add(newBiomassBlob);
|
||||||
LogManager.LOGGER.fine("Spawned biomass at (%d, %d)".format(
|
LogManager.LOGGER.fine("Spawned biomass at (" + newBiomassBlob.getX() +
|
||||||
newBiomassBlob.getX(),newBiomassBlob.getY()));
|
", " + newBiomassBlob.getY() + ")");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,14 +52,11 @@ public class ObjectDeathListener implements GameEventListener {
|
|||||||
* @return the new BiomassBlob created
|
* @return the new BiomassBlob created
|
||||||
*/
|
*/
|
||||||
private BiomassBlob createBiomassBlobAt(int x, int y, World world) {
|
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 biomassBlob = new BiomassBlob();
|
||||||
biomassBlob.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId());
|
biomassBlob.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId());
|
||||||
// biomassBlob.setStyle(0); //TODO: set style depending on difficulty level? or random? from config?
|
// biomassBlob.setStyle(0); //TODO: set style depending on difficulty level? or random? from config?
|
||||||
biomassBlob.setBiomassCount(yield);
|
biomassBlob.setBiomassCount(biomassDropCount);
|
||||||
biomassBlob.setX(x);
|
biomassBlob.setX(x);
|
||||||
biomassBlob.setY(y);
|
biomassBlob.setY(y);
|
||||||
biomassBlob.setWorld(world);
|
biomassBlob.setWorld(world);
|
||||||
|
@ -62,6 +62,8 @@ factory_max_npc_count=16
|
|||||||
harvester_hp_max=100
|
harvester_hp_max=100
|
||||||
# Harvester hp regeneration per tick
|
# Harvester hp regeneration per tick
|
||||||
harvester_regen=5
|
harvester_regen=5
|
||||||
|
# Number of biomass units dropped on death
|
||||||
|
harvester_biomass_drop_count=8
|
||||||
# ----------------------------------------------
|
# ----------------------------------------------
|
||||||
# Minimum center point count for the WorldGenerator
|
# Minimum center point count for the WorldGenerator
|
||||||
wg_centerPointCountMin=5
|
wg_centerPointCountMin=5
|
||||||
|
Loading…
x
Reference in New Issue
Block a user