Exemple #1
0
    virtual protected IEnumerator WaitToAttack(float waitTime)
    {
        yield return(new WaitForSeconds(waitTime));

        enemyAnimations.SetTrigger("Attack");
        attackSubState = AttackSubState.ATTACKING;
    }
Exemple #2
0
    virtual public void Revive()
    {
        curedEnemies.Remove(this);
        targeted = false;

        health = maxHealth;
        agent.stoppingDistance = initialStoppingDistance;
        agent.SetDestination(transform.position);
        nextPatrolPoint  = 0;
        state            = State.DEFAULT;
        defaultSubState  = DefaultSubState.NOT_DEFAULT;
        attackSubState   = AttackSubState.NOT_ATTACKING;
        searchSubState   = SearchSubState.NOT_SEARCHING;
        isStunned        = false;
        sprite.color     = Color.white;
        canStun          = true;
        audioSource.clip = walkSounds;

        GetComponent <Collider>().enabled = true;


        killed = false;


        enemyAnimations.SetBool("Cured", false);
        StopAllCoroutines();
    }
Exemple #3
0
    public void LoadCheckpoint(LevelManager.CheckpointData.EnemyData data)
    {
        transform.position = data.worldPosition;
        transform.rotation = data.worldRotation;
        transform.parent   = data.parent;

        if (!data.cured)
        {
            killed = false;
            GetComponent <Collider>().enabled = true;
            enemyAnimations.SetBool("Cured", false);
            health           = data.health;
            state            = State.DEFAULT;
            attackSubState   = AttackSubState.NOT_ATTACKING;
            searchSubState   = SearchSubState.NOT_SEARCHING;
            defaultSubState  = DefaultSubState.NOT_DEFAULT;
            audioSource.clip = walkSounds;

            curedEnemies.Remove(this);
            targeted = false;
        }
        else
        {
            killed = true;
        }
    }
Exemple #4
0
 //Called by Attack Player animation behavior script
 virtual public bool HurtPlayer()
 {
     attackSubState = AttackSubState.DONE;
     if (isStunned || killed)
     {
         return(false);
     }
     //If the player is in view of the enemy and close enough, hirt player
     if (RaycastToPlayer() && Vector3.Distance(playerTransform.position, transform.position) <= attackRaduis)
     {
         PlayerManager.instance.HurtPlayer(attackDamage);
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemple #5
0
    virtual protected void PerformAttackState()
    {
        switch (attackSubState)
        {
        case AttackSubState.NOT_ATTACKING:
            float waitTime;

            if (attackTimeType == AttackTimeType.CONSTANT)
            {
                waitTime = attackTime;
            }
            else
            {
                waitTime = Random.Range(attackTimeMin, attackTimeMax);
            }

            StartCoroutine(WaitToAttack(waitTime));
            attackSubState = AttackSubState.WAITING;
            break;

        case AttackSubState.WAITING:
            agent.SetDestination(playerTransform.position);
            // **EXITED BY COROUTINE "WaitToAttack"**
            if (!inAttackRadius)
            {
                StopCoroutine("WaitToAttack");
                attackSubState = AttackSubState.DONE;
            }
            agent.SetDestination(transform.position);
            break;

        case AttackSubState.ATTACKING:

            // **EXITED BY FUNCTION CALL "HurtPlayer"
            break;

        case AttackSubState.DONE:
            // Currently Inaccessible
            break;
        }
    }
Exemple #6
0
    override protected IEnumerator Respawn()
    {
        foreach (SpriteRenderer sr in GetComponentsInChildren <SpriteRenderer>())
        {
            sr.enabled = false;
        }

        health                 = maxHealth;
        transform.position     = initialPosition;
        transform.rotation     = initialRotation;
        agent.stoppingDistance = initialStoppingDistance;
        agent.SetDestination(transform.position);
        nextPatrolPoint  = 0;
        state            = State.DEFAULT;
        defaultSubState  = DefaultSubState.NOT_DEFAULT;
        attackSubState   = AttackSubState.NOT_ATTACKING;
        searchSubState   = SearchSubState.NOT_SEARCHING;
        isStunned        = false;
        sprite.color     = Color.white;
        canStun          = true;
        audioSource.clip = walkSounds;

        yield return(new WaitForSeconds(respawnTime));

        foreach (SpriteRenderer sr in GetComponentsInChildren <SpriteRenderer>())
        {
            sr.enabled = true;
        }
        GetComponent <Collider>().enabled = true;


        killed = false;


        enemyAnimations.SetBool("Cured", false);
        StopAllCoroutines();
    }
Exemple #7
0
    virtual protected void PerformAILogic()
    {
        //Reset stopping distance if enemy is aware of player
        if (state != State.DEFAULT)
        {
            agent.stoppingDistance = initialStoppingDistance;
        }

        //Calculate distance to player
        float distance = Vector3.Distance(playerTransform.position, transform.position);

        //reset location flags
        hasLineOfSight = false;
        inChaseRadius  = false;
        inAgroRadius   = false;
        inAttackRadius = false;

        //set location flags
        if (distance <= chaseLimitRadius)
        {
            inChaseRadius  = true;
            hasLineOfSight = RaycastToPlayer();

            if (distance <= agroRadius && hasLineOfSight)
            {
                inAgroRadius = true;
                if (distance <= attackRaduis)
                {
                    inAttackRadius = true;
                }
            }
        }

        if (PlayerManager.instance.isAlive)
        {
            //Implementation of highest level state machine
            switch (state)
            {
            case State.DEFAULT:
                //Exit case: Player enters agro radius
                if (inAgroRadius)
                {
                    state           = State.AGRO;
                    defaultSubState = DefaultSubState.NOT_DEFAULT;
                    PerformAgroState();
                }
                else
                {
                    PerformDefaultState();
                }
                break;

            case State.AGRO:
                //Exit case: Player enters attack radius
                if (inAttackRadius)
                {
                    state = State.ATTACKING;
                    PerformAttackState();
                }
                //Exit case: Player breaks line of sight or leaves chase radius
                else if (!hasLineOfSight)
                {
                    state = State.SEARCHING;
                    PerformSearchingState();
                }
                else
                {
                    PerformAgroState();
                }
                break;

            case State.ATTACKING:
                //Exit Case: enemy finished attacking, return to agro
                if (attackSubState == AttackSubState.DONE)
                {
                    state          = State.AGRO;
                    attackSubState = AttackSubState.NOT_ATTACKING;
                    PerformAgroState();
                }
                else
                {
                    PerformAttackState();
                }
                break;

            case State.SEARCHING:
                //Exit case: Searching concludes without finding player
                if (searchSubState == SearchSubState.DONE)
                {
                    state          = State.DEFAULT;
                    searchSubState = SearchSubState.NOT_SEARCHING;
                    PerformDefaultState();
                }
                //Exit case: Enemy finds player
                else if (hasLineOfSight)
                {
                    state          = State.AGRO;
                    searchSubState = SearchSubState.NOT_SEARCHING;
                }
                else
                {
                    PerformSearchingState();
                }
                break;

            default:
                Debug.LogError("Unrecognized State");
                break;
            }
        }
        else
        {
            searchSubState = SearchSubState.NOT_SEARCHING;
            attackSubState = AttackSubState.NOT_ATTACKING;
            state          = State.DEFAULT;
        }
    }