Exemplo n.º 1
0
 public override void RecieveSensor(int sensorTag)
 {
     if (simpleState == SimpleStates.Idle)
     {
         if (sensorTag == AIBlackboard.NEAR_PLAYER)
         {
             fuzzyDelay      = Random.Range(0f, 1.03f);
             awareDelayTimer = Time.time;
             simpleState     = SimpleStates.BecomingAware;
             isAware         = true;
             monsterAware.PlayOneShot(monsterAware.clip);
         }
     }
 }
    public void run()
    {
        if (current_state == SimpleStates.q0)
        {
            if (str[position] == 'a')
            {
                current_state   = SimpleStates.q1;
                moveCurrent     = SMovement.R;
                replaceChar     = 'x';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == 'y')
            {
                current_state   = SimpleStates.q3;
                moveCurrent     = SMovement.R;
                replaceChar     = 'y';
                positionCurrent = position;
                position        = position + 1;
            }
            else
            {
                current_state = SimpleStates.haltt;
                moveCurrent   = SMovement.H;
            }
        }
        else if (current_state == SimpleStates.q1)
        {
            if (str[position] == 'a')
            {
                current_state   = SimpleStates.q1;
                moveCurrent     = SMovement.R;
                replaceChar     = 'a';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == 'y')
            {
                current_state   = SimpleStates.q1;
                moveCurrent     = SMovement.R;
                replaceChar     = 'y';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == 'b')
            {
                current_state   = SimpleStates.q4;
                moveCurrent     = SMovement.L;
                replaceChar     = 'y';
                positionCurrent = position;
                position        = position - 1;
            }
            else if (str[position] == 'c')
            {
                current_state   = SimpleStates.q10;
                moveCurrent     = SMovement.L;
                replaceChar     = '-';
                positionCurrent = position;
                position        = position - 1;
            }
            else if (str[position] == 'Δ')
            {
                current_state   = SimpleStates.q5;
                moveCurrent     = SMovement.L;
                replaceChar     = 'Δ';
                positionCurrent = position;
                position        = position - 1;
            }
            else
            {
                current_state = SimpleStates.haltt;
                moveCurrent   = SMovement.H;
            }
        }
        else if (current_state == SimpleStates.q2)
        {
            if (str[position] == 'x')
            {
                current_state   = SimpleStates.q2;
                moveCurrent     = SMovement.L;
                replaceChar     = 'a';
                positionCurrent = position;
                position        = position - 1;
            }
            else if (str[position] == 'Δ')
            {
                current_state   = SimpleStates.q0;
                moveCurrent     = SMovement.R;
                replaceChar     = 'Δ';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == 'y')
            {
                current_state   = SimpleStates.q2;
                moveCurrent     = SMovement.L;
                replaceChar     = 'y';
                positionCurrent = position;
                position        = position - 1;
            }
            else if (str[position] == 'c')
            {
                current_state   = SimpleStates.q2;
                moveCurrent     = SMovement.L;
                replaceChar     = 'c';
                positionCurrent = position;
                position        = position - 1;
            }
            else if (str[position] == 'b')
            {
                current_state   = SimpleStates.q2;
                moveCurrent     = SMovement.L;
                replaceChar     = 'b';
                positionCurrent = position;
                position        = position - 1;
            }
            else
            {
                current_state = SimpleStates.haltt;
                moveCurrent   = SMovement.H;
            }
        }
        else if (current_state == SimpleStates.q3)
        {
            if (str[position] == 'c')
            {
                current_state   = SimpleStates.q3;
                moveCurrent     = SMovement.R;
                replaceChar     = 'c';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == 'b')
            {
                current_state   = SimpleStates.q3;
                moveCurrent     = SMovement.R;
                replaceChar     = 'b';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == '-')
            {
                current_state   = SimpleStates.q15;
                moveCurrent     = SMovement.L;
                replaceChar     = '-';
                positionCurrent = position;
                position        = position - 1;
            }
            else if (str[position] == 'y')
            {
                current_state   = SimpleStates.q3;
                moveCurrent     = SMovement.R;
                replaceChar     = 'y';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == 'Δ')
            {
                current_state   = SimpleStates.q2;
                moveCurrent     = SMovement.L;
                replaceChar     = 'c';
                positionCurrent = position;
                position        = position - 1;
            }
            else if (str[position] == '-')
            {
                current_state   = SimpleStates.q9;
                moveCurrent     = SMovement.R;
                replaceChar     = '-';
                positionCurrent = position;
                position        = position + 1;
            }
            else
            {
                current_state = SimpleStates.haltt;
                moveCurrent   = SMovement.H;
            }
        }
        else if (current_state == SimpleStates.q4)
        {
            if (str[position] == 'y')
            {
                current_state   = SimpleStates.q4;
                moveCurrent     = SMovement.L;
                replaceChar     = 'y';
                positionCurrent = position;
                position        = position - 1;
            }
            else if (str[position] == 'a')
            {
                current_state   = SimpleStates.q4;
                moveCurrent     = SMovement.L;
                replaceChar     = 'a';
                positionCurrent = position;
                position        = position - 1;
            }
            else if (str[position] == 'x')
            {
                current_state   = SimpleStates.q0;
                moveCurrent     = SMovement.R;
                replaceChar     = 'x';
                positionCurrent = position;
                position        = position + 1;
            }
            else
            {
                current_state = SimpleStates.haltt;
                moveCurrent   = SMovement.H;
            }
        }
        else if (current_state == SimpleStates.q5)
        {
            if (str[position] == 'y')
            {
                current_state   = SimpleStates.q6;
                moveCurrent     = SMovement.R;
                replaceChar     = 'y';
                positionCurrent = position;
                position        = position + 1;
            }
            else
            {
                current_state = SimpleStates.haltt;
                moveCurrent   = SMovement.H;
            }
        }
        else if (current_state == SimpleStates.q6)
        {
            if (str[position] == 'Δ')
            {
                current_state   = SimpleStates.q8;
                moveCurrent     = SMovement.H;
                replaceChar     = 'Δ';
                positionCurrent = position;
                position        = position + 1;
            }

            else
            {
                current_state = SimpleStates.haltt;
                moveCurrent   = SMovement.H;
            }
        }
        else if (current_state == SimpleStates.q7)
        {
            if (str[position] == 'a')
            {
                current_state   = SimpleStates.q12;
                moveCurrent     = SMovement.R;
                replaceChar     = 'x';
                positionCurrent = position;
                position        = position + 1;
            }

            else
            {
                current_state = SimpleStates.haltt;
                moveCurrent   = SMovement.H;
            }
        }
        else if (current_state == SimpleStates.q8)
        {
            current_state = SimpleStates.haltt;
            moveCurrent   = SMovement.H;
        }
        else if (current_state == SimpleStates.q9)
        {
            if (str[position] == 'x')
            {
                current_state   = SimpleStates.q18;
                moveCurrent     = SMovement.R;
                replaceChar     = 'x';
                positionCurrent = position;
                position        = position + 1;
            }

            else
            {
                current_state = SimpleStates.haltt;
                moveCurrent   = SMovement.H;
            }
        }
        else if (current_state == SimpleStates.q10)
        {
            if (str[position] == 'x')
            {
                current_state   = SimpleStates.q0;
                moveCurrent     = SMovement.R;
                replaceChar     = 'x';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == 'y')
            {
                current_state   = SimpleStates.q10;
                moveCurrent     = SMovement.L;
                replaceChar     = 'y';
                positionCurrent = position;
                position        = position - 1;
            }
            else if (str[position] == '-')
            {
                current_state   = SimpleStates.q10;
                moveCurrent     = SMovement.L;
                replaceChar     = '-';
                positionCurrent = position;
                position        = position - 1;
            }
            else if (str[position] == 'a')
            {
                current_state   = SimpleStates.q11;
                moveCurrent     = SMovement.L;
                replaceChar     = 'a';
                positionCurrent = position;
                position        = position - 1;
            }
            else
            {
                current_state = SimpleStates.haltt;
                moveCurrent   = SMovement.H;
            }
        }
        else if (current_state == SimpleStates.q11)
        {
            if (str[position] == 'a')
            {
                current_state   = SimpleStates.q11;
                moveCurrent     = SMovement.L;
                replaceChar     = 'a';
                positionCurrent = position;
                position        = position - 1;
            }
            else if (str[position] == 'x')
            {
                current_state   = SimpleStates.q7;
                moveCurrent     = SMovement.R;
                replaceChar     = 'x';
                positionCurrent = position;
                position        = position + 1;
            }

            else
            {
                current_state = SimpleStates.haltt;
                moveCurrent   = SMovement.H;
            }
        }
        else if (current_state == SimpleStates.q12)
        {
            if (str[position] == '-')
            {
                current_state   = SimpleStates.q12;
                moveCurrent     = SMovement.R;
                replaceChar     = '-';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == 'y')
            {
                current_state   = SimpleStates.q12;
                moveCurrent     = SMovement.R;
                replaceChar     = 'y';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == 'a')
            {
                current_state   = SimpleStates.q12;
                moveCurrent     = SMovement.R;
                replaceChar     = 'a';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == 'c')
            {
                current_state   = SimpleStates.q13;
                moveCurrent     = SMovement.L;
                replaceChar     = '-';
                positionCurrent = position;
                position        = position - 1;
            }
            else if (str[position] == 'Δ')
            {
                current_state   = SimpleStates.q8;
                moveCurrent     = SMovement.H;
                replaceChar     = 'Δ';
                positionCurrent = position;
                position        = position + 1;
            }
            else
            {
                current_state = SimpleStates.haltt;
                moveCurrent   = SMovement.H;
            }
        }

        else if (current_state == SimpleStates.q13)
        {
            if (str[position] == '-')
            {
                current_state   = SimpleStates.q13;
                moveCurrent     = SMovement.L;
                replaceChar     = '-';
                positionCurrent = position;
                position        = position - 1;
            }
            else if (str[position] == 'y')
            {
                current_state   = SimpleStates.q13;
                moveCurrent     = SMovement.L;
                replaceChar     = 'y';
                positionCurrent = position;
                position        = position - 1;
            }
            else if (str[position] == 'x')
            {
                current_state   = SimpleStates.q14;
                moveCurrent     = SMovement.R;
                replaceChar     = 'x';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == 'a')
            {
                current_state   = SimpleStates.q13;
                moveCurrent     = SMovement.R;
                replaceChar     = 'a';
                positionCurrent = position;
                position        = position + 1;
            }
            else
            {
                current_state = SimpleStates.haltt;
                moveCurrent   = SMovement.H;
            }
        }
        else if (current_state == SimpleStates.q14)
        {
            if (str[position] == '-')
            {
                current_state   = SimpleStates.q14;
                moveCurrent     = SMovement.R;
                replaceChar     = '-';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == 'y')
            {
                current_state   = SimpleStates.q14;
                moveCurrent     = SMovement.R;
                replaceChar     = 'y';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == 'c')
            {
                current_state   = SimpleStates.q8;
                moveCurrent     = SMovement.H;
                replaceChar     = 'Δ';
                positionCurrent = position;
                position        = position + 1;
            }
            else
            {
                current_state = SimpleStates.haltt;
                moveCurrent   = SMovement.H;
            }
        }
        else if (current_state == SimpleStates.q15)
        {
            if (str[position] == '-')
            {
                current_state   = SimpleStates.q15;
                moveCurrent     = SMovement.L;
                replaceChar     = '-';
                positionCurrent = position;
                position        = position - 1;
            }
            else if (str[position] == 'y')
            {
                current_state   = SimpleStates.q16;
                moveCurrent     = SMovement.L;
                replaceChar     = 'y';
                positionCurrent = position;
                position        = position - 1;
            }
            else
            {
                current_state = SimpleStates.haltt;
                moveCurrent   = SMovement.H;
            }
        }
        else if (current_state == SimpleStates.q16)
        {
            if (str[position] == 'x')
            {
                current_state   = SimpleStates.q16;
                moveCurrent     = SMovement.L;
                replaceChar     = 'x';
                positionCurrent = position;
                position        = position - 1;
            }
            else if (str[position] == 'y')
            {
                current_state   = SimpleStates.q16;
                moveCurrent     = SMovement.L;
                replaceChar     = 'y';
                positionCurrent = position;
                position        = position - 1;
            }
            else if (str[position] == 'Δ')
            {
                current_state   = SimpleStates.q9;
                moveCurrent     = SMovement.R;
                replaceChar     = 'Δ';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == 'a')
            {
                current_state   = SimpleStates.q17;
                moveCurrent     = SMovement.R;
                replaceChar     = 'a';
                positionCurrent = position;
                position        = position + 1;
            }
            else
            {
                current_state = SimpleStates.haltt;
                moveCurrent   = SMovement.H;
            }
        }
        else if (current_state == SimpleStates.q17)
        {
            if (str[position] == 'a')
            {
                current_state   = SimpleStates.q17;
                moveCurrent     = SMovement.R;
                replaceChar     = 'a';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == 'c')
            {
                current_state   = SimpleStates.q8;
                moveCurrent     = SMovement.H;
                replaceChar     = 'c';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == 'Δ')
            {
                current_state   = SimpleStates.q8;
                moveCurrent     = SMovement.H;
                replaceChar     = 'Δ';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == 'x')
            {
                current_state   = SimpleStates.q17;
                moveCurrent     = SMovement.R;
                replaceChar     = 'x';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == '-')
            {
                current_state   = SimpleStates.q17;
                moveCurrent     = SMovement.R;
                replaceChar     = '-';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == 'y')
            {
                current_state   = SimpleStates.q17;
                moveCurrent     = SMovement.R;
                replaceChar     = 'y';
                positionCurrent = position;
                position        = position + 1;
            }
            else
            {
                current_state = SimpleStates.haltt;
                moveCurrent   = SMovement.H;
            }
        }
        else if (current_state == SimpleStates.q18)
        {
            if (str[position] == 'a')
            {
                current_state   = SimpleStates.q17;
                moveCurrent     = SMovement.R;
                replaceChar     = 'a';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == 'x')
            {
                current_state   = SimpleStates.q17;
                moveCurrent     = SMovement.R;
                replaceChar     = 'x';
                positionCurrent = position;
                position        = position + 1;
            }
            else if (str[position] == 'y')
            {
                current_state   = SimpleStates.q19;
                moveCurrent     = SMovement.R;
                replaceChar     = 'y';
                positionCurrent = position;
                position        = position + 1;
            }
            else
            {
                current_state = SimpleStates.haltt;
                moveCurrent   = SMovement.H;
            }
        }
        else if (current_state == SimpleStates.q19)
        {
            if (str[position] == 'y')
            {
                current_state   = SimpleStates.q17;
                moveCurrent     = SMovement.R;
                replaceChar     = 'y';
                positionCurrent = position;
                position        = position + 1;
            }
            else
            {
                current_state = SimpleStates.haltt;
                moveCurrent   = SMovement.H;
            }
        }
    }
Exemplo n.º 3
0
    public override void RunBehavior()
    {
        switch (simpleState)
        {
        case SimpleStates.Idle:
            break;

        case SimpleStates.BecomingAware:
            if (Time.time - awareDelayTimer > fuzzyDelay)
            {
                simpleState = SimpleStates.AwareOfPlayer;
            }
            break;

        case SimpleStates.AwareOfPlayer:

            Vector3 fVelocity = navMeshAgent.velocity;

            float d_p = AIBlackboard.DistanceToPlayer2D(transform.position);

            if (AIBlackboard.DistanceToPlayer2D(transform.position) > distanceFromPlayer)
            {
                fVelocity = Vector3.MoveTowards(fVelocity, AIBlackboard.DirectionToPlayer2D(transform.position), Time.deltaTime * 100 * aggressiveness);
            }

            if (d_p < tooCloseToPlayer)
            {
                fVelocity += -AIBlackboard.DirectionToPlayer2D(transform.position).normalized *playerSeparation;
            }

            if (monsterAttack != null)
            {
                if (monsterAttack.AttackCondition() && monsterAttack.HasAttackCooled())
                {
                    simpleState = SimpleStates.Attack;
                    monsterAware.PlayOneShot(monsterAware.clip, 0.3f);
                }
                else if (monsterAttack.CooldownLeft() < fear)
                {
                    fVelocity = Vector3.MoveTowards(fVelocity, -AIBlackboard.DirectionToPlayer2D(transform.position), Time.deltaTime * 40 * fear);
                }
            }

            fVelocity.x = Mathf.Clamp(fVelocity.x, -maxSpeed, maxSpeed);
            fVelocity.y = Mathf.Clamp(fVelocity.y, -maxSpeed, maxSpeed);
            fVelocity.z = Mathf.Clamp(fVelocity.z, -maxSpeed, maxSpeed);

            navMeshAgent.velocity = fVelocity;

            break;

        case SimpleStates.Attack:
            if (monsterAttack != null)
            {
                if (monsterAttack.RunAttack())
                {
                    simpleState = SimpleStates.AwareOfPlayer;
                }
            }
            break;
        }
    }
Exemplo n.º 4
0
 public override void BeginBehavior()
 {
     simpleState = SimpleStates.Idle;
     isAware     = false;
 }