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

Remove target reflection #1367

Merged
merged 16 commits into from
May 11, 2024
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
2 changes: 1 addition & 1 deletion Scripts/Items/Equipment/Instruments/BaseInstrument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ public static void PickInstrument(Mobile from, InstrumentPickedCallback callback
else
{
from.SendLocalizedMessage(500617); // What instrument shall you play?
from.BeginTarget(1, false, TargetFlags.None, new TargetStateCallback(OnPickedInstrument), callback);
Timer.DelayCall(() => from.BeginTarget(1, false, TargetFlags.None, new TargetStateCallback(OnPickedInstrument), callback));
}
}

Expand Down
3 changes: 1 addition & 2 deletions Scripts/Items/Equipment/Spellbooks/Spellbook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,8 @@ private static void Targeted_Spell(TargetedSpellEventArgs e)
}
else if (toI != null)
{
spell.InstantTarget = toI as IDamageableItem;
spell.InstantTarget = toI as IEntity;
}

spell.Cast();
}
}
Expand Down
31 changes: 22 additions & 9 deletions Scripts/Mobiles/PlayerMobile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -833,26 +833,39 @@ private static void Targeted_Skill(TargetedSkillEventArgs e)

from.TargetLocked = true;

if (e.SkillID == 35)
if (e.SkillID == (short)SkillName.Provocation)
{
AnimalTaming.DisableMessage = true;
AnimalTaming.DeferredTarget = false;
Provocation.DeferredSecondaryTarget = true;
InvokeTarget(e, from, target);
Provocation.DeferredSecondaryTarget = false;
}

if (from.UseSkill(e.SkillID))
{
from.Target?.Invoke(from, target);
}

if (e.SkillID == 35)
else if (e.SkillID == (short)SkillName.AnimalTaming)
{
AnimalTaming.DisableMessage = true;
AnimalTaming.DeferredTarget = false;
InvokeTarget(e, from, target);
AnimalTaming.DeferredTarget = true;
AnimalTaming.DisableMessage = false;

}
else
{
InvokeTarget(e, from, target);
}


from.TargetLocked = false;
}

private static void InvokeTarget(TargetedSkillEventArgs e, Mobile from, IEntity target)
{
if (from.UseSkill(e.SkillID))
{
from.Target?.Invoke(from, target);
}
}

public static void EquipMacro(EquipMacroEventArgs e)
{
if (e.Mobile is PlayerMobile pm && pm.Backpack != null && pm.Alive && e.List != null && e.List.Count > 0 && !pm.HasTrade)
Expand Down
16 changes: 15 additions & 1 deletion Scripts/Skills/Provocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ namespace Server.SkillHandlers
{
public class Provocation
{
public static bool DeferredSecondaryTarget { get; set; }

static Provocation()
{
DeferredSecondaryTarget = true;
}

public static void Initialize()
{
SkillInfo.Table[(int)SkillName.Provocation].Callback = OnUse;
Expand Down Expand Up @@ -65,7 +72,14 @@ protected override void OnTarget(Mobile from, object targeted)
m_Instrument.PlayInstrumentWell(from);
from.SendLocalizedMessage(1008085);
// You play your music and your target becomes angered. Whom do you wish them to attack?
from.Target = new InternalSecondTarget(from, m_Instrument, creature);
if (DeferredSecondaryTarget)
{
Timer.DelayCall(() => from.Target = new InternalSecondTarget(from, m_Instrument, creature));
}
else
{
from.Target = new InternalSecondTarget(from, m_Instrument, creature);
}
}
}
else
Expand Down
55 changes: 8 additions & 47 deletions Scripts/Spells/Base/Spell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
using Server.Targeting;
using System;
using System.Collections.Generic;
using System.Reflection;
using Server.Spells.SkillMasteries;


#endregion

namespace Server.Spells
Expand All @@ -26,7 +28,6 @@ public abstract class Spell : ISpell
private readonly SpellInfo m_Info;
private SpellState m_State;
private long m_CastTime;
private IDamageable m_InstantTarget;

public int ID => SpellRegistry.GetRegistryNumber(this);

Expand All @@ -40,7 +41,7 @@ public abstract class Spell : ISpell
public Item Scroll => m_Scroll;
public long CastTime => m_CastTime;

public IDamageable InstantTarget { get => m_InstantTarget; set => m_InstantTarget = value; }
public IEntity InstantTarget { get; set; }

public bool Disturbed { get; set; }

Expand Down Expand Up @@ -486,7 +487,7 @@ public virtual double GetSlayerDamageScalar(Mobile defender)

if (atkSlayer != null && atkSlayer == atkSlayer.Group.Super && atkSlayer.Group != SlayerGroup.Groups[6]) //Fey Slayers give 300% damage
isSuper = true;
else if (atkSlayer2 != null && atkSlayer2 == atkSlayer2.Group.Super && atkSlayer2.Group != SlayerGroup.Groups[6])
else if (atkSlayer2 != null && atkSlayer2 == atkSlayer2.Group.Super && atkSlayer2.Group != SlayerGroup.Groups[6])
isSuper = true;

scalar = isSuper ? 2.0 : 3.0;
Expand Down Expand Up @@ -785,10 +786,9 @@ private void SequenceSpell()
m_Caster.Region?.OnSpellCast(m_Caster, this);

m_Caster.NextSpellTime = Core.TickCount + (int)GetCastRecovery().TotalMilliseconds;

Target originalTarget = m_Caster.Target;

if (InstantTarget == null || !OnCastInstantTarget())
if (InstantTarget == null || !OnInstantCast(InstantTarget))
{
OnCast();
}
Expand All @@ -800,50 +800,11 @@ private void SequenceSpell()
}

#region Enhanced Client
public bool OnCastInstantTarget()
public virtual bool OnInstantCast(IEntity target)
{
if (InstantTarget == null)
return false;

Type spellType = GetType();

Type[] types = spellType.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

Type targetType = null;

for (var index = 0; index < types.Length; index++)
{
var t = types[index];

if (t.IsSubclassOf(typeof(Target)))
{
targetType = t;
break;
}
}

if (targetType != null)
{
Target t = null;

try
{
t = Activator.CreateInstance(targetType, this) as Target;
}
catch
{
LogBadConstructorForInstantTarget();
}

if (t != null)
{
t.Invoke(Caster, InstantTarget);
return true;
}
}

return false;
}

#endregion

public virtual void OnBeginCast()
Expand Down
14 changes: 14 additions & 0 deletions Scripts/Spells/Chivalry/CleanseByFire.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Server.Spells.Bushido;
using Server.Targeting;
using System;

Expand Down Expand Up @@ -25,6 +26,18 @@ public override void OnCast()
Caster.Target = new InternalTarget(this);
}

public override bool OnInstantCast(IEntity target)
{
Target t = new InternalTarget(this);
if (Caster.InRange(target, t.Range) && Caster.InLOS(target))
{
t.Invoke(Caster, target);
return true;
}
else
return false;
}

public override bool CheckDisturb(DisturbType type, bool firstCircle, bool resistable)
{
return true;
Expand Down Expand Up @@ -92,6 +105,7 @@ public void Target(Mobile m)
FinishSequence();
}


private class InternalTarget : Target
{
private readonly CleanseByFireSpell m_Owner;
Expand Down
13 changes: 13 additions & 0 deletions Scripts/Spells/Chivalry/CloseWounds.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Server.Mobiles;
using Server.Network;

using Server.Targeting;
using System;

Expand Down Expand Up @@ -32,6 +33,18 @@ public override void OnCast()
Caster.Target = new InternalTarget(this);
}

public override bool OnInstantCast(IEntity target)
{
Target t = new InternalTarget(this);
if (Caster.InRange(target, t.Range) && Caster.InLOS(target))
{
t.Invoke(Caster, target);
return true;
}
else
return false;
}

public void Target(Mobile m)
{
if (!Caster.InRange(m, 2))
Expand Down
13 changes: 13 additions & 0 deletions Scripts/Spells/Chivalry/RemoveCurse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Server.Items;

using Server.Spells.First;
using Server.Spells.Fourth;
using Server.Spells.Mysticism;
Expand Down Expand Up @@ -39,6 +40,18 @@ public override void OnCast()
Caster.Target = new InternalTarget(this);
}

public override bool OnInstantCast(IEntity target)
{
Target t = new InternalTarget(this);
if (Caster.InRange(target, t.Range) && Caster.InLOS(target))
{
t.Invoke(Caster, target);
return true;
}
else
return false;
}

public void Target(Mobile m)
{
if (CheckBSequence(m))
Expand Down
13 changes: 13 additions & 0 deletions Scripts/Spells/Chivalry/SacredJourney.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using Server.Engines.NewMagincia;


namespace Server.Spells.Chivalry
{
public class SacredJourneySpell : PaladinSpell
Expand Down Expand Up @@ -56,6 +57,18 @@ public override void OnCast()
}
}

public override bool OnInstantCast(IEntity target)
{
Target t = new InternalTarget(this);
if (Caster.InLOS(target))
{
t.Invoke(Caster, target);
return true;
}
else
return false;
}

public override bool CheckCast()
{
if (!base.CheckCast())
Expand Down
13 changes: 13 additions & 0 deletions Scripts/Spells/Eighth/EnergyVortex.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Server.Mobiles;

using Server.Targeting;
using System;

Expand Down Expand Up @@ -40,6 +41,18 @@ public override void OnCast()
Caster.Target = new InternalTarget(this);
}

public override bool OnInstantCast(IEntity target)
{
Target t = new InternalTarget(this);
if (Caster.InRange(target, t.Range) && Caster.InLOS(target))
{
t.Invoke(Caster, target);
return true;
}
else
return false;
}

public void Target(IPoint3D p)
{
Map map = Caster.Map;
Expand Down
13 changes: 13 additions & 0 deletions Scripts/Spells/Eighth/Resurrection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Server.Gumps;

using Server.Targeting;

namespace Server.Spells.Eighth
Expand All @@ -24,6 +25,18 @@ public override void OnCast()
Caster.Target = new InternalTarget(this);
}

public override bool OnInstantCast(IEntity target)
{
Target t = new InternalTarget(this);
if (Caster.InRange(target, t.Range) && Caster.InLOS(target))
{
t.Invoke(Caster, target);
return true;
}
else
return false;
}

public void Target(Mobile m)
{
if (!Caster.CanSee(m))
Expand Down
13 changes: 13 additions & 0 deletions Scripts/Spells/Fifth/BladeSpirits.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Server.Mobiles;

using Server.Targeting;
using System;

Expand Down Expand Up @@ -44,6 +45,18 @@ public override void OnCast()
Caster.Target = new InternalTarget(this);
}

public override bool OnInstantCast(IEntity target)
{
Target t = new InternalTarget(this);
if (Caster.InRange(target, t.Range) && Caster.InLOS(target))
{
t.Invoke(Caster, target);
return true;
}
else
return false;
}

public void Target(IPoint3D p)
{
Map map = Caster.Map;
Expand Down