aboutsummaryrefslogtreecommitdiff
path: root/src/server/scripts/Commands
diff options
context:
space:
mode:
authorariel- <ariel-@users.noreply.github.com>2018-01-17 02:17:49 -0300
committerariel- <ariel-@users.noreply.github.com>2018-01-17 02:17:49 -0300
commitb64c5043140dc7b7908e259e441de16cc0261320 (patch)
treecd3ec7447df76abde2bf4b7ddb9cf591aeffd5f1 /src/server/scripts/Commands
parent72ff2e30c30d4d1b9bf22695b6a097eb82e3c76a (diff)
Core/Globals: throw some RAII into ObjectMgr, and load templates into vectors
Ref #14274
Diffstat (limited to 'src/server/scripts/Commands')
-rw-r--r--src/server/scripts/Commands/cs_lookup.cpp155
-rw-r--r--src/server/scripts/Commands/cs_misc.cpp42
-rw-r--r--src/server/scripts/Commands/cs_quest.cpp10
3 files changed, 108 insertions, 99 deletions
diff --git a/src/server/scripts/Commands/cs_lookup.cpp b/src/server/scripts/Commands/cs_lookup.cpp
index 36706034d03..44e137b5567 100644
--- a/src/server/scripts/Commands/cs_lookup.cpp
+++ b/src/server/scripts/Commands/cs_lookup.cpp
@@ -107,7 +107,7 @@ public:
AreaTableEntry const* areaEntry = sAreaTableStore.LookupEntry(i);
if (areaEntry)
{
- int locale = handler->GetSessionDbcLocale();
+ uint8 locale = handler->GetSessionDbcLocale();
std::string name = areaEntry->area_name[locale];
if (name.empty())
continue;
@@ -176,16 +176,19 @@ public:
uint32 count = 0;
uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
- CreatureTemplateContainer const* ctc = sObjectMgr->GetCreatureTemplates();
- for (CreatureTemplateContainer::const_iterator itr = ctc->begin(); itr != ctc->end(); ++itr)
+ CreatureTemplateContainer const& ctc = sObjectMgr->GetCreatureTemplates();
+ for (auto const& creatureTemplate : ctc)
{
- uint32 id = itr->second.Entry;
+ if (!creatureTemplate)
+ continue;
+
+ uint32 id = creatureTemplate->Entry;
uint8 localeIndex = handler->GetSessionDbLocaleIndex();
if (CreatureLocale const* creatureLocale = sObjectMgr->GetCreatureLocale(id))
{
if (creatureLocale->Name.size() > localeIndex && !creatureLocale->Name[localeIndex].empty())
{
- std::string name = creatureLocale->Name[localeIndex];
+ std::string const& name = creatureLocale->Name[localeIndex];
if (Utf8FitTo(name, wNamePart))
{
@@ -208,7 +211,7 @@ public:
}
}
- std::string name = itr->second.Name;
+ std::string const& name = creatureTemplate->Name;
if (name.empty())
continue;
@@ -319,7 +322,7 @@ public:
{
FactionState const* factionState = target ? target->GetReputationMgr().GetState(factionEntry) : nullptr;
- int locale = handler->GetSessionDbcLocale();
+ uint8 locale = handler->GetSessionDbcLocale();
std::string name = factionEntry->name[locale];
if (name.empty())
continue;
@@ -412,18 +415,21 @@ public:
uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
// Search in `item_template`
- ItemTemplateContainer const* its = sObjectMgr->GetItemTemplateStore();
- for (ItemTemplateContainer::const_iterator itr = its->begin(); itr != its->end(); ++itr)
+ ItemTemplateContainer const& its = sObjectMgr->GetItemTemplateStore();
+ for (auto const& itemTemplate : its)
{
- int localeIndex = handler->GetSessionDbLocaleIndex();
+ if (!itemTemplate)
+ continue;
+
+ uint8 localeIndex = handler->GetSessionDbLocaleIndex();
if (localeIndex >= 0)
{
uint8 ulocaleIndex = uint8(localeIndex);
- if (ItemLocale const* il = sObjectMgr->GetItemLocale(itr->second.ItemId))
+ if (ItemLocale const* il = sObjectMgr->GetItemLocale(itemTemplate->ItemId))
{
if (il->Name.size() > ulocaleIndex && !il->Name[ulocaleIndex].empty())
{
- std::string name = il->Name[ulocaleIndex];
+ std::string const& name = il->Name[ulocaleIndex];
if (Utf8FitTo(name, wNamePart))
{
@@ -434,9 +440,9 @@ public:
}
if (handler->GetSession())
- handler->PSendSysMessage(LANG_ITEM_LIST_CHAT, itr->second.ItemId, itr->second.ItemId, name.c_str());
+ handler->PSendSysMessage(LANG_ITEM_LIST_CHAT, itemTemplate->ItemId, itemTemplate->ItemId, name.c_str());
else
- handler->PSendSysMessage(LANG_ITEM_LIST_CONSOLE, itr->second.ItemId, name.c_str());
+ handler->PSendSysMessage(LANG_ITEM_LIST_CONSOLE, itemTemplate->ItemId, name.c_str());
if (!found)
found = true;
@@ -447,7 +453,7 @@ public:
}
}
- std::string name = itr->second.Name1;
+ std::string const& name = itemTemplate->Name1;
if (name.empty())
continue;
@@ -460,9 +466,9 @@ public:
}
if (handler->GetSession())
- handler->PSendSysMessage(LANG_ITEM_LIST_CHAT, itr->second.ItemId, itr->second.ItemId, name.c_str());
+ handler->PSendSysMessage(LANG_ITEM_LIST_CHAT, itemTemplate->ItemId, itemTemplate->ItemId, name.c_str());
else
- handler->PSendSysMessage(LANG_ITEM_LIST_CONSOLE, itr->second.ItemId, name.c_str());
+ handler->PSendSysMessage(LANG_ITEM_LIST_CONSOLE, itemTemplate->ItemId, name.c_str());
if (!found)
found = true;
@@ -499,7 +505,7 @@ public:
ItemSetEntry const* set = sItemSetStore.LookupEntry(id);
if (set)
{
- int locale = handler->GetSessionDbcLocale();
+ uint8 locale = handler->GetSessionDbcLocale();
std::string name = set->name[locale];
if (name.empty())
continue;
@@ -564,16 +570,18 @@ public:
uint32 count = 0;
uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
- GameObjectTemplateContainer const* gotc = sObjectMgr->GetGameObjectTemplates();
- for (GameObjectTemplateContainer::const_iterator itr = gotc->begin(); itr != gotc->end(); ++itr)
+ GameObjectTemplateContainer const& gotc = sObjectMgr->GetGameObjectTemplates();
+ for (auto const& gameObjectTemplate : gotc)
{
+ if (!gameObjectTemplate)
+ continue;
+
uint8 localeIndex = handler->GetSessionDbLocaleIndex();
- if (GameObjectLocale const* objectLocalte = sObjectMgr->GetGameObjectLocale(itr->second.entry))
+ if (GameObjectLocale const* objectLocalte = sObjectMgr->GetGameObjectLocale(gameObjectTemplate->entry))
{
if (objectLocalte->Name.size() > localeIndex && !objectLocalte->Name[localeIndex].empty())
{
- std::string name = objectLocalte->Name[localeIndex];
-
+ std::string const& name = objectLocalte->Name[localeIndex];
if (Utf8FitTo(name, wNamePart))
{
if (maxResults && count++ == maxResults)
@@ -583,9 +591,9 @@ public:
}
if (handler->GetSession())
- handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, itr->second.entry, itr->second.entry, name.c_str());
+ handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, gameObjectTemplate->entry, gameObjectTemplate->entry, name.c_str());
else
- handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, itr->second.entry, name.c_str());
+ handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, gameObjectTemplate->entry, name.c_str());
if (!found)
found = true;
@@ -595,7 +603,7 @@ public:
}
}
- std::string name = itr->second.name;
+ std::string const& name = gameObjectTemplate->name;
if (name.empty())
continue;
@@ -608,9 +616,9 @@ public:
}
if (handler->GetSession())
- handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, itr->second.entry, itr->second.entry, name.c_str());
+ handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, gameObjectTemplate->entry, gameObjectTemplate->entry, name.c_str());
else
- handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, itr->second.entry, name.c_str());
+ handler->PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, gameObjectTemplate->entry, name.c_str());
if (!found)
found = true;
@@ -644,12 +652,13 @@ public:
uint32 count = 0;
uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
- ObjectMgr::QuestMap const& qTemplates = sObjectMgr->GetQuestTemplates();
- for (ObjectMgr::QuestMap::const_iterator iter = qTemplates.begin(); iter != qTemplates.end(); ++iter)
+ ObjectMgr::QuestContainer const& questTemplates = sObjectMgr->GetQuestTemplates();
+ for (auto const& qInfo : questTemplates)
{
- Quest* qInfo = iter->second;
+ if (!qInfo)
+ continue;
- int localeIndex = handler->GetSessionDbLocaleIndex();
+ uint8 localeIndex = handler->GetSessionDbLocaleIndex();
if (localeIndex >= 0)
{
uint8 ulocaleIndex = uint8(localeIndex);
@@ -780,7 +789,7 @@ public:
SkillLineEntry const* skillInfo = sSkillLineStore.LookupEntry(id);
if (skillInfo)
{
- int locale = handler->GetSessionDbcLocale();
+ uint8 locale = handler->GetSessionDbcLocale();
std::string name = skillInfo->name[locale];
if (name.empty())
continue;
@@ -868,7 +877,7 @@ public:
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(id);
if (spellInfo)
{
- int locale = handler->GetSessionDbcLocale();
+ uint8 locale = handler->GetSessionDbcLocale();
std::string name = spellInfo->SpellName[locale];
if (name.empty())
continue;
@@ -965,7 +974,7 @@ public:
if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(id))
{
- int locale = handler->GetSessionDbcLocale();
+ uint8 locale = handler->GetSessionDbcLocale();
std::string name = spellInfo->SpellName[locale];
if (name.empty())
{
@@ -973,49 +982,49 @@ public:
return true;
}
- bool known = target && target->HasSpell(id);
- bool learn = (spellInfo->Effects[0].Effect == SPELL_EFFECT_LEARN_SPELL);
+ bool known = target && target->HasSpell(id);
+ bool learn = (spellInfo->Effects[0].Effect == SPELL_EFFECT_LEARN_SPELL);
- SpellInfo const* learnSpellInfo = sSpellMgr->GetSpellInfo(spellInfo->Effects[0].TriggerSpell);
+ SpellInfo const* learnSpellInfo = sSpellMgr->GetSpellInfo(spellInfo->Effects[0].TriggerSpell);
- uint32 talentCost = GetTalentSpellCost(id);
+ uint32 talentCost = GetTalentSpellCost(id);
- bool talent = (talentCost > 0);
- bool passive = spellInfo->IsPassive();
- bool active = target && target->HasAura(id);
+ bool talent = (talentCost > 0);
+ bool passive = spellInfo->IsPassive();
+ bool active = target && target->HasAura(id);
- // unit32 used to prevent interpreting uint8 as char at output
- // find rank of learned spell for learning spell, or talent rank
- uint32 rank = talentCost ? talentCost : learn && learnSpellInfo ? learnSpellInfo->GetRank() : spellInfo->GetRank();
+ // unit32 used to prevent interpreting uint8 as char at output
+ // find rank of learned spell for learning spell, or talent rank
+ uint32 rank = talentCost ? talentCost : learn && learnSpellInfo ? learnSpellInfo->GetRank() : spellInfo->GetRank();
- // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
- std::ostringstream ss;
- if (handler->GetSession())
- ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name;
- else
- ss << id << " - " << name;
+ // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
+ std::ostringstream ss;
+ if (handler->GetSession())
+ ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name;
+ else
+ ss << id << " - " << name;
- // include rank in link name
- if (rank)
- ss << handler->GetTrinityString(LANG_SPELL_RANK) << rank;
+ // include rank in link name
+ if (rank)
+ ss << handler->GetTrinityString(LANG_SPELL_RANK) << rank;
- if (handler->GetSession())
- ss << ' ' << localeNames[locale] << "]|h|r";
- else
- ss << ' ' << localeNames[locale];
-
- if (talent)
- ss << handler->GetTrinityString(LANG_TALENT);
- if (passive)
- ss << handler->GetTrinityString(LANG_PASSIVE);
- if (learn)
- ss << handler->GetTrinityString(LANG_LEARN);
- if (known)
- ss << handler->GetTrinityString(LANG_KNOWN);
- if (active)
- ss << handler->GetTrinityString(LANG_ACTIVE);
-
- handler->SendSysMessage(ss.str().c_str());
+ if (handler->GetSession())
+ ss << ' ' << localeNames[locale] << "]|h|r";
+ else
+ ss << ' ' << localeNames[locale];
+
+ if (talent)
+ ss << handler->GetTrinityString(LANG_TALENT);
+ if (passive)
+ ss << handler->GetTrinityString(LANG_PASSIVE);
+ if (learn)
+ ss << handler->GetTrinityString(LANG_LEARN);
+ if (known)
+ ss << handler->GetTrinityString(LANG_KNOWN);
+ if (active)
+ ss << handler->GetTrinityString(LANG_ACTIVE);
+
+ handler->SendSysMessage(ss.str().c_str());
}
else
handler->SendSysMessage(LANG_COMMAND_NOSPELLFOUND);
@@ -1047,7 +1056,7 @@ public:
TaxiNodesEntry const* nodeEntry = sTaxiNodesStore.LookupEntry(id);
if (nodeEntry)
{
- int locale = handler->GetSessionDbcLocale();
+ uint8 locale = handler->GetSessionDbcLocale();
std::string name = nodeEntry->name[locale];
if (name.empty())
continue;
@@ -1185,7 +1194,7 @@ public:
if (titleInfo)
{
/// @todo: implement female support
- int locale = handler->GetSessionDbcLocale();
+ uint8 locale = handler->GetSessionDbcLocale();
std::string name = titleInfo->nameMale[locale];
if (name.empty())
continue;
diff --git a/src/server/scripts/Commands/cs_misc.cpp b/src/server/scripts/Commands/cs_misc.cpp
index 459aed93621..ba3a34f98b1 100644
--- a/src/server/scripts/Commands/cs_misc.cpp
+++ b/src/server/scripts/Commands/cs_misc.cpp
@@ -1342,31 +1342,31 @@ public:
TC_LOG_DEBUG("misc", handler->GetTrinityString(LANG_ADDITEMSET), itemSetId);
bool found = false;
- ItemTemplateContainer const* its = sObjectMgr->GetItemTemplateStore();
- for (ItemTemplateContainer::const_iterator itr = its->begin(); itr != its->end(); ++itr)
+ ItemTemplateContainer const& its = sObjectMgr->GetItemTemplateStore();
+ for (auto const& itemTemplate : its)
{
- if (itr->second.ItemSet == itemSetId)
+ if (!itemTemplate || itemTemplate->ItemSet != itemSetId)
+ continue;
+
+ found = true;
+ ItemPosCountVec dest;
+ InventoryResult msg = playerTarget->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemTemplate->ItemId, 1);
+ if (msg == EQUIP_ERR_OK)
{
- found = true;
- ItemPosCountVec dest;
- InventoryResult msg = playerTarget->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itr->second.ItemId, 1);
- if (msg == EQUIP_ERR_OK)
- {
- Item* item = playerTarget->StoreNewItem(dest, itr->second.ItemId, true);
+ Item* item = playerTarget->StoreNewItem(dest, itemTemplate->ItemId, true);
- // remove binding (let GM give it to another player later)
- if (player == playerTarget)
- item->SetBinding(false);
+ // remove binding (let GM give it to another player later)
+ if (player == playerTarget)
+ item->SetBinding(false);
- player->SendNewItem(item, 1, false, true);
- if (player != playerTarget)
- playerTarget->SendNewItem(item, 1, true, false);
- }
- else
- {
- player->SendEquipError(msg, nullptr, nullptr, itr->second.ItemId);
- handler->PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itr->second.ItemId, 1);
- }
+ player->SendNewItem(item, 1, false, true);
+ if (player != playerTarget)
+ playerTarget->SendNewItem(item, 1, true, false);
+ }
+ else
+ {
+ player->SendEquipError(msg, nullptr, nullptr, itemTemplate->ItemId);
+ handler->PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemTemplate->ItemId, 1);
}
}
diff --git a/src/server/scripts/Commands/cs_quest.cpp b/src/server/scripts/Commands/cs_quest.cpp
index b4622ba0179..c31f5462e8f 100644
--- a/src/server/scripts/Commands/cs_quest.cpp
+++ b/src/server/scripts/Commands/cs_quest.cpp
@@ -81,15 +81,15 @@ public:
}
// check item starting quest (it can work incorrectly if added without item in inventory)
- ItemTemplateContainer const* itc = sObjectMgr->GetItemTemplateStore();
- ItemTemplateContainer::const_iterator result = std::find_if(itc->begin(), itc->end(), [quest](ItemTemplateContainer::value_type const& value)
+ ItemTemplateContainer const& itc = sObjectMgr->GetItemTemplateStore();
+ auto itr = std::find_if(std::begin(itc), std::end(itc), [quest](ItemTemplateContainer::value_type const& value)
{
- return value.second.StartQuest == quest->GetQuestId();
+ return value && value->StartQuest == quest->GetQuestId();
});
- if (result != itc->end())
+ if (itr != std::end(itc))
{
- handler->PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, result->second.ItemId);
+ handler->PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, (*itr)->ItemId);
handler->SetSentErrorMessage(true);
return false;
}