Core/Spells Implement targets 133, 134, 135 : TARGET_UNIT_LINE_CASTER_TO_DEST_***

Port From (https://github.com/TrinityCore/TrinityCore/commit/fb6761c273d518eae6bab72fc9c2a2b6f93eec83)
This commit is contained in:
hondacrx
2021-08-15 09:05:23 -04:00
parent 66280abe58
commit c3367b7508
7 changed files with 1654 additions and 1544 deletions
+103
View File
@@ -337,6 +337,7 @@ namespace Game.Spells
case SpellTargetSelectionCategories.Nearby:
case SpellTargetSelectionCategories.Cone:
case SpellTargetSelectionCategories.Area:
case SpellTargetSelectionCategories.Line:
// targets for effect already selected
if (Convert.ToBoolean(effectMask & processedEffectMask))
return;
@@ -386,6 +387,9 @@ namespace Game.Spells
SelectImplicitTrajTargets(effIndex, targetType);
break;
case SpellTargetSelectionCategories.Line:
SelectImplicitLineTargets(effIndex, targetType, effectMask);
break;
case SpellTargetSelectionCategories.Default:
switch (targetType.GetObjectType())
{
@@ -1238,6 +1242,76 @@ namespace Game.Spells
veh.SetLastShootPos(m_targets.GetDstPos());
}
void SelectImplicitLineTargets(uint effIndex, SpellImplicitTargetInfo targetType, uint effMask)
{
List<WorldObject> targets = new();
SpellTargetObjectTypes objectType = targetType.GetObjectType();
SpellTargetCheckTypes selectionType = targetType.GetCheckType();
SpellEffectInfo effect = m_spellInfo.GetEffect(effIndex);
if (effect == null)
return;
Position dst;
switch (targetType.GetReferenceType())
{
case SpellTargetReferenceTypes.Src:
dst = m_targets.GetSrcPos();
break;
case SpellTargetReferenceTypes.Dest:
dst = m_targets.GetDstPos();
break;
case SpellTargetReferenceTypes.Caster:
dst = m_caster;
break;
case SpellTargetReferenceTypes.Target:
dst = m_targets.GetUnitTarget();
break;
default:
Cypher.Assert(false, "Spell.SelectImplicitLineTargets: received not implemented target reference type");
return;
}
var condList = effect.ImplicitTargetConditions;
float radius = effect.CalcRadius(m_caster) * m_spellValue.RadiusMod;
GridMapTypeMask containerTypeMask = GetSearcherTypeMask(objectType, condList);
if (containerTypeMask != 0)
{
WorldObjectSpellLineTargetCheck check = new(m_caster, dst, m_spellInfo.Width != 0 ? m_spellInfo.Width : m_caster.GetCombatReach(), radius, m_caster, m_spellInfo, selectionType, condList, objectType);
WorldObjectListSearcher searcher = new(m_caster, targets, check, containerTypeMask);
SearchTargets(searcher, containerTypeMask, m_caster, m_caster, radius);
CallScriptObjectAreaTargetSelectHandlers(targets, effIndex, targetType);
if (!targets.Empty())
{
// Other special target selection goes here
uint maxTargets = m_spellValue.MaxAffectedTargets;
if (maxTargets != 0)
{
if (maxTargets < targets.Count)
{
targets.Sort(new ObjectDistanceOrderPred(m_caster));
targets.Resize(maxTargets);
}
}
foreach (var obj in targets)
{
Unit unit = obj.ToUnit();
if (unit != null)
AddUnitTarget(unit, effMask, false);
else
{
GameObject gObjTarget = obj.ToGameObject();
if (gObjTarget != null)
AddGOTarget(gObjTarget, effMask);
}
}
}
}
}
void SelectEffectTypeImplicitTargets(uint effIndex)
{
// special case for SPELL_EFFECT_SUMMON_RAF_FRIEND and SPELL_EFFECT_SUMMON_PLAYER
@@ -7956,6 +8030,7 @@ namespace Game.Spells
{
float _range;
Position _position;
public WorldObjectSpellNearbyTargetCheck(float range, Unit caster, SpellInfo spellInfo, SpellTargetCheckTypes selectionType, List<Condition> condList, SpellTargetObjectTypes objectType)
: base(caster, caster, spellInfo, selectionType, condList, objectType)
{
@@ -7979,6 +8054,7 @@ namespace Game.Spells
{
float _range;
Position _position;
public WorldObjectSpellAreaTargetCheck(float range, Position position, Unit caster, Unit referer, SpellInfo spellInfo, SpellTargetCheckTypes selectionType, List<Condition> condList, SpellTargetObjectTypes objectType)
: base(caster, referer, spellInfo, selectionType, condList, objectType)
{
@@ -8068,6 +8144,33 @@ namespace Game.Spells
}
}
public class WorldObjectSpellLineTargetCheck : WorldObjectSpellAreaTargetCheck
{
Position _srcPosition;
Position _dstPosition;
float _lineWidth;
public WorldObjectSpellLineTargetCheck(Position srcPosition, Position dstPosition, float lineWidth, float range, Unit caster, SpellInfo spellInfo, SpellTargetCheckTypes selectionType, List<Condition> condList, SpellTargetObjectTypes objectType)
: base(range, caster, caster, caster, spellInfo, selectionType, condList, objectType)
{
_srcPosition = srcPosition;
_dstPosition = dstPosition;
_lineWidth = lineWidth;
}
public override bool Invoke(WorldObject target)
{
float angle = _caster.GetOrientation();
if (_srcPosition != _dstPosition)
angle = _srcPosition.GetAngle(_dstPosition);
if (!_caster.HasInLine(target, target.GetCombatReach(), _lineWidth, angle))
return false;
return base.Invoke(target);
}
}
public class SpellEvent : BasicEvent
{
public SpellEvent(Spell spell)