public static List <Vector2Int> CalculateBallFallPositionList(GameObject playerInvolved, int angleMinRange, int angleMaxRange, int angleStep, bool Iscritical, Vector2Int ballOrigin) { List <Vector2Int> ballPositionList = new List <Vector2Int>(); int x; int y; int criticalFactor = 1; PlayerStatus playerInvolvedStatus = PlayerUtils.FetchPlayerStatusScript(playerInvolved); int property = playerInvolvedStatus.BattingPower; /* * parametric circle equation : * x = R * cos(theta) + a * y = R * sin(theta) + b*/ /* * pi => 180 * ? => x */ if (Iscritical) { criticalFactor = CalculateCriticalFactor(); } for (int angle = angleMinRange; angle < angleMaxRange + angleStep; angle += angleStep) { float theta = ConvertDegreeAngleToRadianAngle(GetFixedIsometricAngle(angle)); x = (int)(property * criticalFactor * Mathf.Cos(theta) + ballOrigin.x); y = (int)(property * criticalFactor * Mathf.Sin(theta) + ballOrigin.y); ballPositionList.Add(new Vector2Int(x, y)); } return(ballPositionList); }
public static float CalculateBallOutcomeProbability(GameObject pitcherGameObject) { PlayerStatus pitcherStatus = PlayerUtils.FetchPlayerStatusScript(pitcherGameObject); float result = 100f - pitcherStatus.PitchEfficiency; return(result); }
private void OnTriggerStay2D(Collider2D collision) { if (ColliderUtils.HasBallCollided(collision)) { GameObject player = this.gameObject.transform.parent.parent.parent.gameObject; GameObject ballGameObject = collision.gameObject; BallController ballControlerScript = BallUtils.FetchBallControllerScript(ballGameObject); PlayerStatus currentPlayerStatus = PlayerUtils.FetchPlayerStatusScript(player); GenericPlayerBehaviour genericPlayerBehaviourScript = PlayerUtils.FetchCorrespondingPlayerBehaviourScript(player, currentPlayerStatus); if (ballControlerScript.IsMoving && ballControlerScript.IsHit && !ballControlerScript.IsPitched) { if (PlayerUtils.HasPitcherPosition(player) && !ballControlerScript.IsTargetedByFielder && !ballControlerScript.IsInFoulState) { ballControlerScript.IsTargetedByPitcher = true; ((PitcherBehaviour)genericPlayerBehaviourScript).CalculatePitcherTriggerInterraction(ballGameObject, genericPlayerBehaviourScript, currentPlayerStatus); } if (PlayerUtils.HasFielderPosition(player) && !ballControlerScript.IsTargetedByFielder && !ballControlerScript.IsTargetedByPitcher && !ballControlerScript.IsInFoulState) { GameObject nearestFielder = TeamUtils.GetNearestFielderFromGameObject(ballGameObject); PlayerStatus nearestFielderStatus = PlayerUtils.FetchPlayerStatusScript(nearestFielder); if (nearestFielderStatus.PlayerFieldPosition == currentPlayerStatus.PlayerFieldPosition) { ((FielderBehaviour)genericPlayerBehaviourScript).CalculateFielderTriggerInterraction(genericPlayerBehaviourScript); } } } } }
public static float CalculatePitchSuccessRate(GameObject pitcherGameObject, GameObject opponentGameObject) { PlayerStatus pitcherStatus = PlayerUtils.FetchPlayerStatusScript(pitcherGameObject); PlayerStatus opponentStatus = PlayerUtils.FetchPlayerStatusScript(opponentGameObject); float opponentDefensiveCharacteristic = 0f; float powerEfectiveness = 0f; switch (opponentStatus.PlayerFieldPosition) { case PlayerFieldPositionEnum.BATTER: opponentDefensiveCharacteristic = opponentStatus.BattingEfficiency; powerEfectiveness = 5f; break; case PlayerFieldPositionEnum.CATCHER: opponentDefensiveCharacteristic = opponentStatus.CatchEfficiency; powerEfectiveness = 2f; break; } float result = pitcherStatus.PitchEfficiency + (pitcherStatus.PitchingPower * powerEfectiveness) - opponentDefensiveCharacteristic; return(AdjustResult(result)); }
public void Update() { BallController ballControlerScript = BallUtils.FetchBallControllerScript(FieldBall); if (TargetPlayerToTagOut != null && PlayerUtils.HasFielderPosition(this.gameObject)) { Target = TargetPlayerToTagOut.transform.position; } else if (HasSpottedBall && FieldBall.activeInHierarchy && !IsHoldingBall && ballControlerScript.IsTargetedByFielder) { Target = FieldBall.transform.position; } if (Target.HasValue && Target.Value != this.transform.position) { MovePlayer(); this.IsPrepared = true; } else { PlayerStatus playerStatus = PlayerUtils.FetchPlayerStatusScript(this.gameObject); if (playerStatus.IsAllowedToMove) { this.InitiateFielderAction(); } } }
public static float CalculatePassSuccessRate(GameObject ballReceiverGameObject, GameObject ballPasserGameObject, BallHeightEnum ballHeight) { PlayerStatus receiverStatus = PlayerUtils.FetchPlayerStatusScript(ballReceiverGameObject); PlayerStatus passerStatus = PlayerUtils.FetchPlayerStatusScript(ballPasserGameObject); float passerCharacteristic = passerStatus.PassEfficiency; float result; switch (ballHeight) { case BallHeightEnum.GROUNDED: result = 100f; break; case BallHeightEnum.LOW: result = receiverStatus.CatchEfficiency + passerCharacteristic; break; case BallHeightEnum.HIGH: result = 0f; break; default: result = 100f; break; } return(AdjustResult(result)); }
public void TagOutAimAction(GameObject actionUser, GameObject actionTarget) { PlayerStatus actionUserStatusScript = PlayerUtils.FetchPlayerStatusScript(actionUser); GenericPlayerBehaviour genericPlayerBehaviourScript = PlayerUtils.FetchCorrespondingPlayerBehaviourScript(actionUser, actionUserStatusScript); genericPlayerBehaviourScript.TargetPlayerToTagOut = actionTarget; PlayersTurnManager.IsCommandPhase = false; }
public void CatchBallAction(GameObject actionUser) { //CATCHER TURN GameObject catcher = TeamUtils.GetPlayerTeamMember(PlayerFieldPositionEnum.CATCHER, TeamUtils.GetPlayerIdFromPlayerFieldPosition(PlayerFieldPositionEnum.CATCHER)); PlayerStatus catcherStatusScript = PlayerUtils.FetchPlayerStatusScript(catcher); CatcherBehaviour genericCatcherBehaviourScript = ((CatcherBehaviour)PlayerUtils.FetchCorrespondingPlayerBehaviourScript(catcher, catcherStatusScript)); genericCatcherBehaviourScript.CalculateCatcherColliderInterraction(PitcherGameObject, ballGameObject, ballControllerScript); }
private void OnCollisionExit2D(Collision2D collision) { if (PlayerUtils.HasRunnerPosition(this.gameObject) && ColliderUtils.IsBaseTile(collision.gameObject.name)) { PlayerStatus playerStatusScript = PlayerUtils.FetchPlayerStatusScript(this.gameObject); RunnerBehaviour runnerBehaviourScript = ((RunnerBehaviour)PlayerUtils.FetchCorrespondingPlayerBehaviourScript(this.gameObject, playerStatusScript)); runnerBehaviourScript.ToggleRunnerSafeStatus(); } }
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; } } }
public override void Start() { base.Start(); IsoRenderer.PreferredDirection = 4; PlayerStatus playerStatus = PlayerUtils.FetchPlayerStatusScript(this.gameObject); if (playerStatus.IsAllowedToMove) { this.InitiateRunnerAction(playerStatus); } }
public void AimForTheBall(GenericPlayerBehaviour playerBehaviour) { GameObject player = playerBehaviour.gameObject; PlayerStatus playerStatus = PlayerUtils.FetchPlayerStatusScript(player); BallController ballControlerScript = BallUtils.FetchBallControllerScript(BallGameObject); ballControlerScript.IsTargetedByFielder = true; playerBehaviour.HasSpottedBall = true; playerStatus.IsAllowedToMove = true; playerBehaviour.Target = ballGameObject.transform.position; player.transform.rotation = Quaternion.identity; }
public void HitBallAction(GameObject actionUser) { //BATTER TURN GameObject batter = TeamUtils.GetPlayerTeamMember(PlayerFieldPositionEnum.BATTER, TeamUtils.GetPlayerIdFromPlayerFieldPosition(PlayerFieldPositionEnum.BATTER)); BatterBehaviour batterBehaviourScript = PlayerUtils.FetchBatterBehaviourScript(batter); batterBehaviourScript.IsReadyToSwing = true; batterBehaviourScript.IsSwingHasFinished = false; if (PlayerUtils.HasBatterPosition(batter)) { PlayerStatus playerStatusScript = PlayerUtils.FetchPlayerStatusScript(batter); batterBehaviourScript.CalculateBatterColliderInterraction(PitcherGameObject, BallControllerScript, playerStatusScript); } }
public void PassBallAction(GameObject actionUser, GameObject actionTarget) { PlayersTurnManager playersTurnManager = GameUtils.FetchPlayersTurnManager(); playersTurnManager.TurnState = TurnStateEnum.STANDBY; PlayerStatus actionUserStatus = PlayerUtils.FetchPlayerStatusScript(actionUser); GenericPlayerBehaviour actionUserGenericBehaviour = PlayerUtils.FetchCorrespondingPlayerBehaviourScript(actionUser, actionUserStatus); BallControllerScript.gameObject.transform.SetParent(null); ballGameObject.SetActive(true); BallControllerScript.BallHeight = BallHeightEnum.LOW; BallControllerScript.IsPassed = true; BallControllerScript.IsHit = false; BallControllerScript.Target = actionTarget.transform.position; BallControllerScript.IsHeld = false; BallControllerScript.CurrentPasser = actionUser; actionUserGenericBehaviour.IsHoldingBall = false; }
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; } }
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 CalculateCatcherColliderInterraction(GameObject pitcherGameObject, GameObject ballGameObject, BallController ballControllerScript) { GameManager gameManager = GameUtils.FetchGameManager(); GameObject currentBatter = gameManager.AttackTeamBatterListClone.First(); BatterBehaviour currentBatterBehaviour = PlayerUtils.FetchBatterBehaviourScript(currentBatter); GameObject bat = currentBatterBehaviour.EquipedBat; PlayerStatus currentBatterStatus = PlayerUtils.FetchPlayerStatusScript(currentBatter); PlayersTurnManager playersTurnManager = GameUtils.FetchPlayersTurnManager(); GameObject pitcher = TeamUtils.GetPlayerTeamMember(PlayerFieldPositionEnum.PITCHER, TeamUtils.GetPlayerIdFromPlayerFieldPosition(PlayerFieldPositionEnum.PITCHER)); float catchSuccesRate = ActionCalculationUtils.CalculateCatchSuccessRate(this.gameObject, pitcherGameObject); if (!ActionCalculationUtils.HasActionSucceeded(catchSuccesRate)) { ballControllerScript.Target = null; ballControllerScript.IsPitched = false; ballControllerScript.Target = FieldUtils.GetTileCenterPositionInGameWorld(FieldUtils.GetCathcherOutBallZonePosition()); if (currentBatterBehaviour.StrikeOutcomeCount == 3) { RunnerBehaviour runnerBehaviour = currentBatterBehaviour.ConvertBatterToRunner(currentBatterStatus); currentBatterBehaviour.AddRunnerAbilitiesToBatter(currentBatter); //Not realy hit but rather not catch properly!!!!! ballControllerScript.IsHit = true; currentBatterStatus.IsAllowedToMove = true; runnerBehaviour.EnableMovement = true; this.SetUpNewBatter(gameManager); bat.GetComponent <CapsuleCollider2D>().enabled = false; StartCoroutine(this.WaitForPeriod(4f)); } else { gameManager.ReinitPitcher(pitcher); gameManager.ReturnBallToPitcher(ballControllerScript.gameObject); gameManager.ReinitRunners(gameManager.AttackTeamRunnerList); currentBatter.transform.rotation = Quaternion.identity; bat.transform.position = FieldUtils.GetBatCorrectPosition(currentBatter.transform.position); bat.transform.rotation = Quaternion.Euler(0f, 0f, -70f); playersTurnManager.TurnState = TurnStateEnum.PITCHER_TURN; PlayersTurnManager.IsCommandPhase = true; } } else { bool isInWalkState = false; ballGameObject.SetActive(false); ballControllerScript.CurrentHolder = this.gameObject; if (currentBatterBehaviour.StrikeOutcomeCount == 3) { currentBatter.SetActive(false); gameManager.AttackTeamBatterListClone.Remove(currentBatter); this.SetUpNewBatter(gameManager); currentBatterBehaviour.StrikeOutcomeCount = 0; currentBatterBehaviour.BallOutcomeCount = 0; gameManager.BatterOutCount++; } else if (currentBatterBehaviour.BallOutcomeCount == 4) { isInWalkState = true; RunnerBehaviour newRunnerBehaviour = currentBatterBehaviour.ConvertBatterToRunner(currentBatterStatus); currentBatterBehaviour.AddRunnerAbilitiesToBatter(currentBatter); newRunnerBehaviour.IsInWalkState = isInWalkState; currentBatterStatus.IsAllowedToMove = true; newRunnerBehaviour.EnableMovement = true; currentBatterBehaviour.StrikeOutcomeCount = 0; currentBatterBehaviour.BallOutcomeCount = 0; this.SetUpNewBatter(gameManager); } else { currentBatter.transform.rotation = Quaternion.identity; bat.transform.position = FieldUtils.GetBatCorrectPosition(currentBatter.transform.position); bat.transform.rotation = Quaternion.Euler(0f, 0f, -70f); } gameManager.ReinitPitcher(pitcher); gameManager.ReturnBallToPitcher(ballControllerScript.gameObject); gameManager.ReinitRunners(gameManager.AttackTeamRunnerList); bool isInningHalfEnd = gameManager.BatterOutCount == 3; if (isInningHalfEnd) { //Team switch attack/defense gameManager.BatterOutCount = 0; gameManager.ProcessNextInningHalf(); } if (!isInWalkState && !isInningHalfEnd) { playersTurnManager.TurnState = TurnStateEnum.PITCHER_TURN; PlayersTurnManager.IsCommandPhase = true; } } }
public static PlayerEnum GetBaseballPlayerOwner(GameObject baseballPlayer) { PlayerStatus playerStatus = PlayerUtils.FetchPlayerStatusScript(baseballPlayer); return(playerStatus.PlayerOwner); }
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; } }