Esempio n. 1
0
        public void Decay(EpgpConfiguration config)
        {
            var epDecayPercentage = AsPercentage(config.EpDecayPercentage);

            using var dbContext = _buzzBotDbContextFactory.GetNew();
            foreach (var data in GetAliasData(dbContext, config))
            {
                var alias         = data.Alias;
                var epDecay       = -(int)Math.Round(alias.EffortPoints * epDecayPercentage, MidpointRounding.AwayFromZero);
                var gpDecay       = -(int)Math.Round(alias.GearPoints * AsPercentage(data.GpDecayPercent), MidpointRounding.AwayFromZero);
                var epTransaction =
                    _epgpTransactionFactory.GetTransaction(alias, epDecay, $"{config.EpDecayPercentage}% EP Decay", TransactionType.EpDecay);
                var gpTransaction =
                    _epgpTransactionFactory.GetTransaction(alias, gpDecay, $"{data.GpDecayPercent}% GP Decay", TransactionType.GpDecay);
                PostTransaction(alias, epTransaction, dbContext);
                PostTransaction(alias, gpTransaction, dbContext);
            }

            dbContext.SaveChanges();
        }
Esempio n. 2
0
        private void Initialize()
        {
            var fileDir = Directory.GetCurrentDirectory();

            _filePath = Path.Combine(fileDir, @"epgpconfig.json");
            if (!File.Exists(_filePath))
            {
                _configuration = new EpgpConfiguration
                {
                    EpDecayPercentage  = 5,
                    GpDecayPercentage  = 5,
                    DecayDayOfWeek     = DayOfWeek.Monday,
                    EpMinimum          = 1,
                    GpMinimum          = 1,
                    UseEarnedGpDecay   = 0,
                    EarnedGpDecayValue = 0,
                    Templates          = new List <EpgpRaidTemplate>()
                };
                Save();
            }

            _configuration = Load();
        }
Esempio n. 3
0
        private List <AliasDecayData> GetAliasData(BuzzBotDbContext dbContext, EpgpConfiguration config)
        {
            //Get all EPGP characters in system
            var aliases = dbContext.Aliases.ToList();

            //If bot is not configured to "use earned decay", short circuit the method
            if (config.UseEarnedGpDecay != 1)
            {
                return(aliases.Select(a =>
                                      new AliasDecayData()
                {
                    Alias = a,
                    GpDecayPercent = config.GpDecayPercentage
                }).ToList());
            }
            //Get all raid data from the previous 7 days
            var raids = dbContext.Raids
                        .Include(r => r.Participants)
                        .ThenInclude(p => p.Alias)
                        .ToList();
            var previousWeeksRaids = raids.Where(r => (DateTime.UtcNow - r.EndTime) < TimeSpan.FromDays(7))
                                     .ToList();

            //If no raid data is found, short circuit the method
            if (!previousWeeksRaids.Any())
            {
                return(aliases.Select(a =>
                                      new AliasDecayData()
                {
                    Alias = a,
                    GpDecayPercent = config.GpDecayPercentage
                }).ToList());
            }
            //Aggregate all unique participants from the week's raids
            var participants =
                previousWeeksRaids
                .SelectMany(r => r.Participants)
                .Select(p => p.Alias.UserId)
                .Distinct()
                .ToList();

            //If no participants are found, short circuit the method
            if (!participants.Any())
            {
                return(aliases.Select(a =>
                                      new AliasDecayData()
                {
                    Alias = a,
                    GpDecayPercent = config.GpDecayPercentage
                }).ToList());
            }
            var returnList = new List <AliasDecayData>();

            //Iterate all aliases
            foreach (var alias in aliases)
            {
                var returnVal = new AliasDecayData
                {
                    Alias          = alias,
                    GpDecayPercent = config.GpDecayPercentage - config.EarnedGpDecayValue
                };
                //If an alias is non-primary (alt) or did not participate in a raid, award minimum GP decay
                if (!alias.IsPrimary || !participants.Contains(alias.UserId))
                {
                    returnList.Add(returnVal);
                    continue;
                }
                //Otherwise, award maximum GP decay
                returnVal.GpDecayPercent += config.EarnedGpDecayValue;
                returnList.Add(returnVal);
            }

            return(returnList);
        }