diff --git a/Source/Game/Entities/Object/WorldObject.cs b/Source/Game/Entities/Object/WorldObject.cs index 7b89f3743..9ec1dd507 100644 --- a/Source/Game/Entities/Object/WorldObject.cs +++ b/Source/Game/Entities/Object/WorldObject.cs @@ -3223,7 +3223,7 @@ namespace Game.Entities public float GetTransOffsetY() { return m_movementInfo.transport.pos.GetPositionY(); } public float GetTransOffsetZ() { return m_movementInfo.transport.pos.GetPositionZ(); } public float GetTransOffsetO() { return m_movementInfo.transport.pos.GetOrientation(); } - Position GetTransOffset() { return m_movementInfo.transport.pos; } + public Position GetTransOffset() { return m_movementInfo.transport.pos; } public uint GetTransTime() { return m_movementInfo.transport.time; } public sbyte GetTransSeat() { return m_movementInfo.transport.seat; } public virtual ObjectGuid GetTransGUID() diff --git a/Source/Game/Spells/Spell.cs b/Source/Game/Spells/Spell.cs index bc3ecf187..dbf2d19f3 100644 --- a/Source/Game/Spells/Spell.cs +++ b/Source/Game/Spells/Spell.cs @@ -654,12 +654,12 @@ namespace Game.Spells } if (targetType.GetTarget() == Targets.DestNearbyEntryOrDB) { - SpellTargetPosition st = Global.SpellMgr.GetSpellTargetPosition(m_spellInfo.Id, spellEffectInfo.EffectIndex); + WorldLocation st = Global.SpellMgr.GetSpellTargetPosition(m_spellInfo.Id, spellEffectInfo.EffectIndex); if (st != null) { SpellDestination dest = new(m_caster); - if (st.target_mapId == m_caster.GetMapId() && m_caster.IsInDist(st.target_X, st.target_Y, st.target_Z, range)) - dest = new SpellDestination(st.target_X, st.target_Y, st.target_Z, st.target_Orientation); + if (st.GetMapId() == m_caster.GetMapId() && m_caster.IsInDist(st, range)) + dest = new(st.GetPosition()); else { float randomRadius1 = spellEffectInfo.CalcRadius(m_caster, targetIndex); @@ -1012,14 +1012,14 @@ namespace Game.Spells dest = new SpellDestination(playerCaster.GetHomebind()); break; case Targets.DestDb: - SpellTargetPosition st = Global.SpellMgr.GetSpellTargetPosition(m_spellInfo.Id, spellEffectInfo.EffectIndex); + WorldLocation st = Global.SpellMgr.GetSpellTargetPosition(m_spellInfo.Id, spellEffectInfo.EffectIndex); if (st != null) { // @todo fix this check - if (m_spellInfo.HasEffect(SpellEffectName.TeleportUnits) || m_spellInfo.HasEffect(SpellEffectName.TeleportWithSpellVisualKitLoadingScreen) || m_spellInfo.HasEffect(SpellEffectName.Bind)) - dest = new SpellDestination(st.target_X, st.target_Y, st.target_Z, st.target_Orientation, st.target_mapId); - else if (st.target_mapId == m_caster.GetMapId()) - dest = new SpellDestination(st.target_X, st.target_Y, st.target_Z, st.target_Orientation); + if (spellEffectInfo.IsEffect(SpellEffectName.TeleportUnits) || spellEffectInfo.IsEffect(SpellEffectName.TeleportWithSpellVisualKitLoadingScreen) || spellEffectInfo.IsEffect(SpellEffectName.Bind)) + dest = new(st); + else if (st.GetMapId() == m_caster.GetMapId()) + dest = new(st.GetPosition()); } else { @@ -8763,38 +8763,28 @@ namespace Game.Spells public class SpellDestination { - public SpellDestination() + public SpellDestination() { } + + public SpellDestination(float x, float y, float z, float orientation = 0.0f, uint mapId = 0xFFFFFFFF) { - Position = new WorldLocation(); - TransportGUID = ObjectGuid.Empty; - TransportOffset = new Position(); + Position = new(mapId, x, y, z, orientation); } - public SpellDestination(float x, float y, float z, float orientation = 0.0f, uint mapId = 0xFFFFFFFF) : this() + public SpellDestination(Position pos) { - Position.Relocate(x, y, z, orientation); - TransportGUID = ObjectGuid.Empty; - Position.SetMapId(mapId); + Position = new(0xFFFFFFFF, pos); } - public SpellDestination(Position pos) : this() + public SpellDestination(WorldLocation loc) { - Position.Relocate(pos); - TransportGUID = ObjectGuid.Empty; + Position = loc; } - public SpellDestination(WorldLocation loc) : this() + public SpellDestination(WorldObject obj) { - Position.WorldRelocate(loc); - TransportGUID.Clear(); - TransportOffset.Relocate(0, 0, 0, 0); - } - - public SpellDestination(WorldObject wObj) : this() - { - TransportGUID = wObj.GetTransGUID(); - TransportOffset.Relocate(wObj.GetTransOffsetX(), wObj.GetTransOffsetY(), wObj.GetTransOffsetZ(), wObj.GetTransOffsetO()); - Position.Relocate(wObj.GetPosition()); + Position = new(obj.GetMapId(), obj); + TransportGUID = obj.GetTransGUID(); + TransportOffset = obj.GetTransOffset(); } public void Relocate(Position pos) diff --git a/Source/Game/Spells/SpellManager.cs b/Source/Game/Spells/SpellManager.cs index 98c568201..bfe55e3c8 100644 --- a/Source/Game/Spells/SpellManager.cs +++ b/Source/Game/Spells/SpellManager.cs @@ -294,7 +294,7 @@ namespace Game.Entities return mSpellLearnedBySpells.LookupByKey(learnedSpellId); } - public SpellTargetPosition GetSpellTargetPosition(uint spell_id, uint effIndex) + public WorldLocation GetSpellTargetPosition(uint spell_id, uint effIndex) { return mSpellTargetPositions.LookupByKey(new KeyValuePair(spell_id, effIndex)); } @@ -1020,20 +1020,16 @@ namespace Game.Entities uint spellId = result.Read(0); uint effIndex = result.Read(1); - SpellTargetPosition st = new(); - st.target_mapId = result.Read(2); - st.target_X = result.Read(3); - st.target_Y = result.Read(4); - st.target_Z = result.Read(5); + WorldLocation st = new(result.Read(2), result.Read(3), result.Read(4), result.Read(5)); - var mapEntry = CliDB.MapStorage.LookupByKey(st.target_mapId); + var mapEntry = CliDB.MapStorage.LookupByKey(st.GetMapId()); if (mapEntry == null) { - Log.outError(LogFilter.Sql, "Spell (ID: {0}, EffectIndex: {1}) is using a non-existant MapID (ID: {2})", spellId, effIndex, st.target_mapId); + Log.outError(LogFilter.Sql, "Spell (ID: {0}, EffectIndex: {1}) is using a non-existant MapID (ID: {2})", spellId, effIndex, st.GetMapId()); continue; } - if (st.target_X == 0 && st.target_Y == 0 && st.target_Z == 0) + if (st.GetPositionX() == 0 && st.GetPositionY() == 0 && st.GetPositionZ() == 0) { Log.outError(LogFilter.Sql, "Spell (ID: {0}, EffectIndex: {1}) target coordinates not provided.", spellId, effIndex); continue; @@ -1053,14 +1049,14 @@ namespace Game.Entities } if (!result.IsNull(6)) - st.target_Orientation = result.Read(6); + st.SetOrientation(result.Read(6)); else { - // target facing is in degrees for 6484 & 9268... (blizz sucks) + // target facing is in degrees for 6484 & 9268... if (spellInfo.GetEffect(effIndex).PositionFacing > 2 * MathF.PI) - st.target_Orientation = spellInfo.GetEffect(effIndex).PositionFacing * MathF.PI / 180; + st.SetOrientation(spellInfo.GetEffect(effIndex).PositionFacing * MathF.PI / 180); else - st.target_Orientation = spellInfo.GetEffect(effIndex).PositionFacing; + st.SetOrientation(spellInfo.GetEffect(effIndex).PositionFacing); } bool hasTarget(Targets target) @@ -1071,8 +1067,7 @@ namespace Game.Entities if (hasTarget(Targets.DestDb) || hasTarget(Targets.DestNearbyEntryOrDB)) { - var key = new KeyValuePair(spellId, effIndex); - mSpellTargetPositions[key] = st; + mSpellTargetPositions[(spellId, effIndex)] = st; ++count; } else @@ -4947,7 +4942,7 @@ namespace Game.Entities Dictionary mSpellLearnSkills = new(); MultiMap mSpellLearnSpells = new(); MultiMap mSpellLearnedBySpells = new(); - Dictionary, SpellTargetPosition> mSpellTargetPositions = new(); + Dictionary<(uint, uint), WorldLocation> mSpellTargetPositions = new(); MultiMap mSpellSpellGroup = new(); MultiMap mSpellGroupSpell = new(); Dictionary mSpellGroupStack = new(); @@ -5226,15 +5221,6 @@ namespace Game.Entities public EnchantProcAttributes AttributesMask; // bitmask, see EnchantProcAttributes } - public class SpellTargetPosition - { - public uint target_mapId; - public float target_X; - public float target_Y; - public float target_Z; - public float target_Orientation; - } - public class CreatureImmunities { public BitSet School = new((int)SpellSchools.Max);