///This function is called when the command terminal breaks. public void onBreak() { Toast.addToast("Navigation Corrupted. Please reset", 3); //when the navigation is corrupted add it to the top of the screen isBroken = true; this.setActive(true); GameConditions.setTraveling(false);//sets traveling to false in the game conditions script. }
/************************************************************ * * Below is code to test and generate default objects for testing * *************************************************************/ public static GameContext GetDefault() { List <Player> playerList = new List <Player>(); Player p1 = new Player("myId", "Default", 1); Player p2 = new Player("noId", "Bot", 2); playerList.Add(p1); playerList.Add(p2); Player current = playerList[0]; Dictionary <Vector3Int, Territory> defaultMap = new Dictionary <Vector3Int, Territory>(); for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { Vector3Int pos = new Vector3Int(i, j, 0); // Territory territory = new Territory((i % 2 == 0 && j % 2 == 0) ? Territory.Type.FOREST : Territory.Type.PLAIN); Territory territory = new Territory(GetRandomDefault(i, j)); defaultMap.Add(pos, territory); } } Dictionary <Vector3Int, IUnit> units = new Dictionary <Vector3Int, IUnit>(); GameConditions gm = new GameConditions(); return(new GameContext(playerList, null, defaultMap, units, gm)); }
///This function executes when the command terminal is fixed. public void onFix() { GameConditions.setTraveling(true); this.setActive(false); isBroken = false; hide(); }
public void RefreshRoomProperties(GameplayEvent state) { var chaPos = new Dictionary <string, CharacterPos>(); var allSaved = new Dictionary <string, FG_SavedCharacter>(); foreach (var go in unitControlller.allCharacterUnit) { chaPos.Add(go.name, new CharacterPos() { TileX = go.tileX, TileY = go.tileY }); allSaved.Add(go.name, go.savedCharacter); } GameConditions cc = new GameConditions() { State = state, CurrentChaName = unitControlller.allCharacterUnit[unitControlller.currentId].name, TargetChaName = unitControlller.allCharacterUnit[unitControlller.currentId].attackTarget == null ? "" : unitControlller.allCharacterUnit[unitControlller.currentId].attackTarget.name, MoveToTileX = unitControlller.allCharacterUnit[unitControlller.currentId].currentPath == null ? unitControlller.allCharacterUnit[unitControlller.currentId].tileX : unitControlller.allCharacterUnit[unitControlller.currentId].currentPath[1].x, MoveToTileY = unitControlller.allCharacterUnit[unitControlller.currentId].currentPath == null ? unitControlller.allCharacterUnit[unitControlller.currentId].tileY : unitControlller.allCharacterUnit[unitControlller.currentId].currentPath[1].y, RemainingMovement = unitControlller.allCharacterUnit[unitControlller.currentId].remainingMovement, SelectedSpell = unitControlller.allCharacterUnit[unitControlller.currentId].selectedSpell == null ? "" : unitControlller.allCharacterUnit[unitControlller.currentId].selectedSpell.SpellName, AllSavedChaharacterData = allSaved, AllCharacterPos = chaPos, }; if (GamePlayManager.IsMultiPlayer) { Hashtable hs = new Hashtable(); hs.Add("Conditions", PlayFab.Json.PlayFabSimpleJson.SerializeObject(cc)); PhotonNetwork.room.SetCustomProperties(hs, null, false); } else { this.conditions = cc; if (state == GameplayEvent.PreMoveState) { RaiseGameplayEvent("", GameplayEvent.MoveState); } else if (state == GameplayEvent.PreAttackState) { RaiseGameplayEvent("", GameplayEvent.AttackState); } else if (state == GameplayEvent.TurnEnd) { System.Action action = () => { RaiseGameplayEvent("", GameplayEvent.PreMoveState); }; StartCoroutine(Wait(action, 1)); } else { if (myEvent != conditions.State) { RaiseGameplayEvent("", state); } } } }
///Adjust the accuracy of the turrets with each update. protected override void doUpdate() { ///If its broken fix it and call onbreak. if (doBreak) { doBreak = false; onBreak(); } accuracy = Mathf.MoveTowards(accuracy, missAcc, decreaseRate * Time.deltaTime); ///set the accuracy value based of delta time, so its unaffected by framerates. GameConditions.setAccuracy(accuracy); ///Sets the accuracy in the gameconditions object. }
/// on awake,sets itself as the static gamecondition, or deletes itself if another one is found /// the static allows it to be directly referenced by other scripts void Awake() { if (gamecond == null) { gamecond = this; } else { Destroy(gameObject); } }
public GameContext(List <Player> players, Player current, Dictionary <Vector3Int, Territory> map, Dictionary <Vector3Int, IUnit> units, GameConditions conds) { this.players = players; this.currentPlayer = current == null ? players[0] : current; this.map = map; this.units = units; this.gameConds = conds; }
///doUpdate updates the user interface in real time according to frames per second. protected override void doUpdate() { ///Searches through all gameobjects in the heiarchy of the cryoterminal scene that are named "HEALTH" ///and grabs the text component. foreach (GameObject c in crew) { crew_health = c.transform.Find("HEALTH").gameObject; crew_health_text = crew_health.GetComponent <Text>(); ///if there is now power to the cryo room and all the crew are not dead if (powervalue == false && allcrewdead == false) { ///if crew members health is greater than zero if (CrewHealthNum > 0.0f) { ///decrease the crew members health by 0.0001f and update the crew health text to display the current value CrewHealthNum = CrewHealthNum - 0.0001f; crew_health_text.text = Mathf.Floor(CrewHealthNum) + "%"; } else { ///Text is displayed via pop up to the player HUD Toast.addToast("Crew member died", 3); ///changes the health text of the associated crew member to deceased. crew_health_text.text = "DECEASED"; ///crew member has died. crewdead = true; ///crew member has died, add to crew count variable. crewcount++; } } ///if crew count has reached 41 if (crewcount == 41) { ///call the function allDead from the gameconditions script. which will cause a gameover state to occur. GameConditions.allDead(); } ///if cryo room has power but all the crew are not dead. if (powervalue == true && allcrewdead == false) { ///if crew members health less than 100 if (CrewHealthNum < 100) { ///incrememnt crew health value by 0.00005f and update the crew health text to display the current value CrewHealthNum = CrewHealthNum + 0.00005f; crew_health_text.text = Mathf.Floor(CrewHealthNum) + "%"; } } } }
/// This function is to adjust the accuracy in the terminal and set the accuracy in the GameConditions for use in other scripts. public void changeAccuracy(float change) { accuracy += change; ///adds the change value to the current accuracy. GameConditions.setAccuracy(accuracy); ///Sets the accuracy in the game conditions object. }
public void updatePower(bool powered) { ///set the speeded if powered. GameConditions.setSpeed(powered); }
public override void OnPhotonCustomRoomPropertiesChanged(ExitGames.Client.Photon.Hashtable propertiesThatChanged) { datas = propertiesThatChanged; if (datas["Conditions"] != null) { conditions = new GameConditions(); conditions = (GameConditions)PlayFab.Json.PlayFabSimpleJson.DeserializeObject <GameConditions>((string)datas["Conditions"]); } if (myEvent != conditions.State) { myEvent = conditions.State; RaiseGameplayEvent(conditions.CurrentChaName, myEvent); } switch (myEvent) { case GameplayEvent.IntroQuest: Debug.Log("Game Staet State form room properties"); break; case GameplayEvent.PreMoveState: if (PhotonNetwork.isMasterClient && !unitControlller.currentUnit.tag.Contains("Player")) { System.Action action = () => { RefreshRoomProperties(GameplayEvent.MoveState); }; StartCoroutine(Wait(action, 0.25f)); } break; case GameplayEvent.MoveState: break; case GameplayEvent.PreAttackState: if (PhotonNetwork.isMasterClient && !unitControlller.currentUnit.tag.Contains("Player")) { System.Action action = () => { RefreshRoomProperties(GameplayEvent.AttackState); }; StartCoroutine(Wait(action, 0.25f)); } if (PhotonNetwork.isMasterClient) { if (unitControlller.currentUnit.tag.Contains("Player") && unitControlller.allCharacterUnit[unitControlller.currentId].attackTarget != null) { System.Action action = () => { RefreshRoomProperties(GameplayEvent.AttackState); }; StartCoroutine(Wait(action, 0.25f)); } } break; case GameplayEvent.AttackState: break; case GameplayEvent.TurnEnd: if (PhotonNetwork.isMasterClient) { System.Action action = () => { RefreshRoomProperties(GameplayEvent.PreMoveState); }; StartCoroutine(Wait(action, 1)); } break; case GameplayEvent.OutroAct: //PhotonNetwork.Disconnect(); Debug.Log("Game Over and disconnected photon"); break; //case States.GameWin: // Debug.LogError("game win !!!"); // PhotonNetwork.Disconnect(); // SceneController.Instance.RequestSceneChange(SceneController.GameScenes.Profile); // break; } }