Exemplo n.º 1
0
 internal static GameLobby EnterChampSelect(GameDTO game) {
   var lobby = new GameLobby();
   Session.Current.CurrentLobby = lobby;
   RiotServices.GameService.SetClientReceivedGameMessage(game.Id, "CHAMP_SELECT_CLIENT");
   lobby.GotGameData(game);
   return lobby;
 }
Exemplo n.º 2
0
    public void UpdatePresence(Presence p) {
      IsOffline = p.Status == null;
      if (!IsOffline) {
        Status = new LeagueStatus(p.Status, p.Show);
        if (Status.GameStatus == ChatStatus.inGame) {
          RiotServices.GameService.RetrieveInProgressSpectatorGameInfo(User.Name).ContinueWith(GotGameDTO);
          if (Cache != null)
            CurrentGameFetcher.FetchGame(Cache.Data.Summoner.SummonerId, GotGameInfo);
        } else {
          CurrentGameDTO = null;
          CurrentGameInfo = null;
        }

        Session.Current.SummonerCache.GetData(User.Name, GotSummoner);
        Session.Current.ChatManager.ForceUpdate();
      }
    }
Exemplo n.º 3
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();
    }
Exemplo n.º 4
0
    private TurnInfo RenderPlayers(GameDTO game) {
      var turn = new TurnInfo();
      MyTeam.Children.Clear();
      OtherTeam.Children.Clear();
      bool meBlue = game.TeamOne.Any(p => (p as PlayerParticipant)?.AccountId == Session.Current.Account.AccountID);
      foreach (var thing in game.TeamOne.Concat(game.TeamTwo)) {
        var player = thing as PlayerParticipant;
        var bot = thing as BotParticipant;
        var obfusc = thing as ObfuscatedParticipant;
        bool blue = game.TeamOne.Contains(thing);

        UserControl control;
        if (player != null) {
          var selection = game.PlayerChampionSelections?.FirstOrDefault(c => c.SummonerInternalName == player.SummonerInternalName);
          control = new ChampSelectPlayer(player, selection);
          if (player.PickTurn == game.PickTurn) {
            if (player.SummonerId == Session.Current.Account.SummonerID) {
              turn.IsMyTurn = turn.IsOurTurn = true;
            } else if (meBlue == blue) {
              turn.IsOurTurn = true;
            }
          }
        } else if (bot != null) {
          control = new ChampSelectPlayer(bot);
        } else if (obfusc != null) {
          control = new ChampSelectPlayer(obfusc, null);
        } else {
          Session.Log(thing.GetType().Name);
          control = null;
        }

        if (blue == meBlue) {
          MyTeam.Children.Add(control);
        } else {
          OtherTeam.Children.Add(control);
        }
      }
      if (OtherTeam.Children.Count == 0) OtherTeam.Visibility = Visibility.Collapsed;

      Ban1.Source = Ban2.Source = Ban3.Source = Ban4.Source = Ban5.Source = Ban6.Source = null;
      Image[] blueBans, redBans;
      if (meBlue) {
        blueBans = new[] { Ban1, Ban2, Ban3 };
        redBans = new[] { Ban4, Ban5, Ban6 };
      } else {
        blueBans = new[] { Ban4, Ban5, Ban6 };
        redBans = new[] { Ban1, Ban2, Ban3 };
      }
      foreach (var thing in game.BannedChampions) {
        var champ = DataDragon.GetChampData(thing.ChampionId);
        var image = DataDragon.GetChampIconImage(champ);
        int index = thing.PickTurn - 1;
        if (index % 2 == 0) {
          //0, 2, 4: Blue team's bans
          blueBans[thing.PickTurn / 2].Source = image.Load();
        } else {
          //1, 3, 5: Red team's bans
          redBans[thing.PickTurn / 2].Source = image.Load();
        }
      }

      //Dispatcher.BeginInvoke((Action) (() => MyTeam.Height = OtherTeam.Height = Math.Max(MyTeam.ActualHeight, OtherTeam.ActualHeight)), System.Windows.Threading.DispatcherPriority.Input);
      return turn;
    }
Exemplo n.º 5
0
    private async void Update() {
      var game = this.game.Data;
      var config = Session.Current.Account.LoginPacket.GameTypeConfigs.FirstOrDefault(q => q.Id == game.GameTypeConfigId);
      LockInButt.IsEnabled = false;
      var myChamp = game.PlayerChampionSelections
        .FirstOrDefault(p => p.SummonerInternalName == Session.Current.Account.LoginPacket.AllSummonerData.Summoner.InternalName);
      var me = (PlayerParticipant) game.TeamOne.Concat(game.TeamTwo)
        .FirstOrDefault(p => (p as PlayerParticipant)?.AccountId == Session.Current.Account.AccountID);

      if (game.GameState.Equals("CHAMP_SELECT") || game.GameState.Equals("PRE_CHAMP_SELECT")) {
        var turn = Dispatcher.MyInvoke(RenderPlayers, game);
        Popup.ChampSelector.IsReadOnly = !turn.IsMyTurn;

        spell1 = DataDragon.GetSpellData(myChamp.Spell1Id);
        spell2 = DataDragon.GetSpellData(myChamp.Spell2Id);
        Dispatcher.Invoke(() => {
          Spell1Image.Source = DataDragon.GetSpellImage(spell1).Load();
          Spell2Image.Source = DataDragon.GetSpellImage(spell2).Load();
        });

        LockInButt.IsEnabled = turn.IsMyTurn;

        if (game.GameState.Equals("PRE_CHAMP_SELECT")) {
          if (last?.PickTurn != game.PickTurn) SetTimer(config.BanTimerDuration - 2);
          if (turn.IsMyTurn) state = State.Banning;
          else state = State.Watching;
          var champs = await this.game.GetChampionsForBan();

          if (turn.IsOurTurn) {
            Popup.ChampSelector.SetChampList(champs.Where(c => c.EnemyOwned).Select(c => DataDragon.GetChampData(c.ChampionId)));
          } else {
            Popup.ChampSelector.SetChampList(champs.Where(c => c.Owned).Select(c => DataDragon.GetChampData(c.ChampionId)));
          }

          if (turn.IsMyTurn) header = YouBanString;
          else if (turn.IsOurTurn) header = YourTeamBanString;
          else header = OtherTeamBanString;

        } else {
          if (last?.PickTurn != game.PickTurn) SetTimer(config.MainPickTimerDuration - 2);
          if (turn.IsMyTurn) state = State.Picking;
          else state = State.Watching;
          Popup.ChampSelector.UpdateChampList();

          if (turn.IsMyTurn) header = YouPickString;
          else header = NotPickingString;
        }
      } else if (game.GameState.Equals("POST_CHAMP_SELECT")) {
        if (last?.PickTurn != game.PickTurn) SetTimer(config.PostPickTimerDuration - 2);
        var turn = Dispatcher.MyInvoke(RenderPlayers, game);
        state = State.Watching;
        Popup.ChampSelector.IsReadOnly = true;
        header = PostString;
      } else {

      }

      if (game.GameType == GameConfig.AllRandom.Value) {
        LockInButt.Content = $"{me.PointSummary.NumberOfRolls} / {me.PointSummary.MaxRolls}";
        LockInButt.IsEnabled = me.PointSummary.NumberOfRolls > 0;
      }

      MyTeam.Columns = OtherTeam.Columns = game.MaxNumPlayers / 2;
      UpdateHeader();
      last = game;
    }
Exemplo n.º 6
0
 private void Queue_QueuePopped(object sender, GameDTO e) {
   Dispatcher.Invoke(() => {
     var popup = new DefaultQueuePopup(queue);
     LoLClient.QueueManager.ShowQueuePopup(popup);
   });
 }
Exemplo n.º 7
0
 private void GotGameDTO(Task<PlatformGameLifecycleDTO> task) {
   if (task.IsFaulted) {
     Session.Log(task.Exception);
     return;
   }
   if (task.Result == null) return;
   CurrentGameDTO = task.Result.Game;
 }
Exemplo n.º 8
0
 protected virtual void OnUpdate(GameDTO game) {
   Updated?.Invoke(this, new EventArgs());
 }
Exemplo n.º 9
0
 private void Queue_QueuePopped(object sender, GameDTO e) {
   TimeoutBar.AnimateProgress(1, 0, new Duration(TimeSpan.FromSeconds(e.JoinTimerDuration)));
 }
Exemplo n.º 10
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();
    }
Exemplo n.º 11
0
 protected void OnQueuePopUpdated(GameDTO game) {
   var states = new QueuePopPlayerState[game.StatusOfParticipants.Length];
   for (int i = 0; i < game.StatusOfParticipants.Length; i++) {
     switch (game.StatusOfParticipants[i]) {
       case '0':
         states[i] = QueuePopPlayerState.None;
         break;
       case '1':
         states[i] = QueuePopPlayerState.Accepted;
         break;
       case '2':
         states[i] = QueuePopPlayerState.Declined;
         break;
     }
   }
 }
Exemplo n.º 12
0
 protected void OnQueuePop(GameDTO game) {
   HasPopped = true;
   QueuePopped?.Invoke(this, game);
 }
Exemplo n.º 13
0
 protected void OnEnteredChampSelect(GameDTO game) {
   EnteredChampSelect?.Invoke(this, GameLobby.EnterChampSelect(game));
 }