コード例 #1
0
    IEnumerator executeActions()
    {
        if (gameFlowManager != null)
        {
            gameFlowManager.combatUI.anim.Play("HideSide");
        }

        while (!turnManager.ShouldWaitForPlayerAction(characterManager.GetActivePlayer()))
        {
            float           timer       = 0.0f;
            bool            missed      = false;
            CharacterAction action      = turnManager.Peek();
            CharacterAction enemyAction = action.Targets[0].ActiveAction; //TODO: Maybe add target enemy incase of multiple enemies

            if (action.Actor is Player)
            {
                if (action is Attack)
                {
                    gameFlowManager.combatUI.ShowAttackTimer(action.Actor.EquippedWeapon.GoalSize, action.Actor.EquippedWeapon.GoalPos, action.Actor.EquippedWeapon.TimerSpeed);
                    float delta    = action.Actor.EquippedWeapon.GoalSize * action.Actor.EquippedWeapon.TimerSpeed;
                    float minTimer = -action.Actor.EquippedWeapon.GoalPos / 360 * action.Actor.EquippedWeapon.TimerSpeed;
                    float maxTimer = minTimer + delta;
                    while (timer < action.Actor.EquippedWeapon.TimerSpeed && !action.Actor.hitBonus && !missed)
                    {
                        timer += Time.deltaTime;

                        if (timer > minTimer && timer < maxTimer)
                        {
                            if (Input.GetButton("Fire1"))
                            {
                                action.Actor.hitBonus = true;
                            }
                        }
                        else
                        {
                            if (Input.GetButton("Fire1"))
                            {
                                missed = true;
                            }
                        }


                        yield return(null);
                    }
                    gameFlowManager.combatUI.EndAttackTimer();
                    enemyHit.PlayVFX("small_0002"); //ToDo: Make this a variable passed by the player weapon type
                    enemyHit.PlaySFX("sword_whoosh_01");
                }
                else
                {
                    //Debug.Log("Player turn defend");
                }
            }
            else
            {
                if (action is Attack)
                {
                    //Debug.Log("Enemy turn attack");
                    if (enemyAction.Actor.ActiveAction is Defend)
                    {
                        action = enemyAction;
                        AttackDirection attackDir = enemyAction.Actor.GetAttackDirection(); //TODO: Make better system for choosing enemy attack direction
                        gameFlowManager.combatUI.ShowEnemyDirection(attackDir);
                        //Debug.Log("Enemy turn player defended");
                        bool hitDirection = false;
                        while (timer < defendTimer && !hitDirection)
                        {
                            timer += Time.deltaTime;

                            Vector2 dir = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));

                            if (dir.magnitude > 0)
                            {
                                hitDirection = true;
                            }

                            if (timer > inputStart && timer < inputEnd)
                            {
                                if (dir.x > 0 && attackDir == AttackDirection.Right)
                                {
                                    action.Actor.hitBonus = true;
                                }
                                else if (dir.x < 0 && attackDir == AttackDirection.Left)
                                {
                                    action.Actor.hitBonus = true;
                                }
                                else if (dir.y > 0 && attackDir == AttackDirection.Up)
                                {
                                    action.Actor.hitBonus = true;
                                }
                                else if (dir.y < 0 && attackDir == AttackDirection.Down)
                                {
                                    action.Actor.hitBonus = true;
                                }
                            }

                            yield return(null);
                        }
                        playerHit.PlayVFX("small_0002"); //ToDo: Make this a variable passed by the enemy
                        if (action.Actor.hitBonus)
                        {
                            playerHit.PlaySFX("sword_strike_armor_chain_04");
                        }
                        else
                        {
                            playerHit.PlaySFX("sword_whoosh_06");
                        }
                    }
                }
                else
                {
                    //Debug.Log("Enemy turn defend");
                }
            }

            if (action.Actor.hitBonus)
            {
                action.AddBonus();
            }

            ProcessNextAction();
            yield return(new WaitForSeconds(delayBetweenActions));
        }

        if (gameFlowManager.inBattle)
        {
            gameFlowManager.combatUI.anim.Play("ReturnSide");
        }
    }