public PossibleRoyaleMasterGameViewModel(MasterGameYear masterGame, IClock clock, RoyaleYearQuarter yearQuarter, bool alreadyOwned, IEnumerable <MasterGameTag> masterGameTags)
 {
     MasterGame           = new MasterGameYearViewModel(masterGame, clock);
     WillReleaseInQuarter = masterGame.WillReleaseInQuarter(yearQuarter.YearQuarter);
     IsEligible           = !LeagueTagExtensions.GetRoyaleEligibilitySettings(masterGameTags).GameIsEligible(masterGame.MasterGame).Any();
     AlreadyOwned         = alreadyOwned;
     Cost = masterGame.GetRoyaleGameCost();
 }
Пример #2
0
        public async Task <ClaimResult> PurchaseGame(RoyalePublisher publisher, MasterGameYear masterGame)
        {
            if (publisher.PublisherGames.Count >= MAX_GAMES)
            {
                return(new ClaimResult("Roster is full."));
            }
            if (publisher.PublisherGames.Select(x => x.MasterGame).Contains(masterGame))
            {
                return(new ClaimResult("Publisher already has that game."));
            }
            if (!masterGame.WillReleaseInQuarter(publisher.YearQuarter.YearQuarter))
            {
                return(new ClaimResult("Game will not release this quarter."));
            }
            if (masterGame.MasterGame.IsReleased(_clock.GetCurrentInstant()))
            {
                return(new ClaimResult("Game has been released."));
            }
            if (masterGame.MasterGame.CriticScore.HasValue)
            {
                return(new ClaimResult("Game has a score."));
            }

            var masterGameTags = await _masterGameRepo.GetMasterGameTags();

            var eligibilityErrors = LeagueTagExtensions.GetRoyaleEligibilitySettings(masterGameTags).GameIsEligible(masterGame.MasterGame);

            if (eligibilityErrors.Any())
            {
                return(new ClaimResult("Game is not eligible under Royale rules."));
            }

            var currentBudget = publisher.Budget;
            var gameCost      = masterGame.GetRoyaleGameCost();

            if (currentBudget < gameCost)
            {
                return(new ClaimResult("Not enough budget."));
            }

            RoyalePublisherGame game = new RoyalePublisherGame(publisher.PublisherID, publisher.YearQuarter, masterGame, _clock.GetCurrentInstant(), gameCost, 0m, null);
            await _royaleRepo.PurchaseGame(game);

            return(new ClaimResult());
        }
Пример #3
0
        public async Task <ActionResult <List <PossibleRoyaleMasterGameViewModel> > > PossibleMasterGames(string gameName, Guid publisherID)
        {
            Maybe <RoyalePublisher> publisher = await _royaleService.GetPublisher(publisherID);

            if (publisher.HasNoValue)
            {
                return(NotFound());
            }

            var yearQuarter = await _royaleService.GetYearQuarter(publisher.Value.YearQuarter.YearQuarter.Year, publisher.Value.YearQuarter.YearQuarter.Quarter);

            if (yearQuarter.HasNoValue)
            {
                return(BadRequest());
            }

            var masterGameTags = await _interLeagueService.GetMasterGameTags();

            var masterGames = await _royaleService.GetMasterGamesForYearQuarter(yearQuarter.Value.YearQuarter);

            if (!string.IsNullOrWhiteSpace(gameName))
            {
                masterGames = MasterGameSearching.SearchMasterGameYears(gameName, masterGames);
            }
            else
            {
                masterGames = masterGames
                              .Where(x => x.WillReleaseInQuarter(yearQuarter.Value.YearQuarter))
                              .Where(x => !x.MasterGame.IsReleased(_clock.GetCurrentInstant()))
                              .Where(x => !LeagueTagExtensions.GetRoyaleEligibilitySettings(masterGameTags).GameIsEligible(x.MasterGame).Any())
                              .Take(1000)
                              .ToList();
            }

            var viewModels = masterGames.Select(masterGame =>
                                                new PossibleRoyaleMasterGameViewModel(masterGame, _clock, yearQuarter.Value, publisher.Value.PublisherGames.Any(y =>
                                                                                                                                                                y.MasterGame.MasterGame.Equals(masterGame.MasterGame)), masterGameTags)).ToList();

            return(viewModels);
        }
Пример #4
0
    public bool CalculateIsCurrentlyIneligible(IEnumerable <MasterGameTag> allMasterGameTags)
    {
        var royaleTags        = LeagueTagExtensions.GetRoyaleEligibilitySettings(allMasterGameTags);
        var customCodeTags    = royaleTags.Where(x => x.Tag.HasCustomCode).ToList();
        var nonCustomCodeTags = royaleTags.Except(customCodeTags).ToList();

        var masterGame   = MasterGame.MasterGame;
        var bannedTags   = nonCustomCodeTags.Where(x => x.Status == TagStatus.Banned).Select(x => x.Tag);
        var requiredTags = nonCustomCodeTags.Where(x => x.Status == TagStatus.Required).Select(x => x.Tag);

        var bannedTagsIntersection = masterGame.Tags.Intersect(bannedTags);
        var missingRequiredTags    = requiredTags.Except(masterGame.Tags);

        if (bannedTagsIntersection.Any() || missingRequiredTags.Any())
        {
            return(true);
        }

        var masterGameCustomCodeTags = masterGame.Tags.Where(x => x.HasCustomCode).ToList();

        if (!masterGameCustomCodeTags.Any())
        {
            return(false);
        }

        var dateGameWasAcquired = Timestamp.InZone(TimeExtensions.EasternTimeZone).Date;

        if (masterGame.EarlyAccessReleaseDate.HasValue)
        {
            var plannedForEarlyAccessTag = customCodeTags.SingleOrDefault(x => x.Tag.Name == "PlannedForEarlyAccess");
            if (plannedForEarlyAccessTag is not null)
            {
                if (plannedForEarlyAccessTag.Status == TagStatus.Banned)
                {
                    return(true);
                }
            }

            var currentlyInEarlyAccessTag = customCodeTags.SingleOrDefault(x => x.Tag.Name == "CurrentlyInEarlyAccess");
            if (currentlyInEarlyAccessTag is not null)
            {
                if (currentlyInEarlyAccessTag.Status == TagStatus.Banned)
                {
                    var pickedUpBeforeInEarlyAccess = dateGameWasAcquired < masterGame.EarlyAccessReleaseDate.Value;
                    if (!pickedUpBeforeInEarlyAccess)
                    {
                        return(true);
                    }
                }
            }
        }

        if (masterGame.InternationalReleaseDate.HasValue)
        {
            var willReleaseInternationallyFirstTag = customCodeTags.SingleOrDefault(x => x.Tag.Name == "WillReleaseInternationallyFirst");
            if (willReleaseInternationallyFirstTag is not null)
            {
                if (willReleaseInternationallyFirstTag.Status == TagStatus.Banned)
                {
                    return(true);
                }
            }

            var releasedInternationallyTag = customCodeTags.SingleOrDefault(x => x.Tag.Name == "ReleasedInternationally");
            if (releasedInternationallyTag is not null)
            {
                if (releasedInternationallyTag.Status == TagStatus.Banned)
                {
                    var pickedUpBeforeReleasedInternationally = dateGameWasAcquired < masterGame.InternationalReleaseDate.Value;
                    if (!pickedUpBeforeReleasedInternationally)
                    {
                        return(true);
                    }
                }
            }
        }

        return(false);
    }