예제 #1
0
        public override void TakeDamage(int damage, string damageAnimation = "Damage_01")
        {
            base.TakeDamage(damage, damageAnimation = "Damage_01");


            enemyHealthBar.SetHealth(CurrentHealth);

            enemyAnimatorManager.PlayTargetAnimation(damageAnimation, true);

            if (CurrentHealth <= 0)
            {
                HandleDeath();
            }
        }
예제 #2
0
        public override State Tick(EnemyManager enemyManager, EnemyStats enemyStats, EnemyAnimatorManager enemyAnimatorManager)
        {
            if (isSleeping && enemyManager.isInteracting == false)
            {
                enemyAnimatorManager.PlayTargetAnimation(sleepAnimation, true);
            }

            #region Handle Target Detection
            Collider[] colliders = Physics.OverlapSphere(enemyManager.transform.position, detectionRadius, detectionLayer);

            for (int i = 0; i < colliders.Length; i++)
            {
                //search all colliders finds for a player manager variable
                CharacterStats characterStats = colliders[i].transform.GetComponent <CharacterStats>();

                //if its finds it , continue the logic

                if (characterStats != null)
                {
                    Vector3 targetDirection = characterStats.transform.position - enemyManager.transform.position;
                    float   viewableAngle   = Vector3.Angle(targetDirection, enemyManager.transform.forward);

                    if (viewableAngle > enemyManager.minimumDetectionAngle && viewableAngle < enemyManager.maximumDetectionAngle)
                    {
                        enemyManager.currentTarget = characterStats;
                        isSleeping = false;

                        enemyAnimatorManager.PlayTargetAnimation(wakeAnimation, true);
                    }
                }
            }

            #endregion

            #region Handle State Change

            if (enemyManager.currentTarget != null)
            {
                return(pursueTargetState);
            }
            else
            {
                return(this);
            }
            #endregion
        }
        public override State Tick(EnemyManager enemyManager, EnemyStats enemyStats, EnemyAnimatorManager enemyAnimatorManager)
        {
            if (enemyManager.isInteracting)
            {
                return(this);
            }
            if (playerManager.isUsingRightHand)
            {
                int ran = Random.Range(0, 100);
                if (ran < 90)
                {
                    enemyAnimatorManager.PlayTargetAnimation("Rolling", true);
                }
            }

            // Check for attack range

            //walk around target

            float distanceFromTarget = Vector3.Distance(enemyManager.currentTarget.transform.position, enemyManager.transform.position);

            Debug.Log(distanceFromTarget);
            HandleRotateTowardsTarget(enemyManager);

            if (enemyManager.isPerformingAction)
            {
                //after atk return to combat state
                enemyAnimatorManager.anim.SetFloat("Vertical", 0, 0.1f, Time.deltaTime);
            }

            if (enemyManager.currentRecoveryTime <= 0 && distanceFromTarget <= enemyManager.maximumAttackRange)
            {
                return(attackState);
                // if still in the atk range , return atk state
            }
            else if (distanceFromTarget > enemyManager.maximumAttackRange)
            {
                return(pursueTargetState);
                //in cooldown attacking , return this state and continue focus player
            }
            else
            {
                return(this);
                //fail safe
            }
        }
 public void AttemptToCastSpell(
     EnemyAnimatorManager animationHandler)
 {
     animationHandler.PlayTargetAnimation(actionAnimation, true);
 }
예제 #5
0
        public override State Tick(EnemyManager enemyManager, EnemyStats enemyStats, EnemyAnimatorManager enemyAnimatorManager)
        {
            Vector3 targetDirection    = enemyManager.currentTarget.transform.position - enemyManager.transform.position;
            float   distanceFromTarget = Vector3.Distance(enemyManager.currentTarget.transform.position, enemyManager.transform.position);
            float   viewableAngle      = Vector3.Angle(targetDirection, enemyManager.transform.forward);

            phaseLimit = enemyStats.MaxHealth / 2;
            HandleRotateTowardsTarget(enemyManager);

            if (enemyManager.isInteracting && enemyManager.canDoCombo == false)
            {
                return(this);
            }
            else if (enemyManager.isInteracting && enemyManager.canDoCombo)
            {
                if (comboOnNextAttack)
                {
                    comboOnNextAttack = false;
                    //CUSTOM
                    if (enemyManager.currentAttack.usingWeapon)
                    {
                        enemyAnimatorManager.anim.SetBool("isUsingWeapon", true);
                    }
                    if (!enemyManager.currentAttack.isLeft)
                    {
                        enemyAnimatorManager.anim.SetBool("isUsingRightHand", true);
                    }
                    else if (enemyManager.currentAttack.isLeft)
                    {
                        enemyAnimatorManager.anim.SetBool("isUsingLeftHand", true);
                    }

                    //
                    enemyAnimatorManager.PlayTargetAnimation(enemyManager.currentAttack.actionAnimation, true);
                }
            }



            if (enemyManager.isPerformingAction)
            {
                return(lookForTargetState);
            }
            if (gameObject.tag == "Enemy")
            {
                if (enemyStats.CurrentHealth < phaseLimit && rageCount < 1)
                {
                    enemyAnimatorManager.PlayTargetAnimation("Rage", true);
                    enemyStats.RestoreHP(phaseLimit / 2);
                    rageCount++;
                }
            }


            if (enemyManager.currentAttack != null)
            {
                //CUSTOM
                if (enemyManager.currentAttack.usingWeapon)
                {
                    enemyAnimatorManager.anim.SetBool("isUsingWeapon", true);
                }
                if (!enemyManager.currentAttack.isLeft)
                {
                    enemyAnimatorManager.anim.SetBool("isUsingRightHand", true);
                }
                else if (enemyManager.currentAttack.isLeft)
                {
                    enemyAnimatorManager.anim.SetBool("isUsingLeftHand", true);
                }

                //
                //if we are too close to the enemy to perform current attack , get a new attack
                if (distanceFromTarget < enemyManager.currentAttack.minimumDistanceNeededToAttack)
                {
                    return(this);
                }
                //if we are close enough to attack , then proceed
                else if (distanceFromTarget < enemyManager.currentAttack.maximumDistanceNeededToAttack)
                {
                    //if our enemy is within our attacks viewable angle, we attack
                    if (viewableAngle <= enemyManager.currentAttack.maximumAttackAngle && viewableAngle >= enemyManager.currentAttack.minimumAttackAngle)
                    {
                        if (enemyManager.currentRecoveryTime <= 0 && enemyManager.isPerformingAction == false)
                        {
                            enemyAnimatorManager.anim.SetFloat("Vertical", 0, 0.1f, Time.deltaTime);
                            enemyAnimatorManager.anim.SetFloat("Horizontal", 0, 0.1f, Time.deltaTime);

                            enemyAnimatorManager.PlayTargetAnimation(enemyManager.currentAttack.actionAnimation, true);
                            enemyManager.isPerformingAction = true;
                            RollForComboChance(enemyManager);

                            if (enemyManager.currentAttack.canDoCombo && comboOnNextAttack)
                            {
                                enemyManager.currentAttack = enemyManager.currentAttack.comboAction;
                                return(this);
                            }
                            else
                            {
                                enemyManager.currentRecoveryTime = enemyManager.currentAttack.recoveryTime;
                                enemyManager.currentAttack       = null;
                                return(lookForTargetState);
                            }
                        }
                    }
                }
            }

            else if (enemyManager.currentMagicAttack != null)
            {
                if (distanceFromTarget < enemyManager.currentMagicAttack.maximumDistanceNeededToAttack)
                {
                    //if our enemy is within our attacks viewable angle, we attack
                    if (viewableAngle <= enemyManager.currentMagicAttack.maximumAttackAngle && viewableAngle >= enemyManager.currentMagicAttack.minimumAttackAngle)
                    {
                        if (enemyManager.currentRecoveryTime <= 0 && enemyManager.isPerformingAction == false)
                        {
                            enemyAnimatorManager.anim.SetFloat("Vertical", 0, 0.1f, Time.deltaTime);
                            enemyAnimatorManager.anim.SetFloat("Horizontal", 0, 0.1f, Time.deltaTime);

                            enemyManager.currentMagicAttack.AttemptToCastSpell(enemyAnimatorManager);
                            enemyManager.isPerformingAction = true;

                            enemyManager.currentRecoveryTime = enemyManager.currentMagicAttack.recoveryTime;
                            //enemyManager.currentMagicAttack = null;
                            return(lookForTargetState);
                        }
                        else if (enemyManager.currentRecoveryTime > 0 && distanceFromTarget <= enemyManager.maximumAttackRange)
                        {
                            return(lookForTargetState);
                        }
                    }
                }
            }
            else
            {
                GetNewAttack(enemyManager);
            }

            return(lookForTargetState);
        }