mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-19 18:46:43 +00:00
Changed unreliable sequential integer object id to BSON ObjectId #162
This commit is contained in:
parent
df9c466827
commit
a9cc9662f4
@ -23,7 +23,7 @@ public class ChargeShieldCommandListener implements GameEventListener {
|
|||||||
|
|
||||||
if (e.getName().equals("chargeShield")) {
|
if (e.getName().equals("chargeShield")) {
|
||||||
|
|
||||||
GameObject cubot = GameServer.INSTANCE.getGameUniverse().getObject(e.getLong("objectId"));
|
GameObject cubot = GameServer.INSTANCE.getGameUniverse().getObject(e.getObjectId("objectId"));
|
||||||
|
|
||||||
if (cubot != null) {
|
if (cubot != null) {
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ public class PopItemCommandListener implements GameEventListener {
|
|||||||
|
|
||||||
if (e.getName().equals("popItem")) {
|
if (e.getName().equals("popItem")) {
|
||||||
|
|
||||||
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getLong("objectId"));
|
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getObjectId("objectId"));
|
||||||
|
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ public class PutItemCommandListener implements GameEventListener {
|
|||||||
|
|
||||||
if (e.getName().equals("putItem")) {
|
if (e.getName().equals("putItem")) {
|
||||||
|
|
||||||
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getLong("objectId"));
|
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getObjectId("objectId"));
|
||||||
|
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ public class SetInventoryPosition implements GameEventListener {
|
|||||||
|
|
||||||
if (e.getName().equals("setInventoryPosition")) {
|
if (e.getName().equals("setInventoryPosition")) {
|
||||||
|
|
||||||
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getLong("objectId"));
|
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getObjectId("objectId"));
|
||||||
|
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ import net.simon987.server.event.GameEventListener;
|
|||||||
import net.simon987.server.event.UserCreationEvent;
|
import net.simon987.server.event.UserCreationEvent;
|
||||||
import net.simon987.server.logging.LogManager;
|
import net.simon987.server.logging.LogManager;
|
||||||
import net.simon987.server.user.User;
|
import net.simon987.server.user.User;
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@ -31,7 +32,7 @@ public class UserCreationListener implements GameEventListener {
|
|||||||
User user = (User) event.getSource();
|
User user = (User) event.getSource();
|
||||||
Cubot cubot = new Cubot();
|
Cubot cubot = new Cubot();
|
||||||
cubot.addStatus(CubotStatus.FACTORY_NEW);
|
cubot.addStatus(CubotStatus.FACTORY_NEW);
|
||||||
cubot.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId());
|
cubot.setObjectId(new ObjectId());
|
||||||
ServerConfiguration config = GameServer.INSTANCE.getConfig();
|
ServerConfiguration config = GameServer.INSTANCE.getConfig();
|
||||||
|
|
||||||
Point point = null;
|
Point point = null;
|
||||||
|
@ -4,6 +4,7 @@ import net.simon987.server.GameServer;
|
|||||||
import net.simon987.server.game.objects.Structure;
|
import net.simon987.server.game.objects.Structure;
|
||||||
import net.simon987.server.game.objects.Updatable;
|
import net.simon987.server.game.objects.Updatable;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -75,7 +76,7 @@ public class Factory extends Structure implements Updatable {
|
|||||||
|
|
||||||
for (Object id : tmpNpcArray) {
|
for (Object id : tmpNpcArray) {
|
||||||
|
|
||||||
NonPlayerCharacter npc = (NonPlayerCharacter) GameServer.INSTANCE.getGameUniverse().getObject((long) id);
|
NonPlayerCharacter npc = (NonPlayerCharacter) GameServer.INSTANCE.getGameUniverse().getObject((ObjectId) id);
|
||||||
|
|
||||||
if (npc != null) {
|
if (npc != null) {
|
||||||
npc.setFactory(this);
|
npc.setFactory(this);
|
||||||
@ -94,7 +95,7 @@ public class Factory extends Structure implements Updatable {
|
|||||||
if (p != null) {
|
if (p != null) {
|
||||||
NonPlayerCharacter npc = new HarvesterNPC();
|
NonPlayerCharacter npc = new HarvesterNPC();
|
||||||
npc.setWorld(getWorld());
|
npc.setWorld(getWorld());
|
||||||
npc.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId());
|
npc.setObjectId(new ObjectId());
|
||||||
npc.setX(p.x);
|
npc.setX(p.x);
|
||||||
npc.setY(p.y);
|
npc.setY(p.y);
|
||||||
getWorld().addObject(npc);
|
getWorld().addObject(npc);
|
||||||
@ -117,7 +118,7 @@ public class Factory extends Structure implements Updatable {
|
|||||||
public Document mongoSerialise() {
|
public Document mongoSerialise() {
|
||||||
Document dbObject = super.mongoSerialise();
|
Document dbObject = super.mongoSerialise();
|
||||||
|
|
||||||
List<Long> tmpNpcArray = new ArrayList<>(npcs.size());
|
List<ObjectId> tmpNpcArray = new ArrayList<>(npcs.size());
|
||||||
|
|
||||||
for (NonPlayerCharacter npc : npcs) {
|
for (NonPlayerCharacter npc : npcs) {
|
||||||
tmpNpcArray.add(npc.getObjectId());
|
tmpNpcArray.add(npc.getObjectId());
|
||||||
|
@ -7,6 +7,7 @@ import net.simon987.server.game.world.Location;
|
|||||||
import net.simon987.server.game.world.TileMap;
|
import net.simon987.server.game.world.TileMap;
|
||||||
import net.simon987.server.game.world.World;
|
import net.simon987.server.game.world.World;
|
||||||
import net.simon987.server.logging.LogManager;
|
import net.simon987.server.logging.LogManager;
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -148,6 +149,7 @@ public class VaultDimension {
|
|||||||
exitPortal.setX(exitPortalPt.x);
|
exitPortal.setX(exitPortalPt.x);
|
||||||
exitPortal.setY(exitPortalPt.y);
|
exitPortal.setY(exitPortalPt.y);
|
||||||
exitPortal.setWorld(objectiveWorld);
|
exitPortal.setWorld(objectiveWorld);
|
||||||
|
exitPortal.setObjectId(new ObjectId());
|
||||||
objectiveWorld.addObject(exitPortal);
|
objectiveWorld.addObject(exitPortal);
|
||||||
|
|
||||||
LogManager.LOGGER.severe("Objective: " + objectiveWorld.getId());
|
LogManager.LOGGER.severe("Objective: " + objectiveWorld.getId());
|
||||||
@ -165,6 +167,7 @@ public class VaultDimension {
|
|||||||
homePortal.setX(homePortalPt.x);
|
homePortal.setX(homePortalPt.x);
|
||||||
homePortal.setY(homePortalPt.y);
|
homePortal.setY(homePortalPt.y);
|
||||||
homePortal.setWorld(homeWorld);
|
homePortal.setWorld(homeWorld);
|
||||||
|
homePortal.setObjectId(new ObjectId());
|
||||||
homeWorld.addObject(homePortal);
|
homeWorld.addObject(homePortal);
|
||||||
|
|
||||||
Point entryCoords = homePortal.getAdjacentTile();
|
Point entryCoords = homePortal.getAdjacentTile();
|
||||||
|
@ -113,7 +113,7 @@ public class VaultDoor extends Structure implements MessageReceiver, Enterable,
|
|||||||
@Override
|
@Override
|
||||||
public boolean enter(GameObject object) {
|
public boolean enter(GameObject object) {
|
||||||
|
|
||||||
LogManager.LOGGER.fine("VAULT enter " + open);
|
// LogManager.LOGGER.fine("VAULT enter " + open);
|
||||||
|
|
||||||
if (open) {
|
if (open) {
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package net.simon987.npcplugin;
|
package net.simon987.npcplugin;
|
||||||
|
|
||||||
import net.simon987.server.GameServer;
|
|
||||||
import net.simon987.server.game.world.TileMap;
|
import net.simon987.server.game.world.TileMap;
|
||||||
import net.simon987.server.game.world.World;
|
import net.simon987.server.game.world.World;
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -60,7 +60,7 @@ public class VaultWorldUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ElectricBox box = new ElectricBox();
|
ElectricBox box = new ElectricBox();
|
||||||
box.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId());
|
box.setObjectId(new ObjectId());
|
||||||
box.setX(p.x);
|
box.setX(p.x);
|
||||||
box.setY(p.y);
|
box.setY(p.y);
|
||||||
box.setWorld(world);
|
box.setWorld(world);
|
||||||
|
@ -4,13 +4,13 @@ import net.simon987.npcplugin.Factory;
|
|||||||
import net.simon987.npcplugin.NpcPlugin;
|
import net.simon987.npcplugin.NpcPlugin;
|
||||||
import net.simon987.npcplugin.RadioTower;
|
import net.simon987.npcplugin.RadioTower;
|
||||||
import net.simon987.npcplugin.VaultDoor;
|
import net.simon987.npcplugin.VaultDoor;
|
||||||
import net.simon987.server.GameServer;
|
|
||||||
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.WorldGenerationEvent;
|
import net.simon987.server.event.WorldGenerationEvent;
|
||||||
import net.simon987.server.game.world.TileMap;
|
import net.simon987.server.game.world.TileMap;
|
||||||
import net.simon987.server.game.world.World;
|
import net.simon987.server.game.world.World;
|
||||||
import net.simon987.server.logging.LogManager;
|
import net.simon987.server.logging.LogManager;
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@ -50,7 +50,7 @@ public class WorldCreationListener implements GameEventListener {
|
|||||||
Factory factory = new Factory();
|
Factory factory = new Factory();
|
||||||
|
|
||||||
factory.setWorld(world);
|
factory.setWorld(world);
|
||||||
factory.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId());
|
factory.setObjectId(new ObjectId());
|
||||||
factory.setX(x);
|
factory.setX(x);
|
||||||
factory.setY(y);
|
factory.setY(y);
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ public class WorldCreationListener implements GameEventListener {
|
|||||||
RadioTower radioTower = new RadioTower();
|
RadioTower radioTower = new RadioTower();
|
||||||
|
|
||||||
radioTower.setWorld(world);
|
radioTower.setWorld(world);
|
||||||
radioTower.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId());
|
radioTower.setObjectId(new ObjectId());
|
||||||
radioTower.setX(p.x);
|
radioTower.setX(p.x);
|
||||||
radioTower.setY(p.y);
|
radioTower.setY(p.y);
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ public class WorldCreationListener implements GameEventListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vaultDoor.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId());
|
vaultDoor.setObjectId(new ObjectId());
|
||||||
world.addObject(vaultDoor);
|
world.addObject(vaultDoor);
|
||||||
world.incUpdatable(); //In case the Factory & Radio Tower couldn't be spawned.
|
world.incUpdatable(); //In case the Factory & Radio Tower couldn't be spawned.
|
||||||
vaultDoor.setWorld(world);
|
vaultDoor.setWorld(world);
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package net.simon987.biomassplugin;
|
package net.simon987.biomassplugin;
|
||||||
|
|
||||||
import net.simon987.server.GameServer;
|
|
||||||
import net.simon987.server.game.world.TileMap;
|
import net.simon987.server.game.world.TileMap;
|
||||||
import net.simon987.server.game.world.World;
|
import net.simon987.server.game.world.World;
|
||||||
import net.simon987.server.logging.LogManager;
|
import net.simon987.server.logging.LogManager;
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -63,7 +63,7 @@ public class WorldUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BiomassBlob biomassBlob = new BiomassBlob();
|
BiomassBlob biomassBlob = new BiomassBlob();
|
||||||
biomassBlob.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId());
|
biomassBlob.setObjectId(new ObjectId());
|
||||||
biomassBlob.setBiomassCount(yield);
|
biomassBlob.setBiomassCount(yield);
|
||||||
biomassBlob.setX(p.x);
|
biomassBlob.setX(p.x);
|
||||||
biomassBlob.setY(p.y);
|
biomassBlob.setY(p.y);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package net.simon987.biomassplugin.event;
|
package net.simon987.biomassplugin.event;
|
||||||
|
|
||||||
import net.simon987.biomassplugin.BiomassBlob;
|
import net.simon987.biomassplugin.BiomassBlob;
|
||||||
import net.simon987.server.GameServer;
|
|
||||||
import net.simon987.server.ServerConfiguration;
|
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;
|
||||||
@ -9,6 +8,7 @@ import net.simon987.server.event.ObjectDeathEvent;
|
|||||||
import net.simon987.server.game.objects.GameObject;
|
import net.simon987.server.game.objects.GameObject;
|
||||||
import net.simon987.server.game.world.World;
|
import net.simon987.server.game.world.World;
|
||||||
import net.simon987.server.logging.LogManager;
|
import net.simon987.server.logging.LogManager;
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles ObjectDeathEvent events
|
* Handles ObjectDeathEvent events
|
||||||
@ -58,7 +58,7 @@ public class ObjectDeathListener implements GameEventListener {
|
|||||||
private BiomassBlob createBiomassBlobAt(int x, int y, World world) {
|
private BiomassBlob createBiomassBlobAt(int x, int y, World world) {
|
||||||
|
|
||||||
BiomassBlob biomassBlob = new BiomassBlob();
|
BiomassBlob biomassBlob = new BiomassBlob();
|
||||||
biomassBlob.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId());
|
biomassBlob.setObjectId(new ObjectId());
|
||||||
biomassBlob.setBiomassCount(biomassDropCount);
|
biomassBlob.setBiomassCount(biomassDropCount);
|
||||||
biomassBlob.setX(x);
|
biomassBlob.setX(x);
|
||||||
biomassBlob.setY(y);
|
biomassBlob.setY(y);
|
||||||
|
@ -234,7 +234,6 @@ public class GameServer implements Runnable {
|
|||||||
if (cursor.hasNext()) {
|
if (cursor.hasNext()) {
|
||||||
Document serverObj = cursor.next();
|
Document serverObj = cursor.next();
|
||||||
gameUniverse.setTime((long) serverObj.get("time"));
|
gameUniverse.setTime((long) serverObj.get("time"));
|
||||||
gameUniverse.setNextObjectId((long) serverObj.get("nextObjectId"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LogManager.LOGGER.info("Done loading! W:" + GameServer.INSTANCE.getGameUniverse().getWorldCount() +
|
LogManager.LOGGER.info("Done loading! W:" + GameServer.INSTANCE.getGameUniverse().getWorldCount() +
|
||||||
@ -276,7 +275,6 @@ public class GameServer implements Runnable {
|
|||||||
|
|
||||||
Document serverObj = new Document();
|
Document serverObj = new Document();
|
||||||
serverObj.put("time", gameUniverse.getTime());
|
serverObj.put("time", gameUniverse.getTime());
|
||||||
serverObj.put("nextObjectId", gameUniverse.getNextObjectId());
|
|
||||||
//A constant id ensures only one entry is kept and updated, instead of a new entry created every save.
|
//A constant id ensures only one entry is kept and updated, instead of a new entry created every save.
|
||||||
server.replaceOne(new Document("_id", "serverinfo"), serverObj, updateOptions);
|
server.replaceOne(new Document("_id", "serverinfo"), serverObj, updateOptions);
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package net.simon987.server.event;
|
package net.simon987.server.event;
|
||||||
|
|
||||||
import net.simon987.server.websocket.OnlineUser;
|
import net.simon987.server.websocket.OnlineUser;
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -30,6 +31,10 @@ public class DebugCommandEvent extends GameEvent {
|
|||||||
return (long) command.get(key);
|
return (long) command.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ObjectId getObjectId(String key) {
|
||||||
|
return (ObjectId) command.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send back a response to the command issuer
|
* Send back a response to the command issuer
|
||||||
*/
|
*/
|
||||||
|
@ -13,10 +13,10 @@ import net.simon987.server.game.world.WorldGenerator;
|
|||||||
import net.simon987.server.logging.LogManager;
|
import net.simon987.server.logging.LogManager;
|
||||||
import net.simon987.server.user.User;
|
import net.simon987.server.user.User;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
|
||||||
|
|
||||||
public class GameUniverse {
|
public class GameUniverse {
|
||||||
|
|
||||||
@ -31,8 +31,6 @@ public class GameUniverse {
|
|||||||
|
|
||||||
private long time;
|
private long time;
|
||||||
|
|
||||||
private AtomicLong nextObjectId = new AtomicLong(0);
|
|
||||||
|
|
||||||
private int maxWidth = 0xFFFF;
|
private int maxWidth = 0xFFFF;
|
||||||
|
|
||||||
public GameUniverse(ServerConfiguration config) {
|
public GameUniverse(ServerConfiguration config) {
|
||||||
@ -216,7 +214,7 @@ public class GameUniverse {
|
|||||||
* @param id id of the game object
|
* @param id id of the game object
|
||||||
* @return GameObject, null if not found
|
* @return GameObject, null if not found
|
||||||
*/
|
*/
|
||||||
public GameObject getObject(long id) {
|
public GameObject getObject(ObjectId id) {
|
||||||
|
|
||||||
for (World world : getWorlds()) {
|
for (World world : getWorlds()) {
|
||||||
GameObject obj = world.findObject(id);
|
GameObject obj = world.findObject(id);
|
||||||
@ -251,10 +249,6 @@ public class GameUniverse {
|
|||||||
return users.size();
|
return users.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getNextObjectId() {
|
|
||||||
return nextObjectId.getAndIncrement();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getGuestUsername() {
|
public String getGuestUsername() {
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
|
||||||
@ -287,7 +281,4 @@ public class GameUniverse {
|
|||||||
this.time = time;
|
this.time = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNextObjectId(long nextObjectId) {
|
|
||||||
this.nextObjectId.set(nextObjectId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import net.simon987.server.event.GameEvent;
|
|||||||
import net.simon987.server.event.GameEventListener;
|
import net.simon987.server.event.GameEventListener;
|
||||||
import net.simon987.server.game.objects.GameObject;
|
import net.simon987.server.game.objects.GameObject;
|
||||||
import net.simon987.server.game.objects.MessageReceiver;
|
import net.simon987.server.game.objects.MessageReceiver;
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
|
||||||
public class ComPortMsgCommandListener implements GameEventListener {
|
public class ComPortMsgCommandListener implements GameEventListener {
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ public class ComPortMsgCommandListener implements GameEventListener {
|
|||||||
|
|
||||||
if (e.getName().equals("comPortMsg")) {
|
if (e.getName().equals("comPortMsg")) {
|
||||||
|
|
||||||
long objectId = e.getLong("objectId");
|
ObjectId objectId = e.getObjectId("objectId");
|
||||||
|
|
||||||
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(objectId);
|
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(objectId);
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ public class DamageObjCommandListener implements GameEventListener {
|
|||||||
|
|
||||||
if (e.getName().equals("damageObj")) {
|
if (e.getName().equals("damageObj")) {
|
||||||
|
|
||||||
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getLong("objectId"));
|
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getObjectId("objectId"));
|
||||||
|
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ public class HealObjCommandListener implements GameEventListener {
|
|||||||
|
|
||||||
if (e.getName().equals("healObj")) {
|
if (e.getName().equals("healObj")) {
|
||||||
|
|
||||||
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getLong("objectId"));
|
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getObjectId("objectId"));
|
||||||
|
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ public class MoveObjCommandListener implements GameEventListener {
|
|||||||
|
|
||||||
if (e.getName().equals("moveObj")) {
|
if (e.getName().equals("moveObj")) {
|
||||||
|
|
||||||
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getLong("objectId"));
|
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getObjectId("objectId"));
|
||||||
|
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ public class SetEnergyCommandListener implements GameEventListener {
|
|||||||
|
|
||||||
if (e.getName().equals("setEnergy")) {
|
if (e.getName().equals("setEnergy")) {
|
||||||
|
|
||||||
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getLong("objectId"));
|
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getObjectId("objectId"));
|
||||||
|
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import net.simon987.server.event.GameEventListener;
|
|||||||
import net.simon987.server.game.objects.GameObject;
|
import net.simon987.server.game.objects.GameObject;
|
||||||
import net.simon987.server.game.world.World;
|
import net.simon987.server.game.world.World;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@ -28,7 +29,7 @@ public class SpawnObjCommandListener implements GameEventListener {
|
|||||||
false, e.getString("dimension"));
|
false, e.getString("dimension"));
|
||||||
|
|
||||||
Document dbObj = Document.parse(e.getString("data"));
|
Document dbObj = Document.parse(e.getString("data"));
|
||||||
dbObj.put("i", GameServer.INSTANCE.getGameUniverse().getNextObjectId());
|
dbObj.put("id", new ObjectId());
|
||||||
|
|
||||||
GameObject object = GameServer.INSTANCE.getRegistry().deserializeGameObject(dbObj);
|
GameObject object = GameServer.INSTANCE.getRegistry().deserializeGameObject(dbObj);
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ public class TpObjectCommandListener implements GameEventListener {
|
|||||||
|
|
||||||
if (e.getName().equals("tpObj")) {
|
if (e.getName().equals("tpObj")) {
|
||||||
|
|
||||||
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getLong("objectId"));
|
GameObject object = GameServer.INSTANCE.getGameUniverse().getObject(e.getObjectId("objectId"));
|
||||||
World world = GameServer.INSTANCE.getGameUniverse().getWorld(e.getInt("worldX"), e.getInt("worldY"),
|
World world = GameServer.INSTANCE.getGameUniverse().getWorld(e.getInt("worldX"), e.getInt("worldY"),
|
||||||
false, e.getString("dimension"));
|
false, e.getString("dimension"));
|
||||||
|
|
||||||
|
@ -5,12 +5,13 @@ import net.simon987.server.assembly.Memory;
|
|||||||
import net.simon987.server.game.item.Item;
|
import net.simon987.server.game.item.Item;
|
||||||
import net.simon987.server.game.world.World;
|
import net.simon987.server.game.world.World;
|
||||||
import net.simon987.server.user.User;
|
import net.simon987.server.user.User;
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public interface ControllableUnit {
|
public interface ControllableUnit {
|
||||||
|
|
||||||
long getObjectId();
|
ObjectId getObjectId();
|
||||||
|
|
||||||
void setKeyboardBuffer(ArrayList<Integer> kbBuffer);
|
void setKeyboardBuffer(ArrayList<Integer> kbBuffer);
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import net.simon987.server.game.world.World;
|
|||||||
import net.simon987.server.io.JSONSerialisable;
|
import net.simon987.server.io.JSONSerialisable;
|
||||||
import net.simon987.server.io.MongoSerializable;
|
import net.simon987.server.io.MongoSerializable;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@ -20,7 +21,7 @@ public abstract class GameObject implements JSONSerialisable, MongoSerializable
|
|||||||
/**
|
/**
|
||||||
* Object's unique identifier
|
* Object's unique identifier
|
||||||
*/
|
*/
|
||||||
private long objectId;
|
private ObjectId objectId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* X coordinate of the object in its World
|
* X coordinate of the object in its World
|
||||||
@ -47,7 +48,7 @@ public abstract class GameObject implements JSONSerialisable, MongoSerializable
|
|||||||
}
|
}
|
||||||
|
|
||||||
public GameObject(Document document) {
|
public GameObject(Document document) {
|
||||||
objectId = document.getLong("id");
|
objectId = document.getObjectId("id");
|
||||||
x = document.getInteger("x");
|
x = document.getInteger("x");
|
||||||
y = document.getInteger("y");
|
y = document.getInteger("y");
|
||||||
}
|
}
|
||||||
@ -183,11 +184,11 @@ public abstract class GameObject implements JSONSerialisable, MongoSerializable
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getObjectId() {
|
public ObjectId getObjectId() {
|
||||||
return objectId;
|
return objectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setObjectId(long objectId) {
|
public void setObjectId(ObjectId objectId) {
|
||||||
this.objectId = objectId;
|
this.objectId = objectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +227,7 @@ public abstract class GameObject implements JSONSerialisable, MongoSerializable
|
|||||||
@Override
|
@Override
|
||||||
public JSONObject jsonSerialise() {
|
public JSONObject jsonSerialise() {
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
json.put("i", getObjectId());
|
json.put("i", getObjectId().toHexString());
|
||||||
json.put("t", getClass().getCanonicalName());
|
json.put("t", getClass().getCanonicalName());
|
||||||
json.put("x", getX());
|
json.put("x", getX());
|
||||||
json.put("y", getY());
|
json.put("y", getY());
|
||||||
|
@ -9,6 +9,7 @@ import net.simon987.server.game.objects.Updatable;
|
|||||||
import net.simon987.server.game.pathfinding.Pathfinder;
|
import net.simon987.server.game.pathfinding.Pathfinder;
|
||||||
import net.simon987.server.io.MongoSerializable;
|
import net.simon987.server.io.MongoSerializable;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
|
import org.bson.types.ObjectId;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -35,7 +36,7 @@ public class World implements MongoSerializable {
|
|||||||
|
|
||||||
private String dimension;
|
private String dimension;
|
||||||
|
|
||||||
private ConcurrentHashMap<Long, GameObject> gameObjects = new ConcurrentHashMap<>(8);
|
private ConcurrentHashMap<ObjectId, GameObject> gameObjects = new ConcurrentHashMap<>(8);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this number is greater than 0, the World will be updated.
|
* If this number is greater than 0, the World will be updated.
|
||||||
@ -152,12 +153,10 @@ public class World implements MongoSerializable {
|
|||||||
gameObjects.remove(object.getObjectId());
|
gameObjects.remove(object.getObjectId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameObject findObject(long objectId) {
|
public GameObject findObject(ObjectId objectId) {
|
||||||
return gameObjects.get(objectId);
|
return gameObjects.get(objectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update this World and its GameObjects
|
* Update this World and its GameObjects
|
||||||
* <br>
|
* <br>
|
||||||
|
@ -59,7 +59,7 @@ public class User implements MongoSerializable {
|
|||||||
|
|
||||||
public static User deserialize(Document obj) throws CancelledException {
|
public static User deserialize(Document obj) throws CancelledException {
|
||||||
|
|
||||||
User user = new User((ControllableUnit) GameServer.INSTANCE.getGameUniverse().getObject((long) obj.get("controlledUnit")));
|
User user = new User((ControllableUnit) GameServer.INSTANCE.getGameUniverse().getObject(obj.getObjectId("controlledUnit")));
|
||||||
user.getControlledUnit().setParent(user);
|
user.getControlledUnit().setParent(user);
|
||||||
user.username = (String) obj.get("username");
|
user.username = (String) obj.get("username");
|
||||||
user.userCode = (String) obj.get("code");
|
user.userCode = (String) obj.get("code");
|
||||||
|
14
Server/src/main/resources/static/js/mar.js
vendored
14
Server/src/main/resources/static/js/mar.js
vendored
@ -291,7 +291,7 @@ var config = {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
kbBufferX: 350,
|
kbBufferX: 350,
|
||||||
kbBufferY: 20,
|
kbBufferY: 35,
|
||||||
arrowTextStyle: {
|
arrowTextStyle: {
|
||||||
fontSize: 32,
|
fontSize: 32,
|
||||||
fill: "#ffffff",
|
fill: "#ffffff",
|
||||||
@ -735,25 +735,15 @@ var GameClient = (function () {
|
|||||||
self.listeners.push(new DebugResponseListener());
|
self.listeners.push(new DebugResponseListener());
|
||||||
self.socket.onmessage = function (received) {
|
self.socket.onmessage = function (received) {
|
||||||
var message;
|
var message;
|
||||||
try {
|
|
||||||
message = JSON.parse(received.data);
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
console.log("[MAR] Received: " + received.data);
|
console.log("[MAR] Received: " + received.data);
|
||||||
}
|
}
|
||||||
|
message = JSON.parse(received.data);
|
||||||
for (var i = 0; i < self.listeners.length; i++) {
|
for (var i = 0; i < self.listeners.length; i++) {
|
||||||
if (self.listeners[i].getListenedMessageType() === message.t) {
|
if (self.listeners[i].getListenedMessageType() === message.t) {
|
||||||
self.listeners[i].handle(message);
|
self.listeners[i].handle(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (e) {
|
|
||||||
if (DEBUG) {
|
|
||||||
console.log("[MAR] Received invalid message, assuming floppy data");
|
|
||||||
}
|
|
||||||
document.getElementById("floppyDown").innerHTML = "<i class=\"fa fa-long-arrow-down\" aria-hidden=\"true\"></i> <i class=\"fa fa-floppy-o\" aria-hidden=\"true\"></i>";
|
|
||||||
var blob = new Blob([received.data], { type: "application/octet-stream" });
|
|
||||||
saveAs(blob, "floppy.bin");
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
self.reloadCode();
|
self.reloadCode();
|
||||||
};
|
};
|
||||||
|
@ -84,7 +84,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-sm-2">
|
<div class="col-sm-2">
|
||||||
<button class="btn btn-shadow btn-info text-mono regular-screen"
|
<button id="floppyDown" class="btn btn-shadow btn-info text-mono regular-screen"
|
||||||
onclick="window.location.assign('floppy_download')"><i class="mi">file_download</i>
|
onclick="window.location.assign('floppy_download')"><i class="mi">file_download</i>
|
||||||
Floppy
|
Floppy
|
||||||
</button>
|
</button>
|
||||||
|
@ -412,30 +412,18 @@ class GameClient {
|
|||||||
|
|
||||||
let message;
|
let message;
|
||||||
|
|
||||||
try {
|
|
||||||
message = JSON.parse(received.data);
|
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
console.log("[MAR] Received: " + received.data)
|
console.log("[MAR] Received: " + received.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message = JSON.parse(received.data);
|
||||||
|
|
||||||
for (let i = 0; i < self.listeners.length; i++) {
|
for (let i = 0; i < self.listeners.length; i++) {
|
||||||
|
|
||||||
if (self.listeners[i].getListenedMessageType() === message.t) {
|
if (self.listeners[i].getListenedMessageType() === message.t) {
|
||||||
self.listeners[i].handle(message)
|
self.listeners[i].handle(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e) {
|
|
||||||
if (DEBUG) {
|
|
||||||
console.log("[MAR] Received invalid message, assuming floppy data");
|
|
||||||
}
|
|
||||||
document.getElementById("floppyDown").innerHTML = "<i class=\"fa fa-long-arrow-down\" aria-hidden=\"true\"></i> <i class=\"fa fa-floppy-o\" aria-hidden=\"true\"></i>";
|
|
||||||
let blob = new Blob([received.data], {type: "application/octet-stream"});
|
|
||||||
saveAs(blob, "floppy.bin");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
self.reloadCode();
|
self.reloadCode();
|
||||||
|
@ -40,7 +40,7 @@ let config = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
kbBufferX: 350, ///Position of the keyboard buffer fill on screen
|
kbBufferX: 350, ///Position of the keyboard buffer fill on screen
|
||||||
kbBufferY: 20,
|
kbBufferY: 35,
|
||||||
arrowTextStyle: {
|
arrowTextStyle: {
|
||||||
fontSize: 32,
|
fontSize: 32,
|
||||||
fill: "#ffffff",
|
fill: "#ffffff",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user