public void SendGameOutcome() { var manager = FindObjectOfType <AMainManager>(); List <messages.Player> leaderboards = manager.PlayersInstances .Select(x => x.Value) .OrderByDescending(x => x.CompletedPotionCount) .ThenByDescending(x => x.CollectedIngredientCount) .Select(x => new messages.Player() { color = ColorUtility.ToHtmlStringRGBA(ColorsManager.Get().PlayerAppColors[x.ID]), id = x.ID, name = x.Name, ingredients = x.CollectedIngredientCount, potions = x.CompletedPotionCount, }).ToList(); var gameOutcome = new GameOutcome() { leaderboards = leaderboards.ToArray(), }; var serialized = JsonConvert.SerializeObject(gameOutcome); _Socket.Emit(Command.GAME_OUTCOME, new JSONObject(serialized)); }
public void SendGameStateUpdate() { var players = new List <messages.Player>(); var manager = FindObjectOfType <AMainManager>(); for (var i = 0; i < manager.PlayersInstances.Count; i++) { var player = manager.GetPlayerById(i); players.Add(new messages.Player { id = i, color = "#" + ColorUtility.ToHtmlStringRGBA(ColorsManager.Get().PlayerAppColors[i]), name = player.Name, potions = player.CompletedPotionCount, }); } var game = new Game { players = players, }; var serialized = JsonConvert.SerializeObject(game); _Socket?.Emit(Command.SEND_GAME_STATE, new JSONObject(serialized)); }
/// <summary> /// Return true if connected to server /// False otherwise /// </summary> /// <returns></returns> public bool SendPlayerCharacteristics(List <PlayerManager> playerList) { var players = playerList.Select(p => new messages.Player() { id = p.ID, name = p.Name, color = "#" + ColorUtility.ToHtmlStringRGBA(ColorsManager.Get().PlayerAppColors[p.ID]), }).ToList(); var newtorkedList = new messages.Players { players = players }; var serialized = JsonConvert.SerializeObject(newtorkedList); _Socket.Emit( Command.REGISTER_PLAYERS, new JSONObject(serialized)); return(true); }
void Awake() { Instance = this; }