fix: Magic NPCs now use spell range (#1870)
### Summary - Drastically streamlines the spell targeting by collapsing the target classes into a single `SpellTarget<T>` class. - Moves TargetRange to the spell itself so it can be used by MageAI. - Changes range check in MageAI to use TargetRange. This should fix target acquisition bugs
This commit is contained in:
parent
91e37fb8d4
commit
9b7fea2c20
85 changed files with 255 additions and 313 deletions
58
Projects/UOContent/Spells/Targeting/SpellTarget.cs
Normal file
58
Projects/UOContent/Spells/Targeting/SpellTarget.cs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
using Server.Targeting;
|
||||
|
||||
namespace Server.Spells;
|
||||
|
||||
public class SpellTarget<T> : Target, ISpellTarget<T> where T : class, IPoint3D
|
||||
{
|
||||
private static readonly bool _canTargetStatic = typeof(T).IsAssignableFrom(typeof(StaticTarget));
|
||||
private static readonly bool _canTargetMobile = typeof(T).IsAssignableFrom(typeof(Mobile));
|
||||
private static readonly bool _canTargetItem = typeof(T).IsAssignableFrom(typeof(Item));
|
||||
|
||||
private readonly bool _retryOnLos;
|
||||
protected readonly ITargetingSpell<T> _spell;
|
||||
|
||||
public SpellTarget(
|
||||
ITargetingSpell<T> spell,
|
||||
TargetFlags flags = TargetFlags.None,
|
||||
bool retryOnLos = false
|
||||
) : this(spell, false, flags, retryOnLos)
|
||||
{
|
||||
}
|
||||
|
||||
public SpellTarget(ITargetingSpell<T> spell, bool allowGround, TargetFlags flags = TargetFlags.None, bool retryOnLos = false)
|
||||
: base(spell.TargetRange, allowGround, flags)
|
||||
{
|
||||
_spell = spell;
|
||||
_retryOnLos = retryOnLos;
|
||||
}
|
||||
|
||||
public ITargetingSpell<T> Spell => _spell;
|
||||
|
||||
protected override bool CanTarget(Mobile from, StaticTarget staticTarget, ref Point3D loc, ref Map map)
|
||||
=> _canTargetStatic;
|
||||
|
||||
protected override bool CanTarget(Mobile from, Mobile mobile, ref Point3D loc, ref Map map) => _canTargetMobile;
|
||||
|
||||
protected override bool CanTarget(Mobile from, Item item, ref Point3D loc, ref Map map) => _canTargetItem;
|
||||
|
||||
protected override void OnCantSeeTarget(Mobile from, object o)
|
||||
{
|
||||
from.SendLocalizedMessage(500237); // Target can not be seen.
|
||||
}
|
||||
|
||||
protected override void OnTarget(Mobile from, object o) => _spell.Target(o as T);
|
||||
|
||||
protected override void OnTargetOutOfLOS(Mobile from, object o)
|
||||
{
|
||||
if (!_retryOnLos)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
from.SendLocalizedMessage(501943); // Target cannot be seen. Try again.
|
||||
from.Target = new SpellTarget<T>(_spell, AllowGround, Flags, true);
|
||||
from.Target.BeginTimeout(from, TimeoutTime - Core.TickCount);
|
||||
}
|
||||
|
||||
protected override void OnTargetFinish(Mobile from) => _spell?.FinishSequence();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue