Example #1
0
        public static async Task OverwriteCount(int userId, List <PixelModel> pixels, List <AwardHistoryModel> awards)
        {
            var version         = $"User:{userId}";
            var overwritePixels = pixels.Where(x => x.Points > 1).ToList();

            if (overwritePixels.Count >= 1 && !awards.Any(x => x.AwardType == AwardType.PixelOverwrite))
            {
                await AwardEngine.InsertAward(AwardType.PixelOverwrite, userId, null, version, null);
            }

            if (overwritePixels.Count >= 100 && !awards.Any(x => x.AwardType == AwardType.PixelOverwrite100))
            {
                await AwardEngine.InsertAward(AwardType.PixelOverwrite100, userId, null, version, null);
            }

            if (overwritePixels.Count >= 1000 && !awards.Any(x => x.AwardType == AwardType.PixelOverwrite1000))
            {
                await AwardEngine.InsertAward(AwardType.PixelOverwrite1000, userId, null, version, null);
            }

            if (overwritePixels.Count >= 10000 && !awards.Any(x => x.AwardType == AwardType.PixelOverwrite10000))
            {
                await AwardEngine.InsertAward(AwardType.PixelOverwrite10000, userId, null, version, null);
            }

            if (overwritePixels.Count >= 100000 && !awards.Any(x => x.AwardType == AwardType.PixelOverwrite100000))
            {
                await AwardEngine.InsertAward(AwardType.PixelOverwrite100000, userId, null, version, null);
            }

            if (overwritePixels.Count >= 1000000 && !awards.Any(x => x.AwardType == AwardType.PixelOverwrite1000000))
            {
                await AwardEngine.InsertAward(AwardType.PixelOverwrite1000000, userId, null, version, null);
            }
        }
Example #2
0
        public static async Task LastPixel(List <GameModel> games, List <PixelModel> pixels, List <AwardHistoryModel> awards)
        {
            foreach (var game in games)
            {
                if (game.EndType != GameEndType.LastPixel)
                {
                    continue;
                }

                if (awards.Any(x => x.AwardType == AwardType.PixelLastPixel && x.GameId == game.Id))
                {
                    continue;
                }

                // check if game is complete
                var gameSize   = game.Width * game.Height;
                var gamePixels = pixels
                                 .Where(x => x.GameId == game.Id)
                                 .GroupBy(x => new { x.X, x.Y })
                                 .Select(x => x.OrderBy(y => y.Timestamp).First())
                                 .OrderBy(x => x.Timestamp)
                                 .ToList();
                if (gamePixels.Count == gameSize)
                {
                    var lastPixel        = gamePixels.LastOrDefault();
                    var lastPixelVersion = $"X:{lastPixel.X}-Y:{lastPixel.Y}";

                    await AwardEngine.InsertAward(AwardType.PixelLastPixel, lastPixel.UserId, game.Id, lastPixelVersion, lastPixelVersion);

                    await AwardEngine.UpdateGameStatus(game.Id, GameStatus.Finished);
                }
            }
        }
Example #3
0
        public static async Task PixelCount(int userId, List <PixelModel> pixels, List <AwardHistoryModel> awards)
        {
            var version = $"User:{userId}";

            if (pixels.Count >= 100 && !awards.Any(x => x.AwardType == AwardType.Pixel100))
            {
                await AwardEngine.InsertAward(AwardType.Pixel100, userId, null, version, null);
            }

            if (pixels.Count >= 1000 && !awards.Any(x => x.AwardType == AwardType.Pixel1000))
            {
                await AwardEngine.InsertAward(AwardType.Pixel1000, userId, null, version, null);
            }

            if (pixels.Count >= 10000 && !awards.Any(x => x.AwardType == AwardType.Pixel10000))
            {
                await AwardEngine.InsertAward(AwardType.Pixel10000, userId, null, version, null);
            }

            if (pixels.Count >= 100000 && !awards.Any(x => x.AwardType == AwardType.Pixel100000))
            {
                await AwardEngine.InsertAward(AwardType.Pixel100000, userId, null, version, null);
            }

            if (pixels.Count >= 1000000 && !awards.Any(x => x.AwardType == AwardType.Pixel1000000))
            {
                await AwardEngine.InsertAward(AwardType.Pixel1000000, userId, null, version, null);
            }
        }
        public static async Task HorizontalLines(int userId, GameModel game, List <PixelModel> pixels, List <AwardHistoryModel> awards)
        {
            // HorizontalLines
            var lineGroups = pixels
                             .Where(x => x.Type == PixelType.User)
                             .Select(x => new { X = x.X, Y = x.Y })
                             .GroupBy(x => x.Y)
                             .Select(x => new
            {
                Y     = x.Key,
                Count = x.Distinct()
                        .Count()
            })
                             .Where(x => x.Count == game.Width)
                             .ToList();

            foreach (var lineGroup in lineGroups)
            {
                var key     = $"Y:{lineGroup.Y}";
                var version = $"Game:{game.Id}|{key}";
                if (awards.Any(x => x.AwardType == AwardType.PixelHorizontalLine && x.Version == version))
                {
                    continue;
                }

                await AwardEngine.InsertAward(AwardType.PixelHorizontalLine, userId, game.Id, version, key);
            }
        }
        public static async Task FourCorners(int userId, GameModel game, List <PixelModel> pixels, List <AwardHistoryModel> awards)
        {
            // Four Corners
            if (awards.Any(x => x.AwardType == AwardType.PixelFourCorners))
            {
                return;
            }

            var maxX    = game.Width - 1;
            var maxY    = game.Height - 1;
            var version = $"Game:{game.Id}";

            // top left
            if (!pixels.Any(x => x.X == 0 && x.Y == 0))
            {
                return;
            }
            // top right
            if (!pixels.Any(x => x.X == maxX && x.Y == 0))
            {
                return;
            }
            // bottom left
            if (!pixels.Any(x => x.X == 0 && x.Y == maxY))
            {
                return;
            }
            // bottom right
            if (!pixels.Any(x => x.X == maxX && x.Y == maxY))
            {
                return;
            }

            await AwardEngine.InsertAward(AwardType.PixelFourCorners, userId, game.Id, version, null);
        }
        public static async Task BorderLines(int userId, GameModel game, List <PixelModel> pixels, List <AwardHistoryModel> awards)
        {
            if (awards.Any(x => x.AwardType == AwardType.PixelBorderLines))
            {
                return;
            }

            var version = $"Game:{game.Id}";

            // horizontal rows
            if (!awards.Any(x => x.AwardType == AwardType.PixelHorizontalLine && x.Version == $"{version}|Y:0") ||
                !awards.Any(x => x.AwardType == AwardType.PixelHorizontalLine && x.Version == $"{version}|Y:{game.Height - 1}"))
            {
                return;
            }

            // vertical rows
            if (!awards.Any(x => x.AwardType == AwardType.PixelVerticalLine && x.Version == $"{version}|X:{0}") ||
                !awards.Any(x => x.AwardType == AwardType.PixelVerticalLine && x.Version == $"{version}|X:{game.Width - 1}"))
            {
                return;
            }

            await AwardEngine.InsertAward(AwardType.PixelBorderLines, userId, game.Id, version, null);
        }
        public static async Task ColorBlind(int userId, GameModel game, List <PixelModel> pixels, List <AwardHistoryModel> awards)
        {
            if (awards.Any(x => x.AwardType == AwardType.ColorBlind))
            {
                return;
            }

            var userPixels = pixels.Where(x => x.Type == PixelType.User).ToList();

            // white
            if (!userPixels.Any(x => x.Color.Equals("#ffffff", System.StringComparison.OrdinalIgnoreCase)))
            {
                return;
            }
            // black
            if (!userPixels.Any(x => x.Color.Equals("#000000", System.StringComparison.OrdinalIgnoreCase)))
            {
                return;
            }
            // grey
            if (!userPixels.Any(x => x.Color.Equals("#808080", System.StringComparison.OrdinalIgnoreCase)))
            {
                return;
            }

            var version = $"Game:{game.Id}";
            await AwardEngine.InsertAward(AwardType.ColorBlind, userId, game.Id, version, null);
        }
Example #8
0
        public static async Task VerticalLines(int userId, GameModel game, List <ClickModel> clicks, List <AwardHistoryModel> awards)
        {
            // VerticalLines
            var lineGroups = clicks
                             .Select(x => new { X = x.X, Y = x.Y })
                             .GroupBy(x => x.X)
                             .Select(x => new
            {
                X     = x.Key,
                Count = x.Distinct().Count()
            })
                             .Where(x => x.Count == game.Height)
                             .ToList();

            foreach (var lineGroup in lineGroups)
            {
                var key     = $"X:{lineGroup.X}";
                var version = $"Game:{game.Id}|{key}";
                if (awards.Any(x => x.AwardType == AwardType.ClickVerticalLine && x.Version == version))
                {
                    continue;
                }

                await AwardEngine.InsertAward(AwardType.ClickVerticalLine, userId, game.Id, version, key);
            }
        }
Example #9
0
        public static async Task ClickCount(int userId, List <ClickModel> clicks, List <AwardHistoryModel> awards)
        {
            var version = $"User:{userId}";

            if (clicks.Count >= 100 && !awards.Any(x => x.AwardType == AwardType.Click100))
            {
                await AwardEngine.InsertAward(AwardType.Click100, userId, null, version, null);
            }

            if (clicks.Count >= 1000 && !awards.Any(x => x.AwardType == AwardType.Click1000))
            {
                await AwardEngine.InsertAward(AwardType.Click1000, userId, null, version, null);
            }

            if (clicks.Count >= 10000 && !awards.Any(x => x.AwardType == AwardType.Click10000))
            {
                await AwardEngine.InsertAward(AwardType.Click10000, userId, null, version, null);
            }

            if (clicks.Count >= 100000 && !awards.Any(x => x.AwardType == AwardType.Click100000))
            {
                await AwardEngine.InsertAward(AwardType.Click100000, userId, null, version, null);
            }

            if (clicks.Count >= 1000000 && !awards.Any(x => x.AwardType == AwardType.Click1000000))
            {
                await AwardEngine.InsertAward(AwardType.Click1000000, userId, null, version, null);
            }
        }
Example #10
0
        public static async Task ColorRainbow(int userId, GameModel game, List <PixelModel> pixels, List <AwardHistoryModel> awards)
        {
            if (awards.Any(x => x.AwardType == AwardType.ColorRainbow))
            {
                return;
            }

            var userPixels = pixels.Where(x => x.Type == PixelType.User).ToList();

            // Red
            if (!userPixels.Any(x => x.Color.Equals("#FF0000", System.StringComparison.OrdinalIgnoreCase)))
            {
                return;
            }
            // Orange
            if (!userPixels.Any(x => x.Color.Equals("#FF7F00", System.StringComparison.OrdinalIgnoreCase)))
            {
                return;
            }
            // Yellow
            if (!userPixels.Any(x => x.Color.Equals("#FFFF00", System.StringComparison.OrdinalIgnoreCase)))
            {
                return;
            }
            // Green
            if (!userPixels.Any(x => x.Color.Equals("#00FF00", System.StringComparison.OrdinalIgnoreCase)))
            {
                return;
            }
            // Blue
            if (!userPixels.Any(x => x.Color.Equals("#0000FF", System.StringComparison.OrdinalIgnoreCase)))
            {
                return;
            }
            // Indigo
            if (!userPixels.Any(x => x.Color.Equals("#4B0082", System.StringComparison.OrdinalIgnoreCase)))
            {
                return;
            }
            // Violet
            if (!userPixels.Any(x => x.Color.Equals("#9400D3", System.StringComparison.OrdinalIgnoreCase)))
            {
                return;
            }

            var version = $"Game:{game.Id}";
            await AwardEngine.InsertAward(AwardType.ColorRainbow, userId, game.Id, version, null);
        }
Example #11
0
        public static async Task Number911(int userId, List <ClickModel> clicks, List <AwardHistoryModel> awards)
        {
            var version1 = $"X:{9} Y:{11}";

            if (clicks.Any(a => a.X == 9 && a.Y == 11) && !awards.Any(x => x.AwardType == AwardType.Number911 && x.Version == version1))
            {
                await AwardEngine.InsertAward(AwardType.Number911, userId, null, version1, null);
            }

            var version2 = $"X:{11} Y:{9}";

            if (clicks.Any(a => a.X == 11 && a.Y == 9) && !awards.Any(x => x.AwardType == AwardType.Number911 && x.Version == version2))
            {
                await AwardEngine.InsertAward(AwardType.Number911, userId, null, version2, null);
            }
        }
Example #12
0
        public static async Task DailyClick(int userId, List <ClickModel> clicks, List <AwardHistoryModel> awards)
        {
            // daily pixel
            var dailyClicks = clicks
                              .Select(x => x.Timestamp.ToString("dd/MM/yyyy"))
                              .Distinct();

            foreach (var dailyClick in dailyClicks)
            {
                if (awards.Any(x => x.AwardType == AwardType.ClickDaily && x.Version == dailyClick))
                {
                    continue;
                }

                // new daily pixel award
                await AwardEngine.InsertAward(AwardType.ClickDaily, userId, null, dailyClick, dailyClick);
            }
        }
Example #13
0
        public static async Task DailyPixel(int userId, List <PixelModel> pixels, List <AwardHistoryModel> awards)
        {
            // daily pixel
            var dailyPixels = pixels
                              .Where(x => x.Type == PixelType.User)
                              .Select(x => x.Timestamp.ToString("dd/MM/yyyy"))
                              .Distinct();

            foreach (var dailyPixel in dailyPixels)
            {
                if (awards.Any(x => x.AwardType == AwardType.PixelDaily && x.Version == dailyPixel))
                {
                    continue;
                }

                // new daily pixel award
                await AwardEngine.InsertAward(AwardType.PixelDaily, userId, null, dailyPixel, dailyPixel);
            }
        }
Example #14
0
        public static async Task ColorCount(int userId, GameModel game, List <PixelModel> pixels, List <AwardHistoryModel> awards)
        {
            var version      = $"Game:{game.Id}";
            var userPixels   = pixels.Where(x => x.Type == PixelType.User).ToList();
            var uniqueColors = userPixels.Select(x => x.Color).Distinct().Count();

            if (uniqueColors >= 10 && !awards.Any(x => x.AwardType == AwardType.Color10))
            {
                await AwardEngine.InsertAward(AwardType.Color10, userId, game.Id, version, null);
            }

            if (uniqueColors >= 100 && !awards.Any(x => x.AwardType == AwardType.Color100))
            {
                await AwardEngine.InsertAward(AwardType.Color100, userId, game.Id, version, null);
            }

            if (uniqueColors >= 1000 && !awards.Any(x => x.AwardType == AwardType.Color1000))
            {
                await AwardEngine.InsertAward(AwardType.Color1000, userId, game.Id, version, null);
            }
        }
Example #15
0
        public static async Task Number420(int userId, List <ClickModel> clicks, List <AwardHistoryModel> awards)
        {
            var version1 = $"X:{420} Y:{0}";

            if (clicks.Any(a => a.X == 420 && a.Y == 0) && !awards.Any(x => x.AwardType == AwardType.Number420 && x.Version == version1))
            {
                await AwardEngine.InsertAward(AwardType.Number420, userId, null, version1, null);
            }

            var version2 = $"X:{0} Y:{420}";

            if (clicks.Any(a => a.X == 0 && a.Y == 420) && !awards.Any(x => x.AwardType == AwardType.Number420 && x.Version == version2))
            {
                await AwardEngine.InsertAward(AwardType.Number420, userId, null, version2, null);
            }

            var version3 = $"X:{420} Y:{420}";

            if (clicks.Any(a => a.X == 420 && a.Y == 420) && !awards.Any(x => x.AwardType == AwardType.Number420 && x.Version == version3))
            {
                await AwardEngine.InsertAward(AwardType.Number420, userId, null, version3, null);
            }

            var version4 = $"X:{4} Y:{20}";

            if (clicks.Any(a => a.X == 4 && a.Y == 20) && !awards.Any(x => x.AwardType == AwardType.Number420 && x.Version == version4))
            {
                await AwardEngine.InsertAward(AwardType.Number420, userId, null, version4, null);
            }

            var version5 = $"X:{20} Y:{4}";

            if (clicks.Any(a => a.X == 20 && a.Y == 4) && !awards.Any(x => x.AwardType == AwardType.Number420 && x.Version == version5))
            {
                await AwardEngine.InsertAward(AwardType.Number420, userId, null, version5, null);
            }
        }