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.Second
{
public class AgilitySpell : MagerySpell
public class AgilitySpell : MagerySpell, ISpellTargetingMobile
{
private static SpellInfo m_Info = new SpellInfo(
"Agility", "Ex Uus",
@ -33,15 +33,16 @@ namespace Server.Spells.Second
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetMobile(this, TargetFlags.Beneficial, Core.ML ? 10 : 12);
}
public void Target(Mobile m)
{
if (m == null)
return;
if (!Caster.CanSee(m))
{
Caster.SendLocalizedMessage(500237); // Target can not be seen.
}
else if (CheckBSequence(m))
{
SpellHelper.Turn(Caster, m);
@ -59,26 +60,5 @@ namespace Server.Spells.Second
FinishSequence();
}
private class InternalTarget : Target
{
private AgilitySpell m_Owner;
public InternalTarget(AgilitySpell owner) : base(Core.ML ? 10 : 12, false, TargetFlags.Beneficial)
{
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.Second
{
public class CunningSpell : MagerySpell
public class CunningSpell : MagerySpell, ISpellTargetingMobile
{
private static SpellInfo m_Info = new SpellInfo(
"Cunning", "Uus Wis",
@ -33,15 +33,16 @@ namespace Server.Spells.Second
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetMobile(this, TargetFlags.Beneficial, Core.ML ? 10 : 12);
}
public void Target(Mobile m)
{
if (m == null)
return;
if (!Caster.CanSee(m))
{
Caster.SendLocalizedMessage(500237); // Target can not be seen.
}
else if (CheckBSequence(m))
{
SpellHelper.Turn(Caster, m);
@ -59,26 +60,5 @@ namespace Server.Spells.Second
FinishSequence();
}
private class InternalTarget : Target
{
private CunningSpell m_Owner;
public InternalTarget(CunningSpell owner) : base(Core.ML ? 10 : 12, false, TargetFlags.Beneficial)
{
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

@ -3,7 +3,7 @@ using Server.Targeting;
namespace Server.Spells.Second
{
public class CureSpell : MagerySpell
public class CureSpell : MagerySpell, ISpellTargetingMobile
{
private static SpellInfo m_Info = new SpellInfo(
"Cure", "An Nox",
@ -32,15 +32,16 @@ namespace Server.Spells.Second
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetMobile(this, TargetFlags.Beneficial, Core.ML ? 10 : 12);
}
public void Target(Mobile m)
{
if (m == null)
return;
if (!Caster.CanSee(m))
{
Caster.SendLocalizedMessage(500237); // Target can not be seen.
}
else if (CheckBSequence(m))
{
SpellHelper.Turn(Caster, m);
@ -75,26 +76,5 @@ namespace Server.Spells.Second
FinishSequence();
}
public class InternalTarget : Target
{
private CureSpell m_Owner;
public InternalTarget(CureSpell owner) : base(Core.ML ? 10 : 12, false, TargetFlags.Beneficial)
{
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

@ -2,7 +2,7 @@ using Server.Targeting;
namespace Server.Spells.Second
{
public class HarmSpell : MagerySpell
public class HarmSpell : MagerySpell, ISpellTargetingMobile
{
private static SpellInfo m_Info = new SpellInfo(
"Harm", "An Mani",
@ -22,7 +22,7 @@ namespace Server.Spells.Second
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetMobile(this, TargetFlags.Harmful, Core.ML ? 10 : 12);
}
public override double GetSlayerDamageScalar(Mobile target)
@ -32,10 +32,11 @@ namespace Server.Spells.Second
public void Target(Mobile m)
{
if (m == null)
return;
if (!Caster.CanSee(m))
{
Caster.SendLocalizedMessage(500237); // Target can not be seen.
}
else if (CheckHSequence(m))
{
SpellHelper.Turn(Caster, m);
@ -83,26 +84,5 @@ namespace Server.Spells.Second
FinishSequence();
}
private class InternalTarget : Target
{
private HarmSpell m_Owner;
public InternalTarget(HarmSpell 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

@ -3,7 +3,7 @@ using Server.Targeting;
namespace Server.Spells.Second
{
public class MagicTrapSpell : MagerySpell
public class MagicTrapSpell : MagerySpell, ISpellTargetingItem
{
private static SpellInfo m_Info = new SpellInfo(
"Magic Trap", "In Jux",
@ -22,16 +22,18 @@ namespace Server.Spells.Second
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetItem(this, TargetFlags.None, Core.ML ? 10 : 12);
}
public void Target(TrappableContainer item)
public void Target(Item item)
{
if (!Caster.CanSee(item))
if (!(item is TrappableContainer cont))
Caster.SendMessage("You can't trap that"); // TODO: Localization for this?
else if (!Caster.CanSee(item))
{
Caster.SendLocalizedMessage(500237); // Target can not be seen.
}
else if (item.TrapType != TrapType.None && item.TrapType != TrapType.MagicTrap)
else if (cont.TrapType != TrapType.None && cont.TrapType != TrapType.MagicTrap)
{
base.DoFizzle();
}
@ -39,9 +41,9 @@ namespace Server.Spells.Second
{
SpellHelper.Turn(Caster, item);
item.TrapType = TrapType.MagicTrap;
item.TrapPower = Core.AOS ? Utility.RandomMinMax(10, 50) : 1;
item.TrapLevel = 0;
cont.TrapType = TrapType.MagicTrap;
cont.TrapPower = Core.AOS ? Utility.RandomMinMax(10, 50) : 1;
cont.TrapLevel = 0;
Point3D loc = item.GetWorldLocation();
@ -66,28 +68,5 @@ namespace Server.Spells.Second
FinishSequence();
}
private class InternalTarget : Target
{
private MagicTrapSpell m_Owner;
public InternalTarget(MagicTrapSpell owner) : base(Core.ML ? 10 : 12, false, TargetFlags.None)
{
m_Owner = owner;
}
protected override void OnTarget(Mobile from, object o)
{
if (o is TrappableContainer container)
m_Owner.Target(container);
else
from.SendMessage("You can't trap that");
}
protected override void OnTargetFinish(Mobile from)
{
m_Owner.FinishSequence();
}
}
}
}

View file

@ -3,7 +3,7 @@ using Server.Targeting;
namespace Server.Spells.Second
{
public class RemoveTrapSpell : MagerySpell
public class RemoveTrapSpell : MagerySpell, ISpellTargetingItem
{
private static SpellInfo m_Info = new SpellInfo(
"Remove Trap", "An Jux",
@ -21,17 +21,19 @@ namespace Server.Spells.Second
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.SendMessage("What do you wish to untrap?");
Caster.Target = new SpellTargetItem(this, TargetFlags.None, Core.ML ? 10 : 12);
Caster.SendMessage("What do you wish to untrap?"); // TODO: Localization?
}
public void Target(TrappableContainer item)
public void Target(Item item)
{
if (!Caster.CanSee(item))
if (!(item is TrappableContainer cont))
Caster.SendMessage("You can't disarm that"); // TODO: Localization?
else if (!Caster.CanSee(item))
{
Caster.SendLocalizedMessage(500237); // Target can not be seen.
}
else if (item.TrapType != TrapType.None && item.TrapType != TrapType.MagicTrap)
else if (cont.TrapType != TrapType.None && cont.TrapType != TrapType.MagicTrap)
{
base.DoFizzle();
}
@ -45,35 +47,12 @@ namespace Server.Spells.Second
5015);
Effects.PlaySound(loc, item.Map, 0x1F0);
item.TrapType = TrapType.None;
item.TrapPower = 0;
item.TrapLevel = 0;
cont.TrapType = TrapType.None;
cont.TrapPower = 0;
cont.TrapLevel = 0;
}
FinishSequence();
}
private class InternalTarget : Target
{
private RemoveTrapSpell m_Owner;
public InternalTarget(RemoveTrapSpell owner) : base(Core.ML ? 10 : 12, false, TargetFlags.None)
{
m_Owner = owner;
}
protected override void OnTarget(Mobile from, object o)
{
if (o is TrappableContainer container)
m_Owner.Target(container);
else
from.SendMessage("You can't disarm that");
}
protected override void OnTargetFinish(Mobile from)
{
m_Owner.FinishSequence();
}
}
}
}

View file

@ -4,7 +4,7 @@ using Server.Targeting;
namespace Server.Spells.Second
{
public class StrengthSpell : MagerySpell
public class StrengthSpell : MagerySpell, ISpellTargetingMobile
{
private static SpellInfo m_Info = new SpellInfo(
"Strength", "Uus Mani",
@ -33,15 +33,16 @@ namespace Server.Spells.Second
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetMobile(this, TargetFlags.Beneficial, Core.ML ? 10 : 12);
}
public void Target(Mobile m)
{
if (m == null)
return;
if (!Caster.CanSee(m))
{
Caster.SendLocalizedMessage(500237); // Target can not be seen.
}
else if (CheckBSequence(m))
{
SpellHelper.Turn(Caster, m);
@ -59,26 +60,5 @@ namespace Server.Spells.Second
FinishSequence();
}
private class InternalTarget : Target
{
private StrengthSpell m_Owner;
public InternalTarget(StrengthSpell owner) : base(Core.ML ? 10 : 12, false, TargetFlags.Beneficial)
{
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();
}
}
}
}