Exemplo n.º 1
0
        public void DoDamage(AIAttacks a)
        {
            if (isInvincible)
            {
                return;
            }
            damaged = true;

            int damage = 20;

            characterStats._health -= damage;
            if (canMove)
            {
                int    ran = Random.Range(0, 100);
                string tA  = (ran > 50) ? "damage_1" : "damage_2";
                audio_clip = ResourceManager.singleton.GetAudio("hurt").audio_clip;
                anim.Play(tA);
            }
            anim.SetBool("OnEmpty", false);
            onEmpty              = false;
            isInvincible         = true;
            anim.applyRootMotion = true;
            anim.SetBool("canMove", false);
            if (characterStats._health <= 0 && !isDead)
            {
                Die();
            }
        }
Exemplo n.º 2
0
        public AIAttacks WillAttack()
        {
            int w = 0;
            List <AIAttacks> l = new List <AIAttacks>();

            for (int i = 0; i < ai_attacks.Length; i++)
            {
                AIAttacks a = ai_attacks[i];

                if (a.cool > 0)
                {
                    continue;
                }
                //   GoToTarget();

                if (Dis > a.MinDistance)
                {
                    continue;
                }
                if (_angle < a.minAngle)
                {
                    continue;
                }
                if (_angle > a.maxAngle)
                {
                    continue;
                }
                if (a.Weight == 0)
                {
                    continue;
                }
                w += a.Weight;
                l.Add(a);
            }

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

            int ran = Random.Range(0, w + 1);
            int C_W = 0;

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

            return(null);
        }
Exemplo n.º 3
0
        public AIAttacks WillAttack()
        {
            int w = 0;
            List <AIAttacks> l = new List <AIAttacks>();

            for (int i = 0; i < ai_attacks.Length; i++)
            {
                AIAttacks a = ai_attacks[i];
                if (a._cool > 0)
                {
                    continue;
                }
                if (dis > a.minDistance)
                {
                    continue;
                }
                if (angle < a.minAngle)
                {
                    continue;
                }
                if (angle > a.maxAngle)
                {
                    continue;
                }
                if (a.weight == 0)
                {
                    continue;
                }

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

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

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

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

            return(null);
        }
Exemplo n.º 4
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;
             }
             continue;
         }
     }
 }
Exemplo n.º 5
0
        void Insight()
        {
            #region delay handler

            HandleCooldowns();

            float d2 = Vector3.Distance(states.targetDestionation, target.position);
            if (d2 > 2 || dis > sight * 5)
            {
                GoToTarget();
            }
            if (dis < 2)
            {
                states.agent.isStopped = true;
            }


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

            #endregion

            #region perform attack

            AIAttacks a = WillAttack();
            states.SetCurrentAttack(a);

            if (a != null && en_states.isDead == false)
            {
                aiState = AIState.attacking;
                states.anim.Play(a.targetAnim);
                states.anim.SetBool("OnEmpty", false);
                states.canMove         = false;
                a._cool                = a.cooldown;
                states.agent.isStopped = true;
                states.rotateToTarget  = false;
                return;
            }
            #endregion

            return;
        }
Exemplo n.º 6
0
        public void In_Sight()
        {
            States.RotateToTarget = true;
            HandleCoolDown();
            float disToDes = Vector3.Distance(States.TargetDestination, target.position);

            if (disToDes > 2 || Dis > Sight * 0.5)
            {
                GoToTarget();
            }

            if (Dis < 2)
            {
                States.AgentAI.isStopped = true;
            }


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

            _AttackCount = AttackCount;


            AIAttacks a = WillAttack();

            if (a != null)
            {
                States.anim.applyRootMotion = true;
                //  States.AgentAI.enabled = false;
                _AiStates = AIstates.Attacking;
                States.anim.Play(a.targetAnim);
                States.CanMove           = false;
                a.cool                   = a.CoolDown;
                States.AgentAI.isStopped = true;
                return;
            }
        }
Exemplo n.º 7
0
        void HandleCoolDown()
        {
            for (int i = 0; i < ai_attacks.Length; i++)
            {
                AIAttacks a = ai_attacks[i];

                if (a.cool > 0)
                {
                    a.cool -= Delta;
                    States.anim.Play(States.Block);
                    States.AgentAI.isStopped = true;

                    if (a.cool < 0)
                    {
                        a.cool = 0;
                    }
                }

                if (_AiStates == AIstates.far)
                {
                    a.cool = 0;
                }
            }
        }
Exemplo n.º 8
0
 public void SetCurrentAttack(AIAttacks a)
 {
     curAttack = a;
 }