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

@ -8,7 +8,7 @@ using Server.Targeting;
namespace Server.Spells.Necromancy
{
public class AnimateDeadSpell : NecromancerSpell
public class AnimateDeadSpell : NecromancerSpell, ISpellTargetingItem
{
private static SpellInfo m_Info = new SpellInfo(
"Animate Dead", "Uus Corp",
@ -105,7 +105,7 @@ namespace Server.Spells.Necromancy
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetItem(this, TargetFlags.None, Core.ML ? 10 : 12);
Caster.SendLocalizedMessage(1061083); // Animate what corpse?
}
@ -128,9 +128,9 @@ namespace Server.Spells.Necromancy
return null;
}
public void Target(object obj)
public void Target(Item item)
{
MaabusCoffinComponent comp = obj as MaabusCoffinComponent;
MaabusCoffinComponent comp = item as MaabusCoffinComponent;
if (comp?.Addon is MaabusCoffin addon)
{
@ -152,7 +152,7 @@ namespace Server.Spells.Necromancy
return;
}
if (!(obj is Corpse c))
if (!(item is Corpse c))
{
Caster.SendLocalizedMessage(1061084); // You cannot animate that.
}
@ -370,25 +370,5 @@ namespace Server.Spells.Necromancy
m_Requirement = requirement;
}
}
private class InternalTarget : Target
{
private AnimateDeadSpell m_Owner;
public InternalTarget(AnimateDeadSpell owner) : base(Core.ML ? 10 : 12, false, TargetFlags.None)
{
m_Owner = owner;
}
protected override void OnTarget(Mobile from, object o)
{
m_Owner.Target(o);
}
protected override void OnTargetFinish(Mobile from)
{
m_Owner.FinishSequence();
}
}
}
}

View file

@ -5,7 +5,7 @@ using Server.Targeting;
namespace Server.Spells.Necromancy
{
public class BloodOathSpell : NecromancerSpell
public class BloodOathSpell : NecromancerSpell, ISpellTargetingMobile
{
private static SpellInfo m_Info = new SpellInfo(
"Blood Oath", "In Jux Mani Xen",
@ -28,20 +28,18 @@ namespace Server.Spells.Necromancy
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetMobile(this, TargetFlags.Harmful, Core.ML ? 10 : 12);
}
public void Target(Mobile m)
{
if (Caster == m || !(m is PlayerMobile || m is BaseCreature)
) // only PlayerMobile and BaseCreature implement blood oath checking
{
if (m == null)
Caster.SendLocalizedMessage(1060508); // You can't curse that.
// only PlayerMobile and BaseCreature implement blood oath checking
else if (Caster == m || !(m is PlayerMobile || m is BaseCreature))
Caster.SendLocalizedMessage(1060508); // You can't curse that.
}
else if (m_OathTable.ContainsKey(Caster))
{
Caster.SendLocalizedMessage(1061607); // You are already bonded in a Blood Oath.
}
else if (m_OathTable.ContainsKey(m))
{
if (m.Player)
@ -148,28 +146,5 @@ namespace Server.Spells.Necromancy
m_Table.Remove(m_Caster);
}
}
private class InternalTarget : Target
{
private BloodOathSpell m_Owner;
public InternalTarget(BloodOathSpell owner) : base(Core.ML ? 10 : 12, false, TargetFlags.Harmful)
{
m_Owner = owner;
}
protected override void OnTarget(Mobile from, object o)
{
if (o is Mobile mobile)
m_Owner.Target(mobile);
else
from.SendLocalizedMessage(1060508); // You can't curse that.
}
protected override void OnTargetFinish(Mobile from)
{
m_Owner.FinishSequence();
}
}
}
}

View file

@ -4,7 +4,7 @@ using Server.Targeting;
namespace Server.Spells.Necromancy
{
public class CorpseSkinSpell : NecromancerSpell
public class CorpseSkinSpell : NecromancerSpell, ISpellTargetingMobile
{
private static SpellInfo m_Info = new SpellInfo(
"Corpse Skin", "In Agle Corp Ylem",
@ -27,11 +27,14 @@ namespace Server.Spells.Necromancy
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetMobile(this, TargetFlags.Harmful, Core.ML ? 10 : 12);
}
public void Target(Mobile m)
{
if (m == null)
return;
if (CheckHSequence(m))
{
SpellHelper.Turn(Caster, m);
@ -89,13 +92,11 @@ namespace Server.Spells.Necromancy
public static bool RemoveCurse(Mobile m)
{
ExpireTimer t = m_Table[m];
if (t == null)
if (!m_Table.TryGetValue(m, out ExpireTimer t))
return false;
m.SendLocalizedMessage(1061688); // Your skin returns to normal.
t.DoExpire();
t?.DoExpire();
return true;
}
@ -126,26 +127,5 @@ namespace Server.Spells.Necromancy
DoExpire();
}
}
private class InternalTarget : Target
{
private CorpseSkinSpell m_Owner;
public InternalTarget(CorpseSkinSpell owner) : base(Core.ML ? 10 : 12, false, TargetFlags.Harmful)
{
m_Owner = owner;
}
protected override void OnTarget(Mobile from, object o)
{
if (o is Mobile mobile)
m_Owner.Target(mobile);
}
protected override void OnTargetFinish(Mobile from)
{
m_Owner.FinishSequence();
}
}
}
}

View file

@ -5,7 +5,7 @@ using Server.Targeting;
namespace Server.Spells.Necromancy
{
public class EvilOmenSpell : NecromancerSpell
public class EvilOmenSpell : NecromancerSpell, ISpellTargetingMobile
{
private static SpellInfo m_Info = new SpellInfo(
"Evil Omen", "Pas Tym An Sanct",
@ -29,15 +29,13 @@ namespace Server.Spells.Necromancy
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetMobile(this, TargetFlags.Harmful, Core.ML ? 10 : 12);
}
public void Target(Mobile m)
{
if (!(m is BaseCreature || m is PlayerMobile))
{
Caster.SendLocalizedMessage(1060508); // You can't curse that.
}
else if (CheckHSequence(m))
{
SpellHelper.Turn(Caster, m);
@ -68,7 +66,7 @@ namespace Server.Spells.Necromancy
TimeSpan duration = TimeSpan.FromSeconds(Caster.Skills.SpiritSpeak.Value / 12 + 1.0);
Timer.DelayCall(duration, TryEndEffect_Callback, m);
Timer.DelayCall(duration, mob => TryEndEffect(mob), m);
HarmfulSpell(m);
@ -78,53 +76,15 @@ namespace Server.Spells.Necromancy
FinishSequence();
}
/*
* The naming here was confusing. Its a 1-off effect spell.
* So, we don't actually "checkeffect"; we endeffect with bool
* return to determine external behaviors.
*
* -refactored.
*/
private static void TryEndEffect_Callback(Mobile m)
{
TryEndEffect(m);
}
public static bool TryEndEffect(Mobile m)
{
DefaultSkillMod mod = m_Table[m];
if (mod == null)
if (!m_Table.TryGetValue(m, out DefaultSkillMod mod))
return false;
m_Table.Remove(m);
mod.Remove();
mod?.Remove();
return true;
}
private class InternalTarget : Target
{
private EvilOmenSpell m_Owner;
public InternalTarget(EvilOmenSpell owner)
: base(Core.ML ? 10 : 12, false, TargetFlags.Harmful)
{
m_Owner = owner;
}
protected override void OnTarget(Mobile from, object o)
{
if (o is Mobile mobile)
m_Owner.Target(mobile);
else
from.SendLocalizedMessage(1060508); // You can't curse that.
}
protected override void OnTargetFinish(Mobile from)
{
m_Owner.FinishSequence();
}
}
}
}

View file

@ -4,7 +4,7 @@ using Server.Targeting;
namespace Server.Spells.Necromancy
{
public class MindRotSpell : NecromancerSpell
public class MindRotSpell : NecromancerSpell, ISpellTargetingMobile
{
private static SpellInfo m_Info = new SpellInfo(
"Mind Rot", "Wis An Ben",
@ -28,15 +28,15 @@ namespace Server.Spells.Necromancy
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetMobile(this, TargetFlags.Harmful, Core.ML ? 10 : 12);
}
public void Target(Mobile m)
{
if (HasMindRotScalar(m))
{
if (m == null)
Caster.SendLocalizedMessage(1060508); // You can't curse that.
else if (HasMindRotScalar(m))
Caster.SendLocalizedMessage(1005559); // This spell is already in effect.
}
else if (CheckHSequence(m))
{
SpellHelper.Turn(Caster, m);
@ -103,29 +103,6 @@ namespace Server.Spells.Necromancy
target.SendLocalizedMessage(1074384);
}
}
private class InternalTarget : Target
{
private MindRotSpell m_Owner;
public InternalTarget(MindRotSpell owner) : base(Core.ML ? 10 : 12, false, TargetFlags.Harmful)
{
m_Owner = owner;
}
protected override void OnTarget(Mobile from, object o)
{
if (o is Mobile mobile)
m_Owner.Target(mobile);
else
from.SendLocalizedMessage(1060508); // You can't curse that.
}
protected override void OnTargetFinish(Mobile from)
{
m_Owner.FinishSequence();
}
}
}
public class MRExpireTimer : Timer

View file

@ -5,7 +5,7 @@ using Server.Targeting;
namespace Server.Spells.Necromancy
{
public class PainSpikeSpell : NecromancerSpell
public class PainSpikeSpell : NecromancerSpell, ISpellTargetingMobile
{
private static SpellInfo m_Info = new SpellInfo(
"Pain Spike", "In Sar",
@ -30,11 +30,14 @@ namespace Server.Spells.Necromancy
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetMobile(this, TargetFlags.Harmful, Core.ML ? 10 : 12);
}
public void Target(Mobile m)
{
if (m == null)
return;
if (CheckHSequence(m))
{
SpellHelper.Turn(Caster, m);
@ -108,26 +111,5 @@ namespace Server.Spells.Necromancy
BuffInfo.RemoveBuff(m_Mobile, BuffIcon.PainSpike);
}
}
private class InternalTarget : Target
{
private PainSpikeSpell m_Owner;
public InternalTarget(PainSpikeSpell owner) : base(Core.ML ? 10 : 12, false, TargetFlags.Harmful)
{
m_Owner = owner;
}
protected override void OnTarget(Mobile from, object o)
{
if (o is Mobile mobile)
m_Owner.Target(mobile);
}
protected override void OnTargetFinish(Mobile from)
{
m_Owner.FinishSequence();
}
}
}
}

View file

@ -7,7 +7,7 @@ using Server.Targeting;
namespace Server.Spells.Necromancy
{
public class PoisonStrikeSpell : NecromancerSpell
public class PoisonStrikeSpell : NecromancerSpell, ISpellTargetingMobile
{
private static SpellInfo m_Info = new SpellInfo(
"Poison Strike", "In Vas Nox",
@ -30,11 +30,14 @@ namespace Server.Spells.Necromancy
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetMobile(this, TargetFlags.Harmful, Core.ML ? 10 : 12);
}
public void Target(Mobile m)
{
if (m == null)
return;
if (CheckHSequence(m))
{
SpellHelper.Turn(Caster, m);
@ -92,27 +95,5 @@ namespace Server.Spells.Necromancy
FinishSequence();
}
private class InternalTarget : Target
{
private PoisonStrikeSpell m_Owner;
public InternalTarget(PoisonStrikeSpell owner)
: base(Core.ML ? 10 : 12, false, TargetFlags.Harmful)
{
m_Owner = owner;
}
protected override void OnTarget(Mobile from, object o)
{
if (o is Mobile mobile)
m_Owner.Target(mobile);
}
protected override void OnTargetFinish(Mobile from)
{
m_Owner.FinishSequence();
}
}
}
}

View file

@ -4,7 +4,7 @@ using Server.Targeting;
namespace Server.Spells.Necromancy
{
public class StrangleSpell : NecromancerSpell
public class StrangleSpell : NecromancerSpell, ISpellTargetingMobile
{
private static SpellInfo m_Info = new SpellInfo(
"Strangle", "In Bal Nox",
@ -27,11 +27,14 @@ namespace Server.Spells.Necromancy
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetMobile(this, TargetFlags.Harmful, Core.ML ? 10 : 12);
}
public void Target(Mobile m)
{
if (m == null)
return;
if (CheckHSequence(m))
{
SpellHelper.Turn(Caster, m);
@ -208,26 +211,5 @@ namespace Server.Spells.Necromancy
}
}
}
private class InternalTarget : Target
{
private StrangleSpell m_Owner;
public InternalTarget(StrangleSpell owner) : base(Core.ML ? 10 : 12, false, TargetFlags.Harmful)
{
m_Owner = owner;
}
protected override void OnTarget(Mobile from, object o)
{
if (o is Mobile mobile)
m_Owner.Target(mobile);
}
protected override void OnTargetFinish(Mobile from)
{
m_Owner.FinishSequence();
}
}
}
}

View file

@ -4,7 +4,7 @@ using Server.Targeting;
namespace Server.Spells.Necromancy
{
public class VengefulSpiritSpell : NecromancerSpell
public class VengefulSpiritSpell : NecromancerSpell, ISpellTargetingMobile
{
private static SpellInfo m_Info = new SpellInfo(
"Vengeful Spirit", "Kal Xen Bal Beh",
@ -26,7 +26,7 @@ namespace Server.Spells.Necromancy
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetMobile(this, TargetFlags.Harmful, Core.ML ? 10 : 12);
}
public override bool CheckCast()
@ -45,10 +45,11 @@ namespace Server.Spells.Necromancy
public void Target(Mobile m)
{
if (m == null)
return;
if (Caster == m)
{
Caster.SendLocalizedMessage(1061832); // You cannot exact vengeance on yourself.
}
else if (CheckHSequence(m))
{
SpellHelper.Turn(Caster, m);
@ -70,26 +71,5 @@ namespace Server.Spells.Necromancy
FinishSequence();
}
private class InternalTarget : Target
{
private VengefulSpiritSpell m_Owner;
public InternalTarget(VengefulSpiritSpell owner) : base(Core.ML ? 10 : 12, false, TargetFlags.Harmful)
{
m_Owner = owner;
}
protected override void OnTarget(Mobile from, object o)
{
if (o is Mobile mobile)
m_Owner.Target(mobile);
}
protected override void OnTargetFinish(Mobile from)
{
m_Owner.FinishSequence();
}
}
}
}