diff --git a/src/game/AI/BaseAI/PetAI.cpp b/src/game/AI/BaseAI/PetAI.cpp index 47a8caa414..215f08c760 100644 --- a/src/game/AI/BaseAI/PetAI.cpp +++ b/src/game/AI/BaseAI/PetAI.cpp @@ -190,7 +190,7 @@ void PetAI::UpdateAI(const uint32 diff) && m_unit->IsWithinLOSInMap(victim, true)) { uint32 spellId = charminfo->GetSpellOpener(); - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); Spell* spell = new Spell(m_unit, spellInfo, TRIGGERED_NONE); // Push back stored spell @@ -208,7 +208,7 @@ void PetAI::UpdateAI(const uint32 diff) if (!spellId) continue; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) continue; diff --git a/src/game/AI/BaseAI/TotemAI.cpp b/src/game/AI/BaseAI/TotemAI.cpp index 06c9e97cf3..b606ff05a6 100644 --- a/src/game/AI/BaseAI/TotemAI.cpp +++ b/src/game/AI/BaseAI/TotemAI.cpp @@ -66,7 +66,7 @@ void TotemAI::UpdateAI(const uint32 diff) return; // Search spell - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(getTotem().GetSpell()); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(getTotem().GetSpell()); if (!spellInfo) return; diff --git a/src/game/AI/BaseAI/UnitAI.cpp b/src/game/AI/BaseAI/UnitAI.cpp index c15eb9c8a3..2d0d48bc15 100644 --- a/src/game/AI/BaseAI/UnitAI.cpp +++ b/src/game/AI/BaseAI/UnitAI.cpp @@ -150,7 +150,7 @@ CanCastResult UnitAI::DoCastSpellIfCan(Unit* target, uint32 spellId, uint32 cast // Allowed to cast only if not casting (unless we interrupt ourself) or if spell is triggered if (!caster->IsNonMeleeSpellCasted(false) || (castFlags & (CAST_TRIGGERED | CAST_INTERRUPT_PREVIOUS))) { - if (const SpellEntry* spellInfo = sSpellTemplate.LookupEntry(spellId)) + if (const SpellEntry* spellInfo = sSpellTemplate.LookupEntry(spellId)) { // If cast flag CAST_AURA_NOT_PRESENT is active, check if target already has aura on them if (castFlags & CAST_AURA_NOT_PRESENT) diff --git a/src/game/AI/EventAI/CreatureEventAI.cpp b/src/game/AI/EventAI/CreatureEventAI.cpp index eb5e9e6608..61b7ca70a6 100644 --- a/src/game/AI/EventAI/CreatureEventAI.cpp +++ b/src/game/AI/EventAI/CreatureEventAI.cpp @@ -190,7 +190,7 @@ void CreatureEventAI::InitAI() if (!m_mainSpellId) { m_mainSpellId = i.action[actionIdx].cast.spellId; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(m_mainSpellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(m_mainSpellId); m_mainSpellCost = Spell::CalculatePowerCost(spellInfo, m_creature); m_mainSpellMinRange = GetSpellMinRange(sSpellRangeStore.LookupEntry(spellInfo->rangeIndex)); m_mainAttackMask = SpellSchoolMask(m_mainAttackMask + spellInfo->SchoolMask); @@ -465,18 +465,18 @@ bool CreatureEventAI::CheckEvent(CreatureEventAIHolder& holder, Unit* actionInvo { if (!m_creature->IsInCombat()) return false; - + DoFindFriendlyMissingBuff(pList, (float)event.friendly_buff.radius, event.friendly_buff.spellId, false); } - else if (event.friendly_buff.inCombat == 1) - DoFindFriendlyMissingBuff(pList, (float)event.friendly_buff.radius, event.friendly_buff.spellId, true); + else if (event.friendly_buff.inCombat == 1) + DoFindFriendlyMissingBuff(pList, (float)event.friendly_buff.radius, event.friendly_buff.spellId, true); else if (event.friendly_buff.inCombat == 2) { if (m_creature->IsInCombat()) return false; - + DoFindFriendlyMissingBuff(pList, (float)event.friendly_buff.radius, event.friendly_buff.spellId, true); - } + } // List is empty if (pList.empty()) @@ -830,7 +830,7 @@ bool CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32 if (!(action.cast.castFlags & (CAST_TRIGGERED | CAST_FORCE_CAST | CAST_FORCE_TARGET_SELF))) { spellId = action.cast.spellId; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) return false; if (!IsIgnoreLosSpellCast(spellInfo)) diff --git a/src/game/AI/EventAI/CreatureEventAIMgr.cpp b/src/game/AI/EventAI/CreatureEventAIMgr.cpp index a893a335e2..569195e421 100644 --- a/src/game/AI/EventAI/CreatureEventAIMgr.cpp +++ b/src/game/AI/EventAI/CreatureEventAIMgr.cpp @@ -298,7 +298,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() temp.raw.params[i] = fields[6 + i].GetUInt32(); // Creature does not exist in database - if (!sCreatureStorage.LookupEntry(temp.creature_id)) + if (!sCreatureStorage.LookupEntry(temp.creature_id)) { sLog.outErrorEventAI("Event %u has script for non-existing creature entry (%u), skipping.", i, temp.creature_id); continue; @@ -345,7 +345,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() case EVENT_T_SPELLHIT: if (temp.spell_hit.spellId) { - SpellEntry const* pSpell = sSpellTemplate.LookupEntry(temp.spell_hit.spellId); + SpellEntry const* pSpell = sSpellTemplate.LookupEntry(temp.spell_hit.spellId); if (!pSpell) { sLog.outErrorEventAI("Creature %u has nonexistent SpellID(%u) defined in event %u.", temp.creature_id, temp.spell_hit.spellId, i); @@ -369,7 +369,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() sLog.outErrorEventAI("Creature %u are using repeatable event(%u) with param4 < param3 (RepeatMax < RepeatMin). Event will never repeat.", temp.creature_id, i); break; case EVENT_T_OOC_LOS: - if (temp.ooc_los.conditionId && !sConditionStorage.LookupEntry(temp.ooc_los.conditionId)) + if (temp.ooc_los.conditionId && !sConditionStorage.LookupEntry(temp.ooc_los.conditionId)) { sLog.outErrorDb("Creature %u has `ConditionId` = %u but does not exist. Setting ConditionId to 0 for event %u.", temp.creature_id, temp.ooc_los.conditionId, i); temp.ooc_los.conditionId = 0; @@ -388,7 +388,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() sLog.outErrorEventAI("Creature %u are using spawned event(%u) with param1 = %u 'map specific' but map (param2: %u) does not exist. Event will never repeat.", temp.creature_id, i, temp.spawned.condition, temp.spawned.conditionValue1); break; case SPAWNED_EVENT_ZONE: - if (!GetAreaEntryByAreaID(temp.spawned.conditionValue1)) + if (!TerrainManager::GetAreaEntryByAreaID(temp.spawned.conditionValue1)) sLog.outErrorEventAI("Creature %u are using spawned event(%u) with param1 = %u 'area specific' but area (param2: %u) does not exist. Event will never repeat.", temp.creature_id, i, temp.spawned.condition, temp.spawned.conditionValue1); break; default: @@ -406,7 +406,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() break; case EVENT_T_FRIENDLY_MISSING_BUFF: { - SpellEntry const* pSpell = sSpellTemplate.LookupEntry(temp.friendly_buff.spellId); + SpellEntry const* pSpell = sSpellTemplate.LookupEntry(temp.friendly_buff.spellId); if (!pSpell) { sLog.outErrorEventAI("Creature %u has nonexistent SpellID(%u) defined in event %u.", temp.creature_id, temp.friendly_buff.spellId, i); @@ -432,7 +432,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() case EVENT_T_SUMMONED_UNIT: case EVENT_T_SUMMONED_JUST_DIED: case EVENT_T_SUMMONED_JUST_DESPAWN: - if (!sCreatureStorage.LookupEntry(temp.summoned.creatureId)) + if (!sCreatureStorage.LookupEntry(temp.summoned.creatureId)) sLog.outErrorEventAI("Creature %u are using event(%u) with nonexistent creature template id (%u) in param1, skipped.", temp.creature_id, i, temp.summoned.creatureId); if (temp.summoned.repeatMax < temp.summoned.repeatMin) sLog.outErrorEventAI("Creature %u are using event(%u) with param2 < param1 (RepeatMax < RepeatMin). Event will never repeat.", temp.creature_id, i); @@ -445,7 +445,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() continue; case EVENT_T_DEATH: { - if (temp.death.conditionId && !sConditionStorage.LookupEntry(temp.death.conditionId)) + if (temp.death.conditionId && !sConditionStorage.LookupEntry(temp.death.conditionId)) { // condition does not exist for some reason sLog.outErrorDb("Creature %u has `ConditionId` = %u but does not exist. Setting ConditionId to 0 for event %u.", temp.creature_id, temp.death.conditionId, i); @@ -479,7 +479,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() continue; } - if (temp.receive_emote.conditionId && !sConditionStorage.LookupEntry(temp.receive_emote.conditionId)) + if (temp.receive_emote.conditionId && !sConditionStorage.LookupEntry(temp.receive_emote.conditionId)) { sLog.outErrorDb("Creature %u has `ConditionId` = %u but does not exist. Setting ConditionId to 0 for event %u.", temp.creature_id, temp.receive_emote.conditionId, i); temp.receive_emote.conditionId = 0; @@ -500,7 +500,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() case EVENT_T_MISSING_AURA: case EVENT_T_TARGET_MISSING_AURA: { - SpellEntry const* pSpell = sSpellTemplate.LookupEntry(temp.buffed.spellId); + SpellEntry const* pSpell = sSpellTemplate.LookupEntry(temp.buffed.spellId); if (!pSpell) { sLog.outErrorEventAI("Creature %u has nonexistent SpellID(%u) defined in event %u.", temp.creature_id, temp.buffed.spellId, i); @@ -518,7 +518,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() case EVENT_T_RECEIVE_AI_EVENT: { // Sender-Creature does not exist in database - if (temp.receiveAIEvent.senderEntry && !sCreatureStorage.LookupEntry(temp.receiveAIEvent.senderEntry)) + if (temp.receiveAIEvent.senderEntry && !sCreatureStorage.LookupEntry(temp.receiveAIEvent.senderEntry)) { sLog.outErrorEventAI("Event %u has nonexisting creature (%u) defined for event RECEIVE_AI_EVENT, skipping.", i, temp.receiveAIEvent.senderEntry); continue; @@ -562,7 +562,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() case EVENT_T_SPELLHIT_TARGET: if (temp.spell_hit_target.spellId) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(temp.spell_hit_target.spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(temp.spell_hit_target.spellId); if (!spellInfo) { sLog.outErrorEventAI("Creature %u has nonexistent SpellID(%u) defined in event %u.", temp.creature_id, temp.spell_hit_target.spellId, i); @@ -655,7 +655,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() case ACTION_T_MORPH_TO_ENTRY_OR_MODEL: if (action.morph.creatureId != 0 || action.morph.modelId != 0) { - if (action.morph.creatureId && !sCreatureStorage.LookupEntry(action.morph.creatureId)) + if (action.morph.creatureId && !sCreatureStorage.LookupEntry(action.morph.creatureId)) { sLog.outErrorEventAI("Event %u Action %u uses nonexistent Creature entry %u.", i, j + 1, action.morph.creatureId); action.morph.creatureId = 0; @@ -702,7 +702,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() break; case ACTION_T_CAST: { - const SpellEntry* spell = sSpellTemplate.LookupEntry(action.cast.spellId); + const SpellEntry* spell = sSpellTemplate.LookupEntry(action.cast.spellId); if (!spell) sLog.outErrorEventAI("Event %u Action %u uses nonexistent SpellID %u.", i, j + 1, action.cast.spellId); /* FIXME: temp.raw.param3 not have event tipes with recovery time in it.... @@ -760,7 +760,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() break; } case ACTION_T_SPAWN : - if (!sCreatureStorage.LookupEntry(action.summon.creatureId)) + if (!sCreatureStorage.LookupEntry(action.summon.creatureId)) sLog.outErrorEventAI("Event %u Action %u uses nonexistent creature entry %u.", i, j + 1, action.summon.creatureId); IsValidTargetType(temp.event_type, action.type, action.summon.target, i, j + 1); @@ -786,9 +786,9 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() IsValidTargetType(temp.event_type, action.type, action.quest_event.target, i, j + 1); break; case ACTION_T_CAST_EVENT: - if (!sCreatureStorage.LookupEntry(action.cast_event.creatureId)) + if (!sCreatureStorage.LookupEntry(action.cast_event.creatureId)) sLog.outErrorEventAI("Event %u Action %u uses nonexistent creature entry %u.", i, j + 1, action.cast_event.creatureId); - if (!sSpellTemplate.LookupEntry(action.cast_event.spellId)) + if (!sSpellTemplate.LookupEntry(action.cast_event.spellId)) sLog.outErrorEventAI("Event %u Action %u uses nonexistent SpellID %u.", i, j + 1, action.cast_event.spellId); IsValidTargetType(temp.event_type, action.type, action.cast_event.target, i, j + 1); break; @@ -821,13 +821,13 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() sLog.outErrorEventAI("Event %u Action %u uses nonexistent Quest entry %u.", i, j + 1, action.quest_event_all.questId); break; case ACTION_T_CAST_EVENT_ALL: - if (!sCreatureStorage.LookupEntry(action.cast_event_all.creatureId)) + if (!sCreatureStorage.LookupEntry(action.cast_event_all.creatureId)) sLog.outErrorEventAI("Event %u Action %u uses nonexistent creature entry %u.", i, j + 1, action.cast_event_all.creatureId); - if (!sSpellTemplate.LookupEntry(action.cast_event_all.spellId)) + if (!sSpellTemplate.LookupEntry(action.cast_event_all.spellId)) sLog.outErrorEventAI("Event %u Action %u uses nonexistent SpellID %u.", i, j + 1, action.cast_event_all.spellId); break; case ACTION_T_REMOVEAURASFROMSPELL: - if (!sSpellTemplate.LookupEntry(action.remove_aura.spellId)) + if (!sSpellTemplate.LookupEntry(action.remove_aura.spellId)) sLog.outErrorEventAI("Event %u Action %u uses nonexistent SpellID %u.", i, j + 1, action.remove_aura.spellId); IsValidTargetType(temp.event_type, action.type, action.remove_aura.target, i, j + 1); break; @@ -852,14 +852,14 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() } break; case ACTION_T_SUMMON_ID: - if (!sCreatureStorage.LookupEntry(action.summon_id.creatureId)) + if (!sCreatureStorage.LookupEntry(action.summon_id.creatureId)) sLog.outErrorEventAI("Event %u Action %u uses nonexistent creature entry %u.", i, j + 1, action.summon_id.creatureId); IsValidTargetType(temp.event_type, action.type, action.summon_id.target, i, j + 1); if (m_CreatureEventAI_Summon_Map.find(action.summon_id.spawnId) == m_CreatureEventAI_Summon_Map.end()) sLog.outErrorEventAI("Event %u Action %u summons missing CreatureEventAI_Summon %u", i, j + 1, action.summon_id.spawnId); break; case ACTION_T_KILLED_MONSTER: - if (!sCreatureStorage.LookupEntry(action.killed_monster.creatureId)) + if (!sCreatureStorage.LookupEntry(action.killed_monster.creatureId)) sLog.outErrorEventAI("Event %u Action %u uses nonexistent creature entry %u.", i, j + 1, action.killed_monster.creatureId); IsValidTargetType(temp.event_type, action.type, action.killed_monster.target, i, j + 1); break; @@ -875,7 +875,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() IsValidTargetType(temp.event_type, action.type, action.set_inst_data64.target, i, j + 1); break; case ACTION_T_UPDATE_TEMPLATE: - if (!sCreatureStorage.LookupEntry(action.update_template.creatureId)) + if (!sCreatureStorage.LookupEntry(action.update_template.creatureId)) sLog.outErrorEventAI("Event %u Action %u uses nonexistent creature entry %u.", i, j + 1, action.update_template.creatureId); break; case ACTION_T_SET_SHEATH: @@ -895,7 +895,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() case ACTION_T_MOUNT_TO_ENTRY_OR_MODEL: if (action.mount.creatureId != 0 || action.mount.modelId != 0) { - if (action.mount.creatureId && !sCreatureStorage.LookupEntry(action.mount.creatureId)) + if (action.mount.creatureId && !sCreatureStorage.LookupEntry(action.mount.creatureId)) { sLog.outErrorEventAI("Event %u Action %u uses nonexistent Creature entry %u.", i, j + 1, action.mount.creatureId); action.morph.creatureId = 0; @@ -1032,7 +1032,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() IsValidTargetType(temp.event_type, action.type, action.attackStart.target, i, j + 1); break; case ACTION_T_DESPAWN_GUARDIANS: - if (action.despawnGuardians.entryId && !sCreatureStorage.LookupEntry(action.despawnGuardians.entryId)) + if (action.despawnGuardians.entryId && !sCreatureStorage.LookupEntry(action.despawnGuardians.entryId)) { sLog.outErrorEventAI("Event %u Action %u uses nonexistent Creature entry %u.", i, j + 1, action.despawnGuardians.entryId); action.despawnGuardians.entryId = 0; @@ -1106,7 +1106,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() CreatureEventAI_Action& action = temp.action[j]; if (temp.action[j].type == ACTION_T_CAST && temp.action[j].cast.target == TARGET_T_EVENT_SPECIFIC) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(temp.action[j].cast.spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(temp.action[j].cast.spellId); if (spellInfo->HasAttribute(SPELL_ATTR_EX_CANT_TARGET_SELF)) data.friendlyHp.targetSelf = false; } @@ -1123,17 +1123,14 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() m_usedTextsAmount = usedTextIds.size(); // post check - for (uint32 i = 1; i < sCreatureStorage.GetMaxEntry(); ++i) + for (auto cInfo : sCreatureStorage) { - if (CreatureInfo const* cInfo = sCreatureStorage.LookupEntry(i)) - { - bool ainame = strcmp(cInfo->AIName, "EventAI") == 0 || strcmp(cInfo->AIName, "GuardianAI") == 0; - bool hasevent = m_CreatureEventAI_Event_Map.find(i) != m_CreatureEventAI_Event_Map.end(); - if (ainame && !hasevent) - sLog.outErrorEventAI("EventAI not has script for creature entry (%u), but AIName = '%s'.", i, cInfo->AIName); - else if (!ainame && hasevent) - sLog.outErrorEventAI("EventAI has script for creature entry (%u), but AIName = '%s' instead 'EventAI'.", i, cInfo->AIName); - } + bool ainame = strcmp(cInfo->AIName, "EventAI") == 0 || strcmp(cInfo->AIName, "GuardianAI") == 0; + bool hasevent = m_CreatureEventAI_Event_Map.find(cInfo->Entry) != m_CreatureEventAI_Event_Map.end(); + if (ainame && !hasevent) + sLog.outErrorEventAI("EventAI not has script for creature entry (%u), but AIName = '%s'.", cInfo->Entry, cInfo->AIName); + else if (!ainame && hasevent) + sLog.outErrorEventAI("EventAI has script for creature entry (%u), but AIName = '%s' instead 'EventAI'.", cInfo->Entry, cInfo->AIName); } CheckUnusedAITexts(); diff --git a/src/game/AI/ScriptDevAI/base/CombatAI.cpp b/src/game/AI/ScriptDevAI/base/CombatAI.cpp index 3851372691..567cdd5f7a 100644 --- a/src/game/AI/ScriptDevAI/base/CombatAI.cpp +++ b/src/game/AI/ScriptDevAI/base/CombatAI.cpp @@ -98,7 +98,7 @@ void RangedCombatAI::AddMainSpell(uint32 spellId) if (!m_mainSpellId) // only for first { m_mainSpellId = spellId; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(m_mainSpellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(m_mainSpellId); m_mainSpellCost = Spell::CalculatePowerCost(spellInfo, m_creature); m_mainSpellMinRange = GetSpellMinRange(sSpellRangeStore.LookupEntry(spellInfo->rangeIndex)); m_mainAttackMask = SpellSchoolMask(m_mainAttackMask + spellInfo->SchoolMask); diff --git a/src/game/AI/ScriptDevAI/include/sc_creature.cpp b/src/game/AI/ScriptDevAI/include/sc_creature.cpp index 8b5b13761d..2679abb732 100644 --- a/src/game/AI/ScriptDevAI/include/sc_creature.cpp +++ b/src/game/AI/ScriptDevAI/include/sc_creature.cpp @@ -102,7 +102,7 @@ void ScriptedAI::DoPlaySoundToSet(WorldObject* source, uint32 soundId) if (!source) return; - if (!GetSoundEntriesStore()->LookupEntry(soundId)) + if (!sSoundEntriesStore.LookupEntry(soundId)) { script_error_log("Invalid soundId %u used in DoPlaySoundToSet (Source: TypeId %u, GUID %u)", soundId, source->GetTypeId(), source->GetGUIDLow()); return; @@ -130,7 +130,7 @@ SpellEntry const* ScriptedAI::SelectSpell(Unit* target, int32 school, int32 mech // Check if each spell is viable(set it to null if not) for (uint8 i = 0; i < 4; ++i) { - SpellEntry const* tempSpellInfo = GetSpellStore()->LookupEntry(m_creature->m_spells[i]); + SpellEntry const* tempSpellInfo = GetSpellStore()->LookupEntry(m_creature->m_spells[i]); // This spell doesn't exist if (!tempSpellInfo) @@ -165,7 +165,7 @@ SpellEntry const* ScriptedAI::SelectSpell(Unit* target, int32 school, int32 mech continue; // Get the Range - SpellRangeEntry const* tempRange = GetSpellRangeStore()->LookupEntry(tempSpellInfo->rangeIndex); + SpellRangeEntry const* tempRange = sSpellRangeStore.LookupEntry(tempSpellInfo->rangeIndex); // Spell has invalid range store so we can't use it if (!tempRange) @@ -208,7 +208,7 @@ bool ScriptedAI::CanCast(Unit* target, SpellEntry const* spellInfo, bool trigger if (!triggered && m_creature->GetPower((Powers)spellInfo->powerType) < spellInfo->manaCost) return false; - SpellRangeEntry const* tempRange = GetSpellRangeStore()->LookupEntry(spellInfo->rangeIndex); + SpellRangeEntry const* tempRange = sSpellRangeStore.LookupEntry(spellInfo->rangeIndex); // Spell has invalid range store so we can't use it if (!tempRange) @@ -230,7 +230,7 @@ void FillSpellSummary() SpellSummary[i].Effects = 0; SpellSummary[i].Targets = 0; - SpellEntry const* tempSpell = GetSpellStore()->LookupEntry(i); + SpellEntry const* tempSpell = GetSpellStore()->LookupEntry(i); // This spell doesn't exist if (!tempSpell) continue; @@ -333,7 +333,7 @@ CreatureList ScriptedAI::DoFindFriendlyCC(float range) CreatureList ScriptedAI::DoFindFriendlyMissingBuff(float range, uint32 spellId, bool inCombat) { CreatureList creatureList; - + if (inCombat == false) { MaNGOS::FriendlyMissingBuffInRangeInCombatCheck u_check(m_creature, range, spellId); @@ -346,7 +346,7 @@ CreatureList ScriptedAI::DoFindFriendlyMissingBuff(float range, uint32 spellId, MaNGOS::CreatureListSearcher searcher(creatureList, u_check); Cell::VisitGridObjects(m_creature, searcher, range); - } + } return creatureList; } diff --git a/src/game/AI/ScriptDevAI/scripts/eastern_kingdoms/karazhan/boss_curator.cpp b/src/game/AI/ScriptDevAI/scripts/eastern_kingdoms/karazhan/boss_curator.cpp index f0b51333e0..645caee314 100644 --- a/src/game/AI/ScriptDevAI/scripts/eastern_kingdoms/karazhan/boss_curator.cpp +++ b/src/game/AI/ScriptDevAI/scripts/eastern_kingdoms/karazhan/boss_curator.cpp @@ -221,7 +221,7 @@ struct boss_curatorAI : public CombatAI uint32 randomSpell = astralFlareSpells[urand(0, 3)]; DoCastSpellIfCan(nullptr, randomSpell); ResetCombatAction(action, GetSubsequentActionTimer(action)); - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(randomSpell); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(randomSpell); // supposed to happen right away not on next oom if (m_creature->GetPower((Powers)spellInfo->powerType) < Spell::CalculatePowerCost(spellInfo, m_creature)) { diff --git a/src/game/AI/ScriptDevAI/scripts/eastern_kingdoms/karazhan/chess_event.cpp b/src/game/AI/ScriptDevAI/scripts/eastern_kingdoms/karazhan/chess_event.cpp index 363f795d64..6ba5a00ef5 100644 --- a/src/game/AI/ScriptDevAI/scripts/eastern_kingdoms/karazhan/chess_event.cpp +++ b/src/game/AI/ScriptDevAI/scripts/eastern_kingdoms/karazhan/chess_event.cpp @@ -401,7 +401,7 @@ struct npc_chess_piece_genericAI : public Scripted_NoMovementAI { m_creature->SetFacingTo(m_fCurrentOrientation); } - + } void SpellHit(Unit* pCaster, const SpellEntry* pSpell) override @@ -486,7 +486,7 @@ struct npc_chess_piece_genericAI : public Scripted_NoMovementAI else ++itr; } - + if (lSquaresList.empty()) return nullptr; @@ -654,7 +654,7 @@ bool EffectDummyCreature_npc_chess_generic(Unit* pCaster, uint32 uiSpellId, Spel case NPC_ORC_WOLF: uiMeleeSpell = SPELL_MELEE_WOLF; break; case NPC_SUMMONED_DAEMON: uiMeleeSpell = SPELL_MELEE_DAEMON; break; } - + pCreatureTarget->CastSpell(pCreatureTarget, uiMeleeSpell, TRIGGERED_OLD_TRIGGERED); return true; } @@ -743,7 +743,7 @@ struct npc_king_llaneAI : public npc_chess_piece_genericAI DoCastSpellIfCan(nullptr, SPELL_HEROISM); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_HEROISM); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_HEROISM); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -757,7 +757,7 @@ struct npc_king_llaneAI : public npc_chess_piece_genericAI DoCastSpellIfCan(nullptr, SPELL_SWEEP); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_SWEEP); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_SWEEP); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -856,7 +856,7 @@ struct npc_warchief_blackhandAI : public npc_chess_piece_genericAI DoCastSpellIfCan(nullptr, SPELL_BLOODLUST); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_BLOODLUST); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_BLOODLUST); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -870,7 +870,7 @@ struct npc_warchief_blackhandAI : public npc_chess_piece_genericAI DoCastSpellIfCan(nullptr, SPELL_CLEAVE); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_CLEAVE); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_CLEAVE); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -932,7 +932,7 @@ struct npc_human_conjurerAI : public npc_chess_piece_genericAI DoCastSpellIfCan(pTarget, SPELL_ELEMENTAL_BLAST); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_ELEMENTAL_BLAST); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_ELEMENTAL_BLAST); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -946,7 +946,7 @@ struct npc_human_conjurerAI : public npc_chess_piece_genericAI DoCastSpellIfCan(pTarget, SPELL_RAIN_OF_FIRE); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_RAIN_OF_FIRE); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_RAIN_OF_FIRE); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -1008,7 +1008,7 @@ struct npc_orc_warlockAI : public npc_chess_piece_genericAI DoCastSpellIfCan(pTarget, SPELL_FIREBALL); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_FIREBALL); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_FIREBALL); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -1022,7 +1022,7 @@ struct npc_orc_warlockAI : public npc_chess_piece_genericAI DoCastSpellIfCan(pTarget, SPELL_POISON_CLOUD_ACTION); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_POISON_CLOUD_ACTION); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_POISON_CLOUD_ACTION); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -1098,7 +1098,7 @@ struct npc_human_footmanAI : public npc_chess_piece_genericAI DoCastSpellIfCan(nullptr, SPELL_HEROIC_BLOW); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_HEROIC_BLOW); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_HEROIC_BLOW); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -1112,7 +1112,7 @@ struct npc_human_footmanAI : public npc_chess_piece_genericAI DoCastSpellIfCan(nullptr, SPELL_SHIELD_BLOCK); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_SHIELD_BLOCK); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_SHIELD_BLOCK); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -1188,7 +1188,7 @@ struct npc_orc_gruntAI : public npc_chess_piece_genericAI DoCastSpellIfCan(nullptr, SPELL_VICIOUS_STRIKE); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_VICIOUS_STRIKE); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_VICIOUS_STRIKE); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -1202,7 +1202,7 @@ struct npc_orc_gruntAI : public npc_chess_piece_genericAI DoCastSpellIfCan(nullptr, SPELL_WEAPON_DEFLECTION); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_WEAPON_DEFLECTION); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_WEAPON_DEFLECTION); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -1264,7 +1264,7 @@ struct npc_water_elementalAI : public npc_chess_piece_genericAI DoCastSpellIfCan(nullptr, SPELL_GEYSER); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_GEYSER); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_GEYSER); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -1278,7 +1278,7 @@ struct npc_water_elementalAI : public npc_chess_piece_genericAI DoCastSpellIfCan(nullptr, SPELL_WATER_SHIELD); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_WATER_SHIELD); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_WATER_SHIELD); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -1340,7 +1340,7 @@ struct npc_summoned_daemonAI : public npc_chess_piece_genericAI DoCastSpellIfCan(nullptr, SPELL_HELLFIRE_CHESS); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_HELLFIRE_CHESS); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_HELLFIRE_CHESS); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -1354,7 +1354,7 @@ struct npc_summoned_daemonAI : public npc_chess_piece_genericAI DoCastSpellIfCan(nullptr, SPELL_FIRE_SHIELD); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_FIRE_SHIELD); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_FIRE_SHIELD); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -1416,7 +1416,7 @@ struct npc_human_chargerAI : public npc_chess_piece_genericAI DoCastSpellIfCan(nullptr, SPELL_SMASH); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_SMASH); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_SMASH); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -1430,7 +1430,7 @@ struct npc_human_chargerAI : public npc_chess_piece_genericAI DoCastSpellIfCan(nullptr, SPELL_STOMP); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_STOMP); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_STOMP); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -1492,7 +1492,7 @@ struct npc_orc_wolfAI : public npc_chess_piece_genericAI DoCastSpellIfCan(nullptr, SPELL_BITE); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_BITE); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_BITE); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -1506,7 +1506,7 @@ struct npc_orc_wolfAI : public npc_chess_piece_genericAI DoCastSpellIfCan(nullptr, SPELL_HOWL); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_HOWL); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_HOWL); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -1568,7 +1568,7 @@ struct npc_human_clericAI : public npc_chess_piece_genericAI DoCastSpellIfCan(pTarget, SPELL_HEALING); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_HEALING); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_HEALING); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -1582,7 +1582,7 @@ struct npc_human_clericAI : public npc_chess_piece_genericAI DoCastSpellIfCan(nullptr, SPELL_HOLY_LANCE); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_HOLY_LANCE); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_HOLY_LANCE); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -1644,7 +1644,7 @@ struct npc_orc_necrolyteAI : public npc_chess_piece_genericAI DoCastSpellIfCan(pTarget, SPELL_SHADOW_MEND_ACTION); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_SHADOW_MEND_ACTION); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_SHADOW_MEND_ACTION); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -1658,7 +1658,7 @@ struct npc_orc_necrolyteAI : public npc_chess_piece_genericAI DoCastSpellIfCan(nullptr, SPELL_SHADOW_SPEAR); // reset timer based on spell values - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_SHADOW_SPEAR); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_SHADOW_SPEAR); return pSpell->RecoveryTime ? pSpell->RecoveryTime : pSpell->CategoryRecoveryTime; } @@ -1688,7 +1688,7 @@ bool GossipHello_npc_orc_necrolyte(Player* pPlayer, Creature* pCreature) struct go_chessboard : public GameObjectAI { - go_chessboard(GameObject* go) : GameObjectAI(go), m_auraSearchTimer(1000), m_spellInfo(sSpellTemplate.LookupEntry(SPELL_GAME_IN_SESSION)), m_started(false) {} + go_chessboard(GameObject* go) : GameObjectAI(go), m_auraSearchTimer(1000), m_spellInfo(sSpellTemplate.LookupEntry(SPELL_GAME_IN_SESSION)), m_started(false) {} uint32 m_auraSearchTimer; SpellEntry const* m_spellInfo; diff --git a/src/game/AI/ScriptDevAI/scripts/eastern_kingdoms/naxxramas/boss_kelthuzad.cpp b/src/game/AI/ScriptDevAI/scripts/eastern_kingdoms/naxxramas/boss_kelthuzad.cpp index eabf381f42..9ac1b91d36 100644 --- a/src/game/AI/ScriptDevAI/scripts/eastern_kingdoms/naxxramas/boss_kelthuzad.cpp +++ b/src/game/AI/ScriptDevAI/scripts/eastern_kingdoms/naxxramas/boss_kelthuzad.cpp @@ -708,7 +708,7 @@ struct GuardianPeriodic : public AuraScript if (Unit* target = aura->GetTarget()) { if (target->HasAuraType(SPELL_AURA_MOD_STUN)) // Shackle Undead applies SPELL_AURA_MOD_STUN, so we cover all ranks of the spell this way - data.spellInfo = sSpellTemplate.LookupEntry(SPELL_GUARDIAN_SHACKLE); // Summon Ice Block + data.spellInfo = sSpellTemplate.LookupEntry(SPELL_GUARDIAN_SHACKLE); // Summon Ice Block } } }; diff --git a/src/game/AI/ScriptDevAI/scripts/eastern_kingdoms/naxxramas/boss_sapphiron.cpp b/src/game/AI/ScriptDevAI/scripts/eastern_kingdoms/naxxramas/boss_sapphiron.cpp index 20ec52712f..8193df18a4 100644 --- a/src/game/AI/ScriptDevAI/scripts/eastern_kingdoms/naxxramas/boss_sapphiron.cpp +++ b/src/game/AI/ScriptDevAI/scripts/eastern_kingdoms/naxxramas/boss_sapphiron.cpp @@ -350,7 +350,7 @@ struct PeriodicIceBolt : public AuraScript if (target->IsAlive() && !target->HasAura(SPELL_ICEBOLT_IMMUNITY)) { target->CastSpell(target, SPELL_ICEBOLT_IMMUNITY, TRIGGERED_OLD_TRIGGERED); // Icebolt which causes immunity to frost dmg - data.spellInfo = sSpellTemplate.LookupEntry(SPELL_ICEBLOCK_SUMMON); // Summon Ice Block + data.spellInfo = sSpellTemplate.LookupEntry(SPELL_ICEBLOCK_SUMMON); // Summon Ice Block } } } @@ -386,7 +386,7 @@ struct DespawnBuffet : public AuraScript void OnPeriodicTrigger(Aura* aura, PeriodicTriggerData& data) const override { if (Unit* target = aura->GetTarget()) - data.spellInfo = sSpellTemplate.LookupEntry(SPELL_DESPAWN_BUFFET_EFFECT); // Summon Ice Block + data.spellInfo = sSpellTemplate.LookupEntry(SPELL_DESPAWN_BUFFET_EFFECT); // Summon Ice Block } }; diff --git a/src/game/AI/ScriptDevAI/scripts/eastern_kingdoms/zulaman/boss_halazzi.cpp b/src/game/AI/ScriptDevAI/scripts/eastern_kingdoms/zulaman/boss_halazzi.cpp index 80d9f90bb7..36c6fe8fe2 100644 --- a/src/game/AI/ScriptDevAI/scripts/eastern_kingdoms/zulaman/boss_halazzi.cpp +++ b/src/game/AI/ScriptDevAI/scripts/eastern_kingdoms/zulaman/boss_halazzi.cpp @@ -376,7 +376,7 @@ struct npc_corrupted_lightning_totemAI : public ScriptedAI void JustRespawned() override { m_creature->SetInCombatWithZone(); - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(SPELL_LIGHTNING); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(SPELL_LIGHTNING); m_creature->AddCooldown(*spellInfo); } diff --git a/src/game/AI/ScriptDevAI/scripts/kalimdor/caverns_of_time/hyjal/hyjalScripts.cpp b/src/game/AI/ScriptDevAI/scripts/kalimdor/caverns_of_time/hyjal/hyjalScripts.cpp index 530b16be96..1d90e2b241 100644 --- a/src/game/AI/ScriptDevAI/scripts/kalimdor/caverns_of_time/hyjal/hyjalScripts.cpp +++ b/src/game/AI/ScriptDevAI/scripts/kalimdor/caverns_of_time/hyjal/hyjalScripts.cpp @@ -223,7 +223,7 @@ struct npc_building_triggerAI : public ScriptedAI { npc_building_triggerAI(Creature* creature) : ScriptedAI(creature){} - void Reset() override + void Reset() override { m_creature->AI()->SetReactState(REACT_PASSIVE); } diff --git a/src/game/AI/ScriptDevAI/scripts/kalimdor/mulgore.cpp b/src/game/AI/ScriptDevAI/scripts/kalimdor/mulgore.cpp index 065b9299ad..89eff9d7a6 100644 --- a/src/game/AI/ScriptDevAI/scripts/kalimdor/mulgore.cpp +++ b/src/game/AI/ScriptDevAI/scripts/kalimdor/mulgore.cpp @@ -116,7 +116,7 @@ struct npc_kyle_the_frenziedAI : public ScriptedAI // Workaround for broken function GetGameObject if (!pGo) { - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_LUNCH); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_LUNCH); uint32 uiGameobjectEntry = pSpell->EffectMiscValue[EFFECT_INDEX_1]; diff --git a/src/game/AI/ScriptDevAI/scripts/kalimdor/temple_of_ahnqiraj/boss_cthun.cpp b/src/game/AI/ScriptDevAI/scripts/kalimdor/temple_of_ahnqiraj/boss_cthun.cpp index 6f6f993734..8448cc0baa 100644 --- a/src/game/AI/ScriptDevAI/scripts/kalimdor/temple_of_ahnqiraj/boss_cthun.cpp +++ b/src/game/AI/ScriptDevAI/scripts/kalimdor/temple_of_ahnqiraj/boss_cthun.cpp @@ -664,7 +664,7 @@ struct PeriodicRotate : public AuraScript target->SetFacingTo(newAngle); target->SetOrientation(newAngle); - data.spellInfo = sSpellTemplate.LookupEntry(SPELL_DARK_GLARE); + data.spellInfo = sSpellTemplate.LookupEntry(SPELL_DARK_GLARE); data.caster = aura->GetCaster(); data.target = nullptr; } diff --git a/src/game/AI/ScriptDevAI/scripts/kalimdor/temple_of_ahnqiraj/boss_ouro.cpp b/src/game/AI/ScriptDevAI/scripts/kalimdor/temple_of_ahnqiraj/boss_ouro.cpp index 0beea20e06..853339f98a 100644 --- a/src/game/AI/ScriptDevAI/scripts/kalimdor/temple_of_ahnqiraj/boss_ouro.cpp +++ b/src/game/AI/ScriptDevAI/scripts/kalimdor/temple_of_ahnqiraj/boss_ouro.cpp @@ -435,7 +435,7 @@ struct PeriodicScarabTrigger : public AuraScript { void OnPeriodicTrigger(Aura* aura, PeriodicTriggerData& data) const override { - data.spellInfo = sSpellTemplate.LookupEntry(SPELL_SUMMON_SCARABS); + data.spellInfo = sSpellTemplate.LookupEntry(SPELL_SUMMON_SCARABS); data.caster = aura->GetTarget(); data.target = nullptr; } diff --git a/src/game/AI/ScriptDevAI/scripts/outland/blades_edge_mountains.cpp b/src/game/AI/ScriptDevAI/scripts/outland/blades_edge_mountains.cpp index 7a4c9d7a1a..0ccb03ea19 100644 --- a/src/game/AI/ScriptDevAI/scripts/outland/blades_edge_mountains.cpp +++ b/src/game/AI/ScriptDevAI/scripts/outland/blades_edge_mountains.cpp @@ -1024,7 +1024,7 @@ struct npc_obelisk_triggerAI : public ScriptedAI else m_uiCheckTimer -= uiDiff; } - + if (m_uiActiveObelisk == 5) { if (m_uiActivateTimer) @@ -1644,7 +1644,7 @@ bool AreaTrigger_at_raven_prophecy(Player* pPlayer, AreaTriggerEntry const* pAt) { DoScriptText(prophecy.text, whisper, pPlayer); - //giving credit for the game object automatically negates the id, so we don't have to negate it + //giving credit for the game object automatically negates the id, so we don't have to negate it pPlayer->KilledMonsterCredit(prophecy.creature); } } @@ -1679,7 +1679,7 @@ enum // This is a first attempt to implement GO type 30 behaviour struct go_aura_generator_000AI : public GameObjectAI { - go_aura_generator_000AI(GameObject* go) : GameObjectAI(go), m_auraSearchTimer(1000), m_spellInfo(sSpellTemplate.LookupEntry(SPELL_OSCILLATING_FREQUENCY_SCANNER)) {} + go_aura_generator_000AI(GameObject* go) : GameObjectAI(go), m_auraSearchTimer(1000), m_spellInfo(sSpellTemplate.LookupEntry(SPELL_OSCILLATING_FREQUENCY_SCANNER)) {} uint32 m_auraSearchTimer; ObjectGuid m_player; @@ -1828,7 +1828,7 @@ struct npc_fel_cannon : public Scripted_NoMovementAI uint32 m_uiCannonBlastTimer; bool m_bMCed; - + void Reset() override { m_uiCannonBlastTimer = 1000; @@ -1869,7 +1869,7 @@ struct npc_fel_cannon : public Scripted_NoMovementAI void UpdateAI(const uint32 uiDiff) override { if (m_bMCed && !m_creature->HasCharmer()) - { + { Scripted_NoMovementAI::EnterEvadeMode(); m_creature->FixateTarget(nullptr); return; @@ -1900,7 +1900,7 @@ UnitAI* GetAI_npc_fel_cannon(Creature* pCreature) ## npc_warp_gate ######*/ -static float impSpawns[2][4] = +static float impSpawns[2][4] = { { 2188.340f, 5476.629f, 155.069f, 5.259f }, // north { 1981.730f, 5315.390f, 156.600f, 0.262f} // south @@ -1936,7 +1936,7 @@ struct npc_warp_gate : public Scripted_NoMovementAI ObjectGuid m_guidSmoke; std::vector m_vImpGuids; - + void Reset() override { m_uiHitCounter = 0; @@ -1972,7 +1972,7 @@ struct npc_warp_gate : public Scripted_NoMovementAI } m_guidFelCannon = pCaster->GetObjectGuid(); } - + uint32 spellId; switch (m_uiHitCounter) @@ -2332,7 +2332,7 @@ struct npc_soulgrinderAI : public ScriptedAI for (ObjectGuid& guid : m_ogreSpirits) if (Creature* spirit = m_creature->GetMap()->GetCreature(guid)) spirit->ForcedDespawn(); - + m_creature->CastSpell(nullptr, SPELL_SCARE_SOULGRINDER_GHOST, TRIGGERED_NONE); if (Creature* gronn = m_creature->GetMap()->GetCreature(m_skullocSoulgrinder)) { diff --git a/src/game/AI/ScriptDevAI/scripts/outland/coilfang_reservoir/serpent_shrine/boss_the_lurker_below.cpp b/src/game/AI/ScriptDevAI/scripts/outland/coilfang_reservoir/serpent_shrine/boss_the_lurker_below.cpp index a5b6d9f836..fff1a98c09 100644 --- a/src/game/AI/ScriptDevAI/scripts/outland/coilfang_reservoir/serpent_shrine/boss_the_lurker_below.cpp +++ b/src/game/AI/ScriptDevAI/scripts/outland/coilfang_reservoir/serpent_shrine/boss_the_lurker_below.cpp @@ -347,7 +347,7 @@ struct SpoutTurning : public AuraScript target->SetFacingTo(newAngle); target->SetOrientation(newAngle); - data.spellInfo = sSpellTemplate.LookupEntry(SPELL_SPOUT_DAMAGE); + data.spellInfo = sSpellTemplate.LookupEntry(SPELL_SPOUT_DAMAGE); data.caster = target; data.target = nullptr; } diff --git a/src/game/AI/ScriptDevAI/scripts/outland/shadowmoon_valley.cpp b/src/game/AI/ScriptDevAI/scripts/outland/shadowmoon_valley.cpp index 6f390a358e..1ec8478a05 100644 --- a/src/game/AI/ScriptDevAI/scripts/outland/shadowmoon_valley.cpp +++ b/src/game/AI/ScriptDevAI/scripts/outland/shadowmoon_valley.cpp @@ -381,7 +381,7 @@ struct npc_dragonmaw_peonAI : public ScriptedAI // Workaround for broken function GetGameObject if (!pMutton) { - const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_SERVING_MUTTON); + const SpellEntry* pSpell = GetSpellStore()->LookupEntry(SPELL_SERVING_MUTTON); uint32 uiGameobjectEntry = pSpell->EffectMiscValue[EFFECT_INDEX_0]; diff --git a/src/game/AI/ScriptDevAI/scripts/world/item_scripts.cpp b/src/game/AI/ScriptDevAI/scripts/world/item_scripts.cpp index f6cae024dc..d0a49bf38c 100644 --- a/src/game/AI/ScriptDevAI/scripts/world/item_scripts.cpp +++ b/src/game/AI/ScriptDevAI/scripts/world/item_scripts.cpp @@ -53,7 +53,7 @@ bool ItemUse_item_orb_of_draconic_energy(Player* pPlayer, Item* pItem, const Spe { pPlayer->SendEquipError(EQUIP_ERR_NONE, pItem, nullptr); - if (const SpellEntry* pSpellInfo = GetSpellStore()->LookupEntry(SPELL_DOMINION_SOUL)) + if (const SpellEntry* pSpellInfo = GetSpellStore()->LookupEntry(SPELL_DOMINION_SOUL)) Spell::SendCastResult(pPlayer, pSpellInfo, 1, SPELL_FAILED_TARGET_AURASTATE); return true; @@ -78,7 +78,7 @@ bool ItemUse_item_arcane_charges(Player* pPlayer, Item* pItem, const SpellCastTa pPlayer->SendEquipError(EQUIP_ERR_NONE, pItem, nullptr); - if (const SpellEntry* pSpellInfo = GetSpellStore()->LookupEntry(SPELL_ARCANE_CHARGES)) + if (const SpellEntry* pSpellInfo = GetSpellStore()->LookupEntry(SPELL_ARCANE_CHARGES)) Spell::SendCastResult(pPlayer, pSpellInfo, 1, SPELL_FAILED_ERROR); return true; @@ -121,7 +121,7 @@ bool ItemUse_item_gor_dreks_ointment(Player* pPlayer, Item* pItem, const SpellCa { pPlayer->SendEquipError(EQUIP_ERR_NONE, pItem, nullptr); - if (const SpellEntry* pSpellInfo = GetSpellStore()->LookupEntry(SPELL_GORDREKS_OINTMENT)) + if (const SpellEntry* pSpellInfo = GetSpellStore()->LookupEntry(SPELL_GORDREKS_OINTMENT)) Spell::SendCastResult(pPlayer, pSpellInfo, 1, SPELL_FAILED_TARGET_AURASTATE); return true; diff --git a/src/game/AI/ScriptDevAI/scripts/world/npc_professions.cpp b/src/game/AI/ScriptDevAI/scripts/world/npc_professions.cpp index 4ccaeb6f70..d458112e6c 100644 --- a/src/game/AI/ScriptDevAI/scripts/world/npc_professions.cpp +++ b/src/game/AI/ScriptDevAI/scripts/world/npc_professions.cpp @@ -198,7 +198,7 @@ int32 GetUnlearnCostLow(Player* pPlayer) // blacksmith bool EquippedOk(Player* pPlayer, uint32 spellId) { - SpellEntry const* spell = GetSpellStore()->LookupEntry(spellId); + SpellEntry const* spell = GetSpellStore()->LookupEntry(spellId); if (!spell) return false; diff --git a/src/game/AI/ScriptDevAI/scripts/world/npcs_special.cpp b/src/game/AI/ScriptDevAI/scripts/world/npcs_special.cpp index 9f447e29a7..2580378ea7 100644 --- a/src/game/AI/ScriptDevAI/scripts/world/npcs_special.cpp +++ b/src/game/AI/ScriptDevAI/scripts/world/npcs_special.cpp @@ -1091,7 +1091,7 @@ bool GossipHello_npc_innkeeper(Player* pPlayer, Creature* pCreature) pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_ITEM_TRICK_OR_TREAT, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 2); // Should only apply to innkeeper close to start areas. - if (AreaTableEntry const* pAreaEntry = GetAreaEntryByAreaID(pCreature->GetAreaId())) + if (AreaTableEntry const* pAreaEntry = TerrainManager::GetAreaEntryByAreaID(pCreature->GetAreaId())) { if (pAreaEntry->flags & AREA_FLAG_LOWLEVEL) pPlayer->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_ITEM_WHAT_TO_DO, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF + 1); diff --git a/src/game/AuctionHouse/AuctionHouseMgr.cpp b/src/game/AuctionHouse/AuctionHouseMgr.cpp index 8a25aa4ed4..0bda7c7ae0 100644 --- a/src/game/AuctionHouse/AuctionHouseMgr.cpp +++ b/src/game/AuctionHouse/AuctionHouseMgr.cpp @@ -836,7 +836,7 @@ void WorldSession::BuildListAuctionItems(std::vector const& aucti if (proto->Class == ITEM_CLASS_RECIPE) { - if (SpellEntry const* spell = sSpellTemplate.LookupEntry(proto->Spells[0].SpellId)) + if (SpellEntry const* spell = sSpellTemplate.LookupEntry(proto->Spells[0].SpellId)) { if (_player->HasSpell(spell->EffectTriggerSpell[EFFECT_INDEX_0])) continue; diff --git a/src/game/BattleGround/BattleGround.cpp b/src/game/BattleGround/BattleGround.cpp index f7bccbdd19..3e20720063 100644 --- a/src/game/BattleGround/BattleGround.cpp +++ b/src/game/BattleGround/BattleGround.cpp @@ -673,7 +673,7 @@ void BattleGround::RewardHonorToTeam(uint32 honor, Team teamId) */ void BattleGround::RewardReputationToTeam(uint32 factionId, uint32 reputation, Team teamId) { - FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionId); + FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionId); if (!factionEntry) return; @@ -1013,7 +1013,7 @@ void BattleGround::RewardSpellCast(Player* player, uint32 spellId) const if (player->GetDummyAura(SPELL_AURA_PLAYER_INACTIVE)) return; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) { sLog.outError("Battleground reward casting spell %u not exist.", spellId); diff --git a/src/game/BattleGround/BattleGroundMgr.cpp b/src/game/BattleGround/BattleGroundMgr.cpp index 75257c47c5..cd7ad945d6 100644 --- a/src/game/BattleGround/BattleGroundMgr.cpp +++ b/src/game/BattleGround/BattleGroundMgr.cpp @@ -1816,7 +1816,7 @@ uint32 BattleGroundMgr::CreateBattleGround(BattleGroundTypeId bgTypeId, bool IsA void BattleGroundMgr::CreateInitialBattleGrounds() { uint32 count = 0; - // 0 1 2 3 4 5 6 7 + // 0 1 2 3 4 5 6 7 QueryResult* result = WorldDatabase.Query("SELECT id, MinPlayersPerTeam,MaxPlayersPerTeam,MinLvl,MaxLvl,AllianceStartLoc,HordeStartLoc,StartMaxDist FROM battleground_template"); if (!result) @@ -1870,7 +1870,7 @@ void BattleGroundMgr::CreateInitialBattleGrounds() uint32 start1 = fields[5].GetUInt32(); - WorldSafeLocsEntry const* start = sWorldSafeLocsStore.LookupEntry(start1); + WorldSafeLocsEntry const* start = sWorldSafeLocsStore.LookupEntry(start1); if (start) { allianceStartLoc[0] = start->x; @@ -1893,7 +1893,7 @@ void BattleGroundMgr::CreateInitialBattleGrounds() uint32 start2 = fields[6].GetUInt32(); - start = sWorldSafeLocsStore.LookupEntry(start2); + start = sWorldSafeLocsStore.LookupEntry(start2); if (start) { hordeStartLoc[0] = start->x; diff --git a/src/game/Chat/Channel.cpp b/src/game/Chat/Channel.cpp index 51aa31c8bd..ab2fee5ec8 100644 --- a/src/game/Chat/Channel.cpp +++ b/src/game/Chat/Channel.cpp @@ -1134,3 +1134,50 @@ bool Channel::SetStatic(bool state, bool command/* = false*/) return true; } + +ChatChannelsEntry const* Channel::GetChatChannelsEntryFor(const std::string& name, uint32 channel_id/* = 0*/) +{ + std::wstring wname; + + Utf8toWStr(name, wname); + + if (!channel_id && wname.empty()) + return nullptr; + + // not sorted, numbering index from 0 + for (auto entry : sChatChannelsStore) + { + std::wstring wpattern; + + // try to match by name first, avoid creating custom channels with same name + if (!wname.empty()) + { + for (uint32 i = 0; i < MAX_LOCALE; ++i) + { + Utf8toWStr(entry->pattern[i], wpattern); + + if (wpattern.empty()) + continue; + + size_t argpos = wpattern.find(L"%s"); + + // formatting arg present: strip and attempt partial match + if (argpos != std::wstring::npos) + { + wpattern.replace(argpos, 2, L""); + + if (wname.find(wpattern) != std::wstring::npos) + return entry; + } + // attempt full match + else if (wname.compare(wpattern) == 0) + return entry; + } + } + + // name still not found, but channel id is provided: possibly no dbc data for client locale + if (channel_id && channel_id == entry->ChannelID) + return entry; + } + return nullptr; +} diff --git a/src/game/Chat/Channel.h b/src/game/Chat/Channel.h index eb8bfbde08..c7beb75997 100644 --- a/src/game/Chat/Channel.h +++ b/src/game/Chat/Channel.h @@ -26,6 +26,8 @@ #include +struct ChatChannelsEntry; + enum ChatNotify : uint8 { CHAT_JOINED_NOTICE = 0x00, //+ "%s joined channel."; @@ -211,6 +213,8 @@ class Channel // Make a custom channel acquire global-like properties bool SetStatic(bool state, bool command = false); + static ChatChannelsEntry const* GetChatChannelsEntryFor(const std::string& name, uint32 channel_id = 0); + private: void SendToOne(WorldPacket const& data, ObjectGuid receiver) const; void SendToAll(WorldPacket const& data) const; diff --git a/src/game/Chat/Chat.cpp b/src/game/Chat/Chat.cpp index 432d807434..be1f841b4a 100644 --- a/src/game/Chat/Chat.cpp +++ b/src/game/Chat/Chat.cpp @@ -1889,7 +1889,7 @@ bool ChatHandler::CheckEscapeSequences(const char* message) if (!talentInfo) return false; - linkedSpell = sSpellTemplate.LookupEntry(talentInfo->RankID[0]); + linkedSpell = sSpellTemplate.LookupEntry(talentInfo->RankID[0]); if (!linkedSpell) return false; @@ -1916,7 +1916,7 @@ bool ChatHandler::CheckEscapeSequences(const char* message) spellid += c - '0'; c = reader.peek(); } - linkedSpell = sSpellTemplate.LookupEntry(spellid); + linkedSpell = sSpellTemplate.LookupEntry(spellid); if (!linkedSpell) return false; } @@ -1935,7 +1935,7 @@ bool ChatHandler::CheckEscapeSequences(const char* message) spellid += c - '0'; c = reader.peek(); } - linkedSpell = sSpellTemplate.LookupEntry(spellid); + linkedSpell = sSpellTemplate.LookupEntry(spellid); if (!linkedSpell) return false; } diff --git a/src/game/Chat/Level1.cpp b/src/game/Chat/Level1.cpp index 0bede07676..a5408fbc54 100644 --- a/src/game/Chat/Level1.cpp +++ b/src/game/Chat/Level1.cpp @@ -246,7 +246,7 @@ bool ChatHandler::HandleGMVisibleCommand(char* args) } Player* player = m_session->GetPlayer(); - SpellEntry const* invisibleAuraInfo = sSpellTemplate.LookupEntry(sWorld.getConfig(CONFIG_UINT32_GM_INVISIBLE_AURA)); + SpellEntry const* invisibleAuraInfo = sSpellTemplate.LookupEntry(sWorld.getConfig(CONFIG_UINT32_GM_INVISIBLE_AURA)); if (!invisibleAuraInfo || !IsSpellAppliesAura(invisibleAuraInfo)) invisibleAuraInfo = nullptr; @@ -301,13 +301,13 @@ bool ChatHandler::HandleGPSCommand(char* args) obj->GetZoneAndAreaId(zone_id, area_id); MapEntry const* mapEntry = sMapStore.LookupEntry(obj->GetMapId()); - AreaTableEntry const* zoneEntry = GetAreaEntryByAreaID(zone_id); - AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(area_id); + AreaTableEntry const* zoneEntry = TerrainManager::GetAreaEntryByAreaID(zone_id); + AreaTableEntry const* areaEntry = TerrainManager::GetAreaEntryByAreaID(area_id); float zone_x = obj->GetPositionX(); float zone_y = obj->GetPositionY(); - if (!Map2ZoneCoordinates(zone_x, zone_y, zone_id)) + if (!Map::Map2ZoneCoordinates(zone_x, zone_y, zone_id)) { zone_x = 0; zone_y = 0; @@ -612,7 +612,7 @@ bool ChatHandler::HandleGonameCommand(char* args) // to point to see at target with same orientation float x, y, z; target->GetContactPoint(target, x, y, z); - + if (GenericTransport* transport = target->GetTransport()) transport->CalculatePassengerOffset(x, y, z); _player->TeleportTo(target->GetMapId(), x, y, z, _player->GetAngle(target), TELE_TO_GM_MODE, nullptr, target->GetTransport()); @@ -1331,46 +1331,42 @@ bool ChatHandler::HandleLookupAreaCommand(char* args) wstrToLower(wnamepart); // Search in AreaTable.dbc - for (uint32 areaflag = 0; areaflag < sAreaStore.GetNumRows(); ++areaflag) + for (auto areaEntry : sAreaTableStore) { - AreaTableEntry const* areaEntry = sAreaStore.LookupEntry(areaflag); - if (areaEntry) - { - int loc = GetSessionDbcLocale(); - std::string name = areaEntry->area_name[loc]; - if (name.empty()) - continue; + int loc = GetSessionDbcLocale(); + std::string name = areaEntry->area_name[loc]; + if (name.empty()) + continue; - if (!Utf8FitTo(name, wnamepart)) + if (!Utf8FitTo(name, wnamepart)) + { + loc = 0; + for (; loc < MAX_LOCALE; ++loc) { - loc = 0; - for (; loc < MAX_LOCALE; ++loc) - { - if (loc == GetSessionDbcLocale()) - continue; + if (loc == GetSessionDbcLocale()) + continue; - name = areaEntry->area_name[loc]; - if (name.empty()) - continue; + name = areaEntry->area_name[loc]; + if (name.empty()) + continue; - if (Utf8FitTo(name, wnamepart)) - break; - } + if (Utf8FitTo(name, wnamepart)) + break; } + } - if (loc < MAX_LOCALE) - { - // send area in "id - [name]" format - std::ostringstream ss; - if (m_session) - ss << areaEntry->ID << " - |cffffffff|Harea:" << areaEntry->ID << "|h[" << name << " " << localeNames[loc] << "]|h|r"; - else - ss << areaEntry->ID << " - " << name << " " << localeNames[loc]; + if (loc < MAX_LOCALE) + { + // send area in "id - [name]" format + std::ostringstream ss; + if (m_session) + ss << areaEntry->ID << " - |cffffffff|Harea:" << areaEntry->ID << "|h[" << name << " " << localeNames[loc] << "]|h|r"; + else + ss << areaEntry->ID << " - " << name << " " << localeNames[loc]; - SendSysMessage(ss.str().c_str()); + SendSysMessage(ss.str().c_str()); - ++counter; - } + ++counter; } } @@ -1880,7 +1876,7 @@ bool ChatHandler::HandleGoZoneXYCommand(char* args) else areaid = _player->GetZoneId(); - AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(areaid); + AreaTableEntry const* areaEntry = TerrainManager::GetAreaEntryByAreaID(areaid); if (x < 0 || x > 100 || y < 0 || y > 100 || !areaEntry) { @@ -1890,7 +1886,7 @@ bool ChatHandler::HandleGoZoneXYCommand(char* args) } // update to parent zone if exist (client map show only zones without parents) - AreaTableEntry const* zoneEntry = areaEntry->zone ? GetAreaEntryByAreaID(areaEntry->zone) : areaEntry; + AreaTableEntry const* zoneEntry = areaEntry->zone ? TerrainManager::GetAreaEntryByAreaID(areaEntry->zone) : areaEntry; MapEntry const* mapEntry = sMapStore.LookupEntry(zoneEntry->mapid); @@ -1902,7 +1898,7 @@ bool ChatHandler::HandleGoZoneXYCommand(char* args) return false; } - if (!Zone2MapCoordinates(x, y, zoneEntry->ID)) + if (!Map::Zone2MapCoordinates(x, y, zoneEntry->ID)) { PSendSysMessage(LANG_INVALID_ZONE_MAP, areaEntry->ID, areaEntry->area_name[GetSessionDbcLocale()], mapEntry->MapID, mapEntry->name[GetSessionDbcLocale()]); diff --git a/src/game/Chat/Level2.cpp b/src/game/Chat/Level2.cpp index a10532ef40..1ebda003d6 100644 --- a/src/game/Chat/Level2.cpp +++ b/src/game/Chat/Level2.cpp @@ -242,12 +242,8 @@ bool ChatHandler::HandleTriggerCommand(char* args) float dist2 = MAP_SIZE * MAP_SIZE; // Search triggers - for (uint32 id = 0; id < sAreaTriggerStore.GetNumRows(); ++id) + for (auto atTestEntry : sAreaTriggerStore) { - AreaTriggerEntry const* atTestEntry = sAreaTriggerStore.LookupEntry(id); - if (!atTestEntry) - continue; - if (atTestEntry->mapid != m_session->GetPlayer()->GetMapId()) continue; @@ -324,13 +320,9 @@ bool ChatHandler::HandleTriggerActiveCommand(char* /*args*/) Player* pl = m_session->GetPlayer(); // Search in AreaTable.dbc - for (uint32 id = 0; id < sAreaTriggerStore.GetNumRows(); ++id) + for (auto atEntry : sAreaTriggerStore) { - AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(id); - if (!atEntry) - continue; - - if (!IsPointInAreaTriggerZone(atEntry, pl->GetMapId(), pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ())) + if (!Map::IsPointInAreaTriggerZone(atEntry, pl->GetMapId(), pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ())) continue; ShowTriggerListHelper(atEntry); @@ -353,12 +345,8 @@ bool ChatHandler::HandleTriggerNearCommand(char* args) Player* pl = m_session->GetPlayer(); // Search triggers - for (uint32 id = 0; id < sAreaTriggerStore.GetNumRows(); ++id) + for (auto atEntry : sAreaTriggerStore) { - AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(id); - if (!atEntry) - continue; - if (atEntry->mapid != m_session->GetPlayer()->GetMapId()) continue; @@ -374,12 +362,8 @@ bool ChatHandler::HandleTriggerNearCommand(char* args) } // Search trigger targets - for (uint32 id = 0; id < sAreaTriggerStore.GetNumRows(); ++id) + for (auto atEntry : sAreaTriggerStore) { - AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(id); - if (!atEntry) - continue; - AreaTrigger const* at = sObjectMgr.GetAreaTrigger(atEntry->id); if (!at) continue; @@ -464,7 +448,7 @@ bool ChatHandler::HandleGoGraveyardCommand(char* args) if (!ExtractUInt32(&args, gyId)) return false; - WorldSafeLocsEntry const* gy = sWorldSafeLocsStore.LookupEntry(gyId); + WorldSafeLocsEntry const* gy = sWorldSafeLocsStore.LookupEntry(gyId); if (!gy) { PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, gyId); @@ -1440,39 +1424,35 @@ bool ChatHandler::HandleLookupFactionCommand(char* args) uint32 counter = 0; // Counter for figure out that we found smth. - for (uint32 id = 0; id < sFactionStore.GetMaxEntry(); ++id) + for (auto factionEntry : sFactionStore) { - FactionEntry const* factionEntry = sFactionStore.LookupEntry(id); - if (factionEntry) - { - int loc = GetSessionDbcLocale(); - std::string name = factionEntry->name[loc]; - if (name.empty()) - continue; + int loc = GetSessionDbcLocale(); + std::string name = factionEntry->name[loc]; + if (name.empty()) + continue; - if (!Utf8FitTo(name, wnamepart)) + if (!Utf8FitTo(name, wnamepart)) + { + loc = 0; + for (; loc < MAX_LOCALE; ++loc) { - loc = 0; - for (; loc < MAX_LOCALE; ++loc) - { - if (loc == GetSessionDbcLocale()) - continue; + if (loc == GetSessionDbcLocale()) + continue; - name = factionEntry->name[loc]; - if (name.empty()) - continue; + name = factionEntry->name[loc]; + if (name.empty()) + continue; - if (Utf8FitTo(name, wnamepart)) - break; - } + if (Utf8FitTo(name, wnamepart)) + break; } + } - if (loc < MAX_LOCALE) - { - FactionState const* repState = target ? target->GetReputationMgr().GetState(factionEntry) : nullptr; - ShowFactionListHelper(factionEntry, LocaleConstant(loc), repState, target); - ++counter; - } + if (loc < MAX_LOCALE) + { + FactionState const* repState = target ? target->GetReputationMgr().GetState(factionEntry) : nullptr; + ShowFactionListHelper(factionEntry, LocaleConstant(loc), repState, target); + ++counter; } } @@ -1555,7 +1535,7 @@ bool ChatHandler::HandleModifyRepCommand(char* args) } } - FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionId); + FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionId); if (!factionEntry) { @@ -3438,7 +3418,7 @@ bool ChatHandler::HandleCharacterReputationCommand(char* args) FactionStateList const& targetFSL = target->GetReputationMgr().GetStateList(); for (const auto& itr : targetFSL) { - FactionEntry const* factionEntry = sFactionStore.LookupEntry(itr.second.ID); + FactionEntry const* factionEntry = sFactionStore.LookupEntry(itr.second.ID); ShowFactionListHelper(factionEntry, loc, &itr.second, target); } @@ -3760,12 +3740,8 @@ void ChatHandler::HandleLearnSkillRecipesHelper(Player* player, uint32 skill_id) { uint32 classmask = player->getClassMask(); - for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j) + for (auto skillLine : sSkillLineAbilityStore) { - SkillLineAbilityEntry const* skillLine = sSkillLineAbilityStore.LookupEntry(j); - if (!skillLine) - continue; - // wrong skill if (skillLine->skillId != skill_id) continue; @@ -3782,7 +3758,7 @@ void ChatHandler::HandleLearnSkillRecipesHelper(Player* player, uint32 skill_id) if (skillLine->classmask && (skillLine->classmask & classmask) == 0) continue; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(skillLine->spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(skillLine->spellId); if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo, player, false)) continue; @@ -3792,12 +3768,8 @@ void ChatHandler::HandleLearnSkillRecipesHelper(Player* player, uint32 skill_id) bool ChatHandler::HandleLearnAllCraftsCommand(char* /*args*/) { - for (uint32 i = 0; i < sSkillLineStore.GetNumRows(); ++i) + for (auto skillInfo : sSkillLineStore) { - SkillLineEntry const* skillInfo = sSkillLineStore.LookupEntry(i); - if (!skillInfo) - continue; - if (skillInfo->categoryId == SKILL_CATEGORY_PROFESSION || skillInfo->categoryId == SKILL_CATEGORY_SECONDARY) { HandleLearnSkillRecipesHelper(m_session->GetPlayer(), skillInfo->id); @@ -3834,12 +3806,8 @@ bool ChatHandler::HandleLearnAllRecipesCommand(char* args) std::string name; SkillLineEntry const* targetSkillInfo = nullptr; - for (uint32 i = 1; i < sSkillLineStore.GetNumRows(); ++i) + for (auto skillInfo : sSkillLineStore) { - SkillLineEntry const* skillInfo = sSkillLineStore.LookupEntry(i); - if (!skillInfo) - continue; - if (skillInfo->categoryId != SKILL_CATEGORY_PROFESSION && skillInfo->categoryId != SKILL_CATEGORY_SECONDARY) continue; @@ -4473,52 +4441,48 @@ bool ChatHandler::HandleLookupTitleCommand(char* args) uint32 counter = 0; // Counter for figure out that we found smth. // Search in CharTitles.dbc - for (uint32 id = 0; id < sCharTitlesStore.GetNumRows(); ++id) + for (auto titleInfo : sCharTitlesStore) { - CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id); - if (titleInfo) - { - int loc = GetSessionDbcLocale(); - std::string name = titleInfo->name[loc]; - if (name.empty()) - continue; + int loc = GetSessionDbcLocale(); + std::string name = titleInfo->name[loc]; + if (name.empty()) + continue; - if (!Utf8FitTo(name, wnamepart)) + if (!Utf8FitTo(name, wnamepart)) + { + loc = 0; + for (; loc < MAX_LOCALE; ++loc) { - loc = 0; - for (; loc < MAX_LOCALE; ++loc) - { - if (loc == GetSessionDbcLocale()) - continue; + if (loc == GetSessionDbcLocale()) + continue; - name = titleInfo->name[loc]; - if (name.empty()) - continue; + name = titleInfo->name[loc]; + if (name.empty()) + continue; - if (Utf8FitTo(name, wnamepart)) - break; - } + if (Utf8FitTo(name, wnamepart)) + break; } + } - if (loc < MAX_LOCALE) - { - char const* knownStr = target && target->HasTitle(titleInfo) ? GetMangosString(LANG_KNOWN) : ""; + if (loc < MAX_LOCALE) + { + char const* knownStr = target && target->HasTitle(titleInfo) ? GetMangosString(LANG_KNOWN) : ""; - char const* activeStr = target && target->GetUInt32Value(PLAYER_CHOSEN_TITLE) == titleInfo->bit_index - ? GetMangosString(LANG_ACTIVE) - : ""; + char const* activeStr = target && target->GetUInt32Value(PLAYER_CHOSEN_TITLE) == titleInfo->bit_index + ? GetMangosString(LANG_ACTIVE) + : ""; - char titleNameStr[80]; - snprintf(titleNameStr, 80, name.c_str(), targetName); + char titleNameStr[80]; + snprintf(titleNameStr, 80, name.c_str(), targetName); - // send title in "id (idx:idx) - [namedlink locale]" format - if (m_session) - PSendSysMessage(LANG_TITLE_LIST_CHAT, id, titleInfo->bit_index, id, titleNameStr, localeNames[loc], knownStr, activeStr); - else - PSendSysMessage(LANG_TITLE_LIST_CONSOLE, id, titleInfo->bit_index, titleNameStr, localeNames[loc], knownStr, activeStr); + // send title in "id (idx:idx) - [namedlink locale]" format + if (m_session) + PSendSysMessage(LANG_TITLE_LIST_CHAT, titleInfo->ID, titleInfo->bit_index, titleInfo->ID, titleNameStr, localeNames[loc], knownStr, activeStr); + else + PSendSysMessage(LANG_TITLE_LIST_CONSOLE, titleInfo->ID, titleInfo->bit_index, titleNameStr, localeNames[loc], knownStr, activeStr); - ++counter; - } + ++counter; } } if (counter == 0) // if counter == 0 then we found nth @@ -4649,9 +4613,8 @@ bool ChatHandler::HandleTitlesSetMaskCommand(char* args) uint64 titles2 = titles; - for (uint32 i = 1; i < sCharTitlesStore.GetNumRows(); ++i) - if (CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i)) - titles2 &= ~(uint64(1) << tEntry->bit_index); + for (auto tEntry : sCharTitlesStore) + titles2 &= ~(uint64(1) << tEntry->bit_index); titles &= ~titles2; // remove nonexistent titles @@ -4709,10 +4672,9 @@ bool ChatHandler::HandleCharacterTitlesCommand(char* args) char const* knownStr = GetMangosString(LANG_KNOWN); // Search in CharTitles.dbc - for (uint32 id = 0; id < sCharTitlesStore.GetNumRows(); ++id) + for (auto titleInfo : sCharTitlesStore) { - CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(id); - if (titleInfo && target->HasTitle(titleInfo)) + if (target->HasTitle(titleInfo)) { std::string name = titleInfo->name[loc]; if (name.empty()) @@ -4727,9 +4689,9 @@ bool ChatHandler::HandleCharacterTitlesCommand(char* args) // send title in "id (idx:idx) - [namedlink locale]" format if (m_session) - PSendSysMessage(LANG_TITLE_LIST_CHAT, id, titleInfo->bit_index, id, titleNameStr, localeNames[loc], knownStr, activeStr); + PSendSysMessage(LANG_TITLE_LIST_CHAT, titleInfo->ID, titleInfo->bit_index, titleInfo->ID, titleNameStr, localeNames[loc], knownStr, activeStr); else - PSendSysMessage(LANG_TITLE_LIST_CONSOLE, id, titleInfo->bit_index, name.c_str(), localeNames[loc], knownStr, activeStr); + PSendSysMessage(LANG_TITLE_LIST_CONSOLE, titleInfo->ID, titleInfo->bit_index, name.c_str(), localeNames[loc], knownStr, activeStr); } } return true; diff --git a/src/game/Chat/Level3.cpp b/src/game/Chat/Level3.cpp index 03d2046526..3b9504305a 100644 --- a/src/game/Chat/Level3.cpp +++ b/src/game/Chat/Level3.cpp @@ -57,6 +57,7 @@ #include "Loot/LootMgr.h" #include "World/WorldState.h" #include "Arena/ArenaTeam.h" +#include "Database/SQLStorage.h" #ifdef BUILD_AHBOT #include "AuctionHouseBot/AuctionHouseBot.h" @@ -1351,7 +1352,7 @@ bool ChatHandler::HandleCooldownClearCommand(char* args) if (!spell_id) return false; - SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(spell_id); + SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(spell_id); if (!spellEntry) { PSendSysMessage(LANG_UNKNOWN_SPELL, target == m_session->GetPlayer() ? GetMangosString(LANG_YOU) : tNameLink.c_str()); @@ -1409,19 +1410,15 @@ bool ChatHandler::HandleLearnAllCommand(char* /*args*/) return false; } - for (uint32 i = 0; i < sSpellTemplate.GetMaxEntry(); i++) + for (auto spellInfo : sSpellTemplate) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(i); - if (!spellInfo) - continue; - for (uint32 j = 0; j < MAX_EFFECT_INDEX; j++) { if ((spellInfo->Effect[j] == SPELL_EFFECT_LEARN_SPELL) && (spellInfo->EffectImplicitTargetA[j] == TARGET_NONE)) { uint32 spellId = spellInfo->EffectTriggerSpell[j]; - SpellEntry const* newSpell = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* newSpell = sSpellTemplate.LookupEntry(spellId); // skip broken spells if (!SpellMgr::IsSpellValid(newSpell, player, false)) @@ -1429,9 +1426,9 @@ bool ChatHandler::HandleLearnAllCommand(char* /*args*/) // skip spells with first rank learned as talent (and all talents then also) uint32 firstRankId = sSpellMgr.GetFirstSpellInChain(spellId); - if (GetTalentSpellCost(firstRankId) > 0) + if (ObjectMgr::GetTalentSpellCost(firstRankId) > 0) continue; - + if (!IsSpellHaveEffect(newSpell, SPELL_EFFECT_PROFICIENCY)) { // only class spells @@ -1498,7 +1495,7 @@ bool ChatHandler::HandleLearnAllGMCommand(char* /*args*/) for (uint32 spell : gmSpellList) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell); if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo, m_session->GetPlayer())) { PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spell); @@ -1527,13 +1524,9 @@ bool ChatHandler::HandleLearnAllMySpellsCommand(char* /*args*/) return true; uint32 family = clsEntry->spellfamily; - for (uint32 i = 0; i < sSkillLineAbilityStore.GetNumRows(); ++i) + for (auto entry : sSkillLineAbilityStore) { - SkillLineAbilityEntry const* entry = sSkillLineAbilityStore.LookupEntry(i); - if (!entry) - continue; - - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(entry->spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(entry->spellId); if (!spellInfo) continue; @@ -1551,7 +1544,7 @@ bool ChatHandler::HandleLearnAllMySpellsCommand(char* /*args*/) // skip spells with first rank learned as talent (and all talents then also) uint32 first_rank = sSpellMgr.GetFirstSpellInChain(spellInfo->Id); - if (GetTalentSpellCost(first_rank) > 0) + if (ObjectMgr::GetTalentSpellCost(first_rank) > 0) continue; // skip broken spells @@ -1570,12 +1563,8 @@ bool ChatHandler::HandleLearnAllMyTalentsCommand(char* /*args*/) Player* player = m_session->GetPlayer(); uint32 classMask = player->getClassMask(); - for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i) + for (auto talentInfo : sTalentStore) { - TalentEntry const* talentInfo = sTalentStore.LookupEntry(i); - if (!talentInfo) - continue; - TalentTabEntry const* talentTabInfo = sTalentTabStore.LookupEntry(talentInfo->TalentTab); if (!talentTabInfo) continue; @@ -1598,7 +1587,7 @@ bool ChatHandler::HandleLearnAllMyTalentsCommand(char* /*args*/) if (!spellid) // ??? none spells in talent continue; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellid); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellid); if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo, player, false)) continue; @@ -1650,14 +1639,14 @@ bool ChatHandler::HandleLearnCommand(char* args) // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form uint32 spell = ExtractSpellIdFromLink(&args); - if (!spell || !sSpellTemplate.LookupEntry(spell)) + if (!spell || !sSpellTemplate.LookupEntry(spell)) return false; bool allRanks = ExtractLiteralArg(&args, "all") != nullptr; if (!allRanks && *args) // can be fail also at syntax error return false; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell); if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo, player)) { PSendSysMessage(LANG_COMMAND_SPELL_BROKEN, spell); @@ -1791,12 +1780,8 @@ bool ChatHandler::HandleAddItemSetCommand(char* args) DETAIL_LOG(GetMangosString(LANG_ADDITEMSET), itemsetId); bool found = false; - for (uint32 id = 0; id < sItemStorage.GetMaxEntry(); ++id) + for (auto pProto : sItemStorage) { - ItemPrototype const* pProto = sItemStorage.LookupEntry(id); - if (!pProto) - continue; - if (pProto->ItemSet == itemsetId) { found = true; @@ -2194,7 +2179,7 @@ bool ChatHandler::HandleListCreatureCommand(char* args) void ChatHandler::ShowItemListHelper(uint32 itemId, int loc_idx, Player* target /*=nullptr*/) { - ItemPrototype const* itemProto = sItemStorage.LookupEntry(itemId); + ItemPrototype const* itemProto = sItemStorage.LookupEntry(itemId); if (!itemProto) return; @@ -2234,20 +2219,16 @@ bool ChatHandler::HandleLookupItemCommand(char* args) uint32 counter = 0; // Search in `item_template` - for (uint32 id = 0; id < sItemStorage.GetMaxEntry(); ++id) + for (auto pProto : sItemStorage) { - ItemPrototype const* pProto = sItemStorage.LookupEntry(id); - if (!pProto) - continue; - int loc_idx = GetSessionDbLocaleIndex(); std::string name; // "" for let later only single time check default locale name directly - sObjectMgr.GetItemLocaleStrings(id, loc_idx, &name); + sObjectMgr.GetItemLocaleStrings(pProto->ItemId, loc_idx, &name); if ((name.empty() || !Utf8FitTo(name, wnamepart)) && !Utf8FitTo(pProto->Name1, wnamepart)) continue; - ShowItemListHelper(id, loc_idx, pl); + ShowItemListHelper(pProto->ItemId, loc_idx, pl); ++counter; } @@ -2274,42 +2255,38 @@ bool ChatHandler::HandleLookupItemSetCommand(char* args) uint32 counter = 0; // Counter for figure out that we found smth. // Search in ItemSet.dbc - for (uint32 id = 0; id < sItemSetStore.GetNumRows(); ++id) + for (auto set : sItemSetStore) { - ItemSetEntry const* set = sItemSetStore.LookupEntry(id); - if (set) - { - int loc = GetSessionDbcLocale(); - std::string name = set->name[loc]; - if (name.empty()) - continue; + int loc = GetSessionDbcLocale(); + std::string name = set->name[loc]; + if (name.empty()) + continue; - if (!Utf8FitTo(name, wnamepart)) + if (!Utf8FitTo(name, wnamepart)) + { + loc = 0; + for (; loc < MAX_LOCALE; ++loc) { - loc = 0; - for (; loc < MAX_LOCALE; ++loc) - { - if (loc == GetSessionDbcLocale()) - continue; + if (loc == GetSessionDbcLocale()) + continue; - name = set->name[loc]; - if (name.empty()) - continue; + name = set->name[loc]; + if (name.empty()) + continue; - if (Utf8FitTo(name, wnamepart)) - break; - } + if (Utf8FitTo(name, wnamepart)) + break; } + } - if (loc < MAX_LOCALE) - { - // send item set in "id - [namedlink locale]" format - if (m_session) - PSendSysMessage(LANG_ITEMSET_LIST_CHAT, id, id, name.c_str(), localeNames[loc]); - else - PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE, id, name.c_str(), localeNames[loc]); - ++counter; - } + if (loc < MAX_LOCALE) + { + // send item set in "id - [namedlink locale]" format + if (m_session) + PSendSysMessage(LANG_ITEMSET_LIST_CHAT, set->id, set->id, name.c_str(), localeNames[loc]); + else + PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE, set->id, name.c_str(), localeNames[loc]); + ++counter; } } if (counter == 0) // if counter == 0 then we found nth @@ -2337,57 +2314,53 @@ bool ChatHandler::HandleLookupSkillCommand(char* args) uint32 counter = 0; // Counter for figure out that we found smth. // Search in SkillLine.dbc - for (uint32 id = 0; id < sSkillLineStore.GetNumRows(); ++id) + for (auto skillInfo : sSkillLineStore) { - SkillLineEntry const* skillInfo = sSkillLineStore.LookupEntry(id); - if (skillInfo) - { - int loc = GetSessionDbcLocale(); - std::string name = skillInfo->name[loc]; - if (name.empty()) - continue; + int loc = GetSessionDbcLocale(); + std::string name = skillInfo->name[loc]; + if (name.empty()) + continue; - if (!Utf8FitTo(name, wnamepart)) + if (!Utf8FitTo(name, wnamepart)) + { + loc = 0; + for (; loc < MAX_LOCALE; ++loc) { - loc = 0; - for (; loc < MAX_LOCALE; ++loc) - { - if (loc == GetSessionDbcLocale()) - continue; + if (loc == GetSessionDbcLocale()) + continue; - name = skillInfo->name[loc]; - if (name.empty()) - continue; + name = skillInfo->name[loc]; + if (name.empty()) + continue; - if (Utf8FitTo(name, wnamepart)) - break; - } + if (Utf8FitTo(name, wnamepart)) + break; } + } - if (loc < MAX_LOCALE) + if (loc < MAX_LOCALE) + { + char valStr[50] = ""; + char const* knownStr = ""; + if (target && target->HasSkill(skillInfo->id)) { - char valStr[50] = ""; - char const* knownStr = ""; - if (target && target->HasSkill(id)) - { - knownStr = GetMangosString(LANG_KNOWN); - uint32 curValue = target->GetSkillValuePure(id); - uint32 maxValue = target->GetSkillMaxPure(id); - uint32 permValue = target->GetSkillBonusPermanent(id); - uint32 tempValue = target->GetSkillBonusTemporary(id); - - char const* valFormat = GetMangosString(LANG_SKILL_VALUES); - snprintf(valStr, 50, valFormat, curValue, maxValue, permValue, tempValue); - } + knownStr = GetMangosString(LANG_KNOWN); + uint32 curValue = target->GetSkillValuePure(skillInfo->id); + uint32 maxValue = target->GetSkillMaxPure(skillInfo->id); + uint32 permValue = target->GetSkillBonusPermanent(skillInfo->id); + uint32 tempValue = target->GetSkillBonusTemporary(skillInfo->id); + + char const* valFormat = GetMangosString(LANG_SKILL_VALUES); + snprintf(valStr, 50, valFormat, curValue, maxValue, permValue, tempValue); + } - // send skill in "id - [namedlink locale]" format - if (m_session) - PSendSysMessage(LANG_SKILL_LIST_CHAT, id, id, name.c_str(), localeNames[loc], knownStr, valStr); - else - PSendSysMessage(LANG_SKILL_LIST_CONSOLE, id, name.c_str(), localeNames[loc], knownStr, valStr); + // send skill in "id - [namedlink locale]" format + if (m_session) + PSendSysMessage(LANG_SKILL_LIST_CHAT, skillInfo->id, skillInfo->id, name.c_str(), localeNames[loc], knownStr, valStr); + else + PSendSysMessage(LANG_SKILL_LIST_CONSOLE, skillInfo->id, name.c_str(), localeNames[loc], knownStr, valStr); - ++counter; - } + ++counter; } } if (counter == 0) // if counter == 0 then we found nth @@ -2402,7 +2375,7 @@ void ChatHandler::ShowSpellListHelper(Player* target, SpellEntry const* spellInf bool known = target && target->HasSpell(id); bool learn = (spellInfo->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_LEARN_SPELL); - uint32 talentCost = GetTalentSpellCost(id); + uint32 talentCost = ObjectMgr::GetTalentSpellCost(id); bool talent = (talentCost > 0); bool passive = IsPassiveSpell(spellInfo); @@ -2462,38 +2435,34 @@ bool ChatHandler::HandleLookupSpellCommand(char* args) uint32 counter = 0; // Counter for figure out that we found smth. // Search in Spell.dbc - for (uint32 id = 0; id < sSpellTemplate.GetMaxEntry(); ++id) + for (auto spellInfo : sSpellTemplate) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(id); - if (spellInfo) - { - int loc = int(DEFAULT_LOCALE); - std::string name = spellInfo->SpellName[loc]; - if (name.empty()) - continue; + int loc = int(DEFAULT_LOCALE); + std::string name = spellInfo->SpellName[loc]; + if (name.empty()) + continue; - if (!Utf8FitTo(name, wnamepart)) + if (!Utf8FitTo(name, wnamepart)) + { + loc = 0; + for (; loc < MAX_LOCALE; ++loc) { - loc = 0; - for (; loc < MAX_LOCALE; ++loc) - { - if (loc == GetSessionDbcLocale()) - continue; + if (loc == GetSessionDbcLocale()) + continue; - name = spellInfo->SpellName[loc]; - if (name.empty()) - continue; + name = spellInfo->SpellName[loc]; + if (name.empty()) + continue; - if (Utf8FitTo(name, wnamepart)) - break; - } + if (Utf8FitTo(name, wnamepart)) + break; } + } - if (loc < MAX_LOCALE) - { - ShowSpellListHelper(target, spellInfo, LocaleConstant(loc)); - ++counter; - } + if (loc < MAX_LOCALE) + { + ShowSpellListHelper(target, spellInfo, LocaleConstant(loc)); + ++counter; } } if (counter == 0) // if counter == 0 then we found nth @@ -2592,16 +2561,12 @@ bool ChatHandler::HandleLookupCreatureCommand(char* args) uint32 counter = 0; - for (uint32 id = 0; id < sCreatureStorage.GetMaxEntry(); ++id) + for (auto cInfo : sCreatureStorage) { - CreatureInfo const* cInfo = sCreatureStorage.LookupEntry (id); - if (!cInfo) - continue; - int loc_idx = GetSessionDbLocaleIndex(); char const* name = ""; // "" for avoid repeating check for default locale - sObjectMgr.GetCreatureLocaleStrings(id, loc_idx, &name); + sObjectMgr.GetCreatureLocaleStrings(cInfo->Entry, loc_idx, &name); if (!*name || !Utf8FitTo(name, wnamepart)) { name = cInfo->Name; @@ -2610,9 +2575,9 @@ bool ChatHandler::HandleLookupCreatureCommand(char* args) } if (m_session) - PSendSysMessage(LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name); + PSendSysMessage(LANG_CREATURE_ENTRY_LIST_CHAT, cInfo->Entry, cInfo->Entry, name); else - PSendSysMessage(LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name); + PSendSysMessage(LANG_CREATURE_ENTRY_LIST_CONSOLE, cInfo->Entry, name); ++counter; } @@ -2639,7 +2604,7 @@ bool ChatHandler::HandleLookupObjectCommand(char* args) uint32 counter = 0; - for (SQLStorageBase::SQLSIterator itr = sGOStorage.getDataBegin(); itr < sGOStorage.getDataEnd(); ++itr) + for (auto itr : sGOStorage) { int loc_idx = GetSessionDbLocaleIndex(); if (loc_idx >= 0) @@ -2701,44 +2666,40 @@ bool ChatHandler::HandleLookupTaxiNodeCommand(char* args) uint32 counter = 0; // Counter for figure out that we found smth. // Search in TaxiNodes.dbc - for (uint32 id = 0; id < sTaxiNodesStore.GetNumRows(); ++id) + for (auto nodeEntry : sTaxiNodesStore) { - TaxiNodesEntry const* nodeEntry = sTaxiNodesStore.LookupEntry(id); - if (nodeEntry) - { - int loc = GetSessionDbcLocale(); - std::string name = nodeEntry->name[loc]; - if (name.empty()) - continue; + int loc = GetSessionDbcLocale(); + std::string name = nodeEntry->name[loc]; + if (name.empty()) + continue; - if (!Utf8FitTo(name, wnamepart)) + if (!Utf8FitTo(name, wnamepart)) + { + loc = 0; + for (; loc < MAX_LOCALE; ++loc) { - loc = 0; - for (; loc < MAX_LOCALE; ++loc) - { - if (loc == GetSessionDbcLocale()) - continue; + if (loc == GetSessionDbcLocale()) + continue; - name = nodeEntry->name[loc]; - if (name.empty()) - continue; + name = nodeEntry->name[loc]; + if (name.empty()) + continue; - if (Utf8FitTo(name, wnamepart)) - break; - } + if (Utf8FitTo(name, wnamepart)) + break; } + } - if (loc < MAX_LOCALE) - { - // send taxinode in "id - [name] (Map:m X:x Y:y Z:z)" format - if (m_session) - PSendSysMessage(LANG_TAXINODE_ENTRY_LIST_CHAT, id, id, name.c_str(), localeNames[loc], - nodeEntry->map_id, nodeEntry->x, nodeEntry->y, nodeEntry->z); - else - PSendSysMessage(LANG_TAXINODE_ENTRY_LIST_CONSOLE, id, name.c_str(), localeNames[loc], - nodeEntry->map_id, nodeEntry->x, nodeEntry->y, nodeEntry->z); - ++counter; - } + if (loc < MAX_LOCALE) + { + // send taxinode in "id - [name] (Map:m X:x Y:y Z:z)" format + if (m_session) + PSendSysMessage(LANG_TAXINODE_ENTRY_LIST_CHAT, nodeEntry->ID, nodeEntry->ID, name.c_str(), localeNames[loc], + nodeEntry->map_id, nodeEntry->x, nodeEntry->y, nodeEntry->z); + else + PSendSysMessage(LANG_TAXINODE_ENTRY_LIST_CONSOLE, nodeEntry->ID, name.c_str(), localeNames[loc], + nodeEntry->map_id, nodeEntry->x, nodeEntry->y, nodeEntry->z); + ++counter; } } if (counter == 0) // if counter == 0 then we found nth @@ -3088,7 +3049,7 @@ bool ChatHandler::HandleDamageCommand(char* args) // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form uint32 spellid = ExtractSpellIdFromLink(&args); - if (!spellid || !sSpellTemplate.LookupEntry(spellid)) + if (!spellid || !sSpellTemplate.LookupEntry(spellid)) return false; player->SpellNonMeleeDamageLog(target, spellid, damage); @@ -3149,7 +3110,7 @@ bool ChatHandler::HandleAuraCommand(char* args) // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form uint32 spellID = ExtractSpellIdFromLink(&args); - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellID); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellID); if (!spellInfo) return false; @@ -3229,7 +3190,7 @@ bool ChatHandler::HandleLinkGraveCommand(char* args) else return false; - WorldSafeLocsEntry const* graveyard = sWorldSafeLocsStore.LookupEntry(g_id); + WorldSafeLocsEntry const* graveyard = sWorldSafeLocsStore.LookupEntry(g_id); if (!graveyard) { PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, g_id); @@ -3241,7 +3202,7 @@ bool ChatHandler::HandleLinkGraveCommand(char* args) uint32 zoneId = player->GetZoneId(); - AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(zoneId); + AreaTableEntry const* areaEntry = TerrainManager::GetAreaEntryByAreaID(zoneId); if (!areaEntry || areaEntry->zone != 0) { PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE, g_id, zoneId); @@ -3750,7 +3711,7 @@ bool ChatHandler::HandleShowAreaCommand(char* args) return false; } - int area = GetAreaFlagByAreaID(atoi(args)); + int area = TerrainManager::GetAreaFlagByAreaID(atoi(args)); int offset = area / 32; uint32 val = (uint32)(1 << (area % 32)); @@ -3781,7 +3742,7 @@ bool ChatHandler::HandleHideAreaCommand(char* args) return false; } - int area = GetAreaFlagByAreaID(atoi(args)); + int area = TerrainManager::GetAreaFlagByAreaID(atoi(args)); int offset = area / 32; uint32 val = (uint32)(1 << (area % 32)); @@ -4057,7 +4018,7 @@ bool ChatHandler::HandleListAurasCommand(char* args) PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, uAuras.size()); for (Unit::SpellAuraHolderMap::const_iterator itr = uAuras.begin(); itr != uAuras.end(); ++itr) { - bool talent = GetTalentSpellCost(itr->second->GetId()) > 0; + bool talent = ObjectMgr::GetTalentSpellCost(itr->second->GetId()) > 0; SpellAuraHolder* holder = itr->second; char const* name = holder->GetSpellProto()->SpellName[GetSessionDbcLocale()]; @@ -4099,7 +4060,7 @@ bool ChatHandler::HandleListAurasCommand(char* args) PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, uAuraList.size(), i); for (Unit::AuraList::const_iterator itr = uAuraList.begin(); itr != uAuraList.end(); ++itr) { - bool talent = GetTalentSpellCost((*itr)->GetId()) > 0; + bool talent = ObjectMgr::GetTalentSpellCost((*itr)->GetId()) > 0; char const* name = (*itr)->GetSpellProto()->SpellName[GetSessionDbcLocale()]; @@ -4142,12 +4103,12 @@ bool ChatHandler::HandleListTalentsCommand(char* /*args*/) if (uSpell.second.state == PLAYERSPELL_REMOVED || uSpell.second.disabled) continue; - uint32 cost_itr = GetTalentSpellCost(uSpell.first); + uint32 cost_itr = ObjectMgr::GetTalentSpellCost(uSpell.first); if (cost_itr == 0) continue; - SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(uSpell.first); + SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(uSpell.first); if (!spellEntry) continue; @@ -4489,12 +4450,8 @@ bool ChatHandler::HandleQuestAddCommand(char* args) } // check item starting quest (it can work incorrectly if added without item in inventory) - for (uint32 id = 0; id < sItemStorage.GetMaxEntry(); ++id) + for (auto pProto : sItemStorage) { - ItemPrototype const* pProto = sItemStorage.LookupEntry(id); - if (!pProto) - continue; - if (pProto->StartQuest == entry) { PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, pProto->ItemId); @@ -4638,7 +4595,7 @@ bool ChatHandler::HandleQuestCompleteCommand(char* args) uint32 repValue = pQuest->GetRepObjectiveValue(); uint32 curRep = player->GetReputationMgr().GetReputation(repFaction); if (curRep < repValue) - if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(repFaction)) + if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(repFaction)) player->GetReputationMgr().SetReputation(factionEntry, repValue); } @@ -5556,7 +5513,7 @@ bool ChatHandler::HandleCastCommand(char* args) if (!spell) return false; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell); if (!spellInfo) return false; @@ -5595,7 +5552,7 @@ bool ChatHandler::HandleCastBackCommand(char* args) // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form uint32 spell = ExtractSpellIdFromLink(&args); - if (!spell || !sSpellTemplate.LookupEntry(spell)) + if (!spell || !sSpellTemplate.LookupEntry(spell)) return false; bool triggered = ExtractLiteralArg(&args, "triggered") != nullptr; @@ -5621,7 +5578,7 @@ bool ChatHandler::HandleCastDistCommand(char* args) if (!spell) return false; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell); if (!spellInfo) return false; @@ -5669,7 +5626,7 @@ bool ChatHandler::HandleCastTargetCommand(char* args) // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form uint32 spell = ExtractSpellIdFromLink(&args); - if (!spell || !sSpellTemplate.LookupEntry(spell)) + if (!spell || !sSpellTemplate.LookupEntry(spell)) return false; bool triggered = ExtractLiteralArg(&args, "triggered") != nullptr; @@ -5726,7 +5683,7 @@ bool ChatHandler::HandleCastSelfCommand(char* args) if (!spell) return false; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell); if (!spellInfo) return false; @@ -6922,7 +6879,7 @@ bool ChatHandler::ModifyStatCommandHelper(char* args, char const* statName, uint { if (!*args) return false; - + Unit* target = getSelectedUnit(); if (!target) @@ -7017,7 +6974,7 @@ bool ChatHandler::HandleModifyArcaneCommand(char *args) bool ChatHandler::HandleModifyMeleeApCommand(char *args) { - + return ModifyStatCommandHelper(args, "Melee Attack Power", SPELL_MOD_MELEE_AP); } diff --git a/src/game/Chat/debugcmds.cpp b/src/game/Chat/debugcmds.cpp index 000f661a68..a5110a2afa 100644 --- a/src/game/Chat/debugcmds.cpp +++ b/src/game/Chat/debugcmds.cpp @@ -1079,7 +1079,7 @@ bool ChatHandler::HandleDebugSpellCoefsCommand(char* args) if (!spellid) return false; - SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(spellid); + SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(spellid); if (!spellEntry) return false; diff --git a/src/game/Cinematics/M2Stores.cpp b/src/game/Cinematics/M2Stores.cpp index 1774a7d198..9ea63f94da 100644 --- a/src/game/Cinematics/M2Stores.cpp +++ b/src/game/Cinematics/M2Stores.cpp @@ -165,75 +165,72 @@ void LoadM2Cameras(std::string const& dataPath) sFlyByCameraStore.clear(); uint32 oldMSTime = WorldTimer::getMSTime(); - for (uint32 i = 0; i < sCinematicCameraStore.GetNumRows(); ++i) + for (auto dbcentry : sCinematicCameraStore) { - if (CinematicCameraEntry const* dbcentry = sCinematicCameraStore.LookupEntry(i)) - { - std::string filename = dataPath; - filename.append(dbcentry->Model); + std::string filename = dataPath; + filename.append(dbcentry->Model); - // Replace slashes - std::replace(filename.begin(), filename.end(), '\\', '/'); + // Replace slashes + std::replace(filename.begin(), filename.end(), '\\', '/'); - // Replace mdx to .m2 - size_t loc = filename.find(".mdx"); - if (loc != std::string::npos) - filename.replace(loc, 4, ".m2"); + // Replace mdx to .m2 + size_t loc = filename.find(".mdx"); + if (loc != std::string::npos) + filename.replace(loc, 4, ".m2"); - std::ifstream m2file(filename.c_str(), std::ios::in | std::ios::binary); - if (!m2file.is_open()) - continue; + std::ifstream m2file(filename.c_str(), std::ios::in | std::ios::binary); + if (!m2file.is_open()) + continue; - // Get file size - m2file.seekg(0, std::ios::end); - std::streamoff const fileSize = m2file.tellg(); + // Get file size + m2file.seekg(0, std::ios::end); + std::streamoff const fileSize = m2file.tellg(); - // Reject if not at least the size of the header - if (static_cast(fileSize) < sizeof(M2Header)) - { - sLog.outError("Camera file %s is damaged. File is smaller than header size", filename.c_str()); - m2file.close(); - continue; - } - - // Read 4 bytes (signature) - m2file.seekg(0, std::ios::beg); - char fileCheck[5]; - m2file.read(fileCheck, 4); - fileCheck[4] = 0; + // Reject if not at least the size of the header + if (static_cast(fileSize) < sizeof(M2Header)) + { + sLog.outError("Camera file %s is damaged. File is smaller than header size", filename.c_str()); + m2file.close(); + continue; + } - // Check file has correct magic (MD20) - if (strcmp(fileCheck, "MD20")) - { - sLog.outError("Camera file %s is damaged. File identifier not found", filename.c_str()); - m2file.close(); - continue; - } + // Read 4 bytes (signature) + m2file.seekg(0, std::ios::beg); + char fileCheck[5]; + m2file.read(fileCheck, 4); + fileCheck[4] = 0; - // Now we have a good file, read it all into a vector of char's, then close the file. - std::vector buffer(fileSize); - m2file.seekg(0, std::ios::beg); - if (!m2file.read(buffer.data(), fileSize)) - { - m2file.close(); - continue; - } + // Check file has correct magic (MD20) + if (strcmp(fileCheck, "MD20")) + { + sLog.outError("Camera file %s is damaged. File identifier not found", filename.c_str()); m2file.close(); + continue; + } - // Read header - M2Header const* header = reinterpret_cast(buffer.data()); + // Now we have a good file, read it all into a vector of char's, then close the file. + std::vector buffer(fileSize); + m2file.seekg(0, std::ios::beg); + if (!m2file.read(buffer.data(), fileSize)) + { + m2file.close(); + continue; + } + m2file.close(); - if (header->ofsCameras + sizeof(M2Camera) > static_cast(fileSize)) - { - sLog.outError("Camera file %s is damaged. Camera references position beyond file end (header)", filename.c_str()); - continue; - } + // Read header + M2Header const* header = reinterpret_cast(buffer.data()); - // Get camera(s) - Main header, then dump them. - M2Camera const* cam = reinterpret_cast(buffer.data() + header->ofsCameras); - if (!readCamera(cam, fileSize, header, dbcentry)) - sLog.outError("Camera file %s is damaged. Camera references position beyond file end (camera)", filename.c_str()); + if (header->ofsCameras + sizeof(M2Camera) > static_cast(fileSize)) + { + sLog.outError("Camera file %s is damaged. Camera references position beyond file end (header)", filename.c_str()); + continue; } + + // Get camera(s) - Main header, then dump them. + M2Camera const* cam = reinterpret_cast(buffer.data() + header->ofsCameras); + if (!readCamera(cam, fileSize, header, dbcentry)) + sLog.outError("Camera file %s is damaged. Camera references position beyond file end (camera)", filename.c_str()); } sLog.outString(">> Loaded %u cinematic waypoint sets in %u ms", static_cast(sFlyByCameraStore.size()), WorldTimer::getMSTimeDiff(oldMSTime, WorldTimer::getMSTime())); sLog.outString(); diff --git a/src/game/DBScripts/ScriptMgr.cpp b/src/game/DBScripts/ScriptMgr.cpp index c2e356a0ca..c5610b16f9 100644 --- a/src/game/DBScripts/ScriptMgr.cpp +++ b/src/game/DBScripts/ScriptMgr.cpp @@ -64,11 +64,11 @@ uint8 GetSpellStartDBScriptPriority(SpellEntry const* spellinfo, SpellEffectInde return 9; // NonExisting triggered spells can also start DB-Spell-Scripts - if (spellinfo->Effect[effIdx] == SPELL_EFFECT_TRIGGER_SPELL && !sSpellTemplate.LookupEntry(spellinfo->EffectTriggerSpell[effIdx])) + if (spellinfo->Effect[effIdx] == SPELL_EFFECT_TRIGGER_SPELL && !sSpellTemplate.LookupEntry(spellinfo->EffectTriggerSpell[effIdx])) return 5; // NonExisting trigger missile spells can also start DB-Spell-Scripts - if (spellinfo->Effect[effIdx] == SPELL_EFFECT_TRIGGER_MISSILE && !sSpellTemplate.LookupEntry(spellinfo->EffectTriggerSpell[effIdx])) + if (spellinfo->Effect[effIdx] == SPELL_EFFECT_TRIGGER_MISSILE && !sSpellTemplate.LookupEntry(spellinfo->EffectTriggerSpell[effIdx])) return 4; // Can not start script @@ -146,7 +146,7 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename) tmp.o = fields[16].GetFloat(); tmp.condition_id = fields[17].GetUInt32(); - if (tmp.condition_id && !sConditionStorage.LookupEntry(tmp.condition_id)) + if (tmp.condition_id && !sConditionStorage.LookupEntry(tmp.condition_id)) { sLog.outErrorDb("Table `%s` has condition_id = %u in command %u for script id %u, but this condition does not exist, skipping.", tablename, tmp.condition_id, tmp.command, tmp.id); continue; @@ -451,7 +451,7 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename) break; case SCRIPT_COMMAND_REMOVE_AURA: // 14 { - if (!sSpellTemplate.LookupEntry(tmp.removeAura.spellId)) + if (!sSpellTemplate.LookupEntry(tmp.removeAura.spellId)) { sLog.outErrorDb("Table `%s` using nonexistent spell (id: %u) in SCRIPT_COMMAND_REMOVE_AURA or SCRIPT_COMMAND_CAST_SPELL for script id %u", tablename, tmp.removeAura.spellId, tmp.id); @@ -461,7 +461,7 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename) } case SCRIPT_COMMAND_CAST_SPELL: // 15 { - if (!sSpellTemplate.LookupEntry(tmp.castSpell.spellId)) + if (!sSpellTemplate.LookupEntry(tmp.castSpell.spellId)) { sLog.outErrorDb("Table `%s` using nonexistent spell (id: %u) in SCRIPT_COMMAND_REMOVE_AURA or SCRIPT_COMMAND_CAST_SPELL for script id %u", tablename, tmp.castSpell.spellId, tmp.id); @@ -470,7 +470,7 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename) bool hasErrored = false; for (uint8 i = 0; i < MAX_TEXT_ID; ++i) { - if (tmp.textId[i] && !sSpellTemplate.LookupEntry(uint32(tmp.textId[i]))) + if (tmp.textId[i] && !sSpellTemplate.LookupEntry(uint32(tmp.textId[i]))) { sLog.outErrorDb("Table `%s` using nonexistent spell (id: %u) in SCRIPT_COMMAND_CAST_SPELL for script id %u, dataint%u", tablename, uint32(tmp.textId[i]), tmp.id, i + 1); @@ -633,17 +633,18 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename) if (!sLog.HasLogFilter(LOG_FILTER_DB_STRICTED_CHECK)) { uint32 taxiSpell = 0; - for (uint32 i = 1; i < sSpellTemplate.GetMaxEntry() && taxiSpell == 0; ++i) + for (auto spell : sSpellTemplate) { - if (SpellEntry const* spell = sSpellTemplate.LookupEntry(i)) - for (int j = 0; j < MAX_EFFECT_INDEX; ++j) + for (int j = 0; j < MAX_EFFECT_INDEX; ++j) + { + if (spell->Effect[j] == SPELL_EFFECT_SEND_TAXI && spell->EffectMiscValue[j] == int32(tmp.sendTaxiPath.taxiPathId)) { - if (spell->Effect[j] == SPELL_EFFECT_SEND_TAXI && spell->EffectMiscValue[j] == int32(tmp.sendTaxiPath.taxiPathId)) - { - taxiSpell = i; - break; - } + taxiSpell = spell->Id; + break; } + } + if (taxiSpell) + break; } if (taxiSpell) @@ -674,7 +675,7 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename) break; case SCRIPT_COMMAND_TERMINATE_COND: // 34 { - if (!sConditionStorage.LookupEntry(tmp.terminateCond.conditionId)) + if (!sConditionStorage.LookupEntry(tmp.terminateCond.conditionId)) { sLog.outErrorDb("Table `%s` has datalong = %u in SCRIPT_COMMAND_TERMINATE_COND for script id %u, but this condition_id does not exist.", tablename, tmp.terminateCond.conditionId, tmp.id); continue; @@ -730,7 +731,7 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename) break; case SCRIPT_COMMAND_UPDATE_TEMPLATE: // 44 { - if (!sCreatureStorage.LookupEntry(tmp.updateTemplate.newTemplate)) + if (!sCreatureStorage.LookupEntry(tmp.updateTemplate.newTemplate)) { sLog.outErrorDb("Table `%s` uses nonexistent creature entry %u in SCRIPT_COMMAND_UPDATE_TEMPLATE for script id %u.", tablename, tmp.updateTemplate.newTemplate, tmp.id); continue; @@ -762,7 +763,7 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename) } case SCRIPT_COMMAND_CAST_CUSTOM_SPELL: // 46 { - if (!sSpellTemplate.LookupEntry(tmp.castSpell.spellId)) + if (!sSpellTemplate.LookupEntry(tmp.castSpell.spellId)) { sLog.outErrorDb("Table `%s` using nonexistent spell (id: %u) in SCRIPT_COMMAND_CAST_CUSTOM_SPELL for script id %u", tablename, tmp.castSpell.spellId, tmp.id); @@ -869,7 +870,7 @@ void ScriptMgr::LoadSpellScripts() // check ids for (ScriptMapMap::const_iterator itr = sSpellScripts.second.begin(); itr != sSpellScripts.second.end(); ++itr) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(itr->first); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(itr->first); if (!spellInfo) { sLog.outErrorDb("Table `dbscripts_on_spell` has not existing spell (Id: %u) as script id", itr->first); @@ -2499,7 +2500,7 @@ int32 ScriptMgr::GetRandomRelayDbscriptFromTemplate(uint32 id) void ScriptMgr::CollectPossibleEventIds(std::set& eventIds) { // Load all possible script entries from gameobjects - for (SQLStorageBase::SQLSIterator itr = sGOStorage.getDataBegin(); itr < sGOStorage.getDataEnd(); ++itr) + for (auto itr : sGOStorage) { switch (itr->type) { @@ -2529,18 +2530,14 @@ void ScriptMgr::CollectPossibleEventIds(std::set& eventIds) } // Load all possible script entries from spells - for (uint32 i = 1; i < sSpellTemplate.GetMaxEntry(); ++i) + for (auto spell : sSpellTemplate) { - SpellEntry const* spell = sSpellTemplate.LookupEntry(i); - if (spell) + for (int j = 0; j < MAX_EFFECT_INDEX; ++j) { - for (int j = 0; j < MAX_EFFECT_INDEX; ++j) + if (spell->Effect[j] == SPELL_EFFECT_SEND_EVENT) { - if (spell->Effect[j] == SPELL_EFFECT_SEND_EVENT) - { - if (spell->EffectMiscValue[j]) - eventIds.insert(spell->EffectMiscValue[j]); - } + if (spell->EffectMiscValue[j]) + eventIds.insert(spell->EffectMiscValue[j]); } } } diff --git a/src/game/Entities/CharacterHandler.cpp b/src/game/Entities/CharacterHandler.cpp index 8fa5f7a195..8a3abf6c60 100644 --- a/src/game/Entities/CharacterHandler.cpp +++ b/src/game/Entities/CharacterHandler.cpp @@ -801,7 +801,7 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder* holder) if (!pCurrChar->isGMVisible()) { SendNotification(LANG_INVISIBLE_INVISIBLE); - SpellEntry const* invisibleAuraInfo = sSpellTemplate.LookupEntry(sWorld.getConfig(CONFIG_UINT32_GM_INVISIBLE_AURA)); + SpellEntry const* invisibleAuraInfo = sSpellTemplate.LookupEntry(sWorld.getConfig(CONFIG_UINT32_GM_INVISIBLE_AURA)); if (invisibleAuraInfo && IsSpellAppliesAura(invisibleAuraInfo)) pCurrChar->CastSpell(pCurrChar, invisibleAuraInfo, TRIGGERED_OLD_TRIGGERED); } diff --git a/src/game/Entities/Creature.cpp b/src/game/Entities/Creature.cpp index 83df97aa27..c1e40a1dd4 100644 --- a/src/game/Entities/Creature.cpp +++ b/src/game/Entities/Creature.cpp @@ -399,7 +399,7 @@ bool Creature::InitEntry(uint32 Entry, CreatureData const* data /*=nullptr*/, Ga LoadEquipment(data->spawnTemplate->equipmentId); } else if (data->equipmentId != -1) - LoadEquipment(data->equipmentId); + LoadEquipment(data->equipmentId); } if (eventData && eventData->vendor_id) @@ -546,7 +546,7 @@ bool Creature::UpdateEntry(uint32 Entry, const CreatureData* data /*=nullptr*/, { if (factionTemplate->factionFlags & FACTION_TEMPLATE_FLAG_PVP) { - const AreaTableEntry* zone = GetAreaEntryByAreaID(GetAreaId()); + const AreaTableEntry* zone = TerrainManager::GetAreaEntryByAreaID(GetAreaId()); const bool sanctuary = (zone && (zone->flags & AREA_FLAG_SANCTUARY)); SetPvP(!sanctuary); } @@ -644,6 +644,15 @@ uint32 Creature::ChooseDisplayId(const CreatureInfo* cinfo, const CreatureData* return display_id; } +uint32 Creature::GetCreatureModelRace(uint32 model_id) +{ + CreatureDisplayInfoEntry const* displayEntry = sCreatureDisplayInfoStore.LookupEntry(model_id); + if (!displayEntry) + return 0; + CreatureDisplayInfoExtraEntry const* extraEntry = sCreatureDisplayInfoExtraStore.LookupEntry(displayEntry->ExtendedDisplayInfoID); + return extraEntry ? extraEntry->Race : 0; +} + void Creature::Update(const uint32 diff) { switch (m_deathState) @@ -1858,7 +1867,7 @@ SpellEntry const* Creature::ReachWithSpellAttack(Unit* pVictim) { if (!m_spell) continue; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(m_spell); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(m_spell); if (!spellInfo) { sLog.outError("WORLD: unknown spell id %i", m_spell); @@ -1910,7 +1919,7 @@ SpellEntry const* Creature::ReachWithSpellCure(Unit* pVictim) { if (!m_spell) continue; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(m_spell); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(m_spell); if (!spellInfo) { sLog.outError("WORLD: unknown spell id %i", m_spell); @@ -2301,7 +2310,7 @@ bool Creature::MeetsSelectAttackingRequirement(Unit* pTarget, SpellEntry const* Unit* Creature::SelectAttackingTarget(AttackingTarget target, uint32 position, uint32 spellId, uint32 selectFlags, SelectAttackingTargetParams params /*= SelectAttackingTargetParams()*/) const { - return SelectAttackingTarget(target, position, sSpellTemplate.LookupEntry(spellId), selectFlags, params); + return SelectAttackingTarget(target, position, sSpellTemplate.LookupEntry(spellId), selectFlags, params); } Unit* Creature::SelectAttackingTarget(AttackingTarget target, uint32 position, SpellEntry const* spellInfo /*= nullptr*/, uint32 selectFlags/*= 0*/, SelectAttackingTargetParams params /*= SelectAttackingTargetParams()*/) const @@ -2416,7 +2425,7 @@ Unit* Creature::SelectAttackingTarget(AttackingTarget target, uint32 position, S void Creature::SelectAttackingTargets(std::vector& selectedTargets, AttackingTarget target, uint32 position, uint32 spellId, uint32 selectFlags/*= 0*/, SelectAttackingTargetParams params /*= SelectAttackingTargetParams()*/) const { - SelectAttackingTargets(selectedTargets, target, position, sSpellTemplate.LookupEntry(spellId), selectFlags, params); + SelectAttackingTargets(selectedTargets, target, position, sSpellTemplate.LookupEntry(spellId), selectFlags, params); } void Creature::SelectAttackingTargets(std::vector& selectedTargets, AttackingTarget target, uint32 position, SpellEntry const* spellInfo /*= nullptr*/, uint32 selectFlags/*= 0*/, SelectAttackingTargetParams params /*= SelectAttackingTargetParams()*/) const @@ -2708,7 +2717,7 @@ void Creature::ApplyGameEventSpells(GameEventCreatureData const* eventData, bool uint32 remove_spell = activated ? eventData->spell_id_end : eventData->spell_id_start; if (remove_spell) - if (SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(remove_spell)) + if (SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(remove_spell)) if (IsSpellAppliesAura(spellEntry)) RemoveAurasDueToSpell(remove_spell); diff --git a/src/game/Entities/Creature.h b/src/game/Entities/Creature.h index f63688084b..9e2a3b67ec 100644 --- a/src/game/Entities/Creature.h +++ b/src/game/Entities/Creature.h @@ -67,273 +67,6 @@ enum CreatureExtraFlags CREATURE_EXTRA_FLAG_POISON_IMMUNITY = 0x01000000, // 16777216 creature is immune to poisons }; -// GCC have alternative #pragma pack(N) syntax and old gcc version not support pack(push,N), also any gcc version not support it at some platform -#if defined( __GNUC__ ) -#pragma pack(1) -#else -#pragma pack(push,1) -#endif - -#define MAX_KILL_CREDIT 2 -#define MAX_CREATURE_MODEL 4 -#define USE_DEFAULT_DATABASE_LEVEL 0 // just used to show we don't want to force the new creature level and use the level stored in db -#define MINIMUM_LOOTING_TIME (2 * MINUTE * IN_MILLISECONDS) // give player enough time to pick loot - -// from `creature_template` table -struct CreatureInfo -{ - uint32 Entry; - char* Name; - char* SubName; - char* IconName; - uint32 MinLevel; - uint32 MaxLevel; - uint32 HeroicEntry; - uint32 ModelId[MAX_CREATURE_MODEL]; - uint32 Faction; - float Scale; - uint32 Family; // enum CreatureFamily values (optional) - uint32 CreatureType; // enum CreatureType values - uint32 InhabitType; - uint32 RegenerateStats; - bool RacialLeader; - uint32 NpcFlags; - uint32 UnitFlags; // enum UnitFlags mask values - uint32 DynamicFlags; - uint32 ExtraFlags; - uint32 CreatureTypeFlags; // enum CreatureTypeFlags mask values - float SpeedWalk; - float SpeedRun; - uint32 Detection; // Detection Range for Line of Sight aggro - uint32 CallForHelp; - uint32 Pursuit; - uint32 Leash; - uint32 Timeout; - uint32 UnitClass; // enum Classes. Note only 4 classes are known for creatures. - uint32 Rank; - int32 Expansion; // creature expansion, important for stats, CAN BE -1 as marker for some invalid cases. - float HealthMultiplier; - float PowerMultiplier; - float DamageMultiplier; - float DamageVariance; - float ArmorMultiplier; - float ExperienceMultiplier; - uint32 MinLevelHealth; - uint32 MaxLevelHealth; - uint32 MinLevelMana; - uint32 MaxLevelMana; - float MinMeleeDmg; - float MaxMeleeDmg; - float MinRangedDmg; - float MaxRangedDmg; - uint32 Armor; - uint32 MeleeAttackPower; - uint32 RangedAttackPower; - uint32 MeleeBaseAttackTime; - uint32 RangedBaseAttackTime; - uint32 DamageSchool; - uint32 MinLootGold; - uint32 MaxLootGold; - uint32 LootId; - uint32 PickpocketLootId; - uint32 SkinningLootId; - uint32 KillCredit[MAX_KILL_CREDIT]; - uint32 MechanicImmuneMask; - uint32 SchoolImmuneMask; - int32 ResistanceHoly; - int32 ResistanceFire; - int32 ResistanceNature; - int32 ResistanceFrost; - int32 ResistanceShadow; - int32 ResistanceArcane; - uint32 PetSpellDataId; - uint32 MovementType; - uint32 TrainerType; - uint32 TrainerSpell; - uint32 TrainerClass; - uint32 TrainerRace; - uint32 TrainerTemplateId; - uint32 VendorTemplateId; - uint32 EquipmentTemplateId; - uint32 GossipMenuId; - VisibilityDistanceType visibilityDistanceType; - char const* AIName; - uint32 ScriptID; - - // helpers - static HighGuid GetHighGuid() - { - return HIGHGUID_UNIT; // in pre-3.x always HIGHGUID_UNIT - } - - ObjectGuid GetObjectGuid(uint32 lowguid) const { return ObjectGuid(GetHighGuid(), Entry, lowguid); } - - SkillType GetRequiredLootSkill() const - { - if (CreatureTypeFlags & CREATURE_TYPEFLAGS_HERBLOOT) - return SKILL_HERBALISM; - if (CreatureTypeFlags & CREATURE_TYPEFLAGS_MININGLOOT) - return SKILL_MINING; - - return SKILL_SKINNING; // normal case - } - - bool isTameable() const - { - return CreatureType == CREATURE_TYPE_BEAST && Family != 0 && (CreatureTypeFlags & CREATURE_TYPEFLAGS_TAMEABLE); - } -}; - -struct CreatureTemplateSpells -{ - uint32 entry; - uint32 setId; - uint32 spells[CREATURE_MAX_SPELLS]; -}; - -struct CreatureCooldowns -{ - uint32 entry; - uint32 spellId; - uint32 cooldownMin; - uint32 cooldownMax; -}; - -struct EquipmentInfo -{ - uint32 entry; - uint32 equipentry[3]; -}; - -// depricated old way -struct EquipmentInfoRaw -{ - uint32 entry; - uint32 equipmodel[3]; - uint32 equipinfo[3]; - uint32 equipslot[3]; -}; - -enum SpawnFlags -{ - SPAWN_FLAG_RUN_ON_SPAWN = 0x01, - SPAWN_FLAG_HOVER = 0x02, -}; - -struct CreatureSpawnTemplate -{ - uint32 entry; - int64 unitFlags; - uint32 faction; - uint32 modelId; - int32 equipmentId; - uint32 curHealth; - uint32 curMana; - uint32 spawnFlags; - - bool IsRunning() const { return (spawnFlags & SPAWN_FLAG_RUN_ON_SPAWN) != 0; } - bool IsHovering() const { return (spawnFlags & SPAWN_FLAG_HOVER) != 0; } -}; - -// from `creature` table -struct CreatureData -{ - uint32 id; // entry in creature_template - uint16 mapid; - uint32 modelid_override; // overrides any model defined in creature_template - int32 equipmentId; - float posX; - float posY; - float posZ; - float orientation; - uint32 spawntimesecsmin; - uint32 spawntimesecsmax; - float spawndist; - uint32 currentwaypoint; - uint32 curhealth; - uint32 curmana; - bool is_dead; - uint8 movementType; - uint8 spawnMask; - int16 gameEvent; - uint16 GuidPoolId; - uint16 EntryPoolId; - uint16 OriginalZoneId; - CreatureSpawnTemplate const* spawnTemplate; - - // helper function - ObjectGuid GetObjectGuid(uint32 lowguid) const { return ObjectGuid(CreatureInfo::GetHighGuid(), id, lowguid); } - uint32 GetRandomRespawnTime() const { return urand(spawntimesecsmin, spawntimesecsmax); } - - // return false if it should be handled by GameEventMgr or PoolMgr - bool IsNotPartOfPoolOrEvent() const { return (!gameEvent && !GuidPoolId && !EntryPoolId); } -}; - -enum SplineFlags -{ - SPLINEFLAG_WALKMODE = 0x0000100, - SPLINEFLAG_FLYING = 0x0000200, -}; - -// from `creature_addon` and `creature_template_addon`tables -struct CreatureDataAddon -{ - uint32 guidOrEntry; - uint32 mount; - uint32 bytes1; - uint8 sheath_state; // SheathState - uint8 flags; // UnitBytes2_Flags - uint32 emote; - uint32 move_flags; - uint32 const* auras; // loaded as char* "spell1 spell2 ... " -}; - -// Bases values for given Level and UnitClass -struct CreatureClassLvlStats -{ - uint32 BaseHealth; - uint32 BaseMana; - float BaseDamage; - float BaseMeleeAttackPower; - float BaseRangedAttackPower; - uint32 BaseArmor; -}; - -struct CreatureModelInfo -{ - uint32 modelid; - float bounding_radius; - float combat_reach; - float SpeedWalk; - float SpeedRun; - uint8 gender; - uint32 modelid_other_gender; // The oposite gender for this modelid (male/female) - uint32 modelid_alternative; // An alternative model. Generally same gender(2) -}; - -struct CreatureModelRace -{ - uint32 modelid; // Native model/base model the selection is for - uint32 racemask; // Races it applies to (and then a player source must exist for selection) - uint32 creature_entry; // Modelid from creature_template.entry will be selected - uint32 modelid_racial; // Explicit modelid. Used if creature_template entry is not defined -}; - -struct CreatureConditionalSpawn -{ - uint32 Guid; - uint32 EntryAlliance; - uint32 EntryHorde; - // Note: future condition flags to be added -}; - -// GCC have alternative #pragma pack() syntax and old gcc version not support pack(pop), also any gcc version not support it at some platform -#if defined( __GNUC__ ) -#pragma pack() -#else -#pragma pack(pop) -#endif - struct CreatureLocale { std::vector Name; @@ -738,6 +471,7 @@ class Creature : public Unit CreatureDataAddon const* GetCreatureAddon() const; static uint32 ChooseDisplayId(const CreatureInfo* cinfo, const CreatureData* data = nullptr, GameEventCreatureData const* eventData = nullptr); + static uint32 GetCreatureModelRace(uint32 model_id); std::string GetAIName() const; std::string GetScriptName() const; diff --git a/src/game/Entities/CreatureLinkingMgr.cpp b/src/game/Entities/CreatureLinkingMgr.cpp index 73bac5b449..680afd4393 100644 --- a/src/game/Entities/CreatureLinkingMgr.cpp +++ b/src/game/Entities/CreatureLinkingMgr.cpp @@ -461,7 +461,7 @@ void CreatureLinkingHolder::DoCreatureLinkingEvent(CreatureLinkingEvent eventTyp { Creature* pMaster = nullptr; if (pInfo->mapId != INVALID_MAP_ID) // entry case - { + { BossGuidMapBounds finds = m_masterGuid.equal_range(pInfo->masterId); for (BossGuidMap::const_iterator itr = finds.first; itr != finds.second; ++itr) { @@ -494,7 +494,7 @@ void CreatureLinkingHolder::DoCreatureLinkingEvent(CreatureLinkingEvent eventTyp pEnemy->AddThreat(pMaster); pEnemy->SetInCombatWith(pMaster); pEnemy->GetCombatManager().TriggerCombatTimer(pMaster); - } + } else pMaster->AI()->AttackStart(pEnemy); break; diff --git a/src/game/Entities/DynamicObject.cpp b/src/game/Entities/DynamicObject.cpp index 1fed0bf2a4..bb38e74953 100644 --- a/src/game/Entities/DynamicObject.cpp +++ b/src/game/Entities/DynamicObject.cpp @@ -93,7 +93,7 @@ bool DynamicObject::Create(uint32 guidlow, Unit* caster, uint32 spellId, SpellEf SetFloatValue(DYNAMICOBJECT_POS_Z, z); SetUInt32Value(DYNAMICOBJECT_CASTTIME, WorldTimer::getMSTime()); // new 2.4.0 - SpellEntry const* spellProto = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellProto = sSpellTemplate.LookupEntry(spellId); if (!spellProto) { sLog.outError("DynamicObject (spell %u) not created. Spell not exist!", spellId); diff --git a/src/game/Entities/GameObject.cpp b/src/game/Entities/GameObject.cpp index b7bb392c19..b2d6a30570 100644 --- a/src/game/Entities/GameObject.cpp +++ b/src/game/Entities/GameObject.cpp @@ -430,7 +430,7 @@ void GameObject::Update(const uint32 diff) { if (m_respawnTime > 0) valid = false; - else // battlegrounds gameobjects has data2 == 0 && data5 == 3 + else // battlegrounds gameobjects has data2 == 0 && data5 == 3 radius = float(goInfo->trap.cooldown); } } @@ -1160,7 +1160,7 @@ void GameObject::TriggerLinkedGameObject(Unit* target) const if (!trapEntry) return; - GameObjectInfo const* trapInfo = sGOStorage.LookupEntry(trapEntry); + GameObjectInfo const* trapInfo = sGOStorage.LookupEntry(trapEntry); if (!trapInfo || trapInfo->type != GAMEOBJECT_TYPE_TRAP) return; @@ -1857,7 +1857,7 @@ void GameObject::Use(Unit* user, SpellEntry const* spellInfo) if (!spellId) return; - SpellEntry const* triggeredSpellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* triggeredSpellInfo = sSpellTemplate.LookupEntry(spellId); if (!triggeredSpellInfo) { sLog.outError("WORLD: unknown spell id %u at use action for gameobject (Entry: %u GoType: %u )", spellId, GetEntry(), GetGoType()); @@ -2509,14 +2509,14 @@ SpellEntry const* GameObject::GetSpellForLock(Player const* player) const continue; if (lock->Type[i] == LOCK_KEY_SPELL) - if (SpellEntry const* spell = sSpellTemplate.LookupEntry(lock->Index[i])) + if (SpellEntry const* spell = sSpellTemplate.LookupEntry(lock->Index[i])) return spell; if (lock->Type[i] != LOCK_KEY_SKILL) break; for (auto&& playerSpell : player->GetSpellMap()) - if (SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(playerSpell.first)) + if (SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(playerSpell.first)) for (uint32 i = 0; i < MAX_EFFECT_INDEX; ++i) if (spellInfo->Effect[i] == SPELL_EFFECT_OPEN_LOCK && ((uint32)spellInfo->EffectMiscValue[i]) == lock->Index[i]) if (player->CalculateSpellEffectValue(nullptr, spellInfo, SpellEffectIndex(i), nullptr) >= int32(lock->Skill[i])) @@ -2528,7 +2528,7 @@ SpellEntry const* GameObject::GetSpellForLock(Player const* player) const SpellCastResult GameObject::CastSpell(Unit* temporaryCaster, Unit* Victim, uint32 spellId, uint32 triggeredFlags, Item* castItem, Aura* triggeredByAura, ObjectGuid originalCaster, SpellEntry const* triggeredBy) { - return CastSpell(temporaryCaster, Victim, sSpellTemplate.LookupEntry(spellId), triggeredFlags, castItem, triggeredByAura, originalCaster, triggeredBy); + return CastSpell(temporaryCaster, Victim, sSpellTemplate.LookupEntry(spellId), triggeredFlags, castItem, triggeredByAura, originalCaster, triggeredBy); } SpellCastResult GameObject::CastSpell(Unit* temporaryCaster, Unit* Victim, SpellEntry const* spellInfo, uint32 triggeredFlags, Item* castItem, Aura* triggeredByAura, ObjectGuid originalCaster, SpellEntry const* triggeredBy) diff --git a/src/game/Entities/GameObject.h b/src/game/Entities/GameObject.h index 595976ff7b..3f1ab54feb 100644 --- a/src/game/Entities/GameObject.h +++ b/src/game/Entities/GameObject.h @@ -34,536 +34,7 @@ #pragma pack(push,1) #endif -// from `gameobject_template` -struct GameObjectInfo -{ - uint32 id; - uint32 type; - uint32 displayId; - char* name; - char* IconName; - char* castBarCaption; - uint32 faction; - uint32 flags; - uint32 ExtraFlags; - float size; - union // different GO types have different data field - { - //0 GAMEOBJECT_TYPE_DOOR - struct - { - uint32 startOpen; //0 used client side to determine GO_ACTIVATED means open/closed - uint32 lockId; //1 -> Lock.dbc - uint32 autoCloseTime; //2 secs till autoclose = autoCloseTime / 0x10000 - uint32 noDamageImmune; //3 break opening whenever you recieve damage? - uint32 openTextID; //4 can be used to replace castBarCaption? - uint32 closeTextID; //5 - } door; - //1 GAMEOBJECT_TYPE_BUTTON - struct - { - uint32 startOpen; //0 - uint32 lockId; //1 -> Lock.dbc - uint32 autoCloseTime; //2 secs till autoclose = autoCloseTime / 0x10000 - uint32 linkedTrapId; //3 - uint32 noDamageImmune; //4 isBattlegroundObject - uint32 large; //5 - uint32 openTextID; //6 can be used to replace castBarCaption? - uint32 closeTextID; //7 - uint32 losOK; //8 - } button; - //2 GAMEOBJECT_TYPE_QUESTGIVER - struct - { - uint32 lockId; //0 -> Lock.dbc - uint32 questList; //1 - uint32 pageMaterial; //2 - uint32 gossipID; //3 - uint32 customAnim; //4 - uint32 noDamageImmune; //5 - int32 openTextID; //6 can be used to replace castBarCaption? - uint32 losOK; //7 - uint32 allowMounted; //8 - uint32 large; //9 - } questgiver; - //3 GAMEOBJECT_TYPE_CHEST - struct - { - uint32 lockId; //0 -> Lock.dbc - uint32 lootId; //1 - uint32 chestRestockTime; //2 - uint32 consumable; //3 - uint32 minSuccessOpens; //4 - uint32 maxSuccessOpens; //5 - int32 eventId; //6 lootedEvent - uint32 linkedTrapId; //7 - uint32 questId; //8 not used currently but store quest required for GO activation for player - uint32 level; //9 - uint32 losOK; //10 - uint32 leaveLoot; //11 - uint32 notInCombat; //12 - uint32 logLoot; //13 - uint32 openTextID; //14 can be used to replace castBarCaption? - uint32 groupLootRules; //15 - } chest; - //4 GAMEOBJECT_TYPE_BINDER - empty - //5 GAMEOBJECT_TYPE_GENERIC - struct - { - uint32 floatingTooltip; //0 - uint32 highlight; //1 - uint32 serverOnly; //2 - uint32 large; //3 - uint32 floatOnWater; //4 - uint32 questID; //5 - } _generic; - //6 GAMEOBJECT_TYPE_TRAP - struct - { - uint32 lockId; //0 -> Lock.dbc - uint32 level; //1 - uint32 diameter; //2 radius for trap activation - uint32 spellId; //3 - uint32 charges; //4 need respawn (if > 0) - uint32 cooldown; //5 time in secs - int32 autoCloseTime; //6 - uint32 startDelay; //7 - uint32 serverOnly; //8 - uint32 stealthed; //9 - uint32 large; //10 - uint32 invisible; //11 - uint32 openTextID; //12 can be used to replace castBarCaption? - uint32 closeTextID; //13 - } trap; - //7 GAMEOBJECT_TYPE_CHAIR - struct - { - uint32 slots; //0 - uint32 height; //1 - uint32 onlyCreatorUse; //2 - } chair; - //8 GAMEOBJECT_TYPE_SPELL_FOCUS - struct - { - uint32 focusId; //0 - uint32 dist; //1 - uint32 linkedTrapId; //2 - uint32 serverOnly; //3 - uint32 questID; //4 - uint32 large; //5 - } spellFocus; - //9 GAMEOBJECT_TYPE_TEXT - struct - { - uint32 pageID; //0 - uint32 language; //1 - uint32 pageMaterial; //2 - uint32 allowMounted; //3 - } text; - //10 GAMEOBJECT_TYPE_GOOBER - struct - { - uint32 lockId; //0 -> Lock.dbc - int32 questId; //1 - uint32 eventId; //2 - uint32 autoCloseTime; //3 - uint32 customAnim; //4 - uint32 consumable; //5 - int32 cooldown; //6 - uint32 pageId; //7 - uint32 language; //8 - uint32 pageMaterial; //9 - uint32 spellId; //10 - uint32 noDamageImmune; //11 - uint32 linkedTrapId; //12 - uint32 large; //13 - uint32 openTextID; //14 can be used to replace castBarCaption? - uint32 closeTextID; //15 - uint32 isPvPObject; //16 flags used only in battlegrounds - uint32 allowMounted; //17 - uint32 floatingTooltip; //18 - uint32 gossipID; //19 - } goober; - //11 GAMEOBJECT_TYPE_TRANSPORT - struct - { - uint32 pause; //0 - uint32 startOpen; //1 - uint32 autoCloseTime; //2 secs till autoclose = autoCloseTime / 0x10000 - } transport; - //12 GAMEOBJECT_TYPE_AREADAMAGE - struct - { - uint32 lockId; //0 - uint32 radius; //1 - uint32 damageMin; //2 - uint32 damageMax; //3 - uint32 damageSchool; //4 - uint32 autoCloseTime; //5 secs till autoclose = autoCloseTime / 0x10000 - uint32 openTextID; //6 - uint32 closeTextID; //7 - } areadamage; - //13 GAMEOBJECT_TYPE_CAMERA - struct - { - uint32 lockId; //0 -> Lock.dbc - uint32 cinematicId; //1 - uint32 eventID; //2 - uint32 openTextID; //3 can be used to replace castBarCaption? - } camera; - //14 GAMEOBJECT_TYPE_MAPOBJECT - empty - //15 GAMEOBJECT_TYPE_MO_TRANSPORT - struct - { - uint32 taxiPathId; //0 - uint32 moveSpeed; //1 - uint32 accelRate; //2 - uint32 startEventID; //3 - uint32 stopEventID; //4 - uint32 transportPhysics; //5 - uint32 mapID; //6 - } moTransport; - //16 GAMEOBJECT_TYPE_DUELFLAG - empty - //17 GAMEOBJECT_TYPE_FISHINGNODE - struct - { - uint32 _data0; //0 - uint32 lootId; //1 - } fishnode; - //18 GAMEOBJECT_TYPE_SUMMONING_RITUAL - struct - { - uint32 reqParticipants; //0 - uint32 spellId; //1 - uint32 animSpell; //2 - uint32 ritualPersistent; //3 - uint32 casterTargetSpell; //4 - uint32 casterTargetSpellTargets; //5 - uint32 castersGrouped; //6 - uint32 ritualNoTargetCheck; //7 - } summoningRitual; - //19 GAMEOBJECT_TYPE_MAILBOX - empty - //20 GAMEOBJECT_TYPE_AUCTIONHOUSE - struct - { - uint32 actionHouseID; //0 - } auctionhouse; - //21 GAMEOBJECT_TYPE_GUARDPOST - struct - { - uint32 creatureID; //0 - uint32 charges; //1 - } guardpost; - //22 GAMEOBJECT_TYPE_SPELLCASTER - struct - { - uint32 spellId; //0 - int32 charges; //1 - uint32 partyOnly; //2 - uint32 allowMounted; //3 Is usable while on mount/vehicle. (0/1) - uint32 large; //4 - uint32 conditionID1; //5 - } spellcaster; - //23 GAMEOBJECT_TYPE_MEETINGSTONE - struct - { - uint32 minLevel; //0 - uint32 maxLevel; //1 - uint32 areaID; //2 - } meetingstone; - //24 GAMEOBJECT_TYPE_FLAGSTAND - struct - { - uint32 lockId; //0 - uint32 pickupSpell; //1 - uint32 radius; //2 - uint32 returnAura; //3 - uint32 returnSpell; //4 - uint32 noDamageImmune; //5 - uint32 openTextID; //6 - uint32 losOK; //7 - } flagstand; - //25 GAMEOBJECT_TYPE_FISHINGHOLE - struct - { - uint32 radius; //0 how close bobber must land for sending loot - uint32 lootId; //1 - uint32 minSuccessOpens; //2 - uint32 maxSuccessOpens; //3 - uint32 lockId; //4 -> Lock.dbc; possibly 1628 for all? - } fishinghole; - //26 GAMEOBJECT_TYPE_FLAGDROP - struct - { - uint32 lockId; //0 - uint32 eventID; //1 - uint32 pickupSpell; //2 - uint32 noDamageImmune; //3 - uint32 openTextID; //4 - } flagdrop; - //27 GAMEOBJECT_TYPE_MINI_GAME - struct - { - uint32 gameType; //0 - } miniGame; - //29 GAMEOBJECT_TYPE_CAPTURE_POINT - struct - { - uint32 radius; //0 - uint32 spell; //1 - uint32 worldState1; //2 - uint32 worldState2; //3 - uint32 winEventID1; //4 - uint32 winEventID2; //5 - uint32 contestedEventID1; //6 - uint32 contestedEventID2; //7 - uint32 progressEventID1; //8 - uint32 progressEventID2; //9 - uint32 neutralEventID1; //10 - uint32 neutralEventID2; //11 - uint32 neutralPercent; //12 - uint32 worldState3; //13 - uint32 minSuperiority; //14 - uint32 maxSuperiority; //15 - uint32 minTime; //16 - uint32 maxTime; //17 - uint32 large; //18 - uint32 highlight; //19 - } capturePoint; - //30 GAMEOBJECT_TYPE_AURA_GENERATOR - struct - { - uint32 startOpen; //0 - uint32 radius; //1 - uint32 auraID1; //2 - uint32 conditionID1; //3 - uint32 auraID2; //4 - uint32 conditionID2; //5 - int32 serverOnly; //6 - } auraGenerator; - //31 GAMEOBJECT_TYPE_DUNGEON_DIFFICULTY - struct - { - uint32 mapID; //0 - uint32 difficulty; //1 - } dungeonDifficulty; - //32 GAMEOBJECT_TYPE_DO_NOT_USE_YET - struct - { - uint32 mapID; //0 - uint32 difficulty; //1 - } doNotUseYet; - //33 GAMEOBJECT_TYPE_DESTRUCTIBLE_BUILDING - struct - { - uint32 dmgPctState1; //0 - uint32 dmgPctState2; //1 - uint32 state1Name; //2 - uint32 state2Name; //3 - } destructibleBuilding; - //34 GAMEOBJECT_TYPE_GUILDBANK - empty - - // not use for specific field access (only for output with loop by all filed), also this determinate max union size - struct - { - uint32 data[24]; - } raw; - }; - - union - { - //6 GAMEOBJECT_TYPE_TRAP - struct - { - uint32 triggerOn; - } trapCustom; - - //18 GAMEOBJECT_TYPE_SUMMONING_RITUAL - struct - { - uint32 delay; - } summoningRitualCustom; - - struct - { - uint32 data[1]; - } rawCustom; - }; - - uint32 MinMoneyLoot; - uint32 MaxMoneyLoot; - uint32 ScriptId; - - // helpers - bool IsDespawnAtAction() const - { - switch (type) - { - case GAMEOBJECT_TYPE_CHEST: return chest.consumable != 0; - case GAMEOBJECT_TYPE_GOOBER: return goober.consumable != 0; - default: return false; - } - } - - bool IsUsableMounted() const - { - switch (type) - { - case GAMEOBJECT_TYPE_MAILBOX: return true; - case GAMEOBJECT_TYPE_BARBER_CHAIR: return false; - case GAMEOBJECT_TYPE_QUESTGIVER: return questgiver.allowMounted != 0; - case GAMEOBJECT_TYPE_TEXT: return text.allowMounted != 0; - case GAMEOBJECT_TYPE_GOOBER: return goober.allowMounted != 0; - case GAMEOBJECT_TYPE_SPELLCASTER: return spellcaster.allowMounted != 0; - default: return false; - } - } - - uint32 GetLockId() const - { - switch (type) - { - case GAMEOBJECT_TYPE_DOOR: return door.lockId; - case GAMEOBJECT_TYPE_BUTTON: return button.lockId; - case GAMEOBJECT_TYPE_QUESTGIVER: return questgiver.lockId; - case GAMEOBJECT_TYPE_CHEST: return chest.lockId; - case GAMEOBJECT_TYPE_TRAP: return trap.lockId; - case GAMEOBJECT_TYPE_GOOBER: return goober.lockId; - case GAMEOBJECT_TYPE_AREADAMAGE: return areadamage.lockId; - case GAMEOBJECT_TYPE_CAMERA: return camera.lockId; - case GAMEOBJECT_TYPE_FLAGSTAND: return flagstand.lockId; - case GAMEOBJECT_TYPE_FISHINGHOLE: return fishinghole.lockId; - case GAMEOBJECT_TYPE_FLAGDROP: return flagdrop.lockId; - default: return 0; - } - } - - bool GetDespawnPossibility() const // despawn at targeting of cast? - { - switch (type) - { - case GAMEOBJECT_TYPE_DOOR: return door.noDamageImmune != 0; - case GAMEOBJECT_TYPE_BUTTON: return button.noDamageImmune != 0; - case GAMEOBJECT_TYPE_GOOBER: return goober.noDamageImmune != 0; - case GAMEOBJECT_TYPE_FLAGSTAND: return flagstand.noDamageImmune != 0; - case GAMEOBJECT_TYPE_FLAGDROP: return flagdrop.noDamageImmune != 0; - default: return true; - } - } - - bool CannotBeUsedUnderImmunity() const // Cannot be used/activated/looted by players under immunity effects (example: Divine Shield) - { - switch (type) - { - case GAMEOBJECT_TYPE_DOOR: return door.noDamageImmune != 0; - case GAMEOBJECT_TYPE_BUTTON: return button.noDamageImmune != 0; - case GAMEOBJECT_TYPE_QUESTGIVER: return questgiver.noDamageImmune != 0; - case GAMEOBJECT_TYPE_CHEST: return true; // All chests cannot be opened while immune on 3.3.5a - case GAMEOBJECT_TYPE_GOOBER: return goober.noDamageImmune != 0; - case GAMEOBJECT_TYPE_FLAGSTAND: return flagstand.noDamageImmune != 0; - case GAMEOBJECT_TYPE_FLAGDROP: return flagdrop.noDamageImmune != 0; - default: return false; - } - } - - uint32 GetCharges() const // despawn at uses amount - { - switch (type) - { - case GAMEOBJECT_TYPE_TRAP: return trap.charges; - case GAMEOBJECT_TYPE_GUARDPOST: return guardpost.charges; - case GAMEOBJECT_TYPE_SPELLCASTER: return spellcaster.charges; - default: return 0; - } - } - - uint32 GetCooldown() const // not triggering at detection target or use until coolodwn expire - { - switch (type) - { - case GAMEOBJECT_TYPE_TRAP: return trap.cooldown; - case GAMEOBJECT_TYPE_GOOBER: return goober.cooldown; - default: return 0; - } - } - uint32 GetLinkedGameObjectEntry() const - { - switch (type) - { - case GAMEOBJECT_TYPE_BUTTON: return button.linkedTrapId; - case GAMEOBJECT_TYPE_CHEST: return chest.linkedTrapId; - case GAMEOBJECT_TYPE_SPELL_FOCUS: return spellFocus.linkedTrapId; - case GAMEOBJECT_TYPE_GOOBER: return goober.linkedTrapId; - default: return 0; - } - } - - uint32 GetAutoCloseTime() const - { - uint32 autoCloseTime = 0; - switch (type) - { - case GAMEOBJECT_TYPE_DOOR: autoCloseTime = door.autoCloseTime; break; - case GAMEOBJECT_TYPE_BUTTON: autoCloseTime = button.autoCloseTime; break; - case GAMEOBJECT_TYPE_TRAP: autoCloseTime = trap.autoCloseTime; break; - case GAMEOBJECT_TYPE_GOOBER: autoCloseTime = goober.autoCloseTime; break; - case GAMEOBJECT_TYPE_TRANSPORT: autoCloseTime = transport.autoCloseTime; break; - case GAMEOBJECT_TYPE_AREADAMAGE: autoCloseTime = areadamage.autoCloseTime; break; - default: break; - } - return autoCloseTime / 0x10000; - } - - uint32 GetLootId() const - { - switch (type) - { - case GAMEOBJECT_TYPE_CHEST: return chest.lootId; - case GAMEOBJECT_TYPE_FISHINGHOLE: return fishinghole.lootId; - default: return 0; - } - } - - uint32 GetGossipMenuId() const - { - switch (type) - { - case GAMEOBJECT_TYPE_QUESTGIVER: return questgiver.gossipID; - case GAMEOBJECT_TYPE_GOOBER: return goober.gossipID; - default: return 0; - } - } - - bool IsLargeGameObject() const - { - switch (type) - { - case GAMEOBJECT_TYPE_BUTTON: return button.large != 0; - case GAMEOBJECT_TYPE_QUESTGIVER: return questgiver.large != 0; - case GAMEOBJECT_TYPE_GENERIC: return _generic.large != 0; - case GAMEOBJECT_TYPE_TRAP: return trap.large != 0; - case GAMEOBJECT_TYPE_SPELL_FOCUS: return spellFocus.large != 0; - case GAMEOBJECT_TYPE_GOOBER: return goober.large != 0; - case GAMEOBJECT_TYPE_TRANSPORT: return true; - case GAMEOBJECT_TYPE_SPELLCASTER: return spellcaster.large != 0; - case GAMEOBJECT_TYPE_CAPTURE_POINT: return capturePoint.large != 0; - default: return false; - } - } - - bool IsServerOnly() const - { - switch (type) - { - case GAMEOBJECT_TYPE_GENERIC: return _generic.serverOnly; - case GAMEOBJECT_TYPE_TRAP: return trap.serverOnly; - case GAMEOBJECT_TYPE_SPELL_FOCUS: return spellFocus.serverOnly; - case GAMEOBJECT_TYPE_AURA_GENERATOR: return auraGenerator.serverOnly; - default: return false; - } - } -}; // GCC have alternative #pragma pack() syntax and old gcc version not support pack(pop), also any gcc version not support it at some platform #if defined( __GNUC__ ) diff --git a/src/game/Entities/Item.cpp b/src/game/Entities/Item.cpp index a4e0748e52..3d07bbeff8 100644 --- a/src/game/Entities/Item.cpp +++ b/src/game/Entities/Item.cpp @@ -93,7 +93,7 @@ void AddItemsSetItem(Player* player, Item* item) { if (!spell) // free slot { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(set->spells[x]); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(set->spells[x]); if (!spellInfo) { sLog.outError("WORLD: unknown spell id %u in items set %u effects", set->spells[x], setid); @@ -680,7 +680,7 @@ uint32 Item::GetSpell() const int32 Item::GenerateItemRandomPropertyId(uint32 item_id) { - ItemPrototype const* itemProto = sItemStorage.LookupEntry(item_id); + ItemPrototype const* itemProto = sItemStorage.LookupEntry(item_id); if (!itemProto) return 0; @@ -1024,7 +1024,7 @@ bool Item::GemsFitSockets() const uint32 gemid = enchantEntry->GemID; if (gemid) { - ItemPrototype const* gemProto = sItemStorage.LookupEntry(gemid); + ItemPrototype const* gemProto = sItemStorage.LookupEntry(gemid); if (gemProto) { GemPropertiesEntry const* gemProperty = sGemPropertiesStore.LookupEntry(gemProto->GemProperties); diff --git a/src/game/Entities/ItemEnchantmentMgr.cpp b/src/game/Entities/ItemEnchantmentMgr.cpp index 09bf9855e2..d70e7629da 100644 --- a/src/game/Entities/ItemEnchantmentMgr.cpp +++ b/src/game/Entities/ItemEnchantmentMgr.cpp @@ -126,7 +126,7 @@ uint32 GenerateEnchSuffixFactor(uint32 item_id) if (!itemProto->RandomSuffix) return 0; - RandomPropertiesPointsEntry const* randomProperty = sRandomPropertiesPointsStore.LookupEntry(itemProto->ItemLevel); + RandomPropertiesPointsEntry const* randomProperty = sRandPropPointsStore.LookupEntry(itemProto->ItemLevel); if (!randomProperty) return 0; diff --git a/src/game/Entities/ItemHandler.cpp b/src/game/Entities/ItemHandler.cpp index 3f45cb3a74..b7ab4c242c 100644 --- a/src/game/Entities/ItemHandler.cpp +++ b/src/game/Entities/ItemHandler.cpp @@ -353,7 +353,7 @@ void WorldSession::HandleItemQuerySingleOpcode(WorldPacket& recv_data) { // send DBC data for cooldowns in same way as it used in Spell::SendSpellCooldown // use `item_template` or if not set then only use spell cooldowns - SpellEntry const* spell = sSpellTemplate.LookupEntry(Spell.SpellId); + SpellEntry const* spell = sSpellTemplate.LookupEntry(Spell.SpellId); if (spell) { bool db_data = Spell.SpellCooldown >= 0 || Spell.SpellCategoryCooldown >= 0; diff --git a/src/game/Entities/MiscHandler.cpp b/src/game/Entities/MiscHandler.cpp index a70a4a02cf..d649c93afe 100644 --- a/src/game/Entities/MiscHandler.cpp +++ b/src/game/Entities/MiscHandler.cpp @@ -223,7 +223,7 @@ void WorldSession::HandleWhoOpcode(WorldPacket& recv_data) continue; std::string aname; - if (AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(pzoneid)) + if (AreaTableEntry const* areaEntry = TerrainManager::GetAreaEntryByAreaID(pzoneid)) aname = areaEntry->area_name[GetSessionDbcLocale()]; bool s_show = true; @@ -330,7 +330,7 @@ void WorldSession::HandleLogoutCancelOpcode(WorldPacket& /*recv_data*/) void WorldSession::HandleTogglePvP(WorldPacket& recv_data) { uint32 zoneId = GetPlayer()->GetZoneId(); - if (AreaTableEntry const* zone = GetAreaEntryByAreaID(zoneId)) + if (AreaTableEntry const* zone = TerrainManager::GetAreaEntryByAreaID(zoneId)) { if (zone->flags & AREA_FLAG_SANCTUARY) return; @@ -392,7 +392,7 @@ void WorldSession::HandleSetSelectionOpcode(WorldPacket& recv_data) _player->SetSelectionGuid(guid); - if (Unit* mover = _player->GetMover()) // when player has a mover and the mover is a + if (Unit* mover = _player->GetMover()) // when player has a mover and the mover is a if (mover != _player) mover->SetSelectionGuid(guid); @@ -714,7 +714,7 @@ void WorldSession::HandleAreaTriggerOpcode(WorldPacket& recv_data) const float delta = 5.0f; // check if player in the range of areatrigger - if (!IsPointInAreaTriggerZone(atEntry, player->GetMapId(), player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), delta)) + if (!Map::IsPointInAreaTriggerZone(atEntry, player->GetMapId(), player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), delta)) { DEBUG_LOG("Player '%s' (GUID: %u) too far, ignore Area Trigger ID: %u", player->GetName(), player->GetGUIDLow(), Trigger_ID); return; @@ -1057,7 +1057,7 @@ void WorldSession::HandleInspectOpcode(WorldPacket& recv_data) if (sWorld.getConfig(CONFIG_BOOL_TALENTS_INSPECTING) || _player->IsGameMaster()) { // find class talent tabs (all players have 3 talent tabs) - uint32 const* talentTabIds = GetTalentTabPages(plr->getClass()); + uint32 const* talentTabIds = ObjectMgr::GetTalentTabPages(plr->getClass()); uint32 talentTabPos = 0; // pos of first talent rank in tab including all prev tabs for (uint32 i = 0; i < 3; ++i) @@ -1065,12 +1065,8 @@ void WorldSession::HandleInspectOpcode(WorldPacket& recv_data) uint32 talentTabId = talentTabIds[i]; // fill by real data - for (uint32 talentId = 0; talentId < sTalentStore.GetNumRows(); ++talentId) + for (auto talentInfo : sTalentStore) { - TalentEntry const* talentInfo = sTalentStore.LookupEntry(talentId); - if (!talentInfo) - continue; - // skip another tab talents if (talentInfo->TalentTab != talentTabId) continue; @@ -1091,7 +1087,7 @@ void WorldSession::HandleInspectOpcode(WorldPacket& recv_data) continue; // 1 rank talent bit index - uint32 curtalent_index = talentTabPos + GetTalentInspectBitPosInTab(talentId); + uint32 curtalent_index = talentTabPos + ObjectMgr::GetTalentInspectBitPosInTab(talentInfo->TalentID); uint32 curtalent_rank_index = curtalent_index + curtalent_maxrank - 1; @@ -1112,7 +1108,7 @@ void WorldSession::HandleInspectOpcode(WorldPacket& recv_data) data.put(guid_size + 4 + curtalent_rank_slot, val & 0xFF); } - talentTabPos += GetTalentTabInspectBitSize(talentTabId); + talentTabPos += ObjectMgr::GetTalentTabInspectBitSize(talentTabId); } } diff --git a/src/game/Entities/NPCHandler.h b/src/game/Entities/NPCHandler.h index 1df8de9f6d..6cc0e22fab 100644 --- a/src/game/Entities/NPCHandler.h +++ b/src/game/Entities/NPCHandler.h @@ -26,14 +26,6 @@ #pragma pack(push,1) #endif -struct PageText -{ - uint32 Page_ID; - char* Text; - - uint32 Next_Page; -}; - // GCC have alternative #pragma pack() syntax and old gcc version not support pack(pop), also any gcc version not support it at some platform #if defined( __GNUC__ ) #pragma pack() diff --git a/src/game/Entities/Object.cpp b/src/game/Entities/Object.cpp index 5bb39500bf..3a9ed4ab32 100644 --- a/src/game/Entities/Object.cpp +++ b/src/game/Entities/Object.cpp @@ -2589,7 +2589,7 @@ bool WorldObject::IsSpellReady(SpellEntry const& spellEntry, ItemPrototype const bool WorldObject::IsSpellReady(uint32 spellId, ItemPrototype const* itemProto /*= nullptr*/) const { - SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(spellId); if (!spellEntry) return false; @@ -2666,7 +2666,7 @@ void WorldObject::LockOutSpells(SpellSchoolMask schoolMask, uint32 duration) void WorldObject::RemoveSpellCooldown(uint32 spellId, bool updateClient /*= true*/) { - SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(spellId); if (!spellEntry) return; @@ -2916,8 +2916,8 @@ int32 WorldObject::CalculateSpellEffectValue(Unit const* target, SpellEntry cons if (damage) { - GtNPCManaCostScalerEntry const* spellScaler = sGtNPCManaCostScalerStore.LookupEntry(spellProto->spellLevel - 1); - GtNPCManaCostScalerEntry const* casterScaler = sGtNPCManaCostScalerStore.LookupEntry(unitCaster->getLevel() - 1); + GtNPCManaCostScalerEntry const* spellScaler = sgtNPCManaCostScalerStore.LookupEntry(spellProto->spellLevel - 1); + GtNPCManaCostScalerEntry const* casterScaler = sgtNPCManaCostScalerStore.LookupEntry(unitCaster->getLevel() - 1); if (spellScaler && casterScaler) value *= casterScaler->ratio / spellScaler->ratio; } diff --git a/src/game/Entities/ObjectVisibility.h b/src/game/Entities/ObjectVisibility.h index 59263d8193..5b1557a2e6 100644 --- a/src/game/Entities/ObjectVisibility.h +++ b/src/game/Entities/ObjectVisibility.h @@ -20,36 +20,11 @@ #define __OBJECT_VISIBILITY_H #include "Common.h" +#include "ObjectVisibilityDefines.h" class WorldObject; class Unit; -enum class VisibilityDistanceType : uint32 -{ - Normal = 0, - Tiny = 1, - Small = 2, - Large = 3, - Gigantic = 4, - Infinite = 5, - - Max -}; - -enum StealthType : uint32 -{ - STEALTH_UNIT = 0, - STEALTH_TRAP = 1, - STEALTH_TYPE_MAX, -}; - -enum InvisibilityType : uint32 -{ - INVISIBILITY_TRAP = 3, - INVISIBILITY_DRUNK = 6, - INVISIBILITY_TYPE_MAX = 32, -}; - class VisibilityData { public: diff --git a/src/game/Entities/ObjectVisibilityDefines.h b/src/game/Entities/ObjectVisibilityDefines.h new file mode 100644 index 0000000000..2935a3b2b3 --- /dev/null +++ b/src/game/Entities/ObjectVisibilityDefines.h @@ -0,0 +1,50 @@ +/* + * This file is part of the CMaNGOS Project. See AUTHORS file for Copyright information + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __OBJECT_VISIBILITY_DEFINES_H +#define __OBJECT_VISIBILITY_DEFINES_H + +#include "Common.h" + +enum class VisibilityDistanceType : uint32 +{ + Normal = 0, + Tiny = 1, + Small = 2, + Large = 3, + Gigantic = 4, + Infinite = 5, + + Max +}; + +enum StealthType : uint32 +{ + STEALTH_UNIT = 0, + STEALTH_TRAP = 1, + STEALTH_TYPE_MAX, +}; + +enum InvisibilityType : uint32 +{ + INVISIBILITY_TRAP = 3, + INVISIBILITY_DRUNK = 6, + INVISIBILITY_TYPE_MAX = 32, +}; + +#endif \ No newline at end of file diff --git a/src/game/Entities/Pet.cpp b/src/game/Entities/Pet.cpp index ed4d9c5458..b938695726 100644 --- a/src/game/Entities/Pet.cpp +++ b/src/game/Entities/Pet.cpp @@ -134,7 +134,7 @@ SpellCastResult Pet::TryLoadFromDB(Unit* owner, uint32 petentry /*= 0*/, uint32 return SPELL_FAILED_NO_PET; } - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(summon_spell_id); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(summon_spell_id); bool isTemporarySummoned = spellInfo && GetSpellDuration(spellInfo) > 0; @@ -207,7 +207,7 @@ bool Pet::LoadPetFromDB(Player* owner, uint32 petentry /*= 0*/, uint32 petnumber } uint32 summon_spell_id = fields[21].GetUInt32(); - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(summon_spell_id); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(summon_spell_id); if (permanentOnly && spellInfo && GetSpellDuration(spellInfo) > 0) { @@ -1049,7 +1049,7 @@ void Pet::Unsummon(PetSaveMode mode, Unit* owner /*= nullptr*/) { // returning of reagents only for players, so best done here uint32 spellId = GetUInt32Value(UNIT_CREATED_BY_SPELL); - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (spellInfo) { @@ -1568,7 +1568,7 @@ void Pet::_LoadSpellCooldowns() uint32 spell_id = fields[0].GetUInt32(); uint64 spell_time = fields[1].GetUInt64(); - SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(spell_id); + SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(spell_id); if (!spellEntry) { sLog.outError("%s has unknown spell %u in `character_spell_cooldown`, skipping.", GetGuidStr().c_str(), spell_id); @@ -1730,7 +1730,7 @@ void Pet::_LoadAuras(uint32 timediff) int32 remaintime = fields[12].GetInt32(); uint32 effIndexMask = fields[13].GetUInt32(); - SpellEntry const* spellproto = sSpellTemplate.LookupEntry(spellid); + SpellEntry const* spellproto = sSpellTemplate.LookupEntry(spellid); if (!spellproto) { sLog.outError("Unknown spell (spellid %u), ignore.", spellid); @@ -1885,7 +1885,7 @@ void Pet::_SaveAuras() bool Pet::addSpell(uint32 spell_id, ActiveStates active /*= ACT_DECIDE*/, PetSpellState state /*= PETSPELL_NEW*/, PetSpellType type /*= PETSPELL_NORMAL*/) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell_id); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell_id); if (!spellInfo) { // do pet spell book cleanup @@ -2069,7 +2069,7 @@ void Pet::InitPetCreateSpells() if (!CreateSpells->spellid[i]) break; - SpellEntry const* learn_spellproto = sSpellTemplate.LookupEntry(CreateSpells->spellid[i]); + SpellEntry const* learn_spellproto = sSpellTemplate.LookupEntry(CreateSpells->spellid[i]); if (!learn_spellproto) continue; diff --git a/src/game/Entities/PetHandler.cpp b/src/game/Entities/PetHandler.cpp index 5b7c2cd999..25bbe47818 100644 --- a/src/game/Entities/PetHandler.cpp +++ b/src/game/Entities/PetHandler.cpp @@ -295,7 +295,7 @@ void WorldSession::HandlePetAction(WorldPacket& recv_data) Unit* unit_target = targetGuid ? _player->GetMap()->GetUnit(targetGuid) : nullptr; // do not cast unknown spells - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellid); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellid); if (!spellInfo) { sLog.outError("WORLD: unknown PET spell id %i", spellid); @@ -816,7 +816,7 @@ void WorldSession::HandlePetCastSpellOpcode(WorldPacket& recvPacket) Creature* petCreature = petUnit->GetTypeId() == TYPEID_UNIT ? static_cast(petUnit) : nullptr; Pet* pet = (petCreature && petCreature->IsPet()) ? static_cast(petUnit) : nullptr; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellid); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellid); if (!spellInfo) { sLog.outError("WORLD: unknown PET spell id %i", spellid); diff --git a/src/game/Entities/Player.cpp b/src/game/Entities/Player.cpp index 8fc21eba63..b99e814e15 100644 --- a/src/game/Entities/Player.cpp +++ b/src/game/Entities/Player.cpp @@ -58,7 +58,6 @@ #include "DBScripts/ScriptMgr.h" #include "Social/SocialMgr.h" #include "Mails/Mail.h" -#include "Server/DBCStores.h" #include "Server/SQLStorages.h" #include "Loot/LootMgr.h" #include "World/WorldStateDefines.h" @@ -351,7 +350,7 @@ SpellModifier::SpellModifier(SpellModOp _op, SpellModType _type, int32 _value, A bool SpellModifier::isAffectedOnSpell(SpellEntry const* spell) const { - SpellEntry const* affect_spell = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* affect_spell = sSpellTemplate.LookupEntry(spellId); // False if affect_spell == nullptr or spellFamily not equal if (!affect_spell || affect_spell->SpellFamilyName != spell->SpellFamilyName) return false; @@ -832,15 +831,12 @@ bool Player::Create(uint32 guidlow, const std::string& name, uint8 race, uint8 c uint32 raceClassGender = GetUInt32Value(UNIT_FIELD_BYTES_0) & 0x00FFFFFF; CharStartOutfitEntry const* oEntry = nullptr; - for (uint32 i = 1; i < sCharStartOutfitStore.GetNumRows(); ++i) + for (auto entry : sCharStartOutfitStore) { - if (CharStartOutfitEntry const* entry = sCharStartOutfitStore.LookupEntry(i)) + if (entry->RaceClassGender == raceClassGender) { - if (entry->RaceClassGender == raceClassGender) - { - oEntry = entry; - break; - } + oEntry = entry; + break; } } @@ -1715,7 +1711,7 @@ bool Player::BuildEnumData(QueryResult* result, WorldPacket& p_data) if (result && !(playerFlags & PLAYER_FLAGS_GHOST) && (pClass == CLASS_WARLOCK || pClass == CLASS_HUNTER)) { uint32 entry = fields[16].GetUInt32(); - CreatureInfo const* cInfo = sCreatureStorage.LookupEntry(entry); + CreatureInfo const* cInfo = sCreatureStorage.LookupEntry(entry); if (cInfo) { petDisplayId = fields[17].GetUInt32(); @@ -3115,7 +3111,7 @@ static inline bool IsUnlearnSpellsPacketNeededForSpell(uint32 spellId) bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependent, bool disabled) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell_id); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell_id); if (!spellInfo) { // do character spell book cleanup (all characters) @@ -3250,7 +3246,7 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen } } - TalentSpellPos const* talentPos = GetTalentSpellPos(spell_id); + TalentSpellPos const* talentPos = ObjectMgr::GetTalentSpellPos(spell_id); if (!disabled_case) // skip new spell adding if spell already known (disabled spells case) { @@ -3277,11 +3273,8 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen { // Check if a spell is learned by a talent first bool talent = false; - for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i) + for (auto talentInfo : sTalentStore) { - TalentEntry const* talentInfo = sTalentStore.LookupEntry(i); - if (!talentInfo) - continue; TalentTabEntry const* talentTabInfo = sTalentTabStore.LookupEntry(talentInfo->TalentTab); if (!talentTabInfo || !(getClassMask() & talentTabInfo->ClassMask)) continue; @@ -3380,7 +3373,7 @@ bool Player::addSpell(uint32 spell_id, bool active, bool learning, bool dependen if (talentPos) { // update used talent points count - m_usedTalentCount += GetTalentSpellCost(talentPos); + m_usedTalentCount += ObjectMgr::GetTalentSpellCost(talentPos); UpdateFreeTalentPoints(false); } @@ -3499,13 +3492,13 @@ void Player::removeSpell(uint32 spell_id, bool disabled, bool learn_low_rank, bo if (playerSpell.state == PLAYERSPELL_REMOVED || (disabled && playerSpell.disabled)) return; - if (disabled && GetTalentSpellPos(spell_id)) + if (disabled && ObjectMgr::GetTalentSpellPos(spell_id)) disabled = false; // talents should never be marked as disabled // unlearn non talent higher ranks (recursive) SpellChainMapNext const& nextMap = sSpellMgr.GetSpellChainNext(); for (SpellChainMapNext::const_iterator itr2 = nextMap.lower_bound(spell_id); itr2 != nextMap.upper_bound(spell_id); ++itr2) - if (HasSpell(itr2->second) && !GetTalentSpellPos(itr2->second)) + if (HasSpell(itr2->second) && !ObjectMgr::GetTalentSpellPos(itr2->second)) removeSpell(itr2->second, !IsPassiveSpell(itr2->second), false, sendUpdate); // re-search, it can be corrupted in prev loop @@ -3537,11 +3530,11 @@ void Player::removeSpell(uint32 spell_id, bool disabled, bool learn_low_rank, bo if (PetAura const* petSpell = sSpellMgr.GetPetAura(spell_id)) RemovePetAura(petSpell); - TalentSpellPos const* talentPos = GetTalentSpellPos(spell_id); + TalentSpellPos const* talentPos = ObjectMgr::GetTalentSpellPos(spell_id); if (talentPos) { // free talent points - uint32 talentCosts = GetTalentSpellCost(talentPos); + uint32 talentCosts = ObjectMgr::GetTalentSpellCost(talentPos); if (talentCosts < m_usedTalentCount) m_usedTalentCount -= talentCosts; @@ -3610,7 +3603,7 @@ void Player::removeSpell(uint32 spell_id, bool disabled, bool learn_low_rank, bo // for shaman Dual-wield if (CanDualWield()) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell_id); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell_id); if (IsSpellHaveEffect(spellInfo, SPELL_EFFECT_DUAL_WIELD)) SetCanDualWield(false); @@ -3655,7 +3648,7 @@ void Player::_LoadSpellCooldowns(QueryResult* result) uint64 cat_time = fields[3].GetUInt64(); uint32 item_id = fields[4].GetUInt32(); - SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(spell_id); + SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(spell_id); if (!spellEntry) { sLog.outError("%s has unknown spell %u in `character_spell_cooldown`, skipping.", GetGuidStr().c_str(), spell_id); @@ -3787,13 +3780,8 @@ bool Player::resetTalents(bool no_cost) } } - for (unsigned int i = 0; i < sTalentStore.GetNumRows(); ++i) + for (auto talentInfo : sTalentStore) { - TalentEntry const* talentInfo = sTalentStore.LookupEntry(i); - - if (!talentInfo) - continue; - TalentTabEntry const* talentTabInfo = sTalentTabStore.LookupEntry(talentInfo->TalentTab); if (!talentTabInfo) @@ -4129,7 +4117,7 @@ TrainerSpellState Player::GetTrainerSpellState(TrainerSpell const* trainer_spell return TRAINER_SPELL_RED; // exist, already checked at loading - SpellEntry const* spell = sSpellTemplate.LookupEntry(trainer_spell->learnedSpell); + SpellEntry const* spell = sSpellTemplate.LookupEntry(trainer_spell->learnedSpell); // secondary prof. or not prof. spell uint32 skill = spell->EffectMiscValue[1]; @@ -4247,7 +4235,7 @@ void Player::DeleteFromDB(ObjectGuid playerguid, uint32 accountId, bool updateRe if (has_items) { // data needs to be at first place for Item::LoadFromDB - // 0 1 2 3 4 5 6 7 8 9 10 11 12 + // 0 1 2 3 4 5 6 7 8 9 10 11 12 QueryResult* resultItems = CharacterDatabase.PQuery("SELECT itemEntry, creatorGuid, giftCreatorGuid, count, duration, charges, flags, enchantments, randomPropertyId, durability, itemTextId, item_guid, item_template FROM mail_items JOIN item_instance ON item_guid = guid WHERE mail_id='%u'", mail_id); if (resultItems) { @@ -4963,7 +4951,7 @@ void Player::RepopAtGraveyard() // note: this can be called also when the player is alive // for example from WorldSession::HandleMovementOpcodes - AreaTableEntry const* zone = GetAreaEntryByAreaID(GetAreaId()); + AreaTableEntry const* zone = TerrainManager::GetAreaEntryByAreaID(GetAreaId()); // Such zones are considered unreachable as a ghost and the player must be automatically revived if ((!IsAlive() && zone && zone->flags & AREA_FLAG_NEED_FLY) || GetTransport()) @@ -5026,7 +5014,7 @@ void Player::UpdateLocalChannels(uint32 newZone) if (m_channels.empty()) return; - AreaTableEntry const* current_zone = GetAreaEntryByAreaID(newZone); + AreaTableEntry const* current_zone = TerrainManager::GetAreaEntryByAreaID(newZone); if (!current_zone) return; @@ -5171,8 +5159,8 @@ float Player::GetMeleeCritFromAgility() const if (level > GT_MAX_LEVEL) level = GT_MAX_LEVEL; - GtChanceToMeleeCritBaseEntry const* critBase = sGtChanceToMeleeCritBaseStore.LookupEntry(pclass - 1); - GtChanceToMeleeCritEntry const* critRatio = sGtChanceToMeleeCritStore.LookupEntry((pclass - 1) * GT_MAX_LEVEL + level - 1); + GtChanceToMeleeCritBaseEntry const* critBase = sgtChanceToMeleeCritBaseStore.LookupEntry(pclass - 1); + GtChanceToMeleeCritEntry const* critRatio = sgtChanceToMeleeCritStore.LookupEntry((pclass - 1) * GT_MAX_LEVEL + level - 1); if (critBase == nullptr || critRatio == nullptr) return 0.0f; @@ -5206,7 +5194,7 @@ float Player::GetDodgeFromAgility(float amount) const const uint32 index = ((pclass - 1) * GT_MAX_LEVEL) + (level - 1); // Dodge per agility is proportional to crit per agility, which is available from DBC files - const GtChanceToMeleeCritEntry* entry = sGtChanceToMeleeCritStore.LookupEntry(index); + const GtChanceToMeleeCritEntry* entry = sgtChanceToMeleeCritStore.LookupEntry(index); if (!entry) return 0.0f; return (100.0f * amount * entry->ratio * PLAYER_AGI_TO_CRIT_TO_DODGE[pclass]); @@ -5219,8 +5207,8 @@ float Player::GetSpellCritFromIntellect() const if (level > GT_MAX_LEVEL) level = GT_MAX_LEVEL; - GtChanceToSpellCritBaseEntry const* critBase = sGtChanceToSpellCritBaseStore.LookupEntry(pclass - 1); - GtChanceToSpellCritEntry const* critRatio = sGtChanceToSpellCritStore.LookupEntry((pclass - 1) * GT_MAX_LEVEL + level - 1); + GtChanceToSpellCritBaseEntry const* critBase = sgtChanceToSpellCritBaseStore.LookupEntry(pclass - 1); + GtChanceToSpellCritEntry const* critRatio = sgtChanceToSpellCritStore.LookupEntry((pclass - 1) * GT_MAX_LEVEL + level - 1); if (critBase == nullptr || critRatio == nullptr) return 0.0f; @@ -5234,7 +5222,7 @@ float Player::GetRatingMultiplier(CombatRating cr) const if (level > GT_MAX_LEVEL) level = GT_MAX_LEVEL; - GtCombatRatingsEntry const* Rating = sGtCombatRatingsStore.LookupEntry(cr * GT_MAX_LEVEL + level - 1); + GtCombatRatingsEntry const* Rating = sgtCombatRatingsStore.LookupEntry(cr * GT_MAX_LEVEL + level - 1); if (!Rating) return 1.0f; // By default use minimum coefficient (not must be called) @@ -5440,7 +5428,7 @@ bool Player::UpdateCraftSkill(uint32 spellid) uint32 SkillValue = GetSkillValuePure(skill->skillId); // Alchemy Discoveries here - SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(spellid); + SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(spellid); if (spellEntry && spellEntry->Mechanic == MECHANIC_DISCOVERY) { if (uint32 discoveredSpell = GetSkillDiscoverySpell(skill->skillId, spellid, this)) @@ -6203,7 +6191,7 @@ bool Player::IsActionButtonDataValid(uint8 button, uint32 action, uint8 type, Pl { case ACTION_BUTTON_SPELL: { - SpellEntry const* spellProto = sSpellTemplate.LookupEntry(action); + SpellEntry const* spellProto = sSpellTemplate.LookupEntry(action); if (!spellProto) { if (player) @@ -6419,7 +6407,7 @@ void Player::CheckAreaExploreAndOutdoor() if (HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING) && GetRestType() == REST_TYPE_IN_TAVERN) { AreaTriggerEntry const* at = sAreaTriggerStore.LookupEntry(inn_trigger_id); - if (!at || !IsPointInAreaTriggerZone(at, GetMapId(), GetPositionX(), GetPositionY(), GetPositionZ())) + if (!at || !Map::IsPointInAreaTriggerZone(at, GetMapId(), GetPositionX(), GetPositionY(), GetPositionZ())) { // Player left inn (REST_TYPE_IN_CITY overrides REST_TYPE_IN_TAVERN, so just clear rest) SetRestType(REST_TYPE_NO); @@ -6431,7 +6419,7 @@ void Player::CheckAreaExploreAndOutdoor() { if (itr.second.state == PLAYERSPELL_REMOVED) continue; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(itr.first); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(itr.first); if (!spellInfo || !IsNeedCastSpellAtOutdoor(spellInfo) || HasAura(itr.first)) continue; if ((spellInfo->Stances || spellInfo->StancesNot) && !IsNeedCastSpellAtFormApply(spellInfo, GetShapeshiftForm())) @@ -6459,7 +6447,7 @@ void Player::CheckAreaExploreAndOutdoor() { SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields | val)); - AreaTableEntry const* p = GetAreaEntryByAreaFlagAndMap(areaFlag, GetMapId()); + AreaTableEntry const* p = TerrainManager::GetAreaEntryByAreaFlagAndMap(areaFlag, GetMapId()); if (!p) { sLog.outError("PLAYER: Player %u discovered unknown area (x: %f y: %f map: %u", GetGUIDLow(), GetPositionX(), GetPositionY(), GetMapId()); @@ -6541,7 +6529,7 @@ void Player::setFactionForRace(uint8 race) ReputationRank Player::GetReputationRank(uint32 faction) const { - FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction); + FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction); return GetReputationMgr().GetRank(factionEntry); } @@ -6616,7 +6604,7 @@ int32 Player::CalculateReputationGain(ReputationSource source, int32 rep, int32 if (source == REPUTATION_SOURCE_QUEST && result && faction) { - if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction)) + if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction)) { int32 current = GetReputationMgr().GetReputation(factionEntry); @@ -6651,7 +6639,7 @@ void Player::RewardReputation(Creature* victim, float rate) { int32 donerep1 = CalculateReputationGain(REPUTATION_SOURCE_KILL, Rep->repvalue1, 0, Rep->repfaction1, victim->getLevel()); donerep1 = int32(donerep1 * rate); - FactionEntry const* factionEntry1 = sFactionStore.LookupEntry(Rep->repfaction1); + FactionEntry const* factionEntry1 = sFactionStore.LookupEntry(Rep->repfaction1); uint32 current_reputation_rank1 = GetReputationMgr().GetRank(factionEntry1); if (factionEntry1 && current_reputation_rank1 <= Rep->reputation_max_cap1) GetReputationMgr().ModifyReputation(factionEntry1, donerep1); @@ -6659,7 +6647,7 @@ void Player::RewardReputation(Creature* victim, float rate) // Wiki: Team factions value divided by 2 if (factionEntry1 && Rep->is_teamaward1) { - FactionEntry const* team1_factionEntry = sFactionStore.LookupEntry(factionEntry1->team); + FactionEntry const* team1_factionEntry = sFactionStore.LookupEntry(factionEntry1->team); if (team1_factionEntry) GetReputationMgr().ModifyReputation(team1_factionEntry, donerep1 / 2); } @@ -6669,7 +6657,7 @@ void Player::RewardReputation(Creature* victim, float rate) { int32 donerep2 = CalculateReputationGain(REPUTATION_SOURCE_KILL, Rep->repvalue2, 0, Rep->repfaction2, victim->getLevel()); donerep2 = int32(donerep2 * rate); - FactionEntry const* factionEntry2 = sFactionStore.LookupEntry(Rep->repfaction2); + FactionEntry const* factionEntry2 = sFactionStore.LookupEntry(Rep->repfaction2); uint32 current_reputation_rank2 = GetReputationMgr().GetRank(factionEntry2); if (factionEntry2 && current_reputation_rank2 <= Rep->reputation_max_cap2) GetReputationMgr().ModifyReputation(factionEntry2, donerep2); @@ -6677,7 +6665,7 @@ void Player::RewardReputation(Creature* victim, float rate) // Wiki: Team factions value divided by 2 if (factionEntry2 && Rep->is_teamaward2) { - FactionEntry const* team2_factionEntry = sFactionStore.LookupEntry(factionEntry2->team); + FactionEntry const* team2_factionEntry = sFactionStore.LookupEntry(factionEntry2->team); if (team2_factionEntry) GetReputationMgr().ModifyReputation(team2_factionEntry, donerep2 / 2); } @@ -6697,7 +6685,7 @@ void Player::RewardReputation(Quest const* pQuest) { int32 rep = CalculateReputationGain(REPUTATION_SOURCE_QUEST, pQuest->RewRepValue[i], pQuest->RewMaxRepValue[i], pQuest->RewRepFaction[i], GetQuestLevelForPlayer(pQuest)); - if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(pQuest->RewRepFaction[i])) + if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(pQuest->RewRepFaction[i])) GetReputationMgr().ModifyReputation(factionEntry, rep); } } @@ -6990,7 +6978,7 @@ void Player::UpdateArea(uint32 newArea) { m_areaUpdateId = newArea; - AreaTableEntry const* area = GetAreaEntryByAreaID(newArea); + AreaTableEntry const* area = TerrainManager::GetAreaEntryByAreaID(newArea); // FFA_PVP flags are area and not zone id dependent // so apply them accordingly @@ -7023,7 +7011,7 @@ bool Player::CanUseCapturePoint() const void Player::UpdateZone(uint32 newZone, uint32 newArea, bool force) { - AreaTableEntry const* zone = GetAreaEntryByAreaID(newZone); + AreaTableEntry const* zone = TerrainManager::GetAreaEntryByAreaID(newZone); if (!zone) return; @@ -7582,7 +7570,7 @@ void Player::ApplyItemEquipSpell(Item* item, bool apply, bool form_change) } // check if it is valid spell - SpellEntry const* spellproto = sSpellTemplate.LookupEntry(spellData.SpellId); + SpellEntry const* spellproto = sSpellTemplate.LookupEntry(spellData.SpellId); if (!spellproto) continue; @@ -7757,7 +7745,7 @@ void Player::CastItemCombatSpell(Unit* Target, WeaponAttackType attType, bool sp if (spellData.SpellTrigger != ITEM_SPELLTRIGGER_CHANCE_ON_HIT) continue; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellData.SpellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellData.SpellId); if (!spellInfo) { sLog.outError("WORLD: unknown Item spellid %i", spellData.SpellId); @@ -7801,7 +7789,7 @@ void Player::CastItemCombatSpell(Unit* Target, WeaponAttackType attType, bool sp if (pEnchant->type[s] != ITEM_ENCHANTMENT_TYPE_COMBAT_SPELL) continue; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(proc_spell_id); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(proc_spell_id); if (!spellInfo) { sLog.outError("Player::CastItemCombatSpell Enchant %i, cast unknown spell %i", pEnchant->ID, proc_spell_id); @@ -7847,7 +7835,7 @@ void Player::CastItemUseSpell(Item* item, SpellCastTargets& targets, uint8 cast_ uint32 learn_spell_id = proto->Spells[0].SpellId; uint32 learning_spell_id = proto->Spells[1].SpellId; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(learn_spell_id); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(learn_spell_id); if (!spellInfo) { sLog.outError("Player::CastItemUseSpell: Item (Entry: %u) in have wrong spell id %u, ignoring ", proto->ItemId, learn_spell_id); @@ -7882,7 +7870,7 @@ void Player::CastItemUseSpell(Item* item, SpellCastTargets& targets, uint8 cast_ if (i != spell_index) continue; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellData.SpellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellData.SpellId); if (!spellInfo) { sLog.outError("Player::CastItemUseSpell: Item (Entry: %u) in have wrong spell id %u, ignoring", proto->ItemId, spellData.SpellId); @@ -8308,7 +8296,7 @@ uint8 Player::FindEquipSlot(ItemPrototype const* proto, uint32 slot, bool swap) // in both scenarios, a swap is required if (currentSlot == EQUIPMENT_SLOT_OFFHAND && (IsTwoHandUsed() || proto->InventoryType == INVTYPE_2HWEAPON)) continue; - + return currentSlot; } } @@ -9017,6 +9005,26 @@ InventoryResult Player::_CanTakeMoreSimilarItems(uint32 entry, uint32 count, Ite return EQUIP_ERR_OK; } +bool Player::IsTotemCategoryCompatiableWith(uint32 itemTotemCategoryId, uint32 requiredTotemCategoryId) +{ + if (requiredTotemCategoryId == 0) + return true; + if (itemTotemCategoryId == 0) + return false; + + TotemCategoryEntry const* itemEntry = sTotemCategoryStore.LookupEntry(itemTotemCategoryId); + if (!itemEntry) + return false; + TotemCategoryEntry const* reqEntry = sTotemCategoryStore.LookupEntry(requiredTotemCategoryId); + if (!reqEntry) + return false; + + if (itemEntry->categoryType != reqEntry->categoryType) + return false; + + return (itemEntry->categoryMask & reqEntry->categoryMask) == reqEntry->categoryMask; +} + bool Player::HasItemTotemCategory(uint32 TotemCategory) const { Item* pItem; @@ -10517,7 +10525,7 @@ Item* Player::EquipItem(uint16 pos, Item* pItem, bool update) if (getClass() == CLASS_ROGUE) cooldownSpell = SPELL_ID_WEAPON_SWITCH_COOLDOWN_1_0s; - SpellEntry const* spellProto = sSpellTemplate.LookupEntry(cooldownSpell); + SpellEntry const* spellProto = sSpellTemplate.LookupEntry(cooldownSpell); if (!spellProto) sLog.outError("Weapon switch cooldown spell %u couldn't be found in Spell.dbc", cooldownSpell); @@ -13160,7 +13168,7 @@ void Player::AddQuest(Quest const* pQuest, Object* questGiver) } if (pQuest->GetRepObjectiveFaction()) - if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(pQuest->GetRepObjectiveFaction())) + if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(pQuest->GetRepObjectiveFaction())) GetReputationMgr().SetVisible(factionEntry); uint32 qtime = 0; @@ -13412,7 +13420,7 @@ void Player::RewardQuest(Quest const* pQuest, uint32 reward, Object* questGiver, if (spellId) { - if (SpellEntry const* spellProto = sSpellTemplate.LookupEntry(spellId)) + if (SpellEntry const* spellProto = sSpellTemplate.LookupEntry(spellId)) { Unit* caster = this; @@ -14470,11 +14478,11 @@ void Player::ReputationChanged(FactionEntry const* factionEntry) case FACTION_STORMPIKE_GUARD: case FACTION_SILVERWING_SENTINELS: { - FactionEntry const* factionEntryArathor = sFactionStore.LookupEntry(FACTION_LEAGUE_OF_ARATHOR); + FactionEntry const* factionEntryArathor = sFactionStore.LookupEntry(FACTION_LEAGUE_OF_ARATHOR); if (repMgr.GetRank(factionEntryArathor) < REP_EXALTED) break; - FactionEntry const* factionEntryStormpike = sFactionStore.LookupEntry(FACTION_STORMPIKE_GUARD); + FactionEntry const* factionEntryStormpike = sFactionStore.LookupEntry(FACTION_STORMPIKE_GUARD); if (repMgr.GetRank(factionEntryStormpike) < REP_EXALTED) break; - FactionEntry const* factionEntrySentinels = sFactionStore.LookupEntry(FACTION_SILVERWING_SENTINELS); + FactionEntry const* factionEntrySentinels = sFactionStore.LookupEntry(FACTION_SILVERWING_SENTINELS); if (repMgr.GetRank(factionEntrySentinels) < REP_EXALTED) break; SetTitle(TITLE_JUSTICAR); break; @@ -14483,11 +14491,11 @@ void Player::ReputationChanged(FactionEntry const* factionEntry) case FACTION_FROSTWOLF_CLAN: case FACTION_WARSONG_OUTRIDERS: { - FactionEntry const* factionEntryDefilers = sFactionStore.LookupEntry(FACTION_DEFILERS); + FactionEntry const* factionEntryDefilers = sFactionStore.LookupEntry(FACTION_DEFILERS); if (repMgr.GetRank(factionEntryDefilers) < REP_EXALTED) break; - FactionEntry const* factionEntryFrostwolf = sFactionStore.LookupEntry(FACTION_FROSTWOLF_CLAN); + FactionEntry const* factionEntryFrostwolf = sFactionStore.LookupEntry(FACTION_FROSTWOLF_CLAN); if (repMgr.GetRank(factionEntryFrostwolf) < REP_EXALTED) break; - FactionEntry const* factionEntryWarsong = sFactionStore.LookupEntry(FACTION_WARSONG_OUTRIDERS); + FactionEntry const* factionEntryWarsong = sFactionStore.LookupEntry(FACTION_WARSONG_OUTRIDERS); if (repMgr.GetRank(factionEntryWarsong) < REP_EXALTED) break; SetTitle(TITLE_CONQUEROR); break; @@ -15150,7 +15158,7 @@ bool Player::LoadFromDB(ObjectGuid guid, SqlQueryHolder* holder) ObjectGuid guid(HIGHGUID_MO_TRANSPORT, transGUID); if (GameObjectData const* data = sObjectMgr.GetGOData(transGUID)) { - GameObjectInfo const* transportInfo = sGOStorage.LookupEntry(data->id); + GameObjectInfo const* transportInfo = sGOStorage.LookupEntry(data->id); if (transportInfo->type == GAMEOBJECT_TYPE_TRANSPORT) guid = ObjectGuid(HIGHGUID_GAMEOBJECT, data->id, transGUID); } @@ -15578,7 +15586,7 @@ void Player::_LoadAuras(QueryResult* result, uint32 timediff) int32 remaintime = fields[12].GetInt32(); uint32 effIndexMask = fields[13].GetUInt32(); - SpellEntry const* spellproto = sSpellTemplate.LookupEntry(spellid); + SpellEntry const* spellproto = sSpellTemplate.LookupEntry(spellid); if (!spellproto) { sLog.outError("Unknown spell (spellid %u), ignore.", spellid); @@ -16202,7 +16210,7 @@ void Player::_LoadSpells(QueryResult* result) uint32 spell_id = fields[0].GetUInt32(); bool active = fields[1].GetBool(); bool disabled = fields[2].GetBool(); - TalentSpellPos const* talentPos = GetTalentSpellPos(spell_id); + TalentSpellPos const* talentPos = ObjectMgr::GetTalentSpellPos(spell_id); if (!talentPos) spells.push_back(std::tuple{ spell_id, active, disabled }); else @@ -18963,7 +18971,7 @@ bool Player::EnchantmentFitsRequirements(uint32 enchantmentcondition, int8 slot) if (!gemid) continue; - ItemPrototype const* gemProto = sItemStorage.LookupEntry(gemid); + ItemPrototype const* gemProto = sItemStorage.LookupEntry(gemid); if (!gemProto) continue; @@ -19591,7 +19599,7 @@ void Player::ApplyEquipCooldown(Item* pItem) if (spellData.SpellTrigger != ITEM_SPELLTRIGGER_ON_USE) continue; - SpellEntry const* spellentry = sSpellTemplate.LookupEntry(spellData.SpellId); + SpellEntry const* spellentry = sSpellTemplate.LookupEntry(spellData.SpellId); if (!spellentry) continue; @@ -19645,7 +19653,7 @@ void Player::learnQuestRewardedSpells(Quest const* quest) if (!spell_id) return; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell_id); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell_id); if (!spellInfo) return; @@ -19673,7 +19681,7 @@ void Player::learnQuestRewardedSpells(Quest const* quest) if (!HasSpell(first_spell)) return; - SpellEntry const* learnedInfo = sSpellTemplate.LookupEntry(learned_0); + SpellEntry const* learnedInfo = sSpellTemplate.LookupEntry(learned_0); if (!learnedInfo) return; @@ -19686,7 +19694,7 @@ void Player::learnQuestRewardedSpells(Quest const* quest) if (itr->second.state == PLAYERSPELL_REMOVED || itr->first == learned_0) continue; - SpellEntry const* itrInfo = sSpellTemplate.LookupEntry(itr->first); + SpellEntry const* itrInfo = sSpellTemplate.LookupEntry(itr->first); if (!itrInfo) return; @@ -20432,7 +20440,7 @@ struct UpdateZoneDependentPetsHelper { if (unit->GetTypeId() == TYPEID_UNIT && ((Creature*)unit)->IsPet() && !((Pet*)unit)->isControlled()) if (uint32 spell_id = unit->GetUInt32Value(UNIT_CREATED_BY_SPELL)) - if (SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(spell_id)) + if (SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(spell_id)) if (sSpellMgr.GetSpellAllowedInLocationError(spellEntry, owner->GetMapId(), zone_id, area_id, owner) != SPELL_CAST_OK) ((Pet*)unit)->Unsummon(PET_SAVE_AS_DELETED, owner); } @@ -21169,23 +21177,18 @@ void Player::LearnTalent(uint32 talentId, uint32 talentRank) uint32 tTab = talentInfo->TalentTab; if (talentInfo->Row > 0) { - unsigned int numRows = sTalentStore.GetNumRows(); - for (unsigned int i = 0; i < numRows; ++i) // Loop through all talents. + for (auto tmpTalent : sTalentStore) // Loop through all talents. { // Someday, someone needs to revamp - const TalentEntry* tmpTalent = sTalentStore.LookupEntry(i); - if (tmpTalent) // the way talents are tracked + if (tmpTalent->TalentTab == tTab) { - if (tmpTalent->TalentTab == tTab) + for (int j = 0; j < MAX_TALENT_RANK; ++j) { - for (int j = 0; j < MAX_TALENT_RANK; ++j) + if (tmpTalent->RankID[j] != 0) { - if (tmpTalent->RankID[j] != 0) + if (HasSpell(tmpTalent->RankID[j])) { - if (HasSpell(tmpTalent->RankID[j])) - { - spentPoints += j + 1; - } + spentPoints += j + 1; } } } @@ -21807,7 +21810,7 @@ void Player::LockOutSpells(SpellSchoolMask schoolMask, uint32 duration) continue; uint32 unSpellId = ownerSpellItr.first; - SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(unSpellId); + SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(unSpellId); // Not send cooldown for this spells if (spellEntry->HasAttribute(SPELL_ATTR_DISABLED_WHILE_ACTIVE)) @@ -21843,7 +21846,7 @@ void Player::RemoveSpellLockout(SpellSchoolMask spellSchoolMask, std::set(unSpellId); + SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(unSpellId); // Not send cooldown for this spells if (!spellEntry || !(GetSpellSchoolMask(spellEntry) & spellSchoolMask) || spellEntry->HasAttribute(SPELL_ATTR_DISABLED_WHILE_ACTIVE)) diff --git a/src/game/Entities/Player.h b/src/game/Entities/Player.h index e8ebd865d6..68013bbc4b 100644 --- a/src/game/Entities/Player.h +++ b/src/game/Entities/Player.h @@ -1133,6 +1133,7 @@ class Player : public Unit InventoryResult CanUnequipItem(uint16 pos, bool swap) const; InventoryResult CanBankItem(uint8 bag, uint8 slot, ItemPosCountVec& dest, Item* pItem, bool swap, bool not_loading = true) const; InventoryResult CanUseItem(Item* pItem, bool direct_action = true) const; + static bool IsTotemCategoryCompatiableWith(uint32 itemTotemCategoryId, uint32 requiredTotemCategoryId); bool HasItemTotemCategory(uint32 TotemCategory) const; InventoryResult CanUseItem(ItemPrototype const* pProto) const; InventoryResult CanUseAmmo(uint32 item) const; @@ -2232,7 +2233,7 @@ class Player : public Unit auto spellCDItr = m_cooldownMap.begin(); while (spellCDItr != m_cooldownMap.end()) { - SpellEntry const* entry = sSpellTemplate.LookupEntry(spellCDItr->first); + SpellEntry const* entry = sSpellTemplate.LookupEntry(spellCDItr->first); if (entry && check(*entry)) { SendClearCooldown(spellCDItr->first, this); @@ -2569,7 +2570,7 @@ void RemoveItemsSetItem(Player* player, ItemPrototype const* proto); // "the bodies of template functions must be made available in a header file" template void Player::ApplySpellMod(uint32 spellId, SpellModOp op, T& basevalue, Spell const* spell, bool finalUse) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo || spellInfo->SpellFamilyName != GetSpellClass() || spellInfo->HasAttribute(SPELL_ATTR_EX3_NO_DONE_BONUS)) return; // client condition int32 totalpct = 100; int32 totalflat = 0; diff --git a/src/game/Entities/QueryHandler.cpp b/src/game/Entities/QueryHandler.cpp index d275a8c38f..58aec18231 100644 --- a/src/game/Entities/QueryHandler.cpp +++ b/src/game/Entities/QueryHandler.cpp @@ -417,7 +417,7 @@ void WorldSession::HandlePageTextQueryOpcode(WorldPacket& recv_data) while (pageID) { - PageText const* pPage = sPageTextStore.LookupEntry(pageID); + PageText const* pPage = sPageTextStore.LookupEntry(pageID); // guess size WorldPacket data(SMSG_PAGE_TEXT_QUERY_RESPONSE, 50); data << pageID; diff --git a/src/game/Entities/Relations.cpp b/src/game/Entities/Relations.cpp index 4d7f531bb6..2044a79cd8 100644 --- a/src/game/Entities/Relations.cpp +++ b/src/game/Entities/Relations.cpp @@ -180,7 +180,7 @@ static ReputationRank GetFactionReaction(FactionTemplateEntry const* thisTemplat if (!unit->HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_IGNORE_REPUTATION)) { - const FactionEntry* thisFactionEntry = sFactionStore.LookupEntry(thisTemplate->faction); + const FactionEntry* thisFactionEntry = sFactionStore.LookupEntry(thisTemplate->faction); if (thisFactionEntry && thisFactionEntry->HasReputation()) { const ReputationMgr& reputationMgr = unitPlayer->GetReputationMgr(); @@ -250,7 +250,7 @@ ReputationRank Unit::GetReactionTo(Unit const* unit) const if (const ReputationRank* rank = thisPlayer->GetReputationMgr().GetForcedRankIfAny(unitFactionTemplate)) return (*rank); - const FactionEntry* unitFactionEntry = sFactionStore.LookupEntry(unitFactionTemplate->faction); + const FactionEntry* unitFactionEntry = sFactionStore.LookupEntry(unitFactionTemplate->faction); // If the faction has reputation ranks available, "at war" and contested PVP flags decide outcome if (!this->HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_IGNORE_REPUTATION) && unitFactionEntry && unitFactionEntry->HasReputation()) @@ -271,7 +271,7 @@ ReputationRank Unit::GetReactionTo(Unit const* unit) const { if (const FactionTemplateEntry* unitFactionTemplate = unit->GetFactionTemplateEntry()) { - const FactionEntry* unitFactionEntry = sFactionStore.LookupEntry(unitFactionTemplate->faction); + const FactionEntry* unitFactionEntry = sFactionStore.LookupEntry(unitFactionTemplate->faction); if (unitFactionEntry && unitFactionEntry->HasReputation()) reaction = ReputationRank(int32(reaction) + 1); } @@ -1161,7 +1161,7 @@ bool Unit::CanAttackSpell(Unit const* target, SpellEntry const* spellInfo, bool { if (const FactionTemplateEntry* thisFactionTemplate = GetFactionTemplateEntry()) { - const FactionEntry* thisFactionEntry = sFactionStore.LookupEntry(thisFactionTemplate->faction); + const FactionEntry* thisFactionEntry = sFactionStore.LookupEntry(thisFactionTemplate->faction); if (thisFactionEntry && thisFactionEntry->HasReputation()) return unitPlayer->GetReputationMgr().IsAtWar(thisFactionEntry); } diff --git a/src/game/Entities/Totem.cpp b/src/game/Entities/Totem.cpp index 3a5c76ec79..76d799b792 100644 --- a/src/game/Entities/Totem.cpp +++ b/src/game/Entities/Totem.cpp @@ -159,7 +159,7 @@ void Totem::UnSummon() void Totem::SetTypeBySummonSpell(SpellEntry const* spellProto) { // Get spell casted by totem - SpellEntry const* totemSpell = sSpellTemplate.LookupEntry(GetSpell()); + SpellEntry const* totemSpell = sSpellTemplate.LookupEntry(GetSpell()); if (totemSpell) { // If spell have cast time -> so its active totem diff --git a/src/game/Entities/Unit.cpp b/src/game/Entities/Unit.cpp index 6763a7cc5f..c9dbb8053e 100644 --- a/src/game/Entities/Unit.cpp +++ b/src/game/Entities/Unit.cpp @@ -857,7 +857,7 @@ uint32 Unit::DealDamage(Unit* dealer, Unit* victim, uint32 damage, CleanDamage c } } } - + if (!damage) { // Rage from physical damage received - extend to all units @@ -1184,7 +1184,7 @@ void Unit::HandleDamageDealt(Unit* dealer, Unit* victim, uint32& damage, CleanDa for (auto aura : cleanupHolder) victim->RemoveAurasDueToSpell(aura); } - + if (dealer) dealer->InterruptOrDelaySpell(victim, damagetype); @@ -1278,7 +1278,7 @@ void Unit::JustKilledCreature(Unit* killer, Creature* victim, Player* responsibl } // Interrupt channeling spell when a Possessed Summoned is killed - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(victim->GetUInt32Value(UNIT_CREATED_BY_SPELL)); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(victim->GetUInt32Value(UNIT_CREATED_BY_SPELL)); if (spellInfo && spellInfo->HasAttribute(SPELL_ATTR_EX_FARSIGHT) && spellInfo->HasAttribute(SPELL_ATTR_EX_CHANNELED_1)) { Unit* creator = victim->GetMap()->GetUnit(victim->GetCreatorGuid()); @@ -1372,7 +1372,7 @@ void Unit::CastStop(uint32 except_spellid) SpellCastResult Unit::CastSpell(Unit* Victim, uint32 spellId, uint32 triggeredFlags, Item* castItem, Aura* triggeredByAura, ObjectGuid originalCaster, SpellEntry const* triggeredBy) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) { @@ -1426,7 +1426,7 @@ SpellCastResult Unit::CastSpell(Unit* Victim, SpellEntry const* spellInfo, uint3 SpellCastResult Unit::CastCustomSpell(Unit* Victim, uint32 spellId, int32 const* bp0, int32 const* bp1, int32 const* bp2, uint32 triggeredFlags, Item* castItem, Aura* triggeredByAura, ObjectGuid originalCaster, SpellEntry const* triggeredBy) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) { @@ -1489,7 +1489,7 @@ SpellCastResult Unit::CastCustomSpell(Unit* Victim, SpellEntry const* spellInfo, // used for scripting SpellCastResult Unit::CastSpell(float x, float y, float z, uint32 spellId, uint32 triggeredFlags, Item* castItem, Aura* triggeredByAura, ObjectGuid originalCaster, SpellEntry const* triggeredBy) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) { @@ -1611,7 +1611,7 @@ SpellCastResult Unit::CastCustomSpell(SpellCastTargets& targets, SpellEntry cons // Obsolete func need remove, here only for comotability vs another patches uint32 Unit::SpellNonMeleeDamageLog(Unit* pVictim, uint32 spellID, uint32 damage) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellID); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellID); SpellNonMeleeDamage spellDamageInfo(this, pVictim, spellInfo->Id, SpellSchoolMask(spellInfo->SchoolMask)); CalculateSpellDamage(&spellDamageInfo, damage, spellInfo); spellDamageInfo.target->CalculateAbsorbResistBlock(this, &spellDamageInfo, spellInfo); @@ -1695,7 +1695,7 @@ void Unit::DealSpellDamage(SpellNonMeleeDamage* spellDamageInfo, bool durability if (!pVictim->IsAlive() || pVictim->IsTaxiFlying() || pVictim->GetCombatManager().IsInEvadeMode()) return; - SpellEntry const* spellProto = sSpellTemplate.LookupEntry(spellDamageInfo->SpellID); + SpellEntry const* spellProto = sSpellTemplate.LookupEntry(spellDamageInfo->SpellID); if (spellProto == nullptr) { sLog.outError("Unit::DealSpellDamage have wrong damageInfo->SpellID: %u", spellDamageInfo->SpellID); @@ -2583,7 +2583,7 @@ void Unit::CalculateDamageAbsorbAndResist(Unit* caster, SpellSchoolMask schoolMa case 31229: case 31230: { - SpellEntry const* cheatDeath = sSpellTemplate.LookupEntry(31231); + SpellEntry const* cheatDeath = sSpellTemplate.LookupEntry(31231); CastSpell(this, cheatDeath, TRIGGERED_OLD_TRIGGERED); AddCooldown(*cheatDeath, nullptr, false, 60 * IN_MILLISECONDS); // TODO this may be removed by fixing cooldown value in spell template // with health > 10% lost health until health==10%, in other case no losses @@ -4920,7 +4920,7 @@ void Unit::AddAuraToModList(Aura* aura) void Unit::RemoveRankAurasDueToSpell(uint32 spellId) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) return; SpellAuraHolderMap::const_iterator next; @@ -5785,7 +5785,7 @@ void Unit::AddGameObject(GameObject* gameObj) if (gameObj->GetSpellId()) { - SpellEntry const* createBySpell = sSpellTemplate.LookupEntry(gameObj->GetSpellId()); + SpellEntry const* createBySpell = sSpellTemplate.LookupEntry(gameObj->GetSpellId()); // Need disable spell use for owner if (createBySpell && createBySpell->HasAttribute(SPELL_ATTR_DISABLED_WHILE_ACTIVE)) // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existing cases) @@ -5824,7 +5824,7 @@ void Unit::RemoveGameObject(GameObject* gameObj, bool del) if (GetTypeId() == TYPEID_PLAYER) { - SpellEntry const* createBySpell = sSpellTemplate.LookupEntry(spellid); + SpellEntry const* createBySpell = sSpellTemplate.LookupEntry(spellid); // Need activate spell use for owner if (createBySpell && createBySpell->HasAttribute(SPELL_ATTR_DISABLED_WHILE_ACTIVE)) // note: item based cooldowns and cooldown spell mods with charges ignored (unknown existing cases) @@ -6173,7 +6173,7 @@ void Unit::SendAttackStateUpdate(CalcDamageInfo* calcDamageInfo) const SendMessageToSet(data, true); } -void Unit::SendAttackStateUpdate(uint32 HitInfo, Unit* target, SpellSchoolMask damageSchoolMask, uint32 Damage, +void Unit::SendAttackStateUpdate(uint32 HitInfo, Unit* target, SpellSchoolMask damageSchoolMask, uint32 Damage, uint32 AbsorbDamage, int32 Resist, VictimState TargetState, uint32 BlockedAmount) { CalcDamageInfo dmgInfo; @@ -6242,7 +6242,7 @@ FactionTemplateEntry const* Unit::GetFactionTemplateEntry() const guid = GetObjectGuid(); if (guid.GetHigh() == HIGHGUID_PET) - sLog.outError("%s (base creature entry %u) have invalid faction template id %u, owner %s", + sLog.outError("%s (base creature entry %u) have invalid faction template id %u, owner %s", GetGuidStr().c_str(), GetEntry(), getFaction(), ((Pet*)this)->GetOwnerGuid().GetString().c_str()); else sLog.outError("%s have invalid faction template id %u", GetGuidStr().c_str(), getFaction()); @@ -6257,7 +6257,7 @@ bool Unit::IsNeutralToAll() const if (!my_faction || !my_faction->faction) return true; - FactionEntry const* raw_faction = sFactionStore.LookupEntry(my_faction->faction); + FactionEntry const* raw_faction = sFactionStore.LookupEntry(my_faction->faction); if (raw_faction && raw_faction->reputationListID >= 0) return false; @@ -6496,7 +6496,7 @@ void Unit::ModifyAuraState(AuraState flag, bool apply) for (const auto& itr : sp_list) { if (itr.second.state == PLAYERSPELL_REMOVED) continue; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(itr.first); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(itr.first); if (!spellInfo || !IsPassiveSpell(spellInfo)) continue; if (AuraState(spellInfo->CasterAuraState) == flag) CastSpell(this, itr.first, TRIGGERED_OLD_TRIGGERED, nullptr); @@ -7627,7 +7627,7 @@ bool Unit::IsImmuneToSpell(SpellEntry const* spellInfo, bool /*castOnSelf*/, uin return true; { - if (!spellInfo->HasAttribute(SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY) && + if (!spellInfo->HasAttribute(SPELL_ATTR_UNAFFECTED_BY_INVULNERABILITY) && !spellInfo->HasAttribute(SPELL_ATTR_EX_DISPEL_AURAS_ON_IMMUNITY)) { bool isPositive = IsPositiveEffectMask(spellInfo, effectMask); @@ -9911,7 +9911,7 @@ void CharmInfo::InitCharmCreateSpells() if (spellId == 2) // hardcoded spell id 2 attack - only for possesss continue; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (IsPassiveSpell(spellInfo)) { m_unit->CastSpell(m_unit, spellId, TRIGGERED_OLD_TRIGGERED); @@ -9922,7 +9922,7 @@ void CharmInfo::InitCharmCreateSpells() m_charmspells[x].SetActionAndType(spellId, ACT_DISABLED); ActiveStates newstate; - bool onlyselfcast = true; + bool onlyselfcast = true; for (uint32 i = 0; i < 3 && onlyselfcast; ++i) // nonexistent spell will not make any problems as onlyselfcast would be false -> break right away { @@ -10062,7 +10062,7 @@ void CharmInfo::LoadPetActionBar(const std::string& data) // check correctness if (PetActionBar[index].IsActionBarForSpell()) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(PetActionBar[index].GetAction()); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(PetActionBar[index].GetAction()); if (!spellInfo) SetActionBar(index, 0, ACT_DISABLED); else if (!IsAutocastable(spellInfo)) @@ -11238,7 +11238,7 @@ bool Unit::IsAllowedDamageInArea(Unit* pVictim) const return true; // can't damage player controlled unit by player controlled unit in sanctuary - AreaTableEntry const* area = GetAreaEntryByAreaID(pVictim->GetAreaId()); + AreaTableEntry const* area = TerrainManager::GetAreaEntryByAreaID(pVictim->GetAreaId()); return !(area && area->flags & AREA_FLAG_SANCTUARY); } @@ -11879,7 +11879,7 @@ void Unit::Uncharm(Unit* charmed, uint32 spellId) // if charm expires mid evade clear evade since movement is also cleared // TODO: maybe should be done on HomeMovementGenerator::MovementExpires - charmed->GetCombatManager().SetEvadeState(EVADE_NONE); + charmed->GetCombatManager().SetEvadeState(EVADE_NONE); if (charmed->GetTypeId() == TYPEID_UNIT) { @@ -11987,7 +11987,7 @@ void Unit::Uncharm(Unit* charmed, uint32 spellId) Position const& pos = charmInfo->GetCharmStartPosition(); if (!pos.IsEmpty()) static_cast(charmed)->SetCombatStartPosition(pos); - } + } } } else @@ -12135,8 +12135,8 @@ float Unit::OCTRegenHPPerSpirit() const if (level > GT_MAX_LEVEL) level = GT_MAX_LEVEL; - GtOCTRegenHPEntry const* baseRatio = sGtOCTRegenHPStore.LookupEntry((pclass - 1) * GT_MAX_LEVEL + level - 1); - GtRegenHPPerSptEntry const* moreRatio = sGtRegenHPPerSptStore.LookupEntry((pclass - 1) * GT_MAX_LEVEL + level - 1); + GtOCTRegenHPEntry const* baseRatio = sgtOCTRegenHPStore.LookupEntry((pclass - 1) * GT_MAX_LEVEL + level - 1); + GtRegenHPPerSptEntry const* moreRatio = sgtRegenHPPerSptStore.LookupEntry((pclass - 1) * GT_MAX_LEVEL + level - 1); if (baseRatio == nullptr || moreRatio == nullptr) return 0.0f; @@ -12157,7 +12157,7 @@ float Unit::OCTRegenMPPerSpirit() const if (level > GT_MAX_LEVEL) level = GT_MAX_LEVEL; // GtOCTRegenMPEntry const *baseRatio = sGtOCTRegenMPStore.LookupEntry((pclass-1)*GT_MAX_LEVEL + level-1); - GtRegenMPPerSptEntry const* moreRatio = sGtRegenMPPerSptStore.LookupEntry((pclass - 1) * GT_MAX_LEVEL + level - 1); + GtRegenMPPerSptEntry const* moreRatio = sgtRegenMPPerSptStore.LookupEntry((pclass - 1) * GT_MAX_LEVEL + level - 1); if (moreRatio == nullptr) return 0.0f; diff --git a/src/game/Entities/Unit.h b/src/game/Entities/Unit.h index 4fafa6b332..ae7dc2f732 100644 --- a/src/game/Entities/Unit.h +++ b/src/game/Entities/Unit.h @@ -188,8 +188,6 @@ enum UnitRename // byte flags value (UNIT_FIELD_BYTES_2,3) See enum ShapeshiftForm in SharedDefines.h -#define CREATURE_MAX_SPELLS 10 - enum Swing { NOSWING = 0, @@ -1995,7 +1993,7 @@ class Unit : public WorldObject void UpdateVisibilityAndView() override; // overwrite WorldObject::UpdateVisibilityAndView() // common function for visibility checks for player/creatures with detection code - bool IsVisibleForOrDetect(Unit const* u, WorldObject const* viewPoint, bool detect, bool inVisibleList = false, bool is3dDistance = true, bool spell = false) const; + bool IsVisibleForOrDetect(Unit const* u, WorldObject const* viewPoint, bool detect, bool inVisibleList = false, bool is3dDistance = true, bool spell = false) const; // virtual functions for all world objects types bool isVisibleForInState(Player const* u, WorldObject const* viewPoint, bool inVisibleList) const override; @@ -2336,7 +2334,7 @@ class Unit : public WorldObject uint32 GetDamageDoneByOthers() { return m_damageByOthers; } uint32 GetModifierXpBasedOnDamageReceived(uint32 xp); - + void OverrideMountDisplayId(uint32 newDisplayId); void UpdateSplinePosition(); diff --git a/src/game/GMTickets/GMTicketMgr.cpp b/src/game/GMTickets/GMTicketMgr.cpp index e1b0107c19..9cc3cd7cfa 100644 --- a/src/game/GMTickets/GMTicketMgr.cpp +++ b/src/game/GMTickets/GMTicketMgr.cpp @@ -350,7 +350,7 @@ void GMTicketMgr::LoadGMTickets() } BarGoLink bar(result->GetRowCount()); - + do { bar.step(); diff --git a/src/game/GameEvents/GameEventMgr.cpp b/src/game/GameEvents/GameEventMgr.cpp index 89bb92a7e9..adc385db9f 100644 --- a/src/game/GameEvents/GameEventMgr.cpp +++ b/src/game/GameEvents/GameEventMgr.cpp @@ -164,7 +164,7 @@ void GameEventMgr::LoadFromDB() gameEvent.start = time_t(FAR_FUTURE); gameEvent.occurence = gameEvent.length; } - + if (gameEvent.length == 0 && gameEvent.scheduleType != GAME_EVENT_SCHEDULE_SERVERSIDE) // length>0 is validity check { sLog.outErrorDb("`game_event` game event id (%i) have length 0 and can't be used.", event_id); @@ -474,13 +474,13 @@ void GameEventMgr::LoadFromDB() newData.entry_id = 0; } - if (newData.spell_id_start && !sSpellTemplate.LookupEntry(newData.spell_id_start)) + if (newData.spell_id_start && !sSpellTemplate.LookupEntry(newData.spell_id_start)) { sLog.outErrorDb("Table `game_event_creature_data` have creature (Guid: %u) with nonexistent spell_start %u, set to no start spell.", guid, newData.spell_id_start); newData.spell_id_start = 0; } - if (newData.spell_id_end && !sSpellTemplate.LookupEntry(newData.spell_id_end)) + if (newData.spell_id_end && !sSpellTemplate.LookupEntry(newData.spell_id_end)) { sLog.outErrorDb("Table `game_event_creature_data` have creature (Guid: %u) with nonexistent spell_end %u, set to no end spell.", guid, newData.spell_id_end); newData.spell_id_end = 0; diff --git a/src/game/Globals/Conditions.cpp b/src/game/Globals/Conditions.cpp index 305eb46326..b70ae06efa 100644 --- a/src/game/Globals/Conditions.cpp +++ b/src/game/Globals/Conditions.cpp @@ -118,7 +118,7 @@ bool ConditionEntry::Meets(WorldObject const* target, Map const* map, WorldObjec sLog.outErrorDb("CONDITION %u type %u used with bad parameters, called from %s, used with target: %s, map %i, source %s", m_entry, m_condition, conditionSourceToStr[conditionSourceType], target ? target->GetGuidStr().c_str() : "", map ? map->GetId() : -1, source ? source->GetGuidStr().c_str() : ""); return false; - } + } bool result = Evaluate(target, map, source, conditionSourceType); @@ -136,28 +136,28 @@ bool inline ConditionEntry::Evaluate(WorldObject const* target, Map const* map, case CONDITION_NOT: { // Checked on load - return !sConditionStorage.LookupEntry(m_value1)->Meets(target, map, source, conditionSourceType); + return !sConditionStorage.LookupEntry(m_value1)->Meets(target, map, source, conditionSourceType); } case CONDITION_OR: { // Third and fourth condition are optional - if (m_value3 && sConditionStorage.LookupEntry(m_value3)->Meets(target, map, source, conditionSourceType)) + if (m_value3 && sConditionStorage.LookupEntry(m_value3)->Meets(target, map, source, conditionSourceType)) return true; - if (m_value4 && sConditionStorage.LookupEntry(m_value4)->Meets(target, map, source, conditionSourceType)) + if (m_value4 && sConditionStorage.LookupEntry(m_value4)->Meets(target, map, source, conditionSourceType)) return true; - - return sConditionStorage.LookupEntry(m_value1)->Meets(target, map, source, conditionSourceType) || sConditionStorage.LookupEntry(m_value2)->Meets(target, map, source, conditionSourceType); + + return sConditionStorage.LookupEntry(m_value1)->Meets(target, map, source, conditionSourceType) || sConditionStorage.LookupEntry(m_value2)->Meets(target, map, source, conditionSourceType); } case CONDITION_AND: { // Third and fourth condition are optional bool extraConditionsSatisfied = true; if (m_value3) - extraConditionsSatisfied = extraConditionsSatisfied && sConditionStorage.LookupEntry(m_value3)->Meets(target, map, source, conditionSourceType); + extraConditionsSatisfied = extraConditionsSatisfied && sConditionStorage.LookupEntry(m_value3)->Meets(target, map, source, conditionSourceType); if (m_value4) - extraConditionsSatisfied = extraConditionsSatisfied && sConditionStorage.LookupEntry(m_value4)->Meets(target, map, source, conditionSourceType); + extraConditionsSatisfied = extraConditionsSatisfied && sConditionStorage.LookupEntry(m_value4)->Meets(target, map, source, conditionSourceType); - return extraConditionsSatisfied && sConditionStorage.LookupEntry(m_value1)->Meets(target, map, source, conditionSourceType) && sConditionStorage.LookupEntry(m_value2)->Meets(target, map, source, conditionSourceType); + return extraConditionsSatisfied && sConditionStorage.LookupEntry(m_value1)->Meets(target, map, source, conditionSourceType) && sConditionStorage.LookupEntry(m_value2)->Meets(target, map, source, conditionSourceType); } case CONDITION_NONE: { @@ -184,7 +184,7 @@ bool inline ConditionEntry::Evaluate(WorldObject const* target, Map const* map, } case CONDITION_REPUTATION_RANK_MIN: { - FactionEntry const* faction = sFactionStore.LookupEntry(m_value1); + FactionEntry const* faction = sFactionStore.LookupEntry(m_value1); return faction && static_cast(target)->GetReputationMgr().GetRank(faction) >= ReputationRank(m_value2); } case CONDITION_TEAM: @@ -221,7 +221,7 @@ bool inline ConditionEntry::Evaluate(WorldObject const* target, Map const* map, case CONDITION_AREA_FLAG: { WorldObject const* searcher = source ? source : target; - if (AreaTableEntry const* pAreaEntry = GetAreaEntryByAreaID(searcher->GetAreaId())) + if (AreaTableEntry const* pAreaEntry = TerrainManager::GetAreaEntryByAreaID(searcher->GetAreaId())) { if ((!m_value1 || (pAreaEntry->flags & m_value1)) && (!m_value2 || !(pAreaEntry->flags & m_value2))) return true; @@ -357,7 +357,7 @@ bool inline ConditionEntry::Evaluate(WorldObject const* target, Map const* map, } case CONDITION_REPUTATION_RANK_MAX: { - FactionEntry const* faction = sFactionStore.LookupEntry(m_value1);; + FactionEntry const* faction = sFactionStore.LookupEntry(m_value1);; Player const* player = static_cast(target); return faction && player->GetReputationMgr().GetRank(faction) <= ReputationRank(m_value2); } @@ -372,8 +372,8 @@ bool inline ConditionEntry::Evaluate(WorldObject const* target, Map const* map, } uint32 completedEncounterMask = ((DungeonMap*)map)->GetPersistanceState()->GetCompletedEncountersMask(); - DungeonEncounterEntry const* dbcEntry1 = sDungeonEncounterStore.LookupEntry(m_value1); - DungeonEncounterEntry const* dbcEntry2 = sDungeonEncounterStore.LookupEntry(m_value2); + DungeonEncounterEntry const* dbcEntry1 = sDungeonEncounterStore.LookupEntry(m_value1); + DungeonEncounterEntry const* dbcEntry2 = sDungeonEncounterStore.LookupEntry(m_value2); // Check that on proper map if (dbcEntry1->mapId != map->GetId()) { @@ -542,7 +542,7 @@ bool ConditionEntry::CheckParamRequirements(WorldObject const* target, Map const return true; return false; } - + return true; } @@ -558,7 +558,7 @@ bool ConditionEntry::IsValid() const sLog.outErrorDb("CONDITION_NOT (entry %u, type %d) has invalid value1 %u, must be lower than entry, skipped", m_entry, m_condition, m_value1); return false; } - ConditionEntry const* condition1 = sConditionStorage.LookupEntry(m_value1); + ConditionEntry const* condition1 = sConditionStorage.LookupEntry(m_value1); if (!condition1) { sLog.outErrorDb("CONDITION_NOT (entry %u, type %d) has value1 %u without proper condition, skipped", m_entry, m_condition, m_value1); @@ -579,13 +579,13 @@ bool ConditionEntry::IsValid() const sLog.outErrorDb("CONDITION _AND or _OR (entry %u, type %d) has invalid value2 %u, must be lower than entry, skipped", m_entry, m_condition, m_value2); return false; } - ConditionEntry const* condition1 = sConditionStorage.LookupEntry(m_value1); + ConditionEntry const* condition1 = sConditionStorage.LookupEntry(m_value1); if (!condition1) { sLog.outErrorDb("CONDITION _AND or _OR (entry %u, type %d) has value1 %u without proper condition, skipped", m_entry, m_condition, m_value1); return false; } - ConditionEntry const* condition2 = sConditionStorage.LookupEntry(m_value2); + ConditionEntry const* condition2 = sConditionStorage.LookupEntry(m_value2); if (!condition2) { sLog.outErrorDb("CONDITION _AND or _OR (entry %u, type %d) has value2 %u without proper condition, skipped", m_entry, m_condition, m_value2); @@ -598,7 +598,7 @@ bool ConditionEntry::IsValid() const sLog.outErrorDb("CONDITION _AND or _OR (entry %u, type %d) has invalid value3 %u, must be lower than entry, skipped", m_entry, m_condition, m_value3); return false; } - ConditionEntry const* condition3 = sConditionStorage.LookupEntry(m_value3); + ConditionEntry const* condition3 = sConditionStorage.LookupEntry(m_value3); if (!condition3) { sLog.outErrorDb("CONDITION _AND or _OR (entry %u, type %d) has value3 %u without proper condition, skipped", m_entry, m_condition, m_value3); @@ -612,7 +612,7 @@ bool ConditionEntry::IsValid() const sLog.outErrorDb("CONDITION _AND or _OR (entry %u, type %d) has invalid value4 %u, must be lower than entry, skipped", m_entry, m_condition, m_value4); return false; } - ConditionEntry const* condition4 = sConditionStorage.LookupEntry(m_value4); + ConditionEntry const* condition4 = sConditionStorage.LookupEntry(m_value4); if (!condition4) { sLog.outErrorDb("CONDITION _AND or _OR (entry %u, type %d) has value4 %u without proper condition, skipped", m_entry, m_condition, m_value4); @@ -623,7 +623,7 @@ bool ConditionEntry::IsValid() const } case CONDITION_AURA: { - if (!sSpellTemplate.LookupEntry(m_value1)) + if (!sSpellTemplate.LookupEntry(m_value1)) { sLog.outErrorDb("Aura condition (entry %u, type %u) requires to have non existing spell (Id: %d), skipped", m_entry, m_condition, m_value1); return false; @@ -664,7 +664,7 @@ bool ConditionEntry::IsValid() const } case CONDITION_AREAID: { - AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(m_value1); + AreaTableEntry const* areaEntry = TerrainManager::GetAreaEntryByAreaID(m_value1); if (!areaEntry) { sLog.outErrorDb("Zone condition (entry %u, type %u) requires to be in non existing area (%u), skipped", m_entry, m_condition, m_value1); @@ -681,7 +681,7 @@ bool ConditionEntry::IsValid() const case CONDITION_REPUTATION_RANK_MIN: case CONDITION_REPUTATION_RANK_MAX: { - FactionEntry const* factionEntry = sFactionStore.LookupEntry(m_value1);; + FactionEntry const* factionEntry = sFactionStore.LookupEntry(m_value1);; if (!factionEntry) { sLog.outErrorDb("Reputation condition (entry %u, type %u) requires to have reputation non existing faction (%u), skipped", m_entry, m_condition, m_value1); @@ -801,7 +801,7 @@ bool ConditionEntry::IsValid() const } case CONDITION_SPELL: { - if (!sSpellTemplate.LookupEntry(m_value1)) + if (!sSpellTemplate.LookupEntry(m_value1)) { sLog.outErrorDb("Spell condition (entry %u, type %u) requires to have non existing spell (Id: %d), skipped", m_entry, m_condition, m_value1); return false; @@ -839,7 +839,7 @@ bool ConditionEntry::IsValid() const } case CONDITION_CREATURE_IN_RANGE: { - if (!sCreatureStorage.LookupEntry(m_value1)) + if (!sCreatureStorage.LookupEntry(m_value1)) { sLog.outErrorDb("Creature in range condition (entry %u, type %u) has an invalid value in value1. (Creature %u does not exist in the database), skipping.", m_entry, m_condition, m_value1); return false; @@ -853,8 +853,8 @@ bool ConditionEntry::IsValid() const } case CONDITION_COMPLETED_ENCOUNTER: { - DungeonEncounterEntry const* dbcEntry1 = sDungeonEncounterStore.LookupEntry(m_value1); - DungeonEncounterEntry const* dbcEntry2 = sDungeonEncounterStore.LookupEntry(m_value2); + DungeonEncounterEntry const* dbcEntry1 = sDungeonEncounterStore.LookupEntry(m_value1); + DungeonEncounterEntry const* dbcEntry2 = sDungeonEncounterStore.LookupEntry(m_value2); if (!dbcEntry1) { sLog.outErrorDb("Completed Encounter condition (entry %u, type %u) has an unknown DungeonEncounter entry %u defined (in value1), skipping.", m_entry, m_condition, m_value1); @@ -901,7 +901,7 @@ bool ConditionEntry::IsValid() const } case CONDITION_SPAWN_COUNT: { - if (!sCreatureStorage.LookupEntry(m_value1)) + if (!sCreatureStorage.LookupEntry(m_value1)) { sLog.outErrorDb("Spawn count condition (entry %u, type %u) has an invalid value in value1. (Creature %u does not exist in the database), skipping.", m_entry, m_condition, m_value1); return false; @@ -924,7 +924,7 @@ bool ConditionEntry::IsValid() const // Check if a condition can be used without providing a player param bool ConditionEntry::CanBeUsedWithoutPlayer(uint32 entry) { - ConditionEntry const* condition = sConditionStorage.LookupEntry(entry); + ConditionEntry const* condition = sConditionStorage.LookupEntry(entry); if (!condition) return false; @@ -944,7 +944,7 @@ bool ConditionEntry::CanBeUsedWithoutPlayer(uint32 entry) bool IsConditionSatisfied(uint32 conditionId, WorldObject const* target, Map const* map, WorldObject const* source, ConditionSource conditionSourceType) { - if (ConditionEntry const* condition = sConditionStorage.LookupEntry(conditionId)) + if (ConditionEntry const* condition = sConditionStorage.LookupEntry(conditionId)) return condition->Meets(target, map, source, conditionSourceType); return false; diff --git a/src/game/Globals/Conditions.h b/src/game/Globals/Conditions.h index 99b3e556c4..ef41598717 100644 --- a/src/game/Globals/Conditions.h +++ b/src/game/Globals/Conditions.h @@ -139,6 +139,8 @@ class ConditionEntry // Checks if the condition is met bool Meets(WorldObject const* target, Map const* map, WorldObject const* source, ConditionSource conditionSourceType) const; + uint32 GetEntry() const { return m_entry; } + private: void DisableCondition() { m_condition = CONDITION_NONE; m_flags ^= CONDITION_FLAG_REVERSE_RESULT; } bool CheckParamRequirements(WorldObject const* target, Map const* map, WorldObject const* source) const; diff --git a/src/game/Globals/ObjectMgr.cpp b/src/game/Globals/ObjectMgr.cpp index 17ffcab034..d38c0ffa98 100644 --- a/src/game/Globals/ObjectMgr.cpp +++ b/src/game/Globals/ObjectMgr.cpp @@ -419,7 +419,7 @@ void ObjectMgr::LoadPointOfInterestLocales() sLog.outString(); } -struct SQLCreatureLoader : public SQLStorageLoaderBase +struct SQLCreatureLoader : public SQLStorageLoaderBase> { template void convert_from_str(uint32 /*field_pos*/, char const* src, D& dst) @@ -437,24 +437,20 @@ void ObjectMgr::LoadCreatureTemplates() std::set hasHeroicEntries; // already loaded creatures with heroic entry values // check data correctness - for (uint32 i = 1; i < sCreatureStorage.GetMaxEntry(); ++i) + for (auto cInfo : sCreatureStorage) { - CreatureInfo const* cInfo = sCreatureStorage.LookupEntry(i); - if (!cInfo) - continue; - if (cInfo->HeroicEntry) { CreatureInfo const* heroicInfo = GetCreatureTemplate(cInfo->HeroicEntry); if (!heroicInfo) { - sLog.outErrorDb("Creature (Entry: %u) have `heroic_entry`=%u but creature entry %u not exist.", i, cInfo->HeroicEntry, cInfo->HeroicEntry); + sLog.outErrorDb("Creature (Entry: %u) have `heroic_entry`=%u but creature entry %u not exist.", cInfo->Entry, cInfo->HeroicEntry, cInfo->HeroicEntry); continue; } - if (heroicEntries.find(i) != heroicEntries.end()) + if (heroicEntries.find(cInfo->Entry) != heroicEntries.end()) { - sLog.outErrorDb("Creature (Entry: %u) listed as heroic but have value in `heroic_entry`.", i); + sLog.outErrorDb("Creature (Entry: %u) listed as heroic but have value in `heroic_entry`.", cInfo->Entry); continue; } @@ -466,59 +462,59 @@ void ObjectMgr::LoadCreatureTemplates() if (hasHeroicEntries.find(cInfo->HeroicEntry) != hasHeroicEntries.end()) { - sLog.outErrorDb("Creature (Entry: %u) have `heroic_entry`=%u but creature entry %u have heroic entry also.", i, cInfo->HeroicEntry, cInfo->HeroicEntry); + sLog.outErrorDb("Creature (Entry: %u) have `heroic_entry`=%u but creature entry %u have heroic entry also.", cInfo->Entry, cInfo->HeroicEntry, cInfo->HeroicEntry); continue; } if (cInfo->UnitClass != heroicInfo->UnitClass) { - sLog.outErrorDb("Creature (Entry: %u, class %u) has different `unit_class` in heroic mode (Entry: %u, class %u).", i, cInfo->UnitClass, cInfo->HeroicEntry, heroicInfo->UnitClass); + sLog.outErrorDb("Creature (Entry: %u, class %u) has different `unit_class` in heroic mode (Entry: %u, class %u).", cInfo->Entry, cInfo->UnitClass, cInfo->HeroicEntry, heroicInfo->UnitClass); continue; } if (cInfo->NpcFlags != heroicInfo->NpcFlags) { - sLog.outErrorDb("Creature (Entry: %u) has different `npcflag` in heroic mode (Entry: %u).", i, cInfo->HeroicEntry); + sLog.outErrorDb("Creature (Entry: %u) has different `npcflag` in heroic mode (Entry: %u).", cInfo->Entry, cInfo->HeroicEntry); continue; } if (cInfo->TrainerClass != heroicInfo->TrainerClass) { - sLog.outErrorDb("Creature (Entry: %u) has different `trainer_class` in heroic mode (Entry: %u).", i, cInfo->HeroicEntry); + sLog.outErrorDb("Creature (Entry: %u) has different `trainer_class` in heroic mode (Entry: %u).", cInfo->Entry, cInfo->HeroicEntry); continue; } if (cInfo->TrainerRace != heroicInfo->TrainerRace) { - sLog.outErrorDb("Creature (Entry: %u) has different `trainer_race` in heroic mode (Entry: %u).", i, cInfo->HeroicEntry); + sLog.outErrorDb("Creature (Entry: %u) has different `trainer_race` in heroic mode (Entry: %u).", cInfo->Entry, cInfo->HeroicEntry); continue; } if (cInfo->TrainerType != heroicInfo->TrainerType) { - sLog.outErrorDb("Creature (Entry: %u) has different `trainer_type` in heroic mode (Entry: %u).", i, cInfo->HeroicEntry); + sLog.outErrorDb("Creature (Entry: %u) has different `trainer_type` in heroic mode (Entry: %u).", cInfo->Entry, cInfo->HeroicEntry); continue; } if (cInfo->TrainerSpell != heroicInfo->TrainerSpell) { - sLog.outErrorDb("Creature (Entry: %u) has different `trainer_spell` in heroic mode (Entry: %u).", i, cInfo->HeroicEntry); + sLog.outErrorDb("Creature (Entry: %u) has different `trainer_spell` in heroic mode (Entry: %u).", cInfo->Entry, cInfo->HeroicEntry); continue; } if (heroicInfo->AIName && *heroicInfo->AIName) { - sLog.outErrorDb("Heroic mode creature (Entry: %u) has `AIName`, but in any case will used normal mode creature (Entry: %u) AIName.", cInfo->HeroicEntry, i); + sLog.outErrorDb("Heroic mode creature (Entry: %u) has `AIName`, but in any case will used normal mode creature (Entry: %u) AIName.", cInfo->HeroicEntry, cInfo->Entry); continue; } if (heroicInfo->ScriptID) { - sLog.outErrorDb("Heroic mode creature (Entry: %u) has `ScriptName`, but in any case will used normal mode creature (Entry: %u) ScriptName.", cInfo->HeroicEntry, i); + sLog.outErrorDb("Heroic mode creature (Entry: %u) has `ScriptName`, but in any case will used normal mode creature (Entry: %u) ScriptName.", cInfo->HeroicEntry, cInfo->Entry); continue; } - hasHeroicEntries.insert(i); + hasHeroicEntries.insert(cInfo->Entry); heroicEntries.insert(cInfo->HeroicEntry); } @@ -554,7 +550,7 @@ void ObjectMgr::LoadCreatureTemplates() else if (!displayScaleEntry) displayScaleEntry = displayEntry; - CreatureModelInfo const* minfo = sCreatureModelStorage.LookupEntry(cInfo->ModelId[j]); + CreatureModelInfo const* minfo = sCreatureModelStorage.LookupEntry(cInfo->ModelId[j]); if (!minfo) sLog.outErrorDb("Creature (Entry: %u) are using modelid_%d (%u), but creature_model_info are missing for this model.", cInfo->Entry, j + 1, cInfo->ModelId[j]); } @@ -693,7 +689,7 @@ void ObjectMgr::LoadCreatureTemplates() } - sLog.outString(">> Loaded %u creature definitions", sCreatureStorage.GetRecordCount()); + sLog.outString(">> Loaded %u creature definitions", sCreatureStorage.GetNumRows()); sLog.outString(); } @@ -737,7 +733,7 @@ void ObjectMgr::ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* uint32& cAura = const_cast(addon->auras[i]); cAura = uint32(j); - SpellEntry const* AdditionalSpellInfo = sSpellTemplate.LookupEntry(cAura); + SpellEntry const* AdditionalSpellInfo = sSpellTemplate.LookupEntry(cAura); if (!AdditionalSpellInfo) { sLog.outErrorDb("Creature (%s: %u) has wrong spell %u defined in `auras` field in `%s`.", guidEntryStr, addon->guidOrEntry, cAura, table); @@ -780,14 +776,14 @@ void ObjectMgr::ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* const_cast(addon->auras[i]) = 0; } -void ObjectMgr::LoadCreatureAddons(SQLStorage& creatureaddons, char const* entryName, char const* comment) +void ObjectMgr::LoadCreatureAddons(SQLStorage& creatureaddons, char const* entryName, char const* comment) { creatureaddons.Load(); // check data correctness and convert 'auras' for (uint32 i = 1; i < creatureaddons.GetMaxEntry(); ++i) { - CreatureDataAddon const* addon = creatureaddons.LookupEntry(i); + CreatureDataAddon const* addon = creatureaddons.LookupEntry(i); if (!addon) continue; @@ -812,7 +808,7 @@ void ObjectMgr::LoadCreatureAddons(SQLStorage& creatureaddons, char const* entry ConvertCreatureAddonAuras(const_cast(addon), creatureaddons.GetTableName(), entryName); } - sLog.outString(">> Loaded %u %s", creatureaddons.GetRecordCount(), comment); + sLog.outString(">> Loaded %u %s", creatureaddons.GetNumRows(), comment); } void ObjectMgr::LoadCreatureAddons() @@ -820,18 +816,16 @@ void ObjectMgr::LoadCreatureAddons() LoadCreatureAddons(sCreatureInfoAddonStorage, "Entry", "creature template addons"); // check entry ids - for (uint32 i = 1; i < sCreatureInfoAddonStorage.GetMaxEntry(); ++i) - if (CreatureDataAddon const* addon = sCreatureInfoAddonStorage.LookupEntry(i)) - if (!sCreatureStorage.LookupEntry(addon->guidOrEntry)) - sLog.outErrorDb("Creature (Entry: %u) does not exist but has a record in `%s`", addon->guidOrEntry, sCreatureInfoAddonStorage.GetTableName()); + for (auto addon : sCreatureInfoAddonStorage) + if (!sCreatureStorage.LookupEntry(addon->guidOrEntry)) + sLog.outErrorDb("Creature (Entry: %u) does not exist but has a record in `%s`", addon->guidOrEntry, sCreatureInfoAddonStorage.GetTableName()); LoadCreatureAddons(sCreatureDataAddonStorage, "GUID", "creature addons"); // check entry ids - for (uint32 i = 1; i < sCreatureDataAddonStorage.GetMaxEntry(); ++i) - if (CreatureDataAddon const* addon = sCreatureDataAddonStorage.LookupEntry(i)) - if (mCreatureDataMap.find(addon->guidOrEntry) == mCreatureDataMap.end()) - sLog.outErrorDb("Creature (GUID: %u) does not exist but has a record in `creature_addon`", addon->guidOrEntry); + for (auto addon : sCreatureDataAddonStorage) + if (mCreatureDataMap.find(addon->guidOrEntry) == mCreatureDataMap.end()) + sLog.outErrorDb("Creature (GUID: %u) does not exist but has a record in `creature_addon`", addon->guidOrEntry); } void ObjectMgr::LoadCreatureClassLvlStats() @@ -929,13 +923,8 @@ void ObjectMgr::LoadEquipmentTemplates() { sEquipmentStorage.Load(true); - for (uint32 i = 0; i < sEquipmentStorage.GetMaxEntry(); ++i) + for (auto eqInfo : sEquipmentStorage) { - EquipmentInfo const* eqInfo = sEquipmentStorage.LookupEntry(i); - - if (!eqInfo) - continue; - for (uint8 j = 0; j < 3; ++j) { if (!eqInfo->equipentry[j]) @@ -944,7 +933,7 @@ void ObjectMgr::LoadEquipmentTemplates() ItemPrototype const* itemProto = GetItemPrototype(eqInfo->equipentry[j]); if (!itemProto) { - sLog.outErrorDb("Unknown item (entry=%u) in creature_equip_template.equipentry%u for entry = %u, forced to 0.", eqInfo->equipentry[j], j + 1, i); + sLog.outErrorDb("Unknown item (entry=%u) in creature_equip_template.equipentry%u for entry = %u, forced to 0.", eqInfo->equipentry[j], j + 1, eqInfo->entry); const_cast(eqInfo)->equipentry[j] = 0; continue; } @@ -960,22 +949,21 @@ void ObjectMgr::LoadEquipmentTemplates() itemProto->InventoryType != INVTYPE_RANGEDRIGHT && itemProto->InventoryType != INVTYPE_RELIC) { - sLog.outErrorDb("Item (entry=%u) in creature_equip_template.equipentry%u for entry = %u is not equipable in a hand, forced to 0.", eqInfo->equipentry[j], j + 1, i); + sLog.outErrorDb("Item (entry=%u) in creature_equip_template.equipentry%u for entry = %u is not equipable in a hand, forced to 0.", eqInfo->equipentry[j], j + 1, eqInfo->entry); const_cast(eqInfo)->equipentry[j] = 0; } } } - sLog.outString(">> Loaded %u equipment template", sEquipmentStorage.GetRecordCount()); + sLog.outString(">> Loaded %u equipment template", sEquipmentStorage.GetNumRows()); sLog.outString(); sEquipmentStorageRaw.Load(false); - for (uint32 i = 1; i < sEquipmentStorageRaw.GetMaxEntry(); ++i) - if (sEquipmentStorageRaw.LookupEntry(i)) - if (sEquipmentStorage.LookupEntry(i)) - sLog.outErrorDb("Table 'creature_equip_template_raw` have redundant data for ID %u ('creature_equip_template` already have data)", i); + for (auto eqRawInfo : sEquipmentStorageRaw) + if (sEquipmentStorage.LookupEntry(eqRawInfo->entry)) + sLog.outErrorDb("Table 'creature_equip_template_raw` have redundant data for ID %u ('creature_equip_template` already have data)", eqRawInfo->entry); - sLog.outString(">> Loaded %u equipment template (deprecated format)", sEquipmentStorageRaw.GetRecordCount()); + sLog.outString(">> Loaded %u equipment template (deprecated format)", sEquipmentStorageRaw.GetNumRows()); sLog.outString(); } @@ -1038,12 +1026,8 @@ void ObjectMgr::LoadCreatureModelInfo() sCreatureModelStorage.Load(); // post processing - for (uint32 i = 1; i < sCreatureModelStorage.GetMaxEntry(); ++i) + for (auto minfo : sCreatureModelStorage) { - CreatureModelInfo const* minfo = sCreatureModelStorage.LookupEntry(i); - if (!minfo) - continue; - if (!sCreatureDisplayInfoStore.LookupEntry(minfo->modelid)) sLog.outErrorDb("Table `creature_model_info` has model for nonexistent model id (%u).", minfo->modelid); @@ -1083,51 +1067,47 @@ void ObjectMgr::LoadCreatureModelInfo() } // character races expected have model info data in table - for (uint32 race = 1; race < sChrRacesStore.GetNumRows(); ++race) + for (auto raceEntry : sChrRacesStore) { - ChrRacesEntry const* raceEntry = sChrRacesStore.LookupEntry(race); - if (!raceEntry) - continue; - - if (!((1 << (race - 1)) & RACEMASK_ALL_PLAYABLE)) + if (!((1 << (raceEntry->RaceID - 1)) & RACEMASK_ALL_PLAYABLE)) continue; if (CreatureModelInfo const* minfo = GetCreatureModelInfo(raceEntry->model_f)) { if (minfo->gender != GENDER_FEMALE) - sLog.outErrorDb("Table `creature_model_info` have wrong gender %u for character race %u female model id %u", minfo->gender, race, raceEntry->model_f); + sLog.outErrorDb("Table `creature_model_info` have wrong gender %u for character race %u female model id %u", minfo->gender, raceEntry->RaceID, raceEntry->model_f); if (minfo->modelid_other_gender != raceEntry->model_m) - sLog.outErrorDb("Table `creature_model_info` have wrong other gender model id %u for character race %u female model id %u", minfo->modelid_other_gender, race, raceEntry->model_f); + sLog.outErrorDb("Table `creature_model_info` have wrong other gender model id %u for character race %u female model id %u", minfo->modelid_other_gender, raceEntry->RaceID, raceEntry->model_f); if (minfo->bounding_radius <= 0.0f) { - sLog.outErrorDb("Table `creature_model_info` have wrong bounding_radius %f for character race %u female model id %u, use %f instead", minfo->bounding_radius, race, raceEntry->model_f, DEFAULT_WORLD_OBJECT_SIZE); + sLog.outErrorDb("Table `creature_model_info` have wrong bounding_radius %f for character race %u female model id %u, use %f instead", minfo->bounding_radius, raceEntry->RaceID, raceEntry->model_f, DEFAULT_WORLD_OBJECT_SIZE); const_cast(minfo)->bounding_radius = DEFAULT_WORLD_OBJECT_SIZE; } } else - sLog.outErrorDb("Table `creature_model_info` expect have data for character race %u female model id %u", race, raceEntry->model_f); + sLog.outErrorDb("Table `creature_model_info` expect have data for character race %u female model id %u", raceEntry->RaceID, raceEntry->model_f); if (CreatureModelInfo const* minfo = GetCreatureModelInfo(raceEntry->model_m)) { if (minfo->gender != GENDER_MALE) - sLog.outErrorDb("Table `creature_model_info` have wrong gender %u for character race %u male model id %u", minfo->gender, race, raceEntry->model_m); + sLog.outErrorDb("Table `creature_model_info` have wrong gender %u for character race %u male model id %u", minfo->gender, raceEntry->RaceID, raceEntry->model_m); if (minfo->modelid_other_gender != raceEntry->model_f) - sLog.outErrorDb("Table `creature_model_info` have wrong other gender model id %u for character race %u male model id %u", minfo->modelid_other_gender, race, raceEntry->model_m); + sLog.outErrorDb("Table `creature_model_info` have wrong other gender model id %u for character race %u male model id %u", minfo->modelid_other_gender, raceEntry->RaceID, raceEntry->model_m); if (minfo->bounding_radius <= 0.0f) { - sLog.outErrorDb("Table `creature_model_info` have wrong bounding_radius %f for character race %u male model id %u, use %f instead", minfo->bounding_radius, race, raceEntry->model_f, DEFAULT_WORLD_OBJECT_SIZE); + sLog.outErrorDb("Table `creature_model_info` have wrong bounding_radius %f for character race %u male model id %u, use %f instead", minfo->bounding_radius, raceEntry->RaceID, raceEntry->model_f, DEFAULT_WORLD_OBJECT_SIZE); const_cast(minfo)->bounding_radius = DEFAULT_WORLD_OBJECT_SIZE; } } else - sLog.outErrorDb("Table `creature_model_info` expect have data for character race %u male model id %u", race, raceEntry->model_m); + sLog.outErrorDb("Table `creature_model_info` expect have data for character race %u male model id %u", raceEntry->RaceID, raceEntry->model_m); } - sLog.outString(">> Loaded %u creature model based info", sCreatureModelStorage.GetRecordCount()); + sLog.outString(">> Loaded %u creature model based info", sCreatureModelStorage.GetNumRows()); sLog.outString(); } @@ -1172,7 +1152,7 @@ void ObjectMgr::LoadCreatureModelRace() continue; } - if (!sCreatureModelStorage.LookupEntry(raceData.modelid)) + if (!sCreatureModelStorage.LookupEntry(raceData.modelid)) { sLog.outErrorDb("Table `creature_model_race` modelid %u does not exist in creature_model_info, skipping", raceData.modelid); continue; @@ -1210,7 +1190,7 @@ void ObjectMgr::LoadCreatureModelRace() if (raceData.modelid_racial) sLog.outErrorDb("Table `creature_model_race` modelid %u has modelid_racial for modelid %u but a creature_entry are already defined, modelid_racial will never be used.", raceData.modelid, raceData.modelid_racial); - if (!sCreatureStorage.LookupEntry(raceData.creature_entry)) + if (!sCreatureStorage.LookupEntry(raceData.creature_entry)) { sLog.outErrorDb("Table `creature_model_race` modelid %u has creature_entry for nonexistent creature_template (%u), skipping", raceData.modelid, raceData.creature_entry); continue; @@ -1224,7 +1204,7 @@ void ObjectMgr::LoadCreatureModelRace() continue; } - if (!sCreatureModelStorage.LookupEntry(raceData.modelid_racial)) + if (!sCreatureModelStorage.LookupEntry(raceData.modelid_racial)) { sLog.outErrorDb("Table `creature_model_race` modelid %u has modelid_racial %u, but are not defined in creature_model_info, skipping", raceData.modelid, raceData.modelid_racial); continue; @@ -1253,12 +1233,8 @@ void ObjectMgr::LoadCreatureConditionalSpawn() sCreatureConditionalSpawnStore.Load(); // post processing - for (uint32 i = 1; i < sCreatureConditionalSpawnStore.GetMaxEntry(); ++i) + for (auto spawn : sCreatureConditionalSpawnStore) { - CreatureConditionalSpawn const* spawn = sCreatureConditionalSpawnStore.LookupEntry(i); - if (!spawn) - continue; - CreatureInfo const* cInfoAlliance = GetCreatureTemplate(spawn->EntryAlliance); CreatureInfo const* cInfoHorde = GetCreatureTemplate(spawn->EntryHorde); @@ -1269,7 +1245,7 @@ void ObjectMgr::LoadCreatureConditionalSpawn() } } - sLog.outString(">> Loaded %u creature_conditional_spawn entries", sCreatureConditionalSpawnStore.GetRecordCount()); + sLog.outString(">> Loaded %u creature_conditional_spawn entries", sCreatureConditionalSpawnStore.GetNumRows()); sLog.outString(); } @@ -1286,7 +1262,7 @@ void ObjectMgr::LoadCreatureSpawnDataTemplates() sLog.outString(); return; } - + BarGoLink bar(result->GetRowCount()); uint32 count = 0; @@ -1401,10 +1377,11 @@ void ObjectMgr::LoadCreatures() // build single time for check creature data std::set heroicCreatures; - for (uint32 i = 0; i < sCreatureStorage.GetMaxEntry(); ++i) - if (CreatureInfo const* cInfo = sCreatureStorage.LookupEntry(i)) - if (cInfo->HeroicEntry) - heroicCreatures.insert(cInfo->HeroicEntry); + for (auto cInfo : sCreatureStorage) + { + if (cInfo->HeroicEntry) + heroicCreatures.insert(cInfo->HeroicEntry); + } BarGoLink bar(result->GetRowCount()); @@ -2012,7 +1989,7 @@ void ObjectMgr::LoadItemLocales() sLog.outString(); } -struct SQLItemLoader : public SQLStorageLoaderBase +struct SQLItemLoader : public SQLStorageLoaderBase> { template void convert_from_str(uint32 /*field_pos*/, char const* src, D& dst) @@ -2027,10 +2004,9 @@ void ObjectMgr::LoadItemPrototypes() loader.Load(sItemStorage); // check data correctness - for (uint32 i = 1; i < sItemStorage.GetMaxEntry(); ++i) + for (auto proto : sItemStorage) { - ItemPrototype const* proto = sItemStorage.LookupEntry(i); - ItemEntry const* dbcitem = sItemStore.LookupEntry(i); + ItemEntry const* dbcitem = sItemStore.LookupEntry(proto->ItemId); if (!proto) { /* to many errors, and possible not all items really used in game @@ -2043,63 +2019,63 @@ void ObjectMgr::LoadItemPrototypes() for (const auto& Spell : proto->Spells) if (Spell.SpellCategory && Spell.SpellId) { - if (sSpellTemplate.LookupEntry(Spell.SpellId)) - sItemSpellCategoryStore[Spell.SpellCategory].insert(ItemCategorySpellPair(Spell.SpellId, i)); + if (sSpellTemplate.LookupEntry(Spell.SpellId)) + sItemSpellCategoryStore[Spell.SpellCategory].insert(ItemCategorySpellPair(Spell.SpellId, proto->ItemId)); else - sLog.outErrorDb("Item (Entry: %u) not correct %u spell id, must exist in spell table.", i, Spell.SpellId); + sLog.outErrorDb("Item (Entry: %u) not correct %u spell id, must exist in spell table.", proto->ItemId, Spell.SpellId); } if (dbcitem) { if (proto->InventoryType != dbcitem->InventoryType) { - sLog.outErrorDb("Item (Entry: %u) not correct %u inventory type, must be %u (still using DB value).", i, proto->InventoryType, dbcitem->InventoryType); + sLog.outErrorDb("Item (Entry: %u) not correct %u inventory type, must be %u (still using DB value).", proto->ItemId, proto->InventoryType, dbcitem->InventoryType); // It safe let use InventoryType from DB } if (proto->DisplayInfoID != dbcitem->DisplayId) { - sLog.outErrorDb("Item (Entry: %u) not correct %u display id, must be %u (using it).", i, proto->DisplayInfoID, dbcitem->DisplayId); + sLog.outErrorDb("Item (Entry: %u) not correct %u display id, must be %u (using it).", proto->ItemId, proto->DisplayInfoID, dbcitem->DisplayId); const_cast(proto)->DisplayInfoID = dbcitem->DisplayId; } if (proto->Sheath != dbcitem->Sheath) { - sLog.outErrorDb("Item (Entry: %u) not correct %u sheath, must be %u (using it).", i, proto->Sheath, dbcitem->Sheath); + sLog.outErrorDb("Item (Entry: %u) not correct %u sheath, must be %u (using it).", proto->ItemId, proto->Sheath, dbcitem->Sheath); const_cast(proto)->Sheath = dbcitem->Sheath; } } else { - sLog.outErrorDb("Item (Entry: %u) not correct (not listed in list of existing items).", i); + sLog.outErrorDb("Item (Entry: %u) not correct (not listed in list of existing items).", proto->ItemId); } if (proto->Class >= MAX_ITEM_CLASS) { - sLog.outErrorDb("Item (Entry: %u) has wrong Class value (%u)", i, proto->Class); + sLog.outErrorDb("Item (Entry: %u) has wrong Class value (%u)", proto->ItemId, proto->Class); const_cast(proto)->Class = ITEM_CLASS_MISC; } if (proto->SubClass >= MaxItemSubclassValues[proto->Class]) { - sLog.outErrorDb("Item (Entry: %u) has wrong Subclass value (%u) for class %u", i, proto->SubClass, proto->Class); + sLog.outErrorDb("Item (Entry: %u) has wrong Subclass value (%u) for class %u", proto->ItemId, proto->SubClass, proto->Class); const_cast(proto)->SubClass = 0;// exist for all item classes } if (proto->Quality >= MAX_ITEM_QUALITY) { - sLog.outErrorDb("Item (Entry: %u) has wrong Quality value (%u)", i, proto->Quality); + sLog.outErrorDb("Item (Entry: %u) has wrong Quality value (%u)", proto->ItemId, proto->Quality); const_cast(proto)->Quality = ITEM_QUALITY_NORMAL; } if (proto->BuyCount <= 0) { - sLog.outErrorDb("Item (Entry: %u) has wrong BuyCount value (%u), set to default(1).", i, proto->BuyCount); + sLog.outErrorDb("Item (Entry: %u) has wrong BuyCount value (%u), set to default(1).", proto->ItemId, proto->BuyCount); const_cast(proto)->BuyCount = 1; } if (proto->InventoryType >= MAX_INVTYPE) { - sLog.outErrorDb("Item (Entry: %u) has wrong InventoryType value (%u)", i, proto->InventoryType); + sLog.outErrorDb("Item (Entry: %u) has wrong InventoryType value (%u)", proto->ItemId, proto->InventoryType); const_cast(proto)->InventoryType = INVTYPE_NON_EQUIP; } @@ -2107,13 +2083,13 @@ void ObjectMgr::LoadItemPrototypes() { if (proto->Flags & ITEM_FLAG_HAS_LOOT) { - sLog.outErrorDb("Item container (Entry: %u) has not allowed for containers flag ITEM_FLAG_LOOTABLE (%u), flag removed.", i, ITEM_FLAG_HAS_LOOT); + sLog.outErrorDb("Item container (Entry: %u) has not allowed for containers flag ITEM_FLAG_LOOTABLE (%u), flag removed.", proto->ItemId, ITEM_FLAG_HAS_LOOT); const_cast(proto)->Flags &= ~ITEM_FLAG_HAS_LOOT; } if (proto->Flags & ITEM_FLAG_IS_PROSPECTABLE) { - sLog.outErrorDb("Item container (Entry: %u) has not allowed for containers flag ITEM_FLAG_PROSPECTABLE (%u), flag removed.", i, ITEM_FLAG_IS_PROSPECTABLE); + sLog.outErrorDb("Item container (Entry: %u) has not allowed for containers flag ITEM_FLAG_PROSPECTABLE (%u), flag removed.", proto->ItemId, ITEM_FLAG_IS_PROSPECTABLE); const_cast(proto)->Flags &= ~ITEM_FLAG_IS_PROSPECTABLE; } } @@ -2121,14 +2097,14 @@ void ObjectMgr::LoadItemPrototypes() { if (proto->ContainerSlots > 0) { - sLog.outErrorDb("Non-container item (Entry: %u) has ContainerSlots (%u), set to 0.", i, proto->ContainerSlots); + sLog.outErrorDb("Non-container item (Entry: %u) has ContainerSlots (%u), set to 0.", proto->ItemId, proto->ContainerSlots); const_cast(proto)->ContainerSlots = 0; } } if (proto->RequiredSkill >= MAX_SKILL_TYPE) { - sLog.outErrorDb("Item (Entry: %u) has wrong RequiredSkill value (%u)", i, proto->RequiredSkill); + sLog.outErrorDb("Item (Entry: %u) has wrong RequiredSkill value (%u)", proto->ItemId, proto->RequiredSkill); const_cast(proto)->RequiredSkill = 0; } @@ -2150,44 +2126,44 @@ void ObjectMgr::LoadItemPrototypes() if (req) { if (!(proto->AllowableClass & CLASSMASK_ALL_PLAYABLE)) - sLog.outErrorDb("Item (Entry: %u) not have in `AllowableClass` any playable classes (%u) and can't be equipped or use.", i, proto->AllowableClass); + sLog.outErrorDb("Item (Entry: %u) not have in `AllowableClass` any playable classes (%u) and can't be equipped or use.", proto->ItemId, proto->AllowableClass); if (!(proto->AllowableRace & RACEMASK_ALL_PLAYABLE)) - sLog.outErrorDb("Item (Entry: %u) not have in `AllowableRace` any playable races (%u) and can't be equipped or use.", i, proto->AllowableRace); + sLog.outErrorDb("Item (Entry: %u) not have in `AllowableRace` any playable races (%u) and can't be equipped or use.", proto->ItemId, proto->AllowableRace); } } - if (proto->RequiredSpell && !sSpellTemplate.LookupEntry(proto->RequiredSpell)) + if (proto->RequiredSpell && !sSpellTemplate.LookupEntry(proto->RequiredSpell)) { - sLog.outErrorDb("Item (Entry: %u) have wrong (nonexistent) spell in RequiredSpell (%u)", i, proto->RequiredSpell); + sLog.outErrorDb("Item (Entry: %u) have wrong (nonexistent) spell in RequiredSpell (%u)", proto->ItemId, proto->RequiredSpell); const_cast(proto)->RequiredSpell = 0; } if (proto->RequiredReputationRank >= MAX_REPUTATION_RANK) - sLog.outErrorDb("Item (Entry: %u) has wrong reputation rank in RequiredReputationRank (%u), item can't be used.", i, proto->RequiredReputationRank); + sLog.outErrorDb("Item (Entry: %u) has wrong reputation rank in RequiredReputationRank (%u), item can't be used.", proto->ItemId, proto->RequiredReputationRank); if (proto->RequiredReputationFaction) { - if (!sFactionStore.LookupEntry(proto->RequiredReputationFaction)) + if (!sFactionStore.LookupEntry(proto->RequiredReputationFaction)) { - sLog.outErrorDb("Item (Entry: %u) has wrong (not existing) faction in RequiredReputationFaction (%u)", i, proto->RequiredReputationFaction); + sLog.outErrorDb("Item (Entry: %u) has wrong (not existing) faction in RequiredReputationFaction (%u)", proto->ItemId, proto->RequiredReputationFaction); const_cast(proto)->RequiredReputationFaction = 0; } if (proto->RequiredReputationRank == MIN_REPUTATION_RANK) - sLog.outErrorDb("Item (Entry: %u) has min. reputation rank in RequiredReputationRank (0) but RequiredReputationFaction > 0, faction setting is useless.", i); + sLog.outErrorDb("Item (Entry: %u) has min. reputation rank in RequiredReputationRank (0) but RequiredReputationFaction > 0, faction setting is useless.", proto->ItemId); } else if (proto->RequiredReputationRank > MIN_REPUTATION_RANK) - sLog.outErrorDb("Item (Entry: %u) has RequiredReputationFaction ==0 but RequiredReputationRank > 0, rank setting is useless.", i); + sLog.outErrorDb("Item (Entry: %u) has RequiredReputationFaction ==0 but RequiredReputationRank > 0, rank setting is useless.", proto->ItemId); if (proto->Stackable == 0) { - sLog.outErrorDb("Item (Entry: %u) has wrong value in stackable (%u), replace by default 1.", i, proto->Stackable); + sLog.outErrorDb("Item (Entry: %u) has wrong value in stackable (%u), replace by default 1.", proto->ItemId, proto->Stackable); const_cast(proto)->Stackable = 1; } else if (proto->Stackable > 255) { - sLog.outErrorDb("Item (Entry: %u) has too large value in stackable (%u), replace by hardcoded upper limit (255).", i, proto->Stackable); + sLog.outErrorDb("Item (Entry: %u) has too large value in stackable (%u), replace by hardcoded upper limit (255).", proto->ItemId, proto->Stackable); const_cast(proto)->Stackable = 255; } @@ -2195,7 +2171,7 @@ void ObjectMgr::LoadItemPrototypes() { if (proto->ContainerSlots > MAX_BAG_SIZE) { - sLog.outErrorDb("Item (Entry: %u) has too large value in ContainerSlots (%u), replace by hardcoded limit (%u).", i, proto->ContainerSlots, MAX_BAG_SIZE); + sLog.outErrorDb("Item (Entry: %u) has too large value in ContainerSlots (%u), replace by hardcoded limit (%u).", proto->ItemId, proto->ContainerSlots, MAX_BAG_SIZE); const_cast(proto)->ContainerSlots = MAX_BAG_SIZE; } } @@ -2205,7 +2181,7 @@ void ObjectMgr::LoadItemPrototypes() // for ItemStatValue != 0 if (proto->ItemStat[j].ItemStatValue && proto->ItemStat[j].ItemStatType >= MAX_ITEM_MOD) { - sLog.outErrorDb("Item (Entry: %u) has wrong stat_type%d (%u)", i, j + 1, proto->ItemStat[j].ItemStatType); + sLog.outErrorDb("Item (Entry: %u) has wrong stat_type%d (%u)", proto->ItemId, j + 1, proto->ItemStat[j].ItemStatType); const_cast(proto)->ItemStat[j].ItemStatType = 0; } } @@ -2214,7 +2190,7 @@ void ObjectMgr::LoadItemPrototypes() { if (proto->Damage[j].DamageType >= MAX_SPELL_SCHOOL) { - sLog.outErrorDb("Item (Entry: %u) has wrong dmg_type%d (%u)", i, j + 1, proto->Damage[j].DamageType); + sLog.outErrorDb("Item (Entry: %u) has wrong dmg_type%d (%u)", proto->ItemId, j + 1, proto->Damage[j].DamageType); const_cast(proto)->Damage[j].DamageType = 0; } } @@ -2225,7 +2201,7 @@ void ObjectMgr::LoadItemPrototypes() // spell_1 if (proto->Spells[0].SpellTrigger != ITEM_SPELLTRIGGER_ON_USE) { - sLog.outErrorDb("Item (Entry: %u) has wrong item spell trigger value in spelltrigger_%d (%u) for special learning format", i, 0 + 1, proto->Spells[0].SpellTrigger); + sLog.outErrorDb("Item (Entry: %u) has wrong item spell trigger value in spelltrigger_%d (%u) for special learning format", proto->ItemId, 0 + 1, proto->Spells[0].SpellTrigger); const_cast(proto)->Spells[0].SpellId = 0; const_cast(proto)->Spells[0].SpellTrigger = ITEM_SPELLTRIGGER_ON_USE; const_cast(proto)->Spells[1].SpellId = 0; @@ -2235,23 +2211,23 @@ void ObjectMgr::LoadItemPrototypes() // spell_2 have learning spell if (proto->Spells[1].SpellTrigger != ITEM_SPELLTRIGGER_LEARN_SPELL_ID) { - sLog.outErrorDb("Item (Entry: %u) has wrong item spell trigger value in spelltrigger_%d (%u) for special learning format.", i, 1 + 1, proto->Spells[1].SpellTrigger); + sLog.outErrorDb("Item (Entry: %u) has wrong item spell trigger value in spelltrigger_%d (%u) for special learning format.", proto->ItemId, 1 + 1, proto->Spells[1].SpellTrigger); const_cast(proto)->Spells[0].SpellId = 0; const_cast(proto)->Spells[1].SpellId = 0; const_cast(proto)->Spells[1].SpellTrigger = ITEM_SPELLTRIGGER_ON_USE; } else if (!proto->Spells[1].SpellId) { - sLog.outErrorDb("Item (Entry: %u) not has expected spell in spellid_%d in special learning format.", i, 1 + 1); + sLog.outErrorDb("Item (Entry: %u) not has expected spell in spellid_%d in special learning format.", proto->ItemId, 1 + 1); const_cast(proto)->Spells[0].SpellId = 0; const_cast(proto)->Spells[1].SpellTrigger = ITEM_SPELLTRIGGER_ON_USE; } else { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(proto->Spells[1].SpellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(proto->Spells[1].SpellId); if (!spellInfo) { - sLog.outErrorDb("Item (Entry: %u) has wrong (not existing) spell in spellid_%d (%u)", i, 1 + 1, proto->Spells[1].SpellId); + sLog.outErrorDb("Item (Entry: %u) has wrong (not existing) spell in spellid_%d (%u)", proto->ItemId, 1 + 1, proto->Spells[1].SpellId); const_cast(proto)->Spells[0].SpellId = 0; const_cast(proto)->Spells[1].SpellId = 0; const_cast(proto)->Spells[1].SpellTrigger = ITEM_SPELLTRIGGER_ON_USE; @@ -2259,7 +2235,7 @@ void ObjectMgr::LoadItemPrototypes() // allowed only in special format else if (proto->Spells[1].SpellId == SPELL_ID_GENERIC_LEARN) { - sLog.outErrorDb("Item (Entry: %u) has broken spell in spellid_%d (%u)", i, 1 + 1, proto->Spells[1].SpellId); + sLog.outErrorDb("Item (Entry: %u) has broken spell in spellid_%d (%u)", proto->ItemId, 1 + 1, proto->Spells[1].SpellId); const_cast(proto)->Spells[0].SpellId = 0; const_cast(proto)->Spells[1].SpellId = 0; const_cast(proto)->Spells[1].SpellTrigger = ITEM_SPELLTRIGGER_ON_USE; @@ -2271,13 +2247,13 @@ void ObjectMgr::LoadItemPrototypes() { if (proto->Spells[j].SpellTrigger != ITEM_SPELLTRIGGER_ON_USE) { - sLog.outErrorDb("Item (Entry: %u) has wrong item spell trigger value in spelltrigger_%d (%u)", i, j + 1, proto->Spells[j].SpellTrigger); + sLog.outErrorDb("Item (Entry: %u) has wrong item spell trigger value in spelltrigger_%d (%u)", proto->ItemId, j + 1, proto->Spells[j].SpellTrigger); const_cast(proto)->Spells[j].SpellId = 0; const_cast(proto)->Spells[j].SpellTrigger = ITEM_SPELLTRIGGER_ON_USE; } else if (proto->Spells[j].SpellId != 0) { - sLog.outErrorDb("Item (Entry: %u) has wrong spell in spellid_%d (%u) for learning special format", i, j + 1, proto->Spells[j].SpellId); + sLog.outErrorDb("Item (Entry: %u) has wrong spell in spellid_%d (%u) for learning special format", proto->ItemId, j + 1, proto->Spells[j].SpellId); const_cast(proto)->Spells[j].SpellId = 0; } } @@ -2289,7 +2265,7 @@ void ObjectMgr::LoadItemPrototypes() { if (proto->Spells[j].SpellTrigger >= MAX_ITEM_SPELLTRIGGER || proto->Spells[j].SpellTrigger == ITEM_SPELLTRIGGER_LEARN_SPELL_ID) { - sLog.outErrorDb("Item (Entry: %u) has wrong item spell trigger value in spelltrigger_%d (%u)", i, j + 1, proto->Spells[j].SpellTrigger); + sLog.outErrorDb("Item (Entry: %u) has wrong item spell trigger value in spelltrigger_%d (%u)", proto->ItemId, j + 1, proto->Spells[j].SpellTrigger); const_cast(proto)->Spells[j].SpellId = 0; const_cast(proto)->Spells[j].SpellTrigger = ITEM_SPELLTRIGGER_ON_USE; } @@ -2297,21 +2273,21 @@ void ObjectMgr::LoadItemPrototypes() else if (proto->Spells[j].SpellTrigger == ITEM_SPELLTRIGGER_CHANCE_ON_HIT) { if (proto->Class != ITEM_CLASS_WEAPON) - sLog.outErrorDb("Item (Entry: %u) isn't weapon (Class: %u) but has on hit spelltrigger_%d (%u), it will not triggered.", i, proto->Class, j + 1, proto->Spells[j].SpellTrigger); + sLog.outErrorDb("Item (Entry: %u) isn't weapon (Class: %u) but has on hit spelltrigger_%d (%u), it will not triggered.", proto->ItemId, proto->Class, j + 1, proto->Spells[j].SpellTrigger); } if (proto->Spells[j].SpellId) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(proto->Spells[j].SpellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(proto->Spells[j].SpellId); if (!spellInfo) { - sLog.outErrorDb("Item (Entry: %u) has wrong (not existing) spell in spellid_%d (%u)", i, j + 1, proto->Spells[j].SpellId); + sLog.outErrorDb("Item (Entry: %u) has wrong (not existing) spell in spellid_%d (%u)", proto->ItemId, j + 1, proto->Spells[j].SpellId); const_cast(proto)->Spells[j].SpellId = 0; } // allowed only in special format else if (proto->Spells[j].SpellId == SPELL_ID_GENERIC_LEARN) { - sLog.outErrorDb("Item (Entry: %u) has broken spell in spellid_%d (%u)", i, j + 1, proto->Spells[j].SpellId); + sLog.outErrorDb("Item (Entry: %u) has broken spell in spellid_%d (%u)", proto->ItemId, j + 1, proto->Spells[j].SpellId); const_cast(proto)->Spells[j].SpellId = 0; } } @@ -2319,32 +2295,32 @@ void ObjectMgr::LoadItemPrototypes() } if (proto->Bonding >= MAX_BIND_TYPE) - sLog.outErrorDb("Item (Entry: %u) has wrong Bonding value (%u)", i, proto->Bonding); + sLog.outErrorDb("Item (Entry: %u) has wrong Bonding value (%u)", proto->ItemId, proto->Bonding); if (proto->PageText) { - if (!sPageTextStore.LookupEntry(proto->PageText)) - sLog.outErrorDb("Item (Entry: %u) has non existing first page (Id:%u)", i, proto->PageText); + if (!sPageTextStore.LookupEntry(proto->PageText)) + sLog.outErrorDb("Item (Entry: %u) has non existing first page (Id:%u)", proto->ItemId, proto->PageText); } if (proto->LockID && !sLockStore.LookupEntry(proto->LockID)) - sLog.outErrorDb("Item (Entry: %u) has wrong LockID (%u)", i, proto->LockID); + sLog.outErrorDb("Item (Entry: %u) has wrong LockID (%u)", proto->ItemId, proto->LockID); if (proto->Sheath >= MAX_SHEATHETYPE) { - sLog.outErrorDb("Item (Entry: %u) has wrong Sheath (%u)", i, proto->Sheath); + sLog.outErrorDb("Item (Entry: %u) has wrong Sheath (%u)", proto->ItemId, proto->Sheath); const_cast(proto)->Sheath = SHEATHETYPE_NONE; } if (proto->RandomProperty && !sItemRandomPropertiesStore.LookupEntry(GetItemEnchantMod(proto->RandomProperty))) { - sLog.outErrorDb("Item (Entry: %u) has unknown (wrong or not listed in `item_enchantment_template`) RandomProperty (%u)", i, proto->RandomProperty); + sLog.outErrorDb("Item (Entry: %u) has unknown (wrong or not listed in `item_enchantment_template`) RandomProperty (%u)", proto->ItemId, proto->RandomProperty); const_cast(proto)->RandomProperty = 0; } if (proto->RandomSuffix && !sItemRandomSuffixStore.LookupEntry(GetItemEnchantMod(proto->RandomSuffix))) { - sLog.outErrorDb("Item (Entry: %u) has wrong RandomSuffix (%u)", i, proto->RandomSuffix); + sLog.outErrorDb("Item (Entry: %u) has wrong RandomSuffix (%u)", proto->ItemId, proto->RandomSuffix); const_cast(proto)->RandomSuffix = 0; } @@ -2358,15 +2334,15 @@ void ObjectMgr::LoadItemPrototypes() if (proto->ItemSet && !sItemSetStore.LookupEntry(proto->ItemSet)) { - sLog.outErrorDb("Item (Entry: %u) have wrong ItemSet (%u)", i, proto->ItemSet); + sLog.outErrorDb("Item (Entry: %u) have wrong ItemSet (%u)", proto->ItemId, proto->ItemSet); const_cast(proto)->ItemSet = 0; } - if (proto->Area && !GetAreaEntryByAreaID(proto->Area)) - sLog.outErrorDb("Item (Entry: %u) has wrong Area (%u)", i, proto->Area); + if (proto->Area && !TerrainManager::GetAreaEntryByAreaID(proto->Area)) + sLog.outErrorDb("Item (Entry: %u) has wrong Area (%u)", proto->ItemId, proto->Area); if (proto->Map && !sMapStore.LookupEntry(proto->Map)) - sLog.outErrorDb("Item (Entry: %u) has wrong Map (%u)", i, proto->Map); + sLog.outErrorDb("Item (Entry: %u) has wrong Map (%u)", proto->ItemId, proto->Map); if (proto->BagFamily) { @@ -2380,30 +2356,30 @@ void ObjectMgr::LoadItemPrototypes() ItemBagFamilyEntry const* bf = sItemBagFamilyStore.LookupEntry(j + 1); if (!bf) { - sLog.outErrorDb("Item (Entry: %u) has bag family bit set not listed in ItemBagFamily.dbc, remove bit", i); + sLog.outErrorDb("Item (Entry: %u) has bag family bit set not listed in ItemBagFamily.dbc, remove bit", proto->ItemId); const_cast(proto)->BagFamily &= ~mask; } } } if (proto->TotemCategory && !sTotemCategoryStore.LookupEntry(proto->TotemCategory)) - sLog.outErrorDb("Item (Entry: %u) has wrong TotemCategory (%u)", i, proto->TotemCategory); + sLog.outErrorDb("Item (Entry: %u) has wrong TotemCategory (%u)", proto->ItemId, proto->TotemCategory); for (int j = 0; j < MAX_ITEM_PROTO_SOCKETS; ++j) { if (proto->Socket[j].Color && (proto->Socket[j].Color & SOCKET_COLOR_ALL) != proto->Socket[j].Color) { - sLog.outErrorDb("Item (Entry: %u) has wrong socketColor_%d (%u)", i, j + 1, proto->Socket[j].Color); + sLog.outErrorDb("Item (Entry: %u) has wrong socketColor_%d (%u)", proto->ItemId, j + 1, proto->Socket[j].Color); const_cast(proto)->Socket[j].Color = 0; } } if (proto->GemProperties && !sGemPropertiesStore.LookupEntry(proto->GemProperties)) - sLog.outErrorDb("Item (Entry: %u) has wrong GemProperties (%u)", i, proto->GemProperties); + sLog.outErrorDb("Item (Entry: %u) has wrong GemProperties (%u)", proto->ItemId, proto->GemProperties); if (proto->RequiredDisenchantSkill < -1) { - sLog.outErrorDb("Item (Entry: %u) has wrong RequiredDisenchantSkill (%i), set to (-1).", i, proto->RequiredDisenchantSkill); + sLog.outErrorDb("Item (Entry: %u) has wrong RequiredDisenchantSkill (%i), set to (-1).", proto->ItemId, proto->RequiredDisenchantSkill); const_cast(proto)->RequiredDisenchantSkill = -1; } else if (proto->RequiredDisenchantSkill != -1) @@ -2411,14 +2387,14 @@ void ObjectMgr::LoadItemPrototypes() if (proto->Quality > ITEM_QUALITY_EPIC || proto->Quality < ITEM_QUALITY_UNCOMMON) { ERROR_DB_STRICT_LOG("Item (Entry: %u) has unexpected RequiredDisenchantSkill (%u) for non-disenchantable quality (%u), reset it.", - i, proto->RequiredDisenchantSkill, proto->Quality); + proto->ItemId, proto->RequiredDisenchantSkill, proto->Quality); const_cast(proto)->RequiredDisenchantSkill = -1; } else if (proto->Class != ITEM_CLASS_WEAPON && proto->Class != ITEM_CLASS_ARMOR) { // some wrong data in wdb for unused items ERROR_DB_STRICT_LOG("Item (Entry: %u) has unexpected RequiredDisenchantSkill (%u) for non-disenchantable item class (%u), reset it.", - i, proto->RequiredDisenchantSkill, proto->Class); + proto->ItemId, proto->RequiredDisenchantSkill, proto->Class); const_cast(proto)->RequiredDisenchantSkill = -1; } } @@ -2427,17 +2403,17 @@ void ObjectMgr::LoadItemPrototypes() { if (proto->Quality > ITEM_QUALITY_EPIC || proto->Quality < ITEM_QUALITY_UNCOMMON) { - sLog.outErrorDb("Item (Entry: %u) has wrong quality (%u) for disenchanting, remove disenchanting loot id.", i, proto->Quality); + sLog.outErrorDb("Item (Entry: %u) has wrong quality (%u) for disenchanting, remove disenchanting loot id.", proto->ItemId, proto->Quality); const_cast(proto)->DisenchantID = 0; } else if (proto->Class != ITEM_CLASS_WEAPON && proto->Class != ITEM_CLASS_ARMOR) { - sLog.outErrorDb("Item (Entry: %u) has wrong item class (%u) for disenchanting, remove disenchanting loot id.", i, proto->Class); + sLog.outErrorDb("Item (Entry: %u) has wrong item class (%u) for disenchanting, remove disenchanting loot id.", proto->ItemId, proto->Class); const_cast(proto)->DisenchantID = 0; } else if (proto->RequiredDisenchantSkill < 0) { - sLog.outErrorDb("Item (Entry: %u) marked as non-disenchantable by RequiredDisenchantSkill == -1, remove disenchanting loot id.", i); + sLog.outErrorDb("Item (Entry: %u) marked as non-disenchantable by RequiredDisenchantSkill == -1, remove disenchanting loot id.", proto->ItemId); const_cast(proto)->DisenchantID = 0; } } @@ -2445,25 +2421,25 @@ void ObjectMgr::LoadItemPrototypes() { // lot DB cases if (proto->RequiredDisenchantSkill >= 0) - ERROR_DB_STRICT_LOG("Item (Entry: %u) marked as disenchantable by RequiredDisenchantSkill, but not have disenchanting loot id.", i); + ERROR_DB_STRICT_LOG("Item (Entry: %u) marked as disenchantable by RequiredDisenchantSkill, but not have disenchanting loot id.", proto->ItemId); } if (proto->FoodType >= MAX_PET_DIET) { - sLog.outErrorDb("Item (Entry: %u) has wrong FoodType value (%u)", i, proto->FoodType); + sLog.outErrorDb("Item (Entry: %u) has wrong FoodType value (%u)", proto->ItemId, proto->FoodType); const_cast(proto)->FoodType = 0; } if (proto->ExtraFlags) { if (proto->ExtraFlags & ~ITEM_EXTRA_ALL) - sLog.outErrorDb("Item (Entry: %u) has wrong ExtraFlags (%u) with unused bits set", i, proto->ExtraFlags); + sLog.outErrorDb("Item (Entry: %u) has wrong ExtraFlags (%u) with unused bits set", proto->ItemId, proto->ExtraFlags); if (proto->ExtraFlags & ITEM_EXTRA_REAL_TIME_DURATION) { if (proto->Duration == 0) { - sLog.outErrorDb("Item (Entry: %u) has redundant real-time duration flag in ExtraFlags, item not have duration", i); + sLog.outErrorDb("Item (Entry: %u) has redundant real-time duration flag in ExtraFlags, item not have duration", proto->ItemId); const_cast(proto)->ExtraFlags &= ~ITEM_EXTRA_REAL_TIME_DURATION; } } @@ -2472,12 +2448,8 @@ void ObjectMgr::LoadItemPrototypes() // check some dbc referenced items (avoid duplicate reports) std::set notFoundOutfit; - for (uint32 i = 1; i < sCharStartOutfitStore.GetNumRows(); ++i) + for (auto entry : sCharStartOutfitStore) { - CharStartOutfitEntry const* entry = sCharStartOutfitStore.LookupEntry(i); - if (!entry) - continue; - for (int j : entry->ItemId) { if (j <= 0) @@ -2493,7 +2465,7 @@ void ObjectMgr::LoadItemPrototypes() for (uint32 itr : notFoundOutfit) sLog.outErrorDb("Item (Entry: %u) not exist in `item_template` but referenced in `CharStartOutfit.dbc`", itr); - sLog.outString(">> Loaded %u item prototypes", sItemStorage.GetRecordCount()); + sLog.outString(">> Loaded %u item prototypes", sItemStorage.GetNumRows()); sLog.outString(); } @@ -2525,7 +2497,7 @@ void ObjectMgr::LoadItemRequiredTarget() uint32 uiType = fields[1].GetUInt32(); uint32 uiTargetEntry = fields[2].GetUInt32(); - ItemPrototype const* pItemProto = sItemStorage.LookupEntry(uiItemId); + ItemPrototype const* pItemProto = sItemStorage.LookupEntry(uiItemId); if (!pItemProto) { @@ -2537,11 +2509,11 @@ void ObjectMgr::LoadItemRequiredTarget() for (const auto& Spell : pItemProto->Spells) { - if (SpellEntry const* pSpellInfo = sSpellTemplate.LookupEntry(Spell.SpellId)) + if (SpellEntry const* pSpellInfo = sSpellTemplate.LookupEntry(Spell.SpellId)) { if (Spell.SpellTrigger == ITEM_SPELLTRIGGER_ON_USE) { - SQLMultiStorage::SQLMSIteratorBounds bounds = sSpellScriptTargetStorage.getBounds(pSpellInfo->Id); + auto bounds = sSpellScriptTargetStorage.getBounds(pSpellInfo->Id); if (bounds.first != bounds.second) break; @@ -2580,7 +2552,7 @@ void ObjectMgr::LoadItemRequiredTarget() continue; } - if (!sCreatureStorage.LookupEntry(uiTargetEntry)) + if (!sCreatureStorage.LookupEntry(uiTargetEntry)) { sLog.outErrorDb("Table `item_required_target`: creature template entry %u does not exist.", uiTargetEntry); continue; @@ -2623,7 +2595,7 @@ void ObjectMgr::LoadPetLevelInfo() Field* fields = result->Fetch(); uint32 creature_id = fields[0].GetUInt32(); - if (!sCreatureStorage.LookupEntry(creature_id)) + if (!sCreatureStorage.LookupEntry(creature_id)) { sLog.outErrorDb("Wrong creature id %u in `pet_levelstats` table, ignoring.", creature_id); continue; @@ -3020,7 +2992,7 @@ void ObjectMgr::LoadPlayerInfo() } uint32 spell_id = fields[2].GetUInt32(); - if (!sSpellTemplate.LookupEntry(spell_id)) + if (!sSpellTemplate.LookupEntry(spell_id)) { sLog.outErrorDb("Non existing spell %u in `playercreateinfo_spell` table, ignoring.", spell_id); continue; @@ -3503,19 +3475,19 @@ CreatureTemplateSpells const* ObjectMgr::GetCreatureTemplateSpellSet(uint32 entr /* ********************************************************************************************* */ /* * Static Wrappers */ /* ********************************************************************************************* */ -GameObjectInfo const* ObjectMgr::GetGameObjectInfo(uint32 id) { return sGOStorage.LookupEntry(id); } +GameObjectInfo const* ObjectMgr::GetGameObjectInfo(uint32 id) { return sGOStorage.LookupEntry(id); } Player* ObjectMgr::GetPlayer(const char* name) { return ObjectAccessor::FindPlayerByName(name); } Player* ObjectMgr::GetPlayer(ObjectGuid guid, bool inWorld /*=true*/) { return ObjectAccessor::FindPlayer(guid, inWorld); } -CreatureInfo const* ObjectMgr::GetCreatureTemplate(uint32 id) { return sCreatureStorage.LookupEntry(id); } -CreatureModelInfo const* ObjectMgr::GetCreatureModelInfo(uint32 modelid) { return sCreatureModelStorage.LookupEntry(modelid); } -EquipmentInfo const* ObjectMgr::GetEquipmentInfo(uint32 entry) { return sEquipmentStorage.LookupEntry(entry); } -EquipmentInfoRaw const* ObjectMgr::GetEquipmentInfoRaw(uint32 entry) { return sEquipmentStorageRaw.LookupEntry(entry); } -CreatureDataAddon const* ObjectMgr::GetCreatureAddon(uint32 lowguid) { return sCreatureDataAddonStorage.LookupEntry(lowguid); } -CreatureDataAddon const* ObjectMgr::GetCreatureTemplateAddon(uint32 entry) { return sCreatureInfoAddonStorage.LookupEntry(entry); } -ItemPrototype const* ObjectMgr::GetItemPrototype(uint32 id) { return sItemStorage.LookupEntry(id); } -InstanceTemplate const* ObjectMgr::GetInstanceTemplate(uint32 map) { return sInstanceTemplate.LookupEntry(map); } -WorldTemplate const* ObjectMgr::GetWorldTemplate(uint32 map) { return sWorldTemplate.LookupEntry(map); } -CreatureConditionalSpawn const* ObjectMgr::GetCreatureConditionalSpawn(uint32 lowguid) { return sCreatureConditionalSpawnStore.LookupEntry(lowguid); } +CreatureInfo const* ObjectMgr::GetCreatureTemplate(uint32 id) { return sCreatureStorage.LookupEntry(id); } +CreatureModelInfo const* ObjectMgr::GetCreatureModelInfo(uint32 modelid) { return sCreatureModelStorage.LookupEntry(modelid); } +EquipmentInfo const* ObjectMgr::GetEquipmentInfo(uint32 entry) { return sEquipmentStorage.LookupEntry(entry); } +EquipmentInfoRaw const* ObjectMgr::GetEquipmentInfoRaw(uint32 entry) { return sEquipmentStorageRaw.LookupEntry(entry); } +CreatureDataAddon const* ObjectMgr::GetCreatureAddon(uint32 lowguid) { return sCreatureDataAddonStorage.LookupEntry(lowguid); } +CreatureDataAddon const* ObjectMgr::GetCreatureTemplateAddon(uint32 entry) { return sCreatureInfoAddonStorage.LookupEntry(entry); } +ItemPrototype const* ObjectMgr::GetItemPrototype(uint32 id) { return sItemStorage.LookupEntry(id); } +InstanceTemplate const* ObjectMgr::GetInstanceTemplate(uint32 map) { return sInstanceTemplate.LookupEntry(map); } +WorldTemplate const* ObjectMgr::GetWorldTemplate(uint32 map) { return sWorldTemplate.LookupEntry(map); } +CreatureConditionalSpawn const* ObjectMgr::GetCreatureConditionalSpawn(uint32 lowguid) { return sCreatureConditionalSpawnStore.LookupEntry(lowguid); } /* ********************************************************************************************* */ /* * Loading Functions */ @@ -3781,7 +3753,7 @@ void ObjectMgr::LoadQuests() "RewHonorableKills, RewOrReqMoney, RewMoneyMaxLevel, RewSpell, RewSpellCast, RewMailTemplateId, RewMailDelaySecs, PointMapId, PointX, PointY, PointOpt," // 107 108 109 110 111 112 113 114 "DetailsEmote1, DetailsEmote2, DetailsEmote3, DetailsEmote4, DetailsEmoteDelay1, DetailsEmoteDelay2, DetailsEmoteDelay3, DetailsEmoteDelay4," - // 115 116 117 118 119 120 121 122 + // 115 116 117 118 119 120 121 122 "IncompleteEmote, IncompleteEmoteDelay, CompleteEmote, CompleteEmoteDelay, OfferRewardEmote1, OfferRewardEmote2, OfferRewardEmote3, OfferRewardEmote4," // 123 124 125 126 "OfferRewardEmoteDelay1, OfferRewardEmoteDelay2, OfferRewardEmoteDelay3, OfferRewardEmoteDelay4," @@ -3886,7 +3858,7 @@ void ObjectMgr::LoadQuests() // client quest log visual (area case) if (qinfo->ZoneOrSort > 0) { - if (!GetAreaEntryByAreaID(qinfo->ZoneOrSort)) + if (!TerrainManager::GetAreaEntryByAreaID(qinfo->ZoneOrSort)) { sLog.outErrorDb("Quest %u has `ZoneOrSort` = %u (zone case) but zone with this id does not exist.", qinfo->GetQuestId(), qinfo->ZoneOrSort); @@ -3946,21 +3918,21 @@ void ObjectMgr::LoadQuests() } // else Skill quests can have 0 skill level, this is ok - if (qinfo->RepObjectiveFaction && !sFactionStore.LookupEntry(qinfo->RepObjectiveFaction)) + if (qinfo->RepObjectiveFaction && !sFactionStore.LookupEntry(qinfo->RepObjectiveFaction)) { sLog.outErrorDb("Quest %u has `RepObjectiveFaction` = %u but faction template %u does not exist, quest can't be done.", qinfo->GetQuestId(), qinfo->RepObjectiveFaction, qinfo->RepObjectiveFaction); // no changes, quest can't be done for this requirement } - if (qinfo->RequiredMinRepFaction && !sFactionStore.LookupEntry(qinfo->RequiredMinRepFaction)) + if (qinfo->RequiredMinRepFaction && !sFactionStore.LookupEntry(qinfo->RequiredMinRepFaction)) { sLog.outErrorDb("Quest %u has `RequiredMinRepFaction` = %u but faction template %u does not exist, quest can't be done.", qinfo->GetQuestId(), qinfo->RequiredMinRepFaction, qinfo->RequiredMinRepFaction); // no changes, quest can't be done for this requirement } - if (qinfo->RequiredMaxRepFaction && !sFactionStore.LookupEntry(qinfo->RequiredMaxRepFaction)) + if (qinfo->RequiredMaxRepFaction && !sFactionStore.LookupEntry(qinfo->RequiredMaxRepFaction)) { sLog.outErrorDb("Quest %u has `RequiredMaxRepFaction` = %u but faction template %u does not exist, quest can't be done.", qinfo->GetQuestId(), qinfo->RequiredMaxRepFaction, qinfo->RequiredMaxRepFaction); @@ -4012,7 +3984,7 @@ void ObjectMgr::LoadQuests() if (qinfo->SrcItemId) { - if (!sItemStorage.LookupEntry(qinfo->SrcItemId)) + if (!sItemStorage.LookupEntry(qinfo->SrcItemId)) { sLog.outErrorDb("Quest %u has `SrcItemId` = %u but item with entry %u does not exist, quest can't be done.", qinfo->GetQuestId(), qinfo->SrcItemId, qinfo->SrcItemId); @@ -4034,7 +4006,7 @@ void ObjectMgr::LoadQuests() if (qinfo->SrcSpell) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(qinfo->SrcSpell); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(qinfo->SrcSpell); if (!spellInfo) { sLog.outErrorDb("Quest %u has `SrcSpell` = %u but spell %u doesn't exist, quest can't be done.", @@ -4062,7 +4034,7 @@ void ObjectMgr::LoadQuests() qinfo->SetSpecialFlag(QUEST_SPECIAL_FLAG_DELIVER); - if (!sItemStorage.LookupEntry(id)) + if (!sItemStorage.LookupEntry(id)) { sLog.outErrorDb("Quest %u has `ReqItemId%d` = %u but item with entry %u does not exist, quest can't be done.", qinfo->GetQuestId(), j + 1, id, id); @@ -4081,7 +4053,7 @@ void ObjectMgr::LoadQuests() { if (uint32 id = qinfo->ReqSourceId[j]) { - if (!sItemStorage.LookupEntry(id)) + if (!sItemStorage.LookupEntry(id)) { sLog.outErrorDb("Quest %u has `ReqSourceId%d` = %u but item with entry %u does not exist, quest can't be done.", qinfo->GetQuestId(), j + 1, id, id); @@ -4103,7 +4075,7 @@ void ObjectMgr::LoadQuests() { if (uint32 id = qinfo->ReqSpell[j]) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(id); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(id); if (!spellInfo) { sLog.outErrorDb("Quest %u has `ReqSpellCast%d` = %u but spell %u does not exist, quest can't be done.", @@ -4147,14 +4119,14 @@ void ObjectMgr::LoadQuests() for (int j = 0; j < QUEST_OBJECTIVES_COUNT; ++j) { int32 id = qinfo->ReqCreatureOrGOId[j]; - if (id < 0 && !sGOStorage.LookupEntry(-id)) + if (id < 0 && !sGOStorage.LookupEntry(-id)) { sLog.outErrorDb("Quest %u has `ReqCreatureOrGOId%d` = %i but gameobject %u does not exist, quest can't be done.", qinfo->GetQuestId(), j + 1, id, uint32(-id)); qinfo->ReqCreatureOrGOId[j] = 0; // quest can't be done for this requirement } - if (id > 0 && !sCreatureStorage.LookupEntry(id)) + if (id > 0 && !sCreatureStorage.LookupEntry(id)) { sLog.outErrorDb("Quest %u has `ReqCreatureOrGOId%d` = %i but creature with entry %u does not exist, quest can't be done.", qinfo->GetQuestId(), j + 1, id, uint32(id)); @@ -4187,7 +4159,7 @@ void ObjectMgr::LoadQuests() { if (uint32 id = qinfo->RewChoiceItemId[j]) { - if (!sItemStorage.LookupEntry(id)) + if (!sItemStorage.LookupEntry(id)) { sLog.outErrorDb("Quest %u has `RewChoiceItemId%d` = %u but item with entry %u does not exist, quest will not reward this item.", qinfo->GetQuestId(), j + 1, id, id); @@ -4223,7 +4195,7 @@ void ObjectMgr::LoadQuests() { if (uint32 id = qinfo->RewItemId[j]) { - if (!sItemStorage.LookupEntry(id)) + if (!sItemStorage.LookupEntry(id)) { sLog.outErrorDb("Quest %u has `RewItemId%d` = %u but item with entry %u does not exist, quest will not reward this item.", qinfo->GetQuestId(), j + 1, id, id); @@ -4253,7 +4225,7 @@ void ObjectMgr::LoadQuests() sLog.outErrorDb("Quest %u has `RewRepFaction%d` = %u but `RewRepValue%d` = 0, quest will not reward this reputation.", qinfo->GetQuestId(), j + 1, qinfo->RewRepValue[j], j + 1); - if (!sFactionStore.LookupEntry(qinfo->RewRepFaction[j])) + if (!sFactionStore.LookupEntry(qinfo->RewRepFaction[j])) { sLog.outErrorDb("Quest %u has `RewRepFaction%d` = %u but raw faction (faction.dbc) %u does not exist, quest will not reward reputation for this faction.", qinfo->GetQuestId(), j + 1, qinfo->RewRepFaction[j], qinfo->RewRepFaction[j]); @@ -4270,7 +4242,7 @@ void ObjectMgr::LoadQuests() if (qinfo->RewSpell) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(qinfo->RewSpell); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(qinfo->RewSpell); if (!spellInfo) { @@ -4294,7 +4266,7 @@ void ObjectMgr::LoadQuests() if (qinfo->RewSpellCast) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(qinfo->RewSpellCast); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(qinfo->RewSpellCast); if (!spellInfo) { @@ -4385,12 +4357,8 @@ void ObjectMgr::LoadQuests() } // check QUEST_SPECIAL_FLAG_EXPLORATION_OR_EVENT for spell with SPELL_EFFECT_QUEST_COMPLETE - for (uint32 i = 0; i < sSpellTemplate.GetMaxEntry(); ++i) + for (auto spellInfo : sSpellTemplate) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(i); - if (!spellInfo) - continue; - for (int j = 0; j < MAX_EFFECT_INDEX; ++j) { if (spellInfo->Effect[j] != SPELL_EFFECT_QUEST_COMPLETE) @@ -4592,7 +4560,7 @@ void ObjectMgr::LoadPetCreateSpells() continue; } - CreatureInfo const* cInfo = sCreatureStorage.LookupEntry(creature_id); + CreatureInfo const* cInfo = sCreatureStorage.LookupEntry(creature_id); if (!cInfo) { sLog.outErrorDb("Creature id %u listed in `petcreateinfo_spell` not exist.", creature_id); @@ -4618,7 +4586,7 @@ void ObjectMgr::LoadPetCreateSpells() have_spell_db = true; - SpellEntry const* i_spell = sSpellTemplate.LookupEntry(PetCreateSpell.spellid[i]); + SpellEntry const* i_spell = sSpellTemplate.LookupEntry(PetCreateSpell.spellid[i]); if (!i_spell) { sLog.outErrorDb("Spell %u listed in `petcreateinfo_spell` does not exist", PetCreateSpell.spellid[i]); @@ -4647,12 +4615,8 @@ void ObjectMgr::LoadPetCreateSpells() // cache spell->learn spell map for use in next loop std::map learnCache; - for (uint32 spell_id = 1; spell_id < sSpellTemplate.GetMaxEntry(); ++spell_id) + for (auto spellproto : sSpellTemplate) { - SpellEntry const* spellproto = sSpellTemplate.LookupEntry(spell_id); - if (!spellproto) - continue; - if (spellproto->Effect[0] != SPELL_EFFECT_LEARN_SPELL && spellproto->Effect[0] != SPELL_EFFECT_LEARN_PET_SPELL) continue; @@ -4664,12 +4628,8 @@ void ObjectMgr::LoadPetCreateSpells() // fill data from DBC as more correct source if available uint32 dcount = 0; - for (uint32 cr_id = 1; cr_id < sCreatureStorage.GetMaxEntry(); ++cr_id) + for (auto cInfo : sCreatureStorage) { - CreatureInfo const* cInfo = sCreatureStorage.LookupEntry(cr_id); - if (!cInfo) - continue; - CreatureSpellDataEntry const* petSpellEntry = cInfo->PetSpellDataId ? sCreatureSpellDataStore.LookupEntry(cInfo->PetSpellDataId) : nullptr; if (!petSpellEntry) continue; @@ -4689,7 +4649,7 @@ void ObjectMgr::LoadPetCreateSpells() PetCreateSpell.spellid[i] = petspell_id; } - mPetCreateSpell[cr_id] = PetCreateSpell; + mPetCreateSpell[cInfo->Entry] = PetCreateSpell; ++dcount; } @@ -4737,25 +4697,20 @@ void ObjectMgr::LoadItemTexts() void ObjectMgr::LoadPageTexts() { sPageTextStore.Load(); - sLog.outString(">> Loaded %u page texts", sPageTextStore.GetRecordCount()); + sLog.outString(">> Loaded %u page texts", sPageTextStore.GetNumRows()); sLog.outString(); - for (uint32 i = 1; i < sPageTextStore.GetMaxEntry(); ++i) + for (auto page : sPageTextStore) { - // check data correctness - PageText const* page = sPageTextStore.LookupEntry(i); - if (!page) - continue; - - if (page->Next_Page && !sPageTextStore.LookupEntry(page->Next_Page)) + if (page->Next_Page && !sPageTextStore.LookupEntry(page->Next_Page)) { - sLog.outErrorDb("Page text (Id: %u) has not existing next page (Id:%u)", i, page->Next_Page); + sLog.outErrorDb("Page text (Id: %u) has not existing next page (Id:%u)", page->Page_ID, page->Next_Page); continue; } // detect circular reference std::set checkedPages; - for (PageText const* pageItr = page; pageItr; pageItr = sPageTextStore.LookupEntry(pageItr->Next_Page)) + for (PageText const* pageItr = page; pageItr; pageItr = sPageTextStore.LookupEntry(pageItr->Next_Page)) { if (!pageItr->Next_Page) break; @@ -4799,7 +4754,7 @@ void ObjectMgr::LoadPageTextLocales() uint32 entry = fields[0].GetUInt32(); - if (!sPageTextStore.LookupEntry(entry)) + if (!sPageTextStore.LookupEntry(entry)) { ERROR_DB_STRICT_LOG("Table `locales_page_text` has data for nonexistent page text entry %u, skipped.", entry); continue; @@ -4854,7 +4809,7 @@ void ObjectMgr::LoadInstanceEncounters() bar.step(); uint32 entry = fields[0].GetUInt32(); - DungeonEncounterEntry const* dungeonEncounter = sDungeonEncounterStore.LookupEntry(entry); + DungeonEncounterEntry const* dungeonEncounter = sDungeonEncounterStore.LookupEntry(entry); if (!dungeonEncounter) { @@ -4868,7 +4823,7 @@ void ObjectMgr::LoadInstanceEncounters() { case ENCOUNTER_CREDIT_KILL_CREATURE: { - CreatureInfo const* cInfo = sCreatureStorage.LookupEntry(creditEntry); + CreatureInfo const* cInfo = sCreatureStorage.LookupEntry(creditEntry); if (!cInfo) { sLog.outErrorDb("Table `instance_encounters` has an invalid creature (entry %u) linked to the encounter %u (%s), skipped!", creditEntry, entry, dungeonEncounter->encounterName[0]); @@ -4878,7 +4833,7 @@ void ObjectMgr::LoadInstanceEncounters() } case ENCOUNTER_CREDIT_CAST_SPELL: { - if (!sSpellTemplate.LookupEntry(creditEntry)) + if (!sSpellTemplate.LookupEntry(creditEntry)) { // skip spells that aren't in dbc for now // sLog.outErrorDb("Table `instance_encounters` has an invalid spell (entry %u) linked to the encounter %u (%s), skipped!", creditEntry, entry, dungeonEncounter->encounterName[0]); @@ -4902,7 +4857,7 @@ void ObjectMgr::LoadInstanceEncounters() sLog.outString(); } -struct SQLInstanceLoader : public SQLStorageLoaderBase +struct SQLInstanceLoader : public SQLStorageLoaderBase> { template void convert_from_str(uint32 /*field_pos*/, char const* src, D& dst) @@ -4916,24 +4871,20 @@ void ObjectMgr::LoadInstanceTemplate() SQLInstanceLoader loader; loader.Load(sInstanceTemplate); - for (uint32 i = 0; i < sInstanceTemplate.GetMaxEntry(); ++i) + for (auto temp : sInstanceTemplate) { - InstanceTemplate const* temp = GetInstanceTemplate(i); - if (!temp) - continue; - MapEntry const* mapEntry = sMapStore.LookupEntry(temp->map); if (!mapEntry) { sLog.outErrorDb("ObjectMgr::LoadInstanceTemplate: bad mapid %d for template!", temp->map); - sInstanceTemplate.EraseEntry(i); + sInstanceTemplate.EraseEntry(temp->map); continue; } if (!mapEntry->Instanceable()) { sLog.outErrorDb("ObjectMgr::LoadInstanceTemplate: non-instanceable mapid %d for template!", temp->map); - sInstanceTemplate.EraseEntry(i); + sInstanceTemplate.EraseEntry(temp->map); continue; } @@ -4977,11 +4928,11 @@ void ObjectMgr::LoadInstanceTemplate() } } - sLog.outString(">> Loaded %u Instance Template definitions", sInstanceTemplate.GetRecordCount()); + sLog.outString(">> Loaded %u Instance Template definitions", sInstanceTemplate.GetNumRows()); sLog.outString(); } -struct SQLWorldLoader : public SQLStorageLoaderBase +struct SQLWorldLoader : public SQLStorageLoaderBase> { template void convert_from_str(uint32 /*field_pos*/, char const* src, D& dst) @@ -4995,46 +4946,47 @@ void ObjectMgr::LoadWorldTemplate() SQLWorldLoader loader; loader.Load(sWorldTemplate, false); - for (uint32 i = 0; i < sWorldTemplate.GetMaxEntry(); ++i) + for (auto temp : sWorldTemplate) { - WorldTemplate const* temp = GetWorldTemplate(i); - if (!temp) - continue; - MapEntry const* mapEntry = sMapStore.LookupEntry(temp->map); if (!mapEntry) { sLog.outErrorDb("ObjectMgr::LoadWorldTemplate: bad mapid %d for template!", temp->map); - sWorldTemplate.EraseEntry(i); + sWorldTemplate.EraseEntry(temp->map); continue; } if (mapEntry->Instanceable()) { sLog.outErrorDb("ObjectMgr::LoadWorldTemplate: instanceable mapid %d for template!", temp->map); - sWorldTemplate.EraseEntry(i); + sWorldTemplate.EraseEntry(temp->map); } } - sLog.outString(">> Loaded %u World Template definitions", sWorldTemplate.GetRecordCount()); + sLog.outString(">> Loaded %u World Template definitions", sWorldTemplate.GetNumRows()); sLog.outString(); } +struct SQLConditionLoader : public SQLStorageLoaderBase> +{ + template + void convert_from_str(uint32 /*field_pos*/, char const* src, D& dst) + { + dst = D(sScriptDevAIMgr.GetScriptId(src)); + } +}; + void ObjectMgr::LoadConditions() { - SQLWorldLoader loader; + SQLConditionLoader loader; loader.Load(sConditionStorage); - for (uint32 i = 0; i < sConditionStorage.GetMaxEntry(); ++i) + for (auto condition : sConditionStorage) { - ConditionEntry const* condition = sConditionStorage.LookupEntry(i); - if (!condition) - continue; - if (!condition->IsValid()) { - sLog.outErrorDb("ObjectMgr::LoadConditions: invalid condition_entry %u, skip", i); - sConditionStorage.EraseEntry(i); + sLog.outErrorDb("ObjectMgr::LoadConditions: invalid condition_entry %u, skip", condition->GetEntry()); + sConditionStorage.EraseEntry(condition->GetEntry()); continue; } } @@ -5045,13 +4997,13 @@ void ObjectMgr::LoadConditions() if (qinfo->RequiredCondition) { - const ConditionEntry* condition = sConditionStorage.LookupEntry(qinfo->RequiredCondition); + const ConditionEntry* condition = sConditionStorage.LookupEntry(qinfo->RequiredCondition); if (!condition) // condition does not exist for some reason sLog.outErrorDb("Quest %u has `RequiredCondition` = %u but does not exist.", qinfo->GetQuestId(), qinfo->RequiredCondition); } } - sLog.outString(">> Loaded %u Condition definitions", sConditionStorage.GetRecordCount()); + sLog.outString(">> Loaded %u Condition definitions", sConditionStorage.GetNumRows()); sLog.outString(); } @@ -5119,7 +5071,7 @@ void ObjectMgr::LoadGossipText() sLog.outString(); result.reset(WorldDatabase.Query("SELECT Id,Prob0,Prob1,Prob2,Prob3,Prob4,Prob5,Prob6,Prob7,BroadcastTextId0,BroadcastTextId1,BroadcastTextId2,BroadcastTextId3,BroadcastTextId4,BroadcastTextId5,BroadcastTextId6,BroadcastTextId7 FROM npc_text_broadcast_text")); - + count = 0; if (!result) { @@ -5302,14 +5254,14 @@ void ObjectMgr::LoadQuestgiverGreeting() switch (type) { case QUESTGIVER_CREATURE: - if (!sCreatureStorage.LookupEntry(entry)) + if (!sCreatureStorage.LookupEntry(entry)) { sLog.outErrorEventAI("Table questgiver_greeting uses nonexistent creature entry %u. Skipping.", entry); continue; } break; case QUESTGIVER_GAMEOBJECT: - if (!sGOStorage.LookupEntry(entry)) + if (!sGOStorage.LookupEntry(entry)) { sLog.outErrorEventAI("Table questgiver_greeting uses nonexistent gameobject entry %u. Skipping.", entry); continue; @@ -5370,14 +5322,14 @@ void ObjectMgr::LoadQuestgiverGreetingLocales() switch (type) { case QUESTGIVER_CREATURE: - if (!sCreatureStorage.LookupEntry(entry)) + if (!sCreatureStorage.LookupEntry(entry)) { sLog.outErrorEventAI("Table questgiver_greeting uses nonexistent creature entry %u. Skipping.", entry); continue; } break; case QUESTGIVER_GAMEOBJECT: - if (!sGOStorage.LookupEntry(entry)) + if (!sGOStorage.LookupEntry(entry)) { sLog.outErrorEventAI("Table questgiver_greeting uses nonexistent gameobject entry %u. Skipping.", entry); continue; @@ -5448,7 +5400,7 @@ void ObjectMgr::LoadTrainerGreetings() uint32 entry = fields[0].GetUInt32(); - if (!sCreatureStorage.LookupEntry(entry)) + if (!sCreatureStorage.LookupEntry(entry)) { sLog.outErrorDb("Table trainer_greeting uses nonexistent creature entry %u. Skipping.", entry); continue; @@ -5488,7 +5440,7 @@ void ObjectMgr::LoadTrainerGreetingLocales() uint32 entry = fields[0].GetUInt32(); - if (!sCreatureStorage.LookupEntry(entry)) + if (!sCreatureStorage.LookupEntry(entry)) { sLog.outErrorDb("Table locales_trainer_greeting uses nonexistent creature entry %u. Skipping.", entry); continue; @@ -5893,14 +5845,13 @@ uint32 ObjectMgr::GetNearestTaxiNode(float x, float y, float z, uint32 mapid, Te float dist = std::numeric_limits::max(); uint32 id = 0; - for (uint32 i = 1; i < sTaxiNodesStore.GetNumRows(); ++i) + for (auto node : sTaxiNodesStore) { - TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(i); - if (!node || node->map_id != mapid || !node->MountCreatureID[team == ALLIANCE ? 1 : 0]) + if (node->map_id != mapid || !node->MountCreatureID[team == ALLIANCE ? 1 : 0]) continue; - uint8 field = (uint8)((i - 1) / 32); - uint32 submask = 1 << ((i - 1) % 32); + uint8 field = (uint8)((node->ID - 1) / 32); + uint32 submask = 1 << ((node->ID - 1) % 32); // skip not taxi network nodes if ((sTaxiNodesMask[field] & submask) == 0) @@ -5912,14 +5863,14 @@ uint32 ObjectMgr::GetNearestTaxiNode(float x, float y, float z, uint32 mapid, Te if (dist2 < dist) { dist = dist2; - id = i; + id = node->ID; } } else { found = true; dist = dist2; - id = i; + id = node->ID; } } @@ -6031,14 +5982,14 @@ void ObjectMgr::LoadGraveyardZones() continue; } - WorldSafeLocsEntry const* entry = sWorldSafeLocsStore.LookupEntry(safeLocId); + WorldSafeLocsEntry const* entry = sWorldSafeLocsStore.LookupEntry(safeLocId); if (!entry) { sLog.outErrorDb("Table `game_graveyard_zone` has record for nonexistent graveyard (WorldSafeLocs.dbc id) %u, skipped.", safeLocId); continue; } - if (linkKind == GRAVEYARD_AREALINK && GetAreaEntryByAreaID(locId) == nullptr) + if (linkKind == GRAVEYARD_AREALINK && TerrainManager::GetAreaEntryByAreaID(locId) == nullptr) { sLog.outErrorDb("Table `game_graveyard_zone` has record for nonexistent area id (%u), skipped.", locId); continue; @@ -6102,7 +6053,7 @@ WorldSafeLocsEntry const* ObjectMgr::GetClosestGraveyardHelper( GraveYardData const& data = itr->second; // Checked on load - WorldSafeLocsEntry const* entry = sWorldSafeLocsStore.LookupEntry(data.safeLocId); + WorldSafeLocsEntry const* entry = sWorldSafeLocsStore.LookupEntry(data.safeLocId); // skip enemy faction graveyard // team == TEAM_BOTH_ALLOWED case can be at call from .neargrave @@ -6255,7 +6206,7 @@ uint32 ObjectMgr::GraveyardLinkKey(uint32 locationId, uint32 linkKind) * * \param linkKind The kind of the graveyard link to be added. Kind is either * GRAVEYARD_MAPLINK or GRAVEYARD_AREALINK - * + * * \param team The team that is allowed to use this graveyard link. Can be * TEAM_BOTH_ALLOWED, HORDE or ALLIANCE. * @@ -6315,7 +6266,7 @@ void ObjectMgr::SetGraveYardLinkTeam(uint32 id, uint32 locKey, Team team) void ObjectMgr::LoadWorldSafeLocs() const { sWorldSafeLocsStore.Load(true); - sLog.outString(">> Loaded %u world safe locs", sWorldSafeLocsStore.GetRecordCount()); + sLog.outString(">> Loaded %u world safe locs", sWorldSafeLocsStore.GetNumRows()); } void ObjectMgr::LoadAreaTriggerTeleports() @@ -6432,7 +6383,7 @@ void ObjectMgr::LoadAreaTriggerTeleports() if (at.conditionId) { - const ConditionEntry* condition = sConditionStorage.LookupEntry(at.conditionId); + const ConditionEntry* condition = sConditionStorage.LookupEntry(at.conditionId); if (!condition) // condition does not exist for some reason sLog.outErrorDb("Table `areatrigger_teleport` entry %u has `ConditionId` = %u but does not exist.", at.entry, at.conditionId); } @@ -6779,7 +6730,7 @@ void ObjectMgr::LoadGameObjectLocales() sLog.outString(); } -struct SQLGameObjectLoader : public SQLStorageLoaderBase +struct SQLGameObjectLoader : public SQLStorageLoaderBase> { template void convert_from_str(uint32 /*field_pos*/, char const* src, D& dst) @@ -6799,7 +6750,7 @@ inline void CheckGOLockId(GameObjectInfo const* goInfo, uint32 dataN, uint32 N) inline void CheckGOLinkedTrapId(GameObjectInfo const* goInfo, uint32 dataN, uint32 N) { - if (GameObjectInfo const* trapInfo = sGOStorage.LookupEntry(dataN)) + if (GameObjectInfo const* trapInfo = sGOStorage.LookupEntry(dataN)) { if (trapInfo->type != GAMEOBJECT_TYPE_TRAP) sLog.outErrorDb("Gameobject (Entry: %u GoType: %u) have data%d=%u but GO (Entry %u) have not GAMEOBJECT_TYPE_TRAP (%u) type.", @@ -6813,7 +6764,7 @@ inline void CheckGOLinkedTrapId(GameObjectInfo const* goInfo, uint32 dataN, uint inline void CheckGOSpellId(GameObjectInfo const* goInfo, uint32 dataN, uint32 N) { - if (sSpellTemplate.LookupEntry(dataN)) + if (sSpellTemplate.LookupEntry(dataN)) return; sLog.outErrorDb("Gameobject (Entry: %u GoType: %u) have data%d=%u but Spell (Entry %u) not exist.", @@ -6872,10 +6823,8 @@ std::vector ObjectMgr::LoadGameobjectInfo() std::vector transportDisplayIds; // some checks - for (SQLStorageBase::SQLSIterator itr = sGOStorage.getDataBegin(); itr < sGOStorage.getDataEnd(); ++itr) + for (auto goInfo : sGOStorage) { - GameObjectInfo const* goInfo = itr.getValue(); - if (goInfo->size <= 0.0f) // prevent use too small scales { ERROR_DB_STRICT_LOG("Gameobject (Entry: %u GoType: %u) have too small size=%f", @@ -6956,7 +6905,7 @@ std::vector ObjectMgr::LoadGameobjectInfo() if (goInfo->goober.pageId) // pageId { - if (!sPageTextStore.LookupEntry(goInfo->goober.pageId)) + if (!sPageTextStore.LookupEntry(goInfo->goober.pageId)) sLog.outErrorDb("Gameobject (Entry: %u GoType: %u) have data7=%u but PageText (Entry %u) not exist.", goInfo->id, goInfo->type, goInfo->goober.pageId, goInfo->goober.pageId); } @@ -7037,7 +6986,7 @@ std::vector ObjectMgr::LoadGameobjectInfo() } } - sLog.outString(">> Loaded %u game object templates", sGOStorage.GetRecordCount()); + sLog.outString(">> Loaded %u game object templates", sGOStorage.GetNumRows()); sLog.outString(); return transportDisplayIds; @@ -7250,7 +7199,7 @@ void ObjectMgr::LoadReputationRewardRate() repRate.creature_rate = fields[2].GetFloat(); repRate.spell_rate = fields[3].GetFloat(); - FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionId); + FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionId); if (!factionEntry) { sLog.outErrorDb("Faction (faction.dbc) %u does not exist but is used in `reputation_reward_rate`", factionId); @@ -7334,7 +7283,7 @@ void ObjectMgr::LoadReputationOnKill() if (repOnKill.repfaction1) { - FactionEntry const* factionEntry1 = sFactionStore.LookupEntry(repOnKill.repfaction1); + FactionEntry const* factionEntry1 = sFactionStore.LookupEntry(repOnKill.repfaction1); if (!factionEntry1) { sLog.outErrorDb("Faction (faction.dbc) %u does not exist but is used in `creature_onkill_reputation`", repOnKill.repfaction1); @@ -7344,7 +7293,7 @@ void ObjectMgr::LoadReputationOnKill() if (repOnKill.repfaction2) { - FactionEntry const* factionEntry2 = sFactionStore.LookupEntry(repOnKill.repfaction2); + FactionEntry const* factionEntry2 = sFactionStore.LookupEntry(repOnKill.repfaction2); if (!factionEntry2) { sLog.outErrorDb("Faction (faction.dbc) %u does not exist but is used in `creature_onkill_reputation`", repOnKill.repfaction2); @@ -7405,7 +7354,7 @@ void ObjectMgr::LoadReputationSpilloverTemplate() repTemplate.faction_rate[3] = fields[11].GetFloat(); repTemplate.faction_rank[3] = fields[12].GetUInt32(); - FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionId); + FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionId); if (!factionEntry) { @@ -7423,7 +7372,7 @@ void ObjectMgr::LoadReputationSpilloverTemplate() { if (repTemplate.faction[i]) { - FactionEntry const* factionSpillover = sFactionStore.LookupEntry(repTemplate.faction[i]); + FactionEntry const* factionSpillover = sFactionStore.LookupEntry(repTemplate.faction[i]); if (!factionSpillover) { @@ -7444,25 +7393,25 @@ void ObjectMgr::LoadReputationSpilloverTemplate() } } - FactionEntry const* factionEntry0 = sFactionStore.LookupEntry(repTemplate.faction[0]); + FactionEntry const* factionEntry0 = sFactionStore.LookupEntry(repTemplate.faction[0]); if (repTemplate.faction[0] && !factionEntry0) { sLog.outErrorDb("Faction (faction.dbc) %u does not exist but is used in `reputation_spillover_template`", repTemplate.faction[0]); continue; } - FactionEntry const* factionEntry1 = sFactionStore.LookupEntry(repTemplate.faction[1]); + FactionEntry const* factionEntry1 = sFactionStore.LookupEntry(repTemplate.faction[1]); if (repTemplate.faction[1] && !factionEntry1) { sLog.outErrorDb("Faction (faction.dbc) %u does not exist but is used in `reputation_spillover_template`", repTemplate.faction[1]); continue; } - FactionEntry const* factionEntry2 = sFactionStore.LookupEntry(repTemplate.faction[2]); + FactionEntry const* factionEntry2 = sFactionStore.LookupEntry(repTemplate.faction[2]); if (repTemplate.faction[2] && !factionEntry2) { sLog.outErrorDb("Faction (faction.dbc) %u does not exist but is used in `reputation_spillover_template`", repTemplate.faction[2]); continue; } - FactionEntry const* factionEntry3 = sFactionStore.LookupEntry(repTemplate.faction[3]); + FactionEntry const* factionEntry3 = sFactionStore.LookupEntry(repTemplate.faction[3]); if (repTemplate.faction[3] && !factionEntry3) { sLog.outErrorDb("Faction (faction.dbc) %u does not exist but is used in `reputation_spillover_template`", repTemplate.faction[3]); @@ -7536,7 +7485,7 @@ void ObjectMgr::LoadPointsOfInterest() static char SERVER_SIDE_SPELL[] = "CMaNGOS server-side spell"; -struct SQLSpellLoader : public SQLStorageLoaderBase +struct SQLSpellLoader : public SQLStorageLoaderBase> { template void default_fill(uint32 field_pos, S src, D& dst) @@ -7566,20 +7515,19 @@ void ObjectMgr::LoadSpellTemplate() sSpellTemplate.Load(); /* TODO add validation for spell_dbc */ - for (SQLStorageBase::SQLSIterator itr = sSpellTemplate.getDataBegin(); itr < sSpellTemplate.getDataEnd(); ++itr) + for (auto itr : sSpellTemplate) { - if (!sSpellTemplate.LookupEntry(itr->Id)) + if (!sSpellTemplate.LookupEntry(itr->Id)) { sLog.outErrorDb("LoadSpellDbc: implement validation to erase spell if it does not confirm to requirements for spells"); sSpellTemplate.EraseEntry(itr->Id); } } - for (uint32 i = 1; i < sSpellTemplate.GetMaxEntry(); ++i) + for (auto spell : sSpellTemplate) { - SpellEntry const* spell = sSpellTemplate.LookupEntry(i); - if (spell && spell->Category) - sSpellCategoryStore[spell->Category].insert(i); + if (spell->Category) + sSpellCategoryStore[spell->Category].insert(spell->Id); // DBC not support uint64 fields but SpellEntry have SpellFamilyFlags mapped at 2 uint32 fields // uint32 field already converted to bigendian if need, but must be swapped for correct uint64 bigendian view @@ -7588,25 +7536,24 @@ void ObjectMgr::LoadSpellTemplate() #endif } - sLog.outString(">> Loaded %u spell_template records", sSpellTemplate.GetRecordCount()); + sLog.outString(">> Loaded %u spell_template records", sSpellTemplate.GetNumRows()); sLog.outString(); sSpellCones.Load(); - sLog.outString(">> Loaded %u spell_cone records", sSpellCones.GetRecordCount()); + sLog.outString(">> Loaded %u spell_cone records", sSpellCones.GetNumRows()); sLog.outString(); } void ObjectMgr::CheckSpellCones() { - for (uint32 i = 1; i < sSpellTemplate.GetMaxEntry(); ++i) + for (auto spell : sSpellTemplate) { - SpellEntry const* spell = sSpellTemplate.LookupEntry(i); - SpellCone const* spellCone = sSpellCones.LookupEntry(i); + SpellCone const* spellCone = sSpellCones.LookupEntry(spell->Id); if (spell) { - if (uint32 firstRankId = sSpellMgr.GetFirstSpellInChain(i)) + if (uint32 firstRankId = sSpellMgr.GetFirstSpellInChain(spell->Id)) { - SpellCone const* spellConeFirst = sSpellCones.LookupEntry(firstRankId); + SpellCone const* spellConeFirst = sSpellCones.LookupEntry(firstRankId); if (!spellConeFirst && !spellCone) // no cones for either - is fine continue; @@ -7614,9 +7561,9 @@ void ObjectMgr::CheckSpellCones() continue; if (!spellConeFirst && spellCone) - sLog.outErrorDb("Table spell_cone is missing entry for spell %u - angle %d for its first rank %u. But has cone for this one.", i, spellCone->coneAngle, firstRankId); + sLog.outErrorDb("Table spell_cone is missing entry for spell %u - angle %d for its first rank %u. But has cone for this one.", spell->Id, spellCone->coneAngle, firstRankId); else if (spellCone->coneAngle != spellConeFirst->coneAngle) - sLog.outErrorDb("Table spell_cone has different cone angle for spell Id %u - angle %d and first rank %u - angle %d", i, spellCone->coneAngle, firstRankId, spellConeFirst->coneAngle); + sLog.outErrorDb("Table spell_cone has different cone angle for spell Id %u - angle %d and first rank %u - angle %d", spell->Id, spellCone->coneAngle, firstRankId, spellConeFirst->coneAngle); } } } @@ -7626,17 +7573,16 @@ void ObjectMgr::LoadFactions() { sFactionStore.Load(); - for (uint32 i = 0; i < sFactionStore.GetMaxEntry(); ++i) + for (auto faction : sFactionStore) { - FactionEntry const* faction = sFactionStore.LookupEntry(i); - if (faction && faction->team) + if (faction->team) { SimpleFactionsList& flist = sFactionTeamMap[faction->team]; - flist.push_back(i); + flist.push_back(faction->ID); } } - sLog.outString(">> Loaded %u faction_store records", sFactionStore.GetRecordCount()); + sLog.outString(">> Loaded %u faction_store records", sFactionStore.GetNumRows()); sLog.outString(); } @@ -7738,7 +7684,7 @@ void ObjectMgr::LoadBroadcastTextLocales() sLog.outString(">> Loaded %u texts from %s", count, "broadcast_text_locale"); sLog.outString(); } - + void ObjectMgr::DeleteCreatureData(uint32 guid) { // remove mapid*cellid -> guid_set map @@ -8151,11 +8097,11 @@ void ObjectMgr::LoadGameObjectForQuests() return; } - BarGoLink bar(sGOStorage.GetRecordCount()); + BarGoLink bar(sGOStorage.GetNumRows()); uint32 count = 0; // collect GO entries for GO that must activated - for (SQLStorageBase::SQLSIterator itr = sGOStorage.getDataBegin(); itr < sGOStorage.getDataEnd(); ++itr) + for (auto itr : sGOStorage) { bar.step(); switch (itr->type) @@ -8447,7 +8393,7 @@ void ObjectMgr::LoadFishingBaseSkillLevel() uint32 entry = fields[0].GetUInt32(); int32 skill = fields[1].GetInt32(); - AreaTableEntry const* fArea = GetAreaEntryByAreaID(entry); + AreaTableEntry const* fArea = TerrainManager::GetAreaEntryByAreaID(entry); if (!fArea) { sLog.outErrorDb("AreaId %u defined in `skill_fishing_base_level` does not exist", entry); @@ -8468,7 +8414,7 @@ void ObjectMgr::LoadFishingBaseSkillLevel() // Check if a target meets condition conditionId bool ObjectMgr::IsConditionSatisfied(uint32 conditionId, WorldObject const* target, Map const* map, WorldObject const* source, ConditionSource conditionSourceType) const { - if (ConditionEntry const* condition = sConditionStorage.LookupEntry(conditionId)) + if (ConditionEntry const* condition = sConditionStorage.LookupEntry(conditionId)) return condition->Meets(target, map, source, conditionSourceType); return false; @@ -8756,7 +8702,7 @@ void ObjectMgr::LoadTrainers(char const* tableName, bool isTemplates) uint32 entry = fields[0].GetUInt32(); uint32 spell = fields[1].GetUInt32(); - SpellEntry const* spellinfo = sSpellTemplate.LookupEntry(spell); + SpellEntry const* spellinfo = sSpellTemplate.LookupEntry(spell); if (!spellinfo) { sLog.outErrorDb("Table `%s` (Entry: %u ) has non existing spell %u, ignore", tableName, entry, spell); @@ -8851,7 +8797,7 @@ void ObjectMgr::LoadTrainers(char const* tableName, bool isTemplates) if (trainerSpell.conditionId) { - const ConditionEntry* condition = sConditionStorage.LookupEntry(trainerSpell.conditionId); + const ConditionEntry* condition = sConditionStorage.LookupEntry(trainerSpell.conditionId); if (!condition) // condition does not exist for some reason sLog.outErrorDb("Table `%s` (Entry: %u) has `condition_id` = %u but does not exist.", tableName, entry, trainerSpell.conditionId); } @@ -8879,19 +8825,16 @@ void ObjectMgr::LoadTrainerTemplates() for (CacheTrainerSpellMap::const_iterator tItr = m_mCacheTrainerTemplateSpellMap.begin(); tItr != m_mCacheTrainerTemplateSpellMap.end(); ++tItr) trainer_ids.insert(tItr->first); - for (uint32 i = 1; i < sCreatureStorage.GetMaxEntry(); ++i) + for (auto cInfo : sCreatureStorage) { - if (CreatureInfo const* cInfo = sCreatureStorage.LookupEntry(i)) + if (cInfo->TrainerTemplateId) { - if (cInfo->TrainerTemplateId) + if (m_mCacheTrainerTemplateSpellMap.find(cInfo->TrainerTemplateId) != m_mCacheTrainerTemplateSpellMap.end()) + trainer_ids.erase(cInfo->TrainerTemplateId); + else { - if (m_mCacheTrainerTemplateSpellMap.find(cInfo->TrainerTemplateId) != m_mCacheTrainerTemplateSpellMap.end()) - trainer_ids.erase(cInfo->TrainerTemplateId); - else - { - sLog.outErrorDb("Creature (Entry: %u) has TrainerTemplateId = %u for nonexistent trainer template", cInfo->Entry, cInfo->TrainerTemplateId); - hasErrored = true; - } + sLog.outErrorDb("Creature (Entry: %u) has TrainerTemplateId = %u for nonexistent trainer template", cInfo->Entry, cInfo->TrainerTemplateId); + hasErrored = true; } } } @@ -8967,17 +8910,14 @@ void ObjectMgr::LoadVendorTemplates() for (CacheVendorItemMap::const_iterator vItr = m_mCacheVendorTemplateItemMap.begin(); vItr != m_mCacheVendorTemplateItemMap.end(); ++vItr) vendor_ids.insert(vItr->first); - for (uint32 i = 1; i < sCreatureStorage.GetMaxEntry(); ++i) + for (auto cInfo : sCreatureStorage) { - if (CreatureInfo const* cInfo = sCreatureStorage.LookupEntry(i)) + if (cInfo->VendorTemplateId) { - if (cInfo->VendorTemplateId) - { - if (m_mCacheVendorTemplateItemMap.find(cInfo->VendorTemplateId) != m_mCacheVendorTemplateItemMap.end()) - vendor_ids.erase(cInfo->VendorTemplateId); - else - sLog.outErrorDb("Creature (Entry: %u) has VendorTemplateId = %u for nonexistent vendor template", cInfo->Entry, cInfo->VendorTemplateId); - } + if (m_mCacheVendorTemplateItemMap.find(cInfo->VendorTemplateId) != m_mCacheVendorTemplateItemMap.end()) + vendor_ids.erase(cInfo->VendorTemplateId); + else + sLog.outErrorDb("Creature (Entry: %u) has VendorTemplateId = %u for nonexistent vendor template", cInfo->Entry, cInfo->VendorTemplateId); } } @@ -9147,7 +9087,7 @@ void ObjectMgr::LoadGossipMenu(std::set& gossipScriptSet) if (gMenu.conditionId) { - const ConditionEntry* condition = sConditionStorage.LookupEntry(gMenu.conditionId); + const ConditionEntry* condition = sConditionStorage.LookupEntry(gMenu.conditionId); if (!condition) { sLog.outErrorDb("Table gossip_menu for menu %u, text-id %u has condition_id %u that does not exist in `conditions`, ignoring", gMenu.entry, gMenu.text_id, gMenu.conditionId); @@ -9164,17 +9104,16 @@ void ObjectMgr::LoadGossipMenu(std::set& gossipScriptSet) delete result; // post loading tests - for (uint32 i = 1; i < sCreatureStorage.GetMaxEntry(); ++i) + for (auto cInfo : sCreatureStorage) { - if (CreatureInfo const* cInfo = sCreatureStorage.LookupEntry(i)) - if (cInfo->GossipMenuId) - if (m_mGossipMenusMap.find(cInfo->GossipMenuId) == m_mGossipMenusMap.end()) - sLog.outErrorDb("Creature (Entry: %u) has GossipMenuId = %u for nonexistent menu", cInfo->Entry, cInfo->GossipMenuId); + if (cInfo->GossipMenuId) + if (m_mGossipMenusMap.find(cInfo->GossipMenuId) == m_mGossipMenusMap.end()) + sLog.outErrorDb("Creature (Entry: %u) has GossipMenuId = %u for nonexistent menu", cInfo->Entry, cInfo->GossipMenuId); } if (!sLog.HasLogFilter(LOG_FILTER_DB_STRICTED_CHECK)) { - for (SQLStorageBase::SQLSIterator itr = sGOStorage.getDataBegin(); itr < sGOStorage.getDataEnd(); ++itr) + for (auto itr : sGOStorage) if (uint32 menuid = itr->GetGossipMenuId()) if (m_mGossipMenusMap.find(menuid) == m_mGossipMenusMap.end()) sLog.outErrorDb("Gameobject (Entry: %u) has gossip_menu_id = %u for nonexistent menu", itr->id, menuid); @@ -9211,7 +9150,7 @@ void ObjectMgr::LoadGossipMenuItems(std::set& gossipScriptSet) if (itr->first) menu_ids.insert(itr->first); - for (SQLStorageBase::SQLSIterator itr = sGOStorage.getDataBegin(); itr < sGOStorage.getDataEnd(); ++itr) + for (auto itr : sGOStorage) if (uint32 menuid = itr->GetGossipMenuId()) menu_ids.erase(menuid); } @@ -9224,16 +9163,17 @@ void ObjectMgr::LoadGossipMenuItems(std::set& gossipScriptSet) // prepare menuid -> CreatureInfo map for fast access typedef std::multimap Menu2CInfoMap; Menu2CInfoMap menu2CInfoMap; - for (uint32 i = 1; i < sCreatureStorage.GetMaxEntry(); ++i) - if (CreatureInfo const* cInfo = sCreatureStorage.LookupEntry(i)) - if (cInfo->GossipMenuId) - { - menu2CInfoMap.insert(Menu2CInfoMap::value_type(cInfo->GossipMenuId, cInfo)); + for (auto cInfo : sCreatureStorage) + { + if (cInfo->GossipMenuId) + { + menu2CInfoMap.insert(Menu2CInfoMap::value_type(cInfo->GossipMenuId, cInfo)); - // unused check data preparing part - if (!sLog.HasLogFilter(LOG_FILTER_DB_STRICTED_CHECK)) - menu_ids.erase(cInfo->GossipMenuId); - } + // unused check data preparing part + if (!sLog.HasLogFilter(LOG_FILTER_DB_STRICTED_CHECK)) + menu_ids.erase(cInfo->GossipMenuId); + } + } do { @@ -9329,7 +9269,7 @@ void ObjectMgr::LoadGossipMenuItems(std::set& gossipScriptSet) if (gMenuItem.conditionId) { - const ConditionEntry* condition = sConditionStorage.LookupEntry(gMenuItem.conditionId); + const ConditionEntry* condition = sConditionStorage.LookupEntry(gMenuItem.conditionId); if (!condition) { sLog.outErrorDb("Table gossip_menu_option for menu %u, id %u has condition_id %u that does not exist in `conditions`, ignoring", gMenuItem.menu_id, gMenuItem.id, gMenuItem.conditionId); @@ -9470,7 +9410,7 @@ bool ObjectMgr::IsVendorItemValid(bool isTemplate, char const* tableName, uint32 return false; } - if (conditionId && !sConditionStorage.LookupEntry(conditionId)) + if (conditionId && !sConditionStorage.LookupEntry(conditionId)) { sLog.outErrorDb("Table `%s` has `condition_id`=%u for item %u of %s %u but this condition is not valid, ignoring", tableName, conditionId, item_id, idStr, vendor_entry); return false; @@ -9697,14 +9637,14 @@ void ObjectMgr::LoadCreatureTemplateSpells() for (uint32 i = 0; i < CREATURE_MAX_SPELLS; ++i) templateSpells.spells[i] = fields[2 + i].GetUInt32(); - if (!sCreatureStorage.LookupEntry(templateSpells.entry)) + if (!sCreatureStorage.LookupEntry(templateSpells.entry)) { sLog.outErrorDb("LoadCreatureTemplateSpells: Spells found for creature entry %u, but creature does not exist, skipping", templateSpells.entry); continue; } for (uint8 i = 0; i < CREATURE_MAX_SPELLS; ++i) { - if (templateSpells.spells[i] && !sSpellTemplate.LookupEntry(templateSpells.spells[i]) && templateSpells.spells[i] != 2) // 2 is attack which is hardcoded in client + if (templateSpells.spells[i] && !sSpellTemplate.LookupEntry(templateSpells.spells[i]) && templateSpells.spells[i] != 2) // 2 is attack which is hardcoded in client { sLog.outErrorDb("LoadCreatureTemplateSpells: Spells found for creature entry %u, assigned spell %u does not exist, set to 0", templateSpells.entry, templateSpells.spells[i]); templateSpells.spells[i] = 0; @@ -9731,13 +9671,13 @@ void ObjectMgr::LoadCreatureCooldowns() Field* fields = result->Fetch(); uint32 entry = fields[0].GetUInt32(); - if (!sCreatureStorage.LookupEntry(entry)) + if (!sCreatureStorage.LookupEntry(entry)) { sLog.outErrorDb("LoadCreatureCooldowns: Entry %u does not exist.", entry); continue; } uint32 spellId = fields[1].GetUInt32(); - if (!sSpellTemplate.LookupEntry(spellId)) + if (!sSpellTemplate.LookupEntry(spellId)) { sLog.outErrorDb("LoadCreatureCooldowns: SpellId %u does not exist.", spellId); continue; @@ -9773,7 +9713,7 @@ SimpleFactionsList const* GetFactionTeamList(uint32 faction) CreatureInfo const* GetCreatureTemplateStore(uint32 entry) { - return sCreatureStorage.LookupEntry(entry); + return sCreatureStorage.LookupEntry(entry); } Quest const* GetQuestTemplateStore(uint32 entry) @@ -9938,3 +9878,58 @@ bool DoDisplayText(WorldObject* source, int32 entry, Unit const* target /*=nullp source->MonsterText(data, target); return true; } + +TalentSpellPos const* ObjectMgr::GetTalentSpellPos(uint32 spellId) +{ + TalentSpellPosMap::const_iterator itr = sTalentSpellPosMap.find(spellId); + if (itr == sTalentSpellPosMap.end()) + return nullptr; + + return &itr->second; +} + +uint32 ObjectMgr::GetTalentSpellCost(TalentSpellPos const* pos) +{ + if (pos) + return pos->rank + 1; + + return 0; +} + +uint32 ObjectMgr::GetTalentSpellCost(uint32 spellId) +{ + return GetTalentSpellCost(GetTalentSpellPos(spellId)); +} + +uint32 ObjectMgr::GetTalentInspectBitPosInTab(uint32 talentId) +{ + TalentInspectMap::const_iterator itr = sTalentPosInInspect.find(talentId); + if (itr == sTalentPosInInspect.end()) + return 0; + + return itr->second; +} + +uint32 ObjectMgr::GetTalentTabInspectBitSize(uint32 talentTabId) +{ + TalentInspectMap::const_iterator itr = sTalentTabSizeInInspect.find(talentTabId); + if (itr == sTalentTabSizeInInspect.end()) + return 0; + + return itr->second; +} + +uint32 const* ObjectMgr::GetTalentTabPages(uint32 cls) +{ + return sTalentTabPages[cls]; +} + +char const* ObjectMgr::GetPetName(uint32 petfamily, uint32 dbclang) +{ + if (!petfamily) + return nullptr; + CreatureFamilyEntry const* pet_family = sCreatureFamilyStore.LookupEntry(petfamily); + if (!pet_family) + return nullptr; + return pet_family->Name[dbclang] ? pet_family->Name[dbclang] : nullptr; +} \ No newline at end of file diff --git a/src/game/Globals/ObjectMgr.h b/src/game/Globals/ObjectMgr.h index 4a50a69e0c..4026b70fc0 100644 --- a/src/game/Globals/ObjectMgr.h +++ b/src/game/Globals/ObjectMgr.h @@ -41,6 +41,8 @@ class Group; class ArenaTeam; class Item; + +template class SQLStorage; struct GameTele @@ -354,17 +356,6 @@ struct GraveYardData typedef std::multimap < uint32 /*locId*/, GraveYardData > GraveYardMap; typedef std::pair GraveYardMapBounds; -struct WorldSafeLocsEntry -{ - uint32 ID; - uint32 map_id; - float x; - float y; - float z; - float o; - char* name; -}; - struct QuestgiverGreeting { std::string text; @@ -1180,6 +1171,15 @@ class ObjectMgr * Qualifier: const **/ CreatureClassLvlStats const* GetCreatureClassLvlStats(uint32 level, uint32 unitClass, int32 expansion) const; + + static uint32 GetTalentSpellCost(uint32 spellId); + static uint32 GetTalentSpellCost(TalentSpellPos const* pos); + static TalentSpellPos const* GetTalentSpellPos(uint32 spellId); + static uint32 GetTalentInspectBitPosInTab(uint32 talentId); + static uint32 GetTalentTabInspectBitSize(uint32 talentTabId); + static uint32 const* /*[3]*/ GetTalentTabPages(uint32 cls); + static char const* GetPetName(uint32 petfamily, uint32 dbclang); + protected: // current locale settings @@ -1237,7 +1237,7 @@ class ObjectMgr GossipMenuItemsMap m_mGossipMenuItemsMap; std::unordered_map> mCreatureSpawnEntryMap; - + PointOfInterestMap mPointsOfInterest; PetCreateSpellMap mPetCreateSpell; @@ -1265,7 +1265,7 @@ class ObjectMgr QuestRelationsMap m_GOQuestInvolvedRelations; private: - void LoadCreatureAddons(SQLStorage& creatureaddons, char const* entryName, char const* comment); + void LoadCreatureAddons(SQLStorage& creatureaddons, char const* entryName, char const* comment); void ConvertCreatureAddonAuras(CreatureDataAddon* addon, char const* table, char const* guidEntryStr); void LoadQuestRelationsHelper(QuestRelationsMap& map, char const* table); void LoadVendors(char const* tableName, bool isTemplates); diff --git a/src/game/Globals/SharedDefines.h b/src/game/Globals/SharedDefines.h index 59c220c952..3f6ee76bbd 100644 --- a/src/game/Globals/SharedDefines.h +++ b/src/game/Globals/SharedDefines.h @@ -2593,4 +2593,22 @@ enum MovementEvent EVENT_JUMP = 10001, // TODO: Implement knockback using this }; +enum SpawnFlags +{ + SPAWN_FLAG_RUN_ON_SPAWN = 0x01, + SPAWN_FLAG_HOVER = 0x02, +}; + +enum SplineFlags +{ + SPLINEFLAG_WALKMODE = 0x0000100, + SPLINEFLAG_FLYING = 0x0000200, +}; + +enum ContentLevels +{ + CONTENT_1_60 = 0, + CONTENT_61_70 +}; + #endif diff --git a/src/game/Grids/GridNotifiersImpl.h b/src/game/Grids/GridNotifiersImpl.h index ec2d578dc0..f67b737701 100644 --- a/src/game/Grids/GridNotifiersImpl.h +++ b/src/game/Grids/GridNotifiersImpl.h @@ -200,15 +200,15 @@ inline void MaNGOS::DynamicObjectUpdater::VisitHelper(Unit* target) if (target->GetTypeId() == TYPEID_PLAYER && target != i_check && (((Player*) target)->IsGameMaster() || ((Player*)target)->GetVisibility() == VISIBILITY_OFF)) return; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(i_dynobject.GetSpellId()); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(i_dynobject.GetSpellId()); SpellEffectIndex eff_index = i_dynobject.GetEffIndex(); Unit* caster = i_dynobject.GetCaster(); - SQLMultiStorage::SQLMSIteratorBounds bounds = sSpellScriptTargetStorage.getBounds(spellInfo->Id); + auto bounds = sSpellScriptTargetStorage.getBounds(spellInfo->Id); if (bounds.first != bounds.second) { bool found = false; - for (SQLMultiStorage::SQLMultiSIterator i_spellST = bounds.first; i_spellST != bounds.second; ++i_spellST) + for (auto i_spellST = bounds.first; i_spellST != bounds.second; ++i_spellST) { if (i_spellST->CanNotHitWithSpellEffect(eff_index)) continue; diff --git a/src/game/Loot/LootMgr.cpp b/src/game/Loot/LootMgr.cpp index 3f570f676e..7901ae1e6c 100644 --- a/src/game/Loot/LootMgr.cpp +++ b/src/game/Loot/LootMgr.cpp @@ -128,7 +128,7 @@ void LootStore::LoadLootTable() if (conditionId) { - const ConditionEntry* condition = sConditionStorage.LookupEntry(conditionId); + const ConditionEntry* condition = sConditionStorage.LookupEntry(conditionId); if (!condition) { sLog.outErrorDb("Table `%s` for entry %u, item %u has condition_id %u that does not exist in `conditions`, ignoring", GetName(), entry, item, uint32(conditionId)); @@ -2220,7 +2220,7 @@ void Loot::PrintLootList(ChatHandler& chat, WorldSession* session) const for (auto lootItem : m_lootItems) { uint32 itemId = lootItem->itemId; - ItemPrototype const* pProto = sItemStorage.LookupEntry(itemId); + ItemPrototype const* pProto = sItemStorage.LookupEntry(itemId); if (!pProto) continue; @@ -2629,19 +2629,17 @@ void LoadLootTemplates_Creature() LootTemplates_Creature.LoadAndCollectLootIds(ids_set); // remove real entries and check existence loot - for (uint32 i = 1; i < sCreatureStorage.GetMaxEntry(); ++i) + for (auto cInfo : sCreatureStorage) { - if (CreatureInfo const* cInfo = sCreatureStorage.LookupEntry(i)) + if (uint32 lootid = cInfo->LootId) { - if (uint32 lootid = cInfo->LootId) - { - if (ids_set.find(lootid) == ids_set.end()) - LootTemplates_Creature.ReportNotExistedId(lootid); - else - ids_setUsed.insert(lootid); - } + if (ids_set.find(lootid) == ids_set.end()) + LootTemplates_Creature.ReportNotExistedId(lootid); + else + ids_setUsed.insert(lootid); } } + for (uint32 itr : ids_setUsed) ids_set.erase(itr); @@ -2659,17 +2657,14 @@ void LoadLootTemplates_Disenchant() LootTemplates_Disenchant.LoadAndCollectLootIds(ids_set); // remove real entries and check existence loot - for (uint32 i = 1; i < sItemStorage.GetMaxEntry(); ++i) + for (auto proto : sItemStorage) { - if (ItemPrototype const* proto = sItemStorage.LookupEntry(i)) + if (uint32 lootid = proto->DisenchantID) { - if (uint32 lootid = proto->DisenchantID) - { - if (ids_set.find(lootid) == ids_set.end()) - LootTemplates_Disenchant.ReportNotExistedId(lootid); - else - ids_setUsed.insert(lootid); - } + if (ids_set.find(lootid) == ids_set.end()) + LootTemplates_Disenchant.ReportNotExistedId(lootid); + else + ids_setUsed.insert(lootid); } } for (uint32 itr : ids_setUsed) @@ -2684,11 +2679,10 @@ void LoadLootTemplates_Fishing() LootTemplates_Fishing.LoadAndCollectLootIds(ids_set); // remove real entries and check existence loot - for (uint32 i = 1; i < sAreaStore.GetNumRows(); ++i) + for (auto areaEntry : sAreaTableStore) { - if (AreaTableEntry const* areaEntry = sAreaStore.LookupEntry(i)) - if (ids_set.find(areaEntry->ID) != ids_set.end()) - ids_set.erase(areaEntry->ID); + if (ids_set.find(areaEntry->ID) != ids_set.end()) + ids_set.erase(areaEntry->ID); } // by default (look config options) fishing at fail provide junk loot, entry 0 use for store this loot @@ -2704,7 +2698,7 @@ void LoadLootTemplates_Gameobject() LootTemplates_Gameobject.LoadAndCollectLootIds(ids_set); // remove real entries and check existence loot - for (SQLStorageBase::SQLSIterator itr = sGOStorage.getDataBegin(); itr < sGOStorage.getDataEnd(); ++itr) + for (auto itr : sGOStorage) { if (uint32 lootid = itr->GetLootId()) { @@ -2727,21 +2721,17 @@ void LoadLootTemplates_Item() LootTemplates_Item.LoadAndCollectLootIds(ids_set); // remove real entries and check existence loot - for (uint32 i = 1; i < sItemStorage.GetMaxEntry(); ++i) + for (auto proto : sItemStorage) { - if (ItemPrototype const* proto = sItemStorage.LookupEntry(i)) - { - if (!(proto->Flags & ITEM_FLAG_HAS_LOOT)) - continue; + if (!(proto->Flags & ITEM_FLAG_HAS_LOOT)) + continue; - if (ids_set.find(proto->ItemId) != ids_set.end() || proto->MaxMoneyLoot > 0) - ids_set.erase(proto->ItemId); - // wdb have wrong data cases, so skip by default - else if (!sLog.HasLogFilter(LOG_FILTER_DB_STRICTED_CHECK)) - LootTemplates_Item.ReportNotExistedId(proto->ItemId); - } + if (ids_set.find(proto->ItemId) != ids_set.end() || proto->MaxMoneyLoot > 0) + ids_set.erase(proto->ItemId); + // wdb have wrong data cases, so skip by default + else if (!sLog.HasLogFilter(LOG_FILTER_DB_STRICTED_CHECK)) + LootTemplates_Item.ReportNotExistedId(proto->ItemId); } - // output error for any still listed (not referenced from appropriate table) ids LootTemplates_Item.ReportUnusedIds(ids_set); } @@ -2752,17 +2742,14 @@ void LoadLootTemplates_Pickpocketing() LootTemplates_Pickpocketing.LoadAndCollectLootIds(ids_set); // remove real entries and check existence loot - for (uint32 i = 1; i < sCreatureStorage.GetMaxEntry(); ++i) + for (auto cInfo : sCreatureStorage) { - if (CreatureInfo const* cInfo = sCreatureStorage.LookupEntry(i)) + if (uint32 lootid = cInfo->PickpocketLootId) { - if (uint32 lootid = cInfo->PickpocketLootId) - { - if (ids_set.find(lootid) == ids_set.end()) - LootTemplates_Pickpocketing.ReportNotExistedId(lootid); - else - ids_setUsed.insert(lootid); - } + if (ids_set.find(lootid) == ids_set.end()) + LootTemplates_Pickpocketing.ReportNotExistedId(lootid); + else + ids_setUsed.insert(lootid); } } for (uint32 itr : ids_setUsed) @@ -2778,12 +2765,8 @@ void LoadLootTemplates_Prospecting() LootTemplates_Prospecting.LoadAndCollectLootIds(ids_set); // remove real entries and check existence loot - for (uint32 i = 1; i < sItemStorage.GetMaxEntry(); ++i) + for (auto proto : sItemStorage) { - ItemPrototype const* proto = sItemStorage.LookupEntry(i); - if (!proto) - continue; - if (!(proto->Flags & ITEM_FLAG_IS_PROSPECTABLE)) continue; @@ -2803,10 +2786,9 @@ void LoadLootTemplates_Mail() LootTemplates_Mail.LoadAndCollectLootIds(ids_set); // remove real entries and check existence loot - for (uint32 i = 1; i < sMailTemplateStore.GetNumRows(); ++i) - if (sMailTemplateStore.LookupEntry(i)) - if (ids_set.find(i) != ids_set.end()) - ids_set.erase(i); + for (auto mailEntry : sMailTemplateStore) + if (ids_set.find(mailEntry->ID) != ids_set.end()) + ids_set.erase(mailEntry->ID); // output error for any still listed (not referenced from appropriate table) ids LootTemplates_Mail.ReportUnusedIds(ids_set); @@ -2818,17 +2800,14 @@ void LoadLootTemplates_Skinning() LootTemplates_Skinning.LoadAndCollectLootIds(ids_set); // remove real entries and check existence loot - for (uint32 i = 1; i < sCreatureStorage.GetMaxEntry(); ++i) + for (auto cInfo : sCreatureStorage) { - if (CreatureInfo const* cInfo = sCreatureStorage.LookupEntry(i)) + if (uint32 lootid = cInfo->SkinningLootId) { - if (uint32 lootid = cInfo->SkinningLootId) - { - if (ids_set.find(lootid) == ids_set.end()) - LootTemplates_Skinning.ReportNotExistedId(lootid); - else - ids_setUsed.insert(lootid); - } + if (ids_set.find(lootid) == ids_set.end()) + LootTemplates_Skinning.ReportNotExistedId(lootid); + else + ids_setUsed.insert(lootid); } } for (uint32 itr : ids_setUsed) @@ -3003,7 +2982,7 @@ void LootMgr::CheckDropStats(ChatHandler& chat, uint32 amountOfCheck, uint32 loo for (auto itemStat : sortedResult) { uint32 itemId = itemStat.first; - ItemPrototype const* pProto = sItemStorage.LookupEntry(itemId); + ItemPrototype const* pProto = sItemStorage.LookupEntry(itemId); if (!pProto) continue; diff --git a/src/game/Maps/GridMap.cpp b/src/game/Maps/GridMap.cpp index bb5fbd8090..958711b3ea 100644 --- a/src/game/Maps/GridMap.cpp +++ b/src/game/Maps/GridMap.cpp @@ -565,12 +565,12 @@ GridMapLiquidStatus GridMap::getLiquidStatus(float x, float y, float z, uint8 Re uint32 liqTypeIdx = liquidEntry->Type; if (entry < 21) { - if (AreaTableEntry const* area = sAreaStore.LookupEntry(getArea(x, y))) + if (AreaTableEntry const* area = sAreaTableStore.LookupEntry(getArea(x, y))) { uint32 overrideLiquid = area->LiquidTypeOverride[entry - 1]; if (!overrideLiquid && area->zone) { - area = GetAreaEntryByAreaID(area->zone); + area = TerrainManager::GetAreaEntryByAreaID(area->zone); if (area) overrideLiquid = area->LiquidTypeOverride[entry - 1]; } @@ -919,10 +919,10 @@ uint16 TerrainInfo::GetAreaFlag(float x, float y, float z, bool* isOutdoors) con if (GetAreaInfo(x, y, z, mogpFlags, adtId, rootId, groupId)) { haveAreaInfo = true; - auto wmoEntries = GetWMOAreaTableEntriesByTripple(rootId, adtId, groupId); + auto wmoEntries = TerrainManager::GetWMOAreaTableEntriesByTripple(rootId, adtId, groupId); for (auto wmoEntry : wmoEntries) { - auto areaEntry = GetAreaEntryByAreaID(wmoEntry->areaId); + auto areaEntry = TerrainManager::GetAreaEntryByAreaID(wmoEntry->areaId); if (areaEntry && areaEntry->mapid == GetMapId()) { atEntry = areaEntry; @@ -939,7 +939,7 @@ uint16 TerrainInfo::GetAreaFlag(float x, float y, float z, bool* isOutdoors) con areaflag = gmap->getArea(x, y); // this used while not all *.map files generated (instances) else - areaflag = GetAreaFlagByMapId(GetMapId()); + areaflag = TerrainManager::GetAreaFlagByMapId(GetMapId()); } if (isOutdoors) @@ -997,12 +997,12 @@ GridMapLiquidStatus TerrainInfo::getLiquidStatus(float x, float y, float z, uint if (liquid_type && liquid_type < 21) { - if (AreaTableEntry const* area = GetAreaEntryByAreaFlagAndMap(GetAreaFlag(x, y, z), GetMapId())) + if (AreaTableEntry const* area = TerrainManager::GetAreaEntryByAreaFlagAndMap(GetAreaFlag(x, y, z), GetMapId())) { uint32 overrideLiquid = area->LiquidTypeOverride[liquid_type - 1]; if (!overrideLiquid && area->zone) { - area = GetAreaEntryByAreaID(area->zone); + area = TerrainManager::GetAreaEntryByAreaID(area->zone); if (area) overrideLiquid = area->LiquidTypeOverride[liquid_type - 1]; } @@ -1126,7 +1126,7 @@ float TerrainInfo::GetWaterOrGroundLevel(float x, float y, float z, float& groun // its shallow water so return ground under it return groundZ; } - + return liquid_status.level; } @@ -1331,3 +1331,61 @@ void TerrainManager::GetZoneAndAreaIdByAreaFlag(uint32& zoneid, uint32& areaid, areaid = entry ? entry->ID : 0; zoneid = entry ? ((entry->zone != 0) ? entry->zone : entry->ID) : 0; } + +int32 TerrainManager::GetAreaFlagByAreaID(uint32 area_id) +{ + AreaFlagByAreaID::iterator i = sAreaFlagByAreaID.find(area_id); + if (i == sAreaFlagByAreaID.end()) + return -1; + + return i->second; +} + +uint32 TerrainManager::GetAreaIdByLocalizedName(const std::string& name) +{ + for (auto areaEntry : sAreaTableStore) + { + for (uint32 i = 0; i < MAX_LOCALE; ++i) + { + std::string area_name(areaEntry->area_name[i]); + if (area_name.size() > 0 && name.find(" - " + area_name) != std::string::npos) + { + return areaEntry->ID; + } + } + } + return 0; +} + +std::vector& TerrainManager::GetWMOAreaTableEntriesByTripple(int32 rootid, int32 adtid, int32 groupid) +{ + return sWMOAreaInfoByTripple[WMOAreaTableTripple(rootid, adtid, groupid)]; +} + +AreaTableEntry const* TerrainManager::GetAreaEntryByAreaID(uint32 area_id) +{ + int32 areaflag = GetAreaFlagByAreaID(area_id); + if (areaflag < 0) + return nullptr; + + return sAreaTableStore.LookupEntry(areaflag); +} + +AreaTableEntry const* TerrainManager::GetAreaEntryByAreaFlagAndMap(uint32 area_flag, uint32 map_id) +{ + if (area_flag) + return sAreaTableStore.LookupEntry(area_flag); + + if (MapEntry const* mapEntry = sMapStore.LookupEntry(map_id)) + return GetAreaEntryByAreaID(mapEntry->linked_zone); + + return nullptr; +} + +uint32 TerrainManager::GetAreaFlagByMapId(uint32 mapid) +{ + AreaFlagByMapID::iterator i = sAreaFlagByMapID.find(mapid); + if (i == sAreaFlagByMapID.end()) + return 0; + return i->second; +} diff --git a/src/game/Maps/GridMap.h b/src/game/Maps/GridMap.h index a550c8d09c..8610677123 100644 --- a/src/game/Maps/GridMap.h +++ b/src/game/Maps/GridMap.h @@ -36,6 +36,8 @@ class InstanceData; class Group; class BattleGround; class Map; +struct AreaTableEntry; +struct WMOAreaTableEntry; class GridMap { @@ -234,6 +236,13 @@ class TerrainManager : public MaNGOS::Singleton& GetWMOAreaTableEntriesByTripple(int32 rootid, int32 adtid, int32 groupid); + static AreaTableEntry const* GetAreaEntryByAreaID(uint32 area_id); + static AreaTableEntry const* GetAreaEntryByAreaFlagAndMap(uint32 area_flag, uint32 map_id); + private: TerrainManager(); ~TerrainManager(); diff --git a/src/game/Maps/Map.cpp b/src/game/Maps/Map.cpp index c76c19f221..fcb38ab4b7 100644 --- a/src/game/Maps/Map.cpp +++ b/src/game/Maps/Map.cpp @@ -2597,3 +2597,115 @@ void Map::RemoveFromSpawnCount(const ObjectGuid& guid) { m_spawnedCount[guid.GetEntry()].erase(guid); } + +bool Map::MapCoordinateVsZoneCheck(float x, float y, uint32 mapid, uint32 zone) +{ + WorldMapAreaEntry const* WmaEntry = sWorldMapAreaStore.LookupEntry(zone); + if (WmaEntry && mapid == WmaEntry->map_id && + x >= WmaEntry->x2 && x <= WmaEntry->x1 && y >= WmaEntry->y2 && y <= WmaEntry->y1) + return true; + return false; +} + +bool Map::Zone2MapCoordinates(float& x, float& y, uint32 zone) +{ + WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone); + + // if not listed then map coordinates (instance) + if (!maEntry || maEntry->x2 == maEntry->x1 || maEntry->y2 == maEntry->y1) + return false; + + std::swap(x, y); // at client map coords swapped + x = x * ((maEntry->x2 - maEntry->x1) / 100) + maEntry->x1; + y = y * ((maEntry->y2 - maEntry->y1) / 100) + maEntry->y1; // client y coord from top to down + + return true; +} + +bool Map::Map2ZoneCoordinates(float& x, float& y, uint32 zone) +{ + WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone); + + // if not listed then map coordinates (instance) + if (!maEntry || maEntry->x2 == maEntry->x1 || maEntry->y2 == maEntry->y1) + return false; + + x = (x - maEntry->x1) / ((maEntry->x2 - maEntry->x1) / 100); + y = (y - maEntry->y1) / ((maEntry->y2 - maEntry->y1) / 100); // client y coord from top to down + std::swap(x, y); // client have map coords swapped + + return true; +} + +bool Map::IsPointInAreaTriggerZone(AreaTriggerEntry const* atEntry, uint32 mapid, float x, float y, float z, float delta) +{ + if (mapid != atEntry->mapid) + return false; + + if (atEntry->radius > 0) + { + // if we have radius check it + float dist2 = (x - atEntry->x) * (x - atEntry->x) + (y - atEntry->y) * (y - atEntry->y) + (z - atEntry->z) * (z - atEntry->z); + if (dist2 > (atEntry->radius + delta) * (atEntry->radius + delta)) + return false; + } + else + { + // we have only extent + + // rotate the players position instead of rotating the whole cube, that way we can make a simplified + // is-in-cube check and we have to calculate only one point instead of 4 + + // 2PI = 360, keep in mind that ingame orientation is counter-clockwise + double rotation = 2 * M_PI - atEntry->box_orientation; + double sinVal = sin(rotation); + double cosVal = cos(rotation); + + float playerBoxDistX = x - atEntry->x; + float playerBoxDistY = y - atEntry->y; + + float rotPlayerX = float(atEntry->x + playerBoxDistX * cosVal - playerBoxDistY * sinVal); + float rotPlayerY = float(atEntry->y + playerBoxDistY * cosVal + playerBoxDistX * sinVal); + + // box edges are parallel to coordiante axis, so we can treat every dimension independently :D + float dz = z - atEntry->z; + float dx = rotPlayerX - atEntry->x; + float dy = rotPlayerY - atEntry->y; + if ((fabs(dx) > atEntry->box_x / 2 + delta) || + (fabs(dy) > atEntry->box_y / 2 + delta) || + (fabs(dz) > atEntry->box_z / 2 + delta)) + { + return false; + } + } + + return true; +} + +uint32 Map::GetVirtualMapForMapAndZone(uint32 mapid, uint32 zoneId) +{ + if (mapid != 530) // speed for most cases + return mapid; + + if (WorldMapAreaEntry const* wma = sWorldMapAreaStore.LookupEntry(zoneId)) + return wma->virtual_map_id >= 0 ? wma->virtual_map_id : wma->map_id; + + return mapid; +} + +ContentLevels Map::GetContentLevelsForMapAndZone(uint32 mapid, uint32 zoneId) +{ + mapid = GetVirtualMapForMapAndZone(mapid, zoneId); + if (mapid < 2) + return CONTENT_1_60; + + MapEntry const* mapEntry = sMapStore.LookupEntry(mapid); + if (!mapEntry) + return CONTENT_1_60; + + switch (mapEntry->Expansion()) + { + default: return CONTENT_1_60; + case 1: return CONTENT_61_70; + } +} diff --git a/src/game/Maps/Map.h b/src/game/Maps/Map.h index f1345a1547..019a19f913 100644 --- a/src/game/Maps/Map.h +++ b/src/game/Maps/Map.h @@ -66,25 +66,6 @@ class Transport; #pragma pack(push,1) #endif -struct InstanceTemplate -{ - uint32 map; // instance map - uint32 parent; // non-continent parent instance (for instance with entrance in another instances) - // or 0 (not related to continent 0 map id) - uint32 levelMin; - uint32 levelMax; - uint32 maxPlayers; - uint32 reset_delay; // in days - uint32 script_id; - bool mountAllowed; -}; - -struct WorldTemplate -{ - uint32 map; // non-instance map - uint32 script_id; -}; - enum LevelRequirementVsMode { LEVELREQUIREMENT_HEROIC = 70 @@ -349,6 +330,13 @@ class Map : public GridRefManager bool CanSpawn(TypeID typeId, uint32 dbGuid); + static bool MapCoordinateVsZoneCheck(float x, float y, uint32 mapid, uint32 zone); + static bool Zone2MapCoordinates(float& x, float& y, uint32 zone); + static bool Map2ZoneCoordinates(float& x, float& y, uint32 zone); + static bool IsPointInAreaTriggerZone(AreaTriggerEntry const* atEntry, uint32 mapid, float x, float y, float z, float delta = 0.0f); + static uint32 GetVirtualMapForMapAndZone(uint32 mapid, uint32 zoneId); + static ContentLevels GetContentLevelsForMapAndZone(uint32 mapid, uint32 zoneId); + private: void LoadMapAndVMap(int gx, int gy); diff --git a/src/game/Maps/MapPersistentStateMgr.cpp b/src/game/Maps/MapPersistentStateMgr.cpp index 100040c50e..4fc3c4b49b 100644 --- a/src/game/Maps/MapPersistentStateMgr.cpp +++ b/src/game/Maps/MapPersistentStateMgr.cpp @@ -406,7 +406,7 @@ void DungeonResetScheduler::LoadResetTimes() // load the global respawn times for raid/heroic instances uint32 diff = sWorld.getConfig(CONFIG_UINT32_INSTANCE_RESET_TIME_HOUR) * HOUR; - m_resetTimeByMapId.resize(sMapStore.GetNumRows() + 1); + m_resetTimeByMapId.resize(sMapStore.GetMaxEntry()); result = CharacterDatabase.Query("SELECT mapid, resettime FROM instance_reset"); if (result) { @@ -443,12 +443,8 @@ void DungeonResetScheduler::LoadResetTimes() // calculate new global reset times for expired instances and those that have never been reset yet // add the global reset times to the priority queue - for (uint32 i = 0; i < sInstanceTemplate.GetMaxEntry(); i++) + for (auto temp : sInstanceTemplate) { - InstanceTemplate const* temp = ObjectMgr::GetInstanceTemplate(i); - if (!temp) - continue; - // only raid/heroic maps have a global reset time MapEntry const* mapEntry = sMapStore.LookupEntry(temp->map); if (!mapEntry || !mapEntry->IsDungeon() || !mapEntry->HasResetTime()) @@ -976,10 +972,9 @@ void MapPersistentStateManager::_CleanupExpiredInstancesAtTime(time_t t) void MapPersistentStateManager::InitWorldMaps() { MapPersistentState* state = nullptr; // need any from created for shared pool state - for (uint32 mapid = 0; mapid < sMapStore.GetNumRows(); ++mapid) - if (MapEntry const* entry = sMapStore.LookupEntry(mapid)) - if (!entry->Instanceable()) - state = AddPersistentState(entry, 0, REGULAR_DIFFICULTY, 0, false, false); + for (auto entry : sMapStore) + if (!entry->Instanceable()) + state = AddPersistentState(entry, 0, REGULAR_DIFFICULTY, 0, false, false); } void MapPersistentStateManager::LoadCreatureRespawnTimes() diff --git a/src/game/Maps/TransportMgr.cpp b/src/game/Maps/TransportMgr.cpp index cd7c990909..48d34caf86 100644 --- a/src/game/Maps/TransportMgr.cpp +++ b/src/game/Maps/TransportMgr.cpp @@ -27,9 +27,8 @@ void TransportMgr::LoadTransportAnimationAndRotation() { - for (uint32 i = 0; i < sTransportAnimationStore.GetNumRows(); ++i) - if (TransportAnimationEntry const* anim = sTransportAnimationStore.LookupEntry(i)) - AddPathNodeToTransport(anim->TransportEntry, anim->TimeSeg, anim); + for (auto anim : sTransportAnimationStore) + AddPathNodeToTransport(anim->TransportEntry, anim->TimeSeg, anim); } TransportTemplate* TransportMgr::GetTransportTemplate(uint32 entry) @@ -43,15 +42,14 @@ TransportTemplate* TransportMgr::GetTransportTemplate(uint32 entry) void TransportMgr::LoadTransportTemplates() { - for (uint32 entry = 1; entry <= sGOStorage.GetMaxEntry(); ++entry) + for (auto data : sGOStorage) { - auto data = sGOStorage.LookupEntry(entry); - if (data && data->type == GAMEOBJECT_TYPE_MO_TRANSPORT) + if (data->type == GAMEOBJECT_TYPE_MO_TRANSPORT) { - TransportTemplate& transportTemplate = m_transportTemplates[entry]; - transportTemplate.entry = entry; + TransportTemplate& transportTemplate = m_transportTemplates[data->id]; + transportTemplate.entry = data->id; if (!GenerateWaypoints(data, transportTemplate)) - m_transportTemplates.erase(entry); + m_transportTemplates.erase(data->id); } } } diff --git a/src/game/MotionGenerators/TargetedMovementGenerator.cpp b/src/game/MotionGenerators/TargetedMovementGenerator.cpp index dda20bbd15..7fac4b5c16 100644 --- a/src/game/MotionGenerators/TargetedMovementGenerator.cpp +++ b/src/game/MotionGenerators/TargetedMovementGenerator.cpp @@ -92,7 +92,7 @@ bool TargetedMovementGeneratorMedium::Update(T& owner, const uint32& time_ HandleTargetedMovement(owner, time_diff); - if (owner.movespline->Finalized() && !i_targetReached) + if (owner.movespline->Finalized() && !i_targetReached) HandleFinalizedMovement(owner); return true; diff --git a/src/game/OutdoorPvP/OutdoorPvPSI.cpp b/src/game/OutdoorPvP/OutdoorPvPSI.cpp index 120659a2e7..101ff0e446 100644 --- a/src/game/OutdoorPvP/OutdoorPvPSI.cpp +++ b/src/game/OutdoorPvP/OutdoorPvPSI.cpp @@ -141,7 +141,7 @@ bool OutdoorPvPSI::HandleAreaTrigger(Player* player, uint32 triggerId) // reward the player player->CastSpell(player, SPELL_TRACES_OF_SILITHYST, TRIGGERED_OLD_TRIGGERED); player->RewardHonor(nullptr, 1, HONOR_REWARD_SILITHYST); - player->GetReputationMgr().ModifyReputation(sFactionStore.LookupEntry(FACTION_CENARION_CIRCLE), REPUTATION_REWARD_SILITHYST); + player->GetReputationMgr().ModifyReputation(sFactionStore.LookupEntry(FACTION_CENARION_CIRCLE), REPUTATION_REWARD_SILITHYST); return true; } diff --git a/src/game/PlayerBot/AI/PlayerbotHunterAI.cpp b/src/game/PlayerBot/AI/PlayerbotHunterAI.cpp index a2dd0c8192..844a41527b 100644 --- a/src/game/PlayerBot/AI/PlayerbotHunterAI.cpp +++ b/src/game/PlayerBot/AI/PlayerbotHunterAI.cpp @@ -323,7 +323,7 @@ CombatManeuverReturns PlayerbotHunterAI::DoNextCombatManeuverPVE(Unit* pTarget) if (m_bot.isAttackReady(RANGED_ATTACK)) m_bot.CastSpell(pTarget, AUTO_SHOT, TRIGGERED_OLD_TRIGGERED); - const SpellEntry* spellInfo = sSpellTemplate.LookupEntry(AUTO_SHOT); + const SpellEntry* spellInfo = sSpellTemplate.LookupEntry(AUTO_SHOT); if (!spellInfo) return RETURN_CONTINUE; diff --git a/src/game/PlayerBot/Base/PlayerbotAI.cpp b/src/game/PlayerBot/Base/PlayerbotAI.cpp index aa7d21a4b1..4b0a7cabb7 100644 --- a/src/game/PlayerBot/Base/PlayerbotAI.cpp +++ b/src/game/PlayerBot/Base/PlayerbotAI.cpp @@ -167,7 +167,7 @@ bool PlayerbotAI::CanReachWithSpellAttack(Unit* target) if (target->HasAura(spellId, EFFECT_INDEX_0)) continue; - const SpellEntry* spellInfo = sSpellTemplate.LookupEntry(spellId); + const SpellEntry* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) continue; @@ -240,7 +240,7 @@ uint32 PlayerbotAI::getSpellId(const char* args, bool master) const if (itr->second.state == PLAYERSPELL_REMOVED || itr->second.disabled || IsPassiveSpell(spellId)) continue; - const SpellEntry* pSpellInfo = sSpellTemplate.LookupEntry(spellId); + const SpellEntry* pSpellInfo = sSpellTemplate.LookupEntry(spellId); if (!pSpellInfo) continue; @@ -304,7 +304,7 @@ uint32 PlayerbotAI::getPetSpellId(const char* args) const if (itr->second.state == PETSPELL_REMOVED || IsPassiveSpell(spellId)) continue; - const SpellEntry* pSpellInfo = sSpellTemplate.LookupEntry(spellId); + const SpellEntry* pSpellInfo = sSpellTemplate.LookupEntry(spellId); if (!pSpellInfo) continue; @@ -359,7 +359,7 @@ uint32 PlayerbotAI::initSpell(uint32 spellId) } if (next == 0) { - const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); + const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); if (!pSpellInfo) return spellId; @@ -394,7 +394,7 @@ uint32 PlayerbotAI::initPetSpell(uint32 spellIconId) if (itr->second.state == PETSPELL_REMOVED || IsPassiveSpell(spellId)) continue; - const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); + const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); if (!pSpellInfo) continue; @@ -1799,7 +1799,7 @@ void PlayerbotAI::HandleBotOutgoingPacket(const WorldPacket& packet) p >> spellId >> result >> castCount; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) return; @@ -1950,7 +1950,7 @@ void PlayerbotAI::HandleBotOutgoingPacket(const WorldPacket& packet) uint32 spellId = itr->first; if (itr->second.state == PLAYERSPELL_REMOVED || itr->second.disabled || IsPassiveSpell(spellId)) continue; - const SpellEntry* pSpellInfo = sSpellTemplate.LookupEntry(spellId); + const SpellEntry* pSpellInfo = sSpellTemplate.LookupEntry(spellId); if (!pSpellInfo) continue; @@ -2308,7 +2308,7 @@ void PlayerbotAI::HandleBotOutgoingPacket(const WorldPacket& packet) // DEBUG_LOG("castItemGuid (%s) casterItemGuid(%s) spellId (%u) cast_count (%u) castFlags (%u) msTime (%u)",castItemGuid.GetString().c_str(),casterGuid.GetString().c_str(), spellId, cast_count, castFlags, msTime); - const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); + const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); if (!pSpellInfo) return; @@ -2772,7 +2772,7 @@ Item* PlayerbotAI::FindMount(uint32 matchingRidingSkill) const break; } } - const SpellEntry* const spellInfo = sSpellTemplate.LookupEntry(spellId); + const SpellEntry* const spellInfo = sSpellTemplate.LookupEntry(spellId); if (spellInfo) { Spell* spell = new Spell(m_bot, spellInfo, false); @@ -2812,7 +2812,7 @@ Item* PlayerbotAI::FindMount(uint32 matchingRidingSkill) const break; } } - const SpellEntry* const spellInfo = sSpellTemplate.LookupEntry(spellId); + const SpellEntry* const spellInfo = sSpellTemplate.LookupEntry(spellId); if (spellInfo) { Spell* spell = new Spell(m_bot, spellInfo, false); @@ -5203,7 +5203,7 @@ void PlayerbotAI::UpdateAI(const uint32 /*p_time*/) return; } - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(TAME_BEAST_1); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(TAME_BEAST_1); if (!spellInfo) return; @@ -5255,7 +5255,7 @@ void PlayerbotAI::UpdateAI(const uint32 /*p_time*/) return; } - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(m_CraftSpellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(m_CraftSpellId); if (!spellInfo) return; @@ -5419,11 +5419,11 @@ bool PlayerbotAI::canObeyCommandFrom(const Player& player) const bool PlayerbotAI::In_Range(Unit* Target, uint32 spellId) { - const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); + const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); if (!pSpellInfo) return false; - SpellRangeEntry const* TempRange = GetSpellRangeStore()->LookupEntry(pSpellInfo->rangeIndex); + SpellRangeEntry const* TempRange = sSpellRangeStore.LookupEntry(pSpellInfo->rangeIndex); //Spell has invalid range store so we can't use it if (!TempRange) @@ -5490,7 +5490,7 @@ SpellCastResult PlayerbotAI::CastSpell(uint32 spellId) // see Creature.cpp 1738 for reference // don't allow bot to cast damage spells on friends - const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); + const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); if (!pSpellInfo) { TellMaster("missing spell entry in CastSpell for spellid %u.", spellId); @@ -5632,7 +5632,7 @@ SpellCastResult PlayerbotAI::CastPetSpell(uint32 spellId, Unit* target) if (!pet) return SPELL_FAILED_NO_PET; - const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); + const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); if (!pSpellInfo) { TellMaster("Missing spell entry in CastPetSpell()"); @@ -5685,7 +5685,7 @@ SpellCastResult PlayerbotAI::Buff(uint32 spellId, Unit* target, void (*beforeCas if (target->HasAura(spellId)) return SPELL_FAILED_AURA_BOUNCED; - SpellEntry const* spellProto = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellProto = sSpellTemplate.LookupEntry(spellId); if (!spellProto) return SPELL_NOT_FOUND; @@ -6079,7 +6079,7 @@ bool PlayerbotAI::PickPocket(Unit* pTarget) bool PlayerbotAI::HasSpellReagents(uint32 spellId) { - const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); + const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); if (!pSpellInfo) return false; @@ -6103,7 +6103,7 @@ bool PlayerbotAI::HasSpellReagents(uint32 spellId) uint32 PlayerbotAI::GetSpellCharges(uint32 spellId) { - const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); + const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); if (!pSpellInfo) return 0; @@ -7135,7 +7135,7 @@ void PlayerbotAI::UseItem(Item* item, uint32 targetFlag, ObjectGuid targetGUID) return; } - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) { TellMaster("Can't find spell entry for spell %u on item %u", spellId, item->GetEntry()); @@ -9498,19 +9498,15 @@ void PlayerbotAI::_HandleCommandTalent(std::string& text, Player& fromPlayer) out << "The talents I can learn:\r"; // find class talent tabs (all players have 3 talent tabs) - uint32 const* talentTabIds = GetTalentTabPages(m_bot->getClass()); + uint32 const* talentTabIds = ObjectMgr::GetTalentTabPages(m_bot->getClass()); for (uint32 i = 0; i < 3; ++i) { uint32 talentTabId = talentTabIds[i]; uint32 classMask = m_bot->getClassMask(); - for (uint32 ts = 0; ts < sTalentStore.GetNumRows(); ++ts) + for (auto talentInfo : sTalentStore) { - TalentEntry const* talentInfo = sTalentStore.LookupEntry(ts); - if (!talentInfo) - continue; - TalentTabEntry const* talentTabInfo = sTalentTabStore.LookupEntry(talentInfo->TalentTab); if (!talentTabInfo) continue; @@ -9561,22 +9557,17 @@ void PlayerbotAI::_HandleCommandTalent(std::string& text, Player& fromPlayer) uint32 tTab = talentInfo->TalentTab; if (talentInfo->Row > 0) { - unsigned int numRows = sTalentStore.GetNumRows(); - for (unsigned int i = 0; i < numRows; ++i) // Loop through all talents. + for (auto tmpTalent : sTalentStore) // Loop through all talents. { // Someday, someone needs to revamp - const TalentEntry* tmpTalent = sTalentStore.LookupEntry(i); - if (tmpTalent) // the way talents are tracked + if (tmpTalent->TalentTab == tTab) { - if (tmpTalent->TalentTab == tTab) + for (int j = 0; j < MAX_TALENT_RANK; ++j) { - for (int j = 0; j < MAX_TALENT_RANK; ++j) + if (tmpTalent->RankID[j] != 0) { - if (tmpTalent->RankID[j] != 0) - { - if (m_bot->HasSpell(tmpTalent->RankID[j])) - spentPoints += j + 1; - } + if (m_bot->HasSpell(tmpTalent->RankID[j])) + spentPoints += j + 1; } } } @@ -9587,7 +9578,7 @@ void PlayerbotAI::_HandleCommandTalent(std::string& text, Player& fromPlayer) if (spentPoints < (talentInfo->Row * MAX_TALENT_RANK)) continue; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(talentInfo->RankID[curtalent_maxrank]); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(talentInfo->RankID[curtalent_maxrank]); if (!spellInfo || !SpellMgr::IsSpellValid(spellInfo, m_bot, false)) continue; @@ -9661,7 +9652,7 @@ void PlayerbotAI::_HandleCommandProcess(std::string& text, Player& fromPlayer) Item* reagent = itemList.back(); itemList.pop_back(); - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) return; @@ -9976,7 +9967,7 @@ void PlayerbotAI::_HandleCommandEnchant(std::string& text, Player& fromPlayer) uint32 spellId; extractSpellId(text, spellId); - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) return; @@ -10022,13 +10013,9 @@ void PlayerbotAI::_HandleCommandEnchant(std::string& text, Player& fromPlayer) if (SkillLine->categoryId == SKILL_CATEGORY_PROFESSION && *it == SKILL_ENCHANTING) { - for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j) + for (auto SkillAbility : sSkillLineAbilityStore) { - SkillLineAbilityEntry const* SkillAbility = sSkillLineAbilityStore.LookupEntry(j); - if (!SkillAbility) - continue; - - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(SkillAbility->spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(SkillAbility->spellId); if (!spellInfo) continue; @@ -10182,7 +10169,7 @@ void PlayerbotAI::_HandleCommandCraft(std::string& text, Player& fromPlayer) return; } - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) return; @@ -10216,28 +10203,24 @@ void PlayerbotAI::_HandleCommandCraft(std::string& text, Player& fromPlayer) ChatHandler ch(&fromPlayer); for (std::list::iterator it = m_spellsToLearn.begin(); it != m_spellsToLearn.end(); ++it) { - SkillLineEntry const* SkillLine = sSkillLineStore.LookupEntry(*it); + SkillLineEntry const* skillLine = sSkillLineStore.LookupEntry(*it); - if (SkillLine->categoryId == category && *it == skill) + if (skillLine->categoryId == category && *it == skill) { - for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j) + for (auto skillAbility : sSkillLineAbilityStore) { - SkillLineAbilityEntry const* SkillAbility = sSkillLineAbilityStore.LookupEntry(j); - if (!SkillAbility) - continue; - - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(SkillAbility->spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(skillAbility->spellId); if (!spellInfo) continue; if (IsPrimaryProfessionSkill(*it) && spellInfo->Effect[EFFECT_INDEX_0] != SPELL_EFFECT_CREATE_ITEM) continue; - if (SkillAbility->skillId == *it && m_bot->HasSpell(SkillAbility->spellId) && SkillAbility->forward_spellid == 0 && ((SkillAbility->classmask & m_bot->getClassMask()) == 0)) + if (skillAbility->skillId == *it && m_bot->HasSpell(skillAbility->spellId) && skillAbility->forward_spellid == 0 && ((skillAbility->classmask & m_bot->getClassMask()) == 0)) { MakeSpellLink(spellInfo, msg); ++linkcount; - if ((charges = GetSpellCharges(SkillAbility->spellId)) > 0) + if ((charges = GetSpellCharges(skillAbility->spellId)) > 0) msg << "[" << charges << "]"; if (linkcount >= 10) { @@ -10505,7 +10488,7 @@ void PlayerbotAI::_HandleCommandPet(std::string& text, Player& fromPlayer) if (itr->second.state == PETSPELL_REMOVED || IsPassiveSpell(spellId)) continue; - const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); + const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); if (!pSpellInfo) continue; @@ -10559,7 +10542,7 @@ void PlayerbotAI::_HandleCommandSpells(std::string& /*text*/, Player& fromPlayer if (itr->second.state == PLAYERSPELL_REMOVED || itr->second.disabled || IsPassiveSpell(spellId)) continue; - const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); + const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); if (!pSpellInfo) continue; @@ -10766,7 +10749,7 @@ void PlayerbotAI::_HandleCommandSkill(std::string& text, Player& fromPlayer) ++totalSpellLearnt; totalCost += cost; - const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); + const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); if (!pSpellInfo) continue; @@ -10819,7 +10802,7 @@ void PlayerbotAI::_HandleCommandSkill(std::string& text, Player& fromPlayer) ++totalSpellLearnt; totalCost += cost; - const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); + const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); if (!pSpellInfo) continue; @@ -10880,7 +10863,7 @@ void PlayerbotAI::_HandleCommandSkill(std::string& text, Player& fromPlayer) continue; uint32 spellId = tSpell->spell; - const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); + const SpellEntry* const pSpellInfo = sSpellTemplate.LookupEntry(spellId); if (!pSpellInfo) continue; uint32 cost = uint32(floor(tSpell->spellCost * fDiscountMod)); @@ -10947,19 +10930,15 @@ void PlayerbotAI::_HandleCommandSkill(std::string& text, Player& fromPlayer) for (std::list::iterator it = m_spellsToLearn.begin(); it != m_spellsToLearn.end(); ++it) { if (IsPrimaryProfessionSkill(*it)) - for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j) + for (auto skillLine : sSkillLineAbilityStore) { - SkillLineAbilityEntry const* skillLine = sSkillLineAbilityStore.LookupEntry(j); - if (!skillLine) - continue; - // has skill if (skillLine->skillId == *it && skillLine->learnOnGetSkill == 0) { uint32 SpellId; m_bot->HasSpell(skillLine->forward_spellid) ? SpellId = skillLine->forward_spellid : SpellId = skillLine->spellId; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(SpellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(SpellId); if (!spellInfo) continue; @@ -10981,13 +10960,9 @@ void PlayerbotAI::_HandleCommandSkill(std::string& text, Player& fromPlayer) // has weapon skill if (SkillLine->categoryId == SKILL_CATEGORY_WEAPON) { - for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j) + for (auto skillLine : sSkillLineAbilityStore) { - SkillLineAbilityEntry const* skillLine = sSkillLineAbilityStore.LookupEntry(j); - if (!skillLine) - continue; - - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(skillLine->spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(skillLine->spellId); if (!spellInfo) continue; diff --git a/src/game/PlayerBot/Base/PlayerbotClassAI.cpp b/src/game/PlayerBot/Base/PlayerbotClassAI.cpp index ed11cc5938..7dba41f0e6 100644 --- a/src/game/PlayerBot/Base/PlayerbotClassAI.cpp +++ b/src/game/PlayerBot/Base/PlayerbotClassAI.cpp @@ -236,7 +236,7 @@ bool PlayerbotClassAI::FindTargetAndHeal() if (m_ai.GetClassAI()->HealPlayer(targetToHeal) & RETURN_CONTINUE) return true; - return false; + return false; } /** @@ -402,7 +402,7 @@ bool PlayerbotClassAI::FleeFromAoEIfCan(uint32 spellId, Unit* pTarget) // Step 1: Get radius from hostile AoE spell float radius = 0; - SpellEntry const* spellproto = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellproto = sSpellTemplate.LookupEntry(spellId); if (spellproto) radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(spellproto->EffectRadiusIndex[EFFECT_INDEX_0])); @@ -426,7 +426,7 @@ bool PlayerbotClassAI::FleeFromTrapGOIfCan(uint32 goEntry, Unit* pTarget) if (!goEntry) return false; // Step 1: check if the GO exists and find its trap radius - GameObjectInfo const* trapInfo = sGOStorage.LookupEntry(goEntry); + GameObjectInfo const* trapInfo = sGOStorage.LookupEntry(goEntry); if (!trapInfo || trapInfo->type != GAMEOBJECT_TYPE_TRAP) return false; @@ -463,7 +463,7 @@ bool PlayerbotClassAI::FleeFromNpcWithAuraIfCan(uint32 NpcEntry, uint32 spellId, // Step 1: Get radius from hostile aura spell float radius = 0; - SpellEntry const* spellproto = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellproto = sSpellTemplate.LookupEntry(spellId); if (spellproto) radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(spellproto->EffectRadiusIndex[EFFECT_INDEX_0])); diff --git a/src/game/PlayerBot/Base/PlayerbotMgr.cpp b/src/game/PlayerBot/Base/PlayerbotMgr.cpp index 17b4d7a092..062a0f0de4 100644 --- a/src/game/PlayerBot/Base/PlayerbotMgr.cpp +++ b/src/game/PlayerBot/Base/PlayerbotMgr.cpp @@ -995,13 +995,8 @@ uint32 Player::GetSpec() Player* player = m_session->GetPlayer(); uint32 classMask = player->getClassMask(); - for (unsigned int i = 0; i < sTalentStore.GetNumRows(); ++i) + for (auto talentInfo : sTalentStore) { - TalentEntry const* talentInfo = sTalentStore.LookupEntry(i); - - if (!talentInfo) - continue; - TalentTabEntry const* talentTabInfo = sTalentTabStore.LookupEntry(talentInfo->TalentTab); if (!talentTabInfo) diff --git a/src/game/Reputation/ReputationMgr.cpp b/src/game/Reputation/ReputationMgr.cpp index 39e5d59224..78f0380d62 100644 --- a/src/game/Reputation/ReputationMgr.cpp +++ b/src/game/Reputation/ReputationMgr.cpp @@ -49,7 +49,7 @@ FactionState const* ReputationMgr::GetState(RepListID id) const int32 ReputationMgr::GetReputation(uint32 faction_id) const { - FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction_id); + FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction_id); if (!factionEntry) { @@ -86,7 +86,7 @@ int32 ReputationMgr::GetBaseReputation(FactionEntry const* factionEntry) const bool ReputationMgr::IsAtWar(uint32 faction_id) const { - FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction_id); + FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction_id); if (!factionEntry) { @@ -248,7 +248,7 @@ void ReputationMgr::Initialize() for (unsigned int i = 1; i < sFactionStore.GetMaxEntry(); ++i) { - FactionEntry const* factionEntry = sFactionStore.LookupEntry(i); + FactionEntry const* factionEntry = sFactionStore.LookupEntry(i); if (factionEntry && (factionEntry->HasReputation())) { @@ -282,7 +282,7 @@ void ReputationMgr::SetReputation(FactionEntry const* factionEntry, int32 standi { // bonuses are already given, so just modify standing by rate int32 spilloverRep = standing * repTemplate->faction_rate[i]; - if (SetOneFactionReputation(sFactionStore.LookupEntry(repTemplate->faction[i]), spilloverRep, incremental)) + if (SetOneFactionReputation(sFactionStore.LookupEntry(repTemplate->faction[i]), spilloverRep, incremental)) anyRankIncreased = true; } } @@ -297,7 +297,7 @@ void ReputationMgr::SetReputation(FactionEntry const* factionEntry, int32 standi if (!flist && factionEntry->team && factionEntry->spilloverRateOut != 0.0f) { spillOverRepOut *= factionEntry->spilloverRateOut; - if (FactionEntry const* parent = sFactionStore.LookupEntry(factionEntry->team)) + if (FactionEntry const* parent = sFactionStore.LookupEntry(factionEntry->team)) { FactionStateList::iterator parentState = m_factions.find(parent->reputationListID); // some team factions have own reputation standing, in this case do not spill to other sub-factions @@ -317,7 +317,7 @@ void ReputationMgr::SetReputation(FactionEntry const* factionEntry, int32 standi // Spillover to affiliated factions for (uint32 itr : *flist) { - if (FactionEntry const* factionEntryCalc = sFactionStore.LookupEntry(itr)) + if (FactionEntry const* factionEntryCalc = sFactionStore.LookupEntry(itr)) { if (factionEntryCalc == factionEntry || GetRank(factionEntryCalc) > ReputationRank(factionEntryCalc->spilloverMaxRankIn)) continue; @@ -394,7 +394,7 @@ void ReputationMgr::SetVisible(FactionTemplateEntry const* factionTemplateEntry) if (!factionTemplateEntry || !factionTemplateEntry->faction) return; - if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionTemplateEntry->faction)) + if (FactionEntry const* factionEntry = sFactionStore.LookupEntry(factionTemplateEntry->faction)) SetVisible(factionEntry); } @@ -509,7 +509,7 @@ void ReputationMgr::LoadFromDB(QueryResult* result) { Field* fields = result->Fetch(); - FactionEntry const* factionEntry = sFactionStore.LookupEntry(fields[0].GetUInt32()); + FactionEntry const* factionEntry = sFactionStore.LookupEntry(fields[0].GetUInt32()); if (factionEntry && factionEntry->HasReputation()) { FactionState* faction = &m_factions[factionEntry->reputationListID]; diff --git a/src/game/Server/DBCStores.cpp b/src/game/Server/DBCStores.cpp index 4b02c7cb5d..f826d56e1f 100644 --- a/src/game/Server/DBCStores.cpp +++ b/src/game/Server/DBCStores.cpp @@ -16,888 +16,4 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "Server/DBCStores.h" -#include "Policies/Singleton.h" -#include "Log.h" -#include "ProgressBar.h" -#include "Util.h" -#include "Globals/Locales.h" -#include "Globals/SharedDefines.h" -#include "Server/SQLStorages.h" -#include "DBCfmt.h" - -#include - -typedef std::map AreaFlagByAreaID; -typedef std::map AreaFlagByMapID; - -struct WMOAreaTableTripple -{ - WMOAreaTableTripple(int32 r, int32 a, int32 g) : groupId(g), rootId(r), adtId(a) - { - } - - bool operator <(const WMOAreaTableTripple& b) const - { - return memcmp(this, &b, sizeof(WMOAreaTableTripple)) < 0; - } - - // ordered by entropy; that way memcmp will have a minimal medium runtime - int32 groupId; - int32 rootId; - int32 adtId; -}; - -typedef std::map> WMOAreaInfoByTripple; - -DBCStorage sAreaStore(AreaTableEntryfmt); -static AreaFlagByAreaID sAreaFlagByAreaID; -static AreaFlagByMapID sAreaFlagByMapID; // for instances without generated *.map files - -static WMOAreaInfoByTripple sWMOAreaInfoByTripple; - -DBCStorage sAreaTriggerStore(AreaTriggerEntryfmt); -DBCStorage sAuctionHouseStore(AuctionHouseEntryfmt); -DBCStorage sBankBagSlotPricesStore(BankBagSlotPricesEntryfmt); -DBCStorage sBattlemasterListStore(BattlemasterListEntryfmt); -DBCStorage sCharStartOutfitStore(CharStartOutfitEntryfmt); -DBCStorage sCharTitlesStore(CharTitlesEntryfmt); -DBCStorage sChatChannelsStore(ChatChannelsEntryfmt); -DBCStorage sChrClassesStore(ChrClassesEntryfmt); -DBCStorage sChrRacesStore(ChrRacesEntryfmt); -DBCStorage sCinematicCameraStore(CinematicCameraEntryfmt); -DBCStorage sCinematicSequencesStore(CinematicSequencesEntryfmt); -DBCStorage sCreatureDisplayInfoStore(CreatureDisplayInfofmt); -DBCStorage sCreatureDisplayInfoExtraStore(CreatureDisplayInfoExtrafmt); -DBCStorage sCreatureFamilyStore(CreatureFamilyfmt); -DBCStorage sCreatureModelDataStore(CreatureModelDatafmt); -DBCStorage sCreatureSpellDataStore(CreatureSpellDatafmt); -DBCStorage sCreatureTypeStore(CreatureTypefmt); - -DBCStorage sDurabilityQualityStore(DurabilityQualityfmt); -DBCStorage sDurabilityCostsStore(DurabilityCostsfmt); - -DBCStorage sEmotesStore(EmotesEntryfmt); -DBCStorage sEmotesTextStore(EmotesTextEntryfmt); - -//DBCStorage sFactionStore(FactionEntryfmt); -DBCStorage sFactionTemplateStore(FactionTemplateEntryfmt); - -DBCStorage sGameObjectDisplayInfoStore(GameObjectDisplayInfofmt); -DBCStorage sGemPropertiesStore(GemPropertiesEntryfmt); - -DBCStorage sGMSurveyCurrentSurveyStore(GMSurveyCurrentSurveyfmt); -DBCStorage sGMSurveyQuestionsStore(GMSurveyQuestionsfmt); -DBCStorage sGMSurveySurveysStore(GMSurveySurveysfmt); -DBCStorage sGMTicketCategoryStore(GMTicketCategoryfmt); - -DBCStorage sGtCombatRatingsStore(GtCombatRatingsfmt); -DBCStorage sGtChanceToMeleeCritBaseStore(GtChanceToMeleeCritBasefmt); -DBCStorage sGtChanceToMeleeCritStore(GtChanceToMeleeCritfmt); -DBCStorage sGtChanceToSpellCritBaseStore(GtChanceToSpellCritBasefmt); -DBCStorage sGtChanceToSpellCritStore(GtChanceToSpellCritfmt); -DBCStorage sGtOCTRegenHPStore(GtOCTRegenHPfmt); -DBCStorage sGtNPCManaCostScalerStore(GtNPCManaCostScalerfmt); -// DBCStorage sGtOCTRegenMPStore(GtOCTRegenMPfmt); -- not used currently -DBCStorage sGtRegenHPPerSptStore(GtRegenHPPerSptfmt); -DBCStorage sGtRegenMPPerSptStore(GtRegenMPPerSptfmt); - -DBCStorage sItemStore(Itemfmt); -DBCStorage sItemBagFamilyStore(ItemBagFamilyfmt); -DBCStorage sItemClassStore(ItemClassfmt); -// DBCStorage sItemCondExtCostsStore(ItemCondExtCostsEntryfmt); -// DBCStorage sItemDisplayInfoStore(ItemDisplayTemplateEntryfmt); -- not used currently -DBCStorage sItemExtendedCostStore(ItemExtendedCostEntryfmt); -DBCStorage sItemRandomPropertiesStore(ItemRandomPropertiesfmt); -DBCStorage sItemRandomSuffixStore(ItemRandomSuffixfmt); -DBCStorage sItemSetStore(ItemSetEntryfmt); -DBCStorage sLiquidTypeStore(LiquidTypefmt); -DBCStorage sLockStore(LockEntryfmt); - -DBCStorage sMailTemplateStore(MailTemplateEntryfmt); -DBCStorage sMapStore(MapEntryfmt); - -DBCStorage sQuestSortStore(QuestSortEntryfmt); - -DBCStorage sRandomPropertiesPointsStore(RandomPropertiesPointsfmt); - -DBCStorage sSkillLineStore(SkillLinefmt); -DBCStorage sSkillLineAbilityStore(SkillLineAbilityfmt); -DBCStorage sSkillRaceClassInfoStore(SkillRaceClassInfofmt); -DBCStorage sSkillTiersStore(SkillTiersfmt); - -DBCStorage sSoundEntriesStore(SoundEntriesfmt); - -DBCStorage sSpellItemEnchantmentStore(SpellItemEnchantmentfmt); -DBCStorage sSpellItemEnchantmentConditionStore(SpellItemEnchantmentConditionfmt); -DBCStorage sSpellVisualStore(SpellVisualfmt); -SpellCategoryStore sSpellCategoryStore; -ItemSpellCategoryStore sItemSpellCategoryStore; -PetFamilySpellsStore sPetFamilySpellsStore; - -DBCStorage sSpellCastTimesStore(SpellCastTimefmt); -DBCStorage sSpellDurationStore(SpellDurationfmt); -DBCStorage sSpellFocusObjectStore(SpellFocusObjectfmt); -DBCStorage sSpellRadiusStore(SpellRadiusfmt); -DBCStorage sSpellRangeStore(SpellRangefmt); -DBCStorage sSpellShapeshiftFormStore(SpellShapeshiftfmt); -DBCStorage sStableSlotPricesStore(StableSlotPricesfmt); -DBCStorage sSummonPropertiesStore(SummonPropertiesfmt); -DBCStorage sTalentStore(TalentEntryfmt); -TalentSpellPosMap sTalentSpellPosMap; -DBCStorage sTalentTabStore(TalentTabEntryfmt); - -// store absolute bit position for first rank for talent inspect -typedef std::map TalentInspectMap; -static TalentInspectMap sTalentPosInInspect; -static TalentInspectMap sTalentTabSizeInInspect; -static uint32 sTalentTabPages[12/*MAX_CLASSES*/][3]; - -DBCStorage sTaxiNodesStore(TaxiNodesEntryfmt); -TaxiMask sTaxiNodesMask; - -// DBC used only for initialization sTaxiPathSetBySource at startup. -TaxiPathSetBySource sTaxiPathSetBySource; -DBCStorage sTaxiPathStore(TaxiPathEntryfmt); - -// DBC store data but sTaxiPathNodesByPath used for fast access to entries (it's not owner pointed data). -TaxiPathNodesByPath sTaxiPathNodesByPath; -static DBCStorage sTaxiPathNodeStore(TaxiPathNodeEntryfmt); - -DBCStorage sTransportAnimationStore(TransportAnimationfmt); - -DBCStorage sTotemCategoryStore(TotemCategoryEntryfmt); -DBCStorage sWMOAreaTableStore(WMOAreaTableEntryfmt); -DBCStorage sWorldMapAreaStore(WorldMapAreaEntryfmt); -// DBCStorage sWorldMapOverlayStore(WorldMapOverlayEntryfmt); - -typedef std::list StoreProblemList; - -bool IsAcceptableClientBuild(uint32 build) -{ - int accepted_versions[] = EXPECTED_MANGOSD_CLIENT_BUILD; - for (int i = 0; accepted_versions[i]; ++i) - if (int(build) == accepted_versions[i]) - return true; - - return false; -} - -std::string AcceptableClientBuildsListStr() -{ - std::ostringstream data; - int accepted_versions[] = EXPECTED_MANGOSD_CLIENT_BUILD; - for (int i = 0; accepted_versions[i]; ++i) - data << accepted_versions[i] << " "; - return data.str(); -} - -static bool LoadDBC_assert_print(uint32 fsize, uint32 rsize, const std::string& filename) -{ - sLog.outError("Size of '%s' setted by format string (%u) not equal size of C++ structure (%u).", filename.c_str(), fsize, rsize); - - // ASSERT must fail after function call - return false; -} - -template -inline void LoadDBC(uint32& availableDbcLocales, BarGoLink& bar, StoreProblemList& errlist, DBCStorage& storage, const std::string& dbc_path, const std::string& filename) -{ - // compatibility format and C++ structure sizes - MANGOS_ASSERT(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()) == sizeof(T) || LoadDBC_assert_print(DBCFileLoader::GetFormatRecordSize(storage.GetFormat()), sizeof(T), filename)); - - std::string dbc_filename = dbc_path + filename; - if (storage.Load(dbc_filename.c_str())) - { - bar.step(); - for (uint8 i = 0; fullLocaleNameList[i].name; ++i) - { - if (!(availableDbcLocales & (1 << i))) - continue; - - std::string dbc_filename_loc = dbc_path + fullLocaleNameList[i].name + "/" + filename; - if (!storage.LoadStringsFrom(dbc_filename_loc.c_str())) - availableDbcLocales &= ~(1 << i); // mark as not available for speedup next checks - } - } - else - { - // sort problematic dbc to (1) non compatible and (2) nonexistent - FILE* f = fopen(dbc_filename.c_str(), "rb"); - if (f) - { - char buf[100]; - snprintf(buf, 100, " (exist, but have %u fields instead " SIZEFMTD ") Wrong client version DBC file?", storage.GetFieldCount(), strlen(storage.GetFormat())); - errlist.push_back(dbc_filename + buf); - fclose(f); - } - else - errlist.push_back(dbc_filename); - } -} - -void LoadDBCStores(const std::string& dataPath) -{ - std::string dbcPath = dataPath + "dbc/"; - - const uint32 DBCFilesCount = 66; - - BarGoLink bar(DBCFilesCount); - - StoreProblemList bad_dbc_files; - - // bitmask for index of fullLocaleNameList - uint32 availableDbcLocales = 0xFFFFFFFF; - - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sAreaStore, dbcPath, "AreaTable.dbc"); - - // must be after sAreaStore loading - for (uint32 i = 0; i < sAreaStore.GetNumRows(); ++i) // areaflag numbered from 0 - { - if (AreaTableEntry const* area = sAreaStore.LookupEntry(i)) - { - // fill AreaId->DBC records - sAreaFlagByAreaID.insert(AreaFlagByAreaID::value_type(uint16(area->ID), area->exploreFlag)); - - // fill MapId->DBC records ( skip sub zones and continents ) - if (area->zone == 0 && area->mapid != 0 && area->mapid != 1 && area->mapid != 530) - sAreaFlagByMapID.insert(AreaFlagByMapID::value_type(area->mapid, area->exploreFlag)); - } - } - - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sAreaTriggerStore, dbcPath, "AreaTrigger.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sAuctionHouseStore, dbcPath, "AuctionHouse.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sBankBagSlotPricesStore, dbcPath, "BankBagSlotPrices.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sBattlemasterListStore, dbcPath, "BattlemasterList.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sCharStartOutfitStore, dbcPath, "CharStartOutfit.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sCharTitlesStore, dbcPath, "CharTitles.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sChatChannelsStore, dbcPath, "ChatChannels.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sChrClassesStore, dbcPath, "ChrClasses.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sChrRacesStore, dbcPath, "ChrRaces.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sCinematicCameraStore, dbcPath, "CinematicCamera.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sCinematicSequencesStore, dbcPath, "CinematicSequences.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sCreatureDisplayInfoStore, dbcPath, "CreatureDisplayInfo.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sCreatureDisplayInfoExtraStore, dbcPath, "CreatureDisplayInfoExtra.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sCreatureFamilyStore, dbcPath, "CreatureFamily.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sCreatureModelDataStore, dbcPath, "CreatureModelData.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sCreatureSpellDataStore, dbcPath, "CreatureSpellData.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sCreatureTypeStore, dbcPath, "CreatureType.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sDurabilityCostsStore, dbcPath, "DurabilityCosts.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sDurabilityQualityStore, dbcPath, "DurabilityQuality.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sEmotesStore, dbcPath, "Emotes.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sEmotesTextStore, dbcPath, "EmotesText.dbc"); - // LoadDBC(availableDbcLocales, bar, bad_dbc_files, sFactionStore, dbcPath, "Faction.dbc"); - - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sFactionTemplateStore, dbcPath, "FactionTemplate.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sGameObjectDisplayInfoStore, dbcPath, "GameObjectDisplayInfo.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sGemPropertiesStore, dbcPath, "GemProperties.dbc"); - - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sGMSurveyCurrentSurveyStore, dbcPath, "GMSurveyCurrentSurvey.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sGMSurveyQuestionsStore, dbcPath, "GMSurveyQuestions.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sGMSurveySurveysStore, dbcPath, "GMSurveySurveys.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sGMTicketCategoryStore, dbcPath, "GMTicketCategory.dbc"); - - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sGtCombatRatingsStore, dbcPath, "gtCombatRatings.dbc"); - - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sGtChanceToMeleeCritBaseStore, dbcPath, "gtChanceToMeleeCritBase.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sGtChanceToMeleeCritStore, dbcPath, "gtChanceToMeleeCrit.dbc"); - - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sGtChanceToSpellCritBaseStore, dbcPath, "gtChanceToSpellCritBase.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sGtChanceToSpellCritStore, dbcPath, "gtChanceToSpellCrit.dbc"); - - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sGtOCTRegenHPStore, dbcPath, "gtOCTRegenHP.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sGtNPCManaCostScalerStore, dbcPath, "gtNPCManaCostScaler.dbc"); - // LoadDBC(availableDbcLocales,bar,bad_dbc_files,sGtOCTRegenMPStore, dbcPath,"gtOCTRegenMP.dbc"); -- not used currently - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sGtRegenHPPerSptStore, dbcPath, "gtRegenHPPerSpt.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sGtRegenMPPerSptStore, dbcPath, "gtRegenMPPerSpt.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sItemStore, dbcPath, "Item.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sItemBagFamilyStore, dbcPath, "ItemBagFamily.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sItemClassStore, dbcPath, "ItemClass.dbc"); - // LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemDisplayInfoStore, dbcPath,"ItemDisplayInfo.dbc"); -- not used currently - // LoadDBC(availableDbcLocales,bar,bad_dbc_files,sItemCondExtCostsStore, dbcPath,"ItemCondExtCosts.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sItemExtendedCostStore, dbcPath, "ItemExtendedCost.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sItemRandomPropertiesStore, dbcPath, "ItemRandomProperties.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sItemRandomSuffixStore, dbcPath, "ItemRandomSuffix.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sItemSetStore, dbcPath, "ItemSet.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sLiquidTypeStore, dbcPath, "LiquidType.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sLockStore, dbcPath, "Lock.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sMailTemplateStore, dbcPath, "MailTemplate.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sMapStore, dbcPath, "Map.dbc"); - { - // repairs entry for netherstorm - should be moved to SQL - MapEntry const* mEntry = sMapStore.LookupEntry(550); - MapEntry* tempestKeepMap = new MapEntry(*mEntry); - tempestKeepMap->ghost_entrance_map = 530; - sMapStore.EraseEntry(550); - sMapStore.InsertEntry(tempestKeepMap, 550); - } - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sQuestSortStore, dbcPath, "QuestSort.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sRandomPropertiesPointsStore, dbcPath, "RandPropPoints.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sSkillLineStore, dbcPath, "SkillLine.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sSkillLineAbilityStore, dbcPath, "SkillLineAbility.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sSkillRaceClassInfoStore, dbcPath, "SkillRaceClassInfo.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sSkillTiersStore, dbcPath, "SkillTiers.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sSoundEntriesStore, dbcPath, "SoundEntries.dbc"); - - for (uint32 j = 0; j < sSkillLineAbilityStore.GetNumRows(); ++j) - { - SkillLineAbilityEntry const* skillLine = sSkillLineAbilityStore.LookupEntry(j); - - if (!skillLine) - continue; - - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(skillLine->spellId); - if (spellInfo && (spellInfo->Attributes & (SPELL_ATTR_ABILITY | SPELL_ATTR_PASSIVE | SPELL_ATTR_HIDDEN_CLIENTSIDE | SPELL_ATTR_HIDE_IN_COMBAT_LOG)) == (SPELL_ATTR_ABILITY | SPELL_ATTR_PASSIVE | SPELL_ATTR_HIDDEN_CLIENTSIDE | SPELL_ATTR_HIDE_IN_COMBAT_LOG)) - { - for (unsigned int i = 1; i < sCreatureFamilyStore.GetNumRows(); ++i) - { - CreatureFamilyEntry const* cFamily = sCreatureFamilyStore.LookupEntry(i); - if (!cFamily) - continue; - - if (skillLine->skillId != cFamily->skillLine[0] && skillLine->skillId != cFamily->skillLine[1]) - continue; - - sPetFamilySpellsStore[i].insert(spellInfo->Id); - } - } - } - - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sSpellCastTimesStore, dbcPath, "SpellCastTimes.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sSpellDurationStore, dbcPath, "SpellDuration.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sSpellFocusObjectStore, dbcPath, "SpellFocusObject.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sSpellItemEnchantmentStore, dbcPath, "SpellItemEnchantment.dbc"); - //for (uint32 i = 0; i < sSpellItemEnchantmentStore.GetNumRows(); ++i) - //{ - // SpellItemEnchantmentEntry const* enchantEntry = sSpellItemEnchantmentStore.LookupEntry(i); - // if (!enchantEntry) - // continue; - // for (uint32 k = 0; k < 3; ++k) - // { - // if (enchantEntry->spellid[k]) - // if (!sSpellTemplate.LookupEntry(enchantEntry->spellid[k])) - // sLog.outErrorDb("Spell ID %u found in spell item enchant %u does not exist.", enchantEntry->spellid[k], i); - // } - //} - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sSpellItemEnchantmentConditionStore, dbcPath, "SpellItemEnchantmentCondition.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sSpellRadiusStore, dbcPath, "SpellRadius.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sSpellRangeStore, dbcPath, "SpellRange.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sSpellShapeshiftFormStore, dbcPath, "SpellShapeshiftForm.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sSpellVisualStore, dbcPath, "SpellVisual.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sStableSlotPricesStore, dbcPath, "StableSlotPrices.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sSummonPropertiesStore, dbcPath, "SummonProperties.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sTalentStore, dbcPath, "Talent.dbc"); - - // create talent spells set - for (unsigned int i = 0; i < sTalentStore.GetNumRows(); ++i) - { - TalentEntry const* talentInfo = sTalentStore.LookupEntry(i); - if (!talentInfo) continue; - for (int j = 0; j < 5; ++j) - if (talentInfo->RankID[j]) - sTalentSpellPosMap[talentInfo->RankID[j]] = TalentSpellPos(i, j); - } - - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sTalentTabStore, dbcPath, "TalentTab.dbc"); - - // prepare fast data access to bit pos of talent ranks for use at inspecting - { - // fill table by amount of talent ranks and fill sTalentTabBitSizeInInspect - // store in with (row,col,talent)->size key for correct sorting by (row,col) - typedef std::map TalentBitSize; - TalentBitSize sTalentBitSize; - for (uint32 i = 1; i < sTalentStore.GetNumRows(); ++i) - { - TalentEntry const* talentInfo = sTalentStore.LookupEntry(i); - if (!talentInfo) continue; - - TalentTabEntry const* talentTabInfo = sTalentTabStore.LookupEntry(talentInfo->TalentTab); - if (!talentTabInfo) - continue; - - // find talent rank - uint32 curtalent_maxrank = 0; - for (uint32 k = 5; k > 0; --k) - { - if (talentInfo->RankID[k - 1]) - { - curtalent_maxrank = k; - break; - } - } - - sTalentBitSize[(talentInfo->Row << 24) + (talentInfo->Col << 16) + talentInfo->TalentID] = curtalent_maxrank; - sTalentTabSizeInInspect[talentInfo->TalentTab] += curtalent_maxrank; - } - - // now have all max ranks (and then bit amount used for store talent ranks in inspect) - for (uint32 talentTabId = 1; talentTabId < sTalentTabStore.GetNumRows(); ++talentTabId) - { - TalentTabEntry const* talentTabInfo = sTalentTabStore.LookupEntry(talentTabId); - if (!talentTabInfo) - continue; - - // prevent memory corruption; otherwise cls will become 12 below - if ((talentTabInfo->ClassMask & CLASSMASK_ALL_PLAYABLE) == 0) - continue; - - // store class talent tab pages - uint32 cls = 1; - for (uint32 m = 1; !(m & talentTabInfo->ClassMask) && cls < MAX_CLASSES; m <<= 1, ++cls) {} - - sTalentTabPages[cls][talentTabInfo->tabpage] = talentTabId; - - // add total amount bits for first rank starting from talent tab first talent rank pos. - uint32 pos = 0; - for (TalentBitSize::iterator itr = sTalentBitSize.begin(); itr != sTalentBitSize.end(); ++itr) - { - uint32 talentId = itr->first & 0xFFFF; - TalentEntry const* talentInfo = sTalentStore.LookupEntry(talentId); - if (!talentInfo) - continue; - - if (talentInfo->TalentTab != talentTabId) - continue; - - sTalentPosInInspect[talentId] = pos; - pos += itr->second; - } - } - } - - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sTaxiNodesStore, dbcPath, "TaxiNodes.dbc"); - - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sTaxiPathStore, dbcPath, "TaxiPath.dbc"); - for (uint32 i = 1; i < sTaxiPathStore.GetNumRows(); ++i) - if (TaxiPathEntry const* entry = sTaxiPathStore.LookupEntry(i)) - sTaxiPathSetBySource[entry->from][entry->to] = TaxiPathBySourceAndDestination(entry->ID, entry->price); - uint32 pathCount = sTaxiPathStore.GetNumRows(); - - //## TaxiPathNode.dbc ## Loaded only for initialization different structures - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sTaxiPathNodeStore, dbcPath, "TaxiPathNode.dbc"); - // Calculate path nodes count - std::vector pathLength; - pathLength.resize(pathCount); // 0 and some other indexes not used - for (uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i) - if (TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i)) - { - if (pathLength[entry->path] < entry->index + 1) - pathLength[entry->path] = entry->index + 1; - } - // Set path length - sTaxiPathNodesByPath.resize(pathCount); // 0 and some other indexes not used - for (uint32 i = 1; i < sTaxiPathNodesByPath.size(); ++i) - sTaxiPathNodesByPath[i].resize(pathLength[i]); - // fill data (pointers to sTaxiPathNodeStore elements - for (uint32 i = 1; i < sTaxiPathNodeStore.GetNumRows(); ++i) - if (TaxiPathNodeEntry const* entry = sTaxiPathNodeStore.LookupEntry(i)) - sTaxiPathNodesByPath[entry->path].set(entry->index, entry); - - // Initialize global taxinodes mask - // include existing nodes that have at least single not spell base (scripted) path - { - std::set spellPaths; - for (uint32 i = 1; i < sSpellTemplate.GetMaxEntry(); ++i) - if (SpellEntry const* sInfo = sSpellTemplate.LookupEntry(i)) - for (int j = 0; j < MAX_EFFECT_INDEX; ++j) - if (sInfo->Effect[j] == 123 /*SPELL_EFFECT_SEND_TAXI*/) - spellPaths.insert(sInfo->EffectMiscValue[j]); - - memset(sTaxiNodesMask, 0, sizeof(sTaxiNodesMask)); - for (uint32 i = 1; i < sTaxiNodesStore.GetNumRows(); ++i) - { - TaxiNodesEntry const* node = sTaxiNodesStore.LookupEntry(i); - if (!node) - continue; - - TaxiPathSetBySource::const_iterator src_i = sTaxiPathSetBySource.find(i); - if (src_i != sTaxiPathSetBySource.end() && !src_i->second.empty()) - { - bool ok = false; - for (const auto& dest_i : src_i->second) - { - // not spell path - if (spellPaths.find(dest_i.second.ID) == spellPaths.end()) - { - ok = true; - break; - } - } - - if (!ok) - continue; - } - - // valid taxi network node - uint8 field = (uint8)((i - 1) / 32); - uint32 submask = 1 << ((i - 1) % 32); - sTaxiNodesMask[field] |= submask; - } - } - - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sTransportAnimationStore, dbcPath, "TransportAnimation.dbc"); - - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sTotemCategoryStore, dbcPath, "TotemCategory.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sWorldMapAreaStore, dbcPath, "WorldMapArea.dbc"); - LoadDBC(availableDbcLocales, bar, bad_dbc_files, sWMOAreaTableStore, dbcPath, "WMOAreaTable.dbc"); - for (uint32 i = 0; i < sWMOAreaTableStore.GetNumRows(); ++i) - { - if (WMOAreaTableEntry const* entry = sWMOAreaTableStore.LookupEntry(i)) - { - sWMOAreaInfoByTripple[WMOAreaTableTripple(entry->rootId, entry->adtId, entry->groupId)].push_back(entry); - } - } - // LoadDBC(availableDbcLocales,bar,bad_dbc_files,sWorldMapOverlayStore, dbcPath,"WorldMapOverlay.dbc"); - // LoadDBC(availableDbcLocales, bar, bad_dbc_files, sWorldSafeLocsStore, dbcPath, "WorldSafeLocs.dbc"); - - // error checks - if (bad_dbc_files.size() >= DBCFilesCount) - { - sLog.outError("\nIncorrect DataDir value in mangosd.conf or ALL required *.dbc files (%d) not found by path: %sdbc", DBCFilesCount, dataPath.c_str()); - Log::WaitBeforeContinueIfNeed(); - exit(1); - } - if (!bad_dbc_files.empty()) - { - std::string str; - for (auto& bad_dbc_file : bad_dbc_files) - str += bad_dbc_file + "\n"; - - sLog.outError("\nSome required *.dbc files (%u from %d) not found or not compatible:\n%s", (uint32)bad_dbc_files.size(), DBCFilesCount, str.c_str()); - Log::WaitBeforeContinueIfNeed(); - exit(1); - } - - // Check loaded DBC files proper version - if (!sSkillLineAbilityStore.LookupEntry(17514) || - !sMapStore.LookupEntry(598) || - !sGemPropertiesStore.LookupEntry(1127) || - !sItemExtendedCostStore.LookupEntry(2425) || - !sCharTitlesStore.LookupEntry(71) || - !sAreaStore.LookupEntry(1768)) - { - sLog.outError("\nYou have _outdated_ DBC files. Please re-extract DBC files for one from client build: %s", AcceptableClientBuildsListStr().c_str()); - Log::WaitBeforeContinueIfNeed(); - exit(1); - } - - sLog.outString(">> Initialized %d data stores", DBCFilesCount); - sLog.outString(); -} - -char const* GetPetName(uint32 petfamily, uint32 dbclang) -{ - if (!petfamily) - return nullptr; - CreatureFamilyEntry const* pet_family = sCreatureFamilyStore.LookupEntry(petfamily); - if (!pet_family) - return nullptr; - return pet_family->Name[dbclang] ? pet_family->Name[dbclang] : nullptr; -} - -TalentSpellPos const* GetTalentSpellPos(uint32 spellId) -{ - TalentSpellPosMap::const_iterator itr = sTalentSpellPosMap.find(spellId); - if (itr == sTalentSpellPosMap.end()) - return nullptr; - - return &itr->second; -} - -uint32 GetTalentSpellCost(TalentSpellPos const* pos) -{ - if (pos) - return pos->rank + 1; - - return 0; -} - -uint32 GetTalentSpellCost(uint32 spellId) -{ - return GetTalentSpellCost(GetTalentSpellPos(spellId)); -} - -int32 GetAreaFlagByAreaID(uint32 area_id) -{ - AreaFlagByAreaID::iterator i = sAreaFlagByAreaID.find(area_id); - if (i == sAreaFlagByAreaID.end()) - return -1; - - return i->second; -} - -uint32 GetAreaIdByLocalizedName(const std::string& name) -{ - for (uint32 i = 0; i <= sAreaStore.GetNumRows(); i++) - { - if (AreaTableEntry const* AreaEntry = sAreaStore.LookupEntry(i)) - { - for (uint32 i = 0; i < MAX_LOCALE; ++i) - { - std::string area_name(AreaEntry->area_name[i]); - if (area_name.size() > 0 && name.find(" - " + area_name) != std::string::npos) - { - return AreaEntry->ID; - } - } - } - } - return 0; -} - -std::vector& GetWMOAreaTableEntriesByTripple(int32 rootid, int32 adtid, int32 groupid) -{ - return sWMOAreaInfoByTripple[WMOAreaTableTripple(rootid, adtid, groupid)]; -} - -AreaTableEntry const* GetAreaEntryByAreaID(uint32 area_id) -{ - int32 areaflag = GetAreaFlagByAreaID(area_id); - if (areaflag < 0) - return nullptr; - - return sAreaStore.LookupEntry(areaflag); -} - -AreaTableEntry const* GetAreaEntryByAreaFlagAndMap(uint32 area_flag, uint32 map_id) -{ - if (area_flag) - return sAreaStore.LookupEntry(area_flag); - - if (MapEntry const* mapEntry = sMapStore.LookupEntry(map_id)) - return GetAreaEntryByAreaID(mapEntry->linked_zone); - - return nullptr; -} - -uint32 GetAreaFlagByMapId(uint32 mapid) -{ - AreaFlagByMapID::iterator i = sAreaFlagByMapID.find(mapid); - if (i == sAreaFlagByMapID.end()) - return 0; - return i->second; -} - -uint32 GetVirtualMapForMapAndZone(uint32 mapid, uint32 zoneId) -{ - if (mapid != 530) // speed for most cases - return mapid; - - if (WorldMapAreaEntry const* wma = sWorldMapAreaStore.LookupEntry(zoneId)) - return wma->virtual_map_id >= 0 ? wma->virtual_map_id : wma->map_id; - - return mapid; -} - -ContentLevels GetContentLevelsForMapAndZone(uint32 mapid, uint32 zoneId) -{ - mapid = GetVirtualMapForMapAndZone(mapid, zoneId); - if (mapid < 2) - return CONTENT_1_60; - - MapEntry const* mapEntry = sMapStore.LookupEntry(mapid); - if (!mapEntry) - return CONTENT_1_60; - - switch (mapEntry->Expansion()) - { - default: return CONTENT_1_60; - case 1: return CONTENT_61_70; - } -} - -ChatChannelsEntry const* GetChatChannelsEntryFor(const std::string& name, uint32 channel_id/* = 0*/) -{ - std::wstring wname; - - Utf8toWStr(name, wname); - - if (!channel_id && wname.empty()) - return nullptr; - - // not sorted, numbering index from 0 - for (uint32 i = 0; i < sChatChannelsStore.GetNumRows(); ++i) - { - if (ChatChannelsEntry const* entry = sChatChannelsStore.LookupEntry(i)) - { - std::wstring wpattern; - - // try to match by name first, avoid creating custom channels with same name - if (!wname.empty()) - { - for (uint32 i = 0; i < MAX_LOCALE; ++i) - { - Utf8toWStr(entry->pattern[i], wpattern); - - if (wpattern.empty()) - continue; - - size_t argpos = wpattern.find(L"%s"); - - // formatting arg present: strip and attempt partial match - if (argpos != std::wstring::npos) - { - wpattern.replace(argpos, 2, L""); - - if (wname.find(wpattern) != std::wstring::npos) - return entry; - } - // attempt full match - else if (wname.compare(wpattern) == 0) - return entry; - } - } - - // name still not found, but channel id is provided: possibly no dbc data for client locale - if (channel_id && channel_id == entry->ChannelID) - return entry; - } - } - return nullptr; -} - -bool IsTotemCategoryCompatiableWith(uint32 itemTotemCategoryId, uint32 requiredTotemCategoryId) -{ - if (requiredTotemCategoryId == 0) - return true; - if (itemTotemCategoryId == 0) - return false; - - TotemCategoryEntry const* itemEntry = sTotemCategoryStore.LookupEntry(itemTotemCategoryId); - if (!itemEntry) - return false; - TotemCategoryEntry const* reqEntry = sTotemCategoryStore.LookupEntry(requiredTotemCategoryId); - if (!reqEntry) - return false; - - if (itemEntry->categoryType != reqEntry->categoryType) - return false; - - return (itemEntry->categoryMask & reqEntry->categoryMask) == reqEntry->categoryMask; -} - -bool MapCoordinateVsZoneCheck(float x, float y, uint32 mapid, uint32 zone) -{ - WorldMapAreaEntry const* WmaEntry = sWorldMapAreaStore.LookupEntry(zone); - if (WmaEntry && mapid == WmaEntry->map_id && - x >= WmaEntry->x2 && x <= WmaEntry->x1 && y >= WmaEntry->y2 && y <= WmaEntry->y1) - return true; - return false; -} - -bool Zone2MapCoordinates(float& x, float& y, uint32 zone) -{ - WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone); - - // if not listed then map coordinates (instance) - if (!maEntry || maEntry->x2 == maEntry->x1 || maEntry->y2 == maEntry->y1) - return false; - - std::swap(x, y); // at client map coords swapped - x = x * ((maEntry->x2 - maEntry->x1) / 100) + maEntry->x1; - y = y * ((maEntry->y2 - maEntry->y1) / 100) + maEntry->y1; // client y coord from top to down - - return true; -} - -bool Map2ZoneCoordinates(float& x, float& y, uint32 zone) -{ - WorldMapAreaEntry const* maEntry = sWorldMapAreaStore.LookupEntry(zone); - - // if not listed then map coordinates (instance) - if (!maEntry || maEntry->x2 == maEntry->x1 || maEntry->y2 == maEntry->y1) - return false; - - x = (x - maEntry->x1) / ((maEntry->x2 - maEntry->x1) / 100); - y = (y - maEntry->y1) / ((maEntry->y2 - maEntry->y1) / 100); // client y coord from top to down - std::swap(x, y); // client have map coords swapped - - return true; -} - -uint32 GetTalentInspectBitPosInTab(uint32 talentId) -{ - TalentInspectMap::const_iterator itr = sTalentPosInInspect.find(talentId); - if (itr == sTalentPosInInspect.end()) - return 0; - - return itr->second; -} - -uint32 GetTalentTabInspectBitSize(uint32 talentTabId) -{ - TalentInspectMap::const_iterator itr = sTalentTabSizeInInspect.find(talentTabId); - if (itr == sTalentTabSizeInInspect.end()) - return 0; - - return itr->second; -} - -uint32 const* GetTalentTabPages(uint32 cls) -{ - return sTalentTabPages[cls]; -} - -bool IsPointInAreaTriggerZone(AreaTriggerEntry const* atEntry, uint32 mapid, float x, float y, float z, float delta) -{ - if (mapid != atEntry->mapid) - return false; - - if (atEntry->radius > 0) - { - // if we have radius check it - float dist2 = (x - atEntry->x) * (x - atEntry->x) + (y - atEntry->y) * (y - atEntry->y) + (z - atEntry->z) * (z - atEntry->z); - if (dist2 > (atEntry->radius + delta) * (atEntry->radius + delta)) - return false; - } - else - { - // we have only extent - - // rotate the players position instead of rotating the whole cube, that way we can make a simplified - // is-in-cube check and we have to calculate only one point instead of 4 - - // 2PI = 360, keep in mind that ingame orientation is counter-clockwise - double rotation = 2 * M_PI - atEntry->box_orientation; - double sinVal = sin(rotation); - double cosVal = cos(rotation); - - float playerBoxDistX = x - atEntry->x; - float playerBoxDistY = y - atEntry->y; - - float rotPlayerX = float(atEntry->x + playerBoxDistX * cosVal - playerBoxDistY * sinVal); - float rotPlayerY = float(atEntry->y + playerBoxDistY * cosVal + playerBoxDistX * sinVal); - - // box edges are parallel to coordiante axis, so we can treat every dimension independently :D - float dz = z - atEntry->z; - float dx = rotPlayerX - atEntry->x; - float dy = rotPlayerY - atEntry->y; - if ((fabs(dx) > atEntry->box_x / 2 + delta) || - (fabs(dy) > atEntry->box_y / 2 + delta) || - (fabs(dz) > atEntry->box_z / 2 + delta)) - { - return false; - } - } - - return true; -} - -uint32 GetCreatureModelRace(uint32 model_id) -{ - CreatureDisplayInfoEntry const* displayEntry = sCreatureDisplayInfoStore.LookupEntry(model_id); - if (!displayEntry) - return 0; - CreatureDisplayInfoExtraEntry const* extraEntry = sCreatureDisplayInfoExtraStore.LookupEntry(displayEntry->ExtendedDisplayInfoID); - return extraEntry ? extraEntry->Race : 0; -} - -// script support functions -DBCStorage const* GetSoundEntriesStore() { return &sSoundEntriesStore; } -DBCStorage const* GetSpellRangeStore() { return &sSpellRangeStore; } -// DBCStorage const* GetFactionStore() { return &sFactionStore; } -DBCStorage const* GetItemDisplayStore() { return &sItemStore; } -DBCStorage const* GetCreatureDisplayStore() { return &sCreatureDisplayInfoStore; } -DBCStorage const* GetEmotesStore() { return &sEmotesStore; } -DBCStorage const* GetEmotesTextStore() { return &sEmotesTextStore; } diff --git a/src/game/Server/DBCStores.h b/src/game/Server/DBCStores.h index 5ed9388d69..5d1ee6a517 100644 --- a/src/game/Server/DBCStores.h +++ b/src/game/Server/DBCStores.h @@ -19,151 +19,4 @@ #ifndef MANGOS_DBCSTORES_H #define MANGOS_DBCSTORES_H -#include "Common.h" -#include "Database/DBCStore.h" -#include "Server/DBCStructure.h" - -#include -#include - -bool IsAcceptableClientBuild(uint32 build); -std::string AcceptableClientBuildsListStr(); - -char const* GetPetName(uint32 petfamily, uint32 dbclang); -uint32 GetTalentSpellCost(uint32 spellId); -uint32 GetTalentSpellCost(TalentSpellPos const* pos); -TalentSpellPos const* GetTalentSpellPos(uint32 spellId); - -int32 GetAreaFlagByAreaID(uint32 area_id); // -1 if not found -uint32 GetAreaFlagByMapId(uint32 mapid); - -std::vector& GetWMOAreaTableEntriesByTripple(int32 rootid, int32 adtid, int32 groupid); - -AreaTableEntry const* GetAreaEntryByAreaID(uint32 area_id); -AreaTableEntry const* GetAreaEntryByAreaFlagAndMap(uint32 area_flag, uint32 map_id); - -uint32 GetVirtualMapForMapAndZone(uint32 mapid, uint32 zoneId); - -enum ContentLevels -{ - CONTENT_1_60 = 0, - CONTENT_61_70 -}; -ContentLevels GetContentLevelsForMapAndZone(uint32 mapid, uint32 zoneId); - -ChatChannelsEntry const* GetChatChannelsEntryFor(const std::string& name, uint32 channel_id = 0); - -bool IsTotemCategoryCompatiableWith(uint32 itemTotemCategoryId, uint32 requiredTotemCategoryId); - -bool MapCoordinateVsZoneCheck(float x, float y, uint32 mapid, uint32 zone); -bool Zone2MapCoordinates(float& x, float& y, uint32 zone); -bool Map2ZoneCoordinates(float& x, float& y, uint32 zone); - -uint32 GetTalentInspectBitPosInTab(uint32 talentId); -uint32 GetTalentTabInspectBitSize(uint32 talentTabId); -uint32 const* /*[3]*/ GetTalentTabPages(uint32 cls); - -bool IsPointInAreaTriggerZone(AreaTriggerEntry const* atEntry, uint32 mapid, float x, float y, float z, float delta = 0.0f); - -uint32 GetCreatureModelRace(uint32 model_id); - -extern DBCStorage sAreaStore;// recommend access using functions -extern DBCStorage sAreaTriggerStore; -extern DBCStorage sAuctionHouseStore; -extern DBCStorage sBankBagSlotPricesStore; -extern DBCStorage sBattlemasterListStore; -// extern DBCStorage sChatChannelsStore; -- accessed using function, no usable index -extern DBCStorage sCharStartOutfitStore; -extern DBCStorage sCharTitlesStore; -extern DBCStorage sChatChannelsStore; -extern DBCStorage sChrClassesStore; -extern DBCStorage sChrRacesStore; -extern DBCStorage sCinematicCameraStore; -extern DBCStorage sCinematicSequencesStore; -extern DBCStorage sCreatureDisplayInfoStore; -extern DBCStorage sCreatureDisplayInfoExtraStore; -extern DBCStorage sCreatureFamilyStore; -extern DBCStorage sCreatureModelDataStore; -extern DBCStorage sCreatureSpellDataStore; -extern DBCStorage sCreatureTypeStore; -extern DBCStorage sDurabilityCostsStore; -extern DBCStorage sDurabilityQualityStore; -extern DBCStorage sEmotesStore; -extern DBCStorage sEmotesTextStore; -//extern DBCStorage sFactionStore; -extern DBCStorage sFactionTemplateStore; -extern DBCStorage sGameObjectDisplayInfoStore; -extern DBCStorage sGemPropertiesStore; - -extern DBCStorage sGMSurveyCurrentSurveyStore; -extern DBCStorage sGMSurveyQuestionsStore; -extern DBCStorage sGMSurveySurveysStore; -extern DBCStorage sGMTicketCategoryStore; - -extern DBCStorage sGtCombatRatingsStore; -extern DBCStorage sGtChanceToMeleeCritBaseStore; -extern DBCStorage sGtChanceToMeleeCritStore; -extern DBCStorage sGtChanceToSpellCritBaseStore; -extern DBCStorage sGtChanceToSpellCritStore; -extern DBCStorage sGtOCTRegenHPStore; -extern DBCStorage sGtNPCManaCostScalerStore; -// extern DBCStorage sGtOCTRegenMPStore; -- not used currently -extern DBCStorage sGtRegenHPPerSptStore; -extern DBCStorage sGtRegenMPPerSptStore; -extern DBCStorage sItemStore; -extern DBCStorage sItemBagFamilyStore; -extern DBCStorage sItemClassStore; -// extern DBCStorage sItemDisplayInfoStore; -- not used currently -extern DBCStorage sItemExtendedCostStore; -extern DBCStorage sItemRandomPropertiesStore; -extern DBCStorage sItemRandomSuffixStore; -extern DBCStorage sItemSetStore; -extern DBCStorage sLiquidTypeStore; -extern DBCStorage sLockStore; -extern DBCStorage sMailTemplateStore; -extern DBCStorage sMapStore; -extern DBCStorage sQuestSortStore; -extern DBCStorage sRandomPropertiesPointsStore; -extern DBCStorage sSkillLineStore; -extern DBCStorage sSkillLineAbilityStore; -extern DBCStorage sSkillRaceClassInfoStore; -extern DBCStorage sSkillTiersStore; -extern DBCStorage sSoundEntriesStore; -extern DBCStorage sSpellCastTimesStore; -extern DBCStorage sSpellDurationStore; -extern DBCStorage sSpellFocusObjectStore; -extern DBCStorage sSpellItemEnchantmentStore; -extern DBCStorage sSpellItemEnchantmentConditionStore; -extern SpellCategoryStore sSpellCategoryStore; -extern ItemSpellCategoryStore sItemSpellCategoryStore; -extern PetFamilySpellsStore sPetFamilySpellsStore; -extern DBCStorage sSpellRadiusStore; -extern DBCStorage sSpellRangeStore; -extern DBCStorage sSpellShapeshiftFormStore; -extern DBCStorage sSpellVisualStore; -extern DBCStorage sStableSlotPricesStore; -extern DBCStorage sSummonPropertiesStore; -extern DBCStorage sTalentStore; -extern DBCStorage sTalentTabStore; -extern DBCStorage sTaxiNodesStore; -extern DBCStorage sTaxiPathStore; -extern TaxiMask sTaxiNodesMask; -extern TaxiPathSetBySource sTaxiPathSetBySource; -extern TaxiPathNodesByPath sTaxiPathNodesByPath; -extern DBCStorage sTransportAnimationStore; -extern DBCStorage sTotemCategoryStore; -extern DBCStorage sWMOAreaTableStore; -// extern DBCStorage sWorldMapAreaStore; -- use Zone2MapCoordinates and Map2ZoneCoordinates -// extern DBCStorage sWorldMapOverlayStore; -- not used currently - -void LoadDBCStores(const std::string& dataPath); - -// script support functions -DBCStorage const* GetSoundEntriesStore(); -DBCStorage const* GetSpellRangeStore(); -DBCStorage const* GetFactionStore(); -DBCStorage const* GetItemDisplayStore(); -DBCStorage const* GetCreatureDisplayStore(); -DBCStorage const* GetEmotesStore(); -DBCStorage const* GetEmotesTextStore(); #endif diff --git a/src/game/Server/DBCStructure.h b/src/game/Server/DBCStructure.h index b7c5018703..e458388bb8 100644 --- a/src/game/Server/DBCStructure.h +++ b/src/game/Server/DBCStructure.h @@ -23,10 +23,15 @@ #include "MotionGenerators/Path.h" #include "Platform/Define.h" #include "Globals/SharedDefines.h" +#include "Entities/ObjectVisibilityDefines.h" +#include "Globals/Conditions.h" #include #include #include +#include "Util.h" +#include "Entities/ObjectGuid.h" +#include "Entities/ItemPrototype.h" // Structures using to access raw DBC data and required packing to portability @@ -220,7 +225,7 @@ struct CinematicSequencesEntry struct CreatureDisplayInfoEntry { uint32 Displayid; // 0 m_ID - uint32 ModelId; // 1 + uint32 ModelId; // 1 // 2 m_soundID uint32 ExtendedDisplayInfoID; // 3 m_extendedDisplayInfoID -> CreatureDisplayInfoExtraEntry::DisplayExtraId float scale; // 4 m_creatureModelScale @@ -615,7 +620,7 @@ struct ItemRandomSuffixEntry struct ItemSetEntry { - // uint32 id // 0 m_ID + uint32 id; // 0 m_ID char* name[16]; // 1-16 m_name_lang // 17 string flags // uint32 itemId[17]; // 18-34 m_itemID @@ -1254,13 +1259,6 @@ struct WorldSafeLocsEntry }; */ -// GCC have alternative #pragma pack() syntax and old gcc version not support pack(pop), also any gcc version not support it at some platform -#if defined( __GNUC__ ) -#pragma pack() -#else -#pragma pack(pop) -#endif - struct ItemCategorySpellPair { uint32 spellId; @@ -1304,4 +1302,840 @@ typedef std::vector TaxiPathNodesByPath; #define TaxiMaskSize 16 typedef uint32 TaxiMask[TaxiMaskSize]; + +#define CREATURE_MAX_SPELLS 10 +#define MAX_KILL_CREDIT 2 +#define MAX_CREATURE_MODEL 4 +#define USE_DEFAULT_DATABASE_LEVEL 0 // just used to show we don't want to force the new creature level and use the level stored in db +#define MINIMUM_LOOTING_TIME (2 * MINUTE * IN_MILLISECONDS) // give player enough time to pick loot + +// from `creature_addon` and `creature_template_addon`tables +struct CreatureDataAddon +{ + uint32 guidOrEntry; + uint32 mount; + uint32 bytes1; + uint8 sheath_state; // SheathState + uint8 flags; // UnitBytes2_Flags + uint32 emote; + uint32 move_flags; + uint32 const* auras; // loaded as char* "spell1 spell2 ... " +}; + +// Bases values for given Level and UnitClass +struct CreatureClassLvlStats +{ + uint32 BaseHealth; + uint32 BaseMana; + float BaseDamage; + float BaseMeleeAttackPower; + float BaseRangedAttackPower; + uint32 BaseArmor; +}; + +struct CreatureModelInfo +{ + uint32 modelid; + float bounding_radius; + float combat_reach; + float SpeedWalk; + float SpeedRun; + uint8 gender; + uint32 modelid_other_gender; // The oposite gender for this modelid (male/female) + uint32 modelid_alternative; // An alternative model. Generally same gender(2) +}; + +struct CreatureModelRace +{ + uint32 modelid; // Native model/base model the selection is for + uint32 racemask; // Races it applies to (and then a player source must exist for selection) + uint32 creature_entry; // Modelid from creature_template.entry will be selected + uint32 modelid_racial; // Explicit modelid. Used if creature_template entry is not defined +}; + +struct CreatureConditionalSpawn +{ + uint32 Guid; + uint32 EntryAlliance; + uint32 EntryHorde; + // Note: future condition flags to be added +}; + +// from `creature_template` table +struct CreatureInfo +{ + uint32 Entry; + char* Name; + char* SubName; + char* IconName; + uint32 MinLevel; + uint32 MaxLevel; + uint32 HeroicEntry; + uint32 ModelId[MAX_CREATURE_MODEL]; + uint32 Faction; + float Scale; + uint32 Family; // enum CreatureFamily values (optional) + uint32 CreatureType; // enum CreatureType values + uint32 InhabitType; + uint32 RegenerateStats; + bool RacialLeader; + uint32 NpcFlags; + uint32 UnitFlags; // enum UnitFlags mask values + uint32 DynamicFlags; + uint32 ExtraFlags; + uint32 CreatureTypeFlags; // enum CreatureTypeFlags mask values + float SpeedWalk; + float SpeedRun; + uint32 Detection; // Detection Range for Line of Sight aggro + uint32 CallForHelp; + uint32 Pursuit; + uint32 Leash; + uint32 Timeout; + uint32 UnitClass; // enum Classes. Note only 4 classes are known for creatures. + uint32 Rank; + int32 Expansion; // creature expansion, important for stats, CAN BE -1 as marker for some invalid cases. + float HealthMultiplier; + float PowerMultiplier; + float DamageMultiplier; + float DamageVariance; + float ArmorMultiplier; + float ExperienceMultiplier; + uint32 MinLevelHealth; + uint32 MaxLevelHealth; + uint32 MinLevelMana; + uint32 MaxLevelMana; + float MinMeleeDmg; + float MaxMeleeDmg; + float MinRangedDmg; + float MaxRangedDmg; + uint32 Armor; + uint32 MeleeAttackPower; + uint32 RangedAttackPower; + uint32 MeleeBaseAttackTime; + uint32 RangedBaseAttackTime; + uint32 DamageSchool; + uint32 MinLootGold; + uint32 MaxLootGold; + uint32 LootId; + uint32 PickpocketLootId; + uint32 SkinningLootId; + uint32 KillCredit[MAX_KILL_CREDIT]; + uint32 MechanicImmuneMask; + uint32 SchoolImmuneMask; + int32 ResistanceHoly; + int32 ResistanceFire; + int32 ResistanceNature; + int32 ResistanceFrost; + int32 ResistanceShadow; + int32 ResistanceArcane; + uint32 PetSpellDataId; + uint32 MovementType; + uint32 TrainerType; + uint32 TrainerSpell; + uint32 TrainerClass; + uint32 TrainerRace; + uint32 TrainerTemplateId; + uint32 VendorTemplateId; + uint32 EquipmentTemplateId; + uint32 GossipMenuId; + VisibilityDistanceType visibilityDistanceType; + char const* AIName; + uint32 ScriptID; + + // helpers + static HighGuid GetHighGuid() + { + return HIGHGUID_UNIT; // in pre-3.x always HIGHGUID_UNIT + } + + ObjectGuid GetObjectGuid(uint32 lowguid) const { return ObjectGuid(GetHighGuid(), Entry, lowguid); } + + SkillType GetRequiredLootSkill() const + { + if (CreatureTypeFlags & CREATURE_TYPEFLAGS_HERBLOOT) + return SKILL_HERBALISM; + if (CreatureTypeFlags & CREATURE_TYPEFLAGS_MININGLOOT) + return SKILL_MINING; + + return SKILL_SKINNING; // normal case + } + + bool isTameable() const + { + return CreatureType == CREATURE_TYPE_BEAST && Family != 0 && (CreatureTypeFlags & CREATURE_TYPEFLAGS_TAMEABLE); + } +}; + +struct CreatureTemplateSpells +{ + uint32 entry; + uint32 setId; + uint32 spells[CREATURE_MAX_SPELLS]; +}; + +struct CreatureCooldowns +{ + uint32 entry; + uint32 spellId; + uint32 cooldownMin; + uint32 cooldownMax; +}; + +struct EquipmentInfo +{ + uint32 entry; + uint32 equipentry[3]; +}; + +// depricated old way +struct EquipmentInfoRaw +{ + uint32 entry; + uint32 equipmodel[3]; + uint32 equipinfo[3]; + uint32 equipslot[3]; +}; + +struct CreatureSpawnTemplate +{ + uint32 entry; + int64 unitFlags; + uint32 faction; + uint32 modelId; + int32 equipmentId; + uint32 curHealth; + uint32 curMana; + uint32 spawnFlags; + + bool IsRunning() const { return (spawnFlags & SPAWN_FLAG_RUN_ON_SPAWN) != 0; } + bool IsHovering() const { return (spawnFlags & SPAWN_FLAG_HOVER) != 0; } +}; + +// from `creature` table +struct CreatureData +{ + uint32 id; // entry in creature_template + uint16 mapid; + uint32 modelid_override; // overrides any model defined in creature_template + int32 equipmentId; + float posX; + float posY; + float posZ; + float orientation; + uint32 spawntimesecsmin; + uint32 spawntimesecsmax; + float spawndist; + uint32 currentwaypoint; + uint32 curhealth; + uint32 curmana; + bool is_dead; + uint8 movementType; + uint8 spawnMask; + int16 gameEvent; + uint16 GuidPoolId; + uint16 EntryPoolId; + uint16 OriginalZoneId; + CreatureSpawnTemplate const* spawnTemplate; + + // helper function + ObjectGuid GetObjectGuid(uint32 lowguid) const { return ObjectGuid(CreatureInfo::GetHighGuid(), id, lowguid); } + uint32 GetRandomRespawnTime() const { return urand(spawntimesecsmin, spawntimesecsmax); } + + // return false if it should be handled by GameEventMgr or PoolMgr + bool IsNotPartOfPoolOrEvent() const { return (!gameEvent && !GuidPoolId && !EntryPoolId); } +}; + +struct PageText +{ + uint32 Page_ID; + char* Text; + + uint32 Next_Page; +}; + +struct InstanceTemplate +{ + uint32 map; // instance map + uint32 parent; // non-continent parent instance (for instance with entrance in another instances) + // or 0 (not related to continent 0 map id) + uint32 levelMin; + uint32 levelMax; + uint32 maxPlayers; + uint32 reset_delay; // in days + uint32 script_id; + bool mountAllowed; +}; + +struct WorldTemplate +{ + uint32 map; // non-instance map + uint32 script_id; +}; + +struct SpellCone +{ + uint32 spellId; + int32 coneAngle; +}; + +struct WorldSafeLocsEntry +{ + uint32 ID; + uint32 map_id; + float x; + float y; + float z; + float o; + char* name; +}; + +// from `gameobject_template` +struct GameObjectInfo +{ + uint32 id; + uint32 type; + uint32 displayId; + char* name; + char* IconName; + char* castBarCaption; + uint32 faction; + uint32 flags; + uint32 ExtraFlags; + float size; + union // different GO types have different data field + { + //0 GAMEOBJECT_TYPE_DOOR + struct + { + uint32 startOpen; //0 used client side to determine GO_ACTIVATED means open/closed + uint32 lockId; //1 -> Lock.dbc + uint32 autoCloseTime; //2 secs till autoclose = autoCloseTime / 0x10000 + uint32 noDamageImmune; //3 break opening whenever you recieve damage? + uint32 openTextID; //4 can be used to replace castBarCaption? + uint32 closeTextID; //5 + } door; + //1 GAMEOBJECT_TYPE_BUTTON + struct + { + uint32 startOpen; //0 + uint32 lockId; //1 -> Lock.dbc + uint32 autoCloseTime; //2 secs till autoclose = autoCloseTime / 0x10000 + uint32 linkedTrapId; //3 + uint32 noDamageImmune; //4 isBattlegroundObject + uint32 large; //5 + uint32 openTextID; //6 can be used to replace castBarCaption? + uint32 closeTextID; //7 + uint32 losOK; //8 + } button; + //2 GAMEOBJECT_TYPE_QUESTGIVER + struct + { + uint32 lockId; //0 -> Lock.dbc + uint32 questList; //1 + uint32 pageMaterial; //2 + uint32 gossipID; //3 + uint32 customAnim; //4 + uint32 noDamageImmune; //5 + int32 openTextID; //6 can be used to replace castBarCaption? + uint32 losOK; //7 + uint32 allowMounted; //8 + uint32 large; //9 + } questgiver; + //3 GAMEOBJECT_TYPE_CHEST + struct + { + uint32 lockId; //0 -> Lock.dbc + uint32 lootId; //1 + uint32 chestRestockTime; //2 + uint32 consumable; //3 + uint32 minSuccessOpens; //4 + uint32 maxSuccessOpens; //5 + int32 eventId; //6 lootedEvent + uint32 linkedTrapId; //7 + uint32 questId; //8 not used currently but store quest required for GO activation for player + uint32 level; //9 + uint32 losOK; //10 + uint32 leaveLoot; //11 + uint32 notInCombat; //12 + uint32 logLoot; //13 + uint32 openTextID; //14 can be used to replace castBarCaption? + uint32 groupLootRules; //15 + } chest; + //4 GAMEOBJECT_TYPE_BINDER - empty + //5 GAMEOBJECT_TYPE_GENERIC + struct + { + uint32 floatingTooltip; //0 + uint32 highlight; //1 + uint32 serverOnly; //2 + uint32 large; //3 + uint32 floatOnWater; //4 + uint32 questID; //5 + } _generic; + //6 GAMEOBJECT_TYPE_TRAP + struct + { + uint32 lockId; //0 -> Lock.dbc + uint32 level; //1 + uint32 diameter; //2 radius for trap activation + uint32 spellId; //3 + uint32 charges; //4 need respawn (if > 0) + uint32 cooldown; //5 time in secs + int32 autoCloseTime; //6 + uint32 startDelay; //7 + uint32 serverOnly; //8 + uint32 stealthed; //9 + uint32 large; //10 + uint32 invisible; //11 + uint32 openTextID; //12 can be used to replace castBarCaption? + uint32 closeTextID; //13 + } trap; + //7 GAMEOBJECT_TYPE_CHAIR + struct + { + uint32 slots; //0 + uint32 height; //1 + uint32 onlyCreatorUse; //2 + } chair; + //8 GAMEOBJECT_TYPE_SPELL_FOCUS + struct + { + uint32 focusId; //0 + uint32 dist; //1 + uint32 linkedTrapId; //2 + uint32 serverOnly; //3 + uint32 questID; //4 + uint32 large; //5 + } spellFocus; + //9 GAMEOBJECT_TYPE_TEXT + struct + { + uint32 pageID; //0 + uint32 language; //1 + uint32 pageMaterial; //2 + uint32 allowMounted; //3 + } text; + //10 GAMEOBJECT_TYPE_GOOBER + struct + { + uint32 lockId; //0 -> Lock.dbc + int32 questId; //1 + uint32 eventId; //2 + uint32 autoCloseTime; //3 + uint32 customAnim; //4 + uint32 consumable; //5 + int32 cooldown; //6 + uint32 pageId; //7 + uint32 language; //8 + uint32 pageMaterial; //9 + uint32 spellId; //10 + uint32 noDamageImmune; //11 + uint32 linkedTrapId; //12 + uint32 large; //13 + uint32 openTextID; //14 can be used to replace castBarCaption? + uint32 closeTextID; //15 + uint32 isPvPObject; //16 flags used only in battlegrounds + uint32 allowMounted; //17 + uint32 floatingTooltip; //18 + uint32 gossipID; //19 + } goober; + //11 GAMEOBJECT_TYPE_TRANSPORT + struct + { + uint32 pause; //0 + uint32 startOpen; //1 + uint32 autoCloseTime; //2 secs till autoclose = autoCloseTime / 0x10000 + } transport; + //12 GAMEOBJECT_TYPE_AREADAMAGE + struct + { + uint32 lockId; //0 + uint32 radius; //1 + uint32 damageMin; //2 + uint32 damageMax; //3 + uint32 damageSchool; //4 + uint32 autoCloseTime; //5 secs till autoclose = autoCloseTime / 0x10000 + uint32 openTextID; //6 + uint32 closeTextID; //7 + } areadamage; + //13 GAMEOBJECT_TYPE_CAMERA + struct + { + uint32 lockId; //0 -> Lock.dbc + uint32 cinematicId; //1 + uint32 eventID; //2 + uint32 openTextID; //3 can be used to replace castBarCaption? + } camera; + //14 GAMEOBJECT_TYPE_MAPOBJECT - empty + //15 GAMEOBJECT_TYPE_MO_TRANSPORT + struct + { + uint32 taxiPathId; //0 + uint32 moveSpeed; //1 + uint32 accelRate; //2 + uint32 startEventID; //3 + uint32 stopEventID; //4 + uint32 transportPhysics; //5 + uint32 mapID; //6 + } moTransport; + //16 GAMEOBJECT_TYPE_DUELFLAG - empty + //17 GAMEOBJECT_TYPE_FISHINGNODE + struct + { + uint32 _data0; //0 + uint32 lootId; //1 + } fishnode; + //18 GAMEOBJECT_TYPE_SUMMONING_RITUAL + struct + { + uint32 reqParticipants; //0 + uint32 spellId; //1 + uint32 animSpell; //2 + uint32 ritualPersistent; //3 + uint32 casterTargetSpell; //4 + uint32 casterTargetSpellTargets; //5 + uint32 castersGrouped; //6 + uint32 ritualNoTargetCheck; //7 + } summoningRitual; + //19 GAMEOBJECT_TYPE_MAILBOX - empty + //20 GAMEOBJECT_TYPE_AUCTIONHOUSE + struct + { + uint32 actionHouseID; //0 + } auctionhouse; + //21 GAMEOBJECT_TYPE_GUARDPOST + struct + { + uint32 creatureID; //0 + uint32 charges; //1 + } guardpost; + //22 GAMEOBJECT_TYPE_SPELLCASTER + struct + { + uint32 spellId; //0 + int32 charges; //1 + uint32 partyOnly; //2 + uint32 allowMounted; //3 Is usable while on mount/vehicle. (0/1) + uint32 large; //4 + uint32 conditionID1; //5 + } spellcaster; + //23 GAMEOBJECT_TYPE_MEETINGSTONE + struct + { + uint32 minLevel; //0 + uint32 maxLevel; //1 + uint32 areaID; //2 + } meetingstone; + //24 GAMEOBJECT_TYPE_FLAGSTAND + struct + { + uint32 lockId; //0 + uint32 pickupSpell; //1 + uint32 radius; //2 + uint32 returnAura; //3 + uint32 returnSpell; //4 + uint32 noDamageImmune; //5 + uint32 openTextID; //6 + uint32 losOK; //7 + } flagstand; + //25 GAMEOBJECT_TYPE_FISHINGHOLE + struct + { + uint32 radius; //0 how close bobber must land for sending loot + uint32 lootId; //1 + uint32 minSuccessOpens; //2 + uint32 maxSuccessOpens; //3 + uint32 lockId; //4 -> Lock.dbc; possibly 1628 for all? + } fishinghole; + //26 GAMEOBJECT_TYPE_FLAGDROP + struct + { + uint32 lockId; //0 + uint32 eventID; //1 + uint32 pickupSpell; //2 + uint32 noDamageImmune; //3 + uint32 openTextID; //4 + } flagdrop; + //27 GAMEOBJECT_TYPE_MINI_GAME + struct + { + uint32 gameType; //0 + } miniGame; + //29 GAMEOBJECT_TYPE_CAPTURE_POINT + struct + { + uint32 radius; //0 + uint32 spell; //1 + uint32 worldState1; //2 + uint32 worldState2; //3 + uint32 winEventID1; //4 + uint32 winEventID2; //5 + uint32 contestedEventID1; //6 + uint32 contestedEventID2; //7 + uint32 progressEventID1; //8 + uint32 progressEventID2; //9 + uint32 neutralEventID1; //10 + uint32 neutralEventID2; //11 + uint32 neutralPercent; //12 + uint32 worldState3; //13 + uint32 minSuperiority; //14 + uint32 maxSuperiority; //15 + uint32 minTime; //16 + uint32 maxTime; //17 + uint32 large; //18 + uint32 highlight; //19 + } capturePoint; + //30 GAMEOBJECT_TYPE_AURA_GENERATOR + struct + { + uint32 startOpen; //0 + uint32 radius; //1 + uint32 auraID1; //2 + uint32 conditionID1; //3 + uint32 auraID2; //4 + uint32 conditionID2; //5 + int32 serverOnly; //6 + } auraGenerator; + //31 GAMEOBJECT_TYPE_DUNGEON_DIFFICULTY + struct + { + uint32 mapID; //0 + uint32 difficulty; //1 + } dungeonDifficulty; + //32 GAMEOBJECT_TYPE_DO_NOT_USE_YET + struct + { + uint32 mapID; //0 + uint32 difficulty; //1 + } doNotUseYet; + //33 GAMEOBJECT_TYPE_DESTRUCTIBLE_BUILDING + struct + { + uint32 dmgPctState1; //0 + uint32 dmgPctState2; //1 + uint32 state1Name; //2 + uint32 state2Name; //3 + } destructibleBuilding; + //34 GAMEOBJECT_TYPE_GUILDBANK - empty + + // not use for specific field access (only for output with loop by all filed), also this determinate max union size + struct + { + uint32 data[24]; + } raw; + }; + + union + { + //6 GAMEOBJECT_TYPE_TRAP + struct + { + uint32 triggerOn; + } trapCustom; + + //18 GAMEOBJECT_TYPE_SUMMONING_RITUAL + struct + { + uint32 delay; + } summoningRitualCustom; + + struct + { + uint32 data[1]; + } rawCustom; + }; + + uint32 MinMoneyLoot; + uint32 MaxMoneyLoot; + uint32 ScriptId; + + // helpers + bool IsDespawnAtAction() const + { + switch (type) + { + case GAMEOBJECT_TYPE_CHEST: return chest.consumable != 0; + case GAMEOBJECT_TYPE_GOOBER: return goober.consumable != 0; + default: return false; + } + } + + bool IsUsableMounted() const + { + switch (type) + { + case GAMEOBJECT_TYPE_MAILBOX: return true; + case GAMEOBJECT_TYPE_BARBER_CHAIR: return false; + case GAMEOBJECT_TYPE_QUESTGIVER: return questgiver.allowMounted != 0; + case GAMEOBJECT_TYPE_TEXT: return text.allowMounted != 0; + case GAMEOBJECT_TYPE_GOOBER: return goober.allowMounted != 0; + case GAMEOBJECT_TYPE_SPELLCASTER: return spellcaster.allowMounted != 0; + default: return false; + } + } + + uint32 GetLockId() const + { + switch (type) + { + case GAMEOBJECT_TYPE_DOOR: return door.lockId; + case GAMEOBJECT_TYPE_BUTTON: return button.lockId; + case GAMEOBJECT_TYPE_QUESTGIVER: return questgiver.lockId; + case GAMEOBJECT_TYPE_CHEST: return chest.lockId; + case GAMEOBJECT_TYPE_TRAP: return trap.lockId; + case GAMEOBJECT_TYPE_GOOBER: return goober.lockId; + case GAMEOBJECT_TYPE_AREADAMAGE: return areadamage.lockId; + case GAMEOBJECT_TYPE_CAMERA: return camera.lockId; + case GAMEOBJECT_TYPE_FLAGSTAND: return flagstand.lockId; + case GAMEOBJECT_TYPE_FISHINGHOLE: return fishinghole.lockId; + case GAMEOBJECT_TYPE_FLAGDROP: return flagdrop.lockId; + default: return 0; + } + } + + bool GetDespawnPossibility() const // despawn at targeting of cast? + { + switch (type) + { + case GAMEOBJECT_TYPE_DOOR: return door.noDamageImmune != 0; + case GAMEOBJECT_TYPE_BUTTON: return button.noDamageImmune != 0; + case GAMEOBJECT_TYPE_GOOBER: return goober.noDamageImmune != 0; + case GAMEOBJECT_TYPE_FLAGSTAND: return flagstand.noDamageImmune != 0; + case GAMEOBJECT_TYPE_FLAGDROP: return flagdrop.noDamageImmune != 0; + default: return true; + } + } + + bool CannotBeUsedUnderImmunity() const // Cannot be used/activated/looted by players under immunity effects (example: Divine Shield) + { + switch (type) + { + case GAMEOBJECT_TYPE_DOOR: return door.noDamageImmune != 0; + case GAMEOBJECT_TYPE_BUTTON: return button.noDamageImmune != 0; + case GAMEOBJECT_TYPE_QUESTGIVER: return questgiver.noDamageImmune != 0; + case GAMEOBJECT_TYPE_CHEST: return true; // All chests cannot be opened while immune on 3.3.5a + case GAMEOBJECT_TYPE_GOOBER: return goober.noDamageImmune != 0; + case GAMEOBJECT_TYPE_FLAGSTAND: return flagstand.noDamageImmune != 0; + case GAMEOBJECT_TYPE_FLAGDROP: return flagdrop.noDamageImmune != 0; + default: return false; + } + } + + uint32 GetCharges() const // despawn at uses amount + { + switch (type) + { + case GAMEOBJECT_TYPE_TRAP: return trap.charges; + case GAMEOBJECT_TYPE_GUARDPOST: return guardpost.charges; + case GAMEOBJECT_TYPE_SPELLCASTER: return spellcaster.charges; + default: return 0; + } + } + + uint32 GetCooldown() const // not triggering at detection target or use until coolodwn expire + { + switch (type) + { + case GAMEOBJECT_TYPE_TRAP: return trap.cooldown; + case GAMEOBJECT_TYPE_GOOBER: return goober.cooldown; + default: return 0; + } + } + + uint32 GetLinkedGameObjectEntry() const + { + switch (type) + { + case GAMEOBJECT_TYPE_BUTTON: return button.linkedTrapId; + case GAMEOBJECT_TYPE_CHEST: return chest.linkedTrapId; + case GAMEOBJECT_TYPE_SPELL_FOCUS: return spellFocus.linkedTrapId; + case GAMEOBJECT_TYPE_GOOBER: return goober.linkedTrapId; + default: return 0; + } + } + + uint32 GetAutoCloseTime() const + { + uint32 autoCloseTime = 0; + switch (type) + { + case GAMEOBJECT_TYPE_DOOR: autoCloseTime = door.autoCloseTime; break; + case GAMEOBJECT_TYPE_BUTTON: autoCloseTime = button.autoCloseTime; break; + case GAMEOBJECT_TYPE_TRAP: autoCloseTime = trap.autoCloseTime; break; + case GAMEOBJECT_TYPE_GOOBER: autoCloseTime = goober.autoCloseTime; break; + case GAMEOBJECT_TYPE_TRANSPORT: autoCloseTime = transport.autoCloseTime; break; + case GAMEOBJECT_TYPE_AREADAMAGE: autoCloseTime = areadamage.autoCloseTime; break; + default: break; + } + return autoCloseTime / 0x10000; + } + + uint32 GetLootId() const + { + switch (type) + { + case GAMEOBJECT_TYPE_CHEST: return chest.lootId; + case GAMEOBJECT_TYPE_FISHINGHOLE: return fishinghole.lootId; + default: return 0; + } + } + + uint32 GetGossipMenuId() const + { + switch (type) + { + case GAMEOBJECT_TYPE_QUESTGIVER: return questgiver.gossipID; + case GAMEOBJECT_TYPE_GOOBER: return goober.gossipID; + default: return 0; + } + } + + bool IsLargeGameObject() const + { + switch (type) + { + case GAMEOBJECT_TYPE_BUTTON: return button.large != 0; + case GAMEOBJECT_TYPE_QUESTGIVER: return questgiver.large != 0; + case GAMEOBJECT_TYPE_GENERIC: return _generic.large != 0; + case GAMEOBJECT_TYPE_TRAP: return trap.large != 0; + case GAMEOBJECT_TYPE_SPELL_FOCUS: return spellFocus.large != 0; + case GAMEOBJECT_TYPE_GOOBER: return goober.large != 0; + case GAMEOBJECT_TYPE_TRANSPORT: return true; + case GAMEOBJECT_TYPE_SPELLCASTER: return spellcaster.large != 0; + case GAMEOBJECT_TYPE_CAPTURE_POINT: return capturePoint.large != 0; + default: return false; + } + } + + bool IsServerOnly() const + { + switch (type) + { + case GAMEOBJECT_TYPE_GENERIC: return _generic.serverOnly; + case GAMEOBJECT_TYPE_TRAP: return trap.serverOnly; + case GAMEOBJECT_TYPE_SPELL_FOCUS: return spellFocus.serverOnly; + case GAMEOBJECT_TYPE_AURA_GENERATOR: return auraGenerator.serverOnly; + default: return false; + } + } +}; + +// pre-defined targeting for spells +struct SpellTargetEntry +{ + uint32 spellId; + uint32 type; + uint32 targetEntry; + uint32 inverseEffectMask; + + bool CanNotHitWithSpellEffect(SpellEffectIndex effect) const { return (inverseEffectMask & (1 << effect)) != 0; } +}; + +// GCC have alternative #pragma pack() syntax and old gcc version not support pack(pop), also any gcc version not support it at some platform +#if defined( __GNUC__ ) +#pragma pack() +#else +#pragma pack(pop) +#endif + #endif diff --git a/src/game/Server/SQLStorages.cpp b/src/game/Server/SQLStorages.cpp index 86c5c35846..7dd36aa8e0 100644 --- a/src/game/Server/SQLStorages.cpp +++ b/src/game/Server/SQLStorages.cpp @@ -17,53 +17,484 @@ */ #include "Server/SQLStorages.h" +#include "DBCStructure.h" +#include "World/World.h" + +const char CreatureInfosrcfmt[] = "nsssiiiiiiiifiiiiliiiiiffiiiiiiiiffffffiiiiffffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiss"; +const char CreatureInfodstfmt[] = "nsssiiiiiiiifiiiiliiiiiffiiiiiiiiffffffiiiiffffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiisi"; +const char CreatureDataAddonInfofmt[] = "niibbiis"; +const char CreatureConditionalSpawnSrcFmt[] = "niix"; +const char CreatureConditionalSpawnDstFmt[] = "nii"; +const char CreatureModelfmt[] = "nffffbii"; +const char CreatureInfoAddonInfofmt[] = "niibbiis"; +const char EquipmentInfofmt[] = "niii"; +const char EquipmentInfoRawfmt[] = "niiiiiiiii"; +const char GameObjectInfosrcfmt[] = "niisssiiifiiiiiiiiiiiiiiiiiiiiiiiiiiis"; +const char GameObjectInfodstfmt[] = "niisssiiifiiiiiiiiiiiiiiiiiiiiiiiiiiii"; +const char ItemPrototypesrcfmt[] = "niiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifsiiiiii"; +const char ItemPrototypedstfmt[] = "niiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifiiiiiii"; +const char PageTextfmt[] = "nsi"; +const char InstanceTemplatesrcfmt[] = "niiiiisl"; +const char InstanceTemplatedstfmt[] = "niiiiiil"; +const char WorldTemplatesrcfmt[] = "ns"; +const char WorldTemplatedstfmt[] = "ni"; +const char ConditionsFmt[] = "niiiiiix"; +const char SpellScriptTargetFmt[] = "niii"; +const char SpellEntryfmt[] = "niiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiifiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffffffiiiiiiiiiiiiiiiiiiiiifffiiiiiiiiiiiiiiifffiiiissssssssssssssssssssssssssssssssiiiiiLiiiifffiiiiiiiii"; +const char SpellConefmt[] = "ni"; +const char DungeonEncounterFmt[] = "niiiissssssssssssssssii"; +const char FactionEntryfmt[] = "niiiiiiiiiiiiiiiiiiffiissssssssssssssss"; +const char WorldSafeLocsFmt[] = "niffffs"; + +SQLStorage sCreatureStorage(CreatureInfosrcfmt, CreatureInfodstfmt, "", "creature_template"); +SQLStorage sCreatureDataAddonStorage(CreatureDataAddonInfofmt, "creature_addon"); +SQLStorage sCreatureInfoAddonStorage(CreatureInfoAddonInfofmt, "creature_template_addon"); +SQLStorage sCreatureModelStorage(CreatureModelfmt, "creature_model_info"); +SQLStorage sEquipmentStorage(EquipmentInfofmt, "creature_equip_template"); +SQLStorage sEquipmentStorageRaw(EquipmentInfoRawfmt, "creature_equip_template_raw"); +SQLStorage sPageTextStore(PageTextfmt, "page_text"); +SQLStorage sItemStorage(ItemPrototypesrcfmt, ItemPrototypedstfmt, "", "item_template"); +SQLStorage sInstanceTemplate(InstanceTemplatesrcfmt, InstanceTemplatedstfmt, "", "instance_template"); +SQLStorage sWorldTemplate(WorldTemplatesrcfmt, WorldTemplatedstfmt, "", "world_template"); +SQLStorage sConditionStorage(ConditionsFmt, "conditions"); +SQLStorage sSpellTemplate(SpellEntryfmt, "spell_template"); +SQLStorage sSpellCones(SpellConefmt, "spell_cone"); +SQLStorage sDungeonEncounterStore(DungeonEncounterFmt, "instance_dungeon_encounters"); +SQLStorage sFactionStore(FactionEntryfmt, "faction_store"); +SQLStorage sCreatureConditionalSpawnStore(CreatureConditionalSpawnSrcFmt, CreatureConditionalSpawnDstFmt, "", "creature_conditional_spawn"); +SQLStorage sWorldSafeLocsStore(WorldSafeLocsFmt, "world_safe_locs"); + +SQLHashStorage sGOStorage(GameObjectInfosrcfmt, GameObjectInfodstfmt, "entry", "gameobject_template"); +SQLMultiStorage sSpellScriptTargetStorage(SpellScriptTargetFmt, "entry", "spell_script_target"); + +SQLStorage const* GetSpellStore() { return &sSpellTemplate; } + + +// DBC store in database +const char AreaTablefmt[] = "iiiniwwwwwisssssssssssssssswiiiiiww"; +const char AreaTriggerfmt[] = "niffffffff"; +const char AuctionHousefmt[] = "niiiwwwwwwwwwwwwwwwww"; +const char BankBagSlotPricesfmt[] = "ni"; +const char BattlemasterListfmt[] = "niiiiiiiiiiiiwwssssssssssssssssww"; +const char CharStartOutfitfmt[] = "dbbbbiiiiiiiiiiiiwwwwwwwwwwwwwwwwwwwwwwww"; +const char CharTitlesfmt[] = "nwsssssssssssssssswwwwwwwwwwwwwwwwwwi"; +const char ChatChannelsfmt[] = "niwsssssssssssssssswwwwwwwwwwwwwwwwww"; +const char ChrClassesfmt[] = "nwiwsssssssssssssssswwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwiw"; +const char ChrRacesfmt[] = "nwiwiiwwiwwwwisssssssssssssssswwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwi"; +const char CinematicCamerafmt[] = "nsiffff"; +const char CinematicSequencesfmt[] = "nwiwwwwwww"; +const char CreatureDisplayInfofmt[] = "niwifwwwwwwwww"; +const char CreatureDisplayInfoExtrafmt[] = "niwwwwwwwwwwwwwwwwwww"; +const char CreatureFamilyfmt[] = "nfifiiiissssssssssssssssww"; +const char CreatureModelDatafmt[] = "niwwfwwwwwwwwwwffwwwwwww"; +const char CreatureSpellDatafmt[] = "niiiiwwww"; +const char CreatureTypefmt[] = "nwwwwwwwwwwwwwwwwww"; +const char DurabilityCostsfmt[] = "niiiiiiiiiiiiiiiiiiiiiiiiiiiii"; +const char DurabilityQualityfmt[] = "nf"; +const char Emotesfmt[] = "nwwiiiw"; +const char EmotesTextfmt[] = "nwiwwwwwwwwwwwwwwww"; +const char FactionTemplatefmt[] = "niiiiiiiiiiiii"; +const char GameObjectDisplayInfofmt[] = "nswwwwwwwwwwffffff"; +const char GemPropertiesfmt[] = "niwwi"; +const char GMSurveyCurrentSurveyfmt[] = "ni"; +const char GMSurveyQuestionsfmt[] = "nssssssssssssssssw"; +const char GMSurveySurveysfmt[] = "niiiiiiiiii"; +const char GMTicketCategoryfmt[] = "nssssssssssssssssw"; +const char gtCombatRatingsfmt[] = "f"; +const char gtChanceToMeleeCritBasefmt[] = "f"; +const char gtChanceToMeleeCritfmt[] = "f"; +const char gtChanceToSpellCritBasefmt[] = "f"; +const char gtChanceToSpellCritfmt[] = "f"; +const char gtOCTRegenHPfmt[] = "f"; +const char gtNPCManaCostScalerfmt[] = "f"; +const char gtRegenHPPerSptfmt[] = "f"; +const char gtRegenMPPerSptfmt[] = "f"; +const char Itemfmt[] = "niii"; +const char ItemBagFamilyfmt[] = "nwwwwwwwwwwwwwwwww"; +const char ItemClassfmt[] = "nwwssssssssssssssssw"; +const char ItemExtendedCostfmt[] = "niiiiiiiiiiiii"; +const char ItemRandomPropertiesfmt[] = "nwiiiwwssssssssssssssssw"; +const char ItemRandomSuffixfmt[] = "nsssssssssssssssswwiiiiii"; +const char ItemSetfmt[] = "nsssssssssssssssswwwwwwwwwwwwwwwwwwiiiiiiiiiiiiiiiiii"; +const char LiquidTypefmt[] = "niii"; +const char Lockfmt[] = "niiiiiiiiiiiiiiiiiiiiiiiiwwwwwwww"; +const char MailTemplatefmt[] = "nwwwwwwwwwwwwwwwwwssssssssssssssssw"; +const char Mapfmt[] = "nwiwsssssssssssssssswwwwwwwiwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwiwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwiffiiwwi"; +const char QuestSortfmt[] = "nwwwwwwwwwwwwwwwww"; +const char RandPropPointsfmt[] = "niiiiiiiiiiiiiii"; +const char SkillLinefmt[] = "niwsssssssssssssssswwwwwwwwwwwwwwwwwwi"; +const char SkillLineAbilityfmt[] = "niiiiwwiiiiiwwi"; +const char SkillRaceClassInfofmt[] = "wiiiiiiw"; +const char SkillTiersfmt[] = "niiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"; +const char SoundEntriesfmt[] = "nwwwwwwwwwwwwwwwwwwwwwwwwwwww"; +const char SpellCastTimesfmt[] = "niii"; +const char SpellDurationfmt[] = "niii"; +const char SpellFocusObjectfmt[] = "nwwwwwwwwwwwwwwwww"; +const char SpellItemEnchantmentfmt[] = "niiiiiiwwwiiisssssssssssssssswiiii"; +const char SpellItemEnchantmentConditionfmt[] = "nbbbbbwwwwwbbbbbbbbbbiiiiiwwwww"; +const char SpellRadiusfmt[] = "nfww"; +const char SpellRangefmt[] = "nffiwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww"; +const char SpellShapeshiftFormfmt[] = "nwwwwwwwwwwwwwwwwwwiiwiiwwwiiiiiiii"; +const char SpellVisualfmt[] = "nwwwwwiiwwwwwwwwwwwwwwwww"; +const char StableSlotPricesfmt[] = "ni"; +const char SummonPropertiesfmt[] = "niiiii"; +const char Talentfmt[] = "niiiiiiiiwwwwiwwiwwwi"; +const char TalentTabfmt[] = "nwwwwwwwwwwwwwwwwwwwiiw"; +const char TaxiNodesfmt[] = "nifffsssssssssssssssswii"; +const char TaxiPathfmt[] = "niii"; +const char TaxiPathNodefmt[] = "diiifffiiii"; +const char TransportAnimationfmt[] = "diifffw"; +const char TotemCategoryfmt[] = "nwwwwwwwwwwwwwwwwwii"; +const char WorldMapAreafmt[] = "diiwffffi"; +const char WMOAreaTablefmt[] = "niiiwwwwwiiwwwwwwwwwwwwwwwww"; + +SQLStorage sAreaTableStore(AreaTablefmt, "areatable_store"); +SQLStorage sAreaTriggerStore(AreaTriggerfmt, "areatrigger_store"); +SQLStorage sAuctionHouseStore(AuctionHousefmt, "auctionhouse_store"); +SQLStorage sBankBagSlotPricesStore(BankBagSlotPricesfmt, "bankbagslotprices_store"); +SQLStorage sBattlemasterListStore(BattlemasterListfmt, "battlemasterlist_store"); +SQLStorage sCharStartOutfitStore(CharStartOutfitfmt, "charstartoutfit_store"); +SQLStorage sCharTitlesStore(CharTitlesfmt, "chartitles_store"); +SQLStorage sChatChannelsStore(ChatChannelsfmt, "chatchannels_store"); +SQLStorage sChrClassesStore(ChrClassesfmt, "chrclasses_store"); +SQLStorage sChrRacesStore(ChrRacesfmt, "chrraces_store"); +SQLStorage sCinematicCameraStore(CinematicCamerafmt, "cinematiccamera_store"); +SQLStorage sCinematicSequencesStore(CinematicSequencesfmt, "cinematicsequences_store"); +SQLStorage sCreatureDisplayInfoStore(CreatureDisplayInfofmt, "creaturedisplayinfo_store"); +SQLStorage sCreatureDisplayInfoExtraStore(CreatureDisplayInfoExtrafmt, "creaturedisplayinfoextra_store"); +SQLStorage sCreatureFamilyStore(CreatureFamilyfmt, "creaturefamily_store"); +SQLStorage sCreatureModelDataStore(CreatureModelDatafmt, "creaturemodeldata_store"); +SQLStorage sCreatureSpellDataStore(CreatureSpellDatafmt, "creaturespelldata_store"); +SQLStorage sCreatureTypeStore(CreatureTypefmt, "creaturetype_store"); +SQLStorage sDurabilityCostsStore(DurabilityCostsfmt, "durabilitycosts_store"); +SQLStorage sDurabilityQualityStore(DurabilityQualityfmt, "durabilityquality_store"); +SQLStorage sEmotesStore(Emotesfmt, "emotes_store"); +SQLStorage sEmotesTextStore(EmotesTextfmt, "emotestext_store"); +SQLStorage sFactionTemplateStore(FactionTemplatefmt, "factiontemplate_store"); +SQLStorage sGameObjectDisplayInfoStore(GameObjectDisplayInfofmt, "gameobjectdisplayinfo_store"); +SQLStorage sGemPropertiesStore(GemPropertiesfmt, "gemproperties_store"); +SQLStorage sGMSurveyCurrentSurveyStore(GMSurveyCurrentSurveyfmt, "gmsurveycurrentsurvey_store"); +SQLStorage sGMSurveyQuestionsStore(GMSurveyQuestionsfmt, "gmsurveyquestions_store"); +SQLStorage sGMSurveySurveysStore(GMSurveySurveysfmt, "gmsurveysurveys_store"); +SQLStorage sGMTicketCategoryStore(GMTicketCategoryfmt, "gmticketcategory_store"); +SQLStorage sgtCombatRatingsStore(gtCombatRatingsfmt, "gtcombatratings_store"); +SQLStorage sgtChanceToMeleeCritBaseStore(gtChanceToMeleeCritBasefmt, "gtchancetomeleecritbase_store"); +SQLStorage sgtChanceToMeleeCritStore(gtChanceToMeleeCritfmt, "gtchancetomeleecrit_store"); +SQLStorage sgtChanceToSpellCritBaseStore(gtChanceToSpellCritBasefmt, "gtchancetospellcritbase_store"); +SQLStorage sgtChanceToSpellCritStore(gtChanceToSpellCritfmt, "gtchancetospellcrit_store"); +SQLStorage sgtOCTRegenHPStore(gtOCTRegenHPfmt, "gtoctregenhp_store"); +SQLStorage sgtNPCManaCostScalerStore(gtNPCManaCostScalerfmt, "gtnpcmanacostscaler_store"); +SQLStorage sgtRegenHPPerSptStore(gtRegenHPPerSptfmt, "gtregenhpperspt_store"); +SQLStorage sgtRegenMPPerSptStore(gtRegenMPPerSptfmt, "gtregenmpperspt_store"); +SQLStorage sItemStore(Itemfmt, "item_store"); +SQLStorage sItemBagFamilyStore(ItemBagFamilyfmt, "itembagfamily_store"); +SQLStorage sItemClassStore(ItemClassfmt, "itemclass_store"); +SQLStorage sItemExtendedCostStore(ItemExtendedCostfmt, "itemextendedcost_store"); +SQLStorage sItemRandomPropertiesStore(ItemRandomPropertiesfmt, "itemrandomproperties_store"); +SQLStorage sItemRandomSuffixStore(ItemRandomSuffixfmt, "itemrandomsuffix_store"); +SQLStorage sItemSetStore(ItemSetfmt, "itemset_store"); +SQLStorage sLiquidTypeStore(LiquidTypefmt, "liquidtype_store"); +SQLStorage sLockStore(Lockfmt, "lock_store"); +SQLStorage sMailTemplateStore(MailTemplatefmt, "mailtemplate_store"); +SQLStorage sMapStore(Mapfmt, "map_store"); +SQLStorage sQuestSortStore(QuestSortfmt, "questsort_store"); +SQLStorage sRandPropPointsStore(RandPropPointsfmt, "randproppoints_store"); +SQLStorage sSkillLineStore(SkillLinefmt, "skillline_store"); +SQLStorage sSkillLineAbilityStore(SkillLineAbilityfmt, "skilllineability_store"); +SQLStorage sSkillRaceClassInfoStore(SkillRaceClassInfofmt, "skillraceclassinfo_store"); +SQLStorage sSkillTiersStore(SkillTiersfmt, "skilltiers_store"); +SQLStorage sSoundEntriesStore(SoundEntriesfmt, "soundentries_store"); +SQLStorage sSpellCastTimesStore(SpellCastTimesfmt, "spellcasttimes_store"); +SQLStorage sSpellDurationStore(SpellDurationfmt, "spellduration_store"); +SQLStorage sSpellFocusObjectStore(SpellFocusObjectfmt, "spellfocusobject_store"); +SQLStorage sSpellItemEnchantmentStore(SpellItemEnchantmentfmt, "spellitemenchantment_store"); +SQLStorage sSpellItemEnchantmentConditionStore(SpellItemEnchantmentConditionfmt, "spellitemenchantmentcondition_store"); +SQLStorage sSpellRadiusStore(SpellRadiusfmt, "spellradius_store"); +SQLStorage sSpellRangeStore(SpellRangefmt, "spellrange_store"); +SQLStorage sSpellShapeshiftFormStore(SpellShapeshiftFormfmt, "spellshapeshiftform_store"); +SQLStorage sSpellVisualStore(SpellVisualfmt, "spellvisual_store"); +SQLStorage sStableSlotPricesStore(StableSlotPricesfmt, "stableslotprices_store"); +SQLStorage sSummonPropertiesStore(SummonPropertiesfmt, "summonproperties_store"); +SQLStorage sTalentStore(Talentfmt, "talent_store"); +SQLStorage sTalentTabStore(TalentTabfmt, "talenttab_store"); +SQLStorage sTaxiNodesStore(TaxiNodesfmt, "taxinodes_store"); +SQLStorage sTaxiPathStore(TaxiPathfmt, "taxipath_store"); +SQLStorage sTaxiPathNodeStore(TaxiPathNodefmt, "taxipathnode_store"); +SQLStorage sTransportAnimationStore(TransportAnimationfmt, "transportanimation_store"); +SQLStorage sTotemCategoryStore(TotemCategoryfmt, "totemcategory_store"); +SQLStorage sWorldMapAreaStore(WorldMapAreafmt, "worldmaparea_store"); +SQLStorage sWMOAreaTableStore(WMOAreaTablefmt, "wmoareatable_store"); + +AreaFlagByAreaID sAreaFlagByAreaID; +AreaFlagByMapID sAreaFlagByMapID; // for instances without generated *.map files + +WMOAreaInfoByTripple sWMOAreaInfoByTripple; + +SpellCategoryStore sSpellCategoryStore; +ItemSpellCategoryStore sItemSpellCategoryStore; +PetFamilySpellsStore sPetFamilySpellsStore; + +// store absolute bit position for first rank for talent inspect +TalentInspectMap sTalentPosInInspect; +TalentInspectMap sTalentTabSizeInInspect; +uint32 sTalentTabPages[12/*MAX_CLASSES*/][3]; +TalentSpellPosMap sTalentSpellPosMap; + +TaxiMask sTaxiNodesMask; +TaxiPathSetBySource sTaxiPathSetBySource; +TaxiPathNodesByPath sTaxiPathNodesByPath;// DBC store data but sTaxiPathNodesByPath used for fast access to entries (it's not owner pointed data). + +void InitializeDBC() +{ + // must be after sAreaStore loading + for (auto areaEntry : sAreaTableStore) // areaflag numbered from 0 + { + // fill AreaId->DBC records + sAreaFlagByAreaID.insert(AreaFlagByAreaID::value_type(uint16(areaEntry->ID), areaEntry->exploreFlag)); + + // fill MapId->DBC records ( skip sub zones and continents ) + if (areaEntry->zone == 0 && areaEntry->mapid != 0 && areaEntry->mapid != 1 && areaEntry->mapid != 530) + sAreaFlagByMapID.insert(AreaFlagByMapID::value_type(areaEntry->mapid, areaEntry->exploreFlag)); + } + + for (auto skillLine : sSkillLineAbilityStore) + { + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(skillLine->spellId); + if (spellInfo && (spellInfo->Attributes & (SPELL_ATTR_ABILITY | SPELL_ATTR_PASSIVE | SPELL_ATTR_HIDDEN_CLIENTSIDE | SPELL_ATTR_HIDE_IN_COMBAT_LOG)) == (SPELL_ATTR_ABILITY | SPELL_ATTR_PASSIVE | SPELL_ATTR_HIDDEN_CLIENTSIDE | SPELL_ATTR_HIDE_IN_COMBAT_LOG)) + { + for (auto cFamily : sCreatureFamilyStore) + { + if (skillLine->skillId != cFamily->skillLine[0] && skillLine->skillId != cFamily->skillLine[1]) + continue; + + sPetFamilySpellsStore[cFamily->ID].insert(spellInfo->Id); + } + } + } + + // create talent spells set + for (auto talentInfo : sTalentStore) + { + for (int j = 0; j < 5; ++j) + if (talentInfo->RankID[j]) + sTalentSpellPosMap[talentInfo->RankID[j]] = TalentSpellPos(talentInfo->TalentID, j); + } + + // prepare fast data access to bit pos of talent ranks for use at inspecting + { + // fill table by amount of talent ranks and fill sTalentTabBitSizeInInspect + // store in with (row,col,talent)->size key for correct sorting by (row,col) + typedef std::map TalentBitSize; + TalentBitSize sTalentBitSize; + for (auto talentInfo : sTalentStore) + { + TalentTabEntry const* talentTabInfo = sTalentTabStore.LookupEntry(talentInfo->TalentTab); + if (!talentTabInfo) + continue; + + // find talent rank + uint32 curtalent_maxrank = 0; + for (uint32 k = 5; k > 0; --k) + { + if (talentInfo->RankID[k - 1]) + { + curtalent_maxrank = k; + break; + } + } + + sTalentBitSize[(talentInfo->Row << 24) + (talentInfo->Col << 16) + talentInfo->TalentID] = curtalent_maxrank; + sTalentTabSizeInInspect[talentInfo->TalentTab] += curtalent_maxrank; + } + + // now have all max ranks (and then bit amount used for store talent ranks in inspect) + for (auto talentTabInfo : sTalentTabStore) + { + // prevent memory corruption; otherwise cls will become 12 below + if ((talentTabInfo->ClassMask & CLASSMASK_ALL_PLAYABLE) == 0) + continue; + + // store class talent tab pages + uint32 cls = 1; + for (uint32 m = 1; !(m & talentTabInfo->ClassMask) && cls < MAX_CLASSES; m <<= 1, ++cls) {} + + sTalentTabPages[cls][talentTabInfo->tabpage] = talentTabInfo->TalentTabID; + + // add total amount bits for first rank starting from talent tab first talent rank pos. + uint32 pos = 0; + for (TalentBitSize::iterator itr = sTalentBitSize.begin(); itr != sTalentBitSize.end(); ++itr) + { + uint32 talentId = itr->first & 0xFFFF; + TalentEntry const* talentInfo = sTalentStore.LookupEntry(talentId); + if (!talentInfo) + continue; + + if (talentInfo->TalentTab != talentTabInfo->TalentTabID) + continue; + + sTalentPosInInspect[talentId] = pos; + pos += itr->second; + } + } + } + + for (auto entry : sTaxiPathStore) + sTaxiPathSetBySource[entry->from][entry->to] = TaxiPathBySourceAndDestination(entry->ID, entry->price); + uint32 pathCount = sTaxiPathStore.GetMaxEntry(); + + std::vector pathLength; + pathLength.resize(pathCount); // 0 and some other indexes not used + for (auto entry : sTaxiPathNodeStore) + { + if (pathLength[entry->path] < entry->index + 1) + pathLength[entry->path] = entry->index + 1; + } + // Set path length + sTaxiPathNodesByPath.resize(pathCount); // 0 and some other indexes not used + for (uint32 i = 1; i < sTaxiPathNodesByPath.size(); ++i) + sTaxiPathNodesByPath[i].resize(pathLength[i]); + // fill data (pointers to sTaxiPathNodeStore elements + for (auto entry : sTaxiPathNodeStore) + sTaxiPathNodesByPath[entry->path].set(entry->index, entry); + + // Initialize global taxinodes mask + // include existing nodes that have at least single not spell base (scripted) path + { + std::set spellPaths; + for (auto sInfo : sSpellTemplate) + for (int j = 0; j < MAX_EFFECT_INDEX; ++j) + if (sInfo->Effect[j] == 123 /*SPELL_EFFECT_SEND_TAXI*/) + spellPaths.insert(sInfo->EffectMiscValue[j]); + + memset(sTaxiNodesMask, 0, sizeof(sTaxiNodesMask)); + for (auto node : sTaxiNodesStore) + { + TaxiPathSetBySource::const_iterator src_i = sTaxiPathSetBySource.find(node->ID); + if (src_i != sTaxiPathSetBySource.end() && !src_i->second.empty()) + { + bool ok = false; + for (const auto& dest_i : src_i->second) + { + // not spell path + if (spellPaths.find(dest_i.second.ID) == spellPaths.end()) + { + ok = true; + break; + } + } + + if (!ok) + continue; + } + + // valid taxi network node + uint8 field = (uint8)((node->ID - 1) / 32); + uint32 submask = 1 << ((node->ID - 1) % 32); + sTaxiNodesMask[field] |= submask; + } + } + + for (auto entry : sWMOAreaTableStore) + { + sWMOAreaInfoByTripple[WMOAreaTableTripple(entry->rootId, entry->adtId, entry->groupId)].push_back(entry); + } + + // Check loaded DBC files proper version + if (!sSkillLineAbilityStore.LookupEntry(17514) || + !sMapStore.LookupEntry(598) || + !sGemPropertiesStore.LookupEntry(1127) || + !sItemExtendedCostStore.LookupEntry(2425) || + !sCharTitlesStore.LookupEntry(71) || + !sAreaTableStore.LookupEntry(1768)) + { + sLog.outError("\nYou have _outdated_ DBC files. Please re-extract DBC files for one from client build: %s", World::AcceptableClientBuildsListStr().c_str()); + Log::WaitBeforeContinueIfNeed(); + exit(1); + } +} + +void LoadDBCTables() +{ + sAreaTableStore.Load(); + sAreaTriggerStore.Load(); + sAuctionHouseStore.Load(); + sBankBagSlotPricesStore.Load(); + sBattlemasterListStore.Load(); + sCharStartOutfitStore.Load(); + sCharTitlesStore.Load(); + sChatChannelsStore.Load(); + sChrClassesStore.Load(); + sChrRacesStore.Load(); + sCinematicCameraStore.Load(); + sCinematicSequencesStore.Load(); + sCreatureDisplayInfoStore.Load(); + sCreatureDisplayInfoExtraStore.Load(); + sCreatureFamilyStore.Load(); + sCreatureModelDataStore.Load(); + sCreatureSpellDataStore.Load(); + sCreatureTypeStore.Load(); + sDurabilityQualityStore.Load(); + sDurabilityCostsStore.Load(); + sEmotesStore.Load(); + sEmotesTextStore.Load(); + sFactionTemplateStore.Load(); + sGameObjectDisplayInfoStore.Load(); + sGemPropertiesStore.Load(); + sGMSurveyCurrentSurveyStore.Load(); + sGMSurveyQuestionsStore.Load(); + sGMSurveySurveysStore.Load(); + sGMTicketCategoryStore.Load(); + sgtCombatRatingsStore.Load(); + sgtChanceToMeleeCritBaseStore.Load(); + sgtChanceToMeleeCritStore.Load(); + sgtChanceToSpellCritBaseStore.Load(); + sgtChanceToSpellCritStore.Load(); + sgtOCTRegenHPStore.Load(); + sgtNPCManaCostScalerStore.Load(); + sgtRegenHPPerSptStore.Load(); + sgtRegenMPPerSptStore.Load(); + sItemStore.Load(); + sItemBagFamilyStore.Load(); + sItemClassStore.Load(); + sItemExtendedCostStore.Load(); + sItemRandomPropertiesStore.Load(); + sItemRandomSuffixStore.Load(); + sItemSetStore.Load(); + sLiquidTypeStore.Load(); + sLockStore.Load(); + sMailTemplateStore.Load(); + sMapStore.Load(); + sQuestSortStore.Load(); + sRandPropPointsStore.Load(); + sSkillLineStore.Load(); + sSkillLineAbilityStore.Load(); + sSkillRaceClassInfoStore.Load(); + sSkillTiersStore.Load(); + sSoundEntriesStore.Load(); + sSpellCastTimesStore.Load(); + sSpellDurationStore.Load(); + sSpellFocusObjectStore.Load(); + sSpellItemEnchantmentStore.Load(); + sSpellItemEnchantmentConditionStore.Load(); + sSpellRadiusStore.Load(); + sSpellRangeStore.Load(); + sSpellShapeshiftFormStore.Load(); + sSpellVisualStore.Load(); + sStableSlotPricesStore.Load(); + sSummonPropertiesStore.Load(); + sTalentStore.Load(); + sTalentTabStore.Load(); + sTaxiNodesStore.Load(); + sTaxiPathStore.Load(); + sTaxiPathNodeStore.Load(); + sTransportAnimationStore.Load(); + sTotemCategoryStore.Load(); + sWorldMapAreaStore.Load(); + sWMOAreaTableStore.Load(); + + InitializeDBC(); + + sLog.outString(">> DBC loaded."); + sLog.outString(); +} -const char CreatureInfosrcfmt[] = "isssiiiiiiiifiiiiliiiiiffiiiiiiiiffffffiiiiffffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiss"; -const char CreatureInfodstfmt[] = "isssiiiiiiiifiiiiliiiiiffiiiiiiiiffffffiiiiffffiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiisi"; -const char CreatureDataAddonInfofmt[] = "iiibbiis"; -const char CreatureConditionalSpawnSrcFmt[] = "iiix"; -const char CreatureConditionalSpawnDstFmt[] = "iii"; -const char CreatureModelfmt[] = "iffffbii"; -const char CreatureInfoAddonInfofmt[] = "iiibbiis"; -const char EquipmentInfofmt[] = "iiii"; -const char EquipmentInfoRawfmt[] = "iiiiiiiiii"; -const char GameObjectInfosrcfmt[] = "iiisssiiifiiiiiiiiiiiiiiiiiiiiiiiiiiis"; -const char GameObjectInfodstfmt[] = "iiisssiiifiiiiiiiiiiiiiiiiiiiiiiiiiiii"; -const char ItemPrototypesrcfmt[] = "iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifsiiiiii"; -const char ItemPrototypedstfmt[] = "iiiisiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffiffiffiffiffiiiiiiiiiifiiifiiiiiifiiiiiifiiiiiifiiiiiifiiiisiiiiiiiiiiiiiiiiiiiiiiiiifiiiiiii"; -const char PageTextfmt[] = "isi"; -const char InstanceTemplatesrcfmt[] = "iiiiiisl"; -const char InstanceTemplatedstfmt[] = "iiiiiiil"; -const char WorldTemplatesrcfmt[] = "is"; -const char WorldTemplatedstfmt[] = "ii"; -const char ConditionsFmt[] = "iiiiiiix"; -const char SpellScriptTargetFmt[] = "iiii"; -const char SpellEntryfmt[] = "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiifiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiffffffiiiiiiiiiiiiiiiiiiiiifffiiiiiiiiiiiiiiifffiiiissssssssssssssssssssssssssssssssiiiiiLiiiifffiiiiiiiii"; -const char SpellConefmt[] = "ii"; -const char DungeonEncounterFmt[] = "iiiiissssssssssssssssii"; -const char FactionEntryfmt[] = "iiiiiiiiiiiiiiiiiiiffiissssssssssssssss"; -const char WorldSafeLocsFmt[] = "iiffffs"; - -SQLStorage sCreatureStorage(CreatureInfosrcfmt, CreatureInfodstfmt, "Entry", "creature_template"); -SQLStorage sCreatureDataAddonStorage(CreatureDataAddonInfofmt, "guid", "creature_addon"); -SQLStorage sCreatureModelStorage(CreatureModelfmt, "modelid", "creature_model_info"); -SQLStorage sCreatureInfoAddonStorage(CreatureInfoAddonInfofmt, "entry", "creature_template_addon"); -SQLStorage sEquipmentStorage(EquipmentInfofmt, "entry", "creature_equip_template"); -SQLStorage sEquipmentStorageRaw(EquipmentInfoRawfmt, "entry", "creature_equip_template_raw"); -SQLStorage sItemStorage(ItemPrototypesrcfmt, ItemPrototypedstfmt, "entry", "item_template"); -SQLStorage sPageTextStore(PageTextfmt, "entry", "page_text"); -SQLStorage sInstanceTemplate(InstanceTemplatesrcfmt, InstanceTemplatedstfmt, "map", "instance_template"); -SQLStorage sWorldTemplate(WorldTemplatesrcfmt, WorldTemplatedstfmt, "map", "world_template"); -SQLStorage sConditionStorage(ConditionsFmt, "condition_entry", "conditions"); -SQLStorage sSpellTemplate(SpellEntryfmt, "id", "spell_template"); -SQLStorage sSpellCones(SpellConefmt, "id", "spell_cone"); -SQLStorage sDungeonEncounterStore(DungeonEncounterFmt, "id", "instance_dungeon_encounters"); -SQLStorage sFactionStore(FactionEntryfmt, "entry", "faction_store"); -SQLStorage sCreatureConditionalSpawnStore(CreatureConditionalSpawnSrcFmt, CreatureConditionalSpawnDstFmt, "guid", "creature_conditional_spawn"); -SQLStorage sWorldSafeLocsStore(WorldSafeLocsFmt, "id", "world_safe_locs"); - -SQLHashStorage sGOStorage(GameObjectInfosrcfmt, GameObjectInfodstfmt, "entry", "gameobject_template"); - -SQLMultiStorage sSpellScriptTargetStorage(SpellScriptTargetFmt, "entry", "spell_script_target"); - -SQLStorage const* GetSpellStore() { return &sSpellTemplate; } diff --git a/src/game/Server/SQLStorages.h b/src/game/Server/SQLStorages.h index 16e1a055a5..2752270df2 100644 --- a/src/game/Server/SQLStorages.h +++ b/src/game/Server/SQLStorages.h @@ -20,30 +20,150 @@ #define MANGOS_SQLSTORAGES_H #include "Database/SQLStorage.h" +#include "DBCStructure.h" -extern SQLStorage sCreatureStorage; -extern SQLStorage sCreatureDataAddonStorage; -extern SQLStorage sCreatureInfoAddonStorage; -extern SQLStorage sCreatureModelStorage; -extern SQLStorage sEquipmentStorage; -extern SQLStorage sEquipmentStorageRaw; -extern SQLStorage sPageTextStore; -extern SQLStorage sItemStorage; -extern SQLStorage sInstanceTemplate; -extern SQLStorage sWorldTemplate; -extern SQLStorage sConditionStorage; -extern SQLStorage sSpellTemplate; -extern SQLStorage sSpellCones; -extern SQLStorage sDungeonEncounterStore; -extern SQLStorage sFactionStore; -extern SQLStorage sCreatureConditionalSpawnStore; -extern SQLStorage sWorldSafeLocsStore; - - -extern SQLHashStorage sGOStorage; - -extern SQLMultiStorage sSpellScriptTargetStorage; - -SQLStorage const* GetSpellStore(); +extern SQLStorage sCreatureStorage; +extern SQLStorage sCreatureDataAddonStorage; +extern SQLStorage sCreatureInfoAddonStorage; +extern SQLStorage sCreatureModelStorage; +extern SQLStorage sEquipmentStorage; +extern SQLStorage sEquipmentStorageRaw; +extern SQLStorage sPageTextStore; +extern SQLStorage sItemStorage; +extern SQLStorage sInstanceTemplate; +extern SQLStorage sWorldTemplate; +extern SQLStorage sConditionStorage; +extern SQLStorage sSpellTemplate; +extern SQLStorage sSpellCones; +extern SQLStorage sDungeonEncounterStore; +extern SQLStorage sFactionStore; +extern SQLStorage sCreatureConditionalSpawnStore; +extern SQLStorage sWorldSafeLocsStore; + +extern SQLHashStorage sGOStorage; +extern SQLMultiStorage sSpellScriptTargetStorage; + +// DBC stores in db +extern SQLStorage sAreaTableStore; +extern SQLStorage sAreaTriggerStore; +extern SQLStorage sAuctionHouseStore; +extern SQLStorage sBankBagSlotPricesStore; +extern SQLStorage sBattlemasterListStore; +extern SQLStorage sCharStartOutfitStore; +extern SQLStorage sCharTitlesStore; +extern SQLStorage sChatChannelsStore; +extern SQLStorage sChrClassesStore; +extern SQLStorage sChrRacesStore; +extern SQLStorage sCinematicCameraStore; +extern SQLStorage sCinematicSequencesStore; +extern SQLStorage sCreatureDisplayInfoStore; +extern SQLStorage sCreatureDisplayInfoExtraStore; +extern SQLStorage sCreatureFamilyStore; +extern SQLStorage sCreatureModelDataStore; +extern SQLStorage sCreatureSpellDataStore; // todo not used? +extern SQLStorage sCreatureTypeStore; +extern SQLStorage sDurabilityCostsStore; +extern SQLStorage sDurabilityQualityStore; +extern SQLStorage sEmotesStore; +extern SQLStorage sEmotesTextStore; +extern SQLStorage sFactionTemplateStore; +extern SQLStorage sGameObjectDisplayInfoStore; +extern SQLStorage sGemPropertiesStore; +extern SQLStorage sGMSurveyCurrentSurveyStore; +extern SQLStorage sGMSurveyQuestionsStore; +extern SQLStorage sGMSurveySurveysStore; +extern SQLStorage sGMTicketCategoryStore; +extern SQLStorage sgtCombatRatingsStore; +extern SQLStorage sgtChanceToMeleeCritBaseStore; +extern SQLStorage sgtChanceToMeleeCritStore; +extern SQLStorage sgtChanceToSpellCritBaseStore; +extern SQLStorage sgtChanceToSpellCritStore; +extern SQLStorage sgtOCTRegenHPStore; +extern SQLStorage sgtNPCManaCostScalerStore; +extern SQLStorage sgtRegenHPPerSptStore; +extern SQLStorage sgtRegenMPPerSptStore; +extern SQLStorage sItemStore; +extern SQLStorage sItemBagFamilyStore; +extern SQLStorage sItemClassStore; +extern SQLStorage sItemExtendedCostStore; +extern SQLStorage sItemRandomPropertiesStore; +extern SQLStorage sItemRandomSuffixStore; +extern SQLStorage sItemSetStore; +extern SQLStorage sLiquidTypeStore; +extern SQLStorage sLockStore; +extern SQLStorage sMailTemplateStore; +extern SQLStorage sMapStore; +extern SQLStorage sQuestSortStore; +extern SQLStorage sRandPropPointsStore; +extern SQLStorage sSkillLineStore; +extern SQLStorage sSkillLineAbilityStore; +extern SQLStorage sSkillRaceClassInfoStore; +extern SQLStorage sSkillTiersStore; +extern SQLStorage sSoundEntriesStore; +extern SQLStorage sSpellCastTimesStore; +extern SQLStorage sSpellDurationStore; +extern SQLStorage sSpellFocusObjectStore; +extern SQLStorage sSpellItemEnchantmentStore; +extern SQLStorage sSpellItemEnchantmentConditionStore; +extern SQLStorage sSpellRadiusStore; +extern SQLStorage sSpellRangeStore; +extern SQLStorage sSpellShapeshiftFormStore; +extern SQLStorage sSpellVisualStore; +extern SQLStorage sStableSlotPricesStore; +extern SQLStorage sSummonPropertiesStore; +extern SQLStorage sTalentStore; +extern SQLStorage sTalentTabStore; +extern SQLStorage sTaxiNodesStore; +extern SQLStorage sTaxiPathStore; +extern SQLStorage sTaxiPathNodeStore; +extern SQLStorage sTransportAnimationStore; +extern SQLStorage sTotemCategoryStore; +extern SQLStorage sWorldMapAreaStore; +extern SQLStorage sWMOAreaTableStore; + +// following are mostly helper store to get fast lookup of some other stores +typedef std::map AreaFlagByAreaID; +typedef std::map AreaFlagByMapID; + +struct WMOAreaTableTripple +{ + WMOAreaTableTripple(int32 r, int32 a, int32 g) : groupId(g), rootId(r), adtId(a) + { + } + + bool operator <(const WMOAreaTableTripple& b) const + { + return memcmp(this, &b, sizeof(WMOAreaTableTripple)) < 0; + } + + // ordered by entropy; that way memcmp will have a minimal medium runtime + int32 groupId; + int32 rootId; + int32 adtId; +}; + +typedef std::map> WMOAreaInfoByTripple; + +extern AreaFlagByAreaID sAreaFlagByAreaID; +extern AreaFlagByMapID sAreaFlagByMapID; // for instances without generated *.map files + +extern WMOAreaInfoByTripple sWMOAreaInfoByTripple; + +extern SpellCategoryStore sSpellCategoryStore; +extern ItemSpellCategoryStore sItemSpellCategoryStore; +extern PetFamilySpellsStore sPetFamilySpellsStore; +extern TaxiMask sTaxiNodesMask; +extern TaxiPathSetBySource sTaxiPathSetBySource; +extern TaxiPathNodesByPath sTaxiPathNodesByPath; + +typedef std::map TalentInspectMap; +extern TalentInspectMap sTalentTabSizeInInspect; +extern TalentInspectMap sTalentPosInInspect; +extern uint32 sTalentTabPages[12/*MAX_CLASSES*/][3]; +extern TalentSpellPosMap sTalentSpellPosMap; + +void LoadDBCTables(); + +SQLStorage const* GetSpellStore(); #endif diff --git a/src/game/Server/WorldSocket.cpp b/src/game/Server/WorldSocket.cpp index b92e36181f..d53362369c 100644 --- a/src/game/Server/WorldSocket.cpp +++ b/src/game/Server/WorldSocket.cpp @@ -304,7 +304,7 @@ bool WorldSocket::HandleAuthSession(WorldPacket& recvPacket) clientSeed); // Check the version of client trying to connect - if (!IsAcceptableClientBuild(ClientBuild)) + if (!World::IsAcceptableClientBuild(ClientBuild)) { packet.Initialize(SMSG_AUTH_RESPONSE, 1); packet << uint8(AUTH_VERSION_MISMATCH); diff --git a/src/game/Skills/SkillDiscovery.cpp b/src/game/Skills/SkillDiscovery.cpp index 0c3981a32e..42253d6445 100644 --- a/src/game/Skills/SkillDiscovery.cpp +++ b/src/game/Skills/SkillDiscovery.cpp @@ -85,7 +85,7 @@ void LoadSkillDiscoveryTable() if (reqSkillOrSpell > 0) // spell case { - SpellEntry const* reqSpellEntry = sSpellTemplate.LookupEntry(reqSkillOrSpell); + SpellEntry const* reqSpellEntry = sSpellTemplate.LookupEntry(reqSkillOrSpell); if (!reqSpellEntry) { if (reportedReqSpells.find(reqSkillOrSpell) == reportedReqSpells.end()) diff --git a/src/game/Skills/SkillExtraItems.cpp b/src/game/Skills/SkillExtraItems.cpp index 0c98a2fbfc..2d5356d010 100644 --- a/src/game/Skills/SkillExtraItems.cpp +++ b/src/game/Skills/SkillExtraItems.cpp @@ -72,14 +72,14 @@ void LoadSkillExtraItemTable() uint32 spellId = fields[0].GetUInt32(); - if (!sSpellTemplate.LookupEntry(spellId)) + if (!sSpellTemplate.LookupEntry(spellId)) { sLog.outError("Skill specialization %u has nonexistent spell id in `skill_extra_item_template`!", spellId); continue; } uint32 requiredSpecialization = fields[1].GetUInt32(); - if (!sSpellTemplate.LookupEntry(requiredSpecialization)) + if (!sSpellTemplate.LookupEntry(requiredSpecialization)) { sLog.outError("Skill specialization %u have nonexistent required specialization spell id %u in `skill_extra_item_template`!", spellId, requiredSpecialization); continue; diff --git a/src/game/Spells/Scripts/SpellScript.cpp b/src/game/Spells/Scripts/SpellScript.cpp index 4992c15b5a..fbf5a9af6f 100644 --- a/src/game/Spells/Scripts/SpellScript.cpp +++ b/src/game/Spells/Scripts/SpellScript.cpp @@ -85,7 +85,7 @@ void SpellScriptMgr::LoadScripts() uint32 spellId = fields[0].GetUInt32(); std::string scriptName = fields[1].GetCppString(); - if (!sSpellTemplate.LookupEntry(spellId)) + if (!sSpellTemplate.LookupEntry(spellId)) { sLog.outErrorDb("Spell %u has script %s in spell_scripts but spell does not exist. Skipping.", spellId, scriptName.data()); continue; diff --git a/src/game/Spells/Spell.cpp b/src/game/Spells/Spell.cpp index c2b4098b85..9eb78b2bcd 100644 --- a/src/game/Spells/Spell.cpp +++ b/src/game/Spells/Spell.cpp @@ -51,7 +51,7 @@ extern pEffect SpellEffects[MAX_SPELL_EFFECTS]; bool IsQuestTameSpell(uint32 spellId) { - SpellEntry const* spellproto = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellproto = sSpellTemplate.LookupEntry(spellId); if (!spellproto) return false; @@ -318,7 +318,7 @@ Spell::Spell(Unit* caster, SpellEntry const* info, uint32 triggeredFlags, Object m_spellScript(SpellScriptMgr::GetSpellScript(info->Id)), m_spellLog(this), m_trueCaster(caster) { MANGOS_ASSERT(caster != nullptr && info != nullptr); - MANGOS_ASSERT(info == sSpellTemplate.LookupEntry(info->Id) && "`info` must be pointer to sSpellTemplate element"); + MANGOS_ASSERT(info == sSpellTemplate.LookupEntry(info->Id) && "`info` must be pointer to sSpellTemplate element"); m_spellInfo = info; m_triggeredBySpellInfo = triggeredBy; @@ -1091,7 +1091,7 @@ void Spell::DoAllEffectOnTarget(TargetInfo* target) Unit::DealDamageMods(caster, spellDamageInfo.target, spellDamageInfo.damage, &spellDamageInfo.absorb, SPELL_DIRECT_DAMAGE, m_spellInfo); - // Send log damage message to client + // Send log damage message to client if (reflectTarget) reflectTarget->SendSpellNonMeleeDamageLog(&spellDamageInfo); else @@ -1993,7 +1993,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, bool targ if (tempTargetUnitMap.empty()) break; - SQLMultiStorage::SQLMSIteratorBounds bounds = sSpellScriptTargetStorage.getBounds(m_spellInfo->Id); + auto bounds = sSpellScriptTargetStorage.getBounds(m_spellInfo->Id); if (bounds.first != bounds.second) CheckSpellScriptTargets(bounds, tempTargetUnitMap, tempUnitList, effIndex); else @@ -2113,7 +2113,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, bool targ case TARGET_ENUM_UNITS_SCRIPT_AOE_AT_SRC_LOC: { UnitList tempTargetUnitMap; - SQLMultiStorage::SQLMSIteratorBounds bounds = sSpellScriptTargetStorage.getBounds(m_spellInfo->Id); + auto bounds = sSpellScriptTargetStorage.getBounds(m_spellInfo->Id); // fill real target list if no spell script target defined FillAreaTargets(bounds.first != bounds.second ? tempTargetUnitMap : tempUnitList, @@ -2152,7 +2152,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, bool targ case TARGET_ENUM_UNITS_SCRIPT_AOE_AT_DEST_LOC: { UnitList tempTargetUnitMap; - SQLMultiStorage::SQLMSIteratorBounds bounds = sSpellScriptTargetStorage.getBounds(m_spellInfo->Id); + auto bounds = sSpellScriptTargetStorage.getBounds(m_spellInfo->Id); // fill real target list if no spell script target defined FillAreaTargets(bounds.first != bounds.second ? tempTargetUnitMap : tempUnitList, radius, cone, PUSH_DEST_CENTER, SPELL_TARGETS_ALL); @@ -2178,8 +2178,8 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, bool targ std::set entriesToUse; - SQLMultiStorage::SQLMSIteratorBounds bounds = sSpellScriptTargetStorage.getBounds(m_spellInfo->Id); - for (SQLMultiStorage::SQLMultiSIterator i_spellST = bounds.first; i_spellST != bounds.second; ++i_spellST) + auto bounds = sSpellScriptTargetStorage.getBounds(m_spellInfo->Id); + for (auto i_spellST = bounds.first; i_spellST != bounds.second; ++i_spellST) { if (i_spellST->CanNotHitWithSpellEffect(effIndex)) continue; @@ -2336,7 +2336,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, bool targ case TARGET_ENUM_UNITS_SCRIPT_IN_CONE_60: { UnitList tempTargetUnitMap; - SQLMultiStorage::SQLMSIteratorBounds bounds = sSpellScriptTargetStorage.getBounds(m_spellInfo->Id); + auto bounds = sSpellScriptTargetStorage.getBounds(m_spellInfo->Id); // fill real target list if no spell script target defined FillAreaTargets(bounds.first != bounds.second ? tempTargetUnitMap : tempUnitList, radius, cone, PUSH_CONE, targetType); if (!tempTargetUnitMap.empty()) @@ -2561,7 +2561,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, bool targ SpellCastResult Spell::CheckScriptTargeting(SpellEffectIndex effIndex, uint32 chainTargets, float radius, uint32 targetMode, UnitList& tempUnitList, GameObjectList& tempGOList) { - SQLMultiStorage::SQLMSIteratorBounds bounds = sSpellScriptTargetStorage.getBounds(m_spellInfo->Id); + auto bounds = sSpellScriptTargetStorage.getBounds(m_spellInfo->Id); if (bounds.first == bounds.second) { @@ -2585,7 +2585,7 @@ SpellCastResult Spell::CheckScriptTargeting(SpellEffectIndex effIndex, uint32 ch // corrections for numerous spells missing it uint32 targetCount = std::max(chainTargets, uint32(1)); - for (SQLMultiStorage::SQLMultiSIterator i_spellST = bounds.first; i_spellST != bounds.second; ++i_spellST) + for (auto i_spellST = bounds.first; i_spellST != bounds.second; ++i_spellST) { if (i_spellST->CanNotHitWithSpellEffect(effIndex)) continue; @@ -2756,7 +2756,7 @@ SpellCastResult Spell::CheckScriptTargeting(SpellEffectIndex effIndex, uint32 ch return SPELL_CAST_OK; } -void Spell::CheckSpellScriptTargets(SQLMultiStorage::SQLMSIteratorBounds& bounds, UnitList& tempTargetUnitMap, UnitList& targetUnitMap, SpellEffectIndex effIndex) +void Spell::CheckSpellScriptTargets(SQLMultiStorage::SQLMSIteratorBounds& bounds, UnitList& tempTargetUnitMap, UnitList& targetUnitMap, SpellEffectIndex effIndex) { for (UnitList::const_iterator iter = tempTargetUnitMap.begin(); iter != tempTargetUnitMap.end(); ++iter) { @@ -2764,7 +2764,7 @@ void Spell::CheckSpellScriptTargets(SQLMultiStorage::SQLMSIteratorBoundsGetTypeId() != TYPEID_UNIT) continue; - for (SQLMultiStorage::SQLMultiSIterator i_spellST = bounds.first; i_spellST != bounds.second; ++i_spellST) + for (auto i_spellST = bounds.first; i_spellST != bounds.second; ++i_spellST) { SpellTargetEntry const* spellST = (*i_spellST); if (spellST->CanNotHitWithSpellEffect(effIndex)) @@ -3076,7 +3076,7 @@ void Spell::cast(bool skipCheck) if (!itr.second.active || itr.second.disabled || itr.second.state == PLAYERSPELL_REMOVED) continue; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(itr.first); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(itr.first); if (!spellInfo) continue; @@ -4408,7 +4408,7 @@ void Spell::HandleEffect(Unit* pUnitTarget, Item* pItemTarget, GameObject* pGOTa void Spell::AddTriggeredSpell(uint32 spellId) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) { @@ -4421,7 +4421,7 @@ void Spell::AddTriggeredSpell(uint32 spellId) void Spell::AddPrecastSpell(uint32 spellId) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) { @@ -5031,7 +5031,7 @@ SpellCastResult Spell::CheckCast(bool strict) if (!pet) return SPELL_FAILED_NO_PET; - SpellEntry const* learn_spellproto = sSpellTemplate.LookupEntry(m_spellInfo->EffectTriggerSpell[i]); + SpellEntry const* learn_spellproto = sSpellTemplate.LookupEntry(m_spellInfo->EffectTriggerSpell[i]); if (!learn_spellproto) return SPELL_FAILED_NOT_KNOWN; @@ -5054,7 +5054,7 @@ SpellCastResult Spell::CheckCast(bool strict) if (!pet) return SPELL_FAILED_NO_PET; - SpellEntry const* learn_spellproto = sSpellTemplate.LookupEntry(m_spellInfo->EffectTriggerSpell[i]); + SpellEntry const* learn_spellproto = sSpellTemplate.LookupEntry(m_spellInfo->EffectTriggerSpell[i]); if (!learn_spellproto) return SPELL_FAILED_NOT_KNOWN; @@ -6111,8 +6111,8 @@ uint32 Spell::CalculatePowerCost(SpellEntry const* spellInfo, Unit* caster, Spel if (spellInfo->HasAttribute(SPELL_ATTR_LEVEL_DAMAGE_CALCULATION)) { - GtNPCManaCostScalerEntry const* spellScaler = sGtNPCManaCostScalerStore.LookupEntry(spellInfo->spellLevel - 1); - GtNPCManaCostScalerEntry const* casterScaler = sGtNPCManaCostScalerStore.LookupEntry(caster->getLevel() - 1); + GtNPCManaCostScalerEntry const* spellScaler = sgtNPCManaCostScalerStore.LookupEntry(spellInfo->spellLevel - 1); + GtNPCManaCostScalerEntry const* casterScaler = sgtNPCManaCostScalerStore.LookupEntry(caster->getLevel() - 1); if (spellScaler && casterScaler) powerCost *= casterScaler->ratio / spellScaler->ratio; } @@ -7134,7 +7134,7 @@ float Spell::GetSpellSpeed() const return 0.f; if (IsChanneledSpell(m_spellInfo)) return 0.f; - + return m_spellInfo->speed; } @@ -7199,7 +7199,7 @@ void Spell::SelectMountByAreaAndSkill(Unit* target, SpellEntry const* parentSpel if (skillval >= 225 && (spellId300 > 0 || spellId225 > 0)) { uint32 spellid = skillval >= 300 ? spellId300 : spellId225; - SpellEntry const* pSpell = sSpellTemplate.LookupEntry(spellid); + SpellEntry const* pSpell = sSpellTemplate.LookupEntry(spellid); if (!pSpell) { sLog.outError("SelectMountByAreaAndSkill: unknown spell id %i by caster: %s", spellid, target->GetGuidStr().c_str()); @@ -7219,7 +7219,7 @@ void Spell::SelectMountByAreaAndSkill(Unit* target, SpellEntry const* parentSpel { if (iter->second.state != PLAYERSPELL_REMOVED) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(iter->first); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(iter->first); for (int i = 0; i < MAX_EFFECT_INDEX; ++i) { if (spellInfo->EffectApplyAuraName[i] == SPELL_AURA_MOD_FLIGHT_SPEED_MOUNTED) @@ -7380,7 +7380,7 @@ void Spell::GetSpellRangeAndRadius(SpellEffectIndex effIndex, float& radius, boo float Spell::GetCone() { - if (SpellCone const* coneData = sSpellCones.LookupEntry(sSpellMgr.GetFirstSpellInChain(m_spellInfo->Id))) + if (SpellCone const* coneData = sSpellCones.LookupEntry(sSpellMgr.GetFirstSpellInChain(m_spellInfo->Id))) return G3D::toRadians(coneData->coneAngle); return M_PI_F / 3.f; // 60 degrees is default diff --git a/src/game/Spells/Spell.h b/src/game/Spells/Spell.h index 193df9bc7f..afb8ecb4e1 100644 --- a/src/game/Spells/Spell.h +++ b/src/game/Spells/Spell.h @@ -765,7 +765,7 @@ class Spell void FillTargetMap(); void SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, bool targetB, TempTargetingData& targetingData); bool CheckAndAddMagnetTarget(Unit* unitTarget, SpellEffectIndex effIndex, bool targetB, TempTargetingData& data); - static void CheckSpellScriptTargets(SQLMultiStorage::SQLMSIteratorBounds& bounds, UnitList& tempTargetUnitMap, UnitList& targetUnitMap, SpellEffectIndex effIndex); + static void CheckSpellScriptTargets(SQLMultiStorage::SQLMSIteratorBounds& bounds, UnitList& tempTargetUnitMap, UnitList& targetUnitMap, SpellEffectIndex effIndex); void FilterTargetMap(UnitList& filterUnitList, SpellTargetFilterScheme scheme, uint32 chainTargetCount); void FillFromTargetFlags(TempTargetingData& targetingData, SpellEffectIndex effIndex); diff --git a/src/game/Spells/SpellAuras.cpp b/src/game/Spells/SpellAuras.cpp index 3d2b84a4a3..c7e0af797d 100755 --- a/src/game/Spells/SpellAuras.cpp +++ b/src/game/Spells/SpellAuras.cpp @@ -331,7 +331,7 @@ Aura::Aura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 const* curr m_scriptValue(0) { MANGOS_ASSERT(target); - MANGOS_ASSERT(spellproto && spellproto == sSpellTemplate.LookupEntry(spellproto->Id) && "`info` must be pointer to sSpellTemplate element"); + MANGOS_ASSERT(spellproto && spellproto == sSpellTemplate.LookupEntry(spellproto->Id) && "`info` must be pointer to sSpellTemplate element"); m_currentBasePoints = currentBasePoints ? *currentBasePoints : spellproto->CalculateSimpleValue(eff); @@ -507,7 +507,7 @@ Aura* CreateAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 const uint32 triggeredSpellId = spellproto->EffectTriggerSpell[eff]; - if (SpellEntry const* triggeredSpellInfo = sSpellTemplate.LookupEntry(triggeredSpellId)) + if (SpellEntry const* triggeredSpellInfo = sSpellTemplate.LookupEntry(triggeredSpellId)) for (unsigned int i : triggeredSpellInfo->EffectImplicitTargetA) if (i == TARGET_UNIT_CHANNEL_TARGET) return new SingleEnemyTargetAura(spellproto, eff, currentDamage, currentBasePoints, holder, target, caster, castItem); @@ -1118,7 +1118,7 @@ void Aura::TriggerSpell() // generic casting code with custom spells and target/caster customs uint32 trigger_spell_id = GetSpellProto()->EffectTriggerSpell[m_effIndex]; - SpellEntry const* triggeredSpellInfo = sSpellTemplate.LookupEntry(trigger_spell_id); + SpellEntry const* triggeredSpellInfo = sSpellTemplate.LookupEntry(trigger_spell_id); SpellEntry const* auraSpellInfo = GetSpellProto(); uint32 auraId = auraSpellInfo->Id; Unit* target = GetTarget(); @@ -1528,7 +1528,7 @@ void Aura::TriggerSpell() break; } // // They Must Burn Bomb Aura -// case 36344: break; +// case 36344: break; case 36350: // They Must Burn Bomb Aura (self) trigger_spell_id = 36325; // They Must Burn Bomb Drop (DND) break; @@ -1893,9 +1893,9 @@ void Aura::TriggerSpell() } // Reget trigger spell proto - triggeredSpellInfo = sSpellTemplate.LookupEntry(trigger_spell_id); + triggeredSpellInfo = sSpellTemplate.LookupEntry(trigger_spell_id); } - else + else { // for channeled spell cast applied from aura owner to channel target (persistent aura affects already applied to true target) // come periodic casts applied to targets, so need select proper caster (ex. 15790) @@ -2152,7 +2152,7 @@ void Aura::TriggerSpellWithValue() uint32 trigger_spell_id = GetSpellProto()->EffectTriggerSpell[m_effIndex]; int32 calculatedAmount = GetModifier()->m_amount; - SpellEntry const* triggeredSpellInfo = sSpellTemplate.LookupEntry(trigger_spell_id); + SpellEntry const* triggeredSpellInfo = sSpellTemplate.LookupEntry(trigger_spell_id); int32 basePoints[3] = { 0,0,0 }; // damage triggered from spell might not only be processed by first effect (but always EffectDieSides equal 1) if (triggeredSpellInfo) @@ -3510,7 +3510,7 @@ void Aura::HandleAuraModShapeshift(bool apply, bool Real) if (itr.second.state == PLAYERSPELL_REMOVED) continue; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(itr.first); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(itr.first); if (spellInfo && spellInfo->SpellFamilyName == SPELLFAMILY_WARRIOR && spellInfo->SpellIconID == 139) Rage_val += target->CalculateSpellEffectValue(target, spellInfo, EFFECT_INDEX_0) * 10; } @@ -4337,7 +4337,7 @@ void Aura::HandleAuraModStun(bool apply, bool Real) default: sLog.outError("Spell selection called for unexpected original spell %u, new spell for this spell family?", GetId()); return; } - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell_id); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell_id); if (!spellInfo) return; @@ -6578,7 +6578,7 @@ void Aura::HandleShapeshiftBoosts(bool apply) { if (itr.second.state == PLAYERSPELL_REMOVED) continue; if (itr.first == spellId1 || itr.first == spellId2) continue; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(itr.first); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(itr.first); if (!spellInfo || !IsNeedCastSpellAtFormApply(spellInfo, form)) continue; target->CastSpell(target, itr.first, TRIGGERED_OLD_TRIGGERED, nullptr, this); @@ -6587,7 +6587,7 @@ void Aura::HandleShapeshiftBoosts(bool apply) // Leader of the Pack if (((Player*)target)->HasSpell(17007)) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(24932); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(24932); if (spellInfo && spellInfo->Stances & (1 << (form - 1))) target->CastSpell(target, 24932, TRIGGERED_OLD_TRIGGERED, nullptr, this); } @@ -6812,7 +6812,7 @@ void Aura::HandleSpiritOfRedemption(bool apply, bool Real) if (target->IsNonMeleeSpellCasted(false)) target->InterruptNonMeleeSpells(false); - // set health and mana to maximum + // set health and mana to maximum target->SetPower(POWER_MANA, target->GetMaxPower(POWER_MANA)); } // die at aura end @@ -7554,7 +7554,7 @@ void Aura::PeriodicDummyTick() case 37025: // Coilfang Water if (target->IsInSwimmableWater()) target->CastSpell(target, 37026, TRIGGERED_OLD_TRIGGERED, nullptr, this); - return; + return; case 39993: // Simon Game START timer, (DND) target->AI()->SendAIEvent(AI_EVENT_CUSTOM_A, target, target); break; @@ -7983,7 +7983,7 @@ SpellAuraHolder::SpellAuraHolder(SpellEntry const* spellproto, Unit* target, Wor m_auraScript(SpellScriptMgr::GetAuraScript(spellproto->Id)) { MANGOS_ASSERT(target); - MANGOS_ASSERT(spellproto && spellproto == sSpellTemplate.LookupEntry(spellproto->Id) && "`info` must be pointer to sSpellTemplate element"); + MANGOS_ASSERT(spellproto && spellproto == sSpellTemplate.LookupEntry(spellproto->Id) && "`info` must be pointer to sSpellTemplate element"); if (!caster) m_casterGuid = target->GetObjectGuid(); @@ -8260,7 +8260,7 @@ void SpellAuraHolder::CleanupTriggeredSpells() if (!tSpellId) continue; - SpellEntry const* tProto = sSpellTemplate.LookupEntry(tSpellId); + SpellEntry const* tProto = sSpellTemplate.LookupEntry(tSpellId); if (!tProto) continue; @@ -8535,7 +8535,7 @@ void SpellAuraHolder::HandleSpellSpecificBoosts(bool apply) Unit* boostCaster = m_target; Unit* boostTarget = nullptr; ObjectGuid casterGuid = m_target->GetObjectGuid(); // caster can be nullptr, but guid is still valid for removal - SpellEntry const* boostEntry = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* boostEntry = sSpellTemplate.LookupEntry(spellId); for (uint32 target : boostEntry->EffectImplicitTargetA) { switch (target) @@ -8908,7 +8908,7 @@ GameObjectAura::GameObjectAura(SpellEntry const* spellproto, SpellEffectIndex ef } GameObjectAura::~GameObjectAura() -{ +{ } void GameObjectAura::Update(uint32 diff) diff --git a/src/game/Spells/SpellEffects.cpp b/src/game/Spells/SpellEffects.cpp index c0b5e45f15..33e8ccdfdc 100644 --- a/src/game/Spells/SpellEffects.cpp +++ b/src/game/Spells/SpellEffects.cpp @@ -3046,7 +3046,7 @@ void Spell::EffectDummy(SpellEffectIndex eff_idx) if (pEnchant->type[s] != ITEM_ENCHANTMENT_TYPE_COMBAT_SPELL) continue; - SpellEntry const* combatEntry = sSpellTemplate.LookupEntry(pEnchant->spellid[s]); + SpellEntry const* combatEntry = sSpellTemplate.LookupEntry(pEnchant->spellid[s]); if (!combatEntry || combatEntry->Dispel != DISPEL_POISON) continue; @@ -3145,7 +3145,7 @@ void Spell::EffectDummy(SpellEffectIndex eff_idx) case 561: // Judgement of command { if (unitTarget) - if (SpellEntry const* spell_proto = sSpellTemplate.LookupEntry(m_currentBasePoints[eff_idx])) + if (SpellEntry const* spell_proto = sSpellTemplate.LookupEntry(m_currentBasePoints[eff_idx])) m_caster->CastSpell(unitTarget, spell_proto, TRIGGERED_OLD_TRIGGERED, nullptr); return; @@ -3212,7 +3212,7 @@ void Spell::EffectDummy(SpellEffectIndex eff_idx) return; } - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell_id); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell_id); if (!spellInfo) { @@ -3325,7 +3325,7 @@ void Spell::EffectTriggerSpellWithValue(SpellEffectIndex eff_idx) uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[eff_idx]; // normal case - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(triggered_spell_id); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(triggered_spell_id); if (!spellInfo) { @@ -3349,7 +3349,7 @@ void Spell::EffectTriggerSpellWithValue(SpellEffectIndex eff_idx) void Spell::EffectTriggerRitualOfSummoning(SpellEffectIndex eff_idx) { uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[eff_idx]; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(triggered_spell_id); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(triggered_spell_id); if (!spellInfo) { @@ -3370,7 +3370,7 @@ void Spell::EffectForceCast(SpellEffectIndex effIndex) uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[effIndex]; // normal case - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(triggered_spell_id); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(triggered_spell_id); if (!spellInfo) { @@ -3421,11 +3421,11 @@ void Spell::EffectTriggerSpell(SpellEffectIndex effIndex) // special cases switch (triggered_spell_id) { - case 23209: // Terrordale Haunting Spirit + case 23209: // Terrordale Haunting Spirit if (urand(1, 100) > 55) return; break; - case 23253: // Terrordale Haunting Spirit + case 23253: // Terrordale Haunting Spirit if (urand(1, 100) > 35) return; break; @@ -3453,7 +3453,7 @@ void Spell::EffectTriggerSpell(SpellEffectIndex effIndex) } // normal case - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(triggered_spell_id); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(triggered_spell_id); if (!spellInfo) { sLog.outError("EffectTriggerSpell of spell %u: triggering unknown spell id %i", m_spellInfo->Id, triggered_spell_id); @@ -3527,7 +3527,7 @@ void Spell::EffectTriggerMissileSpell(SpellEffectIndex effect_idx) uint32 triggered_spell_id = m_spellInfo->EffectTriggerSpell[effect_idx]; // normal case - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(triggered_spell_id); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(triggered_spell_id); if (!spellInfo) { @@ -3581,7 +3581,7 @@ void Spell::EffectTeleportUnits(SpellEffectIndex eff_idx) // TODO - Use target else orientation = unitTarget->GetOrientation(); } - + // Teleport if (m_targets.m_mapId == UINT32_MAX || m_targets.m_mapId == unitTarget->GetMapId()) { @@ -4248,7 +4248,7 @@ void Spell::EffectEnergize(SpellEffectIndex eff_idx) if (itr->second & (ELIXIR_UNSTABLE_MASK | ELIXIR_SHATTRATH_MASK)) continue; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(itr->first); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(itr->first); if (spellInfo && (spellInfo->spellLevel < m_spellInfo->spellLevel || spellInfo->spellLevel > unitTarget->getLevel())) continue; @@ -5848,7 +5848,7 @@ void Spell::EffectLearnPetSpell(SpellEffectIndex eff_idx) if (!pet->IsAlive()) return; - SpellEntry const* learn_spellproto = sSpellTemplate.LookupEntry(m_spellInfo->EffectTriggerSpell[eff_idx]); + SpellEntry const* learn_spellproto = sSpellTemplate.LookupEntry(m_spellInfo->EffectTriggerSpell[eff_idx]); if (!learn_spellproto) return; @@ -5961,7 +5961,7 @@ void Spell::EffectWeaponDmg(SpellEffectIndex eff_idx) if (!itr->second.active || itr->second.disabled || itr->second.state == PLAYERSPELL_REMOVED) continue; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(itr->first); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(itr->first); if (!spellInfo) continue; @@ -8002,14 +8002,14 @@ void Spell::EffectDuel(SpellEffectIndex eff_idx) return; // Players can only fight a duel with each other outside (=not inside dungeons and not in capital cities) - AreaTableEntry const* casterAreaEntry = GetAreaEntryByAreaID(caster->GetAreaId()); + AreaTableEntry const* casterAreaEntry = TerrainManager::GetAreaEntryByAreaID(caster->GetAreaId()); if (casterAreaEntry && !(casterAreaEntry->flags & AREA_FLAG_DUEL)) { SendCastResult(SPELL_FAILED_NO_DUELING); // Dueling isn't allowed here return; } - AreaTableEntry const* targetAreaEntry = GetAreaEntryByAreaID(target->GetAreaId()); + AreaTableEntry const* targetAreaEntry = TerrainManager::GetAreaEntryByAreaID(target->GetAreaId()); if (targetAreaEntry && !(targetAreaEntry->flags & AREA_FLAG_DUEL)) { SendCastResult(SPELL_FAILED_NO_DUELING); // Dueling isn't allowed here @@ -8101,7 +8101,7 @@ void Spell::EffectStuck(SpellEffectIndex /*eff_idx*/) { player->TeleportToHomebind(TELE_TO_SPELL); // Trigger cooldown - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(8690); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(8690); if (!spellInfo) return; Spell spell(player, spellInfo, TRIGGERED_OLD_TRIGGERED); @@ -8780,7 +8780,7 @@ void Spell::EffectReputation(SpellEffectIndex eff_idx) int32 rep_change = m_currentBasePoints[eff_idx]; uint32 faction_id = m_spellInfo->EffectMiscValue[eff_idx]; - FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction_id); + FactionEntry const* factionEntry = sFactionStore.LookupEntry(faction_id); if (!factionEntry) return; @@ -9097,7 +9097,7 @@ void Spell::EffectDestroyAllTotems(SpellEffectIndex /*eff_idx*/) if (damage) { uint32 spell_id = totem->GetUInt32Value(UNIT_CREATED_BY_SPELL); - if (SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell_id)) + if (SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell_id)) { uint32 manacost = spellInfo->manaCost + m_caster->GetCreateMana() * spellInfo->ManaCostPercentage / 100; mana += manacost * damage / 100; diff --git a/src/game/Spells/SpellHandler.cpp b/src/game/Spells/SpellHandler.cpp index 5a414a8876..2064ee9c6c 100644 --- a/src/game/Spells/SpellHandler.cpp +++ b/src/game/Spells/SpellHandler.cpp @@ -112,7 +112,7 @@ void WorldSession::HandleUseItemOpcode(WorldPacket& recvPacket) { for (const auto& Spell : proto->Spells) { - if (SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(Spell.SpellId)) + if (SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(Spell.SpellId)) { if (IsNonCombatSpell(spellInfo)) { @@ -157,7 +157,7 @@ void WorldSession::HandleUseItemOpcode(WorldPacket& recvPacket) } // send spell error - if (SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellid)) + if (SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellid)) Spell::SendCastResult(_player, spellInfo, cast_count, SPELL_FAILED_BAD_TARGETS); return; } @@ -335,7 +335,7 @@ void WorldSession::HandleCastSpellOpcode(WorldPacket& recvPacket) DEBUG_LOG("WORLD: CMSG_CAST_SPELL, spellId - %u, cast_count: %u data length = " SIZEFMTD, spellId, cast_count, recvPacket.size()); - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) { sLog.outError("WORLD: unknown spell id %u", spellId); @@ -441,7 +441,7 @@ void WorldSession::HandleCancelAuraOpcode(WorldPacket& recvPacket) uint32 spellId; recvPacket >> spellId; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) return; @@ -510,7 +510,7 @@ void WorldSession::HandlePetCancelAuraOpcode(WorldPacket& recvPacket) if (!_player->IsSelfMover()) return; - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) { sLog.outError("WORLD: unknown PET spell id %u", spellId); @@ -590,7 +590,7 @@ void WorldSession::HandleSelfResOpcode(WorldPacket& /*recv_data*/) if (_player->GetUInt32Value(PLAYER_SELF_RES_SPELL)) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(_player->GetUInt32Value(PLAYER_SELF_RES_SPELL)); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(_player->GetUInt32Value(PLAYER_SELF_RES_SPELL)); if (spellInfo) _player->CastSpell(_player, spellInfo, TRIGGERED_NONE); diff --git a/src/game/Spells/SpellMgr.cpp b/src/game/Spells/SpellMgr.cpp index 9f3ac6a451..2a687d508a 100644 --- a/src/game/Spells/SpellMgr.cpp +++ b/src/game/Spells/SpellMgr.cpp @@ -294,7 +294,7 @@ uint16 GetSpellAuraMaxTicks(SpellEntry const* spellInfo) uint16 GetSpellAuraMaxTicks(uint32 spellId) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) { sLog.outError("GetSpellAuraMaxTicks: Spell %u not exist!", spellId); @@ -350,7 +350,7 @@ WeaponAttackType GetWeaponAttackType(SpellEntry const* spellInfo) SpellSpecific GetSpellSpecific(uint32 spellId) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) return SPELL_NORMAL; @@ -504,7 +504,7 @@ SpellCastResult GetErrorAtShapeshiftedCast(SpellEntry const* spellInfo, uint32 f { // talents that learn spells can have stance requirements that need ignore // (this requirement only for client-side stance show in talent description) - if (GetTalentSpellCost(spellInfo->Id) > 0 && + if (ObjectMgr::GetTalentSpellCost(spellInfo->Id) > 0 && (spellInfo->Effect[EFFECT_INDEX_0] == SPELL_EFFECT_LEARN_SPELL || spellInfo->Effect[EFFECT_INDEX_1] == SPELL_EFFECT_LEARN_SPELL || spellInfo->Effect[EFFECT_INDEX_2] == SPELL_EFFECT_LEARN_SPELL)) return SPELL_CAST_OK; @@ -593,7 +593,7 @@ void SpellMgr::LoadSpellTargetPositions() continue; } - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(Spell_ID); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(Spell_ID); if (!spellInfo) { sLog.outErrorDb("Spell (ID:%u) listed in `spell_target_position` does not exist.", Spell_ID); @@ -632,7 +632,7 @@ struct SpellRankHelper SpellRankHelper(SpellMgr& _mgr, StorageType& _storage): mgr(_mgr), worker(_storage), customRank(0) {} void RecordRank(EntryType& entry, uint32 spell_id) { - const SpellEntry* spell = sSpellTemplate.LookupEntry(spell_id); + const SpellEntry* spell = sSpellTemplate.LookupEntry(spell_id); if (!spell) { sLog.outErrorDb("Spell %u listed in `%s` does not exist", spell_id, worker.TableName()); @@ -892,7 +892,7 @@ void SpellMgr::LoadSpellProcItemEnchant() uint32 entry = fields[0].GetUInt32(); float ppmRate = fields[1].GetFloat(); - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(entry); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(entry); if (!spellInfo) { @@ -956,7 +956,7 @@ void SpellMgr::LoadSpellBonuses() bar.step(); uint32 entry = fields[0].GetUInt32(); - SpellEntry const* spell = sSpellTemplate.LookupEntry(entry); + SpellEntry const* spell = sSpellTemplate.LookupEntry(entry); if (!spell) { sLog.outErrorDb("Spell %u listed in `spell_bonus_data` does not exist", entry); @@ -1193,7 +1193,7 @@ void SpellMgr::LoadSpellElixirs() uint32 entry = fields[0].GetUInt32(); uint8 mask = fields[1].GetUInt8(); - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(entry); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(entry); if (!spellInfo) { @@ -1335,7 +1335,7 @@ bool SpellMgr::IsSpellCanAffectSpell(SpellEntry const* spellInfo_1, SpellEntry c bool SpellMgr::IsProfessionOrRidingSpell(uint32 spellId) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) return false; @@ -1349,7 +1349,7 @@ bool SpellMgr::IsProfessionOrRidingSpell(uint32 spellId) bool SpellMgr::IsProfessionSpell(uint32 spellId) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) return false; @@ -1363,7 +1363,7 @@ bool SpellMgr::IsProfessionSpell(uint32 spellId) bool SpellMgr::IsPrimaryProfessionSpell(uint32 spellId) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) return false; @@ -1431,7 +1431,7 @@ SpellEntry const* SpellMgr::SelectAuraRankForLevel(SpellEntry const* spellInfo, { for (uint32 nextSpellId = spellInfo->Id; nextSpellId != 0; nextSpellId = GetPrevSpellInChain(nextSpellId)) { - SpellEntry const* nextSpellInfo = sSpellTemplate.LookupEntry(nextSpellId); + SpellEntry const* nextSpellInfo = sSpellTemplate.LookupEntry(nextSpellId); if (!nextSpellInfo) break; @@ -1521,12 +1521,8 @@ void SpellMgr::LoadSpellChains() mSpellChainsNext.clear(); // need for reload case // load known data for talents - for (unsigned int i = 0; i < sTalentStore.GetNumRows(); ++i) + for (auto talentInfo : sTalentStore) { - TalentEntry const* talentInfo = sTalentStore.LookupEntry(i); - if (!talentInfo) - continue; - // not add ranks for 1 ranks talents (if exist non ranks spells then it will included in table data) if (!talentInfo->RankID[1]) continue; @@ -1537,7 +1533,7 @@ void SpellMgr::LoadSpellChains() if (!spell_id) continue; - if (!sSpellTemplate.LookupEntry(spell_id)) + if (!sSpellTemplate.LookupEntry(spell_id)) { // sLog.outErrorDb("Talent %u not exist as spell",spell_id); continue; @@ -1566,7 +1562,7 @@ void SpellMgr::LoadSpellChains() continue; // some forward spells not exist and can be ignored (some outdated data) - SpellEntry const* spell_entry = sSpellTemplate.LookupEntry(spell_id); + SpellEntry const* spell_entry = sSpellTemplate.LookupEntry(spell_id); if (!spell_entry) // no cases continue; @@ -1581,7 +1577,7 @@ void SpellMgr::LoadSpellChains() continue; // some forward spells not exist and can be ignored (some outdated data) - SpellEntry const* forward_entry = sSpellTemplate.LookupEntry(forward_id); + SpellEntry const* forward_entry = sSpellTemplate.LookupEntry(forward_id); if (!forward_entry) continue; @@ -1665,7 +1661,7 @@ void SpellMgr::LoadSpellChains() node.rank = fields[3].GetUInt8(); node.req = fields[4].GetUInt32(); - if (!sSpellTemplate.LookupEntry(spell_id)) + if (!sSpellTemplate.LookupEntry(spell_id)) { sLog.outErrorDb("Spell %u listed in `spell_chain` does not exist", spell_id); continue; @@ -1709,14 +1705,14 @@ void SpellMgr::LoadSpellChains() continue; } - if (node.prev != 0 && !sSpellTemplate.LookupEntry(node.prev)) + if (node.prev != 0 && !sSpellTemplate.LookupEntry(node.prev)) { sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has nonexistent previous rank spell.", spell_id, node.prev, node.first, node.rank, node.req); continue; } - if (!sSpellTemplate.LookupEntry(node.first)) + if (!sSpellTemplate.LookupEntry(node.first)) { sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existing first rank spell.", spell_id, node.prev, node.first, node.rank, node.req); @@ -1733,7 +1729,7 @@ void SpellMgr::LoadSpellChains() continue; } - if (node.req != 0 && !sSpellTemplate.LookupEntry(node.req)) + if (node.req != 0 && !sSpellTemplate.LookupEntry(node.req)) { sLog.outErrorDb("Spell %u (prev: %u, first: %u, rank: %d, req: %u) listed in `spell_chain` has not existing required spell.", spell_id, node.prev, node.first, node.rank, node.req); @@ -1741,7 +1737,7 @@ void SpellMgr::LoadSpellChains() } // talents not required data in spell chain for work, but must be checked if present for integrity - if (TalentSpellPos const* pos = GetTalentSpellPos(spell_id)) + if (TalentSpellPos const* pos = ObjectMgr::GetTalentSpellPos(spell_id)) { if (node.rank != pos->rank + 1) { @@ -1869,13 +1865,9 @@ void SpellMgr::LoadSpellLearnSkills() // search auto-learned skills and add its to map also for use in unlearn spells/talents uint32 dbc_count = 0; BarGoLink bar(sSpellTemplate.GetMaxEntry()); - for (uint32 spell = 0; spell < sSpellTemplate.GetMaxEntry(); ++spell) + for (auto entry : sSpellTemplate) { bar.step(); - SpellEntry const* entry = sSpellTemplate.LookupEntry(spell); - - if (!entry) - continue; for (int i = 0; i < MAX_EFFECT_INDEX; ++i) { @@ -1888,7 +1880,7 @@ void SpellMgr::LoadSpellLearnSkills() if (dbc_node.skill && dbc_node.step) { - mSpellLearnSkills[spell] = dbc_node; + mSpellLearnSkills[entry->Id] = dbc_node; ++dbc_count; break; } @@ -1932,19 +1924,19 @@ void SpellMgr::LoadSpellLearnSpells() node.active = fields[2].GetBool(); node.autoLearned = false; - if (!sSpellTemplate.LookupEntry(spell_id)) + if (!sSpellTemplate.LookupEntry(spell_id)) { sLog.outErrorDb("Spell %u listed in `spell_learn_spell` does not exist", spell_id); continue; } - if (!sSpellTemplate.LookupEntry(node.spell)) + if (!sSpellTemplate.LookupEntry(node.spell)) { sLog.outErrorDb("Spell %u listed in `spell_learn_spell` learning nonexistent spell %u", spell_id, node.spell); continue; } - if (GetTalentSpellCost(node.spell)) + if (ObjectMgr::GetTalentSpellCost(node.spell)) { sLog.outErrorDb("Spell %u listed in `spell_learn_spell` attempt learning talent spell %u, skipped", spell_id, node.spell); continue; @@ -1962,7 +1954,7 @@ void SpellMgr::LoadSpellLearnSpells() uint32 dbc_count = 0; for (uint32 spell = 0; spell < sSpellTemplate.GetMaxEntry(); ++spell) { - SpellEntry const* entry = sSpellTemplate.LookupEntry(spell); + SpellEntry const* entry = sSpellTemplate.LookupEntry(spell); if (!entry) continue; @@ -1976,13 +1968,13 @@ void SpellMgr::LoadSpellLearnSpells() dbc_node.active = true; // all dbc based learned spells is active (show in spell book or hide by client itself) // ignore learning nonexistent spells (broken/outdated/or generic learning spell 483 - if (!sSpellTemplate.LookupEntry(dbc_node.spell)) + if (!sSpellTemplate.LookupEntry(dbc_node.spell)) continue; // talent or passive spells or skill-step spells auto-casted and not need dependent learning, // pet teaching spells don't must be dependent learning (casted) // other required explicit dependent learning - dbc_node.autoLearned = entry->EffectImplicitTargetA[i] == TARGET_UNIT_CASTER_PET || GetTalentSpellCost(spell) > 0 || IsPassiveSpell(entry) || IsSpellHaveEffect(entry, SPELL_EFFECT_SKILL_STEP); + dbc_node.autoLearned = entry->EffectImplicitTargetA[i] == TARGET_UNIT_CASTER_PET || ObjectMgr::GetTalentSpellCost(spell) > 0 || IsPassiveSpell(entry) || IsSpellHaveEffect(entry, SPELL_EFFECT_SKILL_STEP); SpellLearnSpellMapBounds db_node_bounds = GetSpellLearnSpellMapBounds(spell); @@ -2016,9 +2008,9 @@ void SpellMgr::LoadSpellScriptTarget() sSpellScriptTargetStorage.Load(); // Check content - for (SQLMultiStorage::SQLSIterator itr = sSpellScriptTargetStorage.getDataBegin(); itr < sSpellScriptTargetStorage.getDataEnd(); ++itr) + for (auto itr = sSpellScriptTargetStorage.begin(); itr < sSpellScriptTargetStorage.end(); ++itr) { - SpellEntry const* spellProto = sSpellTemplate.LookupEntry(itr->spellId); + SpellEntry const* spellProto = sSpellTemplate.LookupEntry(itr->spellId); if (!spellProto) { sLog.outErrorDb("Table `spell_script_target`: spellId %u listed for TargetEntry %u does not exist.", itr->spellId, itr->targetEntry); @@ -2072,7 +2064,7 @@ void SpellMgr::LoadSpellScriptTarget() if (!itr->targetEntry) break; - if (!sGOStorage.LookupEntry(itr->targetEntry)) + if (!sGOStorage.LookupEntry(itr->targetEntry)) { sLog.outErrorDb("Table `spell_script_target`: gameobject template entry %u does not exist.", itr->targetEntry); sSpellScriptTargetStorage.EraseEntry(itr->spellId); @@ -2107,7 +2099,7 @@ void SpellMgr::LoadSpellScriptTarget() sSpellScriptTargetStorage.EraseEntry(itr->spellId); continue; } - if (const CreatureInfo* cInfo = sCreatureStorage.LookupEntry(itr->targetEntry)) + if (const CreatureInfo* cInfo = sCreatureStorage.LookupEntry(itr->targetEntry)) { if (itr->spellId == 30427 && !cInfo->SkinningLootId) { @@ -2127,18 +2119,14 @@ void SpellMgr::LoadSpellScriptTarget() // Check all spells if (!sLog.HasLogFilter(LOG_FILTER_DB_STRICTED_CHECK)) { - for (uint32 i = 1; i < sSpellTemplate.GetMaxEntry(); ++i) + for (auto spellInfo : sSpellTemplate) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(i); - if (!spellInfo) - continue; - for (int j = 0; j < MAX_EFFECT_INDEX; ++j) { if (spellInfo->Effect[j] && (spellInfo->EffectImplicitTargetA[j] == TARGET_UNIT_SCRIPT_NEAR_CASTER || (spellInfo->EffectImplicitTargetA[j] != TARGET_UNIT_CASTER && spellInfo->EffectImplicitTargetB[j] == TARGET_UNIT_SCRIPT_NEAR_CASTER))) { - SQLMultiStorage::SQLMSIteratorBounds bounds = sSpellScriptTargetStorage.getBounds(i); + auto bounds = sSpellScriptTargetStorage.getBounds(spellInfo->Id); if (bounds.first == bounds.second) { sLog.outErrorDb("Spell (ID: %u) has effect EffectImplicitTargetA/EffectImplicitTargetB = %u (TARGET_UNIT_SCRIPT_NEAR_CASTER), but does not have record in `spell_script_target`", spellInfo->Id, TARGET_UNIT_SCRIPT_NEAR_CASTER); @@ -2149,7 +2137,7 @@ void SpellMgr::LoadSpellScriptTarget() } } - sLog.outString(">> Loaded %u spell_script_target definitions", sSpellScriptTargetStorage.GetRecordCount()); + sLog.outString(">> Loaded %u spell_script_target definitions", sSpellScriptTargetStorage.GetNumRows()); sLog.outString(); } @@ -2189,7 +2177,7 @@ void SpellMgr::LoadSpellPetAuras() } else { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spell); if (!spellInfo) { sLog.outErrorDb("Spell %u listed in `spell_pet_auras` does not exist", spell); @@ -2208,7 +2196,7 @@ void SpellMgr::LoadSpellPetAuras() continue; } - SpellEntry const* spellInfo2 = sSpellTemplate.LookupEntry(aura); + SpellEntry const* spellInfo2 = sSpellTemplate.LookupEntry(aura); if (!spellInfo2) { sLog.outErrorDb("Aura %u listed in `spell_pet_auras` does not exist", aura); @@ -2266,7 +2254,7 @@ bool SpellMgr::IsSpellValid(SpellEntry const* spellInfo, Player* pl, bool msg) } case SPELL_EFFECT_LEARN_SPELL: { - SpellEntry const* spellInfo2 = sSpellTemplate.LookupEntry(spellInfo->EffectTriggerSpell[i]); + SpellEntry const* spellInfo2 = sSpellTemplate.LookupEntry(spellInfo->EffectTriggerSpell[i]); if (!IsSpellValid(spellInfo2, pl, msg)) { if (msg) @@ -2344,7 +2332,7 @@ void SpellMgr::LoadSpellAreas() spellArea.gender = Gender(fields[8].GetUInt8()); spellArea.autocast = fields[9].GetBool(); - if (!sSpellTemplate.LookupEntry(spell)) + if (!sSpellTemplate.LookupEntry(spell)) { sLog.outErrorDb("Spell %u listed in `spell_area` does not exist", spell); continue; @@ -2380,13 +2368,13 @@ void SpellMgr::LoadSpellAreas() } } - if (spellArea.areaId && !GetAreaEntryByAreaID(spellArea.areaId)) + if (spellArea.areaId && !TerrainManager::GetAreaEntryByAreaID(spellArea.areaId)) { sLog.outErrorDb("Spell %u listed in `spell_area` have wrong area (%u) requirement", spell, spellArea.areaId); continue; } - if (spellArea.conditionId && !sConditionStorage.LookupEntry(spellArea.conditionId)) + if (spellArea.conditionId && !sConditionStorage.LookupEntry(spellArea.conditionId)) { sLog.outErrorDb("Spell %u listed in `spell_area` have wrong conditionId (%u) requirement", spell, spellArea.conditionId); continue; @@ -2429,7 +2417,7 @@ void SpellMgr::LoadSpellAreas() if (spellArea.auraSpell) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(abs(spellArea.auraSpell)); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(abs(spellArea.auraSpell)); if (!spellInfo) { sLog.outErrorDb("Spell %u listed in `spell_area` have wrong aura spell (%u) requirement", spell, abs(spellArea.auraSpell)); @@ -2527,7 +2515,7 @@ SpellCastResult SpellMgr::GetSpellAllowedInLocationError(SpellEntry const* spell // continent limitation (virtual continent), ignore for GM if (spellInfo->HasAttribute(SPELL_ATTR_EX4_CAST_ONLY_IN_OUTLAND) && !(player && player->IsGameMaster())) { - uint32 v_map = GetVirtualMapForMapAndZone(map_id, zone_id); + uint32 v_map = Map::GetVirtualMapForMapAndZone(map_id, zone_id); MapEntry const* mapEntry = sMapStore.LookupEntry(v_map); if (!mapEntry || mapEntry->addon < 1 || !mapEntry->IsContinent()) return SPELL_FAILED_REQUIRES_AREA; @@ -2632,19 +2620,15 @@ void SpellMgr::LoadSkillLineAbilityMaps() mSkillLineAbilityMapBySpellId.clear(); mSkillLineAbilityMapBySkillId.clear(); - const uint32 rows = sSkillLineAbilityStore.GetNumRows(); uint32 count = 0; - BarGoLink bar(rows); - for (uint32 row = 0; row < rows; ++row) + BarGoLink bar(sSkillLineAbilityStore.GetNumRows()); + for (auto entry : sSkillLineAbilityStore) { bar.step(); - if (SkillLineAbilityEntry const* entry = sSkillLineAbilityStore.LookupEntry(row)) - { - mSkillLineAbilityMapBySpellId.insert(SkillLineAbilityMap::value_type(entry->spellId, entry)); - mSkillLineAbilityMapBySkillId.insert(SkillLineAbilityMap::value_type(entry->skillId, entry)); - ++count; - } + mSkillLineAbilityMapBySpellId.insert(SkillLineAbilityMap::value_type(entry->spellId, entry)); + mSkillLineAbilityMapBySkillId.insert(SkillLineAbilityMap::value_type(entry->skillId, entry)); + ++count; } sLog.outString(">> Loaded %u SkillLineAbility MultiMaps Data", count); @@ -2658,12 +2642,9 @@ void SpellMgr::LoadSkillRaceClassInfoMap() BarGoLink bar(sSkillRaceClassInfoStore.GetNumRows()); uint32 count = 0; - for (uint32 i = 0; i < sSkillRaceClassInfoStore.GetNumRows(); ++i) + for (auto skillRCInfo : sSkillRaceClassInfoStore) { bar.step(); - SkillRaceClassInfoEntry const* skillRCInfo = sSkillRaceClassInfoStore.LookupEntry(i); - if (!skillRCInfo) - continue; // not all skills really listed in ability skills list if (!sSkillLineStore.LookupEntry(skillRCInfo->skillId)) @@ -2770,7 +2751,7 @@ void SpellMgr::CheckUsedSpells(char const* table) const { ++countSpells; - SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(spell); + SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(spell); if (!spellEntry) { sLog.outError("Spell %u '%s' not exist but used in %s.", spell, name.c_str(), code.c_str()); @@ -2854,12 +2835,8 @@ void SpellMgr::CheckUsedSpells(char const* table) const ++countMasks; bool found = false; - for (uint32 spellId = 1; spellId < sSpellTemplate.GetMaxEntry(); ++spellId) + for (auto spellEntry : sSpellTemplate) { - SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(spellId); - if (!spellEntry) - continue; - if (family >= 0 && spellEntry->SpellFamilyName != uint32(family)) continue; @@ -3230,7 +3207,7 @@ void SpellMgr::LoadSpellAffects() uint32 entry = fields[0].GetUInt32(); uint8 effectId = fields[1].GetUInt8(); - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(entry); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(entry); if (!spellInfo) { @@ -3291,12 +3268,8 @@ void SpellMgr::LoadSpellAffects() sLog.outString(); sLog.outString(">> Loaded %u spell affect definitions", count); - for (uint32 id = 0; id < sSpellTemplate.GetMaxEntry(); ++id) + for (auto spellInfo : sSpellTemplate) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(id); - if (!spellInfo) - continue; - for (int effectId = 0; effectId < MAX_EFFECT_INDEX; ++effectId) { if (spellInfo->Effect[effectId] != SPELL_EFFECT_APPLY_AURA || ( @@ -3309,10 +3282,10 @@ void SpellMgr::LoadSpellAffects() if (spellInfo->EffectItemType[effectId] != 0) continue; - if (mSpellAffectMap.find((id << 8) + effectId) != mSpellAffectMap.end()) + if (mSpellAffectMap.find((spellInfo->Id << 8) + effectId) != mSpellAffectMap.end()) continue; - sLog.outErrorDb("Spell %u (%s) misses spell_affect for effect %u", id, spellInfo->SpellName[sWorld.GetDefaultDbcLocale()], effectId); + sLog.outErrorDb("Spell %u (%s) misses spell_affect for effect %u", spellInfo->Id, spellInfo->SpellName[sWorld.GetDefaultDbcLocale()], effectId); } } } diff --git a/src/game/Spells/SpellMgr.h b/src/game/Spells/SpellMgr.h index 58ab33af0d..19babd6044 100644 --- a/src/game/Spells/SpellMgr.h +++ b/src/game/Spells/SpellMgr.h @@ -306,7 +306,7 @@ inline bool IsPassiveSpell(SpellEntry const* spellInfo) inline bool IsPassiveSpell(uint32 spellId) { - const SpellEntry* entry = sSpellTemplate.LookupEntry(spellId); + const SpellEntry* entry = sSpellTemplate.LookupEntry(spellId); return (entry && IsPassiveSpell(entry)); } @@ -325,7 +325,7 @@ inline bool IsAutocastable(SpellEntry const* spellInfo) inline bool IsAutocastable(uint32 spellId) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(spellId); if (!spellInfo) return false; return IsAutocastable(spellInfo); @@ -525,7 +525,7 @@ inline bool IsSpellRemovedOnEvade(SpellEntry const* spellInfo) case 37119: // Spirit Particles (Spawn) case 37266: // Disease Cloud case 37411: // Skettis Corrupted Ghosts - case 37497: // Shadowmoon Ghost Invisibility (Ghostrider of Karabor in SMV) + case 37497: // Shadowmoon Ghost Invisibility (Ghostrider of Karabor in SMV) case 37509: // Ghostly Facade case 37816: // Shadowform case 38732: // Fire Shield @@ -1037,7 +1037,7 @@ inline bool IsPositiveEffectTargetMode(const SpellEntry* entry, SpellEffectIndex // Its possible to go infinite cycle with triggered spells. We are interested to peek only at the first layer so far if (!recursive && spellid && (spellid != entry->Id)) { - if (const SpellEntry* triggered = sSpellTemplate.LookupEntry(spellid)) + if (const SpellEntry* triggered = sSpellTemplate.LookupEntry(spellid)) { for (uint32 i = EFFECT_INDEX_0; i < MAX_EFFECT_INDEX; ++i) { @@ -1250,7 +1250,7 @@ inline bool IsPositiveSpellTargetModeForSpecificTarget(uint32 spellId, uint8 eff { if (!spellId) return false; - return IsPositiveSpellTargetModeForSpecificTarget(sSpellTemplate.LookupEntry(spellId), effectMask, caster, target); + return IsPositiveSpellTargetModeForSpecificTarget(sSpellTemplate.LookupEntry(spellId), effectMask, caster, target); } inline bool IsPositiveSpellTargetMode(const SpellEntry* entry, const WorldObject* caster = nullptr, const WorldObject* target = nullptr) @@ -1269,7 +1269,7 @@ inline bool IsPositiveSpellTargetMode(uint32 spellId, const WorldObject* caster, { if (!spellId) return false; - return IsPositiveSpellTargetMode(sSpellTemplate.LookupEntry(spellId), caster, target); + return IsPositiveSpellTargetMode(sSpellTemplate.LookupEntry(spellId), caster, target); } inline bool IsPositiveSpell(const SpellEntry* entry, const WorldObject* caster = nullptr, const WorldObject* target = nullptr) @@ -1301,11 +1301,11 @@ inline bool IsPositiveSpell(uint32 spellId, const WorldObject* caster = nullptr, { if (!spellId) return false; - return IsPositiveSpell(sSpellTemplate.LookupEntry(spellId), caster, target); + return IsPositiveSpell(sSpellTemplate.LookupEntry(spellId), caster, target); } inline void GetChainJumpRange(SpellEntry const* spellInfo, SpellEffectIndex effIdx, float& minSearchRangeCaster, float& maxSearchRangeTarget) -{ +{ const SpellRangeEntry* range = sSpellRangeStore.LookupEntry(spellInfo->rangeIndex); if (spellInfo->DmgClass == SPELL_DAMAGE_CLASS_MELEE) maxSearchRangeTarget = range->maxRange; @@ -1599,7 +1599,7 @@ inline uint32 GetDispellMask(DispelType dispel) inline bool IsAuraAddedBySpell(uint32 auraType, uint32 spellId) { - SpellEntry const* spellproto = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* spellproto = sSpellTemplate.LookupEntry(spellId); if (!spellproto) return false; for (int i = 0; i < 3; i++) @@ -2070,7 +2070,7 @@ inline bool IsSimilarExistingAuraStronger(const Unit* caster, uint32 spellid, co { if (!spellid) return false; - return IsSimilarExistingAuraStronger(caster, sSpellTemplate.LookupEntry(spellid), existing); + return IsSimilarExistingAuraStronger(caster, sSpellTemplate.LookupEntry(spellid), existing); } // Diminishing Returns interaction with spells @@ -2223,17 +2223,6 @@ enum SpellTargetType #define MAX_SPELL_TARGET_TYPE 5 -// pre-defined targeting for spells -struct SpellTargetEntry -{ - uint32 spellId; - uint32 type; - uint32 targetEntry; - uint32 inverseEffectMask; - - bool CanNotHitWithSpellEffect(SpellEffectIndex effect) const { return (inverseEffectMask & (1 << effect)) != 0; } -}; - // coordinates for spells (accessed using SpellMgr functions) struct SpellTargetPosition { @@ -2244,12 +2233,6 @@ struct SpellTargetPosition float target_Orientation; }; -struct SpellCone -{ - uint32 spellId; - int32 coneAngle; -}; - typedef std::unordered_map SpellTargetPositionMap; // Spell pet auras @@ -2396,7 +2379,7 @@ class SpellMgr SpellAffectMap::const_iterator itr = mSpellAffectMap.find((spellId << 8) + effectId); if (itr != mSpellAffectMap.end()) return ClassFamilyMask(itr->second); - if (SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(spellId)) + if (SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(spellId)) return ClassFamilyMask(spellEntry->EffectItemType[effectId]); return ClassFamilyMask(); } diff --git a/src/game/Spells/SpellTargets.cpp b/src/game/Spells/SpellTargets.cpp index 4b49277990..002816463a 100644 --- a/src/game/Spells/SpellTargets.cpp +++ b/src/game/Spells/SpellTargets.cpp @@ -292,9 +292,9 @@ SpellTargetingData& SpellTargetMgr::GetSpellTargetingData(uint32 spellId) } // check if at least one target is different from different effIdx -bool CheckBoundsEqualForEffects(SQLMultiStorage::SQLMSIteratorBounds& bounds, SpellEffectIndex effIdxSource, SpellEffectIndex effIdxTarget) +bool CheckBoundsEqualForEffects(SQLMultiStorage::SQLMSIteratorBounds& bounds, SpellEffectIndex effIdxSource, SpellEffectIndex effIdxTarget) { - for (SQLMultiStorage::SQLMultiSIterator i_spellST = bounds.first; i_spellST != bounds.second; ++i_spellST) + for (auto i_spellST = bounds.first; i_spellST != bounds.second; ++i_spellST) { SpellTargetEntry const* spellST = (*i_spellST); if (spellST->CanNotHitWithSpellEffect(effIdxSource) != spellST->CanNotHitWithSpellEffect(effIdxTarget)) @@ -307,7 +307,7 @@ void SpellTargetMgr::Initialize() { for (uint32 i = 0; i <= sSpellTemplate.GetMaxEntry(); ++i) { - SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(i); + SpellEntry const* spellInfo = sSpellTemplate.LookupEntry(i); if (!spellInfo) continue; @@ -446,7 +446,7 @@ void SpellTargetMgr::Initialize() continue; if (info.filter == TARGET_SCRIPT && effIdxSource != effIdxTarget) { - SQLMultiStorage::SQLMSIteratorBounds bounds = sSpellScriptTargetStorage.getBounds(i); + auto bounds = sSpellScriptTargetStorage.getBounds(i); if (!CheckBoundsEqualForEffects(bounds, SpellEffectIndex(effIdxSource), SpellEffectIndex(effIdxTarget))) continue; } diff --git a/src/game/Spells/UnitAuraProcHandler.cpp b/src/game/Spells/UnitAuraProcHandler.cpp index 4f4257f73f..9bc0d7d7a1 100644 --- a/src/game/Spells/UnitAuraProcHandler.cpp +++ b/src/game/Spells/UnitAuraProcHandler.cpp @@ -686,7 +686,7 @@ bool Unit::IsTriggeredAtSpellProcEvent(ProcExecutionData& data, SpellAuraHolder* SpellAuraProcResult Unit::TriggerProccedSpell(Unit* target, std::array& basepoints, uint32 triggeredSpellId, Item* castItem, Aura* triggeredByAura, uint32 cooldown) { - SpellEntry const* triggerEntry = sSpellTemplate.LookupEntry(triggeredSpellId); + SpellEntry const* triggerEntry = sSpellTemplate.LookupEntry(triggeredSpellId); if (!triggerEntry) { @@ -1854,7 +1854,7 @@ SpellAuraProcResult Unit::HandleDummyAuraProc(ProcExecutionData& data) } } - SpellEntry const* windfurySpellEntry = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* windfurySpellEntry = sSpellTemplate.LookupEntry(spellId); if (!windfurySpellEntry) { sLog.outError("Unit::HandleDummyAuraProc: nonexistent spell id: %u (Windfury)", spellId); @@ -2003,7 +2003,7 @@ SpellAuraProcResult Unit::HandleDummyAuraProc(ProcExecutionData& data) } // Remove cooldown (Chain Lightning - have Category Recovery time) - SpellEntry const* procSpellEntry = sSpellTemplate.LookupEntry(spellId); + SpellEntry const* procSpellEntry = sSpellTemplate.LookupEntry(spellId); if (!procSpellEntry) { sLog.outError("Unit::HandleDummyAuraProc: nonexistent spell id: %u (Lightning Bolt and Chain Lightning)", spellId); @@ -2509,7 +2509,7 @@ SpellAuraProcResult Unit::HandleProcTriggerSpellAuraProc(ProcExecutionData& data return SPELL_AURA_PROC_FAILED; } } - SpellEntry const* originalSpell = sSpellTemplate.LookupEntry(originalSpellId); + SpellEntry const* originalSpell = sSpellTemplate.LookupEntry(originalSpellId); if (!originalSpell) { sLog.outError("Unit::HandleProcTriggerSpellAuraProc: Spell %u unknown but selected as original in Illu", originalSpellId); @@ -2664,7 +2664,7 @@ SpellAuraProcResult Unit::HandleProcTriggerSpellAuraProc(ProcExecutionData& data } // All ok. Check current trigger spell - SpellEntry const* triggerEntry = sSpellTemplate.LookupEntry(trigger_spell_id); + SpellEntry const* triggerEntry = sSpellTemplate.LookupEntry(trigger_spell_id); if (!triggerEntry) { // Not cast unknown spell @@ -2797,7 +2797,7 @@ SpellAuraProcResult Unit::HandleOverrideClassScriptAuraProc(ProcExecutionData& d triggered_spell_id = 28750; // Blessing of the Claw break; case 5497: // Improved Mana Gems (Serpent-Coil Braid) - CastSpell(pVictim, 37445, TRIGGERED_NONE); // Mana Surge + CastSpell(pVictim, 37445, TRIGGERED_NONE); // Mana Surge return SPELL_AURA_PROC_OK; case 5510: // Flexibility - T4 Holy Priest bonus RemoveAurasDueToSpell(37565); diff --git a/src/game/Tools/CharacterDatabaseCleaner.cpp b/src/game/Tools/CharacterDatabaseCleaner.cpp index 93ad6a9519..b094b7e290 100644 --- a/src/game/Tools/CharacterDatabaseCleaner.cpp +++ b/src/game/Tools/CharacterDatabaseCleaner.cpp @@ -101,7 +101,7 @@ void CharacterDatabaseCleaner::CleanCharacterSkills() bool CharacterDatabaseCleaner::SpellCheck(uint32 spell_id) { - return !!sSpellTemplate.LookupEntry(spell_id); + return !!sSpellTemplate.LookupEntry(spell_id); } void CharacterDatabaseCleaner::CleanCharacterSpell() diff --git a/src/game/Tools/Formulas.h b/src/game/Tools/Formulas.h index de1e6eb05c..989f47c101 100644 --- a/src/game/Tools/Formulas.h +++ b/src/game/Tools/Formulas.h @@ -20,6 +20,7 @@ #define MANGOS_FORMULAS_H #include "World/World.h" +#include "Maps/Map.h" namespace MaNGOS { @@ -134,7 +135,7 @@ namespace MaNGOS if (target->IsTotem() || target->IsPet() || target->IsNoXp() || target->IsCritter()) return 0; - uint32 xp_gain = BaseGain(unit->getLevel(), target->getLevel(), GetContentLevelsForMapAndZone(unit->GetMapId(), unit->GetZoneId())); + uint32 xp_gain = BaseGain(unit->getLevel(), target->getLevel(), Map::GetContentLevelsForMapAndZone(unit->GetMapId(), unit->GetZoneId())); if (xp_gain == 0.0f) return 0; diff --git a/src/game/Trade/TradeHandler.cpp b/src/game/Trade/TradeHandler.cpp index fb126638c0..6aad533a1a 100644 --- a/src/game/Trade/TradeHandler.cpp +++ b/src/game/Trade/TradeHandler.cpp @@ -327,7 +327,7 @@ void WorldSession::HandleAcceptTradeOpcode(WorldPacket& recvPacket) // not accept if spell can't be casted now (cheating) if (uint32 my_spell_id = my_trade->GetSpell()) { - SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(my_spell_id); + SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(my_spell_id); Item* castItem = my_trade->GetSpellCastItem(); if (!spellEntry || !his_trade->GetItem(TRADE_SLOT_NONTRADED) || @@ -362,7 +362,7 @@ void WorldSession::HandleAcceptTradeOpcode(WorldPacket& recvPacket) // not accept if spell can't be casted now (cheating) if (uint32 his_spell_id = his_trade->GetSpell()) { - SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(his_spell_id); + SpellEntry const* spellEntry = sSpellTemplate.LookupEntry(his_spell_id); Item* castItem = his_trade->GetSpellCastItem(); if (!spellEntry || !my_trade->GetItem(TRADE_SLOT_NONTRADED) || diff --git a/src/game/World/World.cpp b/src/game/World/World.cpp index 37d07e0067..7122e2124a 100644 --- a/src/game/World/World.cpp +++ b/src/game/World/World.cpp @@ -891,10 +891,11 @@ void World::SetInitialWorldSettings() sLog.outString("Loading world safe locs ..."); sObjectMgr.LoadWorldSafeLocs(); - + ///- Load the DBC files sLog.outString("Initialize DBC data stores..."); - LoadDBCStores(m_dataPath); + LoadDBCTables(); + //LoadDBCStores(m_dataPath); DetectDBCLang(); sObjectMgr.SetDbc2StorageLocaleIndex(GetDefaultDbcLocale()); // Get once for all the locale index of DBC language (console/broadcasts) @@ -2623,3 +2624,22 @@ void World::GeneratePacketMetrics() meas_players.add_field("warlock", std::to_string(GetOnlineClassPlayers(CLASS_WARLOCK))); meas_players.add_field("druid", std::to_string(GetOnlineClassPlayers(CLASS_DRUID))); } + +bool World::IsAcceptableClientBuild(uint32 build) +{ + int accepted_versions[] = EXPECTED_MANGOSD_CLIENT_BUILD; + for (int i = 0; accepted_versions[i]; ++i) + if (int(build) == accepted_versions[i]) + return true; + + return false; +} + +std::string World::AcceptableClientBuildsListStr() +{ + std::ostringstream data; + int accepted_versions[] = EXPECTED_MANGOSD_CLIENT_BUILD; + for (int i = 0; accepted_versions[i]; ++i) + data << accepted_versions[i] << " "; + return data.str(); +} \ No newline at end of file diff --git a/src/game/World/World.h b/src/game/World/World.h index baad5e9d00..47cd9caf29 100644 --- a/src/game/World/World.h +++ b/src/game/World/World.h @@ -640,6 +640,10 @@ class World Messager& GetMessager() { return m_messager; } void IncrementOpcodeCounter(uint32 opcodeId); // thread safe due to atomics + + static bool IsAcceptableClientBuild(uint32 build); + static std::string AcceptableClientBuildsListStr(); + protected: void _UpdateGameTime(); // callback for UpdateRealmCharacters diff --git a/src/mangosd/Master.cpp b/src/mangosd/Master.cpp index 351e699115..7e23feac98 100644 --- a/src/mangosd/Master.cpp +++ b/src/mangosd/Master.cpp @@ -143,7 +143,7 @@ int Master::Run() // set realmbuilds depend on mangosd expected builds, and set server online { - std::string builds = AcceptableClientBuildsListStr(); + std::string builds = World::AcceptableClientBuildsListStr(); LoginDatabase.escape_string(builds); LoginDatabase.DirectPExecute("UPDATE realmlist SET realmflags = realmflags & ~(%u), population = 0, realmbuilds = '%s' WHERE id = '%u'", REALM_FLAG_OFFLINE, builds.c_str(), realmID); } diff --git a/src/shared/Database/DBCFileLoader.h b/src/shared/Database/DBCFileLoader.h index 3c013e70ca..17f18aa21a 100644 --- a/src/shared/Database/DBCFileLoader.h +++ b/src/shared/Database/DBCFileLoader.h @@ -25,6 +25,7 @@ enum FieldFormat { FT_NA = 'x', // ignore/ default, 4 byte size, in Source String means field is ignored, in Dest String means field is filled with default value + FT_NA2 = 'w', // ignore 4 byte size, in Source and in Dest String FT_NA_BYTE = 'X', // ignore/ default, 1 byte size, see above FT_NA_FLOAT = 'F', // ignore/ default, float size, see above FT_NA_POINTER = 'p', // fill default value into dest, pointer size, Use this only with static data (otherwise mem-leak) diff --git a/src/shared/Database/SQLStorage.cpp b/src/shared/Database/SQLStorage.cpp index 8fb6375f3f..16f0c882be 100644 --- a/src/shared/Database/SQLStorage.cpp +++ b/src/shared/Database/SQLStorage.cpp @@ -18,223 +18,4 @@ #include "SQLStorage.h" -// ----------------------------------- SQLStorageBase ---------------------------------------- // -SQLStorageBase::SQLStorageBase() : - m_tableName(nullptr), - m_entry_field(nullptr), - m_src_format(nullptr), - m_dst_format(nullptr), - m_dstFieldCount(0), - m_srcFieldCount(0), - m_recordCount(0), - m_maxEntry(0), - m_recordSize(0), - m_data(nullptr) -{} - -void SQLStorageBase::Initialize(const char* tableName, const char* entry_field, const char* src_format, const char* dst_format) -{ - m_tableName = tableName; - m_entry_field = entry_field; - m_src_format = src_format; - m_dst_format = dst_format; - - m_srcFieldCount = strlen(m_src_format); - m_dstFieldCount = strlen(m_dst_format); -} - -char* SQLStorageBase::createRecord(uint32 recordId) -{ - char* newRecord = &m_data[m_recordCount * m_recordSize]; - ++m_recordCount; - - JustCreatedRecord(recordId, newRecord); - return newRecord; -} - -void SQLStorageBase::prepareToLoad(uint32 maxEntry, uint32 recordCount, uint32 recordSize) -{ - m_maxEntry = maxEntry; - m_recordSize = recordSize; - - delete[] m_data; - m_data = new char[recordCount * m_recordSize]; - memset(m_data, 0, recordCount * m_recordSize); - - m_recordCount = 0; -} - -// Function to delete the data -void SQLStorageBase::Free() -{ - if (!m_data) - return; - - uint32 offset = 0; - for (uint32 x = 0; x < m_dstFieldCount; ++x) - { - switch (m_dst_format[x]) - { - case FT_LOGIC: - offset += sizeof(bool); - break; - case FT_STRING: - { - for (uint32 recordItr = 0; recordItr < m_recordCount; ++recordItr) - delete[] *(char**)((char*)(m_data + (recordItr * m_recordSize)) + offset); - - offset += sizeof(char*); - break; - } - case FT_NA: - case FT_INT: - offset += sizeof(uint32); - break; - case FT_BYTE: - case FT_NA_BYTE: - offset += sizeof(char); - break; - case FT_FLOAT: - case FT_NA_FLOAT: - offset += sizeof(float); - break; - case FT_NA_POINTER: - // TODO- possible (and small) memleak here possible - offset += sizeof(char*); - break; - case FT_64BITINT: - offset += sizeof(uint64); - break; - case FT_IND: - case FT_SORT: - assert(false && "SQL storage not have sort field types"); - break; - default: - assert(false && "unknown format character"); - break; - } - } - delete[] m_data; - m_data = nullptr; - m_recordCount = 0; -} - -// ----------------------------------- SQLStorage -------------------------------------------- // - -void SQLStorage::EraseEntry(uint32 id) -{ - m_Index[id] = nullptr; -} - -void SQLStorage::Free() -{ - SQLStorageBase::Free(); - delete[] m_Index; - m_Index = nullptr; -} - -void SQLStorage::Load(bool error_at_empty /*= true*/) -{ - SQLStorageLoader loader; - loader.Load(*this, error_at_empty); -} - -SQLStorage::SQLStorage(const char* fmt, const char* _entry_field, const char* sqlname) -{ - Initialize(sqlname, _entry_field, fmt, fmt); - m_Index = nullptr; -} - -SQLStorage::SQLStorage(const char* src_fmt, const char* dst_fmt, const char* _entry_field, const char* sqlname) -{ - Initialize(sqlname, _entry_field, src_fmt, dst_fmt); - m_Index = nullptr; -} - -void SQLStorage::prepareToLoad(uint32 maxRecordId, uint32 recordCount, uint32 recordSize) -{ - // Clear (possible) old data and old index array - Free(); - - // Set index array - m_Index = new char* [maxRecordId]; - memset(m_Index, 0, maxRecordId * sizeof(char*)); - - SQLStorageBase::prepareToLoad(maxRecordId, recordCount, recordSize); -} - -// ----------------------------------- SQLHashStorage ---------------------------------------- // -void SQLHashStorage::Load() -{ - SQLHashStorageLoader loader; - loader.Load(*this); -} - -void SQLHashStorage::Free() -{ - SQLStorageBase::Free(); - m_indexMap.clear(); -} - -void SQLHashStorage::prepareToLoad(uint32 maxRecordId, uint32 recordCount, uint32 recordSize) -{ - // Clear (possible) old data and old index array - Free(); - - SQLStorageBase::prepareToLoad(maxRecordId, recordCount, recordSize); -} - -void SQLHashStorage::EraseEntry(uint32 id) -{ - // do not erase from m_records - RecordMap::iterator find = m_indexMap.find(id); - if (find != m_indexMap.end()) - find->second = nullptr; -} - -SQLHashStorage::SQLHashStorage(const char* fmt, const char* _entry_field, const char* sqlname) -{ - Initialize(sqlname, _entry_field, fmt, fmt); -} - -SQLHashStorage::SQLHashStorage(const char* src_fmt, const char* dst_fmt, const char* _entry_field, const char* sqlname) -{ - Initialize(sqlname, _entry_field, src_fmt, dst_fmt); -} - -// ----------------------------------- SQLMultiStorage --------------------------------------- // -void SQLMultiStorage::Load() -{ - SQLMultiStorageLoader loader; - loader.Load(*this); -} - -void SQLMultiStorage::Free() -{ - SQLStorageBase::Free(); - m_indexMultiMap.clear(); -} - -void SQLMultiStorage::prepareToLoad(uint32 maxRecordId, uint32 recordCount, uint32 recordSize) -{ - // Clear (possible) old data and old index array - Free(); - - SQLStorageBase::prepareToLoad(maxRecordId, recordCount, recordSize); -} - -void SQLMultiStorage::EraseEntry(uint32 id) -{ - m_indexMultiMap.erase(id); -} - -SQLMultiStorage::SQLMultiStorage(const char* fmt, const char* _entry_field, const char* sqlname) -{ - Initialize(sqlname, _entry_field, fmt, fmt); -} - -SQLMultiStorage::SQLMultiStorage(const char* src_fmt, const char* dst_fmt, const char* _entry_field, const char* sqlname) -{ - Initialize(sqlname, _entry_field, src_fmt, dst_fmt); -} diff --git a/src/shared/Database/SQLStorage.h b/src/shared/Database/SQLStorage.h index 3ff15988b9..89107f7f06 100644 --- a/src/shared/Database/SQLStorage.h +++ b/src/shared/Database/SQLStorage.h @@ -23,6 +23,7 @@ #include "Database/DatabaseEnv.h" #include "DBCFileLoader.h" +template class SQLStorageBase { template friend class SQLStorageLoaderBase; @@ -37,9 +38,8 @@ class SQLStorageBase const char* GetSrcFormat() const { return m_src_format; }; uint32 GetMaxEntry() const { return m_maxEntry; }; - uint32 GetRecordCount() const { return m_recordCount; }; + uint32 GetNumRows() const { return m_recordCount; }; - template class SQLSIterator { friend class SQLStorageBase; @@ -50,6 +50,7 @@ class SQLStorageBase void operator ++() { pointer += recordSize; } T const* operator *() const { return getValue(); } T const* operator ->() const { return getValue(); } + bool operator!=(const SQLSIterator& other) const { return pointer != other.pointer; } bool operator <(const SQLSIterator& r) const { return pointer < r.pointer; } void operator =(const SQLSIterator& r) { pointer = r.pointer; recordSize = r.recordSize; } @@ -59,10 +60,8 @@ class SQLStorageBase uint32 recordSize; }; - template - SQLSIterator getDataBegin() const { return SQLSIterator(m_data, m_recordSize); } - template - SQLSIterator getDataEnd() const { return SQLSIterator(m_data + m_recordCount * m_recordSize, m_recordSize); } + SQLSIterator begin() const { return SQLSIterator(m_data, m_recordSize); } + SQLSIterator end() const { return SQLSIterator(m_data + static_cast(m_recordCount * m_recordSize), m_recordSize); } protected: SQLStorageBase(); @@ -98,23 +97,24 @@ class SQLStorageBase char* m_data; }; -class SQLStorage : public SQLStorageBase +template +class SQLStorage : public SQLStorageBase { template friend class SQLStorageLoaderBase; public: SQLStorage(const char* fmt, const char* _entry_field, const char* sqlname); + SQLStorage(const char* fmt, const char* sqlname); SQLStorage(const char* src_fmt, const char* dst_fmt, const char* _entry_field, const char* sqlname); ~SQLStorage() { Free(); } - template - T const* LookupEntry(uint32 id) const + ST const* LookupEntry(uint32 id) const { - if (id >= GetMaxEntry()) + if (id >= SQLStorageBase::GetMaxEntry()) return nullptr; - return reinterpret_cast(m_Index[id]); + return reinterpret_cast(m_Index[id]); } void Load(bool error_at_empty = true); @@ -135,7 +135,8 @@ class SQLStorage : public SQLStorageBase char** m_Index; }; -class SQLHashStorage : public SQLStorageBase +template +class SQLHashStorage : public SQLStorageBase { template friend class SQLStorageLoaderBase; @@ -145,7 +146,6 @@ class SQLHashStorage : public SQLStorageBase ~SQLHashStorage() { Free(); } - template T const* LookupEntry(uint32 id) const { RecordMap::const_iterator find = m_indexMap.find(id); @@ -172,11 +172,12 @@ class SQLHashStorage : public SQLStorageBase RecordMap m_indexMap; }; -class SQLMultiStorage : public SQLStorageBase +template +class SQLMultiStorage : public SQLStorageBase { template friend class SQLStorageLoaderBase; - template friend class SQLMultiSIterator; - template friend class SQLMSIteratorBounds; + friend class SQLMultiSIterator; + friend class SQLMSIteratorBounds; private: typedef std::multimap RecordMultiMap; @@ -188,13 +189,12 @@ class SQLMultiStorage : public SQLStorageBase ~SQLMultiStorage() { Free(); } // forward declaration - template class SQLMSIteratorBounds; + class SQLMSIteratorBounds; - template class SQLMultiSIterator { friend class SQLMultiStorage; - friend class SQLMSIteratorBounds; + friend class SQLMSIteratorBounds; public: T const* getValue() const { return reinterpret_cast(citerator->second); } @@ -211,21 +211,19 @@ class SQLMultiStorage : public SQLStorageBase RecordMultiMap::const_iterator citerator; }; - template class SQLMSIteratorBounds { friend class SQLMultiStorage; public: - const SQLMultiSIterator first; - const SQLMultiSIterator second; + const SQLMultiSIterator first; + const SQLMultiSIterator second; private: SQLMSIteratorBounds(std::pair pair) : first(pair.first), second(pair.second) {} }; - template - SQLMSIteratorBounds getBounds(uint32 key) const { return SQLMSIteratorBounds(m_indexMultiMap.equal_range(key)); } + SQLMSIteratorBounds getBounds(uint32 key) const { return SQLMSIteratorBounds(m_indexMultiMap.equal_range(key)); } void Load(); @@ -278,15 +276,18 @@ class SQLStorageLoaderBase void storeValue(char* value, StorageClass& store, char* record, uint32 field_pos, uint32& offset); }; -class SQLStorageLoader : public SQLStorageLoaderBase +template +class SQLStorageLoader : public SQLStorageLoaderBase, SQLStorage> { }; -class SQLHashStorageLoader : public SQLStorageLoaderBase +template +class SQLHashStorageLoader : public SQLStorageLoaderBase, SQLHashStorage> { }; -class SQLMultiStorageLoader : public SQLStorageLoaderBase +template +class SQLMultiStorageLoader : public SQLStorageLoaderBase, SQLMultiStorage> { }; diff --git a/src/shared/Database/SQLStorageImpl.h b/src/shared/Database/SQLStorageImpl.h index c9d4047b23..77206f1773 100644 --- a/src/shared/Database/SQLStorageImpl.h +++ b/src/shared/Database/SQLStorageImpl.h @@ -22,6 +22,7 @@ #include "ProgressBar.h" #include "Log.h" #include "DBCFileLoader.h" +#include template template // S source-type, D destination-type @@ -129,6 +130,7 @@ void SQLStorageLoaderBase::storeValue(V value, Stor offset += sizeof(char); break; case FT_INT: + case FT_IND: subclass->convert(x, value, *((uint32*)(&p[offset]))); offset += sizeof(uint32); break; @@ -156,9 +158,8 @@ void SQLStorageLoaderBase::storeValue(V value, Stor subclass->default_fill(x, value, *((uint64*)(&p[offset]))); offset += sizeof(uint64); break; - case FT_IND: case FT_SORT: - assert(false && "SQL storage not have sort field types"); + case FT_NA2: break; default: assert(false && "unknown format character"); @@ -181,6 +182,7 @@ void SQLStorageLoaderBase::storeValue(char const* v offset += sizeof(char); break; case FT_INT: + case FT_IND: subclass->convert_from_str(x, value, *((uint32*)(&p[offset]))); offset += sizeof(uint32); break; @@ -200,7 +202,6 @@ void SQLStorageLoaderBase::storeValue(char const* v subclass->convert_from_str(x, value, *((uint64*)(&p[offset]))); offset += sizeof(uint64); break; - case FT_IND: case FT_SORT: assert(false && "SQL storage not have sort field types"); break; @@ -213,8 +214,7 @@ void SQLStorageLoaderBase::storeValue(char const* v template void SQLStorageLoaderBase::Load(StorageClass& store, bool error_at_empty /*= true*/) { - Field* fields = nullptr; - QueryResult* result = WorldDatabase.PQuery("SELECT MAX(%s) FROM %s", store.EntryFieldName(), store.GetTableName()); + QueryResult* result = WorldDatabase.PQuery("SHOW COLUMNS FROM %s", store.GetTableName()); if (!result) { sLog.outError("Error loading %s table (not exist?)\n", store.GetTableName()); @@ -222,21 +222,95 @@ void SQLStorageLoaderBase::Load(StorageClass& store exit(1); // Stop server at loading non exited table or not accessable table } - uint32 maxRecordId = (*result)[0].GetUInt32() + 1; + std::vector colNameList; + colNameList.reserve(result->GetRowCount()); + do + { + Field* fields = result->Fetch(); + colNameList.push_back(fields[0].GetString()); + } while (result->NextRow()); + + delete result; + + int32 indexPos = -1; + std::string indexName = store.EntryFieldName(); + if (indexName.empty()) + { + for (int32 i = 0; i < int32(store.GetDstFieldCount()); ++i) + { + auto format = store.GetSrcFormat(i); + if (format == FT_IND || format == FT_SORT) + { + indexPos = i; + break; + } + } + + if (indexPos >= 0) + { + if (indexPos >= colNameList.size()) + { + sLog.outError("Error loading %s table, provided index position is greater than column number\n", store.GetTableName()); + Log::WaitBeforeContinueIfNeed(); + exit(1); + } + indexName = colNameList[indexPos]; + } + } + else + { + std::transform(indexName.begin(), indexName.end(), indexName.begin(), [](char c) { return std::tolower(c); }); + for (uint32 i = 0; i < colNameList.size(); ++i) + { + std::string colName = colNameList[i]; + std::transform(colName.begin(), colName.end(), colName.begin(), [](char c) { return std::tolower(c); }); + if (indexName == colName) + { + indexName = colNameList[i]; + indexPos = i; + break; + } + } + + if (indexPos < 0) + { + sLog.outError("Error loading %s table (Entry field is not found in column name list)\n", store.GetTableName()); + Log::WaitBeforeContinueIfNeed(); + exit(1); + } + } + + Field* fields = nullptr; + uint32 maxRecordId = 0; uint32 recordCount = 0; uint32 recordsize = 0; - delete result; result = WorldDatabase.PQuery("SELECT COUNT(*) FROM %s", store.GetTableName()); if (result) { - fields = result->Fetch(); - recordCount = fields[0].GetUInt32(); + recordCount = result[0][0].GetUInt32(); delete result; } - result = WorldDatabase.PQuery("SELECT * FROM %s", store.GetTableName()); + if (indexPos < 0) + { + maxRecordId = recordCount; + } + else + { + result = WorldDatabase.PQuery("SELECT MAX(%s) FROM %s", indexName.c_str(), store.GetTableName()); + if (!result) + { + sLog.outError("Error loading %s table (not exist?)\n", store.GetTableName()); + Log::WaitBeforeContinueIfNeed(); + exit(1); // Stop server at loading non exited table or not accessable table + } + + maxRecordId = (*result)[0].GetUInt32() + 1; + delete result; + } + result = WorldDatabase.PQuery("SELECT * FROM %s", store.GetTableName()); if (!result) { if (error_at_empty) @@ -245,6 +319,7 @@ void SQLStorageLoaderBase::Load(StorageClass& store sLog.outString("%s table is empty!\n", store.GetTableName()); recordCount = 0; + maxRecordId = 0; return; } @@ -268,6 +343,7 @@ void SQLStorageLoaderBase::Load(StorageClass& store case FT_BYTE: recordsize += sizeof(char); break; case FT_INT: + case FT_IND: recordsize += sizeof(uint32); break; case FT_FLOAT: recordsize += sizeof(float); break; @@ -283,9 +359,8 @@ void SQLStorageLoaderBase::Load(StorageClass& store recordsize += sizeof(char*); break; case FT_64BITINT: recordsize += sizeof(uint64); break; - case FT_IND: case FT_SORT: - assert(false && "SQL storage not have sort field types"); + case FT_NA2: break; default: assert(false && "unknown format character"); @@ -296,13 +371,20 @@ void SQLStorageLoaderBase::Load(StorageClass& store // Prepare data storage and lookup storage store.prepareToLoad(maxRecordId, recordCount, recordsize); + uint32 generatedId = 0; BarGoLink bar(recordCount); do { fields = result->Fetch(); bar.step(); - char* record = store.createRecord(fields[0].GetUInt32()); + uint32 id = 0; + if (indexPos < 0) + id = generatedId++; + else + id = fields[indexPos].GetUInt32(); + + char* record = store.createRecord(id); offset = 0; // dependend on dest-size @@ -330,17 +412,21 @@ void SQLStorageLoaderBase::Load(StorageClass& store { case FT_LOGIC: storeValue((bool)(fields[y].GetUInt32() > 0), store, record, x, offset); ++x; break; case FT_BYTE: storeValue((char)fields[y].GetUInt8(), store, record, x, offset); ++x; break; + case FT_IND: case FT_INT: storeValue((uint32)fields[y].GetUInt32(), store, record, x, offset); ++x; break; case FT_FLOAT: storeValue((float)fields[y].GetFloat(), store, record, x, offset); ++x; break; case FT_STRING: storeValue((char const*)fields[y].GetString(), store, record, x, offset); ++x; break; case FT_64BITINT: storeValue(fields[y].GetUInt64(), store, record, x, offset); ++x; break; + case FT_SORT: + case FT_NA2: + ++x; + break; + case FT_NA: case FT_NA_BYTE: case FT_NA_FLOAT: // Do Not increase x break; - case FT_IND: - case FT_SORT: case FT_NA_POINTER: assert(false && "SQL storage not have sort or pointer field types"); break; @@ -355,4 +441,254 @@ void SQLStorageLoaderBase::Load(StorageClass& store delete result; } + +// ----------------------------------- SQLStorage -------------------------------------------- // +template +void SQLStorage::EraseEntry(uint32 id) +{ + m_Index[id] = nullptr; +} + +template +void SQLStorage::Free() +{ + SQLStorageBase::Free(); + delete[] m_Index; + m_Index = nullptr; +} + +template +void SQLStorage::Load(bool error_at_empty /*= true*/) +{ + SQLStorageLoader loader; + loader.Load(*this, error_at_empty); +} + +template +SQLStorage::SQLStorage(const char* fmt, const char* sqlname) +{ + SQLStorage::Initialize(sqlname, "",fmt, fmt); + m_Index = nullptr; +} + +template +SQLStorage::SQLStorage(const char* fmt, const char* _entry_field, const char* sqlname) +{ + SQLStorage::Initialize(sqlname, _entry_field, fmt, fmt); + m_Index = nullptr; +} + +template +SQLStorage::SQLStorage(const char* src_fmt, const char* dst_fmt, const char* _entry_field, const char* sqlname) +{ + SQLStorage::Initialize(sqlname, _entry_field, src_fmt, dst_fmt); + m_Index = nullptr; +} + +template +void SQLStorage::prepareToLoad(uint32 maxRecordId, uint32 recordCount, uint32 recordSize) +{ + // Clear (possible) old data and old index array + Free(); + + // Set index array + m_Index = new char* [maxRecordId]; + memset(m_Index, 0, maxRecordId * sizeof(char*)); + + SQLStorageBase::prepareToLoad(maxRecordId, recordCount, recordSize); +} + +// ----------------------------------- SQLStorageBase ---------------------------------------- // +template +SQLStorageBase::SQLStorageBase() : + m_tableName(nullptr), + m_entry_field(nullptr), + m_src_format(nullptr), + m_dst_format(nullptr), + m_dstFieldCount(0), + m_srcFieldCount(0), + m_recordCount(0), + m_maxEntry(0), + m_recordSize(0), + m_data(nullptr) +{} + +template +void SQLStorageBase::Initialize(const char* tableName, const char* entry_field, const char* src_format, const char* dst_format) +{ + m_tableName = tableName; + m_entry_field = entry_field; + m_src_format = src_format; + m_dst_format = dst_format; + + m_srcFieldCount = strlen(m_src_format); + m_dstFieldCount = strlen(m_dst_format); +} + +template +char* SQLStorageBase::createRecord(uint32 recordId) +{ + char* newRecord = &m_data[m_recordCount * m_recordSize]; + ++m_recordCount; + + JustCreatedRecord(recordId, newRecord); + return newRecord; +} + +template +void SQLStorageBase::prepareToLoad(uint32 maxEntry, uint32 recordCount, uint32 recordSize) +{ + m_maxEntry = maxEntry; + m_recordSize = recordSize; + + delete[] m_data; + m_data = new char[recordCount * m_recordSize]; + memset(m_data, 0, recordCount * m_recordSize); + + m_recordCount = 0; +} + +// Function to delete the data +template +void SQLStorageBase::Free() +{ + if (!m_data) + return; + + uint32 offset = 0; + for (uint32 x = 0; x < m_dstFieldCount; ++x) + { + switch (m_dst_format[x]) + { + case FT_LOGIC: + offset += sizeof(bool); + break; + case FT_STRING: + { + for (uint32 recordItr = 0; recordItr < m_recordCount; ++recordItr) + delete[] * (char**)((char*)(m_data + (recordItr * m_recordSize)) + offset); + + offset += sizeof(char*); + break; + } + case FT_NA: + case FT_IND: + case FT_INT: + offset += sizeof(uint32); + break; + case FT_BYTE: + case FT_NA_BYTE: + offset += sizeof(char); + break; + case FT_FLOAT: + case FT_NA_FLOAT: + offset += sizeof(float); + break; + case FT_NA_POINTER: + // TODO- possible (and small) memleak here possible + offset += sizeof(char*); + break; + case FT_64BITINT: + offset += sizeof(uint64); + break; + case FT_SORT: + break; + default: + assert(false && "unknown format character"); + break; + } + } + delete[] m_data; + m_data = nullptr; + m_recordCount = 0; +} + +// ----------------------------------- SQLHashStorage ---------------------------------------- // +template +void SQLHashStorage::Load() +{ + SQLHashStorageLoader loader; + loader.Load(*this); +} + +template +void SQLHashStorage::Free() +{ + SQLStorageBase::Free(); + m_indexMap.clear(); +} + +template +void SQLHashStorage::prepareToLoad(uint32 maxRecordId, uint32 recordCount, uint32 recordSize) +{ + // Clear (possible) old data and old index array + Free(); + + SQLStorageBase::prepareToLoad(maxRecordId, recordCount, recordSize); +} + +template +void SQLHashStorage::EraseEntry(uint32 id) +{ + // do not erase from m_records + RecordMap::iterator find = m_indexMap.find(id); + if (find != m_indexMap.end()) + find->second = nullptr; +} + +template +SQLHashStorage::SQLHashStorage(const char* fmt, const char* _entry_field, const char* sqlname) +{ + SQLHashStorage::Initialize(sqlname, _entry_field, fmt, fmt); +} + +template +SQLHashStorage::SQLHashStorage(const char* src_fmt, const char* dst_fmt, const char* _entry_field, const char* sqlname) +{ + SQLHashStorage::Initialize(sqlname, _entry_field, src_fmt, dst_fmt); +} + +// ----------------------------------- SQLMultiStorage --------------------------------------- // +template +void SQLMultiStorage::Load() +{ + SQLMultiStorageLoader loader; + loader.Load(*this); +} + +template +void SQLMultiStorage::Free() +{ + SQLStorageBase::Free(); + m_indexMultiMap.clear(); +} + +template +void SQLMultiStorage::prepareToLoad(uint32 maxRecordId, uint32 recordCount, uint32 recordSize) +{ + // Clear (possible) old data and old index array + Free(); + + SQLStorageBase::prepareToLoad(maxRecordId, recordCount, recordSize); +} + +template +void SQLMultiStorage::EraseEntry(uint32 id) +{ + m_indexMultiMap.erase(id); +} + +template +SQLMultiStorage::SQLMultiStorage(const char* fmt, const char* _entry_field, const char* sqlname) +{ + SQLMultiStorage::Initialize(sqlname, _entry_field, fmt, fmt); +} + +template +SQLMultiStorage::SQLMultiStorage(const char* src_fmt, const char* dst_fmt, const char* _entry_field, const char* sqlname) +{ + SQLMultiStorage::Initialize(sqlname, _entry_field, src_fmt, dst_fmt); +} + + #endif