Esempio n. 1
0
        public async Task AreYouReadyResponse(ConnectedUser user, AreYouReadyResponse response)
        {
            PlayerEntry entry;

            if (players.TryGetValue(user.Name, out entry))
            {
                if (entry.InvitedToPlay)
                {
                    if (response.Ready)
                    {
                        entry.LastReadyResponse = true;
                    }
                    else
                    {
                        entry.LastReadyResponse = false;
                        await RemoveUser(user.Name, true);
                    }

                    var invitedPeople = players.Values.Where(x => x?.InvitedToPlay == true).ToList();

                    if (invitedPeople.Count <= 1)
                    {
                        foreach (var p in invitedPeople)
                        {
                            p.LastReadyResponse = true;
                        }
                        // if we are doing tick because too few people, make sure we count remaining people as readied to not ban them
                        OnTick();
                    }
                    else if (invitedPeople.All(x => x.LastReadyResponse))
                    {
                        OnTick();
                    }
                    else
                    {
                        var readyCounts = CountQueuedPeople(invitedPeople.Where(x => x.LastReadyResponse));

                        var proposedBattles = ProposeBattles(invitedPeople.Where(x => x.LastReadyResponse));

                        await Task.WhenAll(invitedPeople.Select(async(p) =>
                        {
                            var invitedBattle = invitationBattles?.FirstOrDefault(x => x.Players.Contains(p));
                            await
                            server.SendToUser(p.Name,
                                              new AreYouReadyUpdate()
                            {
                                QueueReadyCounts = readyCounts,
                                ReadyAccepted    = p.LastReadyResponse == true,
                                LikelyToPlay     = proposedBattles.Any(y => y.Players.Contains(p)),
                                YourBattleSize   = invitedBattle?.Size,
                                YourBattleReady  =
                                    invitedPeople.Count(x => x.LastReadyResponse && (invitedBattle?.Players.Contains(x) == true))
                            });
                        }));
                    }
                }
            }
        }
Esempio n. 2
0
 public async Task Process(AreYouReadyResponse response)
 {
     await server.MatchMaker.AreYouReadyResponse(this, response);
 }
Esempio n. 3
0
        public async Task AreYouReadyResponse(ConnectedUser user, AreYouReadyResponse response)
        {
            PlayerEntry entry;

            if (players.TryGetValue(user.Name, out entry))
            {
                if (entry.InvitedToPlay)
                {
                    if (response.Ready)
                    {
                        entry.LastReadyResponse = true;
                        if (entry.QuickPlay)
                        {
                            await server.UserLogSay($"{user.Name} accepted his quickplay MM invitation");
                        }
                        else
                        {
                            await server.UserLogSay($"{user.Name} accepted his pop-up MM invitation");
                        }
                    }
                    else
                    {
                        if (entry.QuickPlay)
                        {
                            await server.UserLogSay($"{user.Name} rejected his quickplay MM invitation");

                            entry.InvitedToPlay = false; //don't ban quickplayers
                        }
                        else
                        {
                            await server.UserLogSay($"{user.Name} rejected his pop-up MM invitation");
                        }
                        lastTimePlayerDeniedMatch[entry.Name] = DateTime.UtcNow; //store that this player is probably not interested in suggestive MM games
                        entry.LastReadyResponse = false;
                        await RemoveUser(user.Name, true);
                    }

                    var invitedPeople = players.Values.Where(x => x?.InvitedToPlay == true).ToList();

                    if (invitedPeople.Count <= 1)
                    {
                        await server.UserLogSay($"Aborting MM invitations because only {invitedPeople.Count} invitations outstanding.");

                        foreach (var p in invitedPeople)
                        {
                            p.LastReadyResponse = true;
                        }
                        // if we are doing tick because too few people, make sure we count remaining people as readied to not ban them
                        OnTick();
                    }
                    else if (invitedPeople.All(x => x.LastReadyResponse))
                    {
                        await server.UserLogSay($"All {invitedPeople.Count} invitations have been accepted, doing tick.");

                        OnTick();
                    }
                    else
                    {
                        var readyCounts = CountQueuedPeople(invitedPeople.Where(x => x.LastReadyResponse));

                        var proposedBattles = ProposeBattles(invitedPeople.Where(x => x.LastReadyResponse), false);

                        await Task.WhenAll(invitedPeople.Select(async(p) =>
                        {
                            var invitedBattle = invitationBattles?.FirstOrDefault(x => x.Players.Contains(p));
                            await server.SendToUser(p.Name,
                                                    new AreYouReadyUpdate()
                            {
                                QueueReadyCounts = readyCounts,
                                ReadyAccepted    = p.LastReadyResponse == true,
                                LikelyToPlay     = proposedBattles.Any(y => y.Players.Contains(p)),
                                YourBattleSize   = invitedBattle?.Size,
                                YourBattleReady  = invitedPeople.Count(x => x.LastReadyResponse && (invitedBattle?.Players.Contains(x) == true))
                            });
                        }));
                    }
                }
            }
        }
 public async Task Process(AreYouReadyResponse response)
 {
     await Task.Factory.StartNew(() => server.MatchMaker.AreYouReadyResponse(this, response));
 }