From ce516f24c0baa0b562cf01caee35c5bbcf24b8b3 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Tue, 2 May 2023 13:08:02 -0400 Subject: [PATCH] Contracted Mob/Npc rotation derived from slot position. --- src/engine/gameManager/BuildingManager.java | 9 +++++---- src/engine/objects/BuildingLocation.java | 10 ++++++++++ src/engine/objects/Mob.java | 10 +++++++++- src/engine/objects/NPC.java | 9 ++++++++- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index 280609aa..95984cb3 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -56,19 +56,20 @@ public enum BuildingManager { return -1; } - public static Vector3fImmutable getSlotLocation(Building building, int slot) { + public static BuildingLocation getSlotLocation(Building building, int slot) { + + BuildingLocation buildingLocation = new BuildingLocation(); if (slot == -1) - return Vector3fImmutable.ZERO; + return buildingLocation; - BuildingLocation buildingLocation; buildingLocation = _slotLocations.get(building.meshUUID).get(slot - 1); // array index if (buildingLocation == null) { Logger.error("Invalid slot for building: " + building.getObjectUUID()); } - return buildingLocation.getLocation(); + return buildingLocation; } public static Quaternion getSlotRotation(Building building, int slot) { diff --git a/src/engine/objects/BuildingLocation.java b/src/engine/objects/BuildingLocation.java index c3b54ca4..4c9c0d6a 100644 --- a/src/engine/objects/BuildingLocation.java +++ b/src/engine/objects/BuildingLocation.java @@ -30,6 +30,16 @@ public class BuildingLocation extends AbstractGameObject { private final Quaternion rotation; + public BuildingLocation() { + + this.buildingUUID = 0; + this.type = 0; + this.slot = 0; + this.unknown = 0; + this.location = Vector3fImmutable.ZERO; + this.rotation = new Quaternion(); + } + /** * ResultSet Constructor */ diff --git a/src/engine/objects/Mob.java b/src/engine/objects/Mob.java index 46651af5..ea8d1f95 100644 --- a/src/engine/objects/Mob.java +++ b/src/engine/objects/Mob.java @@ -20,6 +20,8 @@ import engine.jobs.DeferredPowerJob; import engine.jobs.UpgradeNPCJob; import engine.loot.LootManager; import engine.math.Bounds; +import engine.math.Quaternion; +import engine.math.Vector3f; import engine.math.Vector3fImmutable; import engine.net.ByteBufferWriter; import engine.net.Dispatch; @@ -863,6 +865,7 @@ public class Mob extends AbstractIntelligenceAgent { int slot; Vector3fImmutable slotLocation; + Quaternion slotRotation; if (ConfigManager.serverType.equals(ServerType.LOGINSERVER)) return; @@ -907,10 +910,15 @@ public class Mob extends AbstractIntelligenceAgent { // Override bind and location for this contracted Mobile // derived from BuildingManager slot location data. - slotLocation = BuildingManager.getSlotLocation(building, slot); + slotLocation = BuildingManager.getSlotLocation(building, slot).getLocation(); this.bindLoc = building.getLoc().add(slotLocation); + // Rotate MOB by slot rotation + + slotRotation = BuildingManager.getSlotLocation(building, slot).getRotation(); + this.setRot(new Vector3f(0, slotRotation.y, 0)); + } // Rotate slot position by the building rotation diff --git a/src/engine/objects/NPC.java b/src/engine/objects/NPC.java index ecb1fb8e..cdd5e166 100644 --- a/src/engine/objects/NPC.java +++ b/src/engine/objects/NPC.java @@ -18,6 +18,7 @@ import engine.job.JobContainer; import engine.job.JobScheduler; import engine.jobs.UpgradeNPCJob; import engine.math.Bounds; +import engine.math.Quaternion; import engine.math.Vector3f; import engine.math.Vector3fImmutable; import engine.net.ByteBufferWriter; @@ -319,6 +320,7 @@ public class NPC extends AbstractCharacter { int slot; Vector3fImmutable slotLocation; + Quaternion slotRotation; if (ConfigManager.serverType.equals(ServerType.LOGINSERVER)) return; @@ -358,7 +360,7 @@ public class NPC extends AbstractCharacter { // Override bind and location for this npc derived // from BuildingManager slot location data. - slotLocation = BuildingManager.getSlotLocation(building, slot); + slotLocation = BuildingManager.getSlotLocation(building, slot).getLocation(); this.bindLoc = building.getLoc().add(slotLocation); @@ -368,6 +370,11 @@ public class NPC extends AbstractCharacter { this.loc = new Vector3fImmutable(bindLoc); + // Rotate NPC by slot rotation + + slotRotation = BuildingManager.getSlotLocation(building, slot).getRotation(); + this.setRot(new Vector3f(0, slotRotation.y, 0)); + // Configure region and floor/level for this NPC this.region = BuildingManager.GetRegion(this.building, bindLoc.x, bindLoc.y, bindLoc.z);