private IEnumerator WaitForCondition() { //Wait while the commande pannel is displayed to avoid issues yield return(new WaitWhile(() => PlayersTurnManager.IsCommandPhase)); GameManager gameManager = GameUtils.FetchGameManager(); //Wait an additionnal 4 second to be sure the catcher wait tat the ball gone far enough //Also check for the pannel display to be realy sure if (gameManager.AttackTeamRunnerList.Count > 1) { yield return(new WaitForSeconds(4f)); yield return(new WaitWhile(() => PlayersTurnManager.IsCommandPhase)); } //Catcher must go look for the ball PlayerActionsManager playerActionsManager = GameUtils.FetchPlayerActionsManager(); CatcherBehaviour catcherBehaviour = PlayerUtils.FetchCatcherBehaviourScript(this.gameObject); playerActionsManager.AimForTheBall(catcherBehaviour); //switch the catcher mode (mode normal, mode fielder) this.CatcherMode = ModeConstants.CATCHER_FIELDER_MODE; //Add the relevant abilities this.AddFielderAbilitiesToCatcher(this.gameObject); }
public static PlayerActionsManager FetchPlayerActionsManager() { GameObject playerActionsManagerObject = GameObject.FindGameObjectWithTag(TagsConstants.PLAYER_ACTIONS_MANAGER_TAG); PlayerActionsManager playerActionsManager = playerActionsManagerObject.GetComponent <PlayerActionsManager>(); return(playerActionsManager); }
public void TriggeredBy(HandActionId action, GameObject actorGameObject) { PlayerActionsManager actorActionsManager = actorGameObject.GetComponent <PlayerActionsManager>(); PlayerHandAction playerHandAction = PlayerHandAction.CreateAction(action, actorGameObject, gameObject); actorActionsManager.EnqueueAction(playerHandAction); }
public void AddFielderAbilitiesToCatcher(GameObject player) { PlayerActionsManager playerActionsManager = GameUtils.FetchPlayerActionsManager(); PlayerAbilities playerAbilities = PlayerUtils.FetchPlayerAbilitiesScript(player); playerAbilities.ReinitAbilities(); PlayerAbility passPlayerAbility = new PlayerAbility("Pass to fielder", AbilityTypeEnum.BASIC, AbilityCategoryEnum.NORMAL, playerActionsManager.GenericPassAction, player, true); playerAbilities.AddAbility(passPlayerAbility); }
public void AddRunnerAbilitiesToBatter(GameObject player) { PlayerActionsManager playerActionsManager = GameUtils.FetchPlayerActionsManager(); PlayerAbilities playerAbilities = PlayerUtils.FetchPlayerAbilitiesScript(player); playerAbilities.ReinitAbilities(); PlayerAbility runPlayerAbility = new PlayerAbility("Run to next base", AbilityTypeEnum.BASIC, AbilityCategoryEnum.NORMAL, playerActionsManager.RunAction, player); PlayerAbility StaySafePlayerAbility = new PlayerAbility("Stay on base", AbilityTypeEnum.BASIC, AbilityCategoryEnum.NORMAL, playerActionsManager.StayOnBaseAction, player); playerAbilities.AddAbility(runPlayerAbility); playerAbilities.AddAbility(StaySafePlayerAbility); }
public void CalculateFielderColliderInterraction(GameObject ballGameObject, BallController ballControllerScript, GenericPlayerBehaviour genericPlayerBehaviourScript) { float passSuccessRate; if (ballControllerScript.IsPassed) { passSuccessRate = ActionCalculationUtils.CalculatePassSuccessRate(this.gameObject, ballControllerScript.CurrentHolder, ballControllerScript.BallHeight); } else { passSuccessRate = 100f; } if (ActionCalculationUtils.HasActionSucceeded(passSuccessRate)) { PlayerActionsManager.InterceptBall(ballGameObject, ballControllerScript, genericPlayerBehaviourScript); PlayerStatus fielderStatus = PlayerUtils.FetchPlayerStatusScript(this.gameObject); PlayersTurnManager playersTurnManager = GameUtils.FetchPlayersTurnManager(); playersTurnManager.TurnState = TurnStateEnum.FIELDER_TURN; playersTurnManager.CurrentFielderTypeTurn = fielderStatus.PlayerFieldPosition; PlayersTurnManager.IsCommandPhase = true; } }
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; } }
private void OnCollisionEnter2D(Collision2D collision) { PlayerStatus playerStatusScript = PlayerUtils.FetchPlayerStatusScript(this.gameObject); GenericPlayerBehaviour genericPlayerBehaviourScript = PlayerUtils.FetchCorrespondingPlayerBehaviourScript(this.gameObject, playerStatusScript); if (ColliderUtils.HasBallCollided(collision.collider)) { GameObject ballGameObject = collision.collider.gameObject; BallController ballControllerScript = BallUtils.FetchBallControllerScript(ballGameObject); if (PlayerUtils.HasCatcherPosition(this.gameObject) && ballControllerScript.CurrentPasser != this.gameObject) { CatcherBehaviour catcherBehaviour = (CatcherBehaviour)genericPlayerBehaviourScript; if (catcherBehaviour.CatcherMode == ModeConstants.CATCHER_FIELDER_MODE) { PlayerActionsManager.InterceptBall(ballGameObject, ballControllerScript, genericPlayerBehaviourScript); catcherBehaviour.CatcherMode = ModeConstants.CATCHER_NORMAL_MODE; this.gameObject.transform.position = FieldUtils.GetTileCenterPositionInGameWorld(FieldUtils.GetCatcherZonePosition()); catcherBehaviour.IsoRenderer.ReinitializeAnimator(); } PlayersTurnManager playersTurnManager = GameUtils.FetchPlayersTurnManager(); playersTurnManager.TurnState = TurnStateEnum.CATCHER_TURN; PlayersTurnManager.IsCommandPhase = true; } else if (PlayerUtils.HasFielderPosition(this.gameObject) && !ballControllerScript.IsPitched && ballControllerScript.CurrentPasser != this.gameObject) { ((FielderBehaviour)genericPlayerBehaviourScript).CalculateFielderColliderInterraction(ballGameObject, ballControllerScript, genericPlayerBehaviourScript); } else if (PlayerUtils.HasPitcherPosition(this.gameObject) && !ballControllerScript.IsPitched && !ballControllerScript.IsPassed && ballControllerScript.CurrentPasser != this.gameObject) { ((PitcherBehaviour)genericPlayerBehaviourScript).CalculatePitcherColliderInterraction(ballGameObject, ballControllerScript, genericPlayerBehaviourScript); } } else if (ColliderUtils.HasPlayerCollided(collision)) { if (PlayerUtils.HasFielderPosition(this.gameObject) && genericPlayerBehaviourScript.IsHoldingBall && PlayerUtils.HasRunnerPosition(collision.gameObject)) { PlayerStatus runnerToTagOutStatus = PlayerUtils.FetchPlayerStatusScript(collision.transform.gameObject); RunnerBehaviour runnerBehaviourScript = ((RunnerBehaviour)PlayerUtils.FetchCorrespondingPlayerBehaviourScript(collision.transform.gameObject, runnerToTagOutStatus)); if (!runnerBehaviourScript.IsSafe) { ((FielderBehaviour)genericPlayerBehaviourScript).TagOutRunner(collision.transform.gameObject); } else { ((FielderBehaviour)genericPlayerBehaviourScript).ReplanAction(); } } } else { if (PlayerUtils.HasRunnerPosition(this.gameObject)) { if (!ColliderUtils.IsBaseTile(collision.gameObject.name)) { return; } if (genericPlayerBehaviourScript == null) { return; } if (!genericPlayerBehaviourScript.IsPrepared) { return; } RunnerBehaviour runnerBehaviour = ((RunnerBehaviour)genericPlayerBehaviourScript); BaseEnum baseReached = runnerBehaviour.NextBase; if (baseReached == BaseEnum.HOME_BASE && runnerBehaviour.HasPassedThroughThreeFirstBases()) { //win a point automaticaly without issuing commands if arrived at home base after a complete turn runnerBehaviour.CalculateRunnerColliderInterraction(FieldUtils.GetTileEnumFromName(collision.gameObject.name), true); } else if (baseReached == BaseEnum.FIRST_BASE && runnerBehaviour.IsInWalkState) { //Walk done after 4 ball from pitcher runnerBehaviour.CalculateRunnerColliderInterraction(FieldUtils.GetTileEnumFromName(collision.gameObject.name)); PlayersTurnManager playersTurnManager = GameUtils.FetchPlayersTurnManager(); playersTurnManager.TurnState = TurnStateEnum.PITCHER_TURN; PlayersTurnManager.IsCommandPhase = true; } else if (baseReached == BaseEnum.HOME_BASE) { //automaticaly run to next base, no need for command input runnerBehaviour.CalculateRunnerColliderInterraction(FieldUtils.GetTileEnumFromName(collision.gameObject.name)); runnerBehaviour.GoToNextBase(baseReached, true); } else { //Runner next turn runnerBehaviour.CalculateRunnerColliderInterraction(FieldUtils.GetTileEnumFromName(collision.gameObject.name), true); } } } }
public void CalculateFielderTriggerInterraction(GenericPlayerBehaviour genericPlayerBehaviourScript) { PlayerActionsManager playerActionsManager = GameUtils.FetchPlayerActionsManager(); playerActionsManager.AimForTheBall(genericPlayerBehaviourScript); }