Merge pull request #950 from DarkflameUniverse/vanity-ldf-reading

Add ldf controlls to vanity npc tools
This commit is contained in:
Gie "Max" Vanommeslaeghe 2023-01-11 20:22:21 +01:00 committed by GitHub
commit 45d739499a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 59 deletions

View File

@ -65,17 +65,21 @@ void VanityUtilities::SpawnVanity() {
npcIndex = GeneralUtils::GenerateRandomNumber<uint32_t>(0, npcList.size() - 1);
}
const auto& npc = npcList[npcIndex];
auto& npc = npcList[npcIndex];
taken.push_back(npcIndex);
// Spawn the NPC
std::vector<LDFBaseData*> data = { new LDFData<std::vector<std::u16string>>(
u"syncLDF", { u"custom_script_client" }),
new LDFData<std::u16string>(u"custom_script_client", u"scripts\\ai\\SPEC\\MISSION_MINIGAME_CLIENT.lua") };
Game::logger->Log("VanityUtilities", "ldf size is %i", npc.ldf.size());
if (npc.ldf.empty()) {
npc.ldf = {
new LDFData<std::vector<std::u16string>>(u"syncLDF", { u"custom_script_client" }),
new LDFData<std::u16string>(u"custom_script_client", u"scripts\\ai\\SPEC\\MISSION_MINIGAME_CLIENT.lua")
};
}
// Spawn the NPC
auto* npcEntity = SpawnNPC(npc.m_LOT, npc.m_Name, location.m_Position, location.m_Rotation, npc.m_Equipment, data);
auto* npcEntity = SpawnNPC(npc.m_LOT, npc.m_Name, location.m_Position, location.m_Rotation, npc.m_Equipment, npc.ldf);
npcEntity->SetVar<std::vector<std::string>>(u"chats", m_PartyPhrases);
@ -86,11 +90,11 @@ void VanityUtilities::SpawnVanity() {
}
// Loop through all NPCs
for (const auto& pair : m_NPCs) {
if (pair.m_Locations.find(Game::server->GetZoneID()) == pair.m_Locations.end())
for (auto& npc : m_NPCs) {
if (npc.m_Locations.find(Game::server->GetZoneID()) == npc.m_Locations.end())
continue;
const std::vector<VanityNPCLocation>& locations = pair.m_Locations.at(Game::server->GetZoneID());
const std::vector<VanityNPCLocation>& locations = npc.m_Locations.at(Game::server->GetZoneID());
// Pick a random location
const auto& location = locations[GeneralUtils::GenerateRandomNumber<int>(
@ -101,27 +105,30 @@ void VanityUtilities::SpawnVanity() {
continue;
}
std::vector<LDFBaseData*> data = { new LDFData<std::vector<std::u16string>>(
u"syncLDF", { u"custom_script_client" }),
new LDFData<std::u16string>(u"custom_script_client", u"scripts\\ai\\SPEC\\MISSION_MINIGAME_CLIENT.lua") };
if (npc.ldf.empty()) {
npc.ldf = {
new LDFData<std::vector<std::u16string>>(u"syncLDF", { u"custom_script_client" }),
new LDFData<std::u16string>(u"custom_script_client", u"scripts\\ai\\SPEC\\MISSION_MINIGAME_CLIENT.lua")
};
}
// Spawn the NPC
auto* npc = SpawnNPC(pair.m_LOT, pair.m_Name, location.m_Position, location.m_Rotation, pair.m_Equipment, data);
auto* npcEntity = SpawnNPC(npc.m_LOT, npc.m_Name, location.m_Position, location.m_Rotation, npc.m_Equipment, npc.ldf);
npc->SetVar<std::vector<std::string>>(u"chats", pair.m_Phrases);
npcEntity->SetVar<std::vector<std::string>>(u"chats", npc.m_Phrases);
auto* scriptComponent = npc->GetComponent<ScriptComponent>();
auto* scriptComponent = npcEntity->GetComponent<ScriptComponent>();
if (scriptComponent != nullptr) {
scriptComponent->SetScript(pair.m_Script);
scriptComponent->SetScript(npc.m_Script);
scriptComponent->SetSerialized(false);
for (const auto& pair : pair.m_Flags) {
npc->SetVar<bool>(GeneralUtils::ASCIIToUTF16(pair.first), pair.second);
for (const auto& npc : npc.m_Flags) {
npcEntity->SetVar<bool>(GeneralUtils::ASCIIToUTF16(npc.first), npc.second);
}
}
SetupNPCTalk(npc);
SetupNPCTalk(npcEntity);
}
if (zoneID == 1200) {
@ -266,10 +273,7 @@ void VanityUtilities::ParseXML(const std::string& file) {
// Get the NPC name
auto* name = npc->Attribute("name");
if (name == nullptr) {
Game::logger->Log("VanityUtilities", "Failed to parse NPC name");
continue;
}
if (!name) name = "";
// Get the NPC lot
auto* lot = npc->Attribute("lot");
@ -281,16 +285,11 @@ void VanityUtilities::ParseXML(const std::string& file) {
// Get the equipment
auto* equipment = npc->FirstChildElement("equipment");
if (equipment == nullptr) {
Game::logger->Log("VanityUtilities", "Failed to parse NPC equipment");
continue;
}
auto* text = equipment->GetText();
std::vector<LOT> inventory;
if (equipment) {
auto* text = equipment->GetText();
if (text != nullptr) {
std::string equipmentString(text);
@ -300,45 +299,54 @@ void VanityUtilities::ParseXML(const std::string& file) {
inventory.push_back(std::stoi(item));
}
}
}
// Get the phrases
auto* phrases = npc->FirstChildElement("phrases");
if (phrases == nullptr) {
Game::logger->Log("VanityUtilities", "Failed to parse NPC phrases");
continue;
}
std::vector<std::string> phraseList;
std::vector<std::string> phraseList = {};
if (phrases) {
for (auto* phrase = phrases->FirstChildElement("phrase"); phrase != nullptr;
phrase = phrase->NextSiblingElement("phrase")) {
// Get the phrase
auto* text = phrase->GetText();
if (text == nullptr) {
Game::logger->Log("VanityUtilities", "Failed to parse NPC phrase");
continue;
}
phraseList.push_back(text);
}
}
// Get the script
auto* scriptElement = npc->FirstChildElement("script");
std::string scriptName;
std::string scriptName = "";
if (scriptElement != nullptr) {
auto* scriptNameAttribute = scriptElement->Attribute("name");
if (scriptNameAttribute == nullptr) {
Game::logger->Log("VanityUtilities", "Failed to parse NPC script name");
continue;
if (scriptNameAttribute) scriptName = scriptNameAttribute;
}
scriptName = scriptNameAttribute;
auto* ldfElement = npc->FirstChildElement("ldf");
std::vector<std::u16string> keys = {};
std::vector<LDFBaseData*> ldf = {};
if(ldfElement) {
for (auto* entry = ldfElement->FirstChildElement("entry"); entry != nullptr;
entry = entry->NextSiblingElement("entry")) {
// Get the ldf data
auto* data = entry->Attribute("data");
if (!data) continue;
LDFBaseData* ldfData = LDFBaseData::DataFromString(data);
keys.push_back(ldfData->GetKey());
ldf.push_back(ldfData);
}
}
if (!keys.empty()) ldf.push_back(new LDFData<std::vector<std::u16string>>(u"syncLDF", keys));
VanityNPC npcData;
npcData.m_Name = name;
@ -346,6 +354,7 @@ void VanityUtilities::ParseXML(const std::string& file) {
npcData.m_Equipment = inventory;
npcData.m_Phrases = phraseList;
npcData.m_Script = scriptName;
npcData.ldf = ldf;
// Get flags
auto* flags = npc->FirstChildElement("flags");

View File

@ -20,6 +20,7 @@ struct VanityNPC
std::string m_Script;
std::map<std::string, bool> m_Flags;
std::map<uint32_t, std::vector<VanityNPCLocation>> m_Locations;
std::vector<LDFBaseData*> ldf;
};
struct VanityParty