public DropResult CanConditionallyDropGame(PickupBid request, LeagueYear leagueYear, Publisher publisher, Instant?nextBidTime) { List <ClaimError> dropErrors = new List <ClaimError>(); var basicErrors = GetBasicErrors(leagueYear.League, publisher); dropErrors.AddRange(basicErrors); var currentDate = _clock.GetToday(); var dateOfPotentialAcquisition = currentDate; if (nextBidTime.HasValue) { dateOfPotentialAcquisition = nextBidTime.Value.ToEasternDate(); } if (request.ConditionalDropPublisherGame?.MasterGame is null) { throw new Exception($"Invalid conditional drop for bid: {request.BidID}"); } var masterGameErrors = GetGenericSlotMasterGameErrors(leagueYear, request.ConditionalDropPublisherGame.MasterGame.MasterGame, leagueYear.Year, true, currentDate, dateOfPotentialAcquisition, false, false, false); dropErrors.AddRange(masterGameErrors); //Drop limits var publisherGame = publisher.GetPublisherGameByPublisherGameID(request.ConditionalDropPublisherGame.PublisherGameID); if (publisherGame is null) { return(new DropResult(Result.Failure("Cannot drop a game that you do not have"))); } if (dropErrors.Any()) { return(new DropResult(Result.Failure("Game is no longer eligible for dropping."))); } bool gameWasDrafted = publisherGame.OverallDraftPosition.HasValue; if (!gameWasDrafted && leagueYear.Options.DropOnlyDraftGames) { return(new DropResult(Result.Failure("You can only drop games that you drafted due to your league settings."))); } var otherPublishers = leagueYear.GetAllPublishersExcept(publisher); bool gameWasCounterPicked = otherPublishers .SelectMany(x => x.PublisherGames) .Where(x => x.CounterPick) .ContainsGame(request.ConditionalDropPublisherGame.MasterGame.MasterGame); if (gameWasCounterPicked && leagueYear.Options.CounterPicksBlockDrops) { return(new DropResult(Result.Failure("You cannot drop that game because it was counter picked."))); } bool gameWillRelease = publisherGame.WillRelease(); var dropResult = publisher.CanDropGame(gameWillRelease, leagueYear.Options); return(new DropResult(dropResult)); }
public DropResult CanDropGame(DropRequest request, LeagueYear leagueYear, Publisher publisher) { List <ClaimError> dropErrors = new List <ClaimError>(); var basicErrors = GetBasicErrors(leagueYear.League, publisher); dropErrors.AddRange(basicErrors); var currentDate = _clock.GetToday(); var masterGameErrors = GetGenericSlotMasterGameErrors(leagueYear, request.MasterGame, leagueYear.Year, true, currentDate, currentDate, false, false, false); dropErrors.AddRange(masterGameErrors); //Drop limits var publisherGame = publisher.GetPublisherGame(request.MasterGame); if (publisherGame is null) { return(new DropResult(Result.Failure("Cannot drop a game that you do not have"))); } if (dropErrors.Any()) { return(new DropResult(Result.Failure("Game is no longer eligible for dropping."))); } bool gameWasDrafted = publisherGame.OverallDraftPosition.HasValue; if (!gameWasDrafted && leagueYear.Options.DropOnlyDraftGames) { return(new DropResult(Result.Failure("You can only drop games that you drafted due to your league settings."))); } var otherPublishers = leagueYear.GetAllPublishersExcept(publisher); bool gameWasCounterPicked = otherPublishers .SelectMany(x => x.PublisherGames) .Where(x => x.CounterPick) .ContainsGame(request.MasterGame); if (gameWasCounterPicked && leagueYear.Options.CounterPicksBlockDrops) { return(new DropResult(Result.Failure("You cannot drop that game because it was counter picked."))); } bool gameWillRelease = publisherGame.WillRelease(); var dropResult = publisher.CanDropGame(gameWillRelease, leagueYear.Options); return(new DropResult(dropResult)); }
public IReadOnlyList <PublisherGame> GetAvailableCounterPicks(LeagueYear leagueYear, Publisher publisherMakingCounterPick) { IReadOnlyList <Publisher> otherPublishers = leagueYear.GetAllPublishersExcept(publisherMakingCounterPick); IReadOnlyList <PublisherGame> gamesForYear = leagueYear.Publishers.SelectMany(x => x.PublisherGames).ToList(); IReadOnlyList <PublisherGame> otherPlayersGames = otherPublishers.SelectMany(x => x.PublisherGames).Where(x => !x.CounterPick).ToList(); var alreadyCounterPicked = gamesForYear.Where(x => x.CounterPick).ToList(); List <PublisherGame> availableCounterPicks = new List <PublisherGame>(); foreach (var otherPlayerGame in otherPlayersGames) { bool playerHasCounterPick = alreadyCounterPicked.ContainsGame(otherPlayerGame); if (playerHasCounterPick) { continue; } availableCounterPicks.Add(otherPlayerGame); } return(availableCounterPicks); }