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.Third
{
public class BlessSpell : MagerySpell
public class BlessSpell : MagerySpell, ISpellTargetingMobile
{
private static SpellInfo m_Info = new SpellInfo(
"Bless", "Rel Sanct",
@ -33,15 +33,16 @@ namespace Server.Spells.Third
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);
@ -65,26 +66,5 @@ namespace Server.Spells.Third
FinishSequence();
}
private class InternalTarget : Target
{
private BlessSpell m_Owner;
public InternalTarget(BlessSpell 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.Third
{
public class FireballSpell : MagerySpell
public class FireballSpell : MagerySpell, ISpellTargetingMobile
{
private static SpellInfo m_Info = new SpellInfo(
"Fireball", "Vas Flam",
@ -21,15 +21,16 @@ namespace Server.Spells.Third
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 (!Caster.CanSee(m))
{
Caster.SendLocalizedMessage(500237); // Target can not be seen.
}
else if (CheckHSequence(m))
{
Mobile source = Caster;
@ -66,26 +67,5 @@ namespace Server.Spells.Third
FinishSequence();
}
private class InternalTarget : Target
{
private FireballSpell m_Owner;
public InternalTarget(FireballSpell 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.Third
{
public class MagicLockSpell : MagerySpell
public class MagicLockSpell : MagerySpell, ISpellTargetingItem
{
private static SpellInfo m_Info = new SpellInfo(
"Magic Lock", "An Por",
@ -24,64 +24,37 @@ namespace Server.Spells.Third
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetItem(this, TargetFlags.None, Core.ML ? 10 : 12);
}
public void Target(LockableContainer targ)
public void Target(Item item)
{
if (BaseHouse.CheckLockedDownOrSecured(targ))
{
// You cannot cast this on a locked down item.
Caster.LocalOverheadMessage(MessageType.Regular, 0x22, 501761);
}
else if (targ.Locked || targ.LockLevel == 0 || targ is ParagonChest)
{
// Target must be an unlocked chest.
Caster.SendLocalizedMessage(501762);
}
if (!(item is LockableContainer cont))
Caster.SendLocalizedMessage(501762); // Target must be an unlocked chest.
else if (BaseHouse.CheckLockedDownOrSecured(cont))
Caster.LocalOverheadMessage(MessageType.Regular, 0x22, 501761); // You cannot cast this on a locked down item.
else if (cont.Locked || cont.LockLevel == 0 || cont is ParagonChest)
Caster.SendLocalizedMessage(501762); // Target must be an unlocked chest.
else if (CheckSequence())
{
SpellHelper.Turn(Caster, targ);
SpellHelper.Turn(Caster, cont);
Point3D loc = targ.GetWorldLocation();
Point3D loc = cont.GetWorldLocation();
Effects.SendLocationParticles(
EffectItem.Create(loc, targ.Map, EffectItem.DefaultDuration),
EffectItem.Create(loc, cont.Map, EffectItem.DefaultDuration),
0x376A, 9, 32, 5020);
Effects.PlaySound(loc, targ.Map, 0x1FA);
Effects.PlaySound(loc, cont.Map, 0x1FA);
// The chest is now locked!
Caster.LocalOverheadMessage(MessageType.Regular, 0x3B2, 501763);
targ.LockLevel = -255; // signal magic lock
targ.Locked = true;
cont.LockLevel = -255; // signal magic lock
cont.Locked = true;
}
FinishSequence();
}
private class InternalTarget : Target
{
private MagicLockSpell m_Owner;
public InternalTarget(MagicLockSpell owner) : base(Core.ML ? 10 : 12, false, TargetFlags.None)
{
m_Owner = owner;
}
protected override void OnTarget(Mobile from, object o)
{
if (o is LockableContainer container)
m_Owner.Target(container);
else
from.SendLocalizedMessage(501762); // Target must be an unlocked chest.
}
protected override void OnTargetFinish(Mobile from)
{
m_Owner.FinishSequence();
}
}
}
}

View file

@ -3,7 +3,7 @@ using Server.Targeting;
namespace Server.Spells.Third
{
public class PoisonSpell : MagerySpell
public class PoisonSpell : MagerySpell, ISpellTargetingMobile
{
private static SpellInfo m_Info = new SpellInfo(
"Poison", "In Nox",
@ -20,15 +20,16 @@ namespace Server.Spells.Third
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 (!Caster.CanSee(m))
{
Caster.SendLocalizedMessage(500237); // Target can not be seen.
}
else if (CheckHSequence(m))
{
SpellHelper.Turn(Caster, m);
@ -77,11 +78,8 @@ namespace Server.Spells.Third
if (Caster is PlayerMobile pm)
{
if (pm.DuelContext != null && pm.DuelContext.Started && !pm.DuelContext.Finished &&
!pm.DuelContext.Ruleset.GetOption("Skills", "Poisoning"))
{
}
else
if (pm.DuelContext == null || !pm.DuelContext.Started || pm.DuelContext.Finished ||
pm.DuelContext.Ruleset.GetOption("Skills", "Poisoning"))
{
total += pm.Skills.Poisoning.Value;
}
@ -119,25 +117,5 @@ namespace Server.Spells.Third
FinishSequence();
}
private class InternalTarget : Target
{
private PoisonSpell m_Owner;
public InternalTarget(PoisonSpell 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.Third
{
public class TelekinesisSpell : MagerySpell
public class TelekinesisSpell : MagerySpell, ISpellTargetingItem
{
private static SpellInfo m_Info = new SpellInfo(
"Telekinesis", "Ort Por Ylem",
@ -21,77 +21,55 @@ namespace Server.Spells.Third
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetItem(this, TargetFlags.None, Core.ML ? 10 : 12);
}
public void Target(ITelekinesisable obj)
public void Target(Item item)
{
ITelekinesisable t = item as ITelekinesisable;
if (!(t != null || item is Container))
{
Caster.SendLocalizedMessage(501857); // This spell won't work on that!
return;
}
if (CheckSequence())
{
SpellHelper.Turn(Caster, obj);
obj.OnTelekinesis(Caster);
}
FinishSequence();
}
public void Target(Container item)
{
if (CheckSequence())
{
SpellHelper.Turn(Caster, item);
if (!item.IsAccessibleTo(Caster))
if (t != null)
{
item.OnDoubleClickNotAccessible(Caster);
SpellHelper.Turn(Caster, t);
t.OnTelekinesis(Caster);
}
else if (!item.CheckItemUse(Caster, item))
{
}
else if (item.RootParent is Mobile && item.RootParent != Caster)
{
item.OnSnoop(Caster);
}
else if (item is Corpse corpse && !corpse.CheckLoot(Caster, null))
{
}
else if (Caster.Region.OnDoubleClick(Caster, item))
{
Effects.SendLocationParticles(EffectItem.Create(item.Location, item.Map, EffectItem.DefaultDuration),
0x376A, 9, 32, 5022);
Effects.PlaySound(item.Location, item.Map, 0x1F5);
item.OnItemUsed(Caster, item);
}
}
FinishSequence();
}
public class InternalTarget : Target
{
private TelekinesisSpell m_Owner;
public InternalTarget(TelekinesisSpell owner) : base(Core.ML ? 10 : 12, false, TargetFlags.None)
{
m_Owner = owner;
}
protected override void OnTarget(Mobile from, object o)
{
if (o is ITelekinesisable telekinesisable)
m_Owner.Target(telekinesisable);
else if (o is Container container)
m_Owner.Target(container);
else
from.SendLocalizedMessage(501857); // This spell won't work on that!
{
SpellHelper.Turn(Caster, item);
if (!item.IsAccessibleTo(Caster))
{
item.OnDoubleClickNotAccessible(Caster);
}
else if (!item.CheckItemUse(Caster, item))
{
}
else if (item.RootParent is Mobile && item.RootParent != Caster)
{
item.OnSnoop(Caster);
}
else if (item is Corpse corpse && !corpse.CheckLoot(Caster, null))
{
}
else if (Caster.Region.OnDoubleClick(Caster, item))
{
Effects.SendLocationParticles(EffectItem.Create(item.Location, item.Map, EffectItem.DefaultDuration),
0x376A, 9, 32, 5022);
Effects.PlaySound(item.Location, item.Map, 0x1F5);
item.OnItemUsed(Caster, item);
}
}
}
protected override void OnTargetFinish(Mobile from)
{
m_Owner.FinishSequence();
}
FinishSequence();
}
}
}

View file

@ -9,7 +9,7 @@ using Server.Targeting;
namespace Server.Spells.Third
{
public class TeleportSpell : MagerySpell
public class TeleportSpell : MagerySpell, ISpellTargetingPoint3D
{
private static SpellInfo m_Info = new SpellInfo(
"Teleport", "Rel Por",
@ -44,7 +44,7 @@ namespace Server.Spells.Third
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetPoint3D(this, TargetFlags.None, Core.ML ? 10 : 12);
}
public void Target(IPoint3D p)
@ -118,26 +118,5 @@ namespace Server.Spells.Third
FinishSequence();
}
public class InternalTarget : Target
{
private TeleportSpell m_Owner;
public InternalTarget(TeleportSpell owner) : base(Core.ML ? 11 : 12, true, TargetFlags.None)
{
m_Owner = owner;
}
protected override void OnTarget(Mobile from, object o)
{
if (o is IPoint3D p)
m_Owner.Target(p);
}
protected override void OnTargetFinish(Mobile from)
{
m_Owner.FinishSequence();
}
}
}
}

View file

@ -5,7 +5,7 @@ using Server.Targeting;
namespace Server.Spells.Third
{
public class UnlockSpell : MagerySpell
public class UnlockSpell : MagerySpell, ISpellTargetingPoint3D
{
private static SpellInfo m_Info = new SpellInfo(
"Unlock Spell", "Ex Por",
@ -23,85 +23,53 @@ namespace Server.Spells.Third
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetPoint3D(this, TargetFlags.None, Core.ML ? 10 : 12);
}
private class InternalTarget : Target
public void Target(IPoint3D p)
{
private UnlockSpell m_Owner;
public InternalTarget(UnlockSpell owner) : base(Core.ML ? 10 : 12, false, TargetFlags.None)
if (CheckSequence())
{
m_Owner = owner;
}
SpellHelper.Turn(Caster, p);
protected override void OnTarget(Mobile from, object o)
{
if (!(o is IPoint3D loc))
return;
Effects.SendLocationParticles(EffectItem.Create(new Point3D(p), Caster.Map, EffectItem.DefaultDuration),
0x376A, 9, 32, 5024);
if (m_Owner.CheckSequence())
Effects.PlaySound(p, Caster.Map, 0x1FF);
if (p is Mobile)
Caster.LocalOverheadMessage(MessageType.Regular, 0x3B2, 503101); // That did not need to be unlocked.
else if (!(p is LockableContainer cont))
Caster.SendLocalizedMessage(501666); // You can't unlock that!
else
{
SpellHelper.Turn(from, o);
Effects.SendLocationParticles(EffectItem.Create(new Point3D(loc), from.Map, EffectItem.DefaultDuration),
0x376A, 9, 32, 5024);
Effects.PlaySound(loc, from.Map, 0x1FF);
if (o is Mobile)
{
from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 503101); // That did not need to be unlocked.
}
else if (!(o is LockableContainer))
{
from.SendLocalizedMessage(501666); // You can't unlock that!
}
if (BaseHouse.CheckSecured(cont))
Caster.SendLocalizedMessage(503098); // You cannot cast this on a secure item.
else if (!cont.Locked)
Caster.LocalOverheadMessage(MessageType.Regular, 0x3B2,
503101); // That did not need to be unlocked.
else if (cont.LockLevel == 0)
Caster.SendLocalizedMessage(501666); // You can't unlock that!
else
{
LockableContainer cont = (LockableContainer)o;
int level = (int)(Caster.Skills.Magery.Value * 0.8) - 4;
if (BaseHouse.CheckSecured(cont))
if (level >= cont.RequiredSkill &&
!(cont is TreasureMapChest chest && chest.Level > 2))
{
from.SendLocalizedMessage(503098); // You cannot cast this on a secure item.
}
else if (!cont.Locked)
{
from.LocalOverheadMessage(MessageType.Regular, 0x3B2,
503101); // That did not need to be unlocked.
}
else if (cont.LockLevel == 0)
{
from.SendLocalizedMessage(501666); // You can't unlock that!
cont.Locked = false;
if (cont.LockLevel == -255)
cont.LockLevel = cont.RequiredSkill - 10;
}
else
{
int level = (int)(from.Skills.Magery.Value * 0.8) - 4;
if (level >= cont.RequiredSkill &&
!(cont is TreasureMapChest chest && chest.Level > 2))
{
cont.Locked = false;
if (cont.LockLevel == -255)
cont.LockLevel = cont.RequiredSkill - 10;
}
else
{
from.LocalOverheadMessage(MessageType.Regular, 0x3B2,
503099); // My spell does not seem to have an effect on that lock.
}
}
Caster.LocalOverheadMessage(MessageType.Regular, 0x3B2,
503099); // My spell does not seem to have an effect on that lock.
}
}
m_Owner.FinishSequence();
}
protected override void OnTargetFinish(Mobile from)
{
m_Owner.FinishSequence();
}
FinishSequence();
}
}
}

View file

@ -5,7 +5,7 @@ using Server.Targeting;
namespace Server.Spells.Third
{
public class WallOfStoneSpell : MagerySpell
public class WallOfStoneSpell : MagerySpell, ISpellTargetingPoint3D
{
private static SpellInfo m_Info = new SpellInfo(
"Wall of Stone", "In Sanct Ylem",
@ -24,7 +24,7 @@ namespace Server.Spells.Third
public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetPoint3D(this, TargetFlags.None, Core.ML ? 10 : 12);
}
public void Target(IPoint3D p)
@ -189,26 +189,5 @@ namespace Server.Spells.Third
}
}
}
private class InternalTarget : Target
{
private WallOfStoneSpell m_Owner;
public InternalTarget(WallOfStoneSpell owner) : base(Core.ML ? 10 : 12, true, TargetFlags.None)
{
m_Owner = owner;
}
protected override void OnTarget(Mobile from, object o)
{
if (o is IPoint3D d)
m_Owner.Target(d);
}
protected override void OnTargetFinish(Mobile from)
{
m_Owner.FinishSequence();
}
}
}
}