add spawner handeling and reload to deleted exsiting entities

spawned don't get deleted yet
This commit is contained in:
Aaron Kimbre 2023-11-09 18:33:39 -06:00
parent 2c9a98313a
commit 3dc7b6ef7f
2 changed files with 120 additions and 8 deletions

View File

@ -15,6 +15,9 @@
#include "Logger.h"
#include "BinaryPathFinder.h"
#include "EntityInfo.h"
#include "Spawner.h"
#include "dZoneManager.h"
#include "../dWorldServer/ObjectIDManager.h"
#include <fstream>
@ -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<float>(0, 1);
rate = GeneralUtils::GenerateRandomNumber<float>(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<std::u16string>(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<std::vector<std::string>>(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<LOT>& inventory, const std::vector<LDFBaseData*>& ldf) {
Spawner* VanityUtilities::SpawnSpawner(LOT lot, const NiPoint3& position, const NiQuaternion& rotation, const std::vector<LDFBaseData*>& 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<LDFData<bool>*>(data)->GetValue();
}
if (data->GetKey() == u"no_timed_spawn") {
spawnInfo.noTimedSpawn = static_cast<LDFData<bool>*>(data)->GetValue();
}
if (data->GetKey() == u"spawnActivator") {
spawnInfo.spawnActivator = static_cast<LDFData<bool>*>(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<LOT>& inventory, const std::vector<LDFBaseData*>& 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);

View File

@ -13,6 +13,7 @@ struct VanityNPCLocation
struct VanityNPC
{
LWOOBJID m_ID = LWOOBJID_EMPTY;
std::string m_Name;
LOT m_LOT;
std::vector<LOT> m_Equipment;
@ -41,6 +42,14 @@ public:
const NiPoint3& position,
const NiQuaternion& rotation,
const std::vector<LOT>& inventory,
const std::vector<LDFBaseData*>& ldf,
const LWOOBJID ID = LWOOBJID_EMPTY
);
static Spawner* SpawnSpawner(
LOT lot,
const NiPoint3& position,
const NiQuaternion& rotation,
const std::vector<LDFBaseData*>& ldf
);