Skip to content

Commit 4a2b388

Browse files
committed
shortcircuit depending on spell cast failure reason
(this also makes it easier when looking for reasons in the debugger)
1 parent 93ac10f commit 4a2b388

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

Intersect.Server.Core/Entities/Player.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Intersect.Collections.Slotting;
77
using Intersect.Core;
88
using Intersect.Enums;
9+
using Intersect.Framework;
910
using Intersect.Framework.Core;
1011
using Intersect.Framework.Core.GameObjects.Variables;
1112
using Intersect.GameObjects;
@@ -5686,8 +5687,36 @@ public void UseSpell(int spellSlot, Entity target, bool softRetargetOnSelfCast)
56865687
return;
56875688
}
56885689

5689-
if (!CanCastSpell(spellDescriptor, target, true, softRetargetOnSelfCast, out _))
5690+
if (!CanCastSpell(spellDescriptor, target, true, softRetargetOnSelfCast, out var spellCastFailureReason))
56905691
{
5692+
switch (spellCastFailureReason)
5693+
{
5694+
case SpellCastFailureReason.InvalidSpell:
5695+
case SpellCastFailureReason.InsufficientHP:
5696+
case SpellCastFailureReason.InsufficientMP:
5697+
case SpellCastFailureReason.InvalidTarget:
5698+
case SpellCastFailureReason.InvalidProjectile:
5699+
case SpellCastFailureReason.InsufficientItems:
5700+
case SpellCastFailureReason.OutOfRange:
5701+
case SpellCastFailureReason.ConditionsNotMet:
5702+
case SpellCastFailureReason.OnCooldown:
5703+
// There's no logical reason for the answer to change in any of these cases, just abort
5704+
return;
5705+
5706+
case SpellCastFailureReason.Silenced:
5707+
case SpellCastFailureReason.Stunned:
5708+
case SpellCastFailureReason.Asleep:
5709+
// Leaving these three in a group for now because they _might not_ be reasons to abort all spells
5710+
break;
5711+
5712+
case SpellCastFailureReason.Snared:
5713+
case SpellCastFailureReason.None:
5714+
// Probably aren't hard blocking things
5715+
break;
5716+
5717+
default: throw Exceptions.UnreachableInvalidEnum(spellCastFailureReason);
5718+
}
5719+
56915720
if (!spellDescriptor.Combat.Friendly)
56925721
{
56935722
return;

0 commit comments

Comments
 (0)