Ejemplo n.º 1
0
        public async Task <BattleUnitsListViewModel> Handle(GetBattleUnitsQuery request, CancellationToken cancellationToken)
        {
            var dbHero        = this.Context.Heroes.FromSqlRaw($"GetBattleHero {request.HeroId}").AsEnumerable().First();
            var hero          = this.Mapper.Map <BattleUnitViewModel>(dbHero);
            var fightingClass = await this.Context.FightingClasses.FindAsync(dbHero.FightingClassId);

            var dbSpells           = this.Context.Spells.Where(s => s.FightingClassId == dbHero.FightingClassId).AsNoTracking();
            var conditionValidator = new ConditionValidator();

            foreach (var spell in dbSpells)
            {
                conditionValidator.Process(spell, dbHero, request.Enemy, null, null, true);
                var mappedSpell = this.Mapper.Map <SpellMinViewModel>(spell);
                mappedSpell.ClassType = fightingClass.Type;

                hero.Spells.Add(mappedSpell);
            }

            return(new BattleUnitsListViewModel
            {
                Hero = hero,
                Enemy = this.Mapper.Map <BattleUnitViewModel>(request.Enemy),
            });
        }