Example #1
0
        private void PrepareExplicitTarget()
        {
            ExplicitTargets.Source = Caster.Position;

            // initializes client-provided targets, corrects and automatically attempts to set required target.
            bool targetsUnits = SpellInfo.ExplicitCastTargets.HasAnyFlag(SpellCastTargetFlags.UnitMask);

            if (ExplicitTargets.Target != null && !targetsUnits)
            {
                ExplicitTargets.Target = null;
            }

            if (SpellInfo.ExplicitTargetType == SpellExplicitTargetType.Caster)
            {
                ExplicitTargets.Target = Caster;
            }

            // try to select correct unit target if not provided by client
            if (ExplicitTargets.Target == null && targetsUnits)
            {
                // try to use player selection as target, it has to be valid target for the spell
                if (Caster is Player playerCaster && playerCaster.Target is Unit playerTarget)
                {
                    if (SpellInfo.CheckExplicitTarget(Caster, playerTarget) == SpellCastResult.Success)
                    {
                        ExplicitTargets.Target = playerTarget;
                    }
                }

                // didn't find anything, try to use self as target
                if (ExplicitTargets.Target == null && SpellInfo.ExplicitCastTargets.HasAnyFlag(SpellCastTargetFlags.UnitAlly))
                {
                    ExplicitTargets.Target = Caster;
                }
            }

            if (ExplicitTargets.Target != null && SpellInfo.HasAttribute(SpellCustomAttributes.LaunchSourceIsExplicit))
            {
                ExplicitTargets.Source = ExplicitTargets.Target.Position;
            }
        }
Example #2
0
        private SpellCastResult ValidateCast()
        {
            if (spellCastFlags.HasTargetFlag(SpellCastFlags.TriggeredByAura))
            {
                return(SpellCastResult.Success);
            }

            if (Caster.HasState(UnitControlState.Stunned) && !SpellInfo.HasAttribute(SpellExtraAttributes.UsableWhileStunned))
            {
                return(SpellCastResult.Stunned);
            }

            if (Caster.HasState(UnitControlState.Confused) && !SpellInfo.HasAttribute(SpellExtraAttributes.UsableWhileConfused))
            {
                return(SpellCastResult.Confused);
            }

            if (Caster.HasState(UnitControlState.Fleeing) && !SpellInfo.HasAttribute(SpellExtraAttributes.UsableWhileFeared))
            {
                return(SpellCastResult.Fleeing);
            }

            if (SpellInfo.PreventionType != 0)
            {
                if (SpellInfo.PreventionType.HasTargetFlag(SpellPreventionType.Pacify) && Caster.HasFlag(UnitFlags.Pacified))
                {
                    return(SpellCastResult.Silenced);
                }

                if (SpellInfo.PreventionType.HasTargetFlag(SpellPreventionType.Silence) && Caster.HasFlag(UnitFlags.Silenced))
                {
                    return(SpellCastResult.Pacified);
                }
            }

            // check death state
            if (!Caster.IsAlive && !SpellInfo.IsPassive() && !SpellInfo.HasAttribute(SpellAttributes.CastableWhileDead))
            {
                return(SpellCastResult.CasterDead);
            }

            // check cooldowns to prevent cheating
            if (!SpellInfo.IsPassive() && !Caster.SpellHistory.IsReady(SpellInfo))
            {
                return(SpellCastResult.NotReady);
            }

            // check global cooldown
            if (!spellCastFlags.HasTargetFlag(SpellCastFlags.IgnoreGcd) && Caster.SpellHistory.HasGlobalCooldown)
            {
                return(SpellCastResult.NotReady);
            }

            // check if already casting
            if (Caster.SpellCast.IsCasting && !SpellInfo.HasAttribute(SpellExtraAttributes.CanCastWhileCasting))
            {
                return(SpellCastResult.NotReady);
            }

            SpellCastResult castResult = ValidateRange();

            if (castResult != SpellCastResult.Success)
            {
                return(castResult);
            }

            if (!spellCastFlags.HasTargetFlag(SpellCastFlags.IgnoreTargetCheck))
            {
                castResult = SpellInfo.CheckExplicitTarget(Caster, ExplicitTargets.Target);
                if (castResult != SpellCastResult.Success)
                {
                    return(castResult);
                }

                if (ExplicitTargets.Target != null)
                {
                    castResult = SpellInfo.CheckTarget(Caster, ExplicitTargets.Target, this, false);
                    if (castResult != SpellCastResult.Success)
                    {
                        return(castResult);
                    }
                }
            }

            return(SpellCastResult.Success);
        }
Example #3
0
        private SpellCastResult ValidateCast()
        {
            if (spellCastFlags.HasTargetFlag(SpellCastFlags.TriggeredByAura))
            {
                return(SpellCastResult.Success);
            }

            if (Caster is Player player && !player.PlayerSpells.HasKnownSpell(SpellInfo))
            {
                return(SpellCastResult.NotKnown);
            }

            // check death state
            if (!Caster.IsAlive && !SpellInfo.IsPassive && !SpellInfo.HasAttribute(SpellAttributes.CastableWhileDead))
            {
                return(SpellCastResult.CasterDead);
            }

            // check cooldowns to prevent cheating
            if (!SpellInfo.IsPassive && !Caster.SpellHistory.IsReady(SpellInfo))
            {
                return(SpellCastResult.NotReady);
            }

            // check global cooldown
            if (!spellCastFlags.HasTargetFlag(SpellCastFlags.IgnoreGcd) && Caster.SpellHistory.HasGlobalCooldown)
            {
                return(SpellCastResult.NotReady);
            }

            // check if already casting
            if (Caster.SpellCast.IsCasting && !SpellInfo.HasAttribute(SpellExtraAttributes.CanCastWhileCasting))
            {
                return(SpellCastResult.NotReady);
            }

            SpellCastResult castResult;

            if (!spellCastFlags.HasTargetFlag(SpellCastFlags.IgnoreTargetCheck))
            {
                castResult = SpellInfo.CheckExplicitTarget(Caster, ExplicitTargets.Target);
                if (castResult != SpellCastResult.Success)
                {
                    return(castResult);
                }

                if (ExplicitTargets.Target != null)
                {
                    castResult = SpellInfo.CheckTarget(Caster, ExplicitTargets.Target, this, false);
                    if (castResult != SpellCastResult.Success)
                    {
                        return(castResult);
                    }
                }
            }

            castResult = ValidateRange();
            if (castResult != SpellCastResult.Success)
            {
                return(castResult);
            }

            castResult = ValidateAuras();
            if (castResult != SpellCastResult.Success)
            {
                return(castResult);
            }

            return(SpellCastResult.Success);
        }