Exemplo n.º 1
0
        public void Execute(IJobExecutionContext context)
        {
            try
            {
                // TOOD: Replace with an enum
                const int          inQueue      = 2;
                var                parties      = _partyRepository.FindByMatchmakeStateAsync(inQueue).Result;
                List <PartyMember> partyMembers = new List <PartyMember>();
                foreach (var party in parties)
                {
                    var foundPartyMembers = _partyMemberRepository.FindByPartyId(party.Id).Result;
                    partyMembers.AddRange(foundPartyMembers);
                }

                // TODO: Add some matchmaking logic
                var matchedPartyMembers = partyMembers.ToList();

                if (!matchedPartyMembers.Any())
                {
                    return;
                }

                var session = new Session
                {
                    Id     = Guid.NewGuid().ToString(),
                    MapId  = "guardian",
                    ModeId = "slayer"
                };
                _sessionRepository.CreateAsync(session).Wait();

                // TODO: Set party matchmake state to ingame
                foreach (var partyMember in matchedPartyMembers)
                {
                    partyMember.SessionId = session.Id;
                    _partyMemberRepository.UpdateAsync(partyMember).Wait();
                }
            }
            catch (Exception e)
            {
                // TODO: Use a logging framework
                Debug.WriteLine("An error occured during matchmaking", e);
            }
        }