Cleans up Spell Targeting (#36)

This commit is contained in:
Kamron Batman 2019-03-15 15:23:03 -07:00 • committed by GitHub
parent de50bc9e43
commit 472b84f5ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
99 changed files with 653 additions and 2192 deletions

View file

@ -4,7 +4,7 @@ using Server.Targeting;
namespace Server.Spells.Sixth
{
public class DispelSpell : MagerySpell
public class DispelSpell : MagerySpell, ISpellTargetingMobile
{
private static SpellInfo m_Info = new SpellInfo(
"Dispel", "An Ort",
@ -23,60 +23,41 @@ namespace Server.Spells.Sixth
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetMobile(this, TargetFlags.Harmful, Core.ML ? 10 : 12);
}
public class InternalTarget : Target
public void Target(Mobile m)
{
private DispelSpell m_Owner;
if (m == null)
return;
public InternalTarget(DispelSpell owner) : base(Core.ML ? 10 : 12, false, TargetFlags.Harmful)
if (!Caster.CanSee(m))
Caster.SendLocalizedMessage(500237); // Target can not be seen.
else if (!(m is BaseCreature bc && bc.IsDispellable))
Caster.SendLocalizedMessage(1005049); // That cannot be dispelled.
else if (CheckHSequence(m))
{
m_Owner = owner;
}
SpellHelper.Turn(Caster, m);
protected override void OnTarget(Mobile from, object o)
{
if (o is Mobile m)
double dispelChance =
(50.0 + 100 * (Caster.Skills.Magery.Value - bc.DispelDifficulty) / (bc.DispelFocus * 2)) / 100;
if (dispelChance > Utility.RandomDouble())
{
BaseCreature bc = m as BaseCreature;
Effects.SendLocationParticles(EffectItem.Create(m.Location, m.Map, EffectItem.DefaultDuration),
0x3728, 8, 20, 5042);
Effects.PlaySound(m, m.Map, 0x201);
if (!from.CanSee(m))
{
from.SendLocalizedMessage(500237); // Target can not be seen.
}
else if (bc == null || !bc.IsDispellable)
{
from.SendLocalizedMessage(1005049); // That cannot be dispelled.
}
else if (m_Owner.CheckHSequence(m))
{
SpellHelper.Turn(from, m);
double dispelChance =
(50.0 + 100 * (from.Skills.Magery.Value - bc.DispelDifficulty) / (bc.DispelFocus * 2)) / 100;
if (dispelChance > Utility.RandomDouble())
{
Effects.SendLocationParticles(EffectItem.Create(m.Location, m.Map, EffectItem.DefaultDuration),
0x3728, 8, 20, 5042);
Effects.PlaySound(m, m.Map, 0x201);
m.Delete();
}
else
{
m.FixedEffect(0x3779, 10, 20);
from.SendLocalizedMessage(1010084); // The creature resisted the attempt to dispel it!
}
}
m.Delete();
}
else
{
m.FixedEffect(0x3779, 10, 20);
Caster.SendLocalizedMessage(1010084); // The creature resisted the attempt to dispel it!
}
}
protected override void OnTargetFinish(Mobile from)
{
m_Owner.FinishSequence();
}
FinishSequence();
}
}
}