Exemple #1
0
        private void UpdateFightState()
        {
            FightState currentFightState = new FightState();

            currentFightState.DistanceX = GetDistanceX();

            currentFightState.IsOpponentDamage = battleCore.Fighter1.CurrentActionID == (int)CommonActionID.Damage;

            currentFightState.IsOpponentGuardBreak =
                battleCore.Fighter1.CurrentActionID == (int)CommonActionID.GuardBreak;

            currentFightState.IsOpponentBlocking =
                battleCore.Fighter1.CurrentActionID == (int)CommonActionID.GuardCrouch ||
                battleCore.Fighter1.CurrentActionID == (int)CommonActionID.GuardStand ||
                battleCore.Fighter1.CurrentActionID == (int)CommonActionID.GuardM;

            currentFightState.IsOpponentNormalAttack =
                battleCore.Fighter1.CurrentActionID == (int)CommonActionID.NAttack ||
                battleCore.Fighter1.CurrentActionID == (int)CommonActionID.BAttack;

            currentFightState.IsOpponentSpecialAttack =
                battleCore.Fighter1.CurrentActionID == (int)CommonActionID.NSpecial ||
                battleCore.Fighter1.CurrentActionID == (int)CommonActionID.BSpecial;

            for (int i = 1; i < fightStates.Length; i++)
            {
                fightStates[i] = fightStates[i - 1];
            }

            fightStates[0] = currentFightState;
        }
Exemple #2
0
        public int GetNextAIInput()
        {
            int input = 0;

            UpdateFightState();
            FightState fightState = GetCurrentFightState();

            if (fightState != null)
            {
                //Globals.Logger.Log(fightState.distanceX);
                if (moveQueue.Count > 0)
                {
                    input |= moveQueue.Dequeue();
                }
                else if (moveQueue.Count == 0)
                {
                    SelectMovement(fightState);
                }

                if (attackQueue.Count > 0)
                {
                    input |= attackQueue.Dequeue();
                }
                else if (attackQueue.Count == 0)
                {
                    SelectAttack(fightState);
                }
            }

            return(input);
        }
Exemple #3
0
        private void Awake()
        {
            // Setup dictionary from ScriptableObject data
            foreach (FighterData data in FighterDataList)
            {
                data.SetupDictionary();
            }

            Fighter1 = new Fighter();
            Fighter2 = new Fighter();

            Fighters.Add(Fighter1);
            Fighters.Add(Fighter2);

            debugP2Attack = false;
            debugP2Guard  = false;

            if (roundUI != null)
            {
                RoundUIAnimator = roundUI.GetComponent <Animator>();
            }

            stateMachine = new StateMachine();
            stateMachine.AddState(new StopState(this));
            stateMachine.AddState(new IntroState(this));

            FightState fightState = new FightState(this);

            fightState.DamageOccurred += (damaged, damagePos, damageResult) => DamageOccurred?.Invoke(damaged, damagePos, damageResult);             // TODO refactor this
            stateMachine.AddState(new FightState(this));
            stateMachine.AddState(new KOState(this));
            stateMachine.AddState(new EndState(this));

            stateMachine.SetState <StopState>();
        }
Exemple #4
0
        private void UpdateFightState()
        {
            var currentFightState = new FightState();

            currentFightState.distanceX            = GetDistanceX();
            currentFightState.isOpponentDamage     = battleCore.fighter1.currentActionID == (int)CommonActionID.DAMAGE;
            currentFightState.isOpponentGuardBreak = battleCore.fighter1.currentActionID == (int)CommonActionID.GUARD_BREAK;
            currentFightState.isOpponentBlocking   = (battleCore.fighter1.currentActionID == (int)CommonActionID.GUARD_CROUCH ||
                                                      battleCore.fighter1.currentActionID == (int)CommonActionID.GUARD_STAND ||
                                                      battleCore.fighter1.currentActionID == (int)CommonActionID.GUARD_M);
            currentFightState.isOpponentNormalAttack = (battleCore.fighter1.currentActionID == (int)CommonActionID.N_ATTACK ||
                                                        battleCore.fighter1.currentActionID == (int)CommonActionID.B_ATTACK);
            currentFightState.isOpponentSpecialAttack = (battleCore.fighter1.currentActionID == (int)CommonActionID.N_SPECIAL ||
                                                         battleCore.fighter1.currentActionID == (int)CommonActionID.B_SPECIAL);

            for (int i = 1; i < fightStates.Length; i++)
            {
                fightStates[i] = fightStates[i - 1];
            }
            fightStates[0] = currentFightState;
        }
Exemple #5
0
 private void SelectMovement(FightState fightState)
 {
     if (fightState.DistanceX > 4f)
     {
         int rand = Random.Range(0, 2);
         if (rand == 0)
         {
             AddFarApproach1();
         }
         else
         {
             AddFarApproach2();
         }
     }
     else if (fightState.DistanceX > 3f)
     {
         int rand = Random.Range(0, 7);
         if (rand <= 1)
         {
             AddMidApproach1();
         }
         else if (rand <= 3)
         {
             AddMidApproach2();
         }
         else if (rand == 4)
         {
             AddFarApproach1();
         }
         else if (rand == 5)
         {
             AddFarApproach2();
         }
         else
         {
             AddNeutralMovement();
         }
     }
     else if (fightState.DistanceX > 2.5f)
     {
         int rand = Random.Range(0, 5);
         if (rand == 0)
         {
             AddMidApproach1();
         }
         else if (rand == 1)
         {
             AddMidApproach2();
         }
         else if (rand == 2)
         {
             AddFallBack1();
         }
         else if (rand == 3)
         {
             AddFallBack2();
         }
         else
         {
             AddNeutralMovement();
         }
     }
     else if (fightState.DistanceX > 2f)
     {
         int rand = Random.Range(0, 4);
         if (rand == 0)
         {
             AddFallBack1();
         }
         else if (rand == 1)
         {
             AddFallBack2();
         }
         else
         {
             AddNeutralMovement();
         }
     }
     else
     {
         int rand = Random.Range(0, 3);
         if (rand == 0)
         {
             AddFallBack1();
         }
         else if (rand == 1)
         {
             AddFallBack2();
         }
         else
         {
             AddNeutralMovement();
         }
     }
 }
Exemple #6
0
        private void SelectAttack(FightState fightState)
        {
            if (fightState.IsOpponentDamage ||
                fightState.IsOpponentGuardBreak ||
                fightState.IsOpponentSpecialAttack)
            {
                AddTwoHitImmediateAttack();
            }
            else if (fightState.DistanceX > 4f)
            {
                int rand = Random.Range(0, 4);
                if (rand <= 3)
                {
                    AddNoAttack();
                }
                else
                {
                    AddDelaySpecialAttack();
                }
            }
            else if (fightState.DistanceX > 3f)
            {
                if (fightState.IsOpponentNormalAttack)
                {
                    AddTwoHitImmediateAttack();
                    return;
                }

                int rand = Random.Range(0, 5);
                if (rand <= 1)
                {
                    AddNoAttack();
                }
                else if (rand <= 3)
                {
                    AddOneHitImmediateAttack();
                }
                else
                {
                    AddDelaySpecialAttack();
                }
            }
            else if (fightState.DistanceX > 2.5f)
            {
                int rand = Random.Range(0, 3);
                if (rand == 0)
                {
                    AddNoAttack();
                }
                else if (rand == 1)
                {
                    AddOneHitImmediateAttack();
                }
                else
                {
                    AddTwoHitImmediateAttack();
                }
            }
            else if (fightState.DistanceX > 2f)
            {
                int rand = Random.Range(0, 6);
                if (rand <= 1)
                {
                    AddOneHitImmediateAttack();
                }
                else if (rand <= 3)
                {
                    AddTwoHitImmediateAttack();
                }
                else if (rand == 4)
                {
                    AddImmediateSpecialAttack();
                }
                else
                {
                    AddDelaySpecialAttack();
                }
            }
            else
            {
                int rand = Random.Range(0, 3);
                if (rand == 0)
                {
                    AddOneHitImmediateAttack();
                }
                else
                {
                    AddTwoHitImmediateAttack();
                }
            }
        }