Skip to content

Commit

Permalink
Large code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnchyDev committed Oct 18, 2023
1 parent 8b7399f commit f8b73dd
Show file tree
Hide file tree
Showing 9 changed files with 936 additions and 846 deletions.
19 changes: 0 additions & 19 deletions src/ToSHelpers.h

This file was deleted.

122 changes: 122 additions & 0 deletions src/ToSMapMgr.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#include "ToSMapMgr.h"

std::string ToSMapManager::GetHexColorFromClass(uint8 classId)
{
switch (classId)
{
case CLASS_DEATH_KNIGHT:
return "|cffFC2A43";
case CLASS_HUNTER:
return "|cffAAD174";
case CLASS_PALADIN:
return "|cffF28CBC";
case CLASS_ROGUE:
return "|cffFEF262";
case CLASS_WARLOCK:
return "|cff9A81C2";
case CLASS_DRUID:
return "|cffF67404";
case CLASS_MAGE:
return "|cff70C9F1";
case CLASS_PRIEST:
return "|cffF5F3F6";
case CLASS_SHAMAN:
return "|cff05D7BA";
case CLASS_WARRIOR:
return "|cffC9A074";
}

return "|cffFFFFFF";
}

ToSCurseTemplate* ToSMapManager::GetCurseById(uint32 curseId)
{
auto it = CurseTemplates.find(curseId);
if (it == CurseTemplates.end())
{
return nullptr;
}

return &it->second;
}

ToSWaveTemplate* ToSMapManager::GetWaveTemplateForWave(uint32 wave)
{
auto it = WaveTemplates.find(wave);
if (it == WaveTemplates.end())
{
return nullptr;
}

return &it->second;
}

uint32 ToSMapManager::GetTotalWaves()
{
return WaveTemplates.size();
}

std::vector<ToSEnemyGroup*> ToSMapManager::GetEnemiesFromGroup(uint32 groupId, uint32 subGroup)
{
std::vector<ToSEnemyGroup*> groups;

for (auto it = EnemyGroups.begin(); it != EnemyGroups.end(); ++it)
{
if (it->second.group == groupId &&
it->second.subGroup == subGroup)
{
groups.push_back(&it->second);
}
}

return groups;
}

std::vector<uint32> ToSMapManager::GetSubGroups(uint32 groupId)
{
std::vector<uint32> subgroups;

for (auto it = EnemyGroups.begin(); it != EnemyGroups.end(); ++it)
{
if (it->second.group == groupId)
{
uint32 subgroup = it->second.subGroup;

auto it = std::find(subgroups.begin(), subgroups.end(), subgroup);
if (it != subgroups.end())
{
continue;
}

subgroups.push_back(subgroup);
}
}

return subgroups;
}

std::vector<ToSRewardTemplate>* ToSMapManager::GetRewardTemplates(uint32 rewardId)
{
auto it = RewardTemplates.find(rewardId);
if (it == RewardTemplates.end())
{
return nullptr;
}

return &it->second;
}

Creature* ToSMapManager::SpawnNPC(uint32 entry, Map* map, Position* position)
{
if (!map || !position)
{
return nullptr;
}

if (!sObjectMgr->GetCreatureTemplate(entry))
{
return nullptr;
}

return map->SummonCreature(entry, *position);
}
42 changes: 42 additions & 0 deletions src/ToSMapMgr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef MODULE_TRIAL_OF_STRENGTH_MAP_MGR_H
#define MODULE_TRIAL_OF_STRENGTH_MAP_MGR_H

#include "TrialOfStrength.h"

#include <unordered_map>

class ToSMapManager
{
private:
ToSMapManager() { }
public:
static ToSMapManager* GetInstance()
{
if (!instance)
{
instance = new ToSMapManager();
}

return instance;
}

std::string GetHexColorFromClass(uint8 classId);
ToSCurseTemplate* GetCurseById(uint32 curseId);
ToSWaveTemplate* GetWaveTemplateForWave(uint32 wave);
uint32 GetTotalWaves();
std::vector<ToSEnemyGroup*> GetEnemiesFromGroup(uint32 groupId, uint32 subGroup);
std::vector<ToSRewardTemplate>* GetRewardTemplates(uint32 rewardId);
std::vector<uint32> GetSubGroups(uint32 groupId);
Creature* SpawnNPC(uint32 entry, Map* map, Position* position);
public:
std::unordered_map<uint32, ToSWaveTemplate> WaveTemplates;
std::unordered_map<uint32, ToSEnemyGroup> EnemyGroups;
std::unordered_map<uint32, std::vector<ToSRewardTemplate>> RewardTemplates;
std::unordered_map<uint32, ToSCurseTemplate> CurseTemplates;
private:
inline static ToSMapManager* instance;
};

#define sToSMapMgr ToSMapManager::GetInstance()

#endif // MODULE_TRIAL_OF_STRENGTH_MAP_MGR_H
131 changes: 13 additions & 118 deletions src/TrialOfStrength.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include "TrialOfStrength.h"

#include "ToSHelpers.h"
#include "ToSMapMgr.h"

#include "scripts/ToSEnemyCombatantScript.h"
#include "scripts/ToSEnemyCombatantBossScript.h"

#include "scripts/ToSArenaMasterScript.h"

#include "scripts/ToSInstanceScript.h"
#include "scripts/ToSInstanceMapScript.h"

void LoadWaveTemplates()
{
Expand All @@ -31,7 +32,7 @@ void LoadWaveTemplates()
waveTemplate.hasReward = fields[2].Get<bool>();
waveTemplate.rewardTemplate = fields[3].Get<uint32>();

waveTemplates.emplace(waveTemplate.wave, waveTemplate);
sToSMapMgr->WaveTemplates.emplace(waveTemplate.wave, waveTemplate);

count++;
} while (qResult->NextRow());
Expand Down Expand Up @@ -63,7 +64,7 @@ void LoadEnemyGroups()
enemyGroup.subGroup = fields[2].Get<uint32>();
enemyGroup.creatureEntry = fields[3].Get<uint32>();

enemyGroups.emplace(enemyGroup.id, enemyGroup);
sToSMapMgr->EnemyGroups.emplace(enemyGroup.id, enemyGroup);

count++;
} while (qResult->NextRow());
Expand Down Expand Up @@ -96,12 +97,12 @@ void LoadRewardTemplates()
rewardTemplate.countMax = fields[3].Get<uint32>();
rewardTemplate.chance = fields[4].Get<uint32>();

auto templates = GetRewardTemplates(rewardId);
auto templates = sToSMapMgr->GetRewardTemplates(rewardId);
if (!templates)
{
std::vector<ToSRewardTemplate> newTemplates;
newTemplates.push_back(rewardTemplate);
auto it = rewardTemplates.emplace(rewardId, newTemplates);
auto it = sToSMapMgr->RewardTemplates.emplace(rewardId, newTemplates);
}
else
{
Expand Down Expand Up @@ -140,128 +141,22 @@ void LoadCurseTemplates()
curseTemplate.name = fields[4].Get<std::string>();
curseTemplate.description = fields[5].Get<std::string>();

curseTemplates.emplace(curseId, curseTemplate);
sToSMapMgr->CurseTemplates.emplace(curseId, curseTemplate);

count++;
} while (qResult->NextRow());

LOG_INFO("module", "Loaded '{}' trial of strength curse templates.", count);
}

std::string GetHexColorFromClass(uint8 classId)
{
switch (classId)
{
case CLASS_DEATH_KNIGHT:
return "|cffFC2A43";
case CLASS_HUNTER:
return "|cffAAD174";
case CLASS_PALADIN:
return "|cffF28CBC";
case CLASS_ROGUE:
return "|cffFEF262";
case CLASS_WARLOCK:
return "|cff9A81C2";
case CLASS_DRUID:
return "|cffF67404";
case CLASS_MAGE:
return "|cff70C9F1";
case CLASS_PRIEST:
return "|cffF5F3F6";
case CLASS_SHAMAN:
return "|cff05D7BA";
case CLASS_WARRIOR:
return "|cffC9A074";
}

return "|cffFFFFFF";
}

ToSCurseTemplate* GetCurseById(uint32 curseId)
{
auto it = curseTemplates.find(curseId);
if (it == curseTemplates.end())
{
return nullptr;
}

return &it->second;
}

ToSWaveTemplate* GetWaveTemplateForWave(uint32 wave)
{
auto it = waveTemplates.find(wave);
if (it == waveTemplates.end())
{
return nullptr;
}

return &it->second;
}

uint32 GetTotalWaves()
{
return waveTemplates.size();
}

std::vector<ToSEnemyGroup*> GetEnemiesFromGroup(uint32 groupId, uint32 subGroup)
{
std::vector<ToSEnemyGroup*> groups;

for (auto it = enemyGroups.begin(); it != enemyGroups.end(); ++it)
{
if (it->second.group == groupId &&
it->second.subGroup == subGroup)
{
groups.push_back(&it->second);
}
}

return groups;
}

std::vector<uint32> GetSubGroups(uint32 groupId)
{
std::vector<uint32> subgroups;

for (auto it = enemyGroups.begin(); it != enemyGroups.end(); ++it)
{
if (it->second.group == groupId)
{
uint32 subgroup = it->second.subGroup;

auto it = std::find(subgroups.begin(), subgroups.end(), subgroup);
if (it != subgroups.end())
{
continue;
}

subgroups.push_back(subgroup);
}
}

return subgroups;
}

std::vector<ToSRewardTemplate>* GetRewardTemplates(uint32 rewardId)
{
auto it = rewardTemplates.find(rewardId);
if (it == rewardTemplates.end())
{
return nullptr;
}

return &it->second;
}

void ToSWorldScript::OnAfterConfigLoad(bool reload)
{
if (reload)
{
waveTemplates.clear();
enemyGroups.clear();
rewardTemplates.clear();
curseTemplates.clear();
sToSMapMgr->WaveTemplates.clear();
sToSMapMgr->EnemyGroups.clear();
sToSMapMgr->RewardTemplates.clear();
sToSMapMgr->CurseTemplates.clear();
}

LoadWaveTemplates();
Expand All @@ -278,5 +173,5 @@ void SC_AddTrialOfStrengthScripts()
new ToSEnemyCombatantScript();
new ToSEnemyCombatantBossScript();

new instance_trial_of_strength();
new ToSInstanceMapScript();
}
13 changes: 0 additions & 13 deletions src/TrialOfStrength.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,6 @@ struct ToSCurseTemplate {
std::string description;
};

std::unordered_map<uint32, ToSWaveTemplate> waveTemplates;
std::unordered_map<uint32, ToSEnemyGroup> enemyGroups;
std::unordered_map<uint32, std::vector<ToSRewardTemplate>> rewardTemplates;
std::unordered_map<uint32, ToSCurseTemplate> curseTemplates;

std::string GetHexColorFromClass(uint8 classId);
ToSCurseTemplate* GetCurseById(uint32 curseId);
ToSWaveTemplate* GetWaveTemplateForWave(uint32 wave);
uint32 GetTotalWaves();
std::vector<ToSEnemyGroup*> GetEnemiesFromGroup(uint32 groupId, uint32 subGroup);
std::vector<ToSRewardTemplate>* GetRewardTemplates(uint32 rewardId);
std::vector<uint32> GetSubGroups(uint32 groupId);

class ToSWorldScript : public WorldScript
{
public:
Expand Down
Loading

0 comments on commit f8b73dd

Please sign in to comment.