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 MatchFighterExperienceProcessor( DatabaseContext databaseContext, IFighterExperienceCalculator fighterExperienceCalculator, IFighterLevelUpHandler fighterLevelUpHandler) { this.databaseContext = databaseContext; this.fighterExperienceCalculator = fighterExperienceCalculator; this.fighterLevelUpHandler = fighterLevelUpHandler; }