Exemplo n.º 1
0
    public async Task <ClaimResult> PurchaseGame(RoyalePublisher publisher, MasterGameYear masterGame)
    {
        if (publisher.PublisherGames.Count >= MAX_GAMES)
        {
            return(new ClaimResult("Roster is full.", null));
        }
        if (publisher.PublisherGames.Select(x => x.MasterGame).Contains(masterGame))
        {
            return(new ClaimResult("Publisher already has that game.", null));
        }
        if (!masterGame.WillReleaseInQuarter(publisher.YearQuarter.YearQuarter))
        {
            return(new ClaimResult("Game will not release this quarter.", null));
        }

        var now         = _clock.GetCurrentInstant();
        var currentDate = now.ToEasternDate();

        if (masterGame.MasterGame.IsReleased(currentDate))
        {
            return(new ClaimResult("Game has been released.", null));
        }
        if (masterGame.MasterGame.CriticScore.HasValue)
        {
            return(new ClaimResult("Game has a score.", null));
        }

        var masterGameTags = await _masterGameRepo.GetMasterGameTags();

        var eligibilityErrors = LeagueTagExtensions.GetRoyaleClaimErrors(masterGameTags, masterGame.MasterGame, currentDate);

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

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

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

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

        var nextSlot = publisher.PublisherGames.Count;

        return(new ClaimResult(nextSlot));
    }
Exemplo n.º 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 eligibilityErrors = EligibilitySettings.GetRoyaleEligibilitySettings().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());
        }