コード例 #1
0
        private void ResetFighter(Fighter fighter, Random random, DatabaseContext context)
        {
            fighter.Level = 0;

            if (fighter.Configuration != null)
            {
                fighter.Configuration.AttunementId = null;
            }

            fighterLevelUpHandler.Up(fighter);

            var armorHead      = equipmentGenerator.GenerateArmorHead(fighter.Level, ItemRarity.Basic, fighter.UserId);
            var armorShoulders = equipmentGenerator.GenerateArmorShoulders(fighter.Level, ItemRarity.Basic, fighter.UserId);
            var armorChest     = equipmentGenerator.GenerateArmorChest(fighter.Level, ItemRarity.Basic, fighter.UserId);
            var armorHands     = equipmentGenerator.GenerateArmorHands(fighter.Level, ItemRarity.Basic, fighter.UserId);
            var armorLegs      = equipmentGenerator.GenerateArmorLegs(fighter.Level, ItemRarity.Basic, fighter.UserId);
            var armorShoes     = equipmentGenerator.GenerateArmorShoes(fighter.Level, ItemRarity.Basic, fighter.UserId);

            var weaponType = EquipmentConstants.Weapons.Random(random);
            var weapon     = equipmentGenerator.GenerateEquipment(weaponType, fighter.Level, ItemRarity.Basic, fighter.UserId);

            fighterOutfitter.Equip(fighter, armorHead, true);
            fighterOutfitter.Equip(fighter, armorShoulders, true);
            fighterOutfitter.Equip(fighter, armorChest, true);
            fighterOutfitter.Equip(fighter, armorHands, true);
            fighterOutfitter.Equip(fighter, armorLegs, true);
            fighterOutfitter.Equip(fighter, armorShoes, true);

            fighterOutfitter.Equip(fighter, weapon, true);

            context.AddRange(armorHead, armorShoulders, armorChest, armorHands, armorLegs, armorShoes, weapon);
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        public async Task <ActionResult <FighterDto> > Equip(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.Equip(fighter, equipment, true);

            await Context.SaveChangesAsync();

            return(Ok(Mapper.Map <FighterDto>(fighter)));
        }