Esempio n. 1
0
        public void CastSpell(byte spellSlot, Vector2 position, Vector2 endPosition, AttackableUnit target)
        {
            AttackableUnit autoAttackTarget = null;

            if (AttackManager.IsAttacking)
            {
                autoAttackTarget = AttackManager.GetTarget();
            }

            Action onChannelOverAction = () =>
            {
                if (autoAttackTarget != null)
                {
                    TryBasicAttack(autoAttackTarget);
                }
                PathManager.MoveToPendingPoint();
            };

            if (IsMoving)
            {
                PathManager.PendingPoint = PathManager.GetWaypoints().Last();
            }
            else
            {
                PathManager.PendingPoint = null;
            }



            Spell spell = SpellManager.GetSpell(spellSlot);

            AttackableUnit[] targets = target != null ? new AttackableUnit[] { target } : new AttackableUnit[0];

            SpellCastResultEnum result = spell.Cast(position, endPosition, target, onChannelOverAction);

            if (result == SpellCastResultEnum.OK)
            {
                var netId = spell.GetNextProjectileId();

                Game.Send(new CastSpellAnswerMessage(NetId, Environment.TickCount, false, spell.GetCastInformations(
                                                         new Vector3(position.X, position.Y, Game.Map.Record.GetZ(position) + 100),
                                                         new Vector3(endPosition.X, endPosition.Y, Game.Map.Record.GetZ(endPosition) + 100),
                                                         spell.Record.Name, netId, targets)));
            }
            else
            {
                /* if (result == SpellCastResultEnum.Failed_NoScript)
                 *  NotifyWaypoints(); // we correctly notify to client stop moving (cast spell ans, stop the movement) */
            }
        }
        private bool CloseCombat(SpellLevelRecord level, MapPoint castPoint, string rawZone, ushort weaponGId = 0)
        {
            SpellCastResultEnum canCast = this.CanCastSpell(level, this.CellId, castPoint.CellId);

            if (canCast != SpellCastResultEnum.Ok)
            {
                this.OnSpellCastFailed(canCast, level);
                return(false);
            }

            this.OnWeaponUsedEvt?.Invoke(this);

            this.Fight.SequencesManager.StartSequence(SequenceTypeEnum.SEQUENCE_WEAPON);

            FightSpellCastCriticalEnum fightSpellCastCriticalEnum = this.RollCriticalDice(level);
            bool criticalHit = fightSpellCastCriticalEnum == FightSpellCastCriticalEnum.CRITICAL_HIT;

            EffectInstance[] effects = (criticalHit ? level.CriticalEffects : level.Effects).ToArray();


            this.Fight.Send(new GameActionFightCloseCombatMessage((ushort)ActionsEnum.ACTION_FIGHT_CLOSE_COMBAT,
                                                                  this.Id,
                                                                  false,
                                                                  false,
                                                                  0,
                                                                  castPoint.CellId,
                                                                  (sbyte)fightSpellCastCriticalEnum,
                                                                  weaponGId));

            SpellEffectsManager.Instance.HandleEffects(this,
                                                       effects,
                                                       level,
                                                       castPoint,
                                                       rawZone,
                                                       WeaponManager.WeaponTargetMask,
                                                       criticalHit);


            this.UseAp(level.ApCost);

            this.OnSpellCasted(level, this.CellId, fightSpellCastCriticalEnum);
            this.Fight.SequencesManager.EndSequence(SequenceTypeEnum.SEQUENCE_WEAPON);
            this.Fight.CheckDeads();
            this.Fight.CheckFightEnd();
            return(true);
        }
Esempio n. 3
0
        public override void OnSpellCastFailed(SpellCastResultEnum result, SpellLevelRecord level)
        {
            Character character = GetCharacterPlaying();

            switch (result)
            {
            case SpellCastResultEnum.NotEnoughAp:
                character.TextInformation(TextInformationTypeEnum.TEXT_INFORMATION_ERROR, 170, new object[]
                {
                    Stats.ActionPoints.TotalInContext(),
                    level.ApCost,
                });
                break;

            case SpellCastResultEnum.CantBeSeen:
                character.TextInformation(TextInformationTypeEnum.TEXT_INFORMATION_ERROR, 174);
                break;

            case SpellCastResultEnum.HistoryError:
                character.TextInformation(TextInformationTypeEnum.TEXT_INFORMATION_ERROR, 175);
                break;

            case SpellCastResultEnum.FightEnded:
                character.TextInformation(TextInformationTypeEnum.TEXT_INFORMATION_ERROR, 175);
                break;

            case SpellCastResultEnum.NotPlaying:
                character.TextInformation(TextInformationTypeEnum.TEXT_INFORMATION_ERROR, 175);
                break;

            case SpellCastResultEnum.StateForbidden:
                character.TextInformation(TextInformationTypeEnum.TEXT_INFORMATION_ERROR, 175);
                break;

            case SpellCastResultEnum.StateRequired:
                character.TextInformation(TextInformationTypeEnum.TEXT_INFORMATION_ERROR, 175);
                break;
            }
            character.Client.Send(new GameActionFightNoSpellCastMessage((uint)level.Id));
            base.OnSpellCastFailed(result, level);
        }