Beispiel #1
0
        public AIAttacks WillAttack()
        {
            int w = 0;
            List <AIAttacks> list = new List <AIAttacks>();

            for (int i = 0; i < ai_attacks.Length; i++)
            {
                AIAttacks a = ai_attacks[i];
                if (a._cool > 0)
                {
                    continue;
                }

                if (distanceFromTarget > a.minDistance)
                {
                    continue;
                }

                if (angleToTarget < a.minAngle)
                {
                    continue;
                }

                if (angleToTarget > a.maxAngle)
                {
                    continue;
                }

                if (a.weight == 0)
                {
                    continue;
                }

                w += a.weight;
                list.Add(a);
            }

            if (list.Count == 0)
            {
                return(null);
            }

            int rand = Random.Range(0, w + 1);
            int c_w  = 0;

            for (int i = 0; i < list.Count; i++)
            {
                c_w += list[i].weight;
                if (c_w > rand)
                {
                    return(list[i]);
                    //Do ATTACK!
                }
            }

            return(null);
        }
Beispiel #2
0
 void HandleCoolDowns()
 {
     for (int i = 0; i < ai_attacks.Length; i++)
     {
         AIAttacks a = ai_attacks[i];
         if (a._cool > 0)
         {
             a._cool -= delta;
             if (a._cool < 0)
             {
                 a._cool = 0;
             }
         }
     }
 }
Beispiel #3
0
        void InSight()
        {
            HandleCoolDowns();

            float distanceToDestination = Vector3.Distance(enemyState.targetDestination, target.position);

            if (distanceToDestination > 2 || distanceFromTarget > sight * 0.5)
            {
                GoToTarget();
            }

            if (distanceFromTarget < 2)
            {
                enemyState.navMeshAgent.isStopped = true;
            }

            if (_attackCount > 0)
            {
                _attackCount--;
                return;
            }

            _attackCount = attackCount;

            AIAttacks attack = WillAttack();

            enemyState.SetCurrentAttack(attack);

            if (attack != null)
            {
                enemyState.animator.Play(attack.targetAnim);
                enemyState.animator.SetBool(StaticStrings.animParam_OnEmpty, false);
                enemyState.canMove = false;
                attack._cool       = attack.coolDown;
                enemyState.navMeshAgent.isStopped = true;
                enemyState.rotateToTarget         = false;
                return;
            }
        }
 public void SetCurrentAttack(AIAttacks a)
 {
     currentAttack = a;
 }