Esempio n. 1
0
        private bool OnLobbyStatus(LobbyStatus status)
        {
            if (state == null)
            {
                return(true);
            }
            lastLobbyStatus = status;
            state.IsCaptain = status.Owner.SummonerId == session.Me.SummonerId;

            if (loop.CurrentType == PlayLoopType.STANDARD)
            {
                state.CanMatch = true;

                if (state.Chatroom == Guid.Empty)
                {
                    state.Chatroom = rooms.JoinStandard(status);
                }

                var members = new List <LobbyMember>();
                foreach (var old in status.Members)
                {
                    var member = new LobbyMember(old);
                    if (old.SummonerId == session.Me.SummonerId)
                    {
                        state.Me = member;
                    }
                    members.Add(member);
                }
                state.Members = members;
            }

            state.Invitees = (from old in status.Invitees
                              where old.InviteeState != "CREATOR"
                              select new LobbyInvitee(old)).ToList();

            OnStateChanged();
            return(true);
        }
Esempio n. 2
0
        private bool OnGameDTO(GameDTO data)
        {
            var changed = lastGameDto?.Id != data.Id || lastGameDto?.GameState != data.GameState;

            lastGameDto = data;

            var config = session.Me.GameTypeConfigs.Single(c => c.Id == data.GameTypeConfigId);

            switch (data.GameState)
            {
            case GameState.TEAM_SELECT:
                OnAdvancedToCustom();
                break;

            case GameState.TERMINATED:
                OnAdvancedToMatchmaking();
                break;

            case GameState.START_REQUESTED:
                OnGameStarted();
                break;

            case GameState.PRE_CHAMP_SELECT:
                if (changed)
                {
                    state.Remaining = config.BanTimerDuration * 1000 + 1000;
                    timerUpdated    = DateTime.Now;
                }
                state.Phase = Model.ChampSelectPhase.BANNING;
                #region BANNING
                if (changed)
                {
                    this.session.GameService.GetChampionsForBan().ContinueWith(t => {
                        var available = from c in t.Result
                                        where c.EnemyOwned
                                        select c.ChampionId;
                        state.Inventory.BannableChamps = available.ToList();
                        OnStateChanged();
                    });
                }

                var alliedBans = from b in data.BannedChampions
                                 where RiotUtils.TeamIdToIsBlue(b.TeamId) == state.IsBlue
                                 select b.ChampionId;
                var enemyBans = from b in data.BannedChampions
                                where RiotUtils.TeamIdToIsBlue(b.TeamId) != state.IsBlue
                                select b.ChampionId;

                state.AlliedBans = alliedBans.ToList();
                state.EnemyBans  = enemyBans.ToList();
                #endregion
                goto MAIN_CHAMP_SELECT;

            case GameState.POST_CHAMP_SELECT:
                if (changed)
                {
                    state.Remaining = config.PostPickTimerDuration * 1000 + 1000;
                    timerUpdated    = DateTime.Now;
                }
                state.Phase = Model.ChampSelectPhase.FINALIZING;
                #region FINALIZING
                this.session.ChampionTradeService.GetPotentialTraders().ContinueWith(t => {
                    potentialTraders = t.Result.PotentialTraders;
                    UpdateGameMembers();
                });
                #endregion
                goto MAIN_CHAMP_SELECT;

            case GameState.CHAMP_SELECT:
                if (changed)
                {
                    state.Remaining = config.MainPickTimerDuration * 1000 + 1000;
                    timerUpdated    = DateTime.Now;
                }
                state.Phase = Model.ChampSelectPhase.PICKING;

MAIN_CHAMP_SELECT:
                if (state.Chatroom == Guid.Empty)
                {
                    state.Chatroom = rooms.JoinStandard(data);
                }

                if (changed)
                {
                    this.session.GameService.SetClientReceivedGameMessage(data.Id, "CHAMP_SELECT_CLIENT");

                    state.Inventory = new Model.Inventory();
                    state.IsBlue    = data.TeamOne.Any(p => p.SummonerInternalName == session.Me.InternalName);

                    var ids = from spell in DataDragon.SpellData.Value.data.Values
                              where spell.modes.Contains(data.GameMode)
                              select spell.key;
                    state.Inventory.AvailableSpells = ids.ToList();

                    this.session.InventoryService.GetAvailableChampions().ContinueWith(t => {
                        var available = from c in t.Result
                                        where c.Owned || c.FreeToPlay
                                        select c.ChampionId;
                        state.Inventory.PickableChamps = available.ToList();
                        OnStateChanged();
                    });
                }

                state.Remaining -= (long)(DateTime.Now - timerUpdated).TotalMilliseconds;
                this.session.GameService.GetCurrentTimerForGame().ContinueWith(t => {
                    if (t.Result == null)
                    {
                        return;
                    }

                    state.Remaining = t.Result.RemainingTimeInMillis;
                    OnStateChanged();
                    timerUpdated = DateTime.Now;
                });

                state.Turn = data.PickTurn;
                selections = data.PlayerChampionSelections.ToDictionary(s => s.SummonerInternalName);

                var expired = from trade in trades.Values
                              where trade.RequesterInternalSummonerName == session.Me.InternalName
                              where trade.RequesterChampionId != selections[session.Me.InternalName].ChampionId
                              select trade.ResponderInternalSummonerName;
                foreach (var iName in expired.ToList())
                {
                    trades.Remove(iName);
                }

                UpdateGameMembers();

                break;
            }

            return(true);
        }