From 3dc7b6ef7f61fa3fc34bc8762f5dee69503f4a44 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Thu, 9 Nov 2023 18:33:39 -0600 Subject: [PATCH 1/6] add spawner handeling and reload to deleted exsiting entities spawned don't get deleted yet --- dGame/dUtilities/VanityUtilities.cpp | 119 +++++++++++++++++++++++++-- dGame/dUtilities/VanityUtilities.h | 9 ++ 2 files changed, 120 insertions(+), 8 deletions(-) diff --git a/dGame/dUtilities/VanityUtilities.cpp b/dGame/dUtilities/VanityUtilities.cpp index 95436cd30..ad3f22b09 100644 --- a/dGame/dUtilities/VanityUtilities.cpp +++ b/dGame/dUtilities/VanityUtilities.cpp @@ -15,6 +15,9 @@ #include "Logger.h" #include "BinaryPathFinder.h" #include "EntityInfo.h" +#include "Spawner.h" +#include "dZoneManager.h" +#include "../dWorldServer/ObjectIDManager.h" #include @@ -28,6 +31,27 @@ void VanityUtilities::SpawnVanity() { } const uint32_t zoneID = Game::server->GetZoneID(); + if (!m_NPCs.empty()){ + for (auto& npc : m_NPCs) { + if (npc.m_ID == LWOOBJID_EMPTY) continue; + if (npc.m_LOT == 176){ + auto* spawner = Game::zoneManager->GetSpawner(npc.m_ID); + if (!spawner) continue; + Game::zoneManager->RemoveSpawner(spawner->m_Info.spawnerID); + } + auto* entity = Game::entityManager->GetEntity(npc.m_ID); + if (!entity) continue; + entity->Smash(LWOOBJID_EMPTY, eKillType::VIOLENT); + } + m_NPCs.clear(); + } + + if (!m_Parties.empty()){ + m_Parties.clear(); + } + if (!m_PartyPhrases.empty()){ + m_PartyPhrases.clear(); + } ParseXML((BinaryPathFinder::GetBinaryDir() / "vanity/NPC.xml").string()); @@ -53,7 +77,7 @@ void VanityUtilities::SpawnVanity() { // Loop through all locations for (const auto& location : party.m_Locations) { - rate = GeneralUtils::GenerateRandomNumber(0, 1); + rate = GeneralUtils::GenerateRandomNumber(0, 1); if (0.75f < rate) { continue; } @@ -66,7 +90,9 @@ void VanityUtilities::SpawnVanity() { } auto& npc = npcList[npcIndex]; - + // Skip spawners + if (npc.m_LOT == 176) continue; + taken.push_back(npcIndex); // Spawn the NPC @@ -85,7 +111,6 @@ void VanityUtilities::SpawnVanity() { SetupNPCTalk(npcEntity); } } - return; } @@ -111,9 +136,15 @@ void VanityUtilities::SpawnVanity() { new LDFData(u"custom_script_client", u"scripts\\ai\\SPEC\\MISSION_MINIGAME_CLIENT.lua") }; } - + if (npc.m_LOT == 176){ + auto* spawner = SpawnSpawner(npc.m_LOT, location.m_Position, location.m_Rotation, npc.ldf); + if (!spawner) continue; + npc.m_ID = spawner->m_Info.spawnerID; + } // Spawn the NPC - auto* npcEntity = SpawnNPC(npc.m_LOT, npc.m_Name, location.m_Position, location.m_Rotation, npc.m_Equipment, npc.ldf); + auto* npcEntity = SpawnNPC(npc.m_LOT, npc.m_Name, location.m_Position, location.m_Rotation, npc.m_Equipment, npc.ldf, npc.m_ID); + if (!npcEntity) continue; + npc.m_ID = npcEntity->GetObjectID(); if (!npc.m_Phrases.empty()){ npcEntity->SetVar>(u"chats", npc.m_Phrases); @@ -149,13 +180,85 @@ void VanityUtilities::SpawnVanity() { } } -Entity* VanityUtilities::SpawnNPC(LOT lot, const std::string& name, const NiPoint3& position, - const NiQuaternion& rotation, const std::vector& inventory, const std::vector& ldf) { +Spawner* VanityUtilities::SpawnSpawner(LOT lot, const NiPoint3& position, const NiQuaternion& rotation, const std::vector& ldf){ + SpawnerInfo spawnInfo = SpawnerInfo(); + SpawnerNode* node = new SpawnerNode(); + spawnInfo.templateID = lot; + spawnInfo.spawnerID = ObjectIDManager::Instance()->GenerateObjectID(); + spawnInfo.templateScale = 1.0; + node->position = position; + node->rotation = rotation; + node->config = ldf; + spawnInfo.nodes.push_back(node); + for (LDFBaseData* data : node->config) { + if (data) { + if (data->GetKey() == u"spawntemplate") { + spawnInfo.templateID = std::stoi(data->GetValueAsString()); + } + + if (data->GetKey() == u"spawner_node_id") { + node->nodeID = std::stoi(data->GetValueAsString()); + } + + if (data->GetKey() == u"spawner_name") { + spawnInfo.name = data->GetValueAsString(); + } + + if (data->GetKey() == u"max_to_spawn") { + spawnInfo.maxToSpawn = std::stoi(data->GetValueAsString()); + } + + if (data->GetKey() == u"spawner_active_on_load") { + spawnInfo.activeOnLoad = std::stoi(data->GetValueAsString()); + } + + if (data->GetKey() == u"active_on_load") { + spawnInfo.activeOnLoad = std::stoi(data->GetValueAsString()); + } + + if (data->GetKey() == u"respawn") { + if (data->GetValueType() == eLDFType::LDF_TYPE_FLOAT) // Floats are in seconds + { + spawnInfo.respawnTime = std::stof(data->GetValueAsString()); + } else if (data->GetValueType() == eLDFType::LDF_TYPE_U32) // Ints are in ms? + { + spawnInfo.respawnTime = std::stoul(data->GetValueAsString()) / 1000; + } + } + if (data->GetKey() == u"spawnsGroupOnSmash") { + spawnInfo.spawnsOnSmash = std::stoi(data->GetValueAsString()); + } + if (data->GetKey() == u"spawnNetNameForSpawnGroupOnSmash") { + spawnInfo.spawnOnSmashGroupName = data->GetValueAsString(); + } + if (data->GetKey() == u"groupID") { // Load object groups + std::string groupStr = data->GetValueAsString(); + spawnInfo.groups = GeneralUtils::SplitString(groupStr, ';'); + spawnInfo.groups.erase(spawnInfo.groups.end() - 1); + } + if (data->GetKey() == u"no_auto_spawn") { + spawnInfo.noAutoSpawn = static_cast*>(data)->GetValue(); + } + if (data->GetKey() == u"no_timed_spawn") { + spawnInfo.noTimedSpawn = static_cast*>(data)->GetValue(); + } + if (data->GetKey() == u"spawnActivator") { + spawnInfo.spawnActivator = static_cast*>(data)->GetValue(); + } + } + } + auto* spawner = new Spawner(spawnInfo); + Game::zoneManager->AddSpawner(spawnInfo.spawnerID, spawner); + return spawner; +} + +Entity* VanityUtilities::SpawnNPC(LOT lot, const std::string& name, const NiPoint3& position, const NiQuaternion& rotation, const std::vector& inventory, const std::vector& ldf, const LWOOBJID ID) { EntityInfo info; info.lot = lot; info.pos = position; info.rot = rotation; - info.spawnerID = Game::entityManager->GetZoneControlEntity()->GetObjectID(); + if (ID == LWOOBJID_EMPTY) info.spawnerID = Game::entityManager->GetZoneControlEntity()->GetObjectID(); + else info.spawnerID = ID; info.settings = ldf; auto* entity = Game::entityManager->CreateEntity(info); diff --git a/dGame/dUtilities/VanityUtilities.h b/dGame/dUtilities/VanityUtilities.h index 0cca0abaf..5f639a937 100644 --- a/dGame/dUtilities/VanityUtilities.h +++ b/dGame/dUtilities/VanityUtilities.h @@ -13,6 +13,7 @@ struct VanityNPCLocation struct VanityNPC { + LWOOBJID m_ID = LWOOBJID_EMPTY; std::string m_Name; LOT m_LOT; std::vector m_Equipment; @@ -41,6 +42,14 @@ class VanityUtilities const NiPoint3& position, const NiQuaternion& rotation, const std::vector& inventory, + const std::vector& ldf, + const LWOOBJID ID = LWOOBJID_EMPTY + ); + + static Spawner* SpawnSpawner( + LOT lot, + const NiPoint3& position, + const NiQuaternion& rotation, const std::vector& ldf ); From 6e0779802388d7d8457eb988ae99029dc386a252 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Thu, 9 Nov 2023 18:44:51 -0600 Subject: [PATCH 2/6] try to kill spawners, they don't exist? --- dGame/dUtilities/VanityUtilities.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/dGame/dUtilities/VanityUtilities.cpp b/dGame/dUtilities/VanityUtilities.cpp index ad3f22b09..b5f376c71 100644 --- a/dGame/dUtilities/VanityUtilities.cpp +++ b/dGame/dUtilities/VanityUtilities.cpp @@ -35,9 +35,8 @@ void VanityUtilities::SpawnVanity() { for (auto& npc : m_NPCs) { if (npc.m_ID == LWOOBJID_EMPTY) continue; if (npc.m_LOT == 176){ - auto* spawner = Game::zoneManager->GetSpawner(npc.m_ID); - if (!spawner) continue; - Game::zoneManager->RemoveSpawner(spawner->m_Info.spawnerID); + LOG("Removing spawner %llu", npc.m_ID); + Game::zoneManager->RemoveSpawner(npc.m_ID); } auto* entity = Game::entityManager->GetEntity(npc.m_ID); if (!entity) continue; From 486713613309d1faae440e0bcc39a324edafb005 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Thu, 9 Nov 2023 18:59:43 -0600 Subject: [PATCH 3/6] fix spawners and cleanup --- dGame/dUtilities/VanityUtilities.cpp | 43 ++++++++++++++-------------- dGame/dUtilities/VanityUtilities.h | 3 +- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/dGame/dUtilities/VanityUtilities.cpp b/dGame/dUtilities/VanityUtilities.cpp index b5f376c71..e047eb839 100644 --- a/dGame/dUtilities/VanityUtilities.cpp +++ b/dGame/dUtilities/VanityUtilities.cpp @@ -37,10 +37,11 @@ void VanityUtilities::SpawnVanity() { if (npc.m_LOT == 176){ LOG("Removing spawner %llu", npc.m_ID); Game::zoneManager->RemoveSpawner(npc.m_ID); - } - auto* entity = Game::entityManager->GetEntity(npc.m_ID); - if (!entity) continue; - entity->Smash(LWOOBJID_EMPTY, eKillType::VIOLENT); + } else{ + auto* entity = Game::entityManager->GetEntity(npc.m_ID); + if (!entity) continue; + entity->Smash(LWOOBJID_EMPTY, eKillType::VIOLENT); + } } m_NPCs.clear(); } @@ -139,25 +140,26 @@ void VanityUtilities::SpawnVanity() { auto* spawner = SpawnSpawner(npc.m_LOT, location.m_Position, location.m_Rotation, npc.ldf); if (!spawner) continue; npc.m_ID = spawner->m_Info.spawnerID; - } - // Spawn the NPC - auto* npcEntity = SpawnNPC(npc.m_LOT, npc.m_Name, location.m_Position, location.m_Rotation, npc.m_Equipment, npc.ldf, npc.m_ID); - if (!npcEntity) continue; - npc.m_ID = npcEntity->GetObjectID(); - if (!npc.m_Phrases.empty()){ - npcEntity->SetVar>(u"chats", npc.m_Phrases); + } else { + // Spawn the NPC + auto* npcEntity = SpawnNPC(npc.m_LOT, npc.m_Name, location.m_Position, location.m_Rotation, npc.m_Equipment, npc.ldf); + if (!npcEntity) continue; + npc.m_ID = npcEntity->GetObjectID(); + if (!npc.m_Phrases.empty()){ + npcEntity->SetVar>(u"chats", npc.m_Phrases); - auto* scriptComponent = npcEntity->GetComponent(); + auto* scriptComponent = npcEntity->GetComponent(); - if (scriptComponent && !npc.m_Script.empty()) { - scriptComponent->SetScript(npc.m_Script); - scriptComponent->SetSerialized(false); + if (scriptComponent && !npc.m_Script.empty()) { + scriptComponent->SetScript(npc.m_Script); + scriptComponent->SetSerialized(false); - for (const auto& npc : npc.m_Flags) { - npcEntity->SetVar(GeneralUtils::ASCIIToUTF16(npc.first), npc.second); + for (const auto& npc : npc.m_Flags) { + npcEntity->SetVar(GeneralUtils::ASCIIToUTF16(npc.first), npc.second); + } } + SetupNPCTalk(npcEntity); } - SetupNPCTalk(npcEntity); } } @@ -251,13 +253,12 @@ Spawner* VanityUtilities::SpawnSpawner(LOT lot, const NiPoint3& position, const return spawner; } -Entity* VanityUtilities::SpawnNPC(LOT lot, const std::string& name, const NiPoint3& position, const NiQuaternion& rotation, const std::vector& inventory, const std::vector& ldf, const LWOOBJID ID) { +Entity* VanityUtilities::SpawnNPC(LOT lot, const std::string& name, const NiPoint3& position, const NiQuaternion& rotation, const std::vector& inventory, const std::vector& ldf) { EntityInfo info; info.lot = lot; info.pos = position; info.rot = rotation; - if (ID == LWOOBJID_EMPTY) info.spawnerID = Game::entityManager->GetZoneControlEntity()->GetObjectID(); - else info.spawnerID = ID; + info.spawnerID = Game::entityManager->GetZoneControlEntity()->GetObjectID(); info.settings = ldf; auto* entity = Game::entityManager->CreateEntity(info); diff --git a/dGame/dUtilities/VanityUtilities.h b/dGame/dUtilities/VanityUtilities.h index 5f639a937..97738c8d6 100644 --- a/dGame/dUtilities/VanityUtilities.h +++ b/dGame/dUtilities/VanityUtilities.h @@ -42,8 +42,7 @@ class VanityUtilities const NiPoint3& position, const NiQuaternion& rotation, const std::vector& inventory, - const std::vector& ldf, - const LWOOBJID ID = LWOOBJID_EMPTY + const std::vector& ldf ); static Spawner* SpawnSpawner( From f727e3951c63bcd178d30a8d7696be1704269054 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Thu, 9 Nov 2023 21:28:52 -0600 Subject: [PATCH 4/6] consolidate code --- dGame/dUtilities/VanityUtilities.cpp | 101 +++++-------------- dGame/dUtilities/VanityUtilities.h | 2 +- dZoneManager/Level.cpp | 139 ++++++++++++++------------- dZoneManager/Level.h | 2 + 4 files changed, 97 insertions(+), 147 deletions(-) diff --git a/dGame/dUtilities/VanityUtilities.cpp b/dGame/dUtilities/VanityUtilities.cpp index e047eb839..d29416203 100644 --- a/dGame/dUtilities/VanityUtilities.cpp +++ b/dGame/dUtilities/VanityUtilities.cpp @@ -18,6 +18,7 @@ #include "Spawner.h" #include "dZoneManager.h" #include "../dWorldServer/ObjectIDManager.h" +#include "Level.h" #include @@ -95,7 +96,6 @@ void VanityUtilities::SpawnVanity() { taken.push_back(npcIndex); - // Spawn the NPC LOG("ldf size is %i", npc.ldf.size()); if (npc.ldf.empty()) { npc.ldf = { @@ -105,10 +105,14 @@ void VanityUtilities::SpawnVanity() { } // Spawn the NPC - auto* npcEntity = SpawnNPC(npc.m_LOT, npc.m_Name, location.m_Position, location.m_Rotation, npc.m_Equipment, npc.ldf); - if (!npc.m_Phrases.empty()) { - npcEntity->SetVar>(u"chats", m_PartyPhrases); - SetupNPCTalk(npcEntity); + if (npc.m_LOT == 176){ + npc.m_ID = SpawnSpawner(npc.m_LOT, location.m_Position, location.m_Rotation, npc.ldf); + } else { + auto* npcEntity = SpawnNPC(npc.m_LOT, npc.m_Name, location.m_Position, location.m_Rotation, npc.m_Equipment, npc.ldf); + if (!npc.m_Phrases.empty()) { + npcEntity->SetVar>(u"chats", m_PartyPhrases); + SetupNPCTalk(npcEntity); + } } } return; @@ -137,9 +141,7 @@ void VanityUtilities::SpawnVanity() { }; } if (npc.m_LOT == 176){ - auto* spawner = SpawnSpawner(npc.m_LOT, location.m_Position, location.m_Rotation, npc.ldf); - if (!spawner) continue; - npc.m_ID = spawner->m_Info.spawnerID; + npc.m_ID = SpawnSpawner(npc.m_LOT, location.m_Position, location.m_Rotation, npc.ldf); } else { // Spawn the NPC auto* npcEntity = SpawnNPC(npc.m_LOT, npc.m_Name, location.m_Position, location.m_Rotation, npc.m_Equipment, npc.ldf); @@ -181,76 +183,19 @@ void VanityUtilities::SpawnVanity() { } } -Spawner* VanityUtilities::SpawnSpawner(LOT lot, const NiPoint3& position, const NiQuaternion& rotation, const std::vector& ldf){ - SpawnerInfo spawnInfo = SpawnerInfo(); - SpawnerNode* node = new SpawnerNode(); - spawnInfo.templateID = lot; - spawnInfo.spawnerID = ObjectIDManager::Instance()->GenerateObjectID(); - spawnInfo.templateScale = 1.0; - node->position = position; - node->rotation = rotation; - node->config = ldf; - spawnInfo.nodes.push_back(node); - for (LDFBaseData* data : node->config) { - if (data) { - if (data->GetKey() == u"spawntemplate") { - spawnInfo.templateID = std::stoi(data->GetValueAsString()); - } - - if (data->GetKey() == u"spawner_node_id") { - node->nodeID = std::stoi(data->GetValueAsString()); - } - - if (data->GetKey() == u"spawner_name") { - spawnInfo.name = data->GetValueAsString(); - } - - if (data->GetKey() == u"max_to_spawn") { - spawnInfo.maxToSpawn = std::stoi(data->GetValueAsString()); - } - - if (data->GetKey() == u"spawner_active_on_load") { - spawnInfo.activeOnLoad = std::stoi(data->GetValueAsString()); - } - - if (data->GetKey() == u"active_on_load") { - spawnInfo.activeOnLoad = std::stoi(data->GetValueAsString()); - } - - if (data->GetKey() == u"respawn") { - if (data->GetValueType() == eLDFType::LDF_TYPE_FLOAT) // Floats are in seconds - { - spawnInfo.respawnTime = std::stof(data->GetValueAsString()); - } else if (data->GetValueType() == eLDFType::LDF_TYPE_U32) // Ints are in ms? - { - spawnInfo.respawnTime = std::stoul(data->GetValueAsString()) / 1000; - } - } - if (data->GetKey() == u"spawnsGroupOnSmash") { - spawnInfo.spawnsOnSmash = std::stoi(data->GetValueAsString()); - } - if (data->GetKey() == u"spawnNetNameForSpawnGroupOnSmash") { - spawnInfo.spawnOnSmashGroupName = data->GetValueAsString(); - } - if (data->GetKey() == u"groupID") { // Load object groups - std::string groupStr = data->GetValueAsString(); - spawnInfo.groups = GeneralUtils::SplitString(groupStr, ';'); - spawnInfo.groups.erase(spawnInfo.groups.end() - 1); - } - if (data->GetKey() == u"no_auto_spawn") { - spawnInfo.noAutoSpawn = static_cast*>(data)->GetValue(); - } - if (data->GetKey() == u"no_timed_spawn") { - spawnInfo.noTimedSpawn = static_cast*>(data)->GetValue(); - } - if (data->GetKey() == u"spawnActivator") { - spawnInfo.spawnActivator = static_cast*>(data)->GetValue(); - } - } - } - auto* spawner = new Spawner(spawnInfo); - Game::zoneManager->AddSpawner(spawnInfo.spawnerID, spawner); - return spawner; +LWOOBJID VanityUtilities::SpawnSpawner(LOT lot, const NiPoint3& position, const NiQuaternion& rotation, const std::vector& ldf){ + SceneObject obj; + obj.lot = lot; + // guratantee we have no collisions + do { + obj.id = ObjectIDManager::Instance()->GenerateObjectID(); + } while(Game::zoneManager->GetSpawner(obj.id)); + obj.position = position; + obj.rotation = rotation; + obj.settings = ldf; + Level::MakeSpawner(obj); + LOG("created spawner %llu", obj.id); + return obj.id; } Entity* VanityUtilities::SpawnNPC(LOT lot, const std::string& name, const NiPoint3& position, const NiQuaternion& rotation, const std::vector& inventory, const std::vector& ldf) { diff --git a/dGame/dUtilities/VanityUtilities.h b/dGame/dUtilities/VanityUtilities.h index 97738c8d6..cff73bce2 100644 --- a/dGame/dUtilities/VanityUtilities.h +++ b/dGame/dUtilities/VanityUtilities.h @@ -45,7 +45,7 @@ class VanityUtilities const std::vector& ldf ); - static Spawner* SpawnSpawner( + static LWOOBJID SpawnSpawner( LOT lot, const NiPoint3& position, const NiQuaternion& rotation, diff --git a/dZoneManager/Level.cpp b/dZoneManager/Level.cpp index 953b11e22..4c83d494a 100644 --- a/dZoneManager/Level.cpp +++ b/dZoneManager/Level.cpp @@ -38,6 +38,76 @@ Level::~Level() { } } +void Level::MakeSpawner(SceneObject obj){ + SpawnerInfo spawnInfo = SpawnerInfo(); + SpawnerNode* node = new SpawnerNode(); + spawnInfo.templateID = obj.lot; + spawnInfo.spawnerID = obj.id; + spawnInfo.templateScale = obj.scale; + node->position = obj.position; + node->rotation = obj.rotation; + node->config = obj.settings; + spawnInfo.nodes.push_back(node); + for (LDFBaseData* data : obj.settings) { + if (data) { + if (data->GetKey() == u"spawntemplate") { + spawnInfo.templateID = std::stoi(data->GetValueAsString()); + } + + if (data->GetKey() == u"spawner_node_id") { + node->nodeID = std::stoi(data->GetValueAsString()); + } + + if (data->GetKey() == u"spawner_name") { + spawnInfo.name = data->GetValueAsString(); + } + + if (data->GetKey() == u"max_to_spawn") { + spawnInfo.maxToSpawn = std::stoi(data->GetValueAsString()); + } + + if (data->GetKey() == u"spawner_active_on_load") { + spawnInfo.activeOnLoad = std::stoi(data->GetValueAsString()); + } + + if (data->GetKey() == u"active_on_load") { + spawnInfo.activeOnLoad = std::stoi(data->GetValueAsString()); + } + + if (data->GetKey() == u"respawn") { + if (data->GetValueType() == eLDFType::LDF_TYPE_FLOAT) // Floats are in seconds + { + spawnInfo.respawnTime = std::stof(data->GetValueAsString()); + } else if (data->GetValueType() == eLDFType::LDF_TYPE_U32) // Ints are in ms? + { + spawnInfo.respawnTime = std::stoul(data->GetValueAsString()) / 1000; + } + } + if (data->GetKey() == u"spawnsGroupOnSmash") { + spawnInfo.spawnsOnSmash = std::stoi(data->GetValueAsString()); + } + if (data->GetKey() == u"spawnNetNameForSpawnGroupOnSmash") { + spawnInfo.spawnOnSmashGroupName = data->GetValueAsString(); + } + if (data->GetKey() == u"groupID") { // Load object groups + std::string groupStr = data->GetValueAsString(); + spawnInfo.groups = GeneralUtils::SplitString(groupStr, ';'); + spawnInfo.groups.erase(spawnInfo.groups.end() - 1); + } + if (data->GetKey() == u"no_auto_spawn") { + spawnInfo.noAutoSpawn = static_cast*>(data)->GetValue(); + } + if (data->GetKey() == u"no_timed_spawn") { + spawnInfo.noTimedSpawn = static_cast*>(data)->GetValue(); + } + if (data->GetKey() == u"spawnActivator") { + spawnInfo.spawnActivator = static_cast*>(data)->GetValue(); + } + } + } + Game::zoneManager->MakeSpawner(spawnInfo); +} + const void Level::PrintAllObjects() { for (std::map::iterator it = m_ChunkHeaders.begin(); it != m_ChunkHeaders.end(); ++it) { if (it->second.id == Level::ChunkTypeID::SceneObjectData) { @@ -230,74 +300,7 @@ void Level::ReadSceneObjectDataChunk(std::istream& file, Header& header) { } if (obj.lot == 176) { //Spawner - SpawnerInfo spawnInfo = SpawnerInfo(); - SpawnerNode* node = new SpawnerNode(); - spawnInfo.templateID = obj.lot; - spawnInfo.spawnerID = obj.id; - spawnInfo.templateScale = obj.scale; - node->position = obj.position; - node->rotation = obj.rotation; - node->config = obj.settings; - spawnInfo.nodes.push_back(node); - for (LDFBaseData* data : obj.settings) { - if (data) { - if (data->GetKey() == u"spawntemplate") { - spawnInfo.templateID = std::stoi(data->GetValueAsString()); - } - - if (data->GetKey() == u"spawner_node_id") { - node->nodeID = std::stoi(data->GetValueAsString()); - } - - if (data->GetKey() == u"spawner_name") { - spawnInfo.name = data->GetValueAsString(); - } - - if (data->GetKey() == u"max_to_spawn") { - spawnInfo.maxToSpawn = std::stoi(data->GetValueAsString()); - } - - if (data->GetKey() == u"spawner_active_on_load") { - spawnInfo.activeOnLoad = std::stoi(data->GetValueAsString()); - } - - if (data->GetKey() == u"active_on_load") { - spawnInfo.activeOnLoad = std::stoi(data->GetValueAsString()); - } - - if (data->GetKey() == u"respawn") { - if (data->GetValueType() == eLDFType::LDF_TYPE_FLOAT) // Floats are in seconds - { - spawnInfo.respawnTime = std::stof(data->GetValueAsString()); - } else if (data->GetValueType() == eLDFType::LDF_TYPE_U32) // Ints are in ms? - { - spawnInfo.respawnTime = std::stoul(data->GetValueAsString()) / 1000; - } - } - if (data->GetKey() == u"spawnsGroupOnSmash") { - spawnInfo.spawnsOnSmash = std::stoi(data->GetValueAsString()); - } - if (data->GetKey() == u"spawnNetNameForSpawnGroupOnSmash") { - spawnInfo.spawnOnSmashGroupName = data->GetValueAsString(); - } - if (data->GetKey() == u"groupID") { // Load object groups - std::string groupStr = data->GetValueAsString(); - spawnInfo.groups = GeneralUtils::SplitString(groupStr, ';'); - spawnInfo.groups.erase(spawnInfo.groups.end() - 1); - } - if (data->GetKey() == u"no_auto_spawn") { - spawnInfo.noAutoSpawn = static_cast*>(data)->GetValue(); - } - if (data->GetKey() == u"no_timed_spawn") { - spawnInfo.noTimedSpawn = static_cast*>(data)->GetValue(); - } - if (data->GetKey() == u"spawnActivator") { - spawnInfo.spawnActivator = static_cast*>(data)->GetValue(); - } - } - } - Spawner* spawner = new Spawner(spawnInfo); - Game::zoneManager->AddSpawner(obj.id, spawner); + MakeSpawner(obj); } else { //Regular object EntityInfo info; info.spawnerID = 0; diff --git a/dZoneManager/Level.h b/dZoneManager/Level.h index 0f8fa72d6..a27326a21 100644 --- a/dZoneManager/Level.h +++ b/dZoneManager/Level.h @@ -53,6 +53,8 @@ class Level { public: Level(Zone* parentZone, const std::string& filepath); ~Level(); + + static void MakeSpawner(SceneObject obj); const void PrintAllObjects(); From 4c3949e5d87614cf5132a77e7d92211087c8b5fb Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Thu, 9 Nov 2023 21:29:29 -0600 Subject: [PATCH 5/6] remove logs --- dGame/dUtilities/VanityUtilities.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/dGame/dUtilities/VanityUtilities.cpp b/dGame/dUtilities/VanityUtilities.cpp index d29416203..10e8c4897 100644 --- a/dGame/dUtilities/VanityUtilities.cpp +++ b/dGame/dUtilities/VanityUtilities.cpp @@ -36,7 +36,6 @@ void VanityUtilities::SpawnVanity() { for (auto& npc : m_NPCs) { if (npc.m_ID == LWOOBJID_EMPTY) continue; if (npc.m_LOT == 176){ - LOG("Removing spawner %llu", npc.m_ID); Game::zoneManager->RemoveSpawner(npc.m_ID); } else{ auto* entity = Game::entityManager->GetEntity(npc.m_ID); @@ -194,7 +193,6 @@ LWOOBJID VanityUtilities::SpawnSpawner(LOT lot, const NiPoint3& position, const obj.rotation = rotation; obj.settings = ldf; Level::MakeSpawner(obj); - LOG("created spawner %llu", obj.id); return obj.id; } From 175b354e68ce723ac877e20e65a47ca54c105f83 Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Fri, 10 Nov 2023 22:01:25 -0600 Subject: [PATCH 6/6] address feedback --- dGame/dUtilities/VanityUtilities.cpp | 31 ++++++++++++---------------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/dGame/dUtilities/VanityUtilities.cpp b/dGame/dUtilities/VanityUtilities.cpp index 10e8c4897..6c0085242 100644 --- a/dGame/dUtilities/VanityUtilities.cpp +++ b/dGame/dUtilities/VanityUtilities.cpp @@ -32,27 +32,22 @@ void VanityUtilities::SpawnVanity() { } const uint32_t zoneID = Game::server->GetZoneID(); - if (!m_NPCs.empty()){ - for (auto& npc : m_NPCs) { - if (npc.m_ID == LWOOBJID_EMPTY) continue; - if (npc.m_LOT == 176){ - Game::zoneManager->RemoveSpawner(npc.m_ID); - } else{ - auto* entity = Game::entityManager->GetEntity(npc.m_ID); - if (!entity) continue; - entity->Smash(LWOOBJID_EMPTY, eKillType::VIOLENT); - } + + for (const auto& npc : m_NPCs) { + if (npc.m_ID == LWOOBJID_EMPTY) continue; + if (npc.m_LOT == 176){ + Game::zoneManager->RemoveSpawner(npc.m_ID); + } else{ + auto* entity = Game::entityManager->GetEntity(npc.m_ID); + if (!entity) continue; + entity->Smash(LWOOBJID_EMPTY, eKillType::VIOLENT); } - m_NPCs.clear(); - } - - if (!m_Parties.empty()){ - m_Parties.clear(); - } - if (!m_PartyPhrases.empty()){ - m_PartyPhrases.clear(); } + m_NPCs.clear(); + m_Parties.clear(); + m_PartyPhrases.clear(); + ParseXML((BinaryPathFinder::GetBinaryDir() / "vanity/NPC.xml").string()); // Loop through all parties