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 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 override void Start() { base.Start(); IsoRenderer.LastDirection = 4; IsoRenderer.SetDirection(Vector2.zero); IsoRenderer.PreferredDirection = 4; ballControlerScript = BallUtils.FetchBallControllerScript(FieldBall); }
public void CalculatePitcherTriggerInterraction(GameObject ballGameObject, GenericPlayerBehaviour genericPlayerBehaviourScript, PlayerStatus playerStatus) { BallController ballControlerScript = BallUtils.FetchBallControllerScript(ballGameObject); ballControlerScript.IsTargetedByPitcher = true; genericPlayerBehaviourScript.HasSpottedBall = true; playerStatus.IsAllowedToMove = true; genericPlayerBehaviourScript.Target = ballGameObject.transform.position; this.transform.rotation = Quaternion.identity; }
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; }
private void OnTriggerEnter2D(Collider2D collision) { if (ColliderUtils.HasBallCollided(collision)) { GameObject ball = collision.gameObject; BallController ballControllerScript = BallUtils.FetchBallControllerScript(ball); if (ballControllerScript.IsHit) { ballControllerScript.IsInFoulState = true; } } }
private void InitiateFielderAction() { BallController ballControlerScript = BallUtils.FetchBallControllerScript(FieldBall); if (FieldBall.activeInHierarchy && !HasSpottedBall) { IsoRenderer.LookAtFieldElementAnimation(FieldBall.transform.position); this.GetAngleToLookAt(); } else if (HasSpottedBall && FieldBall.activeInHierarchy && !IsHoldingBall && ballControlerScript.IsTargetedByFielder) { Target = FieldBall.transform.position; } }
private void OnTriggerExit2D(Collider2D collision) { if (ColliderUtils.HasBallCollided(collision)) { GameObject ball = collision.gameObject; BallController ballControllerScript = BallUtils.FetchBallControllerScript(ball); if (ballControllerScript.IsHit) { Debug.Log("the ball not foul any more"); ballControllerScript.IsInFoulState = false; timeElapsed = 0; } } }
private void Update() { BallController ballControlerScript = BallUtils.FetchBallControllerScript(FieldBall); if (HasSpottedBall && FieldBall.activeInHierarchy && !IsHoldingBall && ballControlerScript.IsTargetedByFielder) { Target = FieldBall.transform.position; } if (Target.HasValue && Target.Value != this.transform.position) { MovePlayer(); this.IsPrepared = true; } }
private void OnTriggerEnter2D(Collider2D collision) { if (this.HasBallCollided(collision)) { BallController ballController = BallUtils.FetchBallControllerScript(collision.transform.gameObject); ballController.Target = null; ballController.IsMoving = false; ballController.IsPassed = false; ballController.IsPitched = false; ballController.IsHit = false; PlayersTurnManager playersTurnManager = GameUtils.FetchPlayersTurnManager(); playersTurnManager.TurnState = TurnStateEnum.BATTER_TURN; PlayersTurnManager.IsCommandPhase = true; } }
private void OnTriggerExit2D(Collider2D collision) { if (ColliderUtils.HasBallCollided(collision)) { GameObject ballGameObject = collision.gameObject; BallController ballControlerScript = BallUtils.FetchBallControllerScript(ballGameObject); if (ballControlerScript.IsMoving && ballControlerScript.IsHit && !ballControlerScript.IsPitched) { GameObject player = this.gameObject.transform.parent.parent.parent.gameObject; if (PlayerUtils.HasPitcherPosition(player)) { ballControlerScript.IsTargetedByPitcher = false; PitcherBehaviour pitcherBehaviour = PlayerUtils.FetchPitcherBehaviourScript(player); pitcherBehaviour.Target = FieldUtils.GetTileCenterPositionInGameWorld(FieldUtils.GetPitcherBaseTilePosition()); pitcherBehaviour.HasSpottedBall = false; } } } }
private void OnTriggerStay2D(Collider2D collision) { if (ColliderUtils.HasBallCollided(collision) && !GameData.isPaused) { GameObject ball = collision.gameObject; BallController ballControllerScript = BallUtils.FetchBallControllerScript(ball); if (ballControllerScript.IsHit) { timeElapsed += Time.deltaTime; if (timeElapsed >= TIME_TO_WAIT_IN_FOUL_ZONE) { Debug.Log("the ball is foul"); timeElapsed = 0; DialogBoxManager dialogBoxManagerScript = GameUtils.FetchDialogBoxManager(); dialogBoxManagerScript.DisplayDialogAndTextForGivenAmountOfTime(1f, false, "FOUL!!"); PlayersTurnManager playersTurnManager = GameUtils.FetchPlayersTurnManager(); GameObject pitcher = TeamUtils.GetPlayerTeamMember(PlayerFieldPositionEnum.PITCHER, TeamUtils.GetPlayerIdFromPlayerFieldPosition(PlayerFieldPositionEnum.PITCHER)); GameManager gameManager = GameUtils.FetchGameManager(); GameObject currentBatter = gameManager.AttackTeamBatterListClone.First(); BatterBehaviour currentBatterBehaviour = PlayerUtils.FetchBatterBehaviourScript(currentBatter); GameObject bat = currentBatterBehaviour.EquipedBat; currentBatterBehaviour.FoulOutcomeCount += 1; 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); ballControllerScript.IsInFoulState = false; 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); } } } }