From 70f6ce515465286b9e09b6dbbcb858b747b91660 Mon Sep 17 00:00:00 2001 From: LadyAliceMargatroid Date: Mon, 29 Jul 2024 19:07:14 -0700 Subject: [PATCH] Added MainPathCopyNodeBehaviour Added README --- DunGenPlus/DunGenPlus/API.cs | 14 +++++++ DunGenPlus/DunGenPlus/Assets.cs | 2 +- .../Collections/DunGenExtenderProperties.cs | 12 +++++- DunGenPlus/DunGenPlus/DunGenExtender.cs | 3 ++ .../Generation/DunGenPlusGenerator.cs | 33 ++++++++++++---- README.md | 39 ++++++++++++++++++- 6 files changed, 92 insertions(+), 11 deletions(-) diff --git a/DunGenPlus/DunGenPlus/API.cs b/DunGenPlus/DunGenPlus/API.cs index e70a481..b2eadb9 100644 --- a/DunGenPlus/DunGenPlus/API.cs +++ b/DunGenPlus/DunGenPlus/API.cs @@ -11,6 +11,11 @@ namespace DunGenPlus public class API { public static bool AddDunGenExtender(DungeonFlow dungeonFlow, DunGenExtender dunGenExtender) { + if (dungeonFlow == null) { + Plugin.logger.LogError("dungeonFlow was null"); + return false; + } + if (Plugin.DunGenExtenders.ContainsKey(dungeonFlow)) { Plugin.logger.LogWarning($"Already contains DunGenExtender asset for {dungeonFlow.name}"); return false; @@ -22,5 +27,14 @@ namespace DunGenPlus return true; } + public static bool AddDunGenExtender(DunGenExtender dunGenExtender) { + if (dunGenExtender == null) { + Plugin.logger.LogError("dunGenExtender was null"); + return false; + } + + return AddDunGenExtender(dunGenExtender.DungeonFlow, dunGenExtender); + } + } } diff --git a/DunGenPlus/DunGenPlus/Assets.cs b/DunGenPlus/DunGenPlus/Assets.cs index 1445bf4..84d5d1f 100644 --- a/DunGenPlus/DunGenPlus/Assets.cs +++ b/DunGenPlus/DunGenPlus/Assets.cs @@ -28,7 +28,7 @@ namespace DunGenPlus { } foreach(var e in extenders){ - API.AddDunGenExtender(e.DungeonFlow, e); + API.AddDunGenExtender(e); } } diff --git a/DunGenPlus/DunGenPlus/Collections/DunGenExtenderProperties.cs b/DunGenPlus/DunGenPlus/Collections/DunGenExtenderProperties.cs index 7b5d839..47fab81 100644 --- a/DunGenPlus/DunGenPlus/Collections/DunGenExtenderProperties.cs +++ b/DunGenPlus/DunGenPlus/Collections/DunGenExtenderProperties.cs @@ -12,12 +12,20 @@ namespace DunGenPlus.Collections { [System.Serializable] public class DunGenExtenderProperties { + public enum CopyNodeBehaviour { + CopyFromMainPathPosition, + CopyFromNodeList + } + [Header("Main Path")] [Tooltip("The number of main paths.\n\n1 means no additional main paths\n3 means two additional main paths\netc.")] [Range(1, 9)] public int MainPathCount = 1; [Tooltip("The Tile Prefab where the additional main paths will start from. Cannot be null if MainPathCount is more than 1.\n\nHighly advice for this Tile Prefab to have multiple doorways.")] public GameObject MainRoomTilePrefab; + [Tooltip("CopyFromMainPathPosition means that nodes will copy from the MainRoomTilePrefab's position in the main path.\n\nCopyFromNodeList means that nodes will copy from the MainRoomTilePrefab's location from the node list + 1.")] + public CopyNodeBehaviour MainPathCopyNodeBehaviour = CopyNodeBehaviour.CopyFromMainPathPosition; + //public bool MainPathCopyInjectionTiles; [Header("Dungeon Bounds")] [Tooltip("If enabled, restricts the dungeon's generation to the bounds described below.\n\nThis will help in condensing the dungeon, but it will increase the chance of dungeon generation failure (potentially guarantees failure if the bounds is too small).")] @@ -33,7 +41,7 @@ namespace DunGenPlus.Collections { [Header("Archetypes on Normal Nodes")] [Tooltip("If enabled, adds archetypes to the normal nodes in the DungeonFlow.\n\nBy default, nodes cannot have branching paths since they don't have archetype references. This allows nodes to have branching paths.")] - public bool AddArchetypesToNormalNodes = true; + public bool AddArchetypesToNormalNodes = false; public List NormalNodeArchetypes; internal Dictionary _normalNodeArchetypesDictioanry; internal NodeArchetype _defaultNodeArchetype; @@ -104,6 +112,8 @@ namespace DunGenPlus.Collections { copy.MainPathCount = MainPathCount; copy.MainRoomTilePrefab = MainRoomTilePrefab; + copy.MainPathCopyNodeBehaviour = MainPathCopyNodeBehaviour; + //copy.MainPathCopyInjectionTiles = MainPathCopyInjectionTiles; copy.UseDungeonBounds = UseDungeonBounds; copy.DungeonSizeBase = DungeonSizeBase; diff --git a/DunGenPlus/DunGenPlus/DunGenExtender.cs b/DunGenPlus/DunGenPlus/DunGenExtender.cs index 43903bb..6b9c69f 100644 --- a/DunGenPlus/DunGenPlus/DunGenExtender.cs +++ b/DunGenPlus/DunGenPlus/DunGenExtender.cs @@ -18,5 +18,8 @@ namespace DunGenPlus { public DunGenExtenderProperties Properties; public DunGenExtenderEvents Events; + [Header("DEV ONLY: DON'T TOUCH")] + public string Version = "0"; + } } diff --git a/DunGenPlus/DunGenPlus/Generation/DunGenPlusGenerator.cs b/DunGenPlus/DunGenPlus/Generation/DunGenPlusGenerator.cs index dc2dc16..fb5fb7c 100644 --- a/DunGenPlus/DunGenPlus/Generation/DunGenPlusGenerator.cs +++ b/DunGenPlus/DunGenPlus/Generation/DunGenPlusGenerator.cs @@ -130,13 +130,19 @@ namespace DunGenPlus.Generation { // nodes var nodesSorted = gen.DungeonFlow.Nodes.OrderBy(n => n.Position).ToList(); - var startingNodeIndex = nodesSorted.FindIndex(n => n.TileSets.SelectMany(t => t.TileWeights.Weights).Any(t => t.Value == Properties.MainRoomTilePrefab)); - if (startingNodeIndex == -1) { - Plugin.logger.LogWarning($"Switching to default dungeon branch generation due to MainRoomTilePrefab not existing in the Nodes' tilesets"); - ActiveAlternative = false; - yield return gen.Wait(gen.GenerateBranchPaths()); - ActiveAlternative = true; - yield break; + var startingNodeIndexCache = -1; + if (Properties.MainPathCopyNodeBehaviour == DunGenExtenderProperties.CopyNodeBehaviour.CopyFromNodeList) { + startingNodeIndexCache = nodesSorted.FindIndex(n => n.TileSets.SelectMany(t => t.TileWeights.Weights).Any(t => t.Value == Properties.MainRoomTilePrefab)); + + if (startingNodeIndexCache == -1) { + Plugin.logger.LogWarning($"Switching to default dungeon branch generation due to CopyNodeBehaviour being CopyFromNodeList AND MainRoomTilePrefab not existing in the Nodes' tilesets"); + ActiveAlternative = false; + yield return gen.Wait(gen.GenerateBranchPaths()); + ActiveAlternative = true; + yield break; + } + + startingNodeIndexCache++; } //FixDoorwaysToAllFloors(mainRoom, doorwayGroups); @@ -152,7 +158,18 @@ namespace DunGenPlus.Generation { var newMainPathTiles = new List(); newMainPathTiles.Add(mainRoom); - var nodes = nodesSorted.Skip(startingNodeIndex + 1); + int startingNodeIndex; + if (Properties.MainPathCopyNodeBehaviour == DunGenExtenderProperties.CopyNodeBehaviour.CopyFromMainPathPosition) { + var lineDepthRatio = Mathf.Clamp01(1f / (targetLength - 1)); + startingNodeIndex = nodesSorted.FindIndex(n => n.Position >= lineDepthRatio); + } else if (Properties.MainPathCopyNodeBehaviour == DunGenExtenderProperties.CopyNodeBehaviour.CopyFromNodeList) { + startingNodeIndex = startingNodeIndexCache; + } else { + Plugin.logger.LogError($"{Properties.MainPathCopyNodeBehaviour} is not yet defined. How did this happen?"); + startingNodeIndex = -1; + } + + var nodes = nodesSorted.Skip(startingNodeIndex); var nodesVisited = new List(nodes.Count()); // most of this code is a mix of the GenerateMainPath() diff --git a/README.md b/README.md index eb73ed1..420f779 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,39 @@ -# DungeonGenerationPlus_LethalCompany_Mod +# Dungeon Generation Plus + +An API to expand the compatibilities of Lethal Company's dungeon generation. + +This mod is for interior modders to add to their projects if they so desire. By itself, this mod cannot improve the dungeon generation of vanilla dungeons. + +This API was originally a part of the custom interior, [Scarlet Devil Mansion](https://thunderstore.io/c/lethal-company/p/Alice/ScarletDevilMansion/). + +## How to Setup and Use +Please refer to the [wiki](https://git.touhou.dev/Raphtalia/DungeonGenerationPlus_LethalCompany_Mod/wiki) for documentation on utilizing this API for your custom interior. + + +## Multiple Main Paths + +The prominent feature of this API is the ability to seemlesly add multiple main paths to your interior. Below are some examples. + +![](https://i.imgur.com/nN5Zz5e.png) + +![](https://i.imgur.com/ogrUKAI.png) + +![](https://i.imgur.com/IRjMb9V.png) + +![](https://i.imgur.com/URTcLNF.png) + +## Credits + +LadyEbony.itch.io - Code\ +gav - Mod icon\ +@albinogeek (Discord) - Wiki proofreading\ +@bsl (Discord) - Beta testing + +#### License + +Released under Creative Commons Attribution License. Do what you want, you don't need my permission. You only have to include the text blob above, with the names and their contributions, somewhere reasonably visible in your mod page or whatever you doing. + +## Contact + +Any complaints or questions can asked in this [discord thread](https://discordapp.com/channels/1168655651455639582/1195583267546595389). You can also dm personally at this [discord](https://discord.gg/M7aZKP9Qvc), LadyRaphtalia. Please do not send a friend request, I will not accept it.