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); }