From 2afc83d0c0179e3c5e0319342b2a388ee6762e9d Mon Sep 17 00:00:00 2001 From: Obique PSWG Date: Mon, 4 Jan 2016 23:06:00 -0600 Subject: [PATCH] Fixed teleportation --- src/services/objects/ObjectAwareness.java | 37 ++++++++++++++++------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/src/services/objects/ObjectAwareness.java b/src/services/objects/ObjectAwareness.java index 1a852761e..a14688442 100644 --- a/src/services/objects/ObjectAwareness.java +++ b/src/services/objects/ObjectAwareness.java @@ -152,6 +152,8 @@ public class ObjectAwareness extends Service { SWGObject object = oti.getObject(); Player owner = object.getOwner(); boolean creature = object instanceof CreatureObject && owner != null; + Location old = object.getLocation(); + object.setLocation(oti.getNewLocation()); if (oti.getParent() != null) { if (creature) startScene((CreatureObject) object, oti.getNewLocation()); @@ -160,8 +162,9 @@ public class ObjectAwareness extends Service { if (creature) startScene((CreatureObject) object, oti.getNewLocation()); object.createObject(owner); - move(object, oti.getNewLocation()); + moveFromOld(object, old); } + new PlayerEventIntent(object.getOwner(), PlayerEvent.PE_ZONE_IN).broadcast(); } private void processGalacticPacketIntent(GalacticPacketIntent i) { @@ -182,7 +185,6 @@ public class ObjectAwareness extends Service { long time = (long) (ProjectSWG.getCoreTime() / 1E3); Race race = ((CreatureObject)object).getRace(); sendPacket(object.getOwner(), new CmdStartScene(false, object.getObjectId(), race, newLocation, time, (int)(System.currentTimeMillis()/1E3))); - new PlayerEventIntent(object.getOwner(), PlayerEvent.PE_ZONE_IN).broadcast(); } private void moveObject(SWGObject obj, DataTransform transform) { @@ -247,15 +249,7 @@ public class ObjectAwareness extends Service { * @param object the object to remove */ public void remove(SWGObject object) { - if (object instanceof CreatureObject) - DebugUtilities.printPlayerCharacterDebug(this, (CreatureObject) object, "Removing"); - Location l = object.getLocation(); - if (invalidLocation(l)) - return; - QuadTree tree = getTree(l); - synchronized (tree) { - tree.remove(l.getX(), l.getZ(), object); - } + removeFromLocation(object, object.getLocation()); } /** @@ -321,6 +315,27 @@ public class ObjectAwareness extends Service { obj.updateObjectAwareness(objectAware); } + private void moveFromOld(SWGObject object, Location oldLocation) { + if (object.getParent() != null) { + object.getParent().removeObject(object); // Moving from cell to world + object.sendObserversAndSelf(new UpdateContainmentMessage(object.getObjectId(), 0, object.getSlotArrangement())); + } else { + removeFromLocation(object, oldLocation); // World to World + } + add(object); + } + + private void removeFromLocation(SWGObject object, Location l) { + if (object instanceof CreatureObject) + DebugUtilities.printPlayerCharacterDebug(this, (CreatureObject) object, "Removing"); + if (invalidLocation(l)) + return; + QuadTree tree = getTree(l); + synchronized (tree) { + tree.remove(l.getX(), l.getZ(), object); + } + } + private QuadTree getTree(Location l) { return quadTree.get(l.getTerrain()); }