public static SpellCheckCastResult PrepareSpell(this Unit u, SpellCast spell)
        {
            spell.Initialize();
            SpellCheckCastResult reason = u.CanCast(spell, true);

            if (u.SpellCast.ContainsKey(spell.SpellType) && !u.SpellCast[spell.SpellType].IsFinished)
            {
                reason = SpellCheckCastResult.SPELL_FAILED_SPELL_IN_PROGRESS;
            }

            if (reason != SpellCheckCastResult.SPELL_CAST_OK)
            {
                u.SendCastResult(reason, spell.Spell.Id);
                return(reason);
            }

            spell.SendSpellStart();

            if (spell.Caster.IsTypeOf(ObjectTypes.TYPE_UNIT) && !spell.Caster.IsTypeOf(ObjectTypes.TYPE_PLAYER))
            {
                Creature unit = ((Creature)spell.Caster);
                if (spell.Targets.Target != null)
                {
                    unit.TurnTo(spell.Targets.Target.Location);
                }
                else if (spell.Targets.TargetMask.HasFlag((uint)SpellTargetType.TARGET_TYPE_LOCATION))
                {
                    unit.TurnTo(spell.Targets.TargetLocation);
                }
            }

            spell.State = SpellState.SPELL_STATE_CASTING;
            u.SpellCast[spell.SpellType] = spell;

            if (spell.Duration > 0)
            {
                u.ChannelSpell  = spell.Spell.Id;
                u.ChannelObject = spell.Targets.Target.Guid;
                GridManager.Instance.SendSurrounding(u.BuildUpdate(), u);

                if (u.IsTypeOf(ObjectTypes.TYPE_PLAYER))
                {
                    PacketWriter channel = new PacketWriter(Opcodes.MSG_CHANNEL_START);
                    channel.WriteUInt32(spell.Spell.Id);
                    channel.WriteInt32(spell.Duration * 1000);
                    ((Player)u).Client.Send(channel);
                }
            }
            return(SpellCheckCastResult.SPELL_CAST_OK);
        }
Beispiel #2
0
        [Rpc(61, false)]//PerformSkill
        private void RPC_061(NetMessage message, NetMessageInfo info)
        {
            m_target.OnDeserialize(message);
            var castResult = SpellCastResult.Fail;

            if (CanCast(m_target.SpellID, m_target.Upgrade))
            {
                castResult = m_cast.Initialize(m_target.SpellID, m_target.Upgrade, m_target);
            }
            if (castResult != SpellCastResult.OK)
            {
                m_cast_args.Result = castResult;
                m_owner.Notify(SpellCastArgs.FailEvent, m_cast_args);
            }
        }