//This method is used to distribute roles after comissioner, don or doctor is kicked private void checkAfterKick(Character kickedPlayer) { Character.Characters kickedChar = kickedPlayer.getCharacter(); //Checking if comissionar is kicked, then inherited citizen becomes comissioner if (kickedChar == Character.Characters.Comissioner) { //if there is inherited citizen if (GameLoopController.Current.players.OfType <Citizen>().Where(i => ((i).IsInheritedComissioner())).Count() > 0) { GameLoopController.Current.players.OfType <Citizen>().Where(i => ((i).IsInheritedComissioner())).First().SetCharacter(Character.Characters.Comissioner); Debug.Log("Since comissioner is kicked, " + GameLoopController.Current.players.Where(i => (i.getCharacter() == Character.Characters.Comissioner)).First().Id + " is new Com (inherited)"); } // if there is no inherited citizen, then it is choosen randomly else { GameLoopController.Current.players.OfType <Citizen>()?.OrderBy(x => Guid.NewGuid())?.FirstOrDefault()?.SetCharacter(Character.Characters.Comissioner); Debug.Log("Since comissioner is kicked, " + GameLoopController.Current.players.Where(i => (i.getCharacter() == Character.Characters.Comissioner))?.First()?.Id + " is new Com"); } } else if (kickedChar == Character.Characters.Mafia && (kickedPlayer as Mafia).IsDon()) { GameLoopController.Current.players.OfType <Mafia>()?.OrderBy(x => Guid.NewGuid())?.FirstOrDefault()?.MakeDon(); Debug.Log("Since don mafia is kicked, " + GameLoopController.Current.players.OfType <Mafia>().Where(i => ((i).IsDon()))?.First()?.Id + " is new Don"); } //If doc is kicked, then protected ones by him should be unprotected else if (kickedChar == Character.Characters.Doctor) { GameLoopController.Current.players.Find(i => ((i).isProtectedByDoc))?.protectedByDoc(false); } }
//This method is used to update the number of players and thus, win/lose cases public void UpdateStatistics(Character kickedPlayer) { Character.Characters kickedChar = kickedPlayer.getCharacter(); Debug.Log("Now there is/are " + getNumberOfChar(kickedChar) + " " + kickedChar.ToString()); //Win/Lose cases go below. PS: The snippet should be refactored! if (kickedChar == Character.Characters.Mafia && getNumberOfChar(kickedChar) == 0) { if (getNumberOfChar(Character.Characters.Maniac) == 0) { Debug.Log("Citizen wins the game!"); gameOver.Invoke(0); //0 means citizen wins } else { Debug.Log("Maniac wins the game!"); gameOver.Invoke(2); //2 means maniac wins } isGameOver = true; } else if ((kickedChar == Character.Characters.Citizen || kickedChar == Character.Characters.Comissioner) && GameLoopController.Current.players.OfType <Citizen>().ToList().Count <= 1) { if (getNumberOfChar(Character.Characters.Maniac) == 0) { Debug.Log("Mafia wins the game!"); gameOver.Invoke(1); //1 means mafia wins } else { Debug.Log("Maniac wins the game!"); gameOver.Invoke(2); //2 means maniac wins } isGameOver = true; } }
public int getNumberOfChar(Character.Characters character) { return(GameLoopController.Current.players.FindAll(i => i.getCharacter() == character).Count); }