From 715abf144419233ef8065cc8f4404f8b13eace96 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Tue, 2 May 2023 09:10:41 -0400 Subject: [PATCH] Building Location rotations are now a quaternion. --- src/engine/devcmd/cmds/SlotTestCmd.java | 2 +- src/engine/gameManager/BuildingManager.java | 18 +++++- src/engine/objects/Building.java | 2 +- src/engine/objects/BuildingLocation.java | 63 ++++----------------- src/engine/objects/Mob.java | 13 ++--- 5 files changed, 35 insertions(+), 63 deletions(-) diff --git a/src/engine/devcmd/cmds/SlotTestCmd.java b/src/engine/devcmd/cmds/SlotTestCmd.java index 0c60cce0..d096b947 100644 --- a/src/engine/devcmd/cmds/SlotTestCmd.java +++ b/src/engine/devcmd/cmds/SlotTestCmd.java @@ -37,7 +37,7 @@ public class SlotTestCmd extends AbstractDevCmd { Building building = (Building)target; for (BuildingLocation buildingLocation : BuildingManager._slotLocations.get(building.meshUUID)) - outString += buildingLocation.getSlot() + buildingLocation.getLoc().toString() + "\r\n"; + outString += buildingLocation.getSlot() + buildingLocation.getLocation().toString() + "\r\n"; outString += "\r\nNeext Available Slot: " + BuildingManager.getAvailableSlot(building); diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index ba4c106d..280609aa 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -18,6 +18,7 @@ import engine.job.JobContainer; import engine.job.JobScheduler; import engine.jobs.UpgradeBuildingJob; import engine.math.Bounds; +import engine.math.Quaternion; import engine.math.Vector3fImmutable; import engine.net.client.msg.ErrorPopupMsg; import engine.objects.*; @@ -67,7 +68,22 @@ public enum BuildingManager { Logger.error("Invalid slot for building: " + building.getObjectUUID()); } - return buildingLocation.getLoc(); + return buildingLocation.getLocation(); + } + + public static Quaternion getSlotRotation(Building building, int slot) { + + if (slot == -1) + return new Quaternion(); + + BuildingLocation buildingLocation; + buildingLocation = _slotLocations.get(building.meshUUID).get(slot - 1); // array index + + if (buildingLocation == null) { + Logger.error("Invalid slot rotation for building: " + building.getObjectUUID()); + } + + return buildingLocation.getRotation(); } public static boolean playerCanManage(PlayerCharacter player, Building building) { diff --git a/src/engine/objects/Building.java b/src/engine/objects/Building.java index 95e7dc08..0d255c0c 100644 --- a/src/engine/objects/Building.java +++ b/src/engine/objects/Building.java @@ -1285,7 +1285,7 @@ public class Building extends AbstractWorldObject { stuckLocations.isEmpty()) return this.getLoc(); - stuckLocation = stuckLocations.get(ThreadLocalRandom.current().nextInt(stuckLocations.size())).getLoc(); + stuckLocation = stuckLocations.get(ThreadLocalRandom.current().nextInt(stuckLocations.size())).getLocation(); return stuckLocation; } diff --git a/src/engine/objects/BuildingLocation.java b/src/engine/objects/BuildingLocation.java index e4a03826..c3b54ca4 100644 --- a/src/engine/objects/BuildingLocation.java +++ b/src/engine/objects/BuildingLocation.java @@ -11,6 +11,7 @@ package engine.objects; import engine.gameManager.BuildingManager; import engine.gameManager.DbManager; +import engine.math.Quaternion; import engine.math.Vector3fImmutable; import java.sql.ResultSet; @@ -25,9 +26,8 @@ public class BuildingLocation extends AbstractGameObject { private final int type; private final int slot; private final int unknown; - private final Vector3fImmutable loc; - private final Vector3fImmutable rot; - private final float w; + private final Vector3fImmutable location; + private final Quaternion rotation; /** @@ -39,9 +39,8 @@ public class BuildingLocation extends AbstractGameObject { this.type = rs.getInt("type"); this.slot = rs.getInt("slot"); this.unknown = rs.getInt("unknown"); - this.loc = new Vector3fImmutable(rs.getFloat("locX"), rs.getFloat("locY"), rs.getFloat("locZ")); - this.rot = new Vector3fImmutable(rs.getFloat("rotX"), rs.getFloat("rotY"), rs.getFloat("rotZ")); - this.w = rs.getFloat("w"); + this.location = new Vector3fImmutable(rs.getFloat("locX"), rs.getFloat("locY"), rs.getFloat("locZ")); + this.rotation = new Quaternion(rs.getFloat("rotX"), rs.getFloat("rotY"), rs.getFloat("rotZ"), rs.getFloat("w")); } /* @@ -52,24 +51,6 @@ public class BuildingLocation extends AbstractGameObject { return this.buildingUUID; } - public Vector3fImmutable rotatedLoc() { - Vector3fImmutable convertLoc = null; - - - double rotY = 2.0 * Math.asin(this.rot.y); - - - // handle building rotation - - convertLoc = new Vector3fImmutable( - (float) ((loc.z * Math.sin(rotY)) + (loc.x * Math.cos(rotY))), - loc.y, - (float) ((loc.z * Math.cos(rotY)) - (loc.x * Math.sin(rotY)))); - - return convertLoc; - - } - public int getType() { return this.type; } @@ -83,42 +64,22 @@ public class BuildingLocation extends AbstractGameObject { } public float getLocX() { - return this.loc.x; + return this.location.x; } public float getLocY() { - return this.loc.y; + return this.location.y; } - public float getLocZ() { - return this.loc.z; - } - - public float getRotX() { - return this.rot.x; - } - - public float getRotY() { - return this.rot.y; - } - - public float getRotZ() { - return this.rot.z; - } - - public float getW() { - return this.w; - } - public Vector3fImmutable getLoc() { - return this.loc; + public Vector3fImmutable getLocation() { + return this.location; } - public Vector3fImmutable getRot() { - return this.rot; + public Quaternion getRotation() { + return this.rotation; } - @Override public void updateDatabase() { } @@ -141,7 +102,7 @@ public class BuildingLocation extends AbstractGameObject { break; } - // Add location to the collection in BuildingManager + // Add location to collection in BuildingManager if (locationCollection.containsKey(buildingLocation.buildingUUID)) locationCollection.get(buildingLocation.buildingUUID).add(buildingLocation); diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index 7065623c..46651af5 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -265,16 +265,16 @@ public class Mob extends AbstractIntelligenceAgent { this.notEnemy = EnumBitSet.asEnumBitSet(rs.getLong("notEnemy"), Enum.MonsterType.class); this.enemy = EnumBitSet.asEnumBitSet(rs.getLong("enemy"), Enum.MonsterType.class); this.firstName = rs.getString("mob_name"); - if (this.firstName.isEmpty()) { + + if (this.firstName.isEmpty()) this.firstName = this.mobBase.getFirstName(); - } + if (this.contract != null) { this.equipmentSetID = this.contract.getEquipmentSet(); this.lastName = this.getContract().getName(); - } else { + } else this.equipmentSetID = rs.getInt("equipmentSet"); - } if (rs.getString("fsm").length() > 1) this.BehaviourType = MobBehaviourType.valueOf(rs.getString("fsm")); @@ -370,11 +370,6 @@ public class Mob extends AbstractIntelligenceAgent { writer.putFloat(1.0f); } - // Location serialization matches NPC - - if (mob.region != null) - writer.putVector3f(ZoneManager.convertWorldToLocal(mob.building, mob.getLoc())); - else writer.putVector3f(mob.getLoc()); //Rotation