/// <summary> /// Add the player to the Active Players list for the Mission. /// </summary> /// <param name="client"></param> /// <returns></returns> public bool AddActivePlayer(Client client) { if (client.HasData(EntityData.ActiveMission)) { client.SendChatMessage("You must leave your current mission to join a new one. /leavemission"); return(false); } if (ActivePlayers.Contains(client)) { return(false); } ActivePlayers.Add(client); client.SetData(EntityData.ActiveMission, this); string activePlayers = JsonConvert.SerializeObject(GetActivePlayers()); string activeObjectives = JsonConvert.SerializeObject(GetObjectives()); for (int i = 0; i < ActivePlayers.Count; i++) { NAPI.ClientEvent.TriggerClientEvent(NAPI.Player.GetPlayerFromHandle(ActivePlayers[i]), "MissionInfo", "Mission_Active_Players", activePlayers); NAPI.ClientEvent.TriggerClientEvent(NAPI.Player.GetPlayerFromHandle(ActivePlayers[i]), "MissionInfo", "Mission_Active_Objectives", activeObjectives); } return(true); }
public Game( Dictionary <string, string> userProfileMap, Dictionary <string, List <string> > roleToUsers, List <string> activePlayers, string mafiaTarget, string doctorTarget, string voteTarget, GameState currentState ) { CurrentState = currentState; List <string> mafiaIdList; // all mafias List <string> doctorIdList; roleToUsers.TryGetValue(Role.Mafia.ToString(), out mafiaIdList); roleToUsers.TryGetValue(Role.Doctor.ToString(), out doctorIdList); foreach (KeyValuePair <string, string> idWithName in userProfileMap) { Player newPlayer = new Player(idWithName.Key, idWithName.Value); AddPlayer(newPlayer); newPlayer.Vote = voteTarget; newPlayer.Active = true; if (activePlayers.Contains(newPlayer.Id)) { // TODO: Sheriff if (mafiaIdList != null && mafiaIdList.Contains(newPlayer.Id)) { var mafia = new Mafia(newPlayer); mafia.Target = mafiaTarget; Mafias.Add(mafia); PlayerMapping[newPlayer.Id] = mafia; ActivePlayers.Add(mafia); } else if (doctorIdList != null && doctorIdList.Contains(newPlayer.Id)) { var doctor = new Doctor(newPlayer); doctor.Target = doctorTarget; Doctors.Add(doctor); PlayerMapping[newPlayer.Id] = doctor; ActivePlayers.Add(doctor); } else { var village = new Villager(newPlayer); PlayerMapping[newPlayer.Id] = village; ActivePlayers.Add(village); } } else { newPlayer.Active = false; PlayerMapping[newPlayer.Id] = newPlayer; } } }
public void InitPlayers() { ActivePlayers.Clear(); BettingPlayers = 0; for (int i = 0; i < Config.MaxPlayers; i++) { if (i < Config.Players) { ActivePlayers.Add(players[i]); //turn on active players game objects players[i].gameObject.SetActive(true); } else { //turn off inactive players gameobjects players[i].gameObject.SetActive(false); //players[i].Role = Role.Defeated; } } for (int i = 0; i < ActivePlayers.Count; i++) { //if player has been initialized, reset player. if (!ActivePlayers[i].Initialized) { ActivePlayers[i].Init(i, turnSequencer, this, Config.placingBetDelay, Config.takeDelay, options.CardBackground); } ActivePlayers[i].ResetPlayer(); if (!Config.specialCards) { ActivePlayers[i].Cards = deck.GetCardsFromLiveDeckTasselated(i); //give activePlayers random cards } else { ActivePlayers[i].Cards = deck.GetSpecialCards(i); } ActivePlayers[i].StartReceivingCards(); } //Recalculate turning order after live players list has been created. turnSequencer.RecalculateTurningOrder(ActivePlayers); PlayDealingSound(); //test //activePlayers[0].MakeAllCardsHighestRank(); //activePlayers[1].MakeAllCardsHighestRank(); //activePlayers[2].MakeAllCardsHighestRank(); }
public void Add(Player player) { if (!metadata.NumActivePlayers.HasValue) { ActivePlayers.Add(player); } else { if (ActivePlayers.Count == metadata.NumActivePlayers.Value) { BenchPlayers.Add(player); } else { ActivePlayers.Add(player); } } }
/* Player Management */ public AbstractPlayer SpawnPlayer(EPlayerID playerID) { AbstractPlayer spawnedPlayer = null; if (IS_TRUE(HasPlayerJoined(playerID)) && IS_KEY_NOT_CONTAINED(ActivePlayers, playerID) && IS_KEY_CONTAINED(playersPrefabsMap, playerID)) { AbstractPlayer playerPrefab = playersPrefabsMap[playerID]; Vector3 playerPosition = Vector3.zero; Quaternion playerRotation = Quaternion.identity; AbstractPlayerSpawnPosition playerSpawnPosition = null; if (PlayersSpawnPositions.ContainsKey(playerID)) { playerSpawnPosition = PlayersSpawnPositions[playerID]; playerPosition = playerSpawnPosition.Position; playerRotation = playerSpawnPosition.Rotation; } else { LogConsoleWarning("No spawn position defined for : " + playerID + ". Spawning at root"); } spawnedPlayer = Instantiate(playerPrefab, playerPosition, playerRotation); spawnedPlayer.PlayerID = playerID; spawnedPlayer.TeamID = PlayersTeam[playerID]; ActivePlayers.Add(playerID, spawnedPlayer); // Place player under parent of SpawnPosition if (playerSpawnPosition && MotherOfManagers.Instance.SpawnPlayersUnderSameTransformAsSpawnPositions == true && playerSpawnPosition.transform.parent != null) { spawnedPlayer.transform.parent = playerSpawnPosition.transform.parent; } BEventsCollection.PLAYERS_PlayerSpawned.Invoke(new BEHandle <EPlayerID, IPlayer>(playerID, spawnedPlayer)); } return(spawnedPlayer); }
void SetupTeams() { Host.AssertServer(); ActivePlayers.Clear(); // Setup the Teams. int playerIdx = 0; var game = Game.Current as PlatformWars.Game; var players = game.GetPlayers(); foreach (var p in players) { var ply = p as Player; ply.SetTeam(Team.Red + playerIdx); playerIdx++; ActivePlayers.Add(ply); } }
public void InitializeGameBoard() { FillRolesToAssign(); Random random = new Random(); List <Player> inactivePlayers = PlayerMapping.Select(p => p.Value).ToList(); // TODO: Add some validation to make sure aggregate roles and role counts do not exceed number of players foreach (Role role in RolesToAssign.Keys) { if (inactivePlayers.Count == 0) { break; } for (int i = 0; i < RolesToAssign[role]; i++) { //remove later if (role == Role.Mafia && i == 0) { foreach (Player p in inactivePlayers) { if (p.Name == "Kunyi Liu") { p.Role = role; p.Active = true; inactivePlayers.Remove(p); Mafia mafia = new Mafia(p); Mafias.Add(mafia); PlayerMapping[p.Id] = mafia; ActivePlayers.Add(mafia); break; } } continue; } Player playerToModify = inactivePlayers[random.Next(inactivePlayers.Count)]; playerToModify.Role = role; playerToModify.Active = true; inactivePlayers.Remove(playerToModify); if (role == Role.Mafia) { Mafia mafia = new Mafia(playerToModify); Mafias.Add(mafia); PlayerMapping[playerToModify.Id] = mafia; ActivePlayers.Add(mafia); } else if (role == Role.Doctor) { Doctor doctor = new Doctor(playerToModify); Doctors.Add(doctor); PlayerMapping[playerToModify.Id] = doctor; ActivePlayers.Add(doctor); } } } foreach (Player player in inactivePlayers) { player.Role = Role.Villager; player.Active = true; Villager villager = new Villager(player); PlayerMapping[player.Id] = villager; ActivePlayers.Add(villager); } ShowRolesToPlayers(); CurrentState = GameState.Night; }