Esempio n. 1
0
        protected virtual void GotGameData(GameDTO game)
        {
            Data = game;

            if (ChatLobby == null)
            {
                ChatLobby = new GroupChat(new agsXMPP.Jid(game.RoomName.ToLower() + ".pvp.net"), game.RoomPassword);
            }

            var participants = game.TeamOne.Concat(game.TeamTwo);

            foreach (var thing in participants)
            {
                var player = thing as PlayerParticipant;
                var bot    = thing as BotParticipant;
                int team;
                if (game.TeamOne.Contains(thing))
                {
                    team = 0;
                }
                else
                {
                    team = 1;
                }

                GameMember now;

                if (player != null)
                {
                    now = new GameMember(player, team, this);
                }
                else if (bot != null)
                {
                    now = new GameMember(bot, team, this);
                }
                else
                {
                    throw new Exception("Unknown participant " + thing);
                }

                GameMember old = AllMembers.SingleOrDefault(m => m.SummonerID == now.SummonerID);
                if (old != null)
                {
                    old.Update(now);
                }
                else
                {
                    if (team == 0)
                    {
                        TeamOne.Add(now);
                    }
                    else
                    {
                        TeamTwo.Add(now);
                    }
                    OnMemberJoined(now);
                }
            }

            if (game.GameState == "TEAM_SELECT")
            {
                Dispose();
                Session.Current.CurrentLobby = teamSelect;
                OnGameCancel(teamSelect);
            }

            OnUpdate(game);
            if (!loaded)
            {
                OnLoaded();
            }
        }
Esempio n. 2
0
        protected virtual void GotGameData(GameDTO game)
        {
            Data = game;

            if (ChatLobby == null)
            {
                ChatLobby = new GroupChat(RiotChat.GetCustomRoom(game.RoomName, game.Id, game.RoomPassword), game.RoomPassword);
            }

            var participants = game.TeamOne.Concat(game.TeamTwo);
            var left         = new List <CustomLobbyMember>(AllMembers);

            foreach (var thing in participants)
            {
                var player = thing as PlayerParticipant;
                var bot    = thing as BotParticipant;
                int team;
                if (game.TeamOne.Contains(thing))
                {
                    team = 0;
                }
                else
                {
                    team = 1;
                }

                CustomLobbyMember now;

                if (player != null)
                {
                    now = new CustomLobbyMember(player, team, this);
                }
                else if (bot != null)
                {
                    now = new CustomLobbyMember(bot, team, this);
                }
                else
                {
                    throw new Exception("Unknown participant " + thing);
                }

                CustomLobbyMember old = AllMembers.SingleOrDefault(m => m.SummonerID == now.SummonerID);
                if (old != null)
                {
                    TeamOne.Remove(old);
                    TeamTwo.Remove(old);
                    Observers.Remove(old);

                    bool diff = old.Team != now.Team;
                    old.Update(now);
                    if (team == 0)
                    {
                        TeamOne.Add(old);
                    }
                    else
                    {
                        TeamTwo.Add(old);
                    }

                    if (diff)
                    {
                        OnMemberChangeTeam(old);
                    }
                    left.Remove(old);
                }
                else
                {
                    if (team == 0)
                    {
                        TeamOne.Add(now);
                    }
                    else
                    {
                        TeamTwo.Add(now);
                    }

                    OnMemberJoined(now);
                }
            }

            foreach (var thing in game.Observers)
            {
                var now = new CustomLobbyMember(thing, this);

                CustomLobbyMember old = AllMembers.SingleOrDefault(m => m.SummonerID == thing.SummonerId);

                if (old != null)
                {
                    TeamOne.Remove(old);
                    TeamTwo.Remove(old);
                    Observers.Remove(old);

                    bool diff = old.Team != now.Team;
                    old.Update(now);
                    Observers.Add(old);

                    if (diff)
                    {
                        OnMemberChangeTeam(old);
                    }
                    left.Remove(old);
                }
                else
                {
                    Observers.Add(now);

                    OnMemberJoined(now);
                }
            }

            foreach (var member in left)
            {
                TeamOne.Remove(member);
                TeamTwo.Remove(member);
                OnMemberLeft(member);
            }

            if (game.GameState.Contains("CHAMP_SELECT"))
            {
                var champSelect = GameLobby.EnterChampSelect(game);
                OnGameStart(champSelect);
            }

            OnUpdate(game);
            if (!loaded)
            {
                OnLoaded();
            }
        }