예제 #1
0
        void DoSpellsListCasts(long diff)
        {
            bool bDontCast = false;

            foreach (CreatureSpellsEntry spell in spellsList.spells)
            {
                if (spell.cooldown <= diff)
                {
                    // Cooldown has expired.
                    spell.cooldown = 0;

                    // Prevent casting multiple spells in the same update. Only update timers.
                    if ((spell.data.castFlags & ((byte)CastFlags.CF_TRIGGERED | (byte)CastFlags.CF_INTERRUPT_PREVIOUS)) == 0)
                    {
                        if (bDontCast || IsNonMeleeSpellCasted())
                        {
                            continue;
                        }
                    }

                    if (!DBC.Spell.ContainsKey(spell.data.spellId))
                    {
                        continue;
                    }

                    Unit target = ScriptMgr.GetTargetByType(this, this, spell.data.castTarget, spell.data.targetParam1 != 0 ? spell.data.targetParam1 : (uint)DBC.Spell[spell.data.spellId].GetMaxCastRange(), spell.data.targetParam2)?.ToUnit();
                    SpellCheckCastResult result = ForceCastSpell(spell.data.spellId, target);
                    Console.WriteLine("[Creature " + this.Entry.ToString() + "][Spell " + spell.data.spellId.ToString() + "] Cast Result is " + result.ToString());

                    switch (result)
                    {
                    case SpellCheckCastResult.SPELL_CAST_OK:
                    {
                        bDontCast      = (spell.data.castFlags & (byte)CastFlags.CF_TRIGGERED) == 0;
                        spell.cooldown = (long)(new Random().Next((int)spell.data.delayRepeatMin, (int)spell.data.delayRepeatMax));

                        if ((spell.data.castFlags & (byte)CastFlags.CF_MAIN_RANGED_SPELL) != 0)
                        {
                            //if (IsMoving())
                            //    StopMoving();

                            SetCombatMovement(false);
                            SetMeleeAttack(false);
                        }

                        // If there is a script for this spell, run it.
                        // if (spell.data.scriptId != 0)
                        //     m_creature->GetMap()->ScriptsStart(sCreatureSpellScripts, spell.data.scriptId, this, pTarget);
                        break;
                    }

                    //case SpellCheckCastResult.SPELL_FAILED_FLEEING:
                    case SpellCheckCastResult.SPELL_FAILED_SPELL_IN_PROGRESS:
                    {
                        // Do nothing so it will try again on next update.
                        break;
                    }

                    case SpellCheckCastResult.SPELL_FAILED_TRY_AGAIN:
                    {
                        // Chance roll failed, so we reset cooldown.
                        spell.cooldown = (long)(new Random().Next((int)spell.data.delayRepeatMin, (int)spell.data.delayRepeatMax));
                        if ((spell.data.castFlags & (byte)CastFlags.CF_MAIN_RANGED_SPELL) != 0)
                        {
                            SetCombatMovement(true);
                            SetMeleeAttack(true);
                        }
                        break;
                    }

                    default:
                    {
                        // other error
                        if ((spell.data.castFlags & (byte)CastFlags.CF_MAIN_RANGED_SPELL) != 0)
                        {
                            SetCombatMovement(true);
                            SetMeleeAttack(true);
                        }
                        break;
                    }
                    }
                }
                else
                {
                    spell.cooldown -= diff;
                }
            }
        }