Esempio n. 1
0
        public static async Task <IList <Player> > LoadRandom(
            SocialGamificationAssetContext db,
            Player player,
            IList <CustomDataBase> customData,
            bool alliancesOnly = false,
            int limit          = 1)
        {
            var query = db.Players.Where(a => a.Role == AccountType.Player);

            if (alliancesOnly)
            {
                var alliancesList = Alliance.GetAllianceIds(db, player.Id, AllianceState.Accepted);

                query = query.Where(p => alliancesList.Contains(p.Id));
            }
            else
            {
                query = query.Where(p => p.Id != player.Id);
            }

            // CustomData conditions
            var customDataQuery = Models.CustomData.ConditionBuilder(db, customData, CustomDataType.Player);

            if (customDataQuery != null)
            {
                IList <Guid> similarPlayers = await customDataQuery.Select(c => c.ObjectId).Distinct().ToListAsync();

                // Check if Players satisfy CustomData constraints
                query = query.Where(p => similarPlayers.Contains(p.Id));
            }

            IList <Player> players = await query.ToListAsync();

            return(GenericHelper.Shuffle(players, limit));
        }
Esempio n. 2
0
        public static async Task <IList <Group> > LoadRandom(
            SocialGamificationAssetContext db,
            Group group,
            IList <CustomDataBase> customData,
            bool alliancesOnly = false,
            int limit          = 1)
        {
            IQueryable <Group> query = db.Groups;

            if (alliancesOnly)
            {
                var alliancesList = Alliance.GetAllianceIds(db, group.Id, AllianceState.Accepted);

                query = query.Where(a => alliancesList.Contains(group.Id));
            }
            else
            {
                query = query.Where(g => g.Id != group.Id).Where(g => g.Type == GroupVisibility.Public);
            }

            // CustomData conditions
            var          cQuery        = Models.CustomData.ConditionBuilder(db, customData, CustomDataType.Group);
            IList <Guid> similarGroups = await cQuery.Select(c => c.ObjectId).Distinct().ToListAsync();

            // Check if Group satisfy CustomData constraints
            IList <Group> groups = await query.Where(g => similarGroups.Contains(g.Id)).ToListAsync();

            return(GenericHelper.Shuffle(groups, limit));
        }
Esempio n. 3
0
        public static IQueryable <Actor> Alliances(SocialGamificationAssetContext db, Guid id, AllianceState state)
        {
            var alliancesList = Alliance.GetAllianceIds(db, id, state);

            return(db.Actors.Where(a => alliancesList.Contains(a.Id)));
        }