コード例 #1
0
        private List <RaidParticipant> GetAllUsers(EpgpRaid raid)
        {
            var returnList = new List <RaidParticipant>();

            returnList.AddRange(raid.Participants.Values);
            return(returnList);
        }
コード例 #2
0
        private void UpdateRaidParticipants(EpgpRaid raidData)
        {
            using var scope = _serviceScopeFactory.CreateScope();
            var db   = scope.ServiceProvider.GetRequiredService <BuzzBotDbContext>();
            var raid = db.Raids.Include(r => r.Participants).FirstOrDefault(r => r.Id == raidData.RaidId);

            if (raid == null)
            {
                return;
            }
            var raidParticipants = raidData.Participants.Values;

            foreach (var participant in raidParticipants)
            {
                foreach (var participantAlias in participant.Aliases)
                {
                    if (raid.Participants.Any(rp => rp.AliasId == participantAlias.Id))
                    {
                        continue;
                    }
                    raid.Participants.Add(new RaidAlias()
                    {
                        RaidId = raid.Id, AliasId = participantAlias.Id
                    });
                }
            }

            db.SaveChanges();
        }
コード例 #3
0
        private List <RaidParticipant> GetEndBonusAliases(EpgpRaid raidData)
        {
            var returnList = new List <EpgpAlias>();

            using var scope = _serviceScopeFactory.CreateScope();
            var mapper = scope.ServiceProvider.GetRequiredService <IMapper>();
            var db     = scope.ServiceProvider.GetRequiredService <BuzzBotDbContext>();
            var raid   = db.Raids.Include(r => r.Participants).ThenInclude(a => a.Alias).FirstOrDefault(r => r.Id == raidData.RaidId);

            if (raid == null)
            {
                throw new InvalidOperationException("Unable to locate the raid with the provided ID");
            }
            var userGroups = raid.Participants.GroupBy(rp => rp.Alias.UserId);

            foreach (var userGroup in userGroups)
            {
                //If no user in this grouping was in the end of the raid, move on
                if (!raidData.Participants.ContainsKey(userGroup.Key))
                {
                    continue;
                }
                //If a user was only playing one character, and their primary participated in this raid, award EP to their primary
                if (userGroup.Count() == 1 && userGroup.First().Alias.IsPrimary)
                {
                    returnList.Add(userGroup.First().Alias);
                    continue;
                }
                //Otherwise add it to their active
                if (userGroup.All(rp => rp.Alias.IsActive))
                {
                    returnList.AddRange(userGroup.Select(rp => rp.Alias));
                    continue;
                }
                //If a user was multiboxing, add to their multibox characters as normal.
                var bonusAlias = userGroup.FirstOrDefault(rp => rp.Alias.IsPrimary) ??
                                 userGroup.FirstOrDefault(rp => rp.Alias.IsActive);
                if (bonusAlias == null)
                {
                    continue;
                }
                returnList.Add(bonusAlias.Alias);
            }

            return(returnList.GroupBy(a => a.UserId)
                   .Select(grp =>
                           new RaidParticipant(grp.First().UserId)
            {
                Aliases = mapper.Map <IEnumerable <EpgpAlias>, List <EpgpAliasViewModel> >(grp)
            })
                   .ToList());
        }