コード例 #1
0
 public async Task <DungeonModel> GenerateDungeonAsync(DungeonOptionModel model)
 {
     try
     {
         ValidateModel(model);
         _dungeonHelper.Init(model);
         var dungeonOptions = new DungeonOptionsModel
         {
             Size            = model.DungeonSize,
             RoomDensity     = model.RoomDensity,
             RoomSizePercent = model.RoomSize,
             TrapPercent     = model.TrapPercent,
             HasDeadEnds     = model.DeadEnd,
             RoamingPercent  = model.RoamingPercent
         };
         if (model.Corridor)
         {
             var dungeon = new Generator.Dungeon(dungeonOptions, _dungeonHelper);
             dungeon.Generate();
             return(await Task.FromResult(
                        new DungeonModel()
             {
                 DungeonTiles = JsonSerializer.Serialize(dungeon.DungeonTiles),
                 RoomDescription = JsonSerializer.Serialize(dungeon.RoomDescription),
                 TrapDescription = JsonSerializer.Serialize(dungeon.TrapDescription),
                 RoamingMonsterDescription = JsonSerializer.Serialize(dungeon.RoamingMonsterDescription),
                 DungeonOptionId = model.Id
             }
                        ));
         }
         else
         {
             var dungeonNoCorridor = new DungeonNoCorridor(dungeonOptions.Width, dungeonOptions.Height, model.DungeonSize, model.RoomSize, _dungeonHelper);
             dungeonNoCorridor.Generate();
             return(await Task.FromResult(
                        new DungeonModel()
             {
                 DungeonTiles = JsonSerializer.Serialize(dungeonNoCorridor.DungeonTiles),
                 RoomDescription = JsonSerializer.Serialize(dungeonNoCorridor.RoomDescription),
                 DungeonOptionId = model.Id,
                 TrapDescription = "[]",
                 RoamingMonsterDescription = "[]"
             }
                        ));
         }
     }
     catch (Exception ex)
     {
         _logger.LogError("Error: " + ex.Message);
         throw;
     }
 }
コード例 #2
0
        public Dungeon GetDungeon(DungeonOptionModel optionModel = null)
        {
            var helperService = _scope.ServiceProvider.GetService <IDungeonHelper>();

            if (optionModel is null)
            {
                optionModel = new DungeonOptionModel
                {
                    DungeonName       = "UT Dungeon",
                    Created           = DateTime.UtcNow,
                    ItemsRarity       = 1,
                    DeadEnd           = true,
                    DungeonDifficulty = 1,
                    DungeonSize       = 25,
                    MonsterType       = "any",
                    PartyLevel        = 4,
                    PartySize         = 4,
                    TrapPercent       = 20,
                    RoamingPercent    = 0,
                    TreasureValue     = 1,
                    RoomDensity       = 10,
                    RoomSize          = 20,
                    Corridor          = false
                };
            }

            helperService.Init(optionModel);

            var model = new DungeonOptionsModel
            {
                Size            = optionModel.DungeonSize,
                RoomDensity     = optionModel.RoomDensity,
                RoomSizePercent = optionModel.RoomSize,
                TrapPercent     = optionModel.TrapPercent,
                HasDeadEnds     = optionModel.DeadEnd,
                RoamingPercent  = optionModel.RoamingPercent
            };

            return(new Dungeon(model, helperService));
        }