Пример #1
0
    public void RunAction(GameObject actionUser)
    {
        //RUNNER TURN
        RunnerBehaviour runnerBehaviourScript = PlayerUtils.FetchRunnerBehaviourScript(actionUser);

        runnerBehaviourScript.GoToNextBase(runnerBehaviourScript.CurrentBase);
    }
Пример #2
0
    public void StayOnBaseAction(GameObject actionUser)
    {
        //RUNNER TURN
        RunnerBehaviour runnerBehaviourScript = PlayerUtils.FetchRunnerBehaviourScript(actionUser);

        runnerBehaviourScript.StayOnCurrentBase();
    }
    public void TagOutRunner(GameObject targetToTagOut)
    {
        PlayerStatus       newBatterStatus        = null;
        GameManager        gameManager            = GameUtils.FetchGameManager();
        DialogBoxManager   dialogBoxManagerScript = GameUtils.FetchDialogBoxManager();
        PlayersTurnManager playersTurnManager     = GameUtils.FetchPlayersTurnManager();


        RunnerBehaviour tagOutRunnerBehaviourScript = PlayerUtils.FetchRunnerBehaviourScript(targetToTagOut);

        int batterCount = gameManager.AttackTeamBatterListClone.Count;

        //test in case there no one left to pick
        if (batterCount > 0)
        {
            GameObject newBatter = gameManager.AttackTeamBatterListClone.First();
            newBatterStatus = PlayerUtils.FetchPlayerStatusScript(newBatter);
            BatterBehaviour newbatterBehaviourScript = PlayerUtils.FetchBatterBehaviourScript(newBatter);
            newbatterBehaviourScript.EquipedBat = tagOutRunnerBehaviourScript.EquipedBat;
            newBatter.SetActive(true);
        }

        dialogBoxManagerScript.DisplayDialogAndTextForGivenAmountOfTime(1f, false, "TAG OUT !!!!!!!");
        tagOutRunnerBehaviourScript.EquipedBat = null;
        gameManager.AttackTeamRunnerList.Remove(targetToTagOut);
        targetToTagOut.SetActive(false);
        playersTurnManager.UpdatePlayerTurnQueue(targetToTagOut);


        int runnersCount = gameManager.AttackTeamRunnerList.Count;

        bool isRunnersAllSafeAndStaying = gameManager.AttackTeamRunnerList.TrueForAll(runner => {
            RunnerBehaviour runnerBehaviour = PlayerUtils.FetchRunnerBehaviourScript(runner);
            return(runnerBehaviour.IsSafe && runnerBehaviour.IsStaying);
        });

        if (runnersCount == 0 && batterCount == 0 || batterCount == 0 && runnersCount > 0 && isRunnersAllSafeAndStaying)
        {
            gameManager.ProcessNextInningHalf();
        }
        else if (runnersCount == 0 && batterCount > 0)
        {
            StartCoroutine(gameManager.WaitAndReinit(dialogBoxManagerScript, newBatterStatus, FieldBall));
        }
        else if (runnersCount > 0)
        {
            if (isRunnersAllSafeAndStaying && batterCount > 0)
            {
                StartCoroutine(gameManager.WaitAndReinit(dialogBoxManagerScript, newBatterStatus, FieldBall));
            }
            else
            {
                playersTurnManager.TurnState      = TurnStateEnum.FIELDER_TURN;
                PlayersTurnManager.IsCommandPhase = true;
            }
        }
    }
    private GameObject GetNextRunner()
    {
        GameObject foundRunner;

        if (this.NextRunner == null)
        {
            List <GameObject> runnerList = GameManager.AttackTeamRunnerListClone;
            int runnerListCount          = runnerList.Count;
            int currentIndex             = runnerList.IndexOf(this.CurrentRunner);
            foundRunner = this.FullRunnerSearch(currentIndex, runnerListCount, runnerList);
        }
        else
        {
            int             precalculatedRunnerIndex = GameManager.AttackTeamRunnerListClone.IndexOf(this.NextRunner);
            RunnerBehaviour runnerBehaviour          = PlayerUtils.FetchRunnerBehaviourScript(this.NextRunner);
            if (this.IsplayerAvailable(this.NextRunner.name) && !runnerBehaviour.IsStaying && this.NextRunner.activeInHierarchy)
            {
                this.CurrentRunner = this.NextRunner;


                if (precalculatedRunnerIndex != GameManager.AttackTeamRunnerListClone.Count - 1)
                {
                    this.NextRunner = GameManager.AttackTeamRunnerListClone[precalculatedRunnerIndex + 1];
                }
                else
                {
                    this.NextRunner = GameManager.AttackTeamRunnerListClone.First();
                }
                foundRunner = this.CurrentRunner;
            }
            else
            {
                foundRunner = this.FullRunnerSearch(precalculatedRunnerIndex, GameManager.AttackTeamRunnerListClone.Count, GameManager.AttackTeamRunnerListClone);
            }
        }

        if (foundRunner == null)
        {
            IsRunnersTurnsDone = true;
            gameManager.IsStateCheckAllowed = true;
            TurnState      = TurnStateEnum.STANDBY;
            IsCommandPhase = false;
        }

        return(foundRunner);
    }
    public void ReplanAction()
    {
        GameManager gameManager      = GameUtils.FetchGameManager();
        bool        isRunnersAllSafe = gameManager.AttackTeamRunnerList.TrueForAll(runner => {
            RunnerBehaviour runnerBehaviour = PlayerUtils.FetchRunnerBehaviourScript(runner);
            return(runnerBehaviour.IsSafe);
        });

        if (isRunnersAllSafe)
        {
            gameManager.IsStateCheckAllowed = true;
        }
        else
        {
            PlayersTurnManager playersTurnManager = GameUtils.FetchPlayersTurnManager();
            playersTurnManager.TurnState      = TurnStateEnum.FIELDER_TURN;
            PlayersTurnManager.IsCommandPhase = true;
        }
    }
    public GameObject GetNextRunnerTakingAction()
    {
        List <GameObject> availableRunnerList = GameManager.AttackTeamRunnerList
                                                .Where(attackTeamRunner => {
            RunnerBehaviour runnerBehaviour = PlayerUtils.FetchRunnerBehaviourScript(attackTeamRunner);
            return(this.IsplayerAvailable(attackTeamRunner.name) && !runnerBehaviour.IsStaying);
        })
                                                .ToList();

        int runnerCount = availableRunnerList.Count;

        if (runnerCount == 0)
        {
            return(null);
        }

        GameObject runner;

        if (CurrentRunner == null)
        {
            runner = availableRunnerList.First();
        }
        else
        {
            runner = CurrentRunner;
        }

        int runnerIndex = availableRunnerList.IndexOf(runner);

        if (runnerIndex == runnerCount - 1)
        {
            runner = availableRunnerList.First();
        }
        else
        {
            runner = availableRunnerList[runnerIndex + 1];
        }

        return(runner);
    }
    private GameObject FilterCurrentSearchRunner(int i, List <GameObject> runnerList, int runnerListCount)
    {
        GameObject      currentSearchRunner = runnerList[i];
        RunnerBehaviour runnerBehaviour     = PlayerUtils.FetchRunnerBehaviourScript(currentSearchRunner);

        if (this.IsplayerAvailable(currentSearchRunner.name) && !runnerBehaviour.IsStaying && currentSearchRunner.activeInHierarchy)
        {
            if (i != runnerListCount - 1)
            {
                this.NextRunner = runnerList[i + 1];
            }
            else
            {
                this.NextRunner = runnerList.First();
            }

            this.CurrentRunner = currentSearchRunner;
            return(this.CurrentRunner);
        }

        return(null);
    }
    public void StayOnCurrentBase()
    {
        Debug.Log(this.name + " wait on current base");
        this.IsStaying = true;
        PlayersTurnManager playersTurnManager = GameUtils.FetchPlayersTurnManager();

        playersTurnManager.UpdatePlayerTurnAvailability(this.gameObject.name, TurnAvailabilityEnum.WAITING);
        IsoRenderer.ReinitializeAnimator();

        GameManager gameManager = GameUtils.FetchGameManager();

        bool isRunnersAllSafeAndStaying = gameManager.AttackTeamRunnerList.TrueForAll(runner => {
            RunnerBehaviour runnerBehaviour = PlayerUtils.FetchRunnerBehaviourScript(runner);
            return(runnerBehaviour.IsSafe && runnerBehaviour.IsStaying);
        });

        //test if all remaining runner are out and there no more batters
        int runnersCount = gameManager.AttackTeamRunnerList.Count;
        int batterCount  = gameManager.AttackTeamBatterListClone.Count;

        if (runnersCount == 0 && batterCount == 0 || batterCount == 0 && runnersCount > 0 && isRunnersAllSafeAndStaying)
        {
            gameManager.IsStateCheckAllowed = false;
            gameManager.ProcessNextInningHalf();
            return;
        }
        else if (isRunnersAllSafeAndStaying)
        {
            playersTurnManager.IsRunnersTurnsDone = true;
        }

        Vector3 nextBasePosition = this.GetNextBasePosition(this.CurrentBase);

        IsoRenderer.LookAtFieldElementAnimation(nextBasePosition);

        this.CalculateNextAction();
    }
    public void CalculatePitcherColliderInterraction(GameObject ballGameObject, BallController ballControllerScript, GenericPlayerBehaviour genericPlayerBehaviourScript)
    {
        int runnersOnFieldCount   = -1;
        List <GameObject> runners = PlayerUtils.GetRunnersOnField();

        runnersOnFieldCount = runners.Count;

        if (runnersOnFieldCount < 1)
        {
            return;
        }

        //Choose the runner who just hit the ball
        GameObject runnerToGetOut = runners.Last();

        bool hasIntercepted = false;
        PlayersTurnManager playersTurnManager = GameUtils.FetchPlayersTurnManager();

        if (ballControllerScript.BallHeight == BallHeightEnum.HIGH || ballControllerScript.BallHeight == BallHeightEnum.LOW)
        {
            GameManager      gameManager            = GameUtils.FetchGameManager();
            DialogBoxManager dialogBoxManagerScript = GameUtils.FetchDialogBoxManager();
            dialogBoxManagerScript.DisplayDialogAndTextForGivenAmountOfTime(1f, false, "TAG OUT !!!!!!!");

            ballControllerScript.Target = null;


            PlayerActionsManager.InterceptBall(ballGameObject, ballControllerScript, genericPlayerBehaviourScript);
            hasIntercepted = true;

            gameManager.AttackTeamRunnerList.Remove(runnerToGetOut);
            runnerToGetOut.SetActive(false);
            playersTurnManager.UpdatePlayerTurnQueue(runnerToGetOut);
            gameManager.AttackTeamBatterListClone.First().SetActive(true);
            RunnerBehaviour runnerBehaviourScript = PlayerUtils.FetchRunnerBehaviourScript(runnerToGetOut);
            BatterBehaviour batterBehaviourScript = PlayerUtils.FetchBatterBehaviourScript(gameManager.AttackTeamBatterListClone.First());
            batterBehaviourScript.EquipedBat = runnerBehaviourScript.EquipedBat;
            runnerBehaviourScript.EquipedBat = null;

            if (runnersOnFieldCount == 1)
            {
                GameData.isPaused = true;
                StartCoroutine(gameManager.WaitAndReinit(dialogBoxManagerScript, PlayerUtils.FetchPlayerStatusScript(gameManager.AttackTeamBatterListClone.First()), FieldBall));
                return;
            }
            else
            {
                GameObject bat = batterBehaviourScript.EquipedBat;
                bat.transform.SetParent(null);
                bat.transform.position = FieldUtils.GetBatCorrectPosition(batterBehaviourScript.transform.position);
                bat.transform.rotation = Quaternion.Euler(0f, 0f, -70f);
                bat.transform.SetParent(gameManager.AttackTeamBatterListClone.First().transform);
                batterBehaviourScript.EquipedBat.SetActive(true);
                TeamUtils.AddPlayerTeamMember(PlayerFieldPositionEnum.BATTER, batterBehaviourScript.gameObject, TeamUtils.GetBaseballPlayerOwner(batterBehaviourScript.gameObject));
            }
        }

        if (runnersOnFieldCount >= 1)
        {
            if (!hasIntercepted)
            {
                PlayerActionsManager.InterceptBall(ballGameObject, ballControllerScript, genericPlayerBehaviourScript);
            }

            PlayerActionsManager playerActionsManager = GameUtils.FetchPlayerActionsManager();
            PlayerAbilities      playerAbilities      = PlayerUtils.FetchPlayerAbilitiesScript(this.gameObject);
            playerAbilities.ReinitAbilities();
            PlayerAbility passPlayerAbility = new PlayerAbility("Pass to fielder", AbilityTypeEnum.BASIC, AbilityCategoryEnum.NORMAL, playerActionsManager.GenericPassAction, this.gameObject, true);
            playerAbilities.AddAbility(passPlayerAbility);
            playersTurnManager.TurnState      = TurnStateEnum.PITCHER_TURN;
            PlayersTurnManager.IsCommandPhase = true;
        }
    }
    public void CalculateRunnerColliderInterraction(BaseEnum baseReached, bool isNextRunnerTurnPossible = false)
    {
        Debug.Log(this.name + " interracted with " + baseReached.ToString());
        this.CurrentBase = baseReached;

        PlayerStatus playerStatusScript = PlayerUtils.FetchPlayerStatusScript(this.gameObject);

        this.EnableMovement = false;

        PlayersTurnManager   playersTurnManager   = GameUtils.FetchPlayersTurnManager();
        TurnAvailabilityEnum turnAvailabilityEnum = TurnAvailabilityEnum.READY;

        switch (baseReached)
        {
        case BaseEnum.HOME_BASE:

            if (baseReached == BaseEnum.HOME_BASE && !this.HasPassedThroughThreeFirstBases())
            {
                Debug.Log("Get on HOME BASE FIRST TIME !!");
                this.NextBase = BaseEnum.FIRST_BASE;
                playersTurnManager.TurnState = TurnStateEnum.STANDBY;
                playersTurnManager.UpdatePlayerTurnAvailability(this.gameObject.name, turnAvailabilityEnum);
            }
            else
            {
                Debug.Log("Get on HOME BASE to mark a point");
                Debug.Log("WIN ONE POINT !!!");
                this.Target   = null;
                this.NextBase = this.CurrentBase;
                playerStatusScript.IsAllowedToMove = false;
                this.HasReachedHomeBase            = true;

                PlayerEnum        playerEnum = playerStatusScript.PlayerOwner;
                TeamsScoreManager teamsScoreManagerScript = GameUtils.FetchTeamsScoreManager();
                teamsScoreManagerScript.IncrementTeamScore(GameData.teamIdEnumMap[playerEnum]);
                this.IsStaying = true;
                IsoRenderer.ReinitializeAnimator();
                GameManager gameManager = GameUtils.FetchGameManager();

                this.gameObject.SetActive(false);
                gameManager.AttackTeamRunnerList.Remove(this.gameObject);
                playersTurnManager.UpdatePlayerTurnQueue(this.gameObject);
                gameManager.AttackTeamRunnerHomeList.Add(this.gameObject);

                int batterCount = gameManager.AttackTeamBatterListClone.Count;
                if (this.EquipedBat != null && batterCount > 0)
                {
                    GameObject      newBatter = gameManager.AttackTeamBatterListClone.First();
                    BatterBehaviour newbatterBehaviourScript = PlayerUtils.FetchBatterBehaviourScript(newBatter);
                    newbatterBehaviourScript.EquipedBat = this.EquipedBat;
                    this.EquipedBat = null;
                    gameManager.EquipBatToPlayer(newBatter);
                }

                int runnersCount = gameManager.AttackTeamRunnerList.Count;

                bool isRunnersAllSafeAndStaying = gameManager.AttackTeamRunnerList.TrueForAll(runner => {
                    RunnerBehaviour runnerBehaviour = PlayerUtils.FetchRunnerBehaviourScript(runner);
                    return(runnerBehaviour.IsSafe && runnerBehaviour.IsStaying);
                });

                if (runnersCount == 0 && batterCount == 0 || batterCount == 0 && runnersCount > 0 && isRunnersAllSafeAndStaying)
                {
                    gameManager.IsStateCheckAllowed = false;
                    gameManager.ProcessNextInningHalf();
                }
                else
                {
                    gameManager.IsStateCheckAllowed = true;
                }
            }

            break;

        case BaseEnum.FIRST_BASE:
            Debug.Log("Get on FIRST BASE");

            this.NextBase            = BaseEnum.SECOND_BASE;
            this.HasReachedFirstBase = true;
            if (this.IsInWalkState)
            {
                this.IsInWalkState   = false;
                turnAvailabilityEnum = TurnAvailabilityEnum.WAITING;
                IsoRenderer.ReinitializeAnimator();
            }

            playersTurnManager.UpdatePlayerTurnAvailability(this.gameObject.name, turnAvailabilityEnum);
            break;

        case BaseEnum.SECOND_BASE:
            Debug.Log("Get on SECOND BASE");
            this.NextBase             = BaseEnum.THIRD_BASE;
            this.HasReachedSecondBase = true;
            playersTurnManager.UpdatePlayerTurnAvailability(this.gameObject.name, turnAvailabilityEnum);
            break;

        case BaseEnum.THIRD_BASE:
            Debug.Log("Get on THIRD BASE");
            this.NextBase            = BaseEnum.HOME_BASE;
            this.HasReachedThirdBase = true;
            playersTurnManager.UpdatePlayerTurnAvailability(this.gameObject.name, turnAvailabilityEnum);
            break;

        default:
            Debug.Log("DO NOT KNOW WHAT HAPPEN");
            break;
        }

        if (isNextRunnerTurnPossible)
        {
            playersTurnManager.TurnState      = TurnStateEnum.RUNNER_TURN;
            PlayersTurnManager.IsCommandPhase = true;
        }
    }