diff --git a/src/engine/devcmd/cmds/SetNPCSlotCmd.java b/src/engine/devcmd/cmds/SetNPCSlotCmd.java deleted file mode 100644 index 5b31eb3d..00000000 --- a/src/engine/devcmd/cmds/SetNPCSlotCmd.java +++ /dev/null @@ -1,80 +0,0 @@ -// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ . -// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌· -// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀ -// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌ -// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀ -// Magicbane Emulator Project © 2013 - 2022 -// www.magicbane.com - - - -package engine.devcmd.cmds; - -import engine.Enum.GameObjectType; -import engine.InterestManagement.WorldGrid; -import engine.devcmd.AbstractDevCmd; -import engine.objects.AbstractGameObject; -import engine.objects.NPC; -import engine.objects.PlayerCharacter; - -public class SetNPCSlotCmd extends AbstractDevCmd { - - public SetNPCSlotCmd() { - super("updateNPCSlot"); - this.addCmdString("changeslot"); - } - - @Override - protected void _doCmd(PlayerCharacter pc, String[] words, - AbstractGameObject target) { - // Arg Count Check - if (words.length != 1) { - this.sendUsage(pc); - return; - } - - if (target.getObjectType() != GameObjectType.NPC){ - this.sendUsage(pc); - return; - } - - NPC npc = (NPC)target; - - - int slot = 0; - try { - slot = Integer.parseInt(words[0]); - - if (!NPC.UpdateSlot(npc, slot)){ - this.throwbackError(pc, "Failed to Update Slot"); - return; - } - - npc.setParentZone(npc.getParentZone()); - WorldGrid.updateObject(npc); - - this.setTarget(pc); //for logging - - // Update all surrounding clients. - - } catch (NumberFormatException e) { - this.throwbackError(pc, "Supplied data: " + words[0] - + " failed to parse to an Integer."); - } catch (Exception e) { - this.throwbackError(pc, - "An unknown exception occurred while attempting to setSlot to " - + words[0]); - } - } - - @Override - protected String _getHelpString() { - return "Sets slot position for an NPC to 'slot'"; - } - - @Override - protected String _getUsageString() { - return "' /changeslot slot'"; - } - -} diff --git a/src/engine/gameManager/BuildingManager.java b/src/engine/gameManager/BuildingManager.java index 72e43752..e85a5f83 100644 --- a/src/engine/gameManager/BuildingManager.java +++ b/src/engine/gameManager/BuildingManager.java @@ -472,9 +472,7 @@ public enum BuildingManager { if (npc == null) return false; - npc.setBuilding(building); - npc.setParentZone(zone); WorldGrid.addObject(npc, contractOwner); return true; @@ -530,16 +528,6 @@ public enum BuildingManager { if (npc == null) return false; - npc.setBindLoc(NpcLoc.x - zone.getAbsX(), NpcLoc.y - zone.getAbsY(), NpcLoc.z - zone.getAbsZ()); - - npc.setBuilding(building); - npc.setParentZone(zone); - - if (NPC.GetNPCProfits(npc) == null) - NPCProfits.CreateProfits(npc); - - WorldGrid.addObject(npc, contractOwner); - return true; } diff --git a/src/engine/gameManager/DevCmdManager.java b/src/engine/gameManager/DevCmdManager.java index c42bf426..74a326d2 100644 --- a/src/engine/gameManager/DevCmdManager.java +++ b/src/engine/gameManager/DevCmdManager.java @@ -135,7 +135,6 @@ public enum DevCmdManager { DevCmdManager.registerDevCmd(new MBDropCmd()); DevCmdManager.registerDevCmd(new AuditHeightMapCmd()); DevCmdManager.registerDevCmd(new UnloadFurnitureCmd()); - DevCmdManager.registerDevCmd(new SetNPCSlotCmd()); DevCmdManager.registerDevCmd(new SetNpcEquipSetCmd()); DevCmdManager.registerDevCmd(new SetBuildingAltitudeCmd()); DevCmdManager.registerDevCmd(new ResetLevelCmd()); diff --git a/src/engine/objects/NPC.java b/src/engine/objects/NPC.java index 38209195..01621289 100644 --- a/src/engine/objects/NPC.java +++ b/src/engine/objects/NPC.java @@ -265,8 +265,6 @@ public class NPC extends AbstractCharacter { this.buildingFloor = (rs.getInt("npc_buildingFloor")); this.buildingLevel = (rs.getInt("npc_buildingLevel")); - this.setParentZone(ZoneManager.getZoneByUUID(this.parentZoneID)); - if (this.contract != null) this.nameOverride = rs.getString("npc_name") + " the " + this.getContract().getName(); else @@ -342,6 +340,48 @@ public class NPC extends AbstractCharacter { private void initializeNPC() { + int slot; + Vector3fImmutable slotLocation = Vector3fImmutable.ZERO; + if (ConfigManager.serverType.equals(ServerType.LOGINSERVER)) + return; + + // NPC Guild owners have no contract + + if (this.contract == null) + return; + + // Configure parent zone adding this NPC to the + // zone collection + + this.parentZone = ZoneManager.getZoneByUUID(this.parentZoneID); + this.parentZone.zoneNPCSet.remove(this); + this.parentZone.zoneNPCSet.add(this); + + // Add this npc to the hireling list. + // if slotted within a building + + if (this.building != null) { + + slot = BuildingManager.getAvailableSlot(building); + + if (slot == -1) + Logger.error("No available slot for NPC: " + this.getObjectUUID()); + + building.getHirelings().put(this, slot); + + this.bindLoc = BuildingManager.getSlotLocation(building, slot); + this.loc = BuildingManager.getSlotLocation(building, slot); + this.region = BuildingManager.GetRegion(this.building, bindLoc.x, bindLoc.y, bindLoc.z); + + if (this.region != null) { + this.buildingFloor = region.getRoom(); + this.buildingLevel = region.getLevel(); + } else { + this.buildingFloor = -1; + this.buildingLevel = -1; + } + } + if (this.mobBase != null) { this.healthMax = this.mobBase.getHealthMax(); this.manaMax = 0; @@ -351,12 +391,9 @@ public class NPC extends AbstractCharacter { this.stamina.set(this.staminaMax); } - // Add this npc to building hireling list if not there yet. - // For some reason the npc is created and initialized twice when - // createMobWithNoID() is called. - - if (this.building != null) - slotNPCinBuilding(); // picks first available free slot + if (this.parentZone.isPlayerCity()) + if (NPC.GetNPCProfits(this) == null) + NPCProfits.CreateProfits(this); //TODO set these correctly later this.rangeHandOne = 8; @@ -372,15 +409,6 @@ public class NPC extends AbstractCharacter { this.charItemManager.load(); } - private void slotNPCinBuilding() { - int maxSlots = 10; - - for (int slot = 1; slot < maxSlots + 1; slot++) - if (!this.building.getHirelings().containsValue(slot)) { - this.building.getHirelings().put(this, slot); - break; - } - } public static NPC getFromCache(int id) { return (NPC) DbManager.getFromCache(GameObjectType.NPC, id); @@ -389,9 +417,6 @@ public class NPC extends AbstractCharacter { /* * Getters */ - public int getLoadID() { - return loadID; - } public boolean isMob() { return this.isMob; @@ -860,91 +885,6 @@ public class NPC extends AbstractCharacter { return 0; } - public void setParentZone(Zone zone) { - - if (ConfigManager.serverType.equals(ServerType.LOGINSERVER)) - return; - - if (this.contract == null) - return; - - //update ZoneManager's zone mpc set - - if (zone != null) { - if (this.parentZone != null) { - if (zone.getObjectUUID() != this.parentZone.getObjectUUID()) { - this.parentZone.zoneNPCSet.remove(this); - zone.zoneNPCSet.add(this); - } - } else { - zone.zoneNPCSet.add(this); - } - } else if (this.parentZone != null) { - this.parentZone.zoneNPCSet.remove(this); - } - - if (this.parentZone == null) - this.parentZone = zone; - - if (!this.parentZone.isPlayerCity()) - this.sellPercent = 1; - - if (this.building != null) { - - BuildingModelBase buildingModel = BuildingModelBase.getModelBase(this.building.getMeshUUID()); - - Vector3fImmutable slotLocation = Vector3fImmutable.ZERO; - - if (buildingModel != null){ - - int putSlot; - BuildingLocation buildingLocation = null; - - //-1 slot means no slot available in building. - putSlot = NPC.getBuildingSlot(this); - - buildingLocation = buildingModel.getSlotLocation(putSlot); - - if (buildingLocation != null){ - slotLocation = buildingLocation.getLoc(); - this.setRot(new Vector3f(buildingLocation.getRot())); - } - - else if (this.building.getHirelings().containsKey(this) && putSlot != -1) - Logger.error("could not slot npc : " + currentID + " in slot " + putSlot + " for building Mesh " + this.building.getMeshUUID()); - } - - Vector3fImmutable buildingWorldLoc = ZoneManager.convertLocalToWorld(this.building, slotLocation); - - //Set floor and level here after building World Location. - - this.region = BuildingManager.GetRegion(this.building, buildingWorldLoc.x, buildingWorldLoc.y, buildingWorldLoc.z); - - if (this.region != null){ - this.buildingFloor = region.getRoom(); - this.buildingLevel = region.getLevel(); - }else{ - this.buildingFloor = -1; - this.buildingLevel = -1; - } - this.setBindLoc(new Vector3fImmutable(buildingWorldLoc.x, buildingWorldLoc.y, buildingWorldLoc.z)); - if (ConfigManager.serverType.equals(ServerType.WORLDSERVER)) - this.setLoc(new Vector3fImmutable(buildingWorldLoc.x, buildingWorldLoc.y, buildingWorldLoc.z)); - - }else{ - this.setBindLoc(new Vector3fImmutable(this.statLat + zone.absX, this.statAlt + zone.absY, this.statLon + zone.absZ)); - if (ConfigManager.serverType.equals(ServerType.WORLDSERVER)) - this.setLoc(new Vector3fImmutable(this.statLat + zone.absX, this.statAlt + zone.absY, this.statLon + zone.absZ)); - } - - //create npc profits - if (this.parentZone != null){ - if (this.parentZone.isPlayerCity()) - if (NPC.GetNPCProfits(this) == null) - NPCProfits.CreateProfits(this); - } - - } @Override public Vector3fImmutable getLoc() { diff --git a/src/engine/server/world/WorldServer.java b/src/engine/server/world/WorldServer.java index 5e1d7fa8..1725936d 100644 --- a/src/engine/server/world/WorldServer.java +++ b/src/engine/server/world/WorldServer.java @@ -565,7 +565,6 @@ public class WorldServer { try { n.setObjectTypeMask(MBServerStatics.MASK_NPC); n.setLoc(n.getLoc()); - n.setParentZone(zone); } catch (Exception e) { Logger.error( n.getObjectUUID() + " returned an Error Message :" + e.getMessage()); }