public void RpcHauntEnded() { foreach (GamePlayer player in NetworkGame.GetPlayers()) { if (player.isLocalPlayer) { player.DisplayHauntInfo(gameHaunt.GetComponent <Haunt>()); } } }
public void RpcPrepEnd() { Time.timeScale = 1; foreach (GamePlayer player in NetworkGame.GetPlayers()) { if (player.isLocalPlayer) { player.StopHauntPrep(); } } }
public void RpcHauntStarted(GameObject haunt) { gameHaunt = haunt; Time.timeScale = 0; foreach (GamePlayer player in NetworkGame.GetPlayers()) { if (player.isLocalPlayer) { player.DisplayHauntInfo(gameHaunt.GetComponent <Haunt>()); } } }
// Update is called once per frame void Update() { if (!isServer) { gameState = currState; } else { currState = gameState; } ///Check if the haunt has started yet. if (isServer && gameState == HauntState.EXPLORE) { elapsed += Time.deltaTime; if (elapsed >= checkInterval) { //Debug.Log ("Checking Haunts"); foreach (Haunt haunt in haunts) { if (haunt.CanStartHaunt()) { //Debug.Log ("Started Haunt"); gameHaunt = GameObject.Instantiate(haunt.gameObject); NetworkServer.Spawn(gameHaunt); gameState = HauntState.PREP; RpcHauntStarted(gameHaunt); return; } } elapsed = 0; } } else if (isServer && gameState == HauntState.PREP) { if (ready.Count == NetworkGame.GetPlayers().Length) { gameState = HauntState.HAUNT; RpcPrepEnd(); } } else if (isServer && gameState == HauntState.END) { if (prevState != HauntState.END) { RpcHauntEnded(); } } prevState = gameState; }
// Use this for initialization void Start() { if (isServer) { //Debug.Log ("Starting haunt"); GamePlayer[] players = NetworkGame.GetPlayers(); switch (type) { case HauntType.Tratior: for (int i = 0; i < players.Length; i++) { players [i].RpcSetPlayerState(GamePlayer.PlayerType.HERO); } SelectTratior(players).RpcSetPlayerState(GamePlayer.PlayerType.TRAITOR); break; case HauntType.Cooperative: for (int i = 0; i < players.Length; i++) { players [i].RpcSetPlayerState(GamePlayer.PlayerType.HERO); } break; case HauntType.HiddenTratior: for (int i = 0; i < players.Length; i++) { players [i].RpcSetPlayerState(GamePlayer.PlayerType.HERO); } SelectTratior(players).RpcSetPlayerState(GamePlayer.PlayerType.TRAITOR); break; case HauntType.FreeForAll: for (int i = 0; i < players.Length; i++) { players [i].RpcSetPlayerState(GamePlayer.PlayerType.MADMAN); } break; case HauntType.Mixed: for (int i = 0; i < players.Length; i++) { players [i].RpcSetPlayerState(GamePlayer.PlayerType.HERO); } break; } HauntStarted(); } }
/// <summary> /// Determines whether this instance can start haunt. This is determined by the haunt checking /// the house for what has happened. This method is called quite often, 10 times a second, for /// every haunt so it should not be too intensive of a process. /// </summary> /// <returns><c>true</c> if this instance can start haunt; otherwise, <c>false</c>.</returns> public override bool CanStartHaunt() { foreach (GamePlayer player in NetworkGame.GetPlayers()) { foreach (GameObject item in player.GetComponent <Inventory>().items) { if (item != null && item.GetComponent <Item>().itemName == "Ring") { theRing = item; chosenOne = player; traitorSpawns[player] = player.gameObject.transform.position; traitorDeadTimes [player] = 0; return(true); } } } return(false); }
/// <summary> /// Starts the haunt. This is used in place of Start() which is used by the abstract Haunt to /// setup the default state of the game for the given kind of haunt. /// </summary> public override void HauntStarted() { // Restore traitor health chosenOne.GetComponent <Damageable>().SetHealth(chosenOne.GetComponent <Damageable>().maxHealth); chosenOne.GetComponent <Damageable>().SetSanity(chosenOne.GetComponent <Damageable>().maxSanity); // Add speical actions to all Players foreach (GamePlayer player in NetworkGame.GetPlayers()) { if (player != chosenOne) { GameObject visionBox = Instantiate(visionActionBox); visionBox.transform.parent = player.transform.parent; visionBox.transform.localPosition = Vector3.zero; NetworkServer.Spawn(visionBox); RpcAddVisionAction(player.gameObject, visionBox); } } }
void Update() { if (isServer && HauntManager.gameState == HauntManager.HauntState.HAUNT) { //Check if traitor(s) have won bool allHeroesDead = true; foreach (GamePlayer player in NetworkGame.GetPlayers()) { if (player.playerState == GamePlayer.PlayerType.HERO && player.gameObject.GetComponent <Damageable> ().IsDead() == false) { allHeroesDead = false; } } /*if (allHeroesDead) { * //Traitor wins * HauntManager.EndHaunt(); * winner = GamePlayer.PlayerType.TRAITOR; * }*/ //Check if heroes have won if (theRing == null) { HauntManager.EndHaunt(); winner = GamePlayer.PlayerType.HERO; } //Update ring and invisibility foreach (GamePlayer player in NetworkGame.GetPlayers()) { if (player.playerState == GamePlayer.PlayerType.TRAITOR) { bool hasRing = false; foreach (GameObject item in player.GetComponent <Inventory>().items) { if (item != null) { if (item.GetComponent <Item> ().itemName == "Ring") { hasRing = true; item.GetComponent <Item> ().canDrop = false; } } } traitorHasRing = hasRing; if (hasRing) { RpcMakeInvisible(chosenOne.gameObject); } else { RpcMakeVisible(chosenOne.gameObject); } } if (player.playerState == GamePlayer.PlayerType.HERO) { foreach (GameObject item in player.GetComponent <Inventory>().items) { if (item != null && item.GetComponent <Item> ().itemName == "Ring") { item.GetComponent <Item> ().canDrop = true; } } } } //Update traitor death times foreach (GamePlayer player in NetworkGame.GetPlayers()) { if (player.playerState == GamePlayer.PlayerType.TRAITOR && player.GetComponent <Damageable>().IsDead()) { if (traitorDeadTimes [player] == 0) { //If the traitor just died player.AddTimedMessage("You are dead, but it's only temporary", respawnTime); } traitorDeadTimes [player] = traitorDeadTimes [player] + Time.deltaTime; if (traitorDeadTimes [player] >= respawnTime) { traitorDeadTimes [player] = 0; player.ServerRespawn(); player.gameObject.transform.position = traitorSpawns [player]; player.AddTimedMessage("You are back in the world of the living, for now...", 2.5f); } } } } }