コード例 #1
0
        public PlayerDataLoadedEventArgs(HMessage packet)
        {
            _packet = packet;
            Header  = _packet.Header;

            LoadedPlayers = new ReadOnlyCollection <IHPlayerData>(HPlayerData.Extract(packet));
        }
コード例 #2
0
        public PlayerDataLoadedEventArgs(HMessage packet)
        {
            _packet = packet;
            Header  = _packet.Header;

            LoadedPlayers = new ReadOnlyCollection <IHPlayerData>(HPlayerData.Extract(_packet));

            var playerByGender = new Dictionary <HGender, List <IHPlayerData> >()
            {
                { HGender.Male, new List <IHPlayerData>() },
                { HGender.Female, new List <IHPlayerData>() },
                { HGender.Unknown, new List <IHPlayerData>() }
            };
            var playerByFigureId  = new Dictionary <string, List <IHPlayerData> >();
            var playerByGroupName = new Dictionary <string, List <IHPlayerData> >();

            var figureIds     = new List <string>();
            var groupNames    = new List <string>();
            var playerMottos  = new List <string>();
            var tilesOccupied = new List <HPoint>();
            var playerIds     = new List <int>(LoadedPlayers.Count);
            var playerNames   = new List <string>(LoadedPlayers.Count);

            foreach (IHPlayerData player in LoadedPlayers)
            {
                playerByGender[player.Gender].Add(player);

                if (playerByFigureId.ContainsKey(player.FigureId))
                {
                    playerByFigureId[player.FigureId].Add(player);
                }
                else
                {
                    playerByFigureId.Add(player.FigureId, new List <IHPlayerData>()
                    {
                        player
                    });
                }

                if (playerByGroupName.ContainsKey(player.FavoriteGroup))
                {
                    playerByGroupName[player.FavoriteGroup].Add(player);
                }
                else
                {
                    playerByGroupName.Add(player.FavoriteGroup, new List <IHPlayerData>()
                    {
                        player
                    });
                }

                if (!figureIds.Contains(player.FigureId))
                {
                    figureIds.Add(player.FigureId);
                }

                if (!groupNames.Contains(player.FavoriteGroup))
                {
                    groupNames.Add(player.FavoriteGroup);
                }

                if (!playerMottos.Contains(player.Motto))
                {
                    playerMottos.Add(player.Motto);
                }

                if (!tilesOccupied.Contains(player.Tile))
                {
                    tilesOccupied.Add(player.Tile);
                }

                playerIds.Add(player.PlayerId);
                playerNames.Add(player.PlayerName);
            }

            PlayerIds     = new ReadOnlyCollection <int>(playerIds);
            FigureIds     = new ReadOnlyCollection <string>(figureIds);
            GroupNames    = new ReadOnlyCollection <string>(groupNames);
            PlayerNames   = new ReadOnlyCollection <string>(playerNames);
            PlayerMottos  = new ReadOnlyCollection <string>(playerMottos);
            TilesOccupied = new ReadOnlyCollection <HPoint>(tilesOccupied);

            _groupByGender = new Dictionary <HGender, ReadOnlyCollection <IHPlayerData> >();
            foreach (HGender key in playerByGender.Keys)
            {
                _groupByGender[key] = new ReadOnlyCollection <IHPlayerData>(playerByGender[key]);
            }

            _groupByFigureId = new Dictionary <string, ReadOnlyCollection <IHPlayerData> >();
            foreach (string key in playerByFigureId.Keys)
            {
                _groupByFigureId[key] = new ReadOnlyCollection <IHPlayerData>(playerByFigureId[key]);
            }

            _groupByGroupName = new Dictionary <string, ReadOnlyCollection <IHPlayerData> >();
            foreach (string key in playerByGroupName.Keys)
            {
                _groupByGroupName[key] = new ReadOnlyCollection <IHPlayerData>(playerByGroupName[key]);
            }
        }