diff --git a/odb/doids/placeholder.txt b/odb/doids/placeholder.txt new file mode 100644 index 00000000..e69de29b diff --git a/src/main/NGECore.java b/src/main/NGECore.java index 6a351892..6cff7196 100644 --- a/src/main/NGECore.java +++ b/src/main/NGECore.java @@ -182,6 +182,7 @@ public class NGECore { private ObjectDatabase mailODB; private ObjectDatabase guildODB; private ObjectDatabase objectIdODB; + private ObjectDatabase duplicateIdODB; private BusConfiguration eventBusConfig = BusConfiguration.Default(1, new ThreadPoolExecutor(1, 4, 1, TimeUnit.MINUTES, new LinkedBlockingQueue())); @@ -231,6 +232,7 @@ public class NGECore { mailODB = new ObjectDatabase("mails", true, false, true); guildODB = new ObjectDatabase("guild", true, false, true); objectIdODB = new ObjectDatabase("oids", true, false, false); + duplicateIdODB = new ObjectDatabase("doids", true, false, true); // Services loginService = new LoginService(this); @@ -518,6 +520,10 @@ public class NGECore { return objectIdODB; } + public ObjectDatabase getDuplicateIdODB() { + return duplicateIdODB; + } + public int getActiveClients() { int connections = 0; for (Map.Entry c : clients.entrySet()) { diff --git a/src/services/object/DuplicateId.java b/src/services/object/DuplicateId.java new file mode 100644 index 00000000..57b52cea --- /dev/null +++ b/src/services/object/DuplicateId.java @@ -0,0 +1,26 @@ +package services.object; + +import com.sleepycat.persist.model.Entity; +import com.sleepycat.persist.model.PrimaryKey; + +@Entity +public class DuplicateId { + + @PrimaryKey + private String key; + private long objectId; + + public DuplicateId(String key, long objectId) { + this.key = key; + this.objectId = objectId; + } + + public DuplicateId() { + + } + + public long getObjectId() { + return objectId; + } + +} diff --git a/src/services/object/ObjectService.java b/src/services/object/ObjectService.java index 6f164ebc..dd999972 100644 --- a/src/services/object/ObjectService.java +++ b/src/services/object/ObjectService.java @@ -53,6 +53,7 @@ import org.apache.mina.core.session.IoSession; import org.python.core.Py; import org.python.core.PyObject; +import com.sleepycat.je.Transaction; import com.sleepycat.persist.EntityCursor; import com.sleepycat.persist.model.Entity; import com.sleepycat.persist.model.PrimaryKey; @@ -832,23 +833,38 @@ public class ObjectService implements INetworkDispatch { SWGObject object = getObject(objectId); // Same coordinates is a true duplicate - if ((px + x1) == object.getPosition().x && + if ((px + ((containerId == 0) ? 0 : x1)) == object.getPosition().x && py == object.getPosition().y && - (pz + z1) == object.getPosition().z) { + (pz + ((containerId == 0) ? 0 : z1)) == object.getPosition().z) { //System.out.println("Duplicate buildout object: " + template); continue; } } - if (objectId != 0 && getObject(objectId) != null) { - duplicate.put(objectId, generateObjectID()); - objectId = duplicate.get(objectId); - } - if (duplicate.containsKey(containerId)) { containerId = duplicate.get(containerId); } + if (objectId != 0 && getObject(objectId) != null) { + SWGObject container = getObject(containerId); + int x = ((int) (px + ((container == null) ? x1 : container.getPosition().x))); + int z = ((int) (pz + ((container == null) ? z1 : container.getPosition().z))); + String key = "" + CRC.StringtoCRC(planet.getName()) + CRC.StringtoCRC(template) + type + containerId + cellIndex + x + py + z; + long newObjectId = 0; + + if (core.getDuplicateIdODB().contains(key, String.class, DuplicateId.class)) { + newObjectId = core.getDuplicateIdODB().get(key, String.class, DuplicateId.class).getObjectId(); + } else { + newObjectId = generateObjectID(); + Transaction txn = core.getDuplicateIdODB().getEnvironment().beginTransaction(null, null); + core.getDuplicateIdODB().put(new DuplicateId(key, newObjectId), String.class, DuplicateId.class, txn); + txn.commitSync(); + } + + duplicate.put(objectId, newObjectId); + objectId = newObjectId; + } + List containers = new ArrayList(); SWGObject object; if(objectId != 0 && containerId == 0) { @@ -856,9 +872,11 @@ public class ObjectService implements INetworkDispatch { containers.add(objectId); object = createObject(template, objectId, planet, new Point3D(px + x1, py, pz + z1), new Quaternion(qw, qx, qy, qz), null, true); object.setAttachment("childObjects", null); - ((BuildingObject) object).createTransaction(core.getBuildingODB().getEnvironment()); - core.getBuildingODB().put((BuildingObject) object, Long.class, BuildingObject.class, ((BuildingObject) object).getTransaction()); - ((BuildingObject) object).getTransaction().commitSync(); + if (!duplicate.containsValue(objectId)) { + ((BuildingObject) object).createTransaction(core.getBuildingODB().getEnvironment()); + core.getBuildingODB().put((BuildingObject) object, Long.class, BuildingObject.class, ((BuildingObject) object).getTransaction()); + ((BuildingObject) object).getTransaction().commitSync(); + } } else { object = createObject(template, objectId, planet, new Point3D(px + x1, py, pz + z1), new Quaternion(qw, qx, qy, qz)); }