mirror of
https://github.com/ProjectSWGCore/Holocore.git
synced 2026-07-30 00:15:50 -04:00
Added additional output on init, and Added null check to createObject
This commit is contained in:
@@ -5,6 +5,7 @@ import intents.swgobject_events.SWGObjectEventIntent;
|
||||
import intents.swgobject_events.SWGObjectMovedIntent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -24,6 +25,8 @@ import network.packets.swg.zone.object_controller.ObjectController;
|
||||
import resources.Location;
|
||||
import resources.Race;
|
||||
import resources.Terrain;
|
||||
import resources.client_info.ClientFactory;
|
||||
import resources.client_info.visitors.ObjectData;
|
||||
import resources.control.Intent;
|
||||
import resources.control.Manager;
|
||||
import resources.objects.SWGObject;
|
||||
@@ -43,6 +46,8 @@ public class ObjectManager extends Manager {
|
||||
|
||||
private static final double AWARE_RANGE = 200;
|
||||
|
||||
private ClientFactory clientFac;
|
||||
|
||||
private ObjectDatabase<SWGObject> objects;
|
||||
private Map <String, QuadTree <SWGObject>> quadTree;
|
||||
private long maxObjectId;
|
||||
@@ -61,6 +66,7 @@ public class ObjectManager extends Manager {
|
||||
quadTree.put(t.getFile(), new QuadTree<SWGObject>(-5000, -5000, 5000, 5000));
|
||||
}
|
||||
objects.loadToCache();
|
||||
long startLoad = System.nanoTime();
|
||||
System.out.println("ObjectManager: Loading " + objects.size() + " objects from ObjectDatabase...");
|
||||
objects.traverse(new Traverser<SWGObject>() {
|
||||
@Override
|
||||
@@ -69,7 +75,6 @@ public class ObjectManager extends Manager {
|
||||
if (l.getTerrain() != null) {
|
||||
QuadTree <SWGObject> tree = quadTree.get(l.getTerrain().getFile());
|
||||
if (tree != null) {
|
||||
System.out.println(l.getX() + ", " + l.getZ());
|
||||
tree.put(l.getX(), l.getZ(), obj);
|
||||
} else {
|
||||
System.err.println("ObjectManager: Unable to load QuadTree for object " + obj.getObjectId() + " and terrain: " + l.getTerrain());
|
||||
@@ -80,6 +85,10 @@ public class ObjectManager extends Manager {
|
||||
}
|
||||
}
|
||||
});
|
||||
double loadTime = (System.nanoTime() - startLoad) / 1E6;
|
||||
System.out.printf("ObjectManager: Finished loading %d objects. Time: %fms%n", objects.size(), loadTime);
|
||||
clientFac = new ClientFactory();
|
||||
|
||||
return super.initialize();
|
||||
}
|
||||
|
||||
@@ -99,7 +108,7 @@ public class ObjectManager extends Manager {
|
||||
ObjectController controller = (ObjectController) gpi.getPacket();
|
||||
if (controller.getControllerData() instanceof DataTransform) {
|
||||
DataTransform trans = (DataTransform) controller.getControllerData();
|
||||
SWGObject obj = getObject(trans.getObjectId());
|
||||
SWGObject obj = getObject(controller.getObjectId());
|
||||
Location oldLocation = obj.getLocation();
|
||||
Location newLocation = trans.getLocation();
|
||||
newLocation.setTerrain(oldLocation.getTerrain());
|
||||
@@ -123,6 +132,11 @@ public class ObjectManager extends Manager {
|
||||
synchronized (objects) {
|
||||
long objectId = getNextObjectId();
|
||||
SWGObject obj = createObjectFromTemplate(objectId, template);
|
||||
if (obj == null) {
|
||||
System.err.println("ObjectManager: Unable to create object with template " + template);
|
||||
return null;
|
||||
}
|
||||
addObjectAttributes(obj, template);
|
||||
obj.setTemplate(template);
|
||||
obj.setLocation(l);
|
||||
moveObject(obj, null, l);
|
||||
@@ -143,18 +157,28 @@ public class ObjectManager extends Manager {
|
||||
quadTree.get(oldLocation.getTerrain().getFile()).remove(x, y, obj);
|
||||
}
|
||||
if (newLocation != null && newLocation.getTerrain() != null) { // Add to QuadTree, update awareness
|
||||
obj.setLocation(newLocation);
|
||||
x = newLocation.getX();
|
||||
y = newLocation.getZ();
|
||||
QuadTree<SWGObject> tree = quadTree.get(newLocation.getTerrain().getFile());
|
||||
tree.put(x, y, obj);
|
||||
for (SWGObject inRange : tree.getWithinRange(x, y, AWARE_RANGE)) {
|
||||
if (inRange.getOwner() != null)
|
||||
if (inRange.getOwner() != null && inRange.getObjectId() != obj.getObjectId() && inRange.getOwner() != obj.getOwner())
|
||||
updatedAware.add(inRange.getOwner());
|
||||
}
|
||||
}
|
||||
System.out.println("Now Aware Of: " + Arrays.toString(updatedAware.toArray(new Player[updatedAware.size()])));
|
||||
obj.updateAwareness(updatedAware);
|
||||
}
|
||||
|
||||
|
||||
private void addObjectAttributes(SWGObject obj, String template) {
|
||||
|
||||
ObjectData attributes = (ObjectData) clientFac.getInfoFromFile(ClientFactory.formatToSharedFile(template));
|
||||
|
||||
obj.setStf((String) attributes.getAttribute("objectName"));
|
||||
obj.setDetailStf((String) attributes.getAttribute("detailedDescription"));
|
||||
}
|
||||
|
||||
private void zoneInCharacter(PlayerManager playerManager, long netId, long characterId) {
|
||||
Player player = playerManager.getPlayerFromNetworkId(netId);
|
||||
if (player != null) {
|
||||
|
||||
Reference in New Issue
Block a user