2021-12-05 17:54:36 +00:00
|
|
|
#include "VanityUtilities.h"
|
|
|
|
|
|
|
|
#include "DestroyableComponent.h"
|
|
|
|
#include "EntityManager.h"
|
|
|
|
#include "GameMessages.h"
|
|
|
|
#include "InventoryComponent.h"
|
|
|
|
#include "PhantomPhysicsComponent.h"
|
|
|
|
#include "ProximityMonitorComponent.h"
|
|
|
|
#include "ScriptComponent.h"
|
|
|
|
#include "dCommonVars.h"
|
|
|
|
#include "dConfig.h"
|
|
|
|
#include "dServer.h"
|
|
|
|
#include "tinyxml2.h"
|
2022-07-05 06:00:10 +00:00
|
|
|
#include "Game.h"
|
2023-10-21 23:31:55 +00:00
|
|
|
#include "Logger.h"
|
2022-11-27 11:59:59 +00:00
|
|
|
#include "BinaryPathFinder.h"
|
2023-01-07 05:17:05 +00:00
|
|
|
#include "EntityInfo.h"
|
2023-11-10 00:33:39 +00:00
|
|
|
#include "Spawner.h"
|
|
|
|
#include "dZoneManager.h"
|
2024-01-05 12:31:22 +00:00
|
|
|
#include "ObjectIDManager.h"
|
2023-11-10 03:28:52 +00:00
|
|
|
#include "Level.h"
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
|
2024-02-28 23:16:47 +00:00
|
|
|
namespace {
|
|
|
|
std::vector<VanityObject> objects;
|
|
|
|
std::set<std::string> loadedFiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetupNPCTalk(Entity* npc);
|
|
|
|
void NPCTalk(Entity* npc);
|
|
|
|
void ParseXml(const std::string& file);
|
|
|
|
LWOOBJID SpawnSpawner(const VanityObject& object, const VanityObjectLocation& location);
|
|
|
|
Entity* SpawnObject(const VanityObject& object, const VanityObjectLocation& location);
|
|
|
|
VanityObject* GetObject(const std::string& name);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
void VanityUtilities::SpawnVanity() {
|
2024-02-25 22:59:10 +00:00
|
|
|
const uint32_t zoneID = Game::server->GetZoneID();
|
|
|
|
|
|
|
|
if (zoneID == 1200) {
|
|
|
|
{
|
|
|
|
EntityInfo info;
|
|
|
|
info.lot = 8139;
|
|
|
|
info.pos = { 259.5f, 246.4f, -705.2f };
|
|
|
|
info.rot = { 0.0f, 0.0f, 1.0f, 0.0f };
|
|
|
|
info.spawnerID = Game::entityManager->GetZoneControlEntity()->GetObjectID();
|
2024-02-28 23:16:47 +00:00
|
|
|
info.settings = {
|
|
|
|
new LDFData<bool>(u"hasCustomText", true),
|
|
|
|
new LDFData<std::string>(u"customText", ParseMarkdown((BinaryPathFinder::GetBinaryDir() / "vanity/TESTAMENT.md").string()))
|
|
|
|
};
|
2024-02-25 22:59:10 +00:00
|
|
|
|
|
|
|
auto* entity = Game::entityManager->CreateEntity(info);
|
|
|
|
Game::entityManager->ConstructEntity(entity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-28 23:16:47 +00:00
|
|
|
if (Game::config->GetValue("disable_vanity") == "1") return;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-02-28 23:16:47 +00:00
|
|
|
for (const auto& npc : objects) {
|
2023-11-11 04:01:25 +00:00
|
|
|
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);
|
2023-11-10 00:33:39 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-02-28 23:16:47 +00:00
|
|
|
objects.clear();
|
|
|
|
loadedFiles.clear();
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-02-28 23:16:47 +00:00
|
|
|
ParseXml((BinaryPathFinder::GetBinaryDir() / "vanity/root.xml").string());
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
// Loop through all objects
|
2024-02-28 23:16:47 +00:00
|
|
|
for (auto& object : objects) {
|
2024-02-25 22:59:10 +00:00
|
|
|
if (object.m_Locations.find(Game::server->GetZoneID()) == object.m_Locations.end()) continue;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
const std::vector<VanityObjectLocation>& locations = object.m_Locations.at(Game::server->GetZoneID());
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
// Pick a random location
|
|
|
|
const auto& location = locations[GeneralUtils::GenerateRandomNumber<int>(
|
|
|
|
static_cast<size_t>(0), static_cast<size_t>(locations.size() - 1))];
|
|
|
|
|
|
|
|
float rate = GeneralUtils::GenerateRandomNumber<float>(0, 1);
|
2024-02-25 22:59:10 +00:00
|
|
|
if (location.m_Chance < rate) continue;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
if (object.m_LOT == 176){
|
|
|
|
object.m_ID = SpawnSpawner(object, location);
|
2023-11-10 00:59:43 +00:00
|
|
|
} else {
|
|
|
|
// Spawn the NPC
|
2024-02-25 22:59:10 +00:00
|
|
|
auto* objectEntity = SpawnObject(object, location);
|
|
|
|
if (!objectEntity) continue;
|
|
|
|
object.m_ID = objectEntity->GetObjectID();
|
|
|
|
if (!object.m_Phrases.empty()){
|
|
|
|
objectEntity->SetVar<std::vector<std::string>>(u"chats", object.m_Phrases);
|
|
|
|
SetupNPCTalk(objectEntity);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-28 23:16:47 +00:00
|
|
|
LWOOBJID SpawnSpawner(const VanityObject& object, const VanityObjectLocation& location) {
|
2023-11-10 03:28:52 +00:00
|
|
|
SceneObject obj;
|
2024-02-25 22:59:10 +00:00
|
|
|
obj.lot = object.m_LOT;
|
2023-11-10 03:28:52 +00:00
|
|
|
// guratantee we have no collisions
|
|
|
|
do {
|
2024-01-05 12:31:22 +00:00
|
|
|
obj.id = ObjectIDManager::GenerateObjectID();
|
2023-11-10 03:28:52 +00:00
|
|
|
} while(Game::zoneManager->GetSpawner(obj.id));
|
2024-02-25 22:59:10 +00:00
|
|
|
obj.position = location.m_Position;
|
|
|
|
obj.rotation = location.m_Rotation;
|
|
|
|
obj.settings = object.m_Config;
|
2023-11-10 03:28:52 +00:00
|
|
|
Level::MakeSpawner(obj);
|
|
|
|
return obj.id;
|
2023-11-10 00:33:39 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 23:16:47 +00:00
|
|
|
Entity* SpawnObject(const VanityObject& object, const VanityObjectLocation& location) {
|
2021-12-05 17:54:36 +00:00
|
|
|
EntityInfo info;
|
2024-02-25 22:59:10 +00:00
|
|
|
info.lot = object.m_LOT;
|
|
|
|
info.pos = location.m_Position;
|
|
|
|
info.rot = location.m_Rotation;
|
|
|
|
info.scale = location.m_Scale;
|
2023-11-10 00:59:43 +00:00
|
|
|
info.spawnerID = Game::entityManager->GetZoneControlEntity()->GetObjectID();
|
2024-02-25 22:59:10 +00:00
|
|
|
info.settings = object.m_Config;
|
2021-12-05 17:54:36 +00:00
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
auto* entity = Game::entityManager->CreateEntity(info);
|
2024-02-28 23:16:47 +00:00
|
|
|
if (!object.m_Name.empty()) entity->SetVar(u"npcName", object.m_Name);
|
2023-08-04 02:37:09 +00:00
|
|
|
if (entity->GetVar<bool>(u"noGhosting")) entity->SetIsGhostingCandidate(false);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
auto* inventoryComponent = entity->GetComponent<InventoryComponent>();
|
2024-02-25 22:59:10 +00:00
|
|
|
if (inventoryComponent && !object.m_Equipment.empty()) {
|
|
|
|
inventoryComponent->SetNPCItems(object.m_Equipment);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto* destroyableComponent = entity->GetComponent<DestroyableComponent>();
|
2024-02-28 23:16:47 +00:00
|
|
|
if (destroyableComponent) {
|
2021-12-05 17:54:36 +00:00
|
|
|
destroyableComponent->SetIsGMImmune(true);
|
|
|
|
destroyableComponent->SetMaxHealth(0);
|
|
|
|
destroyableComponent->SetHealth(0);
|
|
|
|
}
|
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->ConstructEntity(entity);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
return entity;
|
|
|
|
}
|
|
|
|
|
2024-02-28 23:16:47 +00:00
|
|
|
void ParseXml(const std::string& file) {
|
|
|
|
if (loadedFiles.contains(file)){
|
2024-02-25 22:59:10 +00:00
|
|
|
LOG("Trying to load vanity file %s twice!!!", file.c_str());
|
|
|
|
return;
|
|
|
|
}
|
2024-02-28 23:16:47 +00:00
|
|
|
loadedFiles.insert(file);
|
2021-12-05 17:54:36 +00:00
|
|
|
// Read the entire file
|
|
|
|
std::ifstream xmlFile(file);
|
|
|
|
std::string xml((std::istreambuf_iterator<char>(xmlFile)), std::istreambuf_iterator<char>());
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
// Parse the XML
|
|
|
|
tinyxml2::XMLDocument doc;
|
|
|
|
doc.Parse(xml.c_str(), xml.size());
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
// Read the objects
|
|
|
|
auto* files = doc.FirstChildElement("files");
|
|
|
|
if (files) {
|
|
|
|
for (auto* file = files->FirstChildElement("file"); file != nullptr; file = file->NextSiblingElement("file")) {
|
|
|
|
std::string enabled = file->Attribute("enabled");
|
|
|
|
std::string filename = file->Attribute("name");
|
|
|
|
if (enabled != "1") {
|
2021-12-05 17:54:36 +00:00
|
|
|
continue;
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2024-02-28 23:16:47 +00:00
|
|
|
ParseXml((BinaryPathFinder::GetBinaryDir() / "vanity" / filename).string());
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
// Read the objects
|
2024-02-28 23:16:47 +00:00
|
|
|
auto* objectsElement = doc.FirstChildElement("objects");
|
|
|
|
const uint32_t currentZoneID = Game::server->GetZoneID();
|
|
|
|
if (objectsElement) {
|
|
|
|
for (auto* object = objectsElement->FirstChildElement("object"); object != nullptr; object = object->NextSiblingElement("object")) {
|
|
|
|
// for use later when adding to the vector of VanityObjects
|
|
|
|
bool useLocationsAsRandomSpawnPoint = false;
|
2024-02-25 22:59:10 +00:00
|
|
|
// Get the NPC name
|
|
|
|
auto* name = object->Attribute("name");
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
if (!name) name = "";
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
// Get the NPC lot
|
2024-02-28 23:16:47 +00:00
|
|
|
auto lot = GeneralUtils::TryParse<LOT>(object->Attribute("lot")).value_or(LOT_NULL);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2024-02-28 23:16:47 +00:00
|
|
|
if (lot == LOT_NULL) {
|
2024-02-25 22:59:10 +00:00
|
|
|
LOG("Failed to parse object lot");
|
|
|
|
continue;
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
// Get the equipment
|
|
|
|
auto* equipment = object->FirstChildElement("equipment");
|
|
|
|
std::vector<LOT> inventory;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
if (equipment) {
|
|
|
|
auto* text = equipment->GetText();
|
2023-01-11 07:10:14 +00:00
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
if (text != nullptr) {
|
|
|
|
std::string equipmentString(text);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
std::vector<std::string> splitEquipment = GeneralUtils::SplitString(equipmentString, ',');
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
for (auto& item : splitEquipment) {
|
2024-02-28 23:16:47 +00:00
|
|
|
// remove spaces for tryParse to work
|
|
|
|
item.erase(remove_if(item.begin(), item.end(), isspace), item.end());
|
|
|
|
auto itemInt = GeneralUtils::TryParse<uint32_t>(item);
|
|
|
|
if (itemInt) inventory.push_back(itemInt.value());
|
2024-02-25 22:59:10 +00:00
|
|
|
}
|
2023-01-11 07:10:14 +00:00
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
// Get the phrases
|
|
|
|
auto* phrases = object->FirstChildElement("phrases");
|
|
|
|
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) {
|
|
|
|
LOG("Failed to parse NPC phrase");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
phraseList.push_back(text);
|
2023-01-11 07:10:14 +00:00
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
auto* configElement = object->FirstChildElement("config");
|
|
|
|
std::vector<std::u16string> keys = {};
|
|
|
|
std::vector<LDFBaseData*> config = {};
|
|
|
|
if(configElement) {
|
|
|
|
for (auto* key = configElement->FirstChildElement("key"); key != nullptr;
|
|
|
|
key = key->NextSiblingElement("key")) {
|
|
|
|
// Get the config data
|
2024-02-28 23:16:47 +00:00
|
|
|
auto* data = key->GetText();
|
2024-02-25 22:59:10 +00:00
|
|
|
if (!data) continue;
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
LDFBaseData* configData = LDFBaseData::DataFromString(data);
|
2024-02-28 23:16:47 +00:00
|
|
|
if (configData->GetKey() == u"useLocationsAsRandomSpawnPoint" && configData->GetValueType() == eLDFType::LDF_TYPE_BOOLEAN){
|
|
|
|
useLocationsAsRandomSpawnPoint = static_cast<bool>(configData);
|
|
|
|
continue;
|
|
|
|
}
|
2024-02-25 22:59:10 +00:00
|
|
|
keys.push_back(configData->GetKey());
|
|
|
|
config.push_back(configData);
|
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2024-02-25 22:59:10 +00:00
|
|
|
if (!keys.empty()) config.push_back(new LDFData<std::vector<std::u16string>>(u"syncLDF", keys));
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2024-02-28 23:16:47 +00:00
|
|
|
VanityObject objectData {
|
|
|
|
.m_Name = name,
|
|
|
|
.m_LOT = lot,
|
|
|
|
.m_Equipment = inventory,
|
|
|
|
.m_Phrases = phraseList,
|
|
|
|
.m_Config = config
|
|
|
|
};
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
// Get the locations
|
2024-02-25 22:59:10 +00:00
|
|
|
auto* locations = object->FirstChildElement("locations");
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (locations == nullptr) {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Failed to parse NPC locations");
|
2021-12-05 17:54:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
for (auto* location = locations->FirstChildElement("location"); location != nullptr;
|
|
|
|
location = location->NextSiblingElement("location")) {
|
2024-02-25 22:59:10 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
// Get the location data
|
2024-02-28 23:16:47 +00:00
|
|
|
auto zoneID = GeneralUtils::TryParse<uint32_t>(location->Attribute("zone"));
|
|
|
|
auto x = GeneralUtils::TryParse<float>(location->Attribute("x"));
|
|
|
|
auto y = GeneralUtils::TryParse<float>(location->Attribute("y"));
|
|
|
|
auto z = GeneralUtils::TryParse<float>(location->Attribute("z"));
|
|
|
|
auto rw = GeneralUtils::TryParse<float>(location->Attribute("rw"));
|
|
|
|
auto rx = GeneralUtils::TryParse<float>(location->Attribute("rx"));
|
|
|
|
auto ry = GeneralUtils::TryParse<float>(location->Attribute("ry"));
|
|
|
|
auto rz = GeneralUtils::TryParse<float>(location->Attribute("rz"));
|
|
|
|
|
|
|
|
if (!zoneID || !x || !y || !z || !rw || !rx || !ry || !rz) {
|
2023-10-21 23:31:55 +00:00
|
|
|
LOG("Failed to parse NPC location data");
|
2021-12-05 17:54:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2024-02-28 23:16:47 +00:00
|
|
|
if (zoneID.value() != currentZoneID) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
VanityObjectLocation locationData {
|
|
|
|
.m_Position = { x.value(), y.value(), z.value() },
|
|
|
|
.m_Rotation = { rw.value(), rx.value(), ry.value(), rz.value() },
|
|
|
|
};
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
if (location->Attribute("chance")) {
|
2024-02-28 23:16:47 +00:00
|
|
|
locationData.m_Chance = GeneralUtils::TryParse<float>(location->Attribute("chance")).value_or(1.0f);
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
if (location->Attribute("scale")) {
|
2024-02-28 23:16:47 +00:00
|
|
|
locationData.m_Scale = GeneralUtils::TryParse<float>(location->Attribute("scale")).value_or(1.0f);
|
2024-02-25 22:59:10 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 23:16:47 +00:00
|
|
|
const auto& it = objectData.m_Locations.find(zoneID.value());
|
2024-02-25 22:59:10 +00:00
|
|
|
|
|
|
|
if (it != objectData.m_Locations.end()) {
|
2021-12-05 17:54:36 +00:00
|
|
|
it->second.push_back(locationData);
|
|
|
|
} else {
|
2024-02-25 22:59:10 +00:00
|
|
|
std::vector<VanityObjectLocation> locations;
|
2021-12-05 17:54:36 +00:00
|
|
|
locations.push_back(locationData);
|
2024-02-28 23:16:47 +00:00
|
|
|
objectData.m_Locations.insert(std::make_pair(zoneID.value(), locations));
|
2024-02-25 22:59:10 +00:00
|
|
|
}
|
|
|
|
|
2024-02-28 23:16:47 +00:00
|
|
|
if (!useLocationsAsRandomSpawnPoint) {
|
|
|
|
objects.push_back(objectData);
|
2024-02-25 22:59:10 +00:00
|
|
|
objectData.m_Locations.clear();
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
2024-02-28 23:16:47 +00:00
|
|
|
|
|
|
|
if (useLocationsAsRandomSpawnPoint && !objectData.m_Locations.empty()) {
|
|
|
|
objects.push_back(objectData);
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
}
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-25 22:59:10 +00:00
|
|
|
VanityObject* VanityUtilities::GetObject(const std::string& name) {
|
2024-02-28 23:16:47 +00:00
|
|
|
for (size_t i = 0; i < objects.size(); i++) {
|
|
|
|
if (objects[i].m_Name == name) {
|
|
|
|
return &objects[i];
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string VanityUtilities::ParseMarkdown(const std::string& file) {
|
|
|
|
// This function will read the file and return the content formatted as ASCII text.
|
|
|
|
|
|
|
|
// Read the file into a string
|
|
|
|
std::ifstream t(file);
|
2024-02-25 22:59:10 +00:00
|
|
|
std::stringstream output;
|
2024-02-28 23:16:47 +00:00
|
|
|
// If the file does not exist, return a useful error.
|
2021-12-05 17:54:36 +00:00
|
|
|
if (!t.good()) {
|
2024-02-25 22:59:10 +00:00
|
|
|
output << "File ";
|
|
|
|
output << file.substr(file.rfind("/") + 1);
|
|
|
|
output << " not found!\nContact your DarkflameServer admin\nor find the server source at https://github.com/DarkflameUniverse/DarkflameServer";
|
|
|
|
return output.str();
|
2021-12-05 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::stringstream buffer;
|
|
|
|
buffer << t.rdbuf();
|
|
|
|
std::string fileContents = buffer.str();
|
|
|
|
|
|
|
|
// Loop through all lines in the file.
|
|
|
|
// Replace all instances of the markdown syntax with the corresponding HTML.
|
|
|
|
// Only care about headers
|
|
|
|
std::string line;
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << fileContents;
|
|
|
|
while (std::getline(ss, line)) {
|
|
|
|
|
|
|
|
#define TOSTRING(x) #x
|
|
|
|
|
2023-10-21 23:31:55 +00:00
|
|
|
#ifndef STRINGIFY
|
|
|
|
#define STRINGIFY(x) TOSTRING(x)
|
|
|
|
#endif
|
2021-12-05 17:54:36 +00:00
|
|
|
// Replace "__TIMESTAMP__" with the __TIMESTAMP__
|
|
|
|
GeneralUtils::ReplaceInString(line, "__TIMESTAMP__", __TIMESTAMP__);
|
2023-12-31 06:26:49 +00:00
|
|
|
// Replace "__VERSION__" with the PROJECT_VERSION
|
|
|
|
GeneralUtils::ReplaceInString(line, "__VERSION__", Game::projectVersion);
|
2021-12-05 17:54:36 +00:00
|
|
|
// Replace "__SOURCE__" with SOURCE
|
|
|
|
GeneralUtils::ReplaceInString(line, "__SOURCE__", Game::config->GetValue("source"));
|
|
|
|
// Replace "__LICENSE__" with LICENSE
|
2023-12-31 06:26:49 +00:00
|
|
|
GeneralUtils::ReplaceInString(line, "__LICENSE__", "AGPL-3.0");
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
if (line.find("##") != std::string::npos) {
|
|
|
|
// Add "<font size='18' color='#000000'>" before the header
|
|
|
|
output << "<font size=\"14\" color=\"#000000\">";
|
|
|
|
// Add the header without the markdown syntax
|
|
|
|
output << line.substr(3);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
output << "</font>";
|
|
|
|
} else if (line.find("#") != std::string::npos) {
|
|
|
|
// Add "<font size='18' color='#000000'>" before the header
|
|
|
|
output << "<font size=\"18\" color=\"#000000\">";
|
|
|
|
// Add the header without the markdown syntax
|
|
|
|
output << line.substr(2);
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
output << "</font>";
|
|
|
|
} else {
|
|
|
|
output << line;
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
output << "\n";
|
|
|
|
}
|
2022-07-28 13:39:57 +00:00
|
|
|
|
2021-12-05 17:54:36 +00:00
|
|
|
return output.str();
|
|
|
|
}
|
|
|
|
|
2024-02-28 23:16:47 +00:00
|
|
|
void SetupNPCTalk(Entity* npc) {
|
2021-12-05 17:54:36 +00:00
|
|
|
npc->AddCallbackTimer(15.0f, [npc]() { NPCTalk(npc); });
|
|
|
|
|
|
|
|
npc->SetProximityRadius(20.0f, "talk");
|
|
|
|
}
|
|
|
|
|
2024-02-28 23:16:47 +00:00
|
|
|
void NPCTalk(Entity* npc) {
|
2021-12-05 17:54:36 +00:00
|
|
|
auto* proximityMonitorComponent = npc->GetComponent<ProximityMonitorComponent>();
|
|
|
|
|
|
|
|
if (!proximityMonitorComponent->GetProximityObjects("talk").empty()) {
|
|
|
|
const auto& chats = npc->GetVar<std::vector<std::string>>(u"chats");
|
|
|
|
|
|
|
|
if (chats.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto& selected
|
|
|
|
= chats[GeneralUtils::GenerateRandomNumber<int32_t>(0, static_cast<int32_t>(chats.size() - 1))];
|
|
|
|
|
|
|
|
GameMessages::SendNotifyClientZoneObject(
|
|
|
|
npc->GetObjectID(), u"sendToclient_bubble", 0, 0, npc->GetObjectID(), selected, UNASSIGNED_SYSTEM_ADDRESS);
|
|
|
|
}
|
|
|
|
|
2023-07-15 20:56:33 +00:00
|
|
|
Game::entityManager->SerializeEntity(npc);
|
2021-12-05 17:54:36 +00:00
|
|
|
|
|
|
|
const float nextTime = GeneralUtils::GenerateRandomNumber<float>(15, 60);
|
|
|
|
|
|
|
|
npc->AddCallbackTimer(nextTime, [npc]() { NPCTalk(npc); });
|
|
|
|
}
|