public async Task <IReadOnlyList <PossibleMasterGameYear> > GetTopAvailableGames(LeagueYear leagueYear, Publisher currentPublisher) { HashSet <MasterGame> publisherMasterGames = leagueYear.Publishers .SelectMany(x => x.PublisherGames) .Where(x => !x.CounterPick && x.MasterGame is not null) .Select(x => x.MasterGame !.MasterGame) .ToHashSet(); HashSet <MasterGame> myPublisherMasterGames = currentPublisher.MyMasterGames; IReadOnlyList <MasterGameYear> masterGames = await _interLeagueService.GetMasterGameYears(leagueYear.Year); IReadOnlyList <MasterGameYear> matchingMasterGames = masterGames.OrderByDescending(x => x.DateAdjustedHypeFactor).ToList(); List <PossibleMasterGameYear> possibleMasterGames = new List <PossibleMasterGameYear>(); var slots = currentPublisher.GetPublisherSlots(leagueYear.Options); var openNonCounterPickSlots = slots.Where(x => !x.CounterPick && x.PublisherGame is null).OrderBy(x => x.SlotNumber).ToList(); LocalDate currentDate = _clock.GetToday(); foreach (var masterGame in matchingMasterGames) { var eligibilityFactors = leagueYear.GetEligibilityFactorsForMasterGame(masterGame.MasterGame, currentDate); PossibleMasterGameYear possibleMasterGame = GetPossibleMasterGameYear(masterGame, openNonCounterPickSlots, publisherMasterGames, myPublisherMasterGames, eligibilityFactors, currentDate); if (!possibleMasterGame.IsAvailable) { continue; } possibleMasterGames.Add(possibleMasterGame); } return(possibleMasterGames); }
public async Task <IReadOnlyList <PossibleMasterGameYear> > GetQueuedPossibleGames(LeagueYear leagueYear, Publisher currentPublisher, IEnumerable <QueuedGame> queuedGames) { HashSet <MasterGame> publisherMasterGames = leagueYear.Publishers .SelectMany(x => x.PublisherGames) .Where(x => !x.CounterPick && x.MasterGame is not null) .Select(x => x.MasterGame !.MasterGame) .ToHashSet(); HashSet <MasterGame> myPublisherMasterGames = currentPublisher.MyMasterGames; IReadOnlyList <MasterGameYear> masterGameYears = await _interLeagueService.GetMasterGameYears(leagueYear.Year); var masterGamesForThisYear = masterGameYears.Where(x => x.Year == leagueYear.Year); var masterGameYearDictionary = masterGamesForThisYear.ToDictionary(x => x.MasterGame.MasterGameID, y => y); var slots = currentPublisher.GetPublisherSlots(leagueYear.Options); var openNonCounterPickSlots = slots.Where(x => !x.CounterPick && x.PublisherGame is null).OrderBy(x => x.SlotNumber).ToList(); List <PossibleMasterGameYear> possibleMasterGames = new List <PossibleMasterGameYear>(); LocalDate currentDate = _clock.GetToday(); foreach (var queuedGame in queuedGames) { var masterGame = masterGameYearDictionary[queuedGame.MasterGame.MasterGameID]; var eligibilityFactors = leagueYear.GetEligibilityFactorsForMasterGame(masterGame.MasterGame, currentDate); PossibleMasterGameYear possibleMasterGame = GetPossibleMasterGameYear(masterGame, openNonCounterPickSlots, publisherMasterGames, myPublisherMasterGames, eligibilityFactors, currentDate); possibleMasterGames.Add(possibleMasterGame); } return(possibleMasterGames); }
public async Task <IReadOnlyList <PossibleMasterGameYear> > SearchGames(string searchName, LeagueYear leagueYear, Publisher currentPublisher, int year) { HashSet <MasterGame> publisherMasterGames = leagueYear.Publishers .SelectMany(x => x.PublisherGames) .Where(x => !x.CounterPick && x.MasterGame is not null) .Select(x => x.MasterGame !.MasterGame) .ToHashSet(); HashSet <MasterGame> myPublisherMasterGames = currentPublisher.MyMasterGames; IReadOnlyList <MasterGameYear> masterGames = await _interLeagueService.GetMasterGameYears(year); IReadOnlyList <MasterGameYear> matchingMasterGames = MasterGameSearching.SearchMasterGameYears(searchName, masterGames); List <PossibleMasterGameYear> possibleMasterGames = new List <PossibleMasterGameYear>(); var slots = currentPublisher.GetPublisherSlots(leagueYear.Options); var openNonCounterPickSlots = slots.Where(x => !x.CounterPick && x.PublisherGame is null).OrderBy(x => x.SlotNumber).ToList(); LocalDate currentDate = _clock.GetToday(); foreach (var masterGame in matchingMasterGames) { var eligibilityFactors = leagueYear.GetEligibilityFactorsForMasterGame(masterGame.MasterGame, currentDate); PossibleMasterGameYear possibleMasterGame = GetPossibleMasterGameYear(masterGame, openNonCounterPickSlots, publisherMasterGames, myPublisherMasterGames, eligibilityFactors, currentDate); possibleMasterGames.Add(possibleMasterGame); } return(possibleMasterGames); }
private IReadOnlyList <ClaimError> GetGenericSlotMasterGameErrors(LeagueYear leagueYear, MasterGame masterGame, int year, bool dropping, LocalDate currentDate, LocalDate dateOfPotentialAcquisition, bool counterPick, bool counterPickedGameIsManualWillNotRelease, bool drafting) { MasterGameWithEligibilityFactors eligibilityFactors = leagueYear.GetEligibilityFactorsForMasterGame(masterGame, dateOfPotentialAcquisition); List <ClaimError> claimErrors = new List <ClaimError>(); bool manuallyEligible = eligibilityFactors.OverridenEligibility.HasValue && eligibilityFactors.OverridenEligibility.Value; bool released = masterGame.IsReleased(currentDate); if (released) { claimErrors.Add(new ClaimError("That game has already been released.", true)); } if (currentDate != dateOfPotentialAcquisition) { bool releaseBeforeNextBids = masterGame.IsReleased(dateOfPotentialAcquisition); if (releaseBeforeNextBids) { if (!dropping) { claimErrors.Add(new ClaimError("That game will release before bids are processed.", true)); } else { claimErrors.Add(new ClaimError("That game will release before drops are processed.", true)); } } } if (released && masterGame.ReleaseDate.HasValue && masterGame.ReleaseDate.Value.Year < year) { claimErrors.Add(new ClaimError($"That game was released prior to the start of {year}.", false)); } bool willRelease = masterGame.MinimumReleaseDate.Year == year && !counterPickedGameIsManualWillNotRelease; if (!dropping && !released && !willRelease && !manuallyEligible) { claimErrors.Add(new ClaimError($"That game is not scheduled to be released in {year}.", true)); } if (counterPick && !drafting) { if (masterGame.DelayContention) { claimErrors.Add(new ClaimError("That game is in 'delay contention', and therefore cannot be counter picked.", false)); } bool confirmedWillRelease = masterGame.ReleaseDate.HasValue && masterGame.ReleaseDate.Value.Year == year; bool acquiringAfterDeadline = dateOfPotentialAcquisition >= leagueYear.CounterPickDeadline; if (!confirmedWillRelease && acquiringAfterDeadline && willRelease) { claimErrors.Add(new ClaimError($"That game does not have a confirmed release date in {year}, and the 'counter pick deadline' has already passed (or will have by the time bids process).", false)); } } bool hasScore = masterGame.CriticScore.HasValue; if (hasScore && !manuallyEligible) { claimErrors.Add(new ClaimError("That game already has a score.", true)); } return(claimErrors); }
public Result <IReadOnlyList <PublisherGame> > GetNewPublisherGamesFromTrade(Instant completionTime) { var dateOfAcquisition = completionTime.ToEasternDate(); var proposerGameDictionary = Proposer.PublisherGames.Where(x => x.MasterGame is not null).ToDictionary(x => x.GetMasterGameYearWithCounterPick() !); var counterPartyGameDictionary = CounterParty.PublisherGames.Where(x => x.MasterGame is not null).ToDictionary(x => x.GetMasterGameYearWithCounterPick() !); List <PotentialPublisherSlot> newlyOpenProposerSlotNumbers = new List <PotentialPublisherSlot>(); foreach (var game in ProposerMasterGames) { var existingPublisherGame = proposerGameDictionary[game]; newlyOpenProposerSlotNumbers.Add(new PotentialPublisherSlot(existingPublisherGame.SlotNumber, game.CounterPick)); } List <PotentialPublisherSlot> newlyOpenCounterPartySlotNumbers = new List <PotentialPublisherSlot>(); foreach (var game in CounterPartyMasterGames) { var existingPublisherGame = counterPartyGameDictionary[game]; newlyOpenCounterPartySlotNumbers.Add(new PotentialPublisherSlot(existingPublisherGame.SlotNumber, game.CounterPick)); } var alreadyOpenProposerSlotNumbers = Proposer.GetPublisherSlots(LeagueYear.Options).Where(x => x.PublisherGame is null).Select(x => new PotentialPublisherSlot(x.SlotNumber, x.CounterPick)); var alreadyOpenCounterPartySlotNumbers = CounterParty.GetPublisherSlots(LeagueYear.Options).Where(x => x.PublisherGame is null).Select(x => new PotentialPublisherSlot(x.SlotNumber, x.CounterPick)); var allOpenProposerSlotNumbers = alreadyOpenProposerSlotNumbers.Concat(newlyOpenProposerSlotNumbers).Distinct().OrderBy(x => x.CounterPick).ThenBy(x => x.SlotNumber).ToList(); var allOpenCounterPartySlotNumbers = alreadyOpenCounterPartySlotNumbers.Concat(newlyOpenCounterPartySlotNumbers).Distinct().OrderBy(x => x.CounterPick).ThenBy(x => x.SlotNumber).ToList(); List <PublisherGame> newPublisherGames = new List <PublisherGame>(); foreach (var game in ProposerMasterGames) { var existingPublisherGame = proposerGameDictionary[game]; var eligibilityFactors = LeagueYear.GetEligibilityFactorsForMasterGame(game.MasterGameYear.MasterGame, dateOfAcquisition); var openSlotNumbers = allOpenCounterPartySlotNumbers.Where(x => x.CounterPick == game.CounterPick).Select(x => x.SlotNumber); var slotResult = SlotEligibilityService.GetTradeSlotResult(CounterParty, LeagueYear.Options, game, eligibilityFactors, openSlotNumbers); if (!slotResult.HasValue) { return(Result.Failure <IReadOnlyList <PublisherGame> >($"Cannot find an appropriate slot for: {game.MasterGameYear.MasterGame.GameName}")); } allOpenCounterPartySlotNumbers = allOpenCounterPartySlotNumbers.Where(x => !(x.SlotNumber == slotResult.Value && x.CounterPick == game.CounterPick)).ToList(); PublisherGame newPublisherGame = new PublisherGame(CounterParty.PublisherID, Guid.NewGuid(), game.MasterGameYear.MasterGame.GameName, completionTime, game.CounterPick, existingPublisherGame.ManualCriticScore, existingPublisherGame.ManualWillNotRelease, existingPublisherGame.FantasyPoints, game.MasterGameYear, slotResult.Value, null, null, null, TradeID); newPublisherGames.Add(newPublisherGame); } foreach (var game in CounterPartyMasterGames) { var existingPublisherGame = counterPartyGameDictionary[game]; var eligibilityFactors = LeagueYear.GetEligibilityFactorsForMasterGame(game.MasterGameYear.MasterGame, dateOfAcquisition); var openSlotNumbers = allOpenProposerSlotNumbers.Where(x => x.CounterPick == game.CounterPick).Select(x => x.SlotNumber); var slotResult = SlotEligibilityService.GetTradeSlotResult(Proposer, LeagueYear.Options, game, eligibilityFactors, openSlotNumbers); if (!slotResult.HasValue) { return(Result.Failure <IReadOnlyList <PublisherGame> >($"Cannot find an appropriate slot for: {game.MasterGameYear.MasterGame.GameName}")); } allOpenProposerSlotNumbers = allOpenProposerSlotNumbers.Where(x => !(x.SlotNumber == slotResult.Value && x.CounterPick == game.CounterPick)).ToList(); PublisherGame newPublisherGame = new PublisherGame(Proposer.PublisherID, Guid.NewGuid(), game.MasterGameYear.MasterGame.GameName, completionTime, game.CounterPick, existingPublisherGame.ManualCriticScore, existingPublisherGame.ManualWillNotRelease, existingPublisherGame.FantasyPoints, game.MasterGameYear, slotResult.Value, null, null, null, TradeID); newPublisherGames.Add(newPublisherGame); } return(newPublisherGames); }