Пример #1
0
    public LeagueYearEntity(League league, int year, LeagueOptions options, PlayStatus playStatus)
    {
        LeagueID = league.LeagueID;
        Year     = year;

        StandardGames                = options.StandardGames;
        GamesToDraft                 = options.GamesToDraft;
        CounterPicks                 = options.CounterPicks;
        CounterPicksToDraft          = options.CounterPicksToDraft;
        FreeDroppableGames           = options.FreeDroppableGames;
        WillNotReleaseDroppableGames = options.WillNotReleaseDroppableGames;
        WillReleaseDroppableGames    = options.WillReleaseDroppableGames;
        DropOnlyDraftGames           = options.DropOnlyDraftGames;
        CounterPicksBlockDrops       = options.CounterPicksBlockDrops;
        MinimumBidAmount             = options.MinimumBidAmount;
        CounterPickDeadlineMonth     = options.CounterPickDeadline.Month;
        CounterPickDeadlineDay       = options.CounterPickDeadline.Day;

        DraftSystem    = options.DraftSystem.Value;
        PickupSystem   = options.PickupSystem.Value;
        TiebreakSystem = options.TiebreakSystem.Value;
        ScoringSystem  = options.ScoringSystem.Name;
        TradingSystem  = options.TradingSystem.Value;
        PlayStatus     = playStatus.Value;
    }
Пример #2
0
        public LeagueYearEntity(League league, int year, LeagueOptions options, PlayStatus playStatus)
        {
            LeagueID = league.LeagueID;
            Year     = year;

            StandardGames                = options.StandardGames;
            GamesToDraft                 = options.GamesToDraft;
            CounterPicks                 = options.CounterPicks;
            FreeDroppableGames           = options.FreeDroppableGames;
            WillNotReleaseDroppableGames = options.WillNotReleaseDroppableGames;
            WillReleaseDroppableGames    = options.WillReleaseDroppableGames;
            DropOnlyDraftGames           = options.DropOnlyDraftGames;

            MaximumEligibilityLevel      = options.AllowedEligibilitySettings.EligibilityLevel.Level;
            AllowYearlyInstallments      = options.AllowedEligibilitySettings.YearlyInstallment;
            AllowEarlyAccess             = options.AllowedEligibilitySettings.EarlyAccess;
            AllowFreeToPlay              = options.AllowedEligibilitySettings.FreeToPlay;
            AllowReleasedInternationally = options.AllowedEligibilitySettings.ReleasedInternationally;
            AllowExpansions              = options.AllowedEligibilitySettings.ExpansionPack;

            DraftSystem   = options.DraftSystem.Value;
            PickupSystem  = options.PickupSystem.Value;
            ScoringSystem = options.ScoringSystem.Name;
            PlayStatus    = playStatus.Value;
        }
        public SeasonStatsModel(SeasonStatsParameters seasonParameters)
        {
            _seasonStatsParameters = seasonParameters;
            _database = new BeaujeauxEntities();

            // League
            LeagueOptions  = _database.Leagues.ToList();
            SelectedLeague = LeagueOptions.Where(s => s.Id == _seasonStatsParameters.leagueId).FirstOrDefault();
            SelectedLeague = SelectedLeague ?? LeagueOptions.FirstOrDefault();

            // All Seasons for the League
            var _seasons = _database.Seasons
                           .Where(s => s.LeagueId == SelectedLeague.Id);

            SelectedLeagueEra = seasonParameters.leagueEra;

            SetSeasonNumberOptions();
            SetSeasonTypeOptions(_seasons);
            SetSelectedSeasonType(_seasonStatsParameters.seasonTypeId);
            SetSelectedSeason(_seasonStatsParameters.seasonNumber);
            SetTeamOptions(_seasons);
            SetSelectedTeam(_seasonStatsParameters.teamId);
            SetPageNumberInfo(seasonParameters.pageNumber);

            SetStatsForPage();
            TotalPages = GetTotalPageCount();
            BoundCurrentPage();
        }
    public PublisherSlotRequirementsViewModel(LeagueOptions options)
    {
        RegularSlot = new PublisherSingleSlotRequirementsViewModel(options.LeagueTags);
        if (!options.HasSpecialSlots)
        {
            OverallSlot  = RegularSlot;
            SpecialSlots = new List <PublisherSingleSlotRequirementsViewModel>();
        }
        else
        {
            var distinctSpecialSlots    = options.SpecialGameSlots.DistinctBy(x => string.Join(",", x.Tags.OrderBy(x => x.Name))).ToList();
            var specialSlotRequiredTags = distinctSpecialSlots.SelectMany(x => x.Tags.Select(y => y.Name)).Distinct().ToList();
            var regularBannedTags       = options.LeagueTags.Where(x => x.Status.Equals(TagStatus.Banned)).Select(x => x.Tag.Name).ToList();
            var overallBannedTags       = regularBannedTags.Except(specialSlotRequiredTags).ToList();
            OverallSlot = new PublisherSingleSlotRequirementsViewModel(overallBannedTags);

            var specialSlots = new List <PublisherSingleSlotRequirementsViewModel>();
            foreach (var specialSlot in distinctSpecialSlots)
            {
                var specialSlotTags = options.LeagueTags.ToList();
                specialSlotTags.AddRange(specialSlot.Tags.Select(x => new LeagueTagStatus(x, TagStatus.Required)));
                specialSlots.Add(new PublisherSingleSlotRequirementsViewModel(specialSlotTags));
            }

            SpecialSlots = specialSlots;
        }
    }
Пример #5
0
    public Result CanDropGame(bool willRelease, LeagueOptions leagueOptions)
    {
        if (willRelease)
        {
            if (leagueOptions.WillReleaseDroppableGames == -1 || leagueOptions.WillReleaseDroppableGames > WillReleaseGamesDropped)
            {
                return(Result.Success());
            }
            if (leagueOptions.FreeDroppableGames == -1 || leagueOptions.FreeDroppableGames > FreeGamesDropped)
            {
                return(Result.Success());
            }
            return(Result.Failure("Publisher cannot drop any more 'Will Release' games"));
        }

        if (leagueOptions.WillNotReleaseDroppableGames == -1 || leagueOptions.WillNotReleaseDroppableGames > WillNotReleaseGamesDropped)
        {
            return(Result.Success());
        }
        if (leagueOptions.FreeDroppableGames == -1 || leagueOptions.FreeDroppableGames > FreeGamesDropped)
        {
            return(Result.Success());
        }
        return(Result.Failure("Publisher cannot drop any more 'Will Not Release' games"));
    }
Пример #6
0
        public SettingsViewModel(IUILanguageProvider uiLanguageProvider,
                                 SidekickSettings sidekickSettings,
                                 INativeKeyboard nativeKeyboard,
                                 ILeagueDataService leagueDataService,
                                 IKeybindEvents keybindEvents)
        {
            this.uiLanguageProvider = uiLanguageProvider;
            this.sidekickSettings   = sidekickSettings;
            this.nativeKeyboard     = nativeKeyboard;
            this.keybindEvents      = keybindEvents;
            this.leagueDataService  = leagueDataService;

            Settings = new SidekickSettings();
            AssignValues(sidekickSettings, Settings);

            Keybinds.Clear();
            Settings.GetType()
            .GetProperties()
            .Where(x => x.Name.StartsWith("Key"))
            .ToList()
            .ForEach(x => Keybinds.Add(x.Name, x.GetValue(Settings).ToString()));

            WikiOptions.Add("POE Wiki", WikiSetting.PoeWiki.ToString());
            WikiOptions.Add("POE Db", WikiSetting.PoeDb.ToString());
            this.leagueDataService.Leagues.ForEach(x => LeagueOptions.Add(x.Id, x.Text));
            uiLanguageProvider.AvailableLanguages.ForEach(x => UILanguageOptions.Add(x.NativeName.First().ToString().ToUpper() + x.NativeName.Substring(1), x.Name));

            nativeKeyboard.OnKeyDown += NativeKeyboard_OnKeyDown;
        }
    public static int?GetTradeSlotResult(Publisher publisher, LeagueOptions leagueOptions, MasterGameYearWithCounterPick masterGameYearWithCounterPick, MasterGameWithEligibilityFactors eligibilityFactors, IEnumerable <int> openSlotNumbers)
    {
        var slots     = publisher.GetPublisherSlots(leagueOptions);
        var openSlots = slots.Where(x => x.CounterPick == masterGameYearWithCounterPick.CounterPick && openSlotNumbers.Contains(x.SlotNumber)).OrderBy(x => x.SlotNumber).ToList();

        if (!openSlots.Any())
        {
            return(null);
        }

        //At this point, there is an open slot. Which one is best?
        //We want to check the special slots first, then the regular slots.
        var openSpotsToCheckOrder = openSlots
                                    .OrderByDescending(x => x.SpecialGameSlot is not null)
                                    .ThenBy(x => x.SlotNumber).ToList();

        foreach (var openSlot in openSpotsToCheckOrder)
        {
            var claimErrorsForSlot = GetClaimErrorsForSlot(openSlot, eligibilityFactors);
            if (!claimErrorsForSlot.Any())
            {
                return(openSlot.SlotNumber);
            }
        }

        //This game isn't eligible in any slots, so we will just take the first open one.
        var bestSlot = openSlots.First();

        return(bestSlot.SlotNumber);
    }
    public async Task <Result <League> > CreateLeague(LeagueCreationParameters parameters)
    {
        LeagueOptions options = new LeagueOptions(parameters.LeagueYearParameters);

        var validateOptions = options.Validate();

        if (validateOptions.IsFailure)
        {
            return(Result.Failure <League>(validateOptions.Error));
        }

        if (parameters.LeagueYearParameters.ScoringSystem.Name != DiminishingScoringSystem.StaticName)
        {
            return(Result.Failure <League>("That scoring mode is no longer supported."));
        }

        IEnumerable <int> years = new List <int>()
        {
            parameters.LeagueYearParameters.Year
        };
        League newLeague = new League(Guid.NewGuid(), parameters.LeagueName, parameters.Manager, years, parameters.PublicLeague, parameters.TestLeague, false, 0);
        await _fantasyCriticRepo.CreateLeague(newLeague, parameters.LeagueYearParameters.Year, options);

        return(Result.Success(newLeague));
    }
Пример #9
0
    public LeagueOptions UpdateOptionsForYear(int requestYear)
    {
        var           newScoringSystem = ScoringSystem.GetDefaultScoringSystem(requestYear);
        LeagueOptions options          = new LeagueOptions(StandardGames, GamesToDraft, CounterPicks, CounterPicksToDraft, FreeDroppableGames, WillNotReleaseDroppableGames, WillReleaseDroppableGames,
                                                           DropOnlyDraftGames, CounterPicksBlockDrops, MinimumBidAmount, LeagueTags, SpecialGameSlots, DraftSystem, PickupSystem, newScoringSystem, TradingSystem, TiebreakSystem, CounterPickDeadline);

        return(options);
    }
Пример #10
0
        public async Task AddNewLeagueYear(League league, int year, LeagueOptions options, LeagueYear mostRecentLeagueYear)
        {
            await _fantasyCriticRepo.AddNewLeagueYear(league, year, options);

            var mostRecentActivePlayers = await _fantasyCriticRepo.GetActivePlayersForLeagueYear(league, mostRecentLeagueYear.Year);

            await _fantasyCriticRepo.SetPlayersActive(league, year, mostRecentActivePlayers);
        }
Пример #11
0
 public MasterGameWithEligibilityFactors(MasterGame masterGame, LeagueOptions options, bool?overridenEligibility,
                                         IReadOnlyList <MasterGameTag> tagOverrides, LocalDate dateAcquired)
 {
     MasterGame           = masterGame;
     Options              = options;
     OverridenEligibility = overridenEligibility;
     TagOverrides         = tagOverrides;
     DateAcquired         = dateAcquired;
 }
 public PlayerWithPublisherViewModel(LeagueYear leagueYear, FantasyCriticUser user, Publisher publisher, IClock clock,
                                     LeagueOptions options, SystemWideValues systemWideValues, bool userIsInLeague, bool userIsInvitedToLeague,
                                     SupportedYear supportedYear, bool removable)
 {
     User                           = new PlayerViewModel(leagueYear.League, user, removable);
     Publisher                      = new PublisherViewModel(publisher, clock, userIsInLeague, userIsInvitedToLeague, systemWideValues, supportedYear.Finished);
     TotalFantasyPoints             = publisher.TotalFantasyPoints;
     SimpleProjectedFantasyPoints   = publisher.GetProjectedFantasyPoints(options, systemWideValues, supportedYear.Finished, true, clock);
     AdvancedProjectedFantasyPoints = publisher.GetProjectedFantasyPoints(options, systemWideValues, supportedYear.Finished, false, clock);
 }
Пример #13
0
        public async Task <Result> EditLeague(League league, EditLeagueYearParameters parameters)
        {
            LeagueOptions options         = new LeagueOptions(parameters);
            var           validateOptions = options.Validate();

            if (validateOptions.IsFailure)
            {
                return(Result.Failure(validateOptions.Error));
            }

            var leagueYear = await GetLeagueYear(league.LeagueID, parameters.Year);

            if (leagueYear.HasNoValue)
            {
                throw new Exception($"League year cannot be found: {parameters.LeagueID}|{parameters.Year}");
            }

            IReadOnlyList <Publisher> publishers = await _publisherService.GetPublishersInLeagueForYear(leagueYear.Value);

            int maxStandardGames = publishers.Select(publisher => publisher.PublisherGames.Count(x => !x.CounterPick)).DefaultIfEmpty(0).Max();
            int maxCounterPicks  = publishers.Select(publisher => publisher.PublisherGames.Count(x => x.CounterPick)).DefaultIfEmpty(0).Max();

            if (maxStandardGames > options.StandardGames)
            {
                return(Result.Failure($"Cannot reduce number of standard games to {options.StandardGames} as a publisher has {maxStandardGames} draft games currently."));
            }
            if (maxCounterPicks > options.CounterPicks)
            {
                return(Result.Failure($"Cannot reduce number of counter picks to {options.CounterPicks} as a publisher has {maxCounterPicks} counter picks currently."));
            }

            int maxFreeGamesFreeDropped       = publishers.Select(publisher => publisher.FreeGamesDropped).DefaultIfEmpty(0).Max();
            int maxWillNotReleaseGamesDropped = publishers.Select(publisher => publisher.WillNotReleaseGamesDropped).DefaultIfEmpty(0).Max();
            int maxWillReleaseGamesDropped    = publishers.Select(publisher => publisher.WillReleaseGamesDropped).DefaultIfEmpty(0).Max();

            if (maxFreeGamesFreeDropped > options.FreeDroppableGames && options.FreeDroppableGames != -1)
            {
                return(Result.Failure($"Cannot reduce number of unrestricted droppable games to {options.FreeDroppableGames} as a publisher has already dropped {maxFreeGamesFreeDropped} games."));
            }
            if (maxWillNotReleaseGamesDropped > options.WillNotReleaseDroppableGames && options.WillNotReleaseDroppableGames != -1)
            {
                return(Result.Failure($"Cannot reduce number of 'will not release' droppable games to {options.WillNotReleaseDroppableGames} as a publisher has already dropped {maxWillNotReleaseGamesDropped} games."));
            }
            if (maxWillReleaseGamesDropped > options.WillReleaseDroppableGames && options.WillReleaseDroppableGames != -1)
            {
                return(Result.Failure($"Cannot reduce number of 'will release' droppable games to {options.WillReleaseDroppableGames} as a publisher has already dropped {maxWillReleaseGamesDropped} games."));
            }

            var eligibilityOverrides = await GetEligibilityOverrides(league, parameters.Year);

            LeagueYear newLeagueYear = new LeagueYear(league, parameters.Year, options, leagueYear.Value.PlayStatus, eligibilityOverrides);
            await _fantasyCriticRepo.EditLeagueYear(newLeagueYear);

            return(Result.Success());
        }
Пример #14
0
        public LeagueYear ToDomain(League league, EligibilityLevel maximumEligibilityLevel)
        {
            DraftSystem   draftSystem   = Lib.Enums.DraftSystem.FromValue(DraftSystem);
            PickupSystem  pickupSystem  = Lib.Enums.PickupSystem.FromValue(PickupSystem);
            ScoringSystem scoringSystem = Lib.Domain.ScoringSystems.ScoringSystem.GetScoringSystem(ScoringSystem);

            LeagueOptions options = new LeagueOptions(StandardGames, GamesToDraft, CounterPicks,
                                                      maximumEligibilityLevel, AllowYearlyInstallments, AllowEarlyAccess, draftSystem, pickupSystem, scoringSystem);

            return(new LeagueYear(league, Year, options, Lib.Enums.PlayStatus.FromValue(PlayStatus)));
        }
Пример #15
0
    public decimal GetTotalFantasyPoints(SupportedYear year, LeagueOptions leagueOptions)
    {
        var emptyCounterPickSlotPoints = GetEmptyCounterPickSlotPoints(year, leagueOptions) ?? 0m;
        var score = PublisherGames.Sum(x => x.FantasyPoints);

        if (!score.HasValue)
        {
            return(emptyCounterPickSlotPoints);
        }

        return(score.Value + emptyCounterPickSlotPoints);
    }
        private IReadOnlyList <ClaimError> GetMasterGameErrors(LeagueOptions yearOptions, MasterGame masterGame, int year, bool counterPick)
        {
            List <ClaimError> claimErrors = new List <ClaimError>();

            bool eligible = masterGame.IsEligible(yearOptions.MaximumEligibilityLevel);

            if (!eligible)
            {
                claimErrors.Add(new ClaimError("That game is not eligible under this league's settings.", true));
            }

            bool earlyAccessEligible = (!masterGame.EarlyAccess || yearOptions.AllowEarlyAccess);

            if (!earlyAccessEligible)
            {
                claimErrors.Add(new ClaimError("That game is not eligible under this league's early access settings.", true));
            }

            bool yearlyInstallmentEligible = (!masterGame.YearlyInstallment || yearOptions.AllowYearlyInstallments);

            if (!yearlyInstallmentEligible)
            {
                claimErrors.Add(new ClaimError("That game is not eligible under this league's yearly installment settings.", true));
            }

            bool released = masterGame.IsReleased(_clock);

            if (released)
            {
                claimErrors.Add(new ClaimError("That game has already been released.", true));
            }

            if (masterGame.ReleaseDate.HasValue)
            {
                if (released && masterGame.ReleaseDate.Value.Year < year)
                {
                    claimErrors.Add(new ClaimError($"That game was released prior to the start of {year}.", false));
                }
                else if (!released && masterGame.ReleaseDate.Value.Year > year && !counterPick)
                {
                    claimErrors.Add(new ClaimError($"That game is not scheduled to be released in {year}.", true));
                }
            }

            bool hasScore = masterGame.CriticScore.HasValue;

            if (hasScore)
            {
                claimErrors.Add(new ClaimError("That game already has a score.", true));
            }

            return(claimErrors);
        }
Пример #17
0
        public async Task AddNewLeagueYear(League league, int year, LeagueOptions options)
        {
            LeagueYearEntity leagueYearEntity = new LeagueYearEntity(league, year, options, PlayStatus.NotStartedDraft);

            using (var connection = new MySqlConnection(_connectionString))
            {
                await connection.ExecuteAsync(
                    "insert into tblleagueyear(LeagueID,Year,StandardGames,GamesToDraft,CounterPicks,MaximumEligibilityLevel,AllowYearlyInstallments,AllowEarlyAccess,DraftSystem,PickupSystem,ScoringSystem,PlayStatus) VALUES " +
                    "(@LeagueID,@Year,@StandardGames,@GamesToDraft,@CounterPicks,@MaximumEligibilityLevel,@AllowYearlyInstallments,@AllowEarlyAccess,@DraftSystem,@PickupSystem,@ScoringSystem,@PlayStatus);",
                    leagueYearEntity);
            }
        }
Пример #18
0
        public LeagueYear ToDomain(League league, EligibilityLevel maximumEligibilityLevel, IEnumerable <EligibilityOverride> eligibilityOverrides)
        {
            DraftSystem   draftSystem         = Lib.Enums.DraftSystem.FromValue(DraftSystem);
            PickupSystem  pickupSystem        = Lib.Enums.PickupSystem.FromValue(PickupSystem);
            ScoringSystem scoringSystem       = Lib.Domain.ScoringSystems.ScoringSystem.GetScoringSystem(ScoringSystem);
            var           eligibilitySettings = new EligibilitySettings(maximumEligibilityLevel, AllowYearlyInstallments, AllowEarlyAccess,
                                                                        AllowFreeToPlay, AllowReleasedInternationally, AllowExpansions);

            LeagueOptions options = new LeagueOptions(StandardGames, GamesToDraft, CounterPicks, FreeDroppableGames, WillNotReleaseDroppableGames, WillReleaseDroppableGames,
                                                      DropOnlyDraftGames, eligibilitySettings, draftSystem, pickupSystem, scoringSystem, league.PublicLeague);

            return(new LeagueYear(league, Year, options, Lib.Enums.PlayStatus.FromValue(PlayStatus), eligibilityOverrides));
        }
Пример #19
0
        public LeagueYearEntity(League league, int year, LeagueOptions options, PlayStatus playStatus)
        {
            LeagueID = league.LeagueID;
            Year     = year;

            StandardGames = options.StandardGames;
            GamesToDraft  = options.GamesToDraft;
            CounterPicks  = options.CounterPicks;

            MaximumEligibilityLevel = options.MaximumEligibilityLevel.Level;
            AllowYearlyInstallments = options.AllowYearlyInstallments;
            AllowEarlyAccess        = options.AllowEarlyAccess;
            DraftSystem             = options.DraftSystem.Value;
            PickupSystem            = options.PickupSystem.Value;
            ScoringSystem           = options.ScoringSystem.Name;
            PlayStatus = playStatus.Value;
        }
Пример #20
0
    public LeagueYear ToDomain(League league, SupportedYear year, IEnumerable <EligibilityOverride> eligibilityOverrides,
                               IEnumerable <TagOverride> tagOverrides, IEnumerable <LeagueTagStatus> leagueTags, IEnumerable <SpecialGameSlot> specialGameSlots,
                               FantasyCriticUser?winningUser, IEnumerable <Publisher> publishersInLeague)
    {
        DraftSystem    draftSystem    = Lib.Enums.DraftSystem.FromValue(DraftSystem);
        PickupSystem   pickupSystem   = Lib.Enums.PickupSystem.FromValue(PickupSystem);
        TradingSystem  tradingSystem  = Lib.Enums.TradingSystem.FromValue(TradingSystem);
        TiebreakSystem tiebreakSystem = Lib.Enums.TiebreakSystem.FromValue(TiebreakSystem);
        ScoringSystem  scoringSystem  = Lib.Domain.ScoringSystems.ScoringSystem.GetScoringSystem(ScoringSystem);

        AnnualDate counterPickDeadline = new AnnualDate(CounterPickDeadlineMonth, CounterPickDeadlineDay);

        LeagueOptions options = new LeagueOptions(StandardGames, GamesToDraft, CounterPicks, CounterPicksToDraft, FreeDroppableGames, WillNotReleaseDroppableGames, WillReleaseDroppableGames,
                                                  DropOnlyDraftGames, CounterPicksBlockDrops, MinimumBidAmount, leagueTags, specialGameSlots, draftSystem, pickupSystem, scoringSystem, tradingSystem, tiebreakSystem, counterPickDeadline);

        return(new LeagueYear(league, year, options, Lib.Enums.PlayStatus.FromValue(PlayStatus), eligibilityOverrides, tagOverrides, DraftStartedTimestamp, winningUser, publishersInLeague));
    }
Пример #21
0
        public LeagueYear ToDomain(League league, IEnumerable <EligibilityOverride> eligibilityOverrides, IEnumerable <LeagueTagStatus> leagueTags)
        {
            DraftSystem   draftSystem   = Lib.Enums.DraftSystem.FromValue(DraftSystem);
            PickupSystem  pickupSystem  = Lib.Enums.PickupSystem.FromValue(PickupSystem);
            ScoringSystem scoringSystem = Lib.Domain.ScoringSystems.ScoringSystem.GetScoringSystem(ScoringSystem);

            LeagueOptions options = new LeagueOptions(StandardGames, GamesToDraft, CounterPicks, FreeDroppableGames, WillNotReleaseDroppableGames, WillReleaseDroppableGames,
                                                      DropOnlyDraftGames, CounterPicksBlockDrops, MinimumBidAmount, leagueTags, draftSystem, pickupSystem, scoringSystem, league.PublicLeague);

            Instant?draftStartedTimestamp = null;

            if (DraftStartedTimestamp.HasValue)
            {
                draftStartedTimestamp = Instant.FromDateTimeUtc(DraftStartedTimestamp.Value);
            }

            return(new LeagueYear(league, Year, options, Lib.Enums.PlayStatus.FromValue(PlayStatus), eligibilityOverrides, draftStartedTimestamp));
        }
Пример #22
0
    private decimal?GetEmptyCounterPickSlotPoints(SupportedYear year, LeagueOptions leagueOptions)
    {
        if (!SupportedYear.Year2022FeatureSupported(year.Year))
        {
            return(0m);
        }

        if (!year.Finished)
        {
            return(null);
        }

        var expectedNumberOfCounterPicks = leagueOptions.CounterPicks;
        var numberCounterPicks           = PublisherGames.Count(x => x.CounterPick);
        var emptySlots = expectedNumberOfCounterPicks - numberCounterPicks;
        var points     = emptySlots * -15m;

        return(points);
    }
Пример #23
0
    public LeagueYear(League league, SupportedYear year, LeagueOptions options, PlayStatus playStatus,
                      IEnumerable <EligibilityOverride> eligibilityOverrides, IEnumerable <TagOverride> tagOverrides,
                      Instant?draftStartedTimestamp, FantasyCriticUser?winningUser, IEnumerable <Publisher> publishers)
    {
        League                          = league;
        SupportedYear                   = year;
        Options                         = options;
        PlayStatus                      = playStatus;
        EligibilityOverrides            = eligibilityOverrides.ToList();
        _eligibilityOverridesDictionary = EligibilityOverrides.ToDictionary(x => x.MasterGame);
        TagOverrides                    = tagOverrides.ToList();
        _tagOverridesDictionary         = TagOverrides.ToDictionary(x => x.MasterGame);
        DraftStartedTimestamp           = draftStartedTimestamp;
        WinningUser                     = winningUser;

        _publisherDictionary = publishers.ToDictionary(x => x.PublisherID);
        _managerPublisher    = Publishers.SingleOrDefault(x => x.User.Id == league.LeagueManager.Id);
        StandardGamesTaken   = _publisherDictionary.Values.SelectMany(x => x.PublisherGames).Count(x => !x.CounterPick);
    }
Пример #24
0
        public async Task <Result <League> > CreateLeague(LeagueCreationParameters parameters)
        {
            LeagueOptions options = new LeagueOptions(parameters);

            var validateOptions = options.Validate();

            if (validateOptions.IsFailure)
            {
                return(Result.Failure <League>(validateOptions.Error));
            }

            IEnumerable <int> years = new List <int>()
            {
                parameters.InitialYear
            };
            League newLeague = new League(Guid.NewGuid(), parameters.LeagueName, parameters.Manager, years, parameters.PublicLeague, parameters.TestLeague, 0);
            await _fantasyCriticRepo.CreateLeague(newLeague, parameters.InitialYear, options);

            return(Result.Success(newLeague));
        }
        public async Task <Result> EditLeague(League league, EditLeagueYearParameters parameters)
        {
            LeagueOptions options         = new LeagueOptions(parameters);
            var           validateOptions = options.Validate();

            if (validateOptions.IsFailure)
            {
                return(Result.Fail(validateOptions.Error));
            }

            var leagueYear = await GetLeagueYear(league.LeagueID, parameters.Year);

            if (leagueYear.HasNoValue)
            {
                throw new Exception($"League year cannot be found: {parameters.LeagueID}|{parameters.Year}");
            }

            IReadOnlyList <Publisher> publishers = await GetPublishersInLeagueForYear(league, parameters.Year);

            int maxStandardGames = publishers.Select(publisher => publisher.PublisherGames.Count(x => !x.CounterPick)).DefaultIfEmpty(0).Max();
            int maxCounterPicks  = publishers.Select(publisher => publisher.PublisherGames.Count(x => x.CounterPick)).DefaultIfEmpty(0).Max();

            if (maxStandardGames > options.StandardGames)
            {
                return(Result.Fail($"Cannot reduce number of standard games to {options.StandardGames} as a publisher has {maxStandardGames} draft games currently."));
            }
            if (maxCounterPicks > options.CounterPicks)
            {
                return(Result.Fail($"Cannot reduce number of counter picks to {options.CounterPicks} as a publisher has {maxCounterPicks} counter picks currently."));
            }

            LeagueYear newLeagueYear = new LeagueYear(league, parameters.Year, options, leagueYear.Value.PlayStatus);
            await _fantasyCriticRepo.EditLeagueYear(newLeagueYear);

            return(Result.Ok());
        }
Пример #26
0
    public IReadOnlyList <PublisherSlot> GetPublisherSlots(LeagueOptions leagueOptions)
    {
        List <PublisherSlot> publisherSlots = new List <PublisherSlot>();

        int overallSlotNumber   = 0;
        var standardGamesBySlot = PublisherGames.Where(x => !x.CounterPick).ToDictionary(x => x.SlotNumber);

        for (int standardGameIndex = 0; standardGameIndex < leagueOptions.StandardGames; standardGameIndex++)
        {
            PublisherGame?standardGame = null;
            if (standardGamesBySlot.TryGetValue(standardGameIndex, out var foundGame))
            {
                standardGame = foundGame;
            }
            SpecialGameSlot?specialSlot = leagueOptions.GetSpecialGameSlotByOverallSlotNumber(standardGameIndex);

            publisherSlots.Add(new PublisherSlot(standardGameIndex, overallSlotNumber, false, specialSlot, standardGame));
            overallSlotNumber++;
        }

        var counterPicksBySlot = PublisherGames.Where(x => x.CounterPick).ToDictionary(x => x.SlotNumber);

        for (int counterPickIndex = 0; counterPickIndex < leagueOptions.CounterPicks; counterPickIndex++)
        {
            PublisherGame?counterPick = null;
            if (counterPicksBySlot.TryGetValue(counterPickIndex, out var foundGame))
            {
                counterPick = foundGame;
            }

            publisherSlots.Add(new PublisherSlot(counterPickIndex, overallSlotNumber, true, null, counterPick));
            overallSlotNumber++;
        }

        return(publisherSlots);
    }
Пример #27
0
        public ClaimResult CanClaimGame(ClaimGameDomainRequest request, IEnumerable <SupportedYear> supportedYears, LeagueYear leagueYear,
                                        IEnumerable <Publisher> publishersInLeague, Instant?nextBidTime, bool allowIfFull)
        {
            List <ClaimError> claimErrors = new List <ClaimError>();

            var basicErrors = GetBasicErrors(request.Publisher.LeagueYear.League, request.Publisher, supportedYears);

            claimErrors.AddRange(basicErrors);

            LeagueOptions yearOptions = leagueYear.Options;

            if (request.MasterGame.HasValue && !request.CounterPick)
            {
                var masterGameErrors = GetMasterGameErrors(leagueYear, request.MasterGame.Value, leagueYear.Year, request.CounterPick, false, nextBidTime);
                claimErrors.AddRange(masterGameErrors);
            }

            IReadOnlyList <Publisher> otherPublishers = publishersInLeague.Where(x => x.User.UserID != request.Publisher.User.UserID).ToList();

            IReadOnlyList <PublisherGame> gamesForYear         = publishersInLeague.SelectMany(x => x.PublisherGames).ToList();
            IReadOnlyList <PublisherGame> standardGamesForYear = gamesForYear.Where(x => !x.CounterPick).ToList();
            IReadOnlyList <PublisherGame> thisPlayersGames     = request.Publisher.PublisherGames;
            IReadOnlyList <PublisherGame> otherPlayersGames    = otherPublishers.SelectMany(x => x.PublisherGames).ToList();

            bool gameAlreadyClaimed   = standardGamesForYear.ContainsGame(request);
            bool thisPlayerAlreadyHas = thisPlayersGames.ContainsGame(request);

            if (!request.CounterPick)
            {
                if (gameAlreadyClaimed)
                {
                    claimErrors.Add(new ClaimError("Cannot claim a game that someone already has.", false));
                }

                if (thisPlayerAlreadyHas)
                {
                    claimErrors.Add(new ClaimError("Cannot claim a game that you already have.", false));
                }

                int leagueDraftGames = yearOptions.StandardGames;
                int userDraftGames   = thisPlayersGames.Count(x => !x.CounterPick);
                if (userDraftGames == leagueDraftGames && !allowIfFull)
                {
                    claimErrors.Add(new ClaimError("User's game spaces are filled.", false));
                }
            }

            if (request.CounterPick)
            {
                bool otherPlayerHasCounterPick = otherPlayersGames.Where(x => x.CounterPick).ContainsGame(request);
                if (otherPlayerHasCounterPick)
                {
                    claimErrors.Add(new ClaimError("Cannot counter-pick a game that someone else has already counter-picked.", false));
                }
                bool thisPlayerHasCounterPick = thisPlayersGames.Where(x => x.CounterPick).ContainsGame(request);
                if (thisPlayerHasCounterPick)
                {
                    claimErrors.Add(new ClaimError("You already have that counter-pick.", false));
                }

                bool otherPlayerHasDraftGame = otherPlayersGames.Where(x => !x.CounterPick).ContainsGame(request);

                int leagueCounterPicks = yearOptions.CounterPicks;
                int userCounterPicks   = thisPlayersGames.Count(x => x.CounterPick);
                if (userCounterPicks == leagueCounterPicks)
                {
                    claimErrors.Add(new ClaimError("User's counter pick spaces are filled.", false));
                }

                if (!otherPlayerHasDraftGame)
                {
                    claimErrors.Add(new ClaimError("Cannot counterPick a game that no other player is publishing.", false));
                }
            }

            var result = new ClaimResult(claimErrors);

            if (result.Overridable && request.ManagerOverride)
            {
                return(new ClaimResult(new List <ClaimError>()));
            }

            return(result);
        }
        private IReadOnlyList <PickupBid> GetWinnableBids(IEnumerable <PickupBid> activeBidsForLeagueYear, LeagueOptions options, SystemWideValues systemWideValues)
        {
            List <PickupBid> winnableBids = new List <PickupBid>();

            var enoughBudgetBids = activeBidsForLeagueYear.Where(x => x.BidAmount <= x.Publisher.Budget);
            var groupedByGame    = enoughBudgetBids.GroupBy(x => x.MasterGame);

            foreach (var gameGroup in groupedByGame)
            {
                PickupBid bestBid;
                if (gameGroup.Count() == 1)
                {
                    bestBid = gameGroup.First();
                }
                else
                {
                    var bestBids = gameGroup.MaxBy(x => x.BidAmount);
                    //TODO change projections
                    var bestBidsByProjectedScore = bestBids.MinBy(x => x.Publisher.GetProjectedFantasyPoints(options, systemWideValues, false, true, _clock));
                    bestBid = bestBidsByProjectedScore.OrderByDescending(x => x.Publisher.DraftPosition).First();
                }

                winnableBids.Add(bestBid);
            }

            return(winnableBids);
        }
 public Task AddNewLeagueYear(League league, int year, LeagueOptions options)
 {
     throw new NotImplementedException();
 }
 public Task CreateLeague(League league, int initialYear, LeagueOptions options)
 {
     throw new NotImplementedException();
 }