Core/Spells: Fixed target radius logic in spell effects for TargetB

Port From (https://github.com/TrinityCore/TrinityCore/commit/889e88ab8033a78db837e0bb8619d8ce9d64967f)
This commit is contained in:
hondacrx
2023-09-04 07:19:38 -04:00
parent 34ce07f880
commit 8bf185f071
6 changed files with 73 additions and 70 deletions
@@ -2962,4 +2962,10 @@ namespace Framework.Constants
ForcedDismount = 9,
Ok = 10 // never sent
}
public enum SpellTargetIndex
{
TargetA = 0,
TargetB = 1
}
}
+30 -29
View File
@@ -243,8 +243,8 @@ namespace Game.Spells
if (Convert.ToBoolean(implicitTargetMask & (SpellCastTargetFlags.Gameobject | SpellCastTargetFlags.GameobjectItem)))
m_targets.SetTargetFlag(SpellCastTargetFlags.Gameobject);
SelectEffectImplicitTargets(spellEffectInfo, spellEffectInfo.TargetA, ref processedAreaEffectsMask);
SelectEffectImplicitTargets(spellEffectInfo, spellEffectInfo.TargetB, ref processedAreaEffectsMask);
SelectEffectImplicitTargets(spellEffectInfo, spellEffectInfo.TargetA, SpellTargetIndex.TargetA, ref processedAreaEffectsMask);
SelectEffectImplicitTargets(spellEffectInfo, spellEffectInfo.TargetB, SpellTargetIndex.TargetB, ref processedAreaEffectsMask);
// Select targets of effect based on effect type
// those are used when no valid target could be added for spell effect based on spell target type
@@ -370,7 +370,7 @@ namespace Game.Spells
m_caster.m_Events.ModifyEventTime(_spellEvent, TimeSpan.FromMilliseconds(GetDelayStart() + m_delayMoment));
}
void SelectEffectImplicitTargets(SpellEffectInfo spellEffectInfo, SpellImplicitTargetInfo targetType, ref uint processedEffectMask)
void SelectEffectImplicitTargets(SpellEffectInfo spellEffectInfo, SpellImplicitTargetInfo targetType, SpellTargetIndex targetIndex, ref uint processedEffectMask)
{
if (targetType.GetTarget() == 0)
return;
@@ -397,7 +397,8 @@ namespace Game.Spells
spellEffectInfo.TargetA.GetTarget() == effects[j].TargetA.GetTarget() &&
spellEffectInfo.TargetB.GetTarget() == effects[j].TargetB.GetTarget() &&
spellEffectInfo.ImplicitTargetConditions == effects[j].ImplicitTargetConditions &&
spellEffectInfo.CalcRadius(m_caster) == effects[j].CalcRadius(m_caster) &&
spellEffectInfo.CalcRadius(m_caster, SpellTargetIndex.TargetA) == effects[j].CalcRadius(m_caster, SpellTargetIndex.TargetA) &&
spellEffectInfo.CalcRadius(m_caster, SpellTargetIndex.TargetB) == effects[j].CalcRadius(m_caster, SpellTargetIndex.TargetB) &&
CheckScriptEffectImplicitTargets(spellEffectInfo.EffectIndex, (uint)j))
{
effectMask |= 1u << j;
@@ -416,13 +417,13 @@ namespace Game.Spells
SelectImplicitChannelTargets(spellEffectInfo, targetType);
break;
case SpellTargetSelectionCategories.Nearby:
SelectImplicitNearbyTargets(spellEffectInfo, targetType, effectMask);
SelectImplicitNearbyTargets(spellEffectInfo, targetType, targetIndex, effectMask);
break;
case SpellTargetSelectionCategories.Cone:
SelectImplicitConeTargets(spellEffectInfo, targetType, effectMask);
SelectImplicitConeTargets(spellEffectInfo, targetType, targetIndex, effectMask);
break;
case SpellTargetSelectionCategories.Area:
SelectImplicitAreaTargets(spellEffectInfo, targetType, effectMask);
SelectImplicitAreaTargets(spellEffectInfo, targetType, targetIndex, effectMask);
break;
case SpellTargetSelectionCategories.Traj:
// just in case there is no dest, explanation in SelectImplicitDestDestTargets
@@ -431,7 +432,7 @@ namespace Game.Spells
SelectImplicitTrajTargets(spellEffectInfo, targetType);
break;
case SpellTargetSelectionCategories.Line:
SelectImplicitLineTargets(spellEffectInfo, targetType, effectMask);
SelectImplicitLineTargets(spellEffectInfo, targetType, targetIndex, effectMask);
break;
case SpellTargetSelectionCategories.Default:
switch (targetType.GetObjectType())
@@ -451,13 +452,13 @@ namespace Game.Spells
switch (targetType.GetReferenceType())
{
case SpellTargetReferenceTypes.Caster:
SelectImplicitCasterDestTargets(spellEffectInfo, targetType);
SelectImplicitCasterDestTargets(spellEffectInfo, targetType, targetIndex);
break;
case SpellTargetReferenceTypes.Target:
SelectImplicitTargetDestTargets(spellEffectInfo, targetType);
SelectImplicitTargetDestTargets(spellEffectInfo, targetType, targetIndex);
break;
case SpellTargetReferenceTypes.Dest:
SelectImplicitDestDestTargets(spellEffectInfo, targetType);
SelectImplicitDestDestTargets(spellEffectInfo, targetType, targetIndex);
break;
default:
Cypher.Assert(false, "Spell.SelectEffectImplicitTargets: received not implemented select target reference type for TARGET_TYPE_OBJECT_DEST");
@@ -563,7 +564,7 @@ namespace Game.Spells
}
}
void SelectImplicitNearbyTargets(SpellEffectInfo spellEffectInfo, SpellImplicitTargetInfo targetType, uint effMask)
void SelectImplicitNearbyTargets(SpellEffectInfo spellEffectInfo, SpellImplicitTargetInfo targetType, SpellTargetIndex targetIndex, uint effMask)
{
if (targetType.GetReferenceType() != SpellTargetReferenceTypes.Caster)
{
@@ -642,7 +643,7 @@ namespace Game.Spells
dest = new SpellDestination(st.target_X, st.target_Y, st.target_Z, st.target_Orientation);
else
{
float randomRadius1 = spellEffectInfo.CalcRadius(m_caster);
float randomRadius1 = spellEffectInfo.CalcRadius(m_caster, targetIndex);
if (randomRadius1 > 0.0f)
m_caster.MovePositionToFirstCollision(dest.Position, randomRadius1, targetType.CalcDirectionAngle());
}
@@ -668,7 +669,7 @@ namespace Game.Spells
{
target = m_caster;
// radius is only meant to be randomized when using caster fallback
randomRadius = spellEffectInfo.CalcRadius(m_caster);
randomRadius = spellEffectInfo.CalcRadius(m_caster, targetIndex);
}
break;
default:
@@ -749,7 +750,7 @@ namespace Game.Spells
SelectImplicitChainTargets(spellEffectInfo, targetType, target, effMask);
}
void SelectImplicitConeTargets(SpellEffectInfo spellEffectInfo, SpellImplicitTargetInfo targetType, uint effMask)
void SelectImplicitConeTargets(SpellEffectInfo spellEffectInfo, SpellImplicitTargetInfo targetType, SpellTargetIndex targetIndex, uint effMask)
{
Position coneSrc = new(m_caster);
float coneAngle = m_spellInfo.ConeAngle;
@@ -780,7 +781,7 @@ namespace Game.Spells
SpellTargetCheckTypes selectionType = targetType.GetCheckType();
var condList = spellEffectInfo.ImplicitTargetConditions;
float radius = spellEffectInfo.CalcRadius(m_caster) * m_spellValue.RadiusMod;
float radius = spellEffectInfo.CalcRadius(m_caster, targetIndex) * m_spellValue.RadiusMod;
GridMapTypeMask containerTypeMask = GetSearcherTypeMask(objectType, condList);
if (containerTypeMask != 0)
@@ -812,7 +813,7 @@ namespace Game.Spells
}
}
void SelectImplicitAreaTargets(SpellEffectInfo spellEffectInfo, SpellImplicitTargetInfo targetType, uint effMask)
void SelectImplicitAreaTargets(SpellEffectInfo spellEffectInfo, SpellImplicitTargetInfo targetType, SpellTargetIndex targetIndex, uint effMask)
{
WorldObject referer;
switch (targetType.GetReferenceType())
@@ -866,7 +867,7 @@ namespace Game.Spells
return;
}
float radius = spellEffectInfo.CalcRadius(m_caster) * m_spellValue.RadiusMod;
float radius = spellEffectInfo.CalcRadius(m_caster, targetIndex) * m_spellValue.RadiusMod;
List<WorldObject> targets = new();
switch (targetType.GetTarget())
{
@@ -944,7 +945,7 @@ namespace Game.Spells
}
}
void SelectImplicitCasterDestTargets(SpellEffectInfo spellEffectInfo, SpellImplicitTargetInfo targetType)
void SelectImplicitCasterDestTargets(SpellEffectInfo spellEffectInfo, SpellImplicitTargetInfo targetType, SpellTargetIndex targetIndex)
{
SpellDestination dest = new(m_caster);
@@ -1016,7 +1017,7 @@ namespace Game.Spells
if (unitCaster == null)
break;
float dist = spellEffectInfo.CalcRadius(unitCaster);
float dist = spellEffectInfo.CalcRadius(unitCaster, targetIndex);
float angle = targetType.CalcDirectionAngle();
if (targetType.GetTarget() == Targets.DestCasterMovementDirection)
{
@@ -1087,7 +1088,7 @@ namespace Game.Spells
}
default:
{
float dist = spellEffectInfo.CalcRadius(m_caster);
float dist = spellEffectInfo.CalcRadius(m_caster, targetIndex);
float angl = targetType.CalcDirectionAngle();
float objSize = m_caster.GetCombatReach();
@@ -1106,7 +1107,7 @@ namespace Game.Spells
case Targets.DestCasterBackRight:
{
float DefaultTotemDistance = 3.0f;
if (!spellEffectInfo.HasRadius() && !spellEffectInfo.HasMaxRadius())
if (!spellEffectInfo.HasRadius(targetIndex))
dist = DefaultTotemDistance;
break;
}
@@ -1132,7 +1133,7 @@ namespace Game.Spells
m_targets.SetDst(dest);
}
void SelectImplicitTargetDestTargets(SpellEffectInfo spellEffectInfo, SpellImplicitTargetInfo targetType)
void SelectImplicitTargetDestTargets(SpellEffectInfo spellEffectInfo, SpellImplicitTargetInfo targetType, SpellTargetIndex targetIndex)
{
WorldObject target = m_targets.GetObjectTarget();
@@ -1147,7 +1148,7 @@ namespace Game.Spells
default:
{
float angle = targetType.CalcDirectionAngle();
float dist = spellEffectInfo.CalcRadius(null);
float dist = spellEffectInfo.CalcRadius(null, targetIndex);
if (targetType.GetTarget() == Targets.DestRandom)
dist *= (float)RandomHelper.NextDouble();
@@ -1166,7 +1167,7 @@ namespace Game.Spells
m_targets.SetDst(dest);
}
void SelectImplicitDestDestTargets(SpellEffectInfo spellEffectInfo, SpellImplicitTargetInfo targetType)
void SelectImplicitDestDestTargets(SpellEffectInfo spellEffectInfo, SpellImplicitTargetInfo targetType, SpellTargetIndex targetIndex)
{
// set destination to caster if no dest provided
// can only happen if previous destination target could not be set for some reason
@@ -1188,7 +1189,7 @@ namespace Game.Spells
break;
case Targets.DestDestTargetTowardsCaster:
{
float dist = spellEffectInfo.CalcRadius(m_caster);
float dist = spellEffectInfo.CalcRadius(m_caster, targetIndex);
Position pos = dest.Position;
float angle = pos.GetAbsoluteAngle(m_caster) - m_caster.GetOrientation();
@@ -1201,7 +1202,7 @@ namespace Game.Spells
default:
{
float angle = targetType.CalcDirectionAngle();
float dist = spellEffectInfo.CalcRadius(m_caster);
float dist = spellEffectInfo.CalcRadius(m_caster, targetIndex);
if (targetType.GetTarget() == Targets.DestRandom)
dist *= (float)RandomHelper.NextDouble();
@@ -1455,7 +1456,7 @@ namespace Game.Spells
}
}
void SelectImplicitLineTargets(SpellEffectInfo spellEffectInfo, SpellImplicitTargetInfo targetType, uint effMask)
void SelectImplicitLineTargets(SpellEffectInfo spellEffectInfo, SpellImplicitTargetInfo targetType, SpellTargetIndex targetIndex, uint effMask)
{
List<WorldObject> targets = new();
SpellTargetObjectTypes objectType = targetType.GetObjectType();
@@ -1482,7 +1483,7 @@ namespace Game.Spells
}
var condList = spellEffectInfo.ImplicitTargetConditions;
float radius = spellEffectInfo.CalcRadius(m_caster) * m_spellValue.RadiusMod;
float radius = spellEffectInfo.CalcRadius(m_caster, targetIndex) * m_spellValue.RadiusMod;
GridMapTypeMask containerTypeMask = GetSearcherTypeMask(objectType, condList);
if (containerTypeMask != 0)
+2 -2
View File
@@ -2701,7 +2701,7 @@ namespace Game.Spells
case 45151:
{
//Workaround for Range ... should be global for every ScriptEffect
float radius = effectInfo.CalcRadius();
float radius = effectInfo.CalcRadius(null, SpellTargetIndex.TargetB);
if (unitTarget != null && unitTarget.IsTypeId(TypeId.Player) && unitTarget.GetDistance(m_caster) >= radius && !unitTarget.HasAura(46394) && unitTarget != m_caster)
unitTarget.CastSpell(unitTarget, 46394, new CastSpellExtraArgs(this));
@@ -4078,7 +4078,7 @@ namespace Game.Spells
if (m_targets.HasDst())
destTarget.GetPosition(out fx, out fy, out fz, out fo);
//FIXME: this can be better check for most objects but still hack
else if (effectInfo.HasRadius() && m_spellInfo.Speed == 0)
else if (effectInfo.HasRadius(SpellTargetIndex.TargetA) && m_spellInfo.Speed == 0)
{
float dis = effectInfo.CalcRadius(unitCaster);
unitCaster.GetClosePoint(out fx, out fy, out fz, SharedConst.DefaultPlayerBoundingRadius, dis);
+21 -15
View File
@@ -4088,8 +4088,8 @@ namespace Game.Spells
PositionFacing = effect.EffectPosFacing;
TargetA = new SpellImplicitTargetInfo((Targets)effect.ImplicitTarget[0]);
TargetB = new SpellImplicitTargetInfo((Targets)effect.ImplicitTarget[1]);
RadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(effect.EffectRadiusIndex[0]);
MaxRadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(effect.EffectRadiusIndex[1]);
TargetARadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(effect.EffectRadiusIndex[0]);
TargetBRadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(effect.EffectRadiusIndex[1]);
ChainTargets = effect.EffectChainTargets;
ItemType = effect.EffectItemType;
TriggerSpell = effect.EffectTriggerSpell;
@@ -4332,21 +4332,27 @@ namespace Game.Spells
return multiplierPercent / 100.0f;
}
public bool HasRadius()
public bool HasRadius(SpellTargetIndex targetIndex)
{
return RadiusEntry != null;
switch (targetIndex)
{
case SpellTargetIndex.TargetA:
return TargetARadiusEntry != null;
case SpellTargetIndex.TargetB:
return TargetBRadiusEntry != null;
default:
return false;
}
}
public bool HasMaxRadius()
public float CalcRadius(WorldObject caster = null, SpellTargetIndex targetIndex = SpellTargetIndex.TargetA, Spell spell = null)
{
return MaxRadiusEntry != null;
}
public float CalcRadius(WorldObject caster = null, Spell spell = null)
{
SpellRadiusRecord entry = RadiusEntry;
if (!HasRadius() && HasMaxRadius())
entry = MaxRadiusEntry;
// TargetA -> TargetARadiusEntry
// TargetB -> TargetBRadiusEntry
// Aura effects have TargetARadiusEntry == TargetBRadiusEntry (mostly)
var entry = TargetARadiusEntry;
if (targetIndex == SpellTargetIndex.TargetB && HasRadius(targetIndex))
entry = TargetBRadiusEntry;
if (entry == null)
return 0.0f;
@@ -4854,8 +4860,8 @@ namespace Game.Spells
public float PositionFacing;
public SpellImplicitTargetInfo TargetA = new();
public SpellImplicitTargetInfo TargetB = new();
public SpellRadiusRecord RadiusEntry;
public SpellRadiusRecord MaxRadiusEntry;
public SpellRadiusRecord TargetARadiusEntry;
public SpellRadiusRecord TargetBRadiusEntry;
public int ChainTargets;
public uint ItemType;
public uint TriggerSpell;
+13 -23
View File
@@ -3207,7 +3207,7 @@ namespace Game.Entities
{
ApplySpellEffectFix(spellInfo, 0, spellEffectInfo =>
{
spellEffectInfo.RadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards100); // 100yards instead of 50000?!
spellEffectInfo.TargetARadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards100); // 100yards instead of 50000?!
});
});
@@ -3403,7 +3403,7 @@ namespace Game.Entities
{
ApplySpellEffectFix(spellInfo, 0, spellEffectInfo =>
{
spellEffectInfo.RadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards10);
spellEffectInfo.TargetARadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards10);
});
});
@@ -3514,7 +3514,7 @@ namespace Game.Entities
{
ApplySpellEffectFix(spellInfo, 0, spellEffectInfo =>
{
spellEffectInfo.RadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards200);
spellEffectInfo.TargetARadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards200);
spellEffectInfo.TargetA = new SpellImplicitTargetInfo(Targets.UnitSrcAreaEntry);
});
});
@@ -3588,7 +3588,7 @@ namespace Game.Entities
{
ApplySpellEffectFix(spellInfo, 0, spellEffectInfo =>
{
spellEffectInfo.RadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards10);
spellEffectInfo.TargetARadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards10);
});
});
@@ -3676,7 +3676,7 @@ namespace Game.Entities
// use max radius from 4.3.4
ApplySpellEffectFix(spellInfo, 0, spellEffectInfo =>
{
spellEffectInfo.RadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards25);
spellEffectInfo.TargetARadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards25);
});
});
// ENDOF VIOLET HOLD
@@ -3689,7 +3689,7 @@ namespace Game.Entities
{
ApplySpellEffectFix(spellInfo, 0, spellEffectInfo =>
{
spellEffectInfo.RadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards50000); // 50000yd
spellEffectInfo.TargetARadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards50000); // 50000yd
});
});
@@ -4008,11 +4008,11 @@ namespace Game.Entities
{
ApplySpellEffectFix(spellInfo, 0, spellEffectInfo =>
{
spellEffectInfo.RadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards200); // 200yd
spellEffectInfo.TargetARadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards200); // 200yd
});
ApplySpellEffectFix(spellInfo, 1, spellEffectInfo =>
{
spellEffectInfo.RadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards200); // 200yd
spellEffectInfo.TargetARadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards200); // 200yd
});
});
@@ -4057,7 +4057,7 @@ namespace Game.Entities
{
ApplySpellEffectFix(spellInfo, 0, spellEffectInfo =>
{
spellEffectInfo.RadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards25); // 25yd
spellEffectInfo.TargetARadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards25); // 25yd
});
});
@@ -4073,20 +4073,10 @@ namespace Game.Entities
spellInfo.RangeEntry = CliDB.SpellRangeStorage.LookupByKey(5); // 40yd
ApplySpellEffectFix(spellInfo, 0, spellEffectInfo =>
{
spellEffectInfo.RadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards10); // 10yd
spellEffectInfo.TargetARadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards10); // 10yd
spellEffectInfo.MiscValue = 190;
});
});
// Broken Frostmourne
ApplySpellFix(new[] { 72405 }, spellInfo =>
{
spellInfo.AttributesEx |= SpellAttr1.NoThreat;
ApplySpellEffectFix(spellInfo, 1, spellEffectInfo =>
{
spellEffectInfo.RadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards20); // 20yd
});
});
// ENDOF ICECROWN CITADEL SPELLS
//
@@ -4097,7 +4087,7 @@ namespace Game.Entities
{
ApplySpellEffectFix(spellInfo, 1, spellEffectInfo =>
{
spellEffectInfo.RadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards12);
spellEffectInfo.TargetARadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards12);
});
});
@@ -4177,7 +4167,7 @@ namespace Game.Entities
// Little hack, Increase the radius so it can hit the Cave In Stalkers in the platform.
ApplySpellEffectFix(spellInfo, 0, spellEffectInfo =>
{
spellEffectInfo.MaxRadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards45);
spellEffectInfo.TargetBRadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards45);
});
});
@@ -4282,7 +4272,7 @@ namespace Game.Entities
{
ApplySpellEffectFix(spellInfo, 0, spellEffectInfo =>
{
spellEffectInfo.MaxRadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards15);
spellEffectInfo.TargetBRadiusEntry = CliDB.SpellRadiusStorage.LookupByKey(EffectRadiusIndex.Yards15);
});
});
+1 -1
View File
@@ -1122,7 +1122,7 @@ namespace Scripts.Spells.Mage
void FilterTargets(List<WorldObject> targets)
{
WorldLocation dest = GetExplTargetDest();
float outRadius = Global.SpellMgr.GetSpellInfo(SpellIds.RingOfFrostSummon, GetCastDifficulty()).GetEffect(0).CalcRadius();
float outRadius = Global.SpellMgr.GetSpellInfo(SpellIds.RingOfFrostSummon, GetCastDifficulty()).GetEffect(0).CalcRadius(null, SpellTargetIndex.TargetB);
float inRadius = 6.5f;
targets.RemoveAll(target =>