mirror of
https://github.com/ProjectSWGCore/NGECore2.git
synced 2026-07-31 01:15:57 -04:00
more work on AI, added odb for object id(should hopefully fix object id duplicates), fixed tons of bugs
This commit is contained in:
@@ -193,7 +193,7 @@ public class SimulationService implements INetworkDispatch {
|
||||
Vector<SWGObject> childObjects = (Vector<SWGObject>) object.getAttachment("childObjects");
|
||||
if(childObjects != null) {
|
||||
addChildObjects(object, childObjects);
|
||||
object.setAttachment("childObjects", null);
|
||||
//object.setAttachment("childObjects", null);
|
||||
}
|
||||
if(notifyObservers) {
|
||||
Point3D pos = new Point3D(x, 0, y);
|
||||
@@ -303,6 +303,8 @@ public class SimulationService implements INetworkDispatch {
|
||||
Point3D oldPos;
|
||||
synchronized(object.getMutex()) {
|
||||
newPos = new Point3D(dataTransform.getXPosition(), dataTransform.getYPosition(), dataTransform.getZPosition());
|
||||
if(Float.isNaN(newPos.x) || Float.isNaN(newPos.y) || Float.isNaN(newPos.z))
|
||||
return;
|
||||
oldPos = object.getPosition();
|
||||
//Collection<Client> oldObservers = object.getObservers();
|
||||
//Collection<Client> newObservers = new HashSet<Client>();
|
||||
@@ -396,6 +398,8 @@ public class SimulationService implements INetworkDispatch {
|
||||
CreatureObject object = (CreatureObject) client.getParent();
|
||||
|
||||
Point3D newPos = new Point3D(dataTransform.getXPosition(), dataTransform.getYPosition(), dataTransform.getZPosition());
|
||||
if(Float.isNaN(newPos.x) || Float.isNaN(newPos.y) || Float.isNaN(newPos.z))
|
||||
return;
|
||||
Point3D oldPos = object.getPosition();
|
||||
Quaternion newOrientation = new Quaternion(dataTransform.getWOrientation(), dataTransform.getXOrientation(), dataTransform.getYOrientation(), dataTransform.getZOrientation());
|
||||
|
||||
@@ -469,7 +473,108 @@ public class SimulationService implements INetworkDispatch {
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void moveObject(SWGObject object, Point3D newPosition, Quaternion newOrientation, int movementCounter, float speed, CellObject cell) {
|
||||
|
||||
if(Float.isNaN(newPosition.x) || Float.isNaN(newPosition.y) || Float.isNaN(newPosition.z))
|
||||
return;
|
||||
|
||||
if(cell == null) {
|
||||
|
||||
Point3D oldPos;
|
||||
synchronized(object.getMutex()) {
|
||||
oldPos = object.getPosition();
|
||||
if(object.getContainer() == null)
|
||||
move(object, oldPos.x, oldPos.z, newPosition.x, newPosition.z);
|
||||
object.setPosition(newPosition);
|
||||
object.setOrientation(newOrientation);
|
||||
object.setMovementCounter(movementCounter + 1);
|
||||
}
|
||||
if(object.getContainer() != null && newPosition != oldPos) {
|
||||
object.getContainer()._remove(object);
|
||||
add(object, newPosition.x, newPosition.z);
|
||||
}
|
||||
|
||||
UpdateTransformMessage utm = new UpdateTransformMessage(object.getObjectID(), (short) (newPosition.x * 4 + 0.5), (short) (newPosition.y * 4 + 0.5), (short) (newPosition.z * 4 + 0.5), movementCounter + 1, getSpecialDirection(newOrientation), speed);
|
||||
|
||||
List<SWGObject> newAwareObjects = get(object.getPlanet(), newPosition.x, newPosition.z, 512);
|
||||
ArrayList<SWGObject> oldAwareObjects = new ArrayList<SWGObject>(object.getAwareObjects());
|
||||
Collection<SWGObject> updateAwareObjects = CollectionUtils.intersection(oldAwareObjects, newAwareObjects);
|
||||
object.notifyObservers(utm, false);
|
||||
|
||||
for(int i = 0; i < oldAwareObjects.size(); i++) {
|
||||
SWGObject obj = oldAwareObjects.get(i);
|
||||
if(!updateAwareObjects.contains(obj) && obj != object && obj.getWorldPosition().getDistance2D(newPosition) > 200 && obj.isInQuadtree() /*&& obj.getParentId() == 0*/) {
|
||||
if(obj.getAttachment("bigSpawnRange") != null && obj.getWorldPosition().getDistance2D(newPosition) < 512)
|
||||
continue;
|
||||
object.makeUnaware(obj);
|
||||
if(obj.getClient() != null)
|
||||
obj.makeUnaware(object);
|
||||
} else if(obj != object && obj.getWorldPosition().getDistance2D(newPosition) > 200 && obj.isInQuadtree() && obj.getAttachment("bigSpawnRange") == null) {
|
||||
object.makeUnaware(obj);
|
||||
if(obj.getClient() != null)
|
||||
obj.makeUnaware(object);
|
||||
}
|
||||
}
|
||||
for(int i = 0; i < newAwareObjects.size(); i++) {
|
||||
SWGObject obj = newAwareObjects.get(i);
|
||||
//System.out.println(obj.getTemplate());
|
||||
if(!updateAwareObjects.contains(obj) && obj != object && !object.getAwareObjects().contains(obj) && obj.getContainer() != object && obj.isInQuadtree()) {
|
||||
if(obj.getAttachment("bigSpawnRange") == null && obj.getWorldPosition().getDistance2D(newPosition) > 200)
|
||||
continue;
|
||||
object.makeAware(obj);
|
||||
if(obj.getClient() != null)
|
||||
obj.makeAware(object);
|
||||
}
|
||||
}
|
||||
|
||||
checkForCollidables(object);
|
||||
MoveEvent event = new MoveEvent();
|
||||
event.object = object;
|
||||
object.getEventBus().publish(event);
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
newPosition.setCell(cell);
|
||||
Point3D oldPos = object.getPosition();
|
||||
object.setPosition(newPosition);
|
||||
object.setOrientation(newOrientation);
|
||||
object.setMovementCounter(movementCounter + 1);
|
||||
|
||||
UpdateTransformWithParentMessage utm = new UpdateTransformWithParentMessage(object.getObjectID(), cell.getObjectID(), (short) (newPosition.x * 8 + 0.5), (short) (newPosition.y * 8 + 0.5), (short) (newPosition.z * 8 + 0.5), movementCounter + 1, getSpecialDirection(newOrientation), speed);
|
||||
|
||||
if(object.getContainer() != cell) {
|
||||
remove(object, oldPos.x, oldPos.z);
|
||||
if(object.getContainer() != null)
|
||||
object.getContainer()._remove(object);
|
||||
cell._add(object);
|
||||
}
|
||||
object.notifyObservers(utm, false);
|
||||
|
||||
checkForCollidables(object);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public byte getSpecialDirection(Quaternion orientation) {
|
||||
byte movementAngle = (byte) 0.0f;
|
||||
float wOrient = orientation.w;
|
||||
float yOrient = orientation.y;
|
||||
float sq = (float) Math.sqrt(1- (orientation.w * orientation.w));
|
||||
|
||||
if (sq != 0) {
|
||||
if (orientation.w > 0 && orientation.y < 0) {
|
||||
wOrient *= -1;
|
||||
yOrient *= -1;
|
||||
}
|
||||
movementAngle = (byte) ((yOrient / sq) * (2 * Math.acos(wOrient) / 0.06283f));
|
||||
}
|
||||
|
||||
return movementAngle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
// TODO Auto-generated method stub
|
||||
@@ -545,6 +650,28 @@ public class SimulationService implements INetworkDispatch {
|
||||
return new Ray(origin, direction);
|
||||
|
||||
}
|
||||
|
||||
public Point3D convertPointToModelSpace(Point3D point, SWGObject object) {
|
||||
|
||||
Point3D position = object.getPosition();
|
||||
|
||||
WB_M44 translateMatrix = new WB_M44(1, 0, 0, position.x, 0, 1, 0, position.y, 0, 0, 1, position.z, 0, 0, 0, 1);
|
||||
|
||||
float radians = object.getRadians();
|
||||
float sin = (float) Math.sin(radians);
|
||||
float cos = (float) Math.cos(radians);
|
||||
|
||||
WB_M44 rotationMatrix = new WB_M44(cos, 0, sin, 0, 0, 1, 0, 0, -sin, 0, cos, 0, 0, 0, 0, 1);
|
||||
|
||||
WB_M44 modelSpace = translateMatrix.mult(rotationMatrix).inverse();
|
||||
|
||||
float x = (float) (modelSpace.m11 * point.x + modelSpace.m12 * point.y + modelSpace.m13 * point.z + modelSpace.m14);
|
||||
float y = (float) (modelSpace.m21 * point.x + modelSpace.m22 * point.y + modelSpace.m23 * point.z + modelSpace.m24);
|
||||
float z = (float) (modelSpace.m31 * point.x + modelSpace.m32 * point.y + modelSpace.m33 * point.z + modelSpace.m34);
|
||||
|
||||
return new Point3D(x, y, z);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Moved this to ConnectionService which will disconnect them
|
||||
@@ -557,7 +684,7 @@ public class SimulationService implements INetworkDispatch {
|
||||
* and continues sending packets.
|
||||
*/
|
||||
public void handleDisconnect(final IoSession session) {
|
||||
Client client = core.getClient(session);
|
||||
final Client client = core.getClient(session);
|
||||
|
||||
if(client == null)
|
||||
return;
|
||||
@@ -565,11 +692,11 @@ public class SimulationService implements INetworkDispatch {
|
||||
if(client.getParent() == null)
|
||||
return;
|
||||
|
||||
CreatureObject object = (CreatureObject) client.getParent();
|
||||
final CreatureObject object = (CreatureObject) client.getParent();
|
||||
PlayerObject ghost = (PlayerObject) object.getSlottedObject("ghost");
|
||||
|
||||
//session.suspendWrite();
|
||||
|
||||
final long objectId = object.getObjectID();
|
||||
|
||||
if(!ghost.isSet(PlayerFlags.LD))
|
||||
ghost.toggleFlag(PlayerFlags.LD);
|
||||
@@ -582,9 +709,11 @@ public class SimulationService implements INetworkDispatch {
|
||||
ScheduledFuture<?> disconnectTask = scheduler.schedule(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
core.connectionService.disconnect(session);
|
||||
if(core.objectService.getObject(objectId).getAttachment("disconnectTask") != null)
|
||||
core.connectionService.disconnect(client);
|
||||
}
|
||||
}, 5, TimeUnit.MINUTES);
|
||||
core.removeClient(session);
|
||||
|
||||
object.setAttachment("disconnectTask", disconnectTask);
|
||||
|
||||
@@ -626,7 +755,7 @@ public class SimulationService implements INetworkDispatch {
|
||||
object.playEffectObject("clienteffect/skill_granted.cef", "");
|
||||
object.playMusic("sound/music_acq_bountyhunter.snd");
|
||||
core.skillService.addSkill(object, ghost.getProfessionWheelPosition());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void transferToPlanet(SWGObject object, Planet planet, Point3D newPos, Quaternion newOrientation, SWGObject newParent) {
|
||||
|
||||
Reference in New Issue
Block a user