Improved World update performance. Decreased save file size. Added Harvester NPC #19.

This commit is contained in:
simon
2017-12-16 15:40:03 -05:00
parent cd41db9e58
commit 3548928218
20 changed files with 102 additions and 37 deletions

View File

@@ -1,6 +1,7 @@
package net.simon987.npcplugin;
import net.simon987.server.GameServer;
import net.simon987.server.assembly.Util;
import net.simon987.server.game.Direction;
import net.simon987.server.game.GameObject;
@@ -83,7 +84,18 @@ public class HarvestTask extends NPCTask {
} else {
if (nextWorldDirection == null) {
nextWorldDirection = Direction.getDirection(random.nextInt(3));
//Stay near the center of the map 50% of the time
if (random.nextBoolean()) {
nextWorldDirection = Direction.getDirectionTo(npc.getX(), npc.getY(),
GameServer.INSTANCE.getConfig().getInt("new_user_worldX"),
GameServer.INSTANCE.getConfig().getInt("new_user_worldY"));
} else {
nextWorldDirection = Direction.getDirection(random.nextInt(3));
}
pause += 6;
}
npc.gotoWorld(nextWorldDirection);

View File

@@ -37,14 +37,14 @@ public class HarvesterNPC extends NonPlayerCharacter {
public JSONObject serialise() {
JSONObject json = super.serialise();
json.put("id", getObjectId());
json.put("i", getObjectId());
json.put("x", getX());
json.put("y", getY());
json.put("direction", getDirection().ordinal());
json.put("hp", hp);
json.put("energy", energy);
json.put("action", getAction().ordinal());
json.put("type", 10);
json.put("t", 10);
return json;
}
@@ -52,7 +52,7 @@ public class HarvesterNPC extends NonPlayerCharacter {
public static HarvesterNPC deserialize(JSONObject json) {
HarvesterNPC npc = new HarvesterNPC();
npc.setObjectId((int) (long) json.get("id"));
npc.setObjectId((int) (long) json.get("i"));
npc.setX((int) (long) json.get("x"));
npc.setY((int) (long) json.get("y"));
npc.hp = (int) (long) json.get("hp");

View File

@@ -57,8 +57,6 @@ public abstract class NonPlayerCharacter extends GameObject implements Updatable
public boolean gotoWorld(Direction direction) {
System.out.println("going " + direction);
if (direction == Direction.NORTH) {
if (!moveTo(8, 0, 0)) {
setDirection(Direction.NORTH);

View File

@@ -22,7 +22,7 @@ public class NpcPlugin extends ServerPlugin implements GameObjectDeserializer {
@Override
public GameObject deserializeObject(JSONObject object) {
int objType = (int) (long) object.get("type");
int objType = (int) (long) object.get("t");
if (objType == HarvesterNPC.ID) {
return HarvesterNPC.deserialize(object);

View File

@@ -43,9 +43,8 @@ public class WorldUpdateListener implements GameEventListener {
npc.setX(p.x);
npc.setY(p.y);
world.getGameObjects().add(npc);
world.incUpdatable();
}
}