public async Task <ActionResult <FighterDto> > CreateFighter( [FromBody] FighterDto dto, [FromServices] IFighterLevelUpHandler fighterLevelUpHandler, [FromServices] IFighterOutfitter fighterOutfitter, [FromServices] IEquipmentGenerator equipmentGenerator) { var userId = User.Claims.GetUserId(); if (userId == null) { return(Forbid()); } var name = dto.Name; if (string.IsNullOrEmpty(name) || await Context.Fighters.AnyAsync(o => o.Name == name)) { return(BadRequest()); } if (await Context.Fighters.AnyAsync(o => o.UserId == userId)) { return(BadRequest()); } var fighter = new Fighter() { Name = name, UserId = userId.Value, Created = dateTimeProvider.Now, Equipment = new List <Equipment>(), }; fighterLevelUpHandler.Up(fighter); var armorHead = equipmentGenerator.GenerateArmorHead(fighter.Level, ItemRarity.Basic, userId.Value); var armorShoulders = equipmentGenerator.GenerateArmorShoulders(fighter.Level, ItemRarity.Basic, userId.Value); var armorChest = equipmentGenerator.GenerateArmorChest(fighter.Level, ItemRarity.Basic, userId.Value); var armorHands = equipmentGenerator.GenerateArmorHands(fighter.Level, ItemRarity.Basic, userId.Value); var armorLegs = equipmentGenerator.GenerateArmorLegs(fighter.Level, ItemRarity.Basic, userId.Value); var armorShoes = equipmentGenerator.GenerateArmorShoes(fighter.Level, ItemRarity.Basic, userId.Value); var weapon = equipmentGenerator.GenerateWeaponGreatsword(fighter.Level, ItemRarity.Basic, userId.Value); fighterOutfitter.Equip(fighter, armorHead, false); fighterOutfitter.Equip(fighter, armorShoulders, false); fighterOutfitter.Equip(fighter, armorChest, false); fighterOutfitter.Equip(fighter, armorHands, false); fighterOutfitter.Equip(fighter, armorLegs, false); fighterOutfitter.Equip(fighter, armorShoes, false); fighterOutfitter.Equip(fighter, weapon, false); Context.Fighters.Add(fighter); Context.Equipment.AddRange(armorHead, armorShoulders, armorChest, armorHands, armorLegs, armorShoes, weapon); await Context.SaveChangesAsync(); return(Mapper.Map <FighterDto>(fighter)); }
public SeasonFighterResetter( IFighterLevelUpHandler fighterLevelUpHandler, IFighterOutfitter fighterOutfitter, IEquipmentGenerator equipmentGenerator) { this.fighterLevelUpHandler = fighterLevelUpHandler; this.fighterOutfitter = fighterOutfitter; this.equipmentGenerator = equipmentGenerator; }
public async Task <ActionResult <FighterDto> > Unequip(Guid id, [FromBody] EquipmentDto dto, [FromServices] IFighterOutfitter fighterOutfitter) { var userId = User.Claims.GetUserId(); if (userId == null) { return(Forbid()); } var fighter = await Context.Fighters .AsTracking() .Where(o => o.UserId == userId) .Include(o => o.Equipment) .ThenInclude(o => o.Option) .Include(o => o.Equipment) .ThenInclude(o => o.SocketStones) .FirstOrDefaultAsync(o => o.Id == id); if (fighter == null) { return(BadRequest(new InvalidFighterException())); } var equipment = await Context.Equipment .AsTracking() .Where(o => o.UserId == userId) .Include(o => o.SocketStones) .FirstOrDefaultAsync(o => o.Id == dto.Id); if (equipment == null) { return(BadRequest()); } fighterOutfitter.Unequip(fighter, equipment); await Context.SaveChangesAsync(); return(Mapper.Map <FighterDto>(fighter)); }