public static int[][] GetMapOfTemplatesActiveAreas(int templateIndex) { float[][] chanceMap = MapManager.GetTemplateAreaChanceMap(templateIndex, scaling: 100); int[][] spawnMap = new int[chanceMap.Length][]; var template = WorldSpawnTemplateManager.GetTemplate(templateIndex); if (template is null) { Log.LogWarning($"Unable to find config with index '{templateIndex}'"); return(null); } var allowedBiomes = template.BiomeMask ?? (Heightmap.Biome) 1023; var locationCondition = template.SpawnConditions.FirstOrDefault(x => x is ConditionLocation) as ConditionLocation; var distanceToCenterCondition = template.SpawnConditions.FirstOrDefault(x => x is ConditionDistanceToCenter) as ConditionDistanceToCenter; var areaIdsCondition = template.SpawnConditions.FirstOrDefault(x => x is ConditionAreaIds) as ConditionAreaIds; var areaSpawnChance = template.SpawnConditions.FirstOrDefault(x => x is ConditionAreaSpawnChance) as ConditionAreaSpawnChance; for (int x = 0; x < spawnMap.Length; ++x) { spawnMap[x] = new int[spawnMap.Length]; for (int y = 0; y < spawnMap.Length; ++y) { if ((WeightedCornerBiome(x, y) & (int)allowedBiomes) == 0) { continue; } var coordX = MapManager.AreaMap.IndexToCoordinate(x); var coordY = MapManager.AreaMap.IndexToCoordinate(y); var position = new Vector3(coordX, 0, coordY); if (locationCondition?.IsValid(position) == false) { continue; } if (distanceToCenterCondition?.IsValid(position) == false) { continue; } if (areaIdsCondition?.IsValid(MapManager.AreaMap.AreaIds[x][y]) == false) { continue; } if (chanceMap[x][y] <= (areaSpawnChance?.AreaChance ?? 100)) { spawnMap[x][y] = 255; } } } return(spawnMap); }
private static void ApplyWorldSpawnerTemplates(List <SpawnSystemList> spawnLists) { var templates = WorldSpawnTemplateManager .GetTemplates() .Where(x => x.template.TemplateEnabled) .OrderBy(x => x.id) .ToList(); Log.LogTrace($"Found {templates.Count} world spawner templates to apply."); if (templates.Count == 0) { return; } var spawners = spawnLists .SelectMany(x => x.m_spawners) .ToList(); var mainSpawnList = spawnLists.FirstOrDefault(); if (mainSpawnList.IsNull()) { Log.LogWarning("Something is really wrong. No SpawnSystemLists found. Skipping configuration of world spawners."); return; } foreach ((int id, WorldSpawnTemplate template) in templates) { // Validate if (!template.TemplateEnabled) { continue; } SpawnSystem.SpawnData entry; if (ConfigurationManager.GeneralConfig?.AlwaysAppend?.Value == true || id >= spawners.Count) { entry = new SpawnSystem.SpawnData(); mainSpawnList.m_spawners.Add(entry); Log.LogTrace($"Creating spawner entry for template [{id}:{template.PrefabName}]"); ConfigureNewEntry(entry, template); } else { Log.LogTrace($"Overriding spawner entry [{id}:{spawners[id].m_prefab.name}] with template '{template.TemplateName}'"); entry = spawners[id]; ConfigureExistingEntry(entry, template); } WorldSpawnerManager.SetTemplate(entry, template); } }
public static void CommandPrintTemplateSpawnAreas(int templateIndex) { var spawnMap = WorldSpawnerSpawnMapService.GetMapOfTemplatesActiveAreas(templateIndex); var template = WorldSpawnTemplateManager.GetTemplate(templateIndex); if (spawnMap is null || template is null) { Console.instance.Print($"Unable to find template '{templateIndex}', skipping print."); return; } ImageBuilder .SetGrayscaleBiomes(MapManager.AreaMap) .AddHeatZones(spawnMap) .Print($"spawn_map_{templateIndex}_{template.PrefabName}"); var debugFolder = Path.Combine(Paths.BepInExRootPath, ConfigurationManager.GeneralConfig?.DebugFileFolder?.Value ?? "Debug"); Console.instance.Print("Printing map of spawn areas to: " + debugFolder); }