示例#1
0
        /// <summary>
        /// Damage is dealt to the AI and if it isn't already engaging another target, will engage the target that damaged them.
        /// </summary>
        /// <param name="amount">Damage value</param>
        /// <param name="from">The target that dealt the damge</param>
        public virtual void TakeDamage(float amount, AbstractCombatPerson from)
        {
            TakeDamage(amount);
            if (CurrentState == ActionState.Dying && from.CurrWeapon.Type == WeaponType.tazer)
            {
                hasBeenTazed = true;
            }

            if (CurrentState != ActionState.Dying && !IsTargetAlive())
            {
                CurrTarget = from;
            }
        }
示例#2
0
        /// <summary>
        /// Damage is dealt to the AI and if it isn't already engaging another target, will engage the target that damaged them.
        /// </summary>
        /// <param name="amount">Damage value</param>
        /// <param name="from">The target that dealt the damge</param>
        public override void TakeDamage(float amount, AbstractCombatPerson from)
        {
            TakeDamage(amount);
            if (CurrentState == ActionState.Dying && from.CurrWeapon.Type == WeaponType.tazer)
            {
                hasBeenTazed = true;
            }

            if (CurrentState != ActionState.Dying && !IsTargetAlive() && !IsMoving())
            {
                if (CheckInRange(from.Trans.position, CurrWeapon.Range))
                {
                    CurrTarget = from;
                }
            }
        }
示例#3
0
 /// <summary>
 /// Runs the logic for the move to target state of th AI, moving till within weapon range of the target
 /// </summary>
 private void StateCheckMoveToTarget()
 {
     if (IsTargetAlive())
     {
         AbstractCombatPerson temp = CurrTarget;
         SetDestination(CurrTarget.transform.position);
         CurrTarget = temp;
         if (CheckInRange(CurrTarget.Trans.position, CurrWeapon.Range) && CheckLineOfSight())
         {
             SetToAttack();
         }
     }
     else
     {
         SetToIdle();
     }
 }
示例#4
0
 /// <summary>
 /// Used by input to set current target.
 /// </summary>
 /// <param name="target"> The new current target. </param>
 public void SetTarget(AbstractCombatPerson target)
 {
     CurrTarget = target;
 }
示例#5
0
        /// <summary>
        /// Checks whether there is a line of sight between this AI and their target
        /// </summary>
        /// <param name="target"> The target of the line of sight check </param>
        /// <param name="normal"> The normal of the cover of this AI </param>
        /// <returns> True if there is line of sight </returns>
        protected bool CheckLineOfSight(AbstractCombatPerson target, Vector3 normal)
        {
            Vector3 start     = GetSightCheckPosition(trans, normal, CurrCoverType);
            Vector3 end       = GetSightCheckPosition(target.Trans, target.CoverNormal, target.CurrCoverType);
            Vector3 direction = end - start;

            direction.Normalize();

            float distance = Vector3.Distance(start, end);

            Ray        ray = new Ray(start, direction);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, distance))
            {
                if (hit.collider.CompareTag(target.tag))
                {
                    return(true);
                }
                else if (hit.collider.CompareTag(tag))
                {
                    RaycastHit rehit;
                    Vector3    hitPoint     = hit.point;
                    float      distanceLeft = distance - Vector3.Distance(hitPoint, start) - 0.05f;
                    int        iterations   = 0;
                    while (MissionInput.RaycastThroughObject(hitPoint, direction, distanceLeft, out rehit))
                    {
                        if (hit.collider.CompareTag(target.tag))
                        {
                            return(true);
                        }
                        else if (hit.collider.CompareTag(tag))
                        {
                            hitPoint     = rehit.point;
                            distanceLeft = distance - Vector3.Distance(hitPoint, start) - 0.05f;

                            iterations++;

                            if (iterations > 50)
                            {
                                break;
                            }

                            continue;
                        }
                        else
                        {
                            return(false);
                        }
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(true);
            }
        }
示例#6
0
 /// <summary>
 /// Checks whether there is a line of sight between this AI and their target
 /// </summary>
 /// <param name="target"> The target of the line of sight check </param>
 /// <returns> True if there is line of sight </returns>
 protected bool CheckLineOfSight(AbstractCombatPerson target)
 {
     return(CheckLineOfSight(target, CoverNormal));
 }
示例#7
0
 /// <summary>
 /// Sets the AI values to its attack state and sets its current target.
 /// </summary>
 /// <param name="enemy"> The new current target. </param>
 protected void SetToAttack(AbstractCombatPerson enemy)
 {
     SetToAttack();
     CurrTarget = enemy;
 }
示例#8
0
 /// <summary>
 /// Sets the AI values to its moving state and sets its current target.
 /// </summary>
 /// <param name="enemy"> The new current target. </param>
 protected void SetToMoving(AbstractCombatPerson enemy)
 {
     SetToMoving();
     CurrTarget = enemy;
     SetDestination(CurrTarget.Trans.position);
 }