Fixed several object structures and drastically sped up object creation

This commit is contained in:
Obique PSWG
2016-03-25 23:21:16 -05:00
parent 210d6182ac
commit 0fedef77a3
14 changed files with 550 additions and 115 deletions
+62 -10
View File
@@ -35,6 +35,8 @@ import resources.client_info.visitors.ObjectData;
import resources.client_info.visitors.ObjectData.ObjectDataAttribute;
import resources.client_info.visitors.SlotArrangementData;
import resources.client_info.visitors.SlotDescriptorData;
import resources.objects.GameObjectType;
import resources.objects.GameObjectTypeMask;
import resources.objects.SWGObject;
import resources.objects.building.BuildingObject;
import resources.objects.cell.CellObject;
@@ -45,6 +47,7 @@ import resources.objects.guild.GuildObject;
import resources.objects.installation.InstallationObject;
import resources.objects.intangible.IntangibleObject;
import resources.objects.manufacture.ManufactureSchematicObject;
import resources.objects.mission.MissionObject;
import resources.objects.player.PlayerObject;
import resources.objects.resource.ResourceContainerObject;
import resources.objects.ship.ShipObject;
@@ -71,12 +74,14 @@ public final class ObjectCreator {
return null;
if (!template.endsWith(".iff"))
return null;
SWGObject obj = createObjectFromType(objectId, getTemplatePart(template, 1));
ObjectData attributes = (ObjectData) ClientFactory.getInfoFromFile(ClientFactory.formatToSharedFile(template), true);
GameObjectType type = GameObjectType.getTypeFromId((Integer) attributes.getAttribute(ObjectDataAttribute.GAME_OBJECT_TYPE));
SWGObject obj = createObjectFromType(objectId, template, type);
if (obj == null)
return null;
obj.setTemplate(template);
handlePostCreation(obj);
handlePostCreation(obj, attributes);
updateMaxObjectId(objectId);
return obj;
}
@@ -93,7 +98,8 @@ public final class ObjectCreator {
return null;
obj.setTemplate(template);
handlePostCreation(obj);
ObjectData attributes = (ObjectData) ClientFactory.getInfoFromFile(ClientFactory.formatToSharedFile(template), true);
handlePostCreation(obj, attributes);
updateMaxObjectId(objectId);
return obj;
}
@@ -114,7 +120,53 @@ public final class ObjectCreator {
return createObjectFromTemplate(id, template, c);
}
private static SWGObject createObjectFromType(long objectId, String type) {
private static SWGObject createObjectFromType(long objectId, String template, GameObjectType got) {
SWGObject obj;
obj = createFastFromMask(objectId, got.getMask());
if (obj != null)
return obj;
obj = createFastFromType(objectId, got);
if (obj != null)
return obj;
return createSlowFromType(objectId, getTemplatePart(template, 1));
}
private static SWGObject createFastFromType(long objectId, GameObjectType type) {
switch (type) {
case GOT_DATA_MANUFACTURING_SCHEMATIC: return new ManufactureSchematicObject(objectId);
case GOT_MISC_ITEM:
case GOT_MISC_SIGN:
case GOT_MISC_CONTAINER:
case GOT_MISC_CONTAINER_PUBLIC:
case GOT_MISC_CONTAINER_SHIP_LOOT:
case GOT_MISC_CONTAINER_WEARABLE: return new TangibleObject(objectId);
default: return null;
}
}
private static SWGObject createFastFromMask(long objectId, GameObjectTypeMask mask) {
switch (mask) {
case GOTM_BUILDING: return new BuildingObject(objectId);
case GOTM_INSTALLATION: return new InstallationObject(objectId);
case GOTM_RESOURCE_CONTAINER: return new ResourceContainerObject(objectId);
case GOTM_SHIP: return new ShipObject(objectId);
case GOTM_WEAPON: return new WeaponObject(objectId);
case GOTM_ARMOR:
case GOTM_CLOTHING:
case GOTM_COMPONENT:
case GOTM_SHIP_COMPONENT:
case GOTM_TOOL:
case GOTM_JEWELRY:
case GOTM_CHRONICLES:
case GOTM_CYBERNETIC:
case GOTM_TERMINAL:
case GOTM_POWERUP_WEAPON:
case GOTM_VEHICLE: return new TangibleObject(objectId);
default: return null;
}
}
private static SWGObject createSlowFromType(long objectId, String type) {
switch (type) {
case "building": return new BuildingObject(objectId);
case "cell": return new CellObject(objectId);
@@ -125,6 +177,7 @@ public final class ObjectCreator {
case "installation": return new InstallationObject(objectId);
case "intangible": return new IntangibleObject(objectId);
case "manufacture_schematic": return new ManufactureSchematicObject(objectId);
case "mission": return new MissionObject(objectId);
case "mobile": return new CreatureObject(objectId);
case "player": return new PlayerObject(objectId);
case "resource_container": return new ResourceContainerObject(objectId);
@@ -137,15 +190,14 @@ public final class ObjectCreator {
default: System.err.println("Unknown type: " + type); return null;
}
}
private static void handlePostCreation(SWGObject object) {
addObjectAttributes(object, object.getTemplate());
private static void handlePostCreation(SWGObject object, ObjectData attributes) {
addObjectAttributes(object, attributes);
createObjectSlots(object);
object.setGameObjectType(GameObjectType.getTypeFromId((Integer) object.getDataAttribute(ObjectDataAttribute.GAME_OBJECT_TYPE)));
}
private static void addObjectAttributes(SWGObject obj, String template) {
ObjectData attributes = (ObjectData) ClientFactory.getInfoFromFile(ClientFactory.formatToSharedFile(template), true);
private static void addObjectAttributes(SWGObject obj, ObjectData attributes) {
if (attributes == null)
return;