示例#1
0
    IEnumerator PatrolingCor()
    {
        yield return(new WaitForSeconds(AggressionCooldownTime));

        BehaivourType = Behaivour.Patroling;
    }
示例#2
0
    void Normal_Update()
    {
        // Bow Attack over here
        if (CanShoot)
        {
            bowAttackCooldownTimer = BowAttackCooldownTime;
            fsm.ChangeState(States.BowAttack, StateTransition.Overwrite);
            return;
        }

        if (CanCast)
        {
            castAttackCooldownTimer = CastAttackCooldownTime;
            fsm.ChangeState(States.Cast, StateTransition.Overwrite);
            return;
        }

        if (CanAttack)
        {
            Debug.Log("attack");
            meleeAttackCooldownTimer = MeleeAttackCooldownTime;
            fsm.ChangeState(States.Attack, StateTransition.Overwrite);
            return;
        }

        if (CanFirstSpecial)
        {
            firstSpecialAttackCooldownTimer = FirstSpecialAttackCooldownTime;
            fsm.ChangeState(States.FirstSpecial, StateTransition.Overwrite);
            return;
        }

        if (CanSecondSpecial)
        {
            secondSpecialAttackCooldownTimer = SecondSpecialAttackCooldownTime;
            fsm.ChangeState(States.SecondSpecial, StateTransition.Overwrite);
            return;
        }

        if (CanThirdSpecial)
        {
            thirdSpecialAttackCooldownTimer = ThirdSpecialAttackCooldownTime;
            fsm.ChangeState(States.ThirdSpecial, StateTransition.Overwrite);
            return;
        }

        if (CanStuned)
        {
            //stunedCooldownTimer = StunedCooldownTime;
            fsm.ChangeState(States.Hit, StateTransition.Overwrite);
            return;
        }

        if (CanAggression)
        {
            BehaivourType = Behaivour.Aggression;
            StartCoroutine("PatrolingCor");
            OnAggression = false;
        }

        if (CanIdle)
        {
            fsm.ChangeState(States.Normal, StateTransition.Overwrite);
            BehaivourType = Behaivour.Idle;
            return;
        }

        if (CanBlink)
        {
            blinkCooldownTimer = BlinkCooldownTime;
            OnBlink            = false;
            fsm.ChangeState(States.Blink, StateTransition.Overwrite);
            return;
        }

        if (BehaivourType == Behaivour.Idle)//if (expectationCooldownTimer >= 0f)
        {
            BehaivourType = Behaivour.Patroling;
        }

        float num = onGround ? 1f : 0.65f;

        if (BehaivourType == Behaivour.Patroling)
        {
            // преследование
            if (InDetectionZone)
            {
                OnAggression = true;
                OnBlink      = true;
            }
            // патрулироавние
            else if (!InVisibilityZone)
            {
                Speed.x = Calc.Approach(Speed.x, moveX * walkSpeed, RunReduce * num * Time.deltaTime);

                if (!onGround)
                {
                    float target = MaxFall;
                    Speed.y = Calc.Approach(Speed.y, target, Gravity * Time.deltaTime);
                }

                if (moveX != 0 && CheckColInDir(new Vector2(moveX, 0), bumper_layer) || CheckColInDir(new Vector2(moveX, 0), solid_layer))
                {
                    if (turnCooldownTimer <= 0f)
                    {
                        CharacterRotation();
                        moveX            *= -1;
                        turnCooldownTimer = TurnCooldownTime;
                    }
                }
            }
        }

        if (BehaivourType == Behaivour.Following)
        {
            if (InDetectionZone)
            {
                if (moveX != 0 && CheckColInDir(new Vector2(moveX, 0), solid_layer))
                {
                    if (turnCooldownTimer <= 0f)
                    {
                        CharacterRotation();
                        moveX            *= -1;
                        turnCooldownTimer = TurnCooldownTime;
                    }
                }

                if (!InVisibilityZone)
                {
                    if (turnCooldownTimer <= 0f)
                    {
                        CharacterRotation();
                        moveX            *= -1;
                        turnCooldownTimer = TurnCooldownTime;
                    }
                }

                Speed.x = Calc.Approach(Speed.x, moveX * walkSpeed, RunReduce * num * Time.deltaTime);

                if (!onGround)
                {
                    float target = MaxFall;
                    Speed.y = Calc.Approach(Speed.y, target, Gravity * Time.deltaTime);
                }
            }
        }

        if (BehaivourType == Behaivour.Aggression)  // переделать новую зону
        {
            Speed.x = Calc.Approach(Speed.x, 0f, RunReduce * num * Time.deltaTime);

            if (!(moveX != 0 && CheckColInDir(new Vector2(moveX, 0), solid_layer)))
            {
                Speed.x = Calc.Approach(Speed.x, moveX * walkSpeed, RunReduce * num * Time.deltaTime);
            }

            var diff = Player.transform.position.x - transform.position.x; //позиция

            if (-(int)Facing * diff < 0)                                   // разворот за игроком
            {
                if (turnCooldownTimer <= 0f)
                {
                    CharacterRotation();
                    moveX            *= -1;
                    turnCooldownTimer = TurnCooldownTime;
                }
            }
            if (!onGround)
            {
                float target = MaxFall;
                Speed.y = Calc.Approach(Speed.y, target, Gravity * Time.deltaTime);
            }
        }

        if (BehaivourType == Behaivour.Idle)
        {
            // Horizontal Speed Update Section

            Speed.x = Calc.Approach(Speed.x, 0f, RunReduce * num * Time.deltaTime);

            if (!onGround)
            {
                float target = MaxFall;
                Speed.y = Calc.Approach(Speed.y, target, Gravity * Time.deltaTime);
            }
        }

        // Special
        if (hasFirstSpecial && hasSecondSpecial && hasThirdSpecial && InDetectionZone)
        {
            int rnd = Random.Range(0, 2);
            Debug.Log("random special attack:" + rnd);
            OnSpecial = false;
            if (rnd == 0)
            {
                StartCoroutine("FirstSpecialCoroutine");
            }
            if (rnd == 1)
            {
                StartCoroutine("SecondSpecialCoroutine");
            }
            if (rnd == 2)
            {
                StartCoroutine("ThirdSpecialCoroutine");
            }
        }

        if (hasFirstSpecial && hasSecondSpecial && InDetectionZone)
        {
            int rnd = Random.Range(0, 1);
            Debug.Log("random special attack:" + rnd);
            OnSpecial = false;
            if (rnd == 0)
            {
                StartCoroutine("FirstSpecialCoroutine");
            }
            if (rnd == 1)
            {
                StartCoroutine("SecondSpecialCoroutine");
            }
        }

        if (hasFirstSpecial && InDetectionZone)
        {
            OnSpecial = false;
            StartCoroutine("FirstSpecialCoroutine");
        }
    }