Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleans up Spell Targeting #36

Merged
merged 6 commits into from Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion Scripts/Engines/BulkOrders/LargeBOD.cs
@@ -1,4 +1,3 @@
using System.Collections.Generic;
using Server.Mobiles;

namespace Server.Engines.BulkOrders
Expand Down
1 change: 0 additions & 1 deletion Scripts/Engines/BulkOrders/LargeSmithBOD.cs
@@ -1,4 +1,3 @@
using System.Collections.Generic;
using Mat = Server.Engines.BulkOrders.BulkMaterialType;

namespace Server.Engines.BulkOrders
Expand Down
1 change: 0 additions & 1 deletion Scripts/Engines/BulkOrders/LargeTailorBOD.cs
@@ -1,4 +1,3 @@
using System.Collections.Generic;
using Mat = Server.Engines.BulkOrders.BulkMaterialType;

namespace Server.Engines.BulkOrders
Expand Down
1 change: 0 additions & 1 deletion Scripts/Engines/BulkOrders/SmallBOD.cs
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using Server.Items;
using Server.Mobiles;

Expand Down
2 changes: 1 addition & 1 deletion Scripts/Engines/Factions/Mobiles/Guards/GuardAI.cs
Expand Up @@ -469,7 +469,7 @@ public override bool Think()
if (m_Guard.Map == toHarm.Map && (targ.Range < 0 || m_Guard.InRange(toHarm, targ.Range)) &&
m_Guard.CanSee(toHarm) && m_Guard.InLOS(toHarm))
targ.Invoke(m_Guard, toHarm);
else if (targ is DispelSpell.InternalTarget)
else if ((targ as ISpellTarget)?.Spell is DispelSpell)
targ.Cancel(m_Guard, TargetCancelType.Canceled);
}
else if ((targ.Flags & TargetFlags.Beneficial) != 0)
Expand Down
2 changes: 0 additions & 2 deletions Scripts/Engines/Quests/Core/QuestItemInfo.cs
@@ -1,5 +1,3 @@
using Server.Gumps;

namespace Server.Engines.Quests
{
public class QuestItemInfo
Expand Down
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Server.Spells;
using Server.Targeting;

Expand Down
9 changes: 6 additions & 3 deletions Scripts/Mobiles/AI/HealerAI.cs
@@ -1,3 +1,4 @@
using Server.Spells;
using Server.Spells.First;
using Server.Spells.Fourth;
using Server.Spells.Second;
Expand Down Expand Up @@ -28,11 +29,13 @@ public override bool Think()

if (targ != null)
{
if (targ is CureSpell.InternalTarget)
ISpellTarget spellTarg = targ as ISpellTarget;

if (spellTarg?.Spell is CureSpell)
ProcessTarget(targ, m_ACure);
else if (targ is GreaterHealSpell.InternalTarget)
else if (spellTarg?.Spell is GreaterHealSpell)
ProcessTarget(targ, m_AGHeal);
else if (targ is HealSpell.InternalTarget)
else if (spellTarg?.Spell is HealSpell)
ProcessTarget(targ, m_ALHeal);
else
targ.Cancel(m_Mobile, TargetCancelType.Canceled);
Expand Down
12 changes: 7 additions & 5 deletions Scripts/Mobiles/AI/MageAI.cs
Expand Up @@ -960,11 +960,13 @@ private bool ProcessTarget()
if (targ == null)
return false;

bool isReveal = targ is RevealSpell.InternalTarget;
bool isDispel = targ is DispelSpell.InternalTarget;
bool isParalyze = targ is ParalyzeSpell.InternalTarget;
bool isTeleport = targ is TeleportSpell.InternalTarget;
bool isInvisible = targ is InvisibilitySpell.InternalTarget;
ISpellTarget spellTarg = targ as ISpellTarget;

bool isReveal = spellTarg?.Spell is RevealSpell;
bool isDispel = spellTarg?.Spell is DispelSpell;
bool isParalyze = spellTarg?.Spell is ParalyzeSpell;
bool isTeleport = spellTarg?.Spell is TeleportSpell;
bool isInvisible = spellTarg?.Spell is InvisibilitySpell;
bool teleportAway = false;

Mobile toTarget;
Expand Down
18 changes: 3 additions & 15 deletions Scripts/Mobiles/Monsters/AOS/Revenant.cs
Expand Up @@ -51,20 +51,8 @@ public class Revenant : BaseCreature

VirtualArmor = 32;

Item shroud = new DeathShroud();

shroud.Hue = 0x455;

shroud.Movable = false;

AddItem(shroud);

Halberd weapon = new Halberd();

weapon.Hue = 1;
weapon.Movable = false;

AddItem(weapon);
AddItem(new DeathShroud { Hue = 0x455, Movable = false });
AddItem(new Halberd { Hue = 1, Movable = false });
}

public Revenant(Serial serial) : base(serial)
Expand Down Expand Up @@ -181,4 +169,4 @@ public override void Deserialize(GenericReader reader)
Delete();
}
}
}
}
6 changes: 6 additions & 0 deletions Scripts/Scripts.csproj
Expand Up @@ -3269,6 +3269,12 @@
<Compile Include="Spells\Sixth\MassCurse.cs" />
<Compile Include="Spells\Sixth\ParalyzeField.cs" />
<Compile Include="Spells\Sixth\Reveal.cs" />
<Compile Include="Spells\Targeting\IRecallSpell.cs" />
<Compile Include="Spells\Targeting\ISpellTarget.cs" />
<Compile Include="Spells\Targeting\SpellTargetPoint3D.cs" />
<Compile Include="Spells\Targeting\SpellTargetItem.cs" />
<Compile Include="Spells\Targeting\SpellTargetMobile.cs" />
<Compile Include="Spells\Targeting\RecallSpellTarget.cs" />
<Compile Include="Spells\Spellweaving\ArcaneCircle.cs" />
<Compile Include="Spells\Spellweaving\ArcaneForm.cs" />
<Compile Include="Spells\Spellweaving\ArcaneSummon.cs" />
Expand Down
15 changes: 3 additions & 12 deletions Scripts/Spells/Base/MagerySpell.cs
Expand Up @@ -20,13 +20,7 @@ public MagerySpell(Mobile caster, Item scroll, SpellInfo info)

public override bool ConsumeReagents()
{
if (base.ConsumeReagents())
return true;

if (ArcaneGem.ConsumeCharges(Caster, Core.SE ? 1 : 1 + (int)Circle))
return true;

return false;
return base.ConsumeReagents() || ArcaneGem.ConsumeCharges(Caster, Core.SE ? 1 : 1 + (int)Circle);
}

public override void GetCastSkills(out double min, out double max)
Expand All @@ -44,10 +38,7 @@ public override void GetCastSkills(out double min, out double max)

public override int GetMana()
{
if (Scroll is BaseWand)
return 0;

return m_ManaTable[(int)Circle];
return Scroll is BaseWand ? 0 : m_ManaTable[(int)Circle];
}

public override double GetResistSkill(Mobile m)
Expand Down Expand Up @@ -108,4 +99,4 @@ public override TimeSpan GetCastDelay()
return base.GetCastDelay();
}
}
}
}
30 changes: 5 additions & 25 deletions Scripts/Spells/Chivalry/CleanseByFire.cs
Expand Up @@ -4,7 +4,7 @@

namespace Server.Spells.Chivalry
{
public class CleanseByFireSpell : PaladinSpell
public class CleanseByFireSpell : PaladinSpell, ISpellTargetingMobile
{
private static SpellInfo m_Info = new SpellInfo(
"Cleanse By Fire", "Expor Flamus",
Expand Down Expand Up @@ -36,15 +36,16 @@ public override bool CheckCast()

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 (!m.Poisoned)
{
Caster.SendLocalizedMessage(1060176); // That creature is not poisoned!
}
else if (CheckBSequence(m))
{
SpellHelper.Turn(Caster, m);
Expand Down Expand Up @@ -101,26 +102,5 @@ public void Target(Mobile m)

FinishSequence();
}

private class InternalTarget : Target
{
private CleanseByFireSpell m_Owner;

public InternalTarget(CleanseByFireSpell 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();
}
}
}
}
38 changes: 5 additions & 33 deletions Scripts/Spells/Chivalry/CloseWounds.cs
Expand Up @@ -7,7 +7,7 @@

namespace Server.Spells.Chivalry
{
public class CloseWoundsSpell : PaladinSpell
public class CloseWoundsSpell : PaladinSpell, ISpellTargetingMobile
{
private static SpellInfo m_Info = new SpellInfo(
"Close Wounds", "Obsu Vulni",
Expand Down Expand Up @@ -39,31 +39,24 @@ public override bool CheckCast()

public override void OnCast()
{
Caster.Target = new InternalTarget(this);
Caster.Target = new SpellTargetMobile(this, TargetFlags.Beneficial);
}

public void Target(Mobile m)
{
if (m == null)
return;

if (!Caster.InRange(m, 2))
{
Caster.SendLocalizedMessage(1060178); // You are too far away to perform that action!
}
else if (m is BaseCreature creature && creature.IsAnimatedDead)
{
Caster.SendLocalizedMessage(1061654); // You cannot heal that which is not alive.
}
else if (m.IsDeadBondedPet)
{
Caster.SendLocalizedMessage(1060177); // You cannot heal a creature that is already dead!
}
else if (m.Hits >= m.HitsMax)
{
Caster.SendLocalizedMessage(500955); // That being is not damaged!
}
else if (m.Poisoned || MortalStrike.IsWounded(m))
{
Caster.LocalOverheadMessage(MessageType.Regular, 0x3B2, Caster == m ? 1005000 : 1010398);
}
else if (CheckBSequence(m))
{
SpellHelper.Turn(Caster, m);
Expand All @@ -90,26 +83,5 @@ public void Target(Mobile m)

FinishSequence();
}

private class InternalTarget : Target
{
private CloseWoundsSpell m_Owner;

public InternalTarget(CloseWoundsSpell owner) : base(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();
}
}
}
}
30 changes: 6 additions & 24 deletions Scripts/Spells/Chivalry/RemoveCurse.cs
Expand Up @@ -7,7 +7,7 @@

namespace Server.Spells.Chivalry
{
public class RemoveCurseSpell : PaladinSpell
public class RemoveCurseSpell : PaladinSpell, ISpellTargetingMobile
{
private static SpellInfo m_Info = new SpellInfo(
"Remove Curse", "Extermo Vomica",
Expand Down Expand Up @@ -39,11 +39,14 @@ public override bool CheckCast()

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 (CheckBSequence(m))
{
SpellHelper.Turn(Caster, m);
Expand All @@ -54,7 +57,7 @@ public void Target(Mobile m)
* Chance of removing curse is affected by Caster's Karma.
*/

int chance = 0;
int chance;

if (Caster.Karma < -5000)
chance = 0;
Expand Down Expand Up @@ -116,26 +119,5 @@ public void Target(Mobile m)

FinishSequence();
}

private class InternalTarget : Target
{
private RemoveCurseSpell m_Owner;

public InternalTarget(RemoveCurseSpell 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();
}
}
}
}