Example #1
0
        public void DoDamage(AIAttacks a)
        {
            if (isInvicible)
            {
                return;
            }

            int damage = 5;

            characterStats._health -= damage;

            if (a.hasReactAnim)
            {
                anim.Play(a.reactAnim);
            }
            else
            {
                int    ran = Random.Range(0, 100);
                string tA  = (ran > 50) ? StaticStrings.damage1 : StaticStrings.damage2;
                anim.Play(tA);
            }

            anim.SetBool(StaticStrings.onEmpty, false);
            canMove              = false;
            onEmpty              = false;
            inAction             = true;
            isInvicible          = true;
            anim.applyRootMotion = true;
        }
Example #2
0
        public AIAttacks WillAttack()
        {
            int weight         = 0;
            List <AIAttacks> l = new List <AIAttacks>();

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

                if (dis > a.minDistance)
                {
                    continue;
                }
                if (angle < a.minAngle)
                {
                    continue;
                }
                if (angle > a.maxAngle)
                {
                    continue;
                }
                if (a.weight == 0)
                {
                    continue;
                }

                weight += a.weight;
                l.Add(a);
            }

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

            int ran      = Random.Range(0, weight + 1);
            int c_weight = 0;

            for (int i = 0; i < l.Count; i++)
            {
                c_weight += l[i].weight;
                if (c_weight > ran)
                {
                    return(l[i]);
                }
            }

            return(null);
        }
Example #3
0
 void HandleCooldowns()
 {
     for (int i = 0; i < ai_attacks.Length; i++)
     {
         AIAttacks a = ai_attacks[i];
         if (a._cooldown > 0)
         {
             a._cooldown -= delta;
             if (a._cooldown < 0)
             {
                 a._cooldown = 0;
             }
         }
     }
 }
Example #4
0
        void InSight()
        {
            HandleCooldowns();

            float d2 = Vector3.Distance(states.targetDestination, target.position);

            if (d2 > 2 || dis > sight * .5)
            {
                GoToTarget();
            }

            if (dis < 2)
            {
                states.navAgent.isStopped = true;
            }

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

            _attack = attackCount;

            AIAttacks a = WillAttack();

            states.SetCurAttack(a);
            if (a != null)
            {
                aiState = AIstate.attacking;
                states.anim.Play(a.targetAnim);
                states.anim.SetBool(StaticStrings.onEmpty, false);
                states.canMove            = false;
                a._cooldown               = a.cooldown;
                states.navAgent.isStopped = true;
                states.rotateToTarget     = false;
                return;
            }
        }
Example #5
0
 public void SetCurAttack(AIAttacks a)
 {
     curAttack = a;
 }