void HandleAttack(eAttackResult attack_result)
    {
        bool has_hit = false;

        if (canBlock)
        {
            has_hit = attack_result == eAttackResult.Hit;

            if (attack_result == eAttackResult.Parry)
            {
                Stun(this);
            }

            if (attack_result == eAttackResult.Block)
            {
                AbortAttack();
            }
        }
        else
        {
            has_hit = attack_result != eAttackResult.Block;
        }

        if (has_hit)
        {
            ApplyDamage(this);
        }
    }
    void LandAttack()
    {
        GameObject attack_target = DetermineAttackTarget(currentAttackDirection);

        if (attack_target == null)
        {
            return;
        }

        Attacking     damagee = attack_target.GetComponentInChildren <Attacking>();
        eAttackResult result  = damagee.CalcAttackResult(this);

        damagee.HandleAttack(result);
    }
Example #3
0
        /// <summary>
        /// We need an event after an attack is finished so we know when players are unreachable by archery
        /// </summary>
        /// <param name="e"></param>
        /// <param name="sender"></param>
        /// <param name="arguments"></param>
        public static void AttackFinished(DOLEvent e, object sender, EventArgs arguments)
        {
            GameKeepGuard guard = sender as GameKeepGuard;

            if (guard.TargetObject == null)
            {
                return;
            }
            if (!guard.AttackState)
            {
                return;
            }
            if (guard is GuardArcher == false && guard is GuardLord == false && guard is GuardCaster == false)
            {
                return;
            }

            AttackFinishedEventArgs afargs = arguments as AttackFinishedEventArgs;

            if (guard.ActiveWeaponSlot != eActiveWeaponSlot.Distance && !guard.IsMoving)
            {
                eAttackResult result = afargs.AttackData.AttackResult;
                if (result == eAttackResult.OutOfRange)
                {
                    guard.StopAttack();
                    lock (guard.Attackers)
                    {
                        foreach (GameLiving living in guard.Attackers)
                        {
                            if (guard.IsWithinRadius(living, guard.AttackRange))
                            {
                                guard.StartAttack(living);
                                return;
                            }
                        }
                    }

                    if (guard.IsWithinRadius(guard.TargetObject, guard.AttackRangeDistance))
                    {
                        if (guard.MaxSpeedBase == 0 || (guard is GuardArcher && !guard.BeenAttackedRecently))
                        {
                            guard.SwitchToRanged(guard.TargetObject);
                        }
                    }
                }
                return;
            }

            if (guard.ActiveWeaponSlot == eActiveWeaponSlot.Distance)
            {
                if (GameServer.ServerRules.IsAllowedToAttack(guard, guard.TargetObject as GameLiving, true) == false)
                {
                    guard.StopAttack();
                    return;
                }
                if (!guard.IsWithinRadius(guard.TargetObject, guard.AttackRange))
                {
                    guard.StopAttack();
                    return;
                }
            }

            GamePlayer player = null;

            if (guard.TargetObject is GamePlayer)
            {
                player = guard.TargetObject as GamePlayer;
            }
            else if (guard.TargetObject is GameNPC)
            {
                GameNPC npc = (guard.TargetObject as GameNPC);

                if (npc.Brain != null && ((npc is GameKeepGuard) == false) && npc.Brain is IControlledBrain)
                {
                    player = (npc.Brain as IControlledBrain).GetPlayerOwner();
                }
            }

            if (player != null)
            {
                player.Out.SendCheckLOS(guard, guard.TargetObject, new CheckLOSResponse(guard.GuardStopAttackCheckLOS));
            }
        }