mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-08-05 18:24:12 +00:00
consolidate code
This commit is contained in:
@@ -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<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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Game::zoneManager->MakeSpawner(spawnInfo);
|
||||
}
|
||||
|
||||
const void Level::PrintAllObjects() {
|
||||
for (std::map<uint32_t, Header>::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<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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Spawner* spawner = new Spawner(spawnInfo);
|
||||
Game::zoneManager->AddSpawner(obj.id, spawner);
|
||||
MakeSpawner(obj);
|
||||
} else { //Regular object
|
||||
EntityInfo info;
|
||||
info.spawnerID = 0;
|
||||
|
@@ -53,6 +53,8 @@ public:
|
||||
public:
|
||||
Level(Zone* parentZone, const std::string& filepath);
|
||||
~Level();
|
||||
|
||||
static void MakeSpawner(SceneObject obj);
|
||||
|
||||
const void PrintAllObjects();
|
||||
|
||||
|
Reference in New Issue
Block a user