using DunGen.Graph; using DunGen; using DunGenPlus.Collections; using DunGenPlus; using HarmonyLib; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LoadstoneNighty { // patch 17 has the patch functions for me to use public class PatchVer17 { public static void Activate(){ Loadstone.Patches.DungenOptimizationPatches.tileCollectors.Add(GetTiles); Plugin.logger.LogInfo($"DungenOptimizationPatches function has been patched!"); } private static HashSet GetTiles(DungeonGenerator generator) { var flow = generator.DungeonFlow; var extender = API.GetDunGenExtender(flow); var hashset = new HashSet(); if (API.IsDunGenExtenderActive(extender)){ Plugin.logger.LogDebug("Creating custom hashset for Loadstone"); var props = extender.Properties; GenerateTileHashSet(ref hashset, props.MainPathProperties.MainPathDetails); GenerateTileHashSet(ref hashset, props.AdditionalTilesProperties.AdditionalTileSets); GenerateTileHashSet(ref hashset, props.NormalNodeArchetypesProperties.NormalNodeArchetypes); GenerateTileHashSet(ref hashset, props.LineRandomizerProperties.Archetypes); } return hashset; } static void GenerateTileHashSet(ref HashSet tiles, List nodes) { foreach (var n in nodes) { GenerateTileHashSet(ref tiles, n.Archetypes); } } static void GenerateTileHashSet(ref HashSet tiles, List list) { foreach (var l in list) { GenerateTileHashSet(ref tiles, l.TileSets); } } static void GenerateTileHashSet(ref HashSet tiles, List extenders) { foreach (var ext in extenders) { GenerateTileHashSet(ref tiles, ext.Nodes.Value); GenerateTileHashSet(ref tiles, ext.Lines.Value); } } static void GenerateTileHashSet(ref HashSet tiles, List nodes) { foreach (var n in nodes) { GenerateTileHashSet(ref tiles, n.TileSets); } } static void GenerateTileHashSet(ref HashSet tiles, List lines) { foreach (var l in lines) { GenerateTileHashSet(ref tiles, l.DungeonArchetypes); } } static void GenerateTileHashSet(ref HashSet tiles, List archetypes) { foreach (var a in archetypes) { GenerateTileHashSet(ref tiles, a.TileSets); GenerateTileHashSet(ref tiles, a.BranchCapTileSets); } } static void GenerateTileHashSet(ref HashSet tiles, List tileSets) { foreach (var tileSet in tileSets) { foreach (var tileChance in tileSet.TileWeights.Weights) { var tile = tileChance.Value.GetComponent(); if (tile != null) tiles.Add(tile); } } } [HarmonyPrefix] [HarmonyPatch(typeof(Loadstone.Patches.FromProxyPatches), "FromProxyEnd")] public static void FromProxyEndPatch(Dictionary dictionary){ DunGenPlus.API.AddTileToMainPathDictionary(dictionary); } } }