Beispiel #1
0
        /// <summary>
        /// Called when the character casts the spell
        /// </summary>
        public virtual bool Cast(float x, float y, float x2, float y2, AttackableUnit u = null)
        {
            if (HasEmptyScript)
            {
                return(false);
            }

            var stats = Owner.Stats;

            if (SpellData.ManaCost[Level] * (1 - stats.SpellCostReduction) >= stats.CurrentMana ||
                State != SpellState.STATE_READY)
            {
                return(false);
            }

            if (_game.Config.ManaCostsEnabled)
            {
                stats.CurrentMana = stats.CurrentMana - SpellData.ManaCost[Level] * (1 - stats.SpellCostReduction);
            }

            X               = x;
            Y               = y;
            X2              = x2;
            Y2              = y2;
            Target          = u;
            FutureProjNetId = _networkIdManager.GetNewNetId();
            SpellNetId      = _networkIdManager.GetNewNetId();

            if (SpellData.TargettingType == 1 && Target != null && Target.GetDistanceTo(Owner) > SpellData.CastRange[Level])
            {
                return(false);
            }

            _spellGameScript.OnStartCasting(Owner, this, Target);

            if (SpellData.GetCastTime() > 0 && (SpellData.Flags & (int)SpellFlag.SPELL_FLAG_INSTANT_CAST) == 0)
            {
                Owner.SetPosition(Owner.X, Owner.Y); //stop moving serverside too. TODO: check for each spell if they stop movement or not
                State           = SpellState.STATE_CASTING;
                CurrentCastTime = SpellData.GetCastTime();
            }
            else
            {
                FinishCasting();
            }

            _game.PacketNotifier.NotifyCastSpell(_game.Map.NavGrid, this, x, y, x2, y2, FutureProjNetId, SpellNetId);
            return(true);
        }