mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-12-13 14:49:03 +00:00
Refactor: changed the way game objects and cpu hardware are saved/loaded from the database #151
This commit is contained in:
@@ -2,11 +2,10 @@ package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.Util;
|
||||
import net.simon987.server.game.Attackable;
|
||||
import net.simon987.server.game.GameObject;
|
||||
import net.simon987.server.game.Rechargeable;
|
||||
import net.simon987.server.game.Updatable;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import net.simon987.server.game.objects.Attackable;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.objects.Rechargeable;
|
||||
import net.simon987.server.game.objects.Updatable;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@@ -17,8 +16,6 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public class ElectricBox extends GameObject implements Updatable, Attackable {
|
||||
|
||||
public static final int ID = 7;
|
||||
|
||||
/**
|
||||
* Hit points
|
||||
*/
|
||||
@@ -42,8 +39,12 @@ public class ElectricBox extends GameObject implements Updatable, Attackable {
|
||||
private ArrayList<Attackable> nearObjects = new ArrayList<>();
|
||||
|
||||
public ElectricBox() {
|
||||
hp = maxHp;
|
||||
}
|
||||
|
||||
this.hp = maxHp;
|
||||
public ElectricBox(Document document) {
|
||||
super(document);
|
||||
hp = (int) document.get("hp");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,7 +93,6 @@ public class ElectricBox extends GameObject implements Updatable, Attackable {
|
||||
//YOU ARE DEAD
|
||||
if (hp <= 0) {
|
||||
setDead(true);
|
||||
LogManager.LOGGER.severe("BOX DEAD");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,13 +136,9 @@ public class ElectricBox extends GameObject implements Updatable, Attackable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject serialise() {
|
||||
JSONObject json = new JSONObject();
|
||||
public JSONObject jsonSerialise() {
|
||||
JSONObject json = super.jsonSerialise();
|
||||
|
||||
json.put("i", getObjectId());
|
||||
json.put("x", getX());
|
||||
json.put("y", getY());
|
||||
json.put("t", ID);
|
||||
json.put("hp", hp);
|
||||
|
||||
return json;
|
||||
@@ -150,28 +146,13 @@ public class ElectricBox extends GameObject implements Updatable, Attackable {
|
||||
|
||||
@Override
|
||||
public Document mongoSerialise() {
|
||||
Document dbObject = new Document();
|
||||
Document dbObject = super.mongoSerialise();
|
||||
|
||||
dbObject.put("i", getObjectId());
|
||||
dbObject.put("x", getX());
|
||||
dbObject.put("y", getY());
|
||||
dbObject.put("t", ID);
|
||||
dbObject.put("hp", getHp());
|
||||
|
||||
return dbObject;
|
||||
}
|
||||
|
||||
public static ElectricBox deserialize(Document obj) {
|
||||
|
||||
ElectricBox electricBox = new ElectricBox();
|
||||
electricBox.setHp((int) obj.get("hp"));
|
||||
electricBox.setObjectId((long) obj.get("i"));
|
||||
electricBox.setX((int) obj.get("x"));
|
||||
electricBox.setY((int) obj.get("y"));
|
||||
|
||||
return electricBox;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onDeadCallback() {
|
||||
getWorld().decUpdatable();
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.GameObject;
|
||||
import net.simon987.server.game.Updatable;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.objects.Updatable;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
@@ -16,7 +15,6 @@ import java.util.List;
|
||||
public class Factory extends GameObject implements Updatable {
|
||||
|
||||
private static final int MAP_INFO = 0x0200;
|
||||
static final int ID = 3;
|
||||
|
||||
/**
|
||||
* Maximum number of NonPlayerCharacters assigned to this Factory
|
||||
@@ -49,6 +47,19 @@ public class Factory extends GameObject implements Updatable {
|
||||
*/
|
||||
private boolean initialised = false;
|
||||
|
||||
public Factory() {
|
||||
}
|
||||
|
||||
public Factory(Document document) {
|
||||
super(document);
|
||||
|
||||
setObjectId((long) document.get("i"));
|
||||
setX((int) document.get("x"));
|
||||
setY((int) document.get("y"));
|
||||
|
||||
tmpNpcArray = ((ArrayList) document.get("tmpNpcArray")).toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getMapInfo() {
|
||||
return MAP_INFO;
|
||||
@@ -118,27 +129,9 @@ public class Factory extends GameObject implements Updatable {
|
||||
return (x == getX() + 1 || x == getX()) && (y == getY() + 1 || y == getY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject serialise() {
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
|
||||
json.put("i", getObjectId());
|
||||
json.put("x", getX());
|
||||
json.put("y", getY());
|
||||
json.put("t", ID);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document mongoSerialise() {
|
||||
Document dbObject = new Document();
|
||||
|
||||
dbObject.put("i", getObjectId());
|
||||
dbObject.put("x", getX());
|
||||
dbObject.put("y", getY());
|
||||
dbObject.put("t", ID);
|
||||
Document dbObject = super.mongoSerialise();
|
||||
|
||||
List<Long> tmpNpcArray = new ArrayList<>(npcs.size());
|
||||
|
||||
@@ -151,18 +144,6 @@ public class Factory extends GameObject implements Updatable {
|
||||
return dbObject;
|
||||
}
|
||||
|
||||
public static Factory deserialise(Document obj) {
|
||||
|
||||
Factory factory = new Factory();
|
||||
factory.setObjectId((long) obj.get("i"));
|
||||
factory.setX((int) obj.get("x"));
|
||||
factory.setY((int) obj.get("y"));
|
||||
|
||||
factory.tmpNpcArray = ((ArrayList) obj.get("tmpNpcArray")).toArray();
|
||||
|
||||
return factory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first non-blocked tile that is directly adjacent to the factory, starting from the north-east corner
|
||||
* going clockwise.
|
||||
|
||||
@@ -2,9 +2,9 @@ package net.simon987.npcplugin;
|
||||
|
||||
|
||||
import net.simon987.server.assembly.Util;
|
||||
import net.simon987.server.game.Direction;
|
||||
import net.simon987.server.game.GameObject;
|
||||
import net.simon987.server.game.InventoryHolder;
|
||||
import net.simon987.server.game.objects.Direction;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.objects.InventoryHolder;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -105,8 +105,5 @@ public class HarvestTask extends NPCTask {
|
||||
} else {
|
||||
pause--;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,18 +2,13 @@ package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.event.ObjectDeathEvent;
|
||||
import net.simon987.server.game.Direction;
|
||||
import net.simon987.server.game.objects.Direction;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
|
||||
public class HarvesterNPC extends NonPlayerCharacter {
|
||||
|
||||
public static final int ID = 10;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static final int MAX_HEALTH = GameServer.INSTANCE.getConfig().getInt("harvester_hp_max");
|
||||
public static final int HEAL_RATE = GameServer.INSTANCE.getConfig().getInt("harvester_regen");
|
||||
|
||||
@@ -26,6 +21,12 @@ public class HarvesterNPC extends NonPlayerCharacter {
|
||||
setHealRate(HEAL_RATE);
|
||||
}
|
||||
|
||||
public HarvesterNPC(Document document) {
|
||||
super(document);
|
||||
|
||||
setDirection(Direction.getDirection(document.getInteger("direction")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
|
||||
@@ -56,53 +57,30 @@ public class HarvesterNPC extends NonPlayerCharacter {
|
||||
getFactory().getNpcs().remove(this);
|
||||
}
|
||||
|
||||
GameServer.INSTANCE.getEventDispatcher().dispatch(
|
||||
new ObjectDeathEvent(this, ID));
|
||||
GameServer.INSTANCE.getEventDispatcher().dispatch(new ObjectDeathEvent(this));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject serialise() {
|
||||
JSONObject json = super.serialise();
|
||||
public JSONObject jsonSerialise() {
|
||||
JSONObject json = super.jsonSerialise();
|
||||
|
||||
json.put("i", getObjectId());
|
||||
json.put("x", getX());
|
||||
json.put("y", getY());
|
||||
json.put("direction", getDirection().ordinal());
|
||||
json.put("hp", getHp());
|
||||
json.put("energy", energy);
|
||||
json.put("action", getAction().ordinal());
|
||||
json.put("t", ID);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document mongoSerialise() {
|
||||
Document dbObject = new Document();
|
||||
Document dbObject = super.mongoSerialise();
|
||||
|
||||
dbObject.put("i", getObjectId());
|
||||
dbObject.put("x", getX());
|
||||
dbObject.put("y", getY());
|
||||
dbObject.put("direction", getDirection().ordinal());
|
||||
dbObject.put("hp", getHp());
|
||||
dbObject.put("action", getAction().ordinal());
|
||||
dbObject.put("t", ID);
|
||||
|
||||
return dbObject;
|
||||
}
|
||||
|
||||
public static HarvesterNPC deserialize(Document obj) {
|
||||
|
||||
HarvesterNPC npc = new HarvesterNPC();
|
||||
npc.setObjectId((long) obj.get("i"));
|
||||
npc.setX((int) obj.get("x"));
|
||||
npc.setY((int) obj.get("y"));
|
||||
npc.setHp((int) obj.get("hp"));
|
||||
npc.setDirection(Direction.getDirection((int) obj.get("direction")));
|
||||
|
||||
return npc;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@ package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.Util;
|
||||
import net.simon987.server.game.*;
|
||||
import net.simon987.server.game.objects.*;
|
||||
import net.simon987.server.game.pathfinding.Node;
|
||||
import net.simon987.server.game.pathfinding.Pathfinder;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -30,11 +31,6 @@ public abstract class NonPlayerCharacter extends GameObject implements Updatable
|
||||
public static final int HP_MAX_DEFAULT = 100;
|
||||
public static final int HP_REGEN_RATE_DEFAULT = 0;
|
||||
|
||||
/**
|
||||
* Currently unused
|
||||
*/
|
||||
int energy;
|
||||
|
||||
/**
|
||||
* Current task
|
||||
*/
|
||||
@@ -76,6 +72,17 @@ public abstract class NonPlayerCharacter extends GameObject implements Updatable
|
||||
*/
|
||||
private int maxHp = HP_MAX_DEFAULT;
|
||||
|
||||
public NonPlayerCharacter() {
|
||||
|
||||
}
|
||||
|
||||
public NonPlayerCharacter(Document document) {
|
||||
super(document);
|
||||
|
||||
hp = document.getInteger("hp");
|
||||
setDirection(Direction.getDirection(document.getInteger("direction")));
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getMapInfo() {
|
||||
return MAP_INFO;
|
||||
|
||||
@@ -4,17 +4,13 @@ import net.simon987.npcplugin.event.CpuInitialisationListener;
|
||||
import net.simon987.npcplugin.event.VaultWorldUpdateListener;
|
||||
import net.simon987.npcplugin.event.WorldCreationListener;
|
||||
import net.simon987.server.ServerConfiguration;
|
||||
import net.simon987.server.assembly.CpuHardware;
|
||||
import net.simon987.server.game.GameObject;
|
||||
import net.simon987.server.io.CpuHardwareDeserializer;
|
||||
import net.simon987.server.io.GameObjectDeserializer;
|
||||
import net.simon987.server.game.objects.GameRegistry;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import net.simon987.server.plugin.ServerPlugin;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class NpcPlugin extends ServerPlugin implements GameObjectDeserializer, CpuHardwareDeserializer {
|
||||
public class NpcPlugin extends ServerPlugin {
|
||||
|
||||
/**
|
||||
* Radio tower cache
|
||||
@@ -22,55 +18,28 @@ public class NpcPlugin extends ServerPlugin implements GameObjectDeserializer, C
|
||||
private static ArrayList<RadioTower> radioTowers;
|
||||
|
||||
@Override
|
||||
public void init(ServerConfiguration configuration) {
|
||||
public void init(ServerConfiguration configuration, GameRegistry registry) {
|
||||
|
||||
listeners.add(new WorldCreationListener());
|
||||
listeners.add(new CpuInitialisationListener());
|
||||
listeners.add(new VaultWorldUpdateListener(configuration));
|
||||
|
||||
registry.registerGameObject(HarvesterNPC.class);
|
||||
registry.registerGameObject(Factory.class);
|
||||
registry.registerGameObject(RadioTower.class);
|
||||
registry.registerGameObject(VaultDoor.class);
|
||||
registry.registerGameObject(Obstacle.class);
|
||||
registry.registerGameObject(ElectricBox.class);
|
||||
registry.registerGameObject(Portal.class);
|
||||
registry.registerGameObject(VaultExitPortal.class);
|
||||
|
||||
registry.registerHardware(RadioReceiverHardware.class);
|
||||
|
||||
radioTowers = new ArrayList<>(32);
|
||||
|
||||
LogManager.LOGGER.info("Initialised NPC plugin");
|
||||
}
|
||||
|
||||
@Override
|
||||
public GameObject deserializeObject(Document obj) {
|
||||
|
||||
int objType = (int) obj.get("t");
|
||||
|
||||
if (objType == HarvesterNPC.ID) {
|
||||
return HarvesterNPC.deserialize(obj);
|
||||
} else if (objType == Factory.ID) {
|
||||
return Factory.deserialise(obj);
|
||||
} else if (objType == RadioTower.ID) {
|
||||
return RadioTower.deserialize(obj);
|
||||
} else if (objType == VaultDoor.ID) {
|
||||
return VaultDoor.deserialize(obj);
|
||||
} else if (objType == Obstacle.ID) {
|
||||
return Obstacle.deserialize(obj);
|
||||
} else if (objType == ElectricBox.ID) {
|
||||
return ElectricBox.deserialize(obj);
|
||||
} else if (objType == Portal.ID) {
|
||||
return Portal.deserialize(obj);
|
||||
} else if (objType == VaultExitPortal.ID) {
|
||||
return VaultExitPortal.deserialize(obj);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CpuHardware deserializeHardware(Document obj) {
|
||||
int hwid = (int) obj.get("hwid");
|
||||
|
||||
switch (hwid) {
|
||||
case RadioReceiverHardware.HWID:
|
||||
return RadioReceiverHardware.deserialize(obj);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ArrayList<RadioTower> getRadioTowers() {
|
||||
return radioTowers;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.server.game.Attackable;
|
||||
import net.simon987.server.game.GameObject;
|
||||
import net.simon987.server.game.objects.Attackable;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.json.simple.JSONObject;
|
||||
*/
|
||||
public class Obstacle extends GameObject implements Attackable {
|
||||
|
||||
public static final int ID = 6;
|
||||
public static final int MAP_INFO = 0x0400;
|
||||
|
||||
/**
|
||||
@@ -33,6 +32,10 @@ public class Obstacle extends GameObject implements Attackable {
|
||||
this.maxHp = hp;
|
||||
}
|
||||
|
||||
public Obstacle(Document document) {
|
||||
style = document.getInteger("style");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHealRate(int hp) {
|
||||
//No op
|
||||
@@ -89,12 +92,8 @@ public class Obstacle extends GameObject implements Attackable {
|
||||
|
||||
@Override
|
||||
public Document mongoSerialise() {
|
||||
Document dbObject = new Document();
|
||||
Document dbObject = super.mongoSerialise();
|
||||
|
||||
dbObject.put("i", getObjectId());
|
||||
dbObject.put("x", getX());
|
||||
dbObject.put("y", getY());
|
||||
dbObject.put("t", ID);
|
||||
dbObject.put("hp", hp);
|
||||
dbObject.put("style", style);
|
||||
|
||||
@@ -102,27 +101,12 @@ public class Obstacle extends GameObject implements Attackable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject serialise() {
|
||||
JSONObject json = new JSONObject();
|
||||
public JSONObject jsonSerialise() {
|
||||
JSONObject json = super.jsonSerialise();
|
||||
|
||||
json.put("i", getObjectId());
|
||||
json.put("x", getX());
|
||||
json.put("y", getY());
|
||||
json.put("t", ID);
|
||||
json.put("hp", hp);
|
||||
json.put("style", style);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
public static Obstacle deserialize(Document obj) {
|
||||
|
||||
Obstacle obstacle = new Obstacle((int) obj.get("hp"));
|
||||
obstacle.setObjectId((long) obj.get("i"));
|
||||
obstacle.setX((int) obj.get("x"));
|
||||
obstacle.setY((int) obj.get("y"));
|
||||
obstacle.setStyle((int) obj.get("style"));
|
||||
|
||||
return obstacle;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.*;
|
||||
import net.simon987.server.game.objects.Enterable;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.objects.Updatable;
|
||||
import net.simon987.server.game.world.Location;
|
||||
import net.simon987.server.game.world.World;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
|
||||
public class Portal extends GameObject implements Enterable {
|
||||
|
||||
@@ -14,7 +18,22 @@ public class Portal extends GameObject implements Enterable {
|
||||
|
||||
public static final int MAP_INFO = 0x0020;
|
||||
|
||||
public static final int ID = 8;
|
||||
public Portal() {
|
||||
|
||||
}
|
||||
|
||||
public Portal(Document document) {
|
||||
super(document);
|
||||
|
||||
destination = new Location(
|
||||
document.getInteger("dstWorldX"),
|
||||
document.getInteger("dstWorldY"),
|
||||
document.getString("dstDimension"),
|
||||
document.getInteger("dstX"),
|
||||
document.getInteger("dstY"));
|
||||
setX(document.getInteger("x"));
|
||||
setY(document.getInteger("y"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when an object attempts to walk directly into a Enterable object
|
||||
@@ -48,12 +67,8 @@ public class Portal extends GameObject implements Enterable {
|
||||
|
||||
@Override
|
||||
public Document mongoSerialise() {
|
||||
Document dbObject = new Document();
|
||||
Document dbObject = super.mongoSerialise();
|
||||
|
||||
dbObject.put("i", getObjectId());
|
||||
dbObject.put("x", getX());
|
||||
dbObject.put("y", getY());
|
||||
dbObject.put("t", ID);
|
||||
dbObject.put("dstWorldX", destination.worldX);
|
||||
dbObject.put("dstWorldY", destination.worldY);
|
||||
dbObject.put("dstX", destination.x);
|
||||
@@ -63,34 +78,6 @@ public class Portal extends GameObject implements Enterable {
|
||||
return dbObject;
|
||||
}
|
||||
|
||||
public static Portal deserialize(Document obj) {
|
||||
|
||||
Portal portal = new Portal();
|
||||
|
||||
portal.destination = new Location(
|
||||
(int) obj.get("dstWorldX"),
|
||||
(int) obj.get("dstWorldY"),
|
||||
(String) obj.get("dstDimension"),
|
||||
(int) obj.get("dstX"),
|
||||
(int) obj.get("dstY"));
|
||||
portal.setX((int) obj.get("x"));
|
||||
portal.setY((int) obj.get("y"));
|
||||
|
||||
return portal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject serialise() {
|
||||
JSONObject json = new JSONObject();
|
||||
|
||||
json.put("i", getObjectId());
|
||||
json.put("x", getX());
|
||||
json.put("y", getY());
|
||||
json.put("t", ID);
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
public Location getDestination() {
|
||||
return destination;
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import net.simon987.server.GameServer;
|
||||
import net.simon987.server.assembly.CpuHardware;
|
||||
import net.simon987.server.assembly.Status;
|
||||
import net.simon987.server.assembly.Util;
|
||||
import net.simon987.server.game.Action;
|
||||
import net.simon987.server.game.ControllableUnit;
|
||||
import net.simon987.server.game.objects.Action;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import org.bson.Document;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -24,6 +24,12 @@ public class RadioReceiverHardware extends CpuHardware {
|
||||
this.cubot = cubot;
|
||||
}
|
||||
|
||||
public RadioReceiverHardware(Document document) {
|
||||
super(document);
|
||||
|
||||
this.cubot = (ControllableUnit) GameServer.INSTANCE.getGameUniverse().getObject((long) document.get("cubot"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleInterrupt(Status status) {
|
||||
int x = getCpu().getRegisterSet().getRegister("X").getValue();
|
||||
@@ -70,13 +76,9 @@ public class RadioReceiverHardware extends CpuHardware {
|
||||
|
||||
Document dbObject = new Document();
|
||||
|
||||
dbObject.put("hwid", (int) HWID);
|
||||
dbObject.put("type", getClass().getCanonicalName());
|
||||
dbObject.put("cubot", cubot.getObjectId());
|
||||
|
||||
return dbObject;
|
||||
}
|
||||
|
||||
public static RadioReceiverHardware deserialize(Document obj) {
|
||||
return new RadioReceiverHardware((ControllableUnit) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("cubot")));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.server.game.GameObject;
|
||||
import net.simon987.server.game.Programmable;
|
||||
import net.simon987.server.game.Updatable;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.objects.Programmable;
|
||||
import net.simon987.server.game.objects.Updatable;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -12,12 +11,19 @@ public class RadioTower extends GameObject implements Programmable, Updatable {
|
||||
|
||||
private static final int MAP_INFO = 0x1000;
|
||||
|
||||
public static final int ID = 4;
|
||||
|
||||
public static final int MAX_RANGE = 3; //todo load from config
|
||||
|
||||
private static final int MAX_MESSAGES = 16;
|
||||
|
||||
public RadioTower() {
|
||||
|
||||
}
|
||||
|
||||
public RadioTower(Document document) {
|
||||
super(document);
|
||||
NpcPlugin.getRadioTowers().add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getMapInfo() {
|
||||
return MAP_INFO;
|
||||
@@ -50,46 +56,7 @@ public class RadioTower extends GameObject implements Programmable, Updatable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject serialise() {
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
|
||||
json.put("i", getObjectId());
|
||||
json.put("x", getX());
|
||||
json.put("y", getY());
|
||||
json.put("t", ID);
|
||||
|
||||
return json;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Document mongoSerialise() {
|
||||
Document dbObject = new Document();
|
||||
|
||||
dbObject.put("i", getObjectId());
|
||||
dbObject.put("x", getX());
|
||||
dbObject.put("y", getY());
|
||||
dbObject.put("t", ID);
|
||||
|
||||
return dbObject;
|
||||
}
|
||||
|
||||
public static RadioTower deserialize(Document obj) {
|
||||
|
||||
RadioTower tower = new RadioTower();
|
||||
tower.setObjectId((long) obj.get("i"));
|
||||
tower.setX((int) obj.get("x"));
|
||||
tower.setY((int) obj.get("y"));
|
||||
|
||||
NpcPlugin.getRadioTowers().add(tower);
|
||||
|
||||
return tower;
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<char[]> getMessages() {
|
||||
ArrayList<char[]> getMessages() {
|
||||
return lastMessages;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.Direction;
|
||||
import net.simon987.server.game.Location;
|
||||
import net.simon987.server.game.TileMap;
|
||||
import net.simon987.server.game.World;
|
||||
import net.simon987.server.game.objects.Direction;
|
||||
import net.simon987.server.game.world.Location;
|
||||
import net.simon987.server.game.world.TileMap;
|
||||
import net.simon987.server.game.world.World;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
|
||||
import java.awt.*;
|
||||
@@ -250,5 +250,4 @@ public class VaultDimension {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,10 +2,13 @@ package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.crypto.RandomStringGenerator;
|
||||
import net.simon987.server.game.*;
|
||||
import net.simon987.server.game.objects.Enterable;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.objects.Programmable;
|
||||
import net.simon987.server.game.objects.Updatable;
|
||||
import net.simon987.server.game.world.World;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import org.bson.Document;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -14,7 +17,6 @@ public class VaultDoor extends GameObject implements Programmable, Enterable, Up
|
||||
|
||||
private static final int MAP_INFO = 0x0800;
|
||||
|
||||
public static final int ID = 5;
|
||||
/**
|
||||
* Password to open the vault door
|
||||
*/
|
||||
@@ -48,6 +50,21 @@ public class VaultDoor extends GameObject implements Programmable, Enterable, Up
|
||||
this.password = "12345678".toCharArray();
|
||||
}
|
||||
|
||||
public VaultDoor(Document document) {
|
||||
super(document);
|
||||
|
||||
setX(document.getInteger("x"));
|
||||
setY(document.getInteger("y"));
|
||||
|
||||
|
||||
if (document.containsKey("homeX") && document.containsKey("homeY")) {
|
||||
homeX = document.getInteger("homeX");
|
||||
homeY = document.getInteger("homeY");
|
||||
}
|
||||
|
||||
password = document.getString("password").toCharArray();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
@@ -124,51 +141,15 @@ public class VaultDoor extends GameObject implements Programmable, Enterable, Up
|
||||
|
||||
@Override
|
||||
public Document mongoSerialise() {
|
||||
Document dbObject = new Document();
|
||||
Document dbObject = super.mongoSerialise();
|
||||
|
||||
dbObject.put("i", getObjectId());
|
||||
dbObject.put("x", getX());
|
||||
dbObject.put("y", getY());
|
||||
dbObject.put("homeX", getHomeX());
|
||||
dbObject.put("homeY", getHomeY());
|
||||
dbObject.put("t", ID);
|
||||
dbObject.put("pw", new String(password));
|
||||
|
||||
return dbObject;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject serialise() {
|
||||
|
||||
JSONObject json = new JSONObject();
|
||||
|
||||
json.put("i", getObjectId());
|
||||
json.put("x", getX());
|
||||
json.put("y", getY());
|
||||
json.put("t", ID);
|
||||
//Don't send the password to the client!
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
public static VaultDoor deserialize(Document obj) {
|
||||
|
||||
VaultDoor vaultDoor = new VaultDoor(0); //cypherId ?
|
||||
vaultDoor.setX((int) obj.get("x"));
|
||||
vaultDoor.setY((int) obj.get("y"));
|
||||
vaultDoor.setObjectId((long) obj.get("i"));
|
||||
|
||||
|
||||
if (obj.containsKey("homeX") && obj.containsKey("homeY")) {
|
||||
vaultDoor.setHomeX((int) obj.get("homeX"));
|
||||
vaultDoor.setHomeY((int) obj.get("homeY"));
|
||||
}
|
||||
|
||||
vaultDoor.password = ((String) obj.get("pw")).toCharArray();
|
||||
|
||||
return vaultDoor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
//Get or generate vault world
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.server.game.ControllableUnit;
|
||||
import net.simon987.server.game.GameObject;
|
||||
import net.simon987.server.game.Location;
|
||||
import net.simon987.server.game.objects.ControllableUnit;
|
||||
import net.simon987.server.game.objects.GameObject;
|
||||
import net.simon987.server.game.world.Location;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
import org.bson.Document;
|
||||
|
||||
@@ -11,23 +11,21 @@ import org.bson.Document;
|
||||
*/
|
||||
public class VaultExitPortal extends Portal {
|
||||
|
||||
public static final int ID = 9;
|
||||
public VaultExitPortal() {
|
||||
|
||||
@Override
|
||||
public Document mongoSerialise() {
|
||||
Document dbObject = new Document();
|
||||
}
|
||||
|
||||
dbObject.put("i", getObjectId());
|
||||
dbObject.put("x", getX());
|
||||
dbObject.put("y", getY());
|
||||
dbObject.put("t", ID);
|
||||
dbObject.put("dstWorldX", getDestination().worldX);
|
||||
dbObject.put("dstWorldY", getDestination().worldY);
|
||||
dbObject.put("dstX", getDestination().x);
|
||||
dbObject.put("dstY", getDestination().y);
|
||||
dbObject.put("dstDimension", getDestination().dimension);
|
||||
public VaultExitPortal(Document document) {
|
||||
super(document);
|
||||
|
||||
return dbObject;
|
||||
setDestination(new Location(
|
||||
document.getInteger("dstWorldX"),
|
||||
document.getInteger("dstWorldY"),
|
||||
document.getString("dstDimension"),
|
||||
document.getInteger("dstX"),
|
||||
document.getInteger("dstY")));
|
||||
setX(document.getInteger("x"));
|
||||
setY(document.getInteger("y"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,20 +40,4 @@ public class VaultExitPortal extends Portal {
|
||||
|
||||
return super.enter(object);
|
||||
}
|
||||
|
||||
public static Portal deserialize(Document obj) {
|
||||
|
||||
VaultExitPortal portal = new VaultExitPortal();
|
||||
|
||||
portal.setDestination(new Location(
|
||||
(int) obj.get("dstWorldX"),
|
||||
(int) obj.get("dstWorldY"),
|
||||
(String) obj.get("dstDimension"),
|
||||
(int) obj.get("dstX"),
|
||||
(int) obj.get("dstY")));
|
||||
portal.setX((int) obj.get("x"));
|
||||
portal.setY((int) obj.get("y"));
|
||||
|
||||
return portal;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.server.game.Direction;
|
||||
import net.simon987.server.game.TileMap;
|
||||
import net.simon987.server.game.World;
|
||||
import net.simon987.server.game.objects.Direction;
|
||||
import net.simon987.server.game.world.TileMap;
|
||||
import net.simon987.server.game.world.World;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.simon987.npcplugin;
|
||||
|
||||
import net.simon987.server.GameServer;
|
||||
import net.simon987.server.game.TileMap;
|
||||
import net.simon987.server.game.World;
|
||||
import net.simon987.server.game.world.TileMap;
|
||||
import net.simon987.server.game.world.World;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.simon987.server.ServerConfiguration;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
import net.simon987.server.event.WorldUpdateEvent;
|
||||
import net.simon987.server.game.World;
|
||||
import net.simon987.server.game.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -8,7 +8,7 @@ import net.simon987.server.GameServer;
|
||||
import net.simon987.server.event.GameEvent;
|
||||
import net.simon987.server.event.GameEventListener;
|
||||
import net.simon987.server.event.WorldGenerationEvent;
|
||||
import net.simon987.server.game.World;
|
||||
import net.simon987.server.game.world.World;
|
||||
import net.simon987.server.logging.LogManager;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
Reference in New Issue
Block a user