Esempio n. 1
0
        public async Task AdvanceYear(int amount)
        {
            if (amount <= 0)
            {
                await ReplyAsync("YOU FOOL, YOU ABSOLUTE BUFFOON");

                return;
            }

            var currentYear = _stewardContext.Year.First();

            var charactersOver60AndAlive = _stewardContext.PlayerCharacters.Where(c =>
                                                                                  c.YearOfDeath == null && c.YearOfBirth < currentYear.CurrentYear - 60);

            Console.WriteLine("Amount of characters checked: " + charactersOver60AndAlive.Count());

            foreach (var character in charactersOver60AndAlive)
            {
                //-1, because else it'll check a year twice
                await _deathService.PerformOldAgeCalculation(character, currentYear.CurrentYear, currentYear.CurrentYear + amount - 1);
            }

            currentYear.CurrentYear += amount;

            _stewardContext.PlayerCharacters.UpdateRange(charactersOver60AndAlive);
            _stewardContext.Year.Update(currentYear);
            await _stewardContext.SaveChangesAsync();

            await ReplyAsync($"The year is now {currentYear.CurrentYear}.");
        }