public static DieScript instance() { if (instance_ == null) { instance_ = GameObject.FindObjectOfType <DieScript>(); } return(instance_); }
// Main Functions public void Init() { // components capsule = GetComponent <CapsuleCollider>(); rigidBody = GetComponent <Rigidbody>(); audioSource = GetComponent <AudioSource>(); rpg = GetComponent <RPGManager>(); rpg.Init(); // initialize bodies /*for (int i = 0; i < 2; i++) * { * bodies[i] = ObjectPool.Instance.GetObject(model + "(Clone)", transform); * }*/ // life body bodies[1] = ObjectPool.Instance.GetObject(model + "_L(Clone)", transform); //DisableRagdoll(bodies[1]); aem = bodies[1].AddComponent <AnimatorEventManager>(); aem.Init(this); animator = aem.animator; ikManager = bodies[1].AddComponent <IKManager>(); ikManager.Init(this); // dead body bodies[0] = ObjectPool.Instance.GetObject(model + "(Clone)", transform); dieScript = bodies[0].AddComponent <DieScript>(); dieScript.Init(); dieScript.states = this; deadBody = dieScript.gameObject; deadBody.SetActive(false); // item interaction and stuff PotionHandIdentifier potionHand = GetComponentInChildren <PotionHandIdentifier>(); if (potionHand != null) { this.potionHand = potionHand.transform; } pickUp.actionAnimationName = "Pick Up"; }
// Init void Start() { // setting initial state (must be Active) state = State.Active; // reference to die die = DieScript.instance(); // reference to board board = BoardScript.instance(); // reference to the game manager gm = GameManagerScript.instance(); // inital assigns // playerInfoText.text = "init"; cash = 1500; moveTime = 0.25f; timeInJail = 0; elapsedTime = int.MaxValue; }
// Update is called once per frame void Update() { if (currentState == TurnState.MOVING_CAM_TO_DIE && camera.movementCompleted()) { rollDie(); } else if (currentState == TurnState.ROLLING_DIE && DieScript.isDone() && DieScript2.isDone()) { actionPoints = DieScript.rollResult + DieScript2.rollResult; currentState = TurnState.MOVING_CAM_TO_PLAYER; camera.moveToPlayer(activePlayer); } else if (currentState == TurnState.MOVING_CAM_TO_PLAYER && camera.movementCompleted()) { startNewTurn(); } else if (currentState == TurnState.ACCEPTING_INPUT && actionPoints <= 0) { applyTileEffect(); } else if (currentState == TurnState.EXECUTING_ACTION && (currentActionFSM == null || currentActionFSM.update()) && playerBelongings[activePlayer].animationsAreDone()) { currentActionFSM = null; if (!updateTruePartyState()) { if (playerData[activePlayer].currentTile().hasTrap() && !(playerData[activePlayer].currentTile().getTrapOwner().Equals(activePlayer))) { int creditsToRemove = Math.Min(5, playerBelongings[activePlayer].creditAmount()); playerBelongings[activePlayer].addCreditAmount(-creditsToRemove); actionPoints = Math.Max(actionPoints - 3, 0); playerData[activePlayer].currentTile().setTrap(false); currentState = TurnState.EXECUTING_ACTION; currentActionFSM = new RemoveTrap(activePlayer); } else if (actionPoints <= 0) { // turn is over! applyTileEffect(); } else { // await next input/action currentState = TurnState.ACCEPTING_INPUT; } } } else if (currentState == TurnState.APPLYING_TILE_EFFECT && currentActionFSM.update()) { if (!updateTruePartyState()) { currentState = TurnState.TURN_ENDED; currentActionFSM = null; } } else if (currentState == TurnState.TURN_ENDED) { finishTurn(); } foreach (PlayerAction action in interactions.actions) { if (currentState == TurnState.ACCEPTING_INPUT && actionPoints > 0) { action.updateStatus(actionIsActive(action), canAfford(action)); } else { action.updateStatus(false, false); } } updateHUD(); }
private void rollDie() { currentState = TurnState.ROLLING_DIE; DieScript.rollDie(); DieScript2.rollDie(); }
// Update is called once per frame void Update() { if (firstFrame) { firstFrame = false; if (StatePreserver.Instance.gameStarted) { // spawn the first golden brick in the first round (no previous minigame) // this is called in the update method and not in Start() because the tiles // build their neighborhood relation during the Start() phase // however, relocate() recalculate the paths to the brick for the AIs which requires // a complete and correct tile neighborhood relation. brickManager.relocate(); } else { // restore golden brick location, this is done here for the same reason as the initial spawn foreach (GameObject t in GameObject.FindGameObjectsWithTag("Tile")) // for each tile { Tile tile = (t.GetComponent(typeof(Tile)) as Tile); if (t.transform.position.x == StatePreserver.Instance.boardState.brickTile.x && t.transform.position.z == StatePreserver.Instance.boardState.brickTile.z) { brickManager.restore(tile, t.transform); } } } } if (currentState == TurnState.MOVING_CAM_TO_DIE && camera.movementCompleted()) { rollDie(); } else if (currentState == TurnState.ROLLING_DIE && DieScript.isDone() && DieScript2.isDone()) { actionPoints = DieScript.rollResult + DieScript2.rollResult; currentState = TurnState.MOVING_CAM_TO_PLAYER; camera.moveToPlayer(activePlayer); } else if (currentState == TurnState.MOVING_CAM_TO_PLAYER && camera.movementCompleted()) { startNewTurn(); } else if (currentState == TurnState.ACCEPTING_INPUT && isAI() && actionPoints > 0) { takeActionAI(); } // else if (currentState == TurnState.ACCEPTING_INPUT && actionPoints <= 0) { // applyTileEffect(); // } else if (currentState == TurnState.EXECUTING_ACTION && (currentActionFSM == null || currentActionFSM.update()) && playerBelongings[activePlayer].animationsAreDone()) { currentActionFSM = null; if (!updateTruePartyState()) { if (playerData[activePlayer].currentTile().hasTrap() && !(playerData[activePlayer].currentTile().getTrapOwner().Equals(activePlayer))) { int creditsToRemove = Math.Min(5, playerBelongings[activePlayer].creditAmount()); playerBelongings[activePlayer].addCreditAmount(-creditsToRemove); actionPoints = Math.Max(actionPoints - 3, 0); currentState = TurnState.EXECUTING_ACTION; currentActionFSM = new RemoveTrap(playerData[activePlayer]); playerData[activePlayer].currentTile().setTrap(false, playerData[activePlayer].currentTile().getTrap()); } else if (actionPoints <= 0) { // turn is over! applyTileEffect(); } else { // await next input/action currentState = TurnState.ACCEPTING_INPUT; } } } else if (currentState == TurnState.APPLYING_TILE_EFFECT && currentActionFSM.update() && playerBelongings[activePlayer].animationsAreDone()) { if (!updateTruePartyState()) { currentState = TurnState.TURN_ENDED; currentActionFSM = null; } } else if (currentState == TurnState.TURN_ENDED) { finishTurn(); } else if (currentState == TurnState.SCOREBOARD) { for (int i = 0; i < 4; i++) { int place = PlayerPrefs.GetInt("PLAYER" + (i + 1).ToString() + "_PLACE"); // place: {1,2,3,4} -> credits {3,2,1,0} int reward = 4 - place; playerBelongings[i].addCreditAmount(reward); } currentState = TurnState.SCOREBOARD_END; } else if (currentState == TurnState.SCOREBOARD_END && playerBelongings[0].animationsAreDone() && playerBelongings[1].animationsAreDone() && playerBelongings[2].animationsAreDone() && playerBelongings[3].animationsAreDone()) { finishRound(); updateTruePartyState(); } foreach (PlayerAction action in interactions.actions) { if (currentState == TurnState.ACCEPTING_INPUT && actionPoints > 0) { if (action.type == PlayerAction.Type.SET_TRAP) { action.updateStatus(actionIsActive(action), currentTileHasNoTrap() && playerIsAloneOnTile() && canAfford(action)); } else { action.updateStatus(actionIsActive(action), canAfford(action)); } } else { action.updateStatus(false, false); } } updateHUD(); }
//Return the propety's current rent (multiply by dice roll) public int GetRent() { return(DieScript.instance().GetPrevDieRoll() * multiplier[multIndex]); }
// Use this for initialization void Start() { instance = this; tween = GetComponent <TweenPosition>(); }
// Update is called once per frame void Update() { if (currentState == TurnState.MOVING_CAM_TO_DIE && camera.movementCompleted()) { rollDie(); } else if (currentState == TurnState.ROLLING_DIE && DieScript.isDone() && DieScript2.isDone()) { actionPoints = DieScript.rollResult + DieScript2.rollResult; currentState = TurnState.MOVING_CAM_TO_PLAYER; camera.moveToPlayer(activePlayer); } else if (currentState == TurnState.MOVING_CAM_TO_PLAYER && camera.movementCompleted()) { startNewTurn(); } else if (currentState == TurnState.ACCEPTING_INPUT && isAI() && actionPoints > 0) { takeActionAI(); } else if (currentState == TurnState.ACCEPTING_INPUT && actionPoints <= 0) { applyTileEffect(); } else if (currentState == TurnState.EXECUTING_ACTION && (currentActionFSM == null || currentActionFSM.update()) && playerBelongings[activePlayer].animationsAreDone()) { currentActionFSM = null; if (!updateTruePartyState()) { if (playerData[activePlayer].currentTile().hasTrap() && !(playerData[activePlayer].currentTile().getTrapOwner().Equals(activePlayer))) { int creditsToRemove = Math.Min(5, playerBelongings[activePlayer].creditAmount()); playerBelongings[activePlayer].addCreditAmount(-creditsToRemove); actionPoints = Math.Max(actionPoints - 3, 0); currentState = TurnState.EXECUTING_ACTION; currentActionFSM = new RemoveTrap(playerData[activePlayer]); playerData[activePlayer].currentTile().setTrap(false, playerData[activePlayer].currentTile().getTrap()); } else if (actionPoints <= 0) { // turn is over! applyTileEffect(); } else { // await next input/action currentState = TurnState.ACCEPTING_INPUT; } } } else if (currentState == TurnState.APPLYING_TILE_EFFECT && currentActionFSM.update()) { if (!updateTruePartyState()) { currentState = TurnState.TURN_ENDED; currentActionFSM = null; } } else if (currentState == TurnState.TURN_ENDED) { finishTurn(); } else if (currentState == TurnState.SCOREBOARD) { for (int i = 0; i < 4; i++) { int place = PlayerPrefs.GetInt("PLAYER" + i.ToString() + "_PLACE"); playerBelongings[i].addCreditAmount(4 - place + 1); } currentState = TurnState.SCOREBOARD_END; } else if (currentState == TurnState.SCOREBOARD_END && playerBelongings[0].animationsAreDone() && playerBelongings[1].animationsAreDone() && playerBelongings[2].animationsAreDone() && playerBelongings[3].animationsAreDone()) { finishRound(); updateTruePartyState(); } foreach (PlayerAction action in interactions.actions) { if (currentState == TurnState.ACCEPTING_INPUT && actionPoints > 0) { if (action.type == PlayerAction.Type.SET_TRAP) { action.updateStatus(actionIsActive(action), currentTileHasNoTrap() && playerIsAloneOnTile() && canAfford(action)); } else { action.updateStatus(actionIsActive(action), canAfford(action)); } } else { action.updateStatus(false, false); } } updateHUD(); }