Esempio n. 1
0
    private IEnumerator GiantHazardEmission(float minRate, float maxRate)
    {
        GameManager_LevelManager.emitState = EmitState.Giant;
        //emitHazardsComponent.enabled = false;
        float oldXPos = 5;         // Out of valid X range value.

        yield return(new WaitForSeconds(delay));

        //hazardsNumber = numberOfHazards;
        int i = 0;

        while (i < numberOfHazards)
        {
            float newXPos = FixedRandom.Range(-4, 4, 2);
            if (newXPos != oldXPos)
            {
                Instantiate(giantHazard, new Vector3(newXPos, 0.0f, GameManager_EmitHazards.fixedZPosition), Quaternion.identity);
                oldXPos = newXPos;
                i++;
            }
            else
            {
                continue;
            }
            yield return(new WaitForSeconds(Random.Range(minRate, maxRate)));
        }
        yield return(new WaitForSeconds(1));

        gmMaster.CallEventPhaseChanged("EmitHazards");
        GameManager_LevelManager.emitState = EmitState.Regular;
    }
    void ChangeStatus(EmMyStatus newStatus)
    {
        timer     = 0f;
        curStatus = newStatus;
        switch (newStatus)
        {
        case EmMyStatus.Idle:
            Actor.Idle();
            statusDuration = FixedRandom.Range(0, idlMaxDuration);
            break;

        case EmMyStatus.RandomMoveDirection:
        case EmMyStatus.RandomMoveDirectionAfterAttack:
            Vector3[] dirs = new Vector3[]
            {
                new Vector3(0, 0, 1),
                new Vector3(1, 0, 1),
                new Vector3(1, 0, 0),
                new Vector3(1, 0, -1),
                new Vector3(0, 0, -1),
                new Vector3(-1, 0, -1),
                new Vector3(-1, 0, 0),
                new Vector3(-1, 0, 1),
            };
            randomMoveDir = dirs[FixedRandom.Range(0, 8)];
            randomMovePos = Actor.transform.position + randomMoveDir * 3;
            Actor.LookAt(randomMovePos);
            statusDuration = moveMaxDuratoin;
            break;

        case EmMyStatus.MoveToTarget:
            Actor.LookAt(attackTarget.transform.position);
            break;

        case EmMyStatus.AttackPrepair:
            Actor.Idle();
            statusDuration = attackPrepairDuration;
            break;

        case EmMyStatus.NormalAttack:
            Actor.Attack();
            break;

        case EmMyStatus.BeAttacked:
            break;
        }
    }
    // Update is called once per frame
    public void Tick(float deltaTime)
    {
        timer += deltaTime;

        if (Actor.IsBeAttacked())
        {
            ChangeStatus(EmMyStatus.BeAttacked);
            return;
        }

        if (Actor.IsDead() || Actor.IsDying())
        {
            return;
        }

        switch (curStatus)
        {
        case EmMyStatus.Idle:
            if (timer >= statusDuration)
            {
                int r = FixedRandom.Range(0, 101);
                if (r < idleRandom)
                {
                }
                else if (r < idleRandom + moveRandom)
                {
                    ChangeStatus(EmMyStatus.RandomMoveDirection);
                }
            }

            //if(Patrol()) MoveToTarget();

            break;

        case EmMyStatus.RandomMoveDirection:
        case EmMyStatus.RandomMoveDirectionAfterAttack:
            Actor.WalkForward(0);
            if (timer >= statusDuration)
            {
                ChangeStatus(EmMyStatus.Idle);
            }

            //if(curStatus == EmMyStatus.RandomMoveDirection)
            //	if(Patrol()) MoveToTarget();
            break;

        case EmMyStatus.MoveToTarget:
            Actor.LookAt(attackTarget.transform.position);
            Actor.WalkForward(0);
            if (Vector3.SqrMagnitude(Actor.transform.position - moveToTarget.transform.position) < 2 * 2)
            {
                ChangeStatus(EmMyStatus.AttackPrepair);
            }
            break;

        case EmMyStatus.AttackPrepair:
            if (timer >= attackPrepairDuration)
            {
                if (attackTarget != null && attackTarget.IsAlive() &&
                    (Actor.transform.position - moveToTarget.transform.position).sqrMagnitude <= 2 * 2)
                {
                    DoAttack();
                }
                else
                {
                    ChangeStatus(EmMyStatus.Idle);
                }
            }

            break;

        case EmMyStatus.NormalAttack:
            if (Actor.IsIdle())
            {
                ChangeStatus(EmMyStatus.Idle);
            }
            break;

        case EmMyStatus.BeAttacked:
            if (Actor.IsIdle())
            {
                ChangeStatus(EmMyStatus.Idle);
            }
            break;
        }
    }