private void Parse64005(Packet packet) { var token = JToken.Parse(packet.Message); arenaInfo = ArenaInfo.Parse(token); timesLabel.Text = String.Format("Số lần: {0}/5", arenaInfo.CurrentPlayer.RemainTimes); cascadeLabel.Text = String.Format("Liên thắng hiện tại: {0}", arenaInfo.CurrentPlayer.Cascade); topRankLabel.Text = String.Format("Hạng cao nhất: {0}", arenaInfo.CurrentPlayer.TopRank); var oldSelectedIndex = playerList.SelectedIndex; playerList.SetObjects(arenaInfo.Players, true); playerList.SelectedIndex = oldSelectedIndex; }
public static ArenaInfo Parse(JToken token) { var result = new ArenaInfo(); result.Players = new List <ArenaPlayer>(); var rankList = (JArray)token["rankList"]; foreach (var rank in rankList) { var player = ArenaPlayer.Parse(rank); result.Players.Add(player); } var playerInfo = token["playerInfo"]; result.CurrentPlayer = ArenaPlayer.Parse(playerInfo); var cd = (int)token["cd"]; // seconds. result.cooldown = new Cooldown(cd * 1000); return(result); }
/// <summary> /// Cập nhật võ đài tất cả các tài khoản đang kết nối. /// </summary> private async Task <bool> RefreshPlayersAsync(List <IClient> connectedClients) { if (isRefreshing) { LogInfo("Đang làm mới, không thể làm mới!"); return(false); } if (isDueling) { LogInfo("Đang khiêu chiến, không thể làm mới!"); return(false); } try { isRefreshing = true; LogInfo("Bắt đầu làm mới..."); clients.Clear(); infos.Clear(); playerIds.Clear(); playerList.Items.Clear(); var tasks = connectedClients.Select(client => client.RefreshArenaAsync()); var packets = await Task.WhenAll(tasks); Debug.Assert(packets.Length == connectedClients.Count); for (int i = 0; i < packets.Length; ++i) { var packet = packets[i]; if (packet == null) { continue; } Debug.Assert(packet.CommandId == "64005"); var token = JToken.Parse(packet.Message); var errmessage = token["errmessage"]; if (errmessage != null) { // { "errmessage": "A system error occurred! code:64005" } continue; } var client = connectedClients[i]; var info = ArenaInfo.Parse(token); var playerId = client.PlayerId; playerIds.Add(playerId); clients.Add(playerId, client); infos.Add(playerId, info); } playerIds.Sort((lhs, rhs) => { var lhsRank = infos[lhs].CurrentPlayer.Rank; var rhsRank = infos[rhs].CurrentPlayer.Rank; return(lhsRank.CompareTo(rhsRank)); }); playerList.SetObjects(playerIds, true); } finally { LogInfo("Làm mới hoàn thành!"); isRefreshing = false; } return(true); }