@@ -355,6 +355,11 @@ SpellTargetPosition const* SpellMgr::GetSpellTargetPosition(uint32 spell_id, Spe
355355 return nullptr ;
356356}
357357
358+ Trinity::IteratorPair<SpellTargetPositionMap::const_iterator> SpellMgr::GetSpellTargetPositions (uint32 spell_id, SpellEffIndex effIndex) const
359+ {
360+ return Trinity::Containers::MapEqualRange (mSpellTargetPositions , { spell_id, effIndex });
361+ }
362+
358363SpellSpellGroupMapBounds SpellMgr::GetSpellSpellGroupMapBounds (uint32 spell_id) const
359364{
360365 spell_id = GetFirstSpellInChain (spell_id);
@@ -1156,23 +1161,22 @@ void SpellMgr::LoadSpellTargetPositions()
11561161
11571162 mSpellTargetPositions .clear (); // need for reload case
11581163
1159- // 0 1 2 3 4 5 6
1160- QueryResult result = WorldDatabase.Query (" SELECT ID, EffectIndex, MapID, PositionX, PositionY, PositionZ, Orientation FROM spell_target_position" );
1164+ // 0 1 2 3 4 5 6 7
1165+ QueryResult result = WorldDatabase.Query (" SELECT ID, EffectIndex, OrderIndex, MapID, PositionX, PositionY, PositionZ, Orientation FROM spell_target_position" );
11611166 if (!result)
11621167 {
11631168 TC_LOG_INFO (" server.loading" , " >> Loaded 0 spell target coordinates. DB table `spell_target_position` is empty." );
11641169 return ;
11651170 }
11661171
1167- uint32 count = 0 ;
11681172 do
11691173 {
11701174 Field* fields = result->Fetch ();
11711175
11721176 uint32 spellId = fields[0 ].GetUInt32 ();
11731177 SpellEffIndex effIndex = SpellEffIndex (fields[1 ].GetUInt8 ());
11741178
1175- SpellTargetPosition st (fields[2 ].GetUInt16 (), fields[3 ].GetFloat (), fields[4 ].GetFloat (), fields[5 ].GetFloat ());
1179+ SpellTargetPosition st (fields[3 ].GetUInt16 (), fields[4 ].GetFloat (), fields[5 ].GetFloat (), fields[6 ].GetFloat ());
11761180
11771181 MapEntry const * mapEntry = sMapStore .LookupEntry (st.GetMapId ());
11781182 if (!mapEntry)
@@ -1200,61 +1204,62 @@ void SpellMgr::LoadSpellTargetPositions()
12001204 continue ;
12011205 }
12021206
1203- if (!fields[6 ].IsNull ())
1204- st.SetOrientation (fields[6 ].GetFloat ());
1207+ SpellEffectInfo const & spellEffectInfo = spellInfo->GetEffect (effIndex);
1208+ if (!fields[7 ].IsNull ())
1209+ st.SetOrientation (fields[7 ].GetFloat ());
12051210 else
12061211 {
12071212 // target facing is in degrees for 6484 & 9268...
1208- if (spellInfo-> GetEffect (effIndex) .PositionFacing > 2 * float (M_PI))
1209- st.SetOrientation (spellInfo-> GetEffect (effIndex) .PositionFacing * float (M_PI) / 180 );
1213+ if (spellEffectInfo .PositionFacing > 2 * float (M_PI))
1214+ st.SetOrientation (spellEffectInfo .PositionFacing * float (M_PI) / 180 );
12101215 else
1211- st.SetOrientation (spellInfo-> GetEffect (effIndex) .PositionFacing );
1216+ st.SetOrientation (spellEffectInfo .PositionFacing );
12121217 }
12131218
12141219 auto hasTarget = [&](Targets target)
12151220 {
1216- SpellEffectInfo const & spellEffectInfo = spellInfo->GetEffect (effIndex);
12171221 return spellEffectInfo.TargetA .GetTarget () == target || spellEffectInfo.TargetB .GetTarget () == target;
12181222 };
12191223
1220- if (hasTarget (TARGET_DEST_DB) || hasTarget (TARGET_DEST_NEARBY_ENTRY_OR_DB))
1221- {
1222- std::pair<uint32, SpellEffIndex> key = std::make_pair (spellId, effIndex);
1223- mSpellTargetPositions [key] = st;
1224- ++count;
1225- }
1226- else
1224+ if (!hasTarget (TARGET_DEST_NEARBY_DB))
12271225 {
1228- TC_LOG_ERROR (" sql.sql" , " Spell (Id: {}, effIndex: {}) listed in `spell_target_position` does not have a target TARGET_DEST_DB (17)." , spellId, uint32 (effIndex));
1229- continue ;
1226+ if (!hasTarget (TARGET_DEST_DB) && !hasTarget (TARGET_DEST_NEARBY_ENTRY_OR_DB))
1227+ {
1228+ TC_LOG_ERROR (" sql.sql" , " Spell (Id: {}, effIndex: {}) listed in `spell_target_position` does not have a target TARGET_DEST_DB ({}) or TARGET_DEST_NEARBY_DB ({}) or TARGET_DEST_NEARBY_ENTRY_OR_DB ({})." ,
1229+ spellId, uint32 (effIndex), TARGET_DEST_DB, TARGET_DEST_NEARBY_DB, TARGET_DEST_NEARBY_ENTRY_OR_DB);
1230+ continue ;
1231+ }
1232+ if (fields[2 ].GetInt32 () != 0 )
1233+ {
1234+ TC_LOG_ERROR (" sql.sql" , " Spell (Id: {}, effIndex: {}) listed in `spell_target_position` does not have a target TARGET_DEST_NEARBY_DB ({}) but lists multiple points, only one is allowed." ,
1235+ spellId, uint32 (effIndex), TARGET_DEST_NEARBY_DB);
1236+ continue ;
1237+ }
12301238 }
12311239
1240+ mSpellTargetPositions .emplace (std::make_pair (spellId, effIndex), st);
1241+
12321242 } while (result->NextRow ());
12331243
12341244 /*
12351245 // Check all spells
1236- for (uint32 i = 1; i < GetSpellInfoStoreSize(); ++i )
1246+ for (SpellInfo const& spellInfo : mSpellInfoMap )
12371247 {
1238- SpellInfo const* spellInfo = GetSpellInfo(i);
1239- if (!spellInfo)
1248+ if (spellInfo.Difficulty != DIFFICULTY_NONE)
12401249 continue;
12411250
1242- for (uint8 j = 0; j < MAX_SPELL_EFFECTS; ++j )
1251+ for (SpellEffectInfo const& effect : spellInfo.GetEffects() )
12431252 {
1244- SpellEffectInfo const* effect = spellInfo->GetEffect(j);
1245- if (!effect)
1246- continue;
1247-
1248- if (effect->TargetA.GetTarget() != TARGET_DEST_DB && effect->TargetB.GetTarget() != TARGET_DEST_DB)
1253+ if (effect.TargetA.GetTarget() != TARGET_DEST_DB && effect.TargetB.GetTarget() != TARGET_DEST_DB)
12491254 continue;
12501255
1251- if (!GetSpellTargetPosition(i, SpellEffIndex(j) ))
1252- TC_LOG_DEBUG("spells", "Spell (Id: {}, EffectIndex: {}) does not have record in `spell_target_position`.", i, j );
1256+ if (!GetSpellTargetPosition(spellInfo.Id, effect.EffectIndex ))
1257+ TC_LOG_DEBUG("spells", "Spell (Id: {}, EffectIndex: {}) does not have record in `spell_target_position`.", spellInfo.Id, effect.EffectIndex );
12531258 }
12541259 }
12551260 */
12561261
1257- TC_LOG_INFO (" server.loading" , " >> Loaded {} spell teleport coordinates in {} ms" , count , GetMSTimeDiffToNow (oldMSTime));
1262+ TC_LOG_INFO (" server.loading" , " >> Loaded {} spell teleport coordinates in {} ms" , mSpellTargetPositions . size () , GetMSTimeDiffToNow (oldMSTime));
12581263}
12591264
12601265void SpellMgr::LoadSpellGroups ()
0 commit comments