Example #1
0
        private void ProcessTarget(SpellTargetEntry targetEntry)
        {
            if (targetEntry.Processed)
            {
                return;
            }

            targetEntry.Processed = true;
            if (targetEntry.Target.IsAlive != targetEntry.Alive)
            {
                return;
            }

            Unit caster = OriginalCaster ?? Caster;

            if (caster == null)
            {
                return;
            }

            SpellMissType missType = targetEntry.MissCondition;

            EffectDamage  = 0;
            EffectHealing = 0;

            Unit hitTarget = targetEntry.Target;

            if (missType == SpellMissType.Reflect && targetEntry.ReflectResult == SpellMissType.None)
            {
                hitTarget = Caster;
            }

            missType = ProcessSpellHit(hitTarget);

            if (missType != SpellMissType.None)
            {
                EffectDamage = 0;
            }

            EventHandler.ExecuteEvent(EventHandler.GlobalDispatcher, GameEvents.ServerSpellHit, Caster, hitTarget, SpellInfo, missType);

            if (EffectHealing > 0)
            {
                caster.Spells.HealBySpell(new SpellHealInfo(caster, targetEntry.Target, SpellInfo, (uint)EffectHealing, targetEntry.Crit));
            }
            else if (EffectDamage > 0)
            {
                caster.Spells.DamageBySpell(new SpellDamageInfo(caster, targetEntry.Target, SpellInfo, (uint)EffectDamage, targetEntry.Crit, SpellDamageType.Direct), this);
            }

            if (missType == SpellMissType.None)
            {
                for (int effectIndex = 0; effectIndex < SpellInfo.Effects.Count; effectIndex++)
                {
                    SpellInfo.Effects[effectIndex].Handle(this, effectIndex, hitTarget, SpellEffectHandleMode.HitFinal);
                }
            }
        }
Example #2
0
        private SpellMissType ProcessSpellHit(SpellTargetEntry targetEntry)
        {
            if (targetEntry.Target.IsImmuneToSpell(SpellInfo, Caster))
            {
                return(SpellMissType.Immune);
            }

            for (int effectIndex = 0; effectIndex < SpellInfo.Effects.Count; effectIndex++)
            {
                if (targetEntry.EffectMask.HasBit(effectIndex))
                {
                    SpellInfo.Effects[effectIndex].Handle(this, effectIndex, targetEntry.Target, SpellEffectHandleMode.HitStart);
                }
            }

            return(SpellMissType.None);
        }
Example #3
0
        internal void AddTargetIfNotExists(Unit target, int effectMask)
        {
            if (!targetEntryByTarget.TryGetValue(target, out SpellTargetEntry targetEntry))
            {
                var newEntry = new SpellTargetEntry
                {
                    Target     = target,
                    Processed  = false,
                    Alive      = target.IsAlive,
                    Crit       = false,
                    EffectMask = effectMask
                };

                targetEntryByTarget.Add(target, newEntry);
                Entries.Add(newEntry);
            }
            else
            {
                targetEntry.EffectMask |= effectMask;
            }
        }
Example #4
0
        private void ProcessTarget(SpellTargetEntry targetEntry)
        {
            if (targetEntry.Processed)
            {
                return;
            }

            targetEntry.Processed = true;
            if (targetEntry.Target.IsAlive != targetEntry.Alive)
            {
                return;
            }

            Unit caster = OriginalCaster ?? Caster;

            if (caster == null)
            {
                return;
            }

            SpellMissType missType = targetEntry.MissCondition;

            EffectDamage  = 0;
            EffectHealing = 0;

            Unit hitTarget = targetEntry.Target;

            if (missType == SpellMissType.Reflect && targetEntry.ReflectResult == SpellMissType.None)
            {
                hitTarget = Caster;
            }

            missType = ProcessSpellHit(targetEntry);

            if (missType != SpellMissType.None)
            {
                EffectDamage = 0;
            }

            if (!spellValue.CastFlags.HasTargetFlag(SpellCastFlags.DontReportCastSuccess))
            {
                EventHandler.ExecuteEvent(GameEvents.ServerSpellHit, Caster, hitTarget, SpellInfo, missType);
            }

            Caster.Spells.ApplySpellTriggers(SpellTriggerFlags.DoneSpellHit, hitTarget, this);

            if (EffectHealing > 0)
            {
                caster.Spells.HealBySpell(new SpellHealInfo(caster, targetEntry.Target, SpellInfo, (uint)EffectHealing, targetEntry.Crit));
            }
            else if (EffectDamage > 0)
            {
                caster.Spells.DamageBySpell(new SpellDamageInfo(caster, targetEntry.Target, SpellInfo, (uint)EffectDamage, targetEntry.Crit, SpellDamageType.Direct), this);
            }

            if (missType == SpellMissType.None)
            {
                for (int effectIndex = 0; effectIndex < SpellInfo.Effects.Count; effectIndex++)
                {
                    if (targetEntry.EffectMask.HasBit(effectIndex))
                    {
                        SpellInfo.Effects[effectIndex].Handle(this, effectIndex, hitTarget, SpellEffectHandleMode.HitFinal);
                    }
                }
            }
            else if (missType == SpellMissType.Immune && SpellInfo.SomeEffectsIgnoreSpellImmunity)
            {
                for (int effectIndex = 0; effectIndex < SpellInfo.Effects.Count; effectIndex++)
                {
                    if (targetEntry.EffectMask.HasBit(effectIndex) && SpellInfo.Effects[effectIndex].IgnoresSpellImmunity)
                    {
                        SpellInfo.Effects[effectIndex].Handle(this, effectIndex, hitTarget, SpellEffectHandleMode.HitFinal);
                    }
                }
            }

            if (missType != SpellMissType.Evade && !caster.IsFriendlyTo(hitTarget) && !SpellInfo.IsPositive)
            {
                caster.Combat.StartCombatWith(hitTarget);
            }
        }