コード例 #1
0
        private async Task ApplyBalanceResults(BalanceTeamsResult balance)
        {
            if (!IsNullOrEmpty(balance.Message))
            {
                await SayBattle(balance.Message);
            }
            if ((balance.Players != null) && (balance.Players.Count > 0))
            {
                foreach (var p in balance.Players)
                {
                    UserBattleStatus u;
                    if (Users.TryGetValue(p.Name, out u))
                    {
                        u.IsSpectator = p.IsSpectator;
                        u.AllyNumber  = p.AllyID;
                    }
                }

                foreach (var u in Users.Where(x => !balance.Players.Any(y => y.Name == x.Key)))
                {
                    u.Value.IsSpectator = true;
                }
            }

            if (balance.DeleteBots)
            {
                foreach (var b in Bots.Keys)
                {
                    await server.Broadcast(Users.Keys, new RemoveBot()
                    {
                        Name = b
                    });
                }
                Bots.Clear();
            }

            if ((balance.Bots != null) && (balance.Bots.Count > 0))
            {
                foreach (var p in balance.Bots)
                {
                    Bots.AddOrUpdate(p.BotName,
                                     s => new BotBattleStatus(p.BotName, p.Owner ?? FounderName, p.BotAI)
                    {
                        AllyNumber = p.AllyID
                    },
                                     (s, status) =>
                    {
                        status.AllyNumber = p.AllyID;
                        status.owner      = p.Owner ?? FounderName;
                        status.aiLib      = p.BotAI;
                        status.Name       = p.BotName;
                        return(status);
                    });
                }
            }

            foreach (var u in Users.Values.Select(x => x.ToUpdateBattleStatus()).ToList())
            {
                await server.Broadcast(Users.Keys, u);                                                                            // send other's status to self
            }
            foreach (var u in Bots.Values.Select(x => x.ToUpdateBotStatus()).ToList())
            {
                await server.Broadcast(Users.Keys, u);
            }
        }