Added system to temporary modify the scrap and enemy list of levels
This commit is contained in:
		
							parent
							
								
									075f3b5d85
								
							
						
					
					
						commit
						4729e67aef
					
				
					 7 changed files with 222 additions and 1 deletions
				
			
		|  | @ -151,6 +151,8 @@ | |||
|     <Compile Include="DevTools\Panels\AssetsPanel.cs" /> | ||||
|     <Compile Include="Generation\DunGenPlusGenerationPaths.cs" /> | ||||
|     <Compile Include="MainPathExtender.cs" /> | ||||
|     <Compile Include="Managers\EnemyManager.cs" /> | ||||
|     <Compile Include="Managers\ScrapItemManager.cs" /> | ||||
|     <Compile Include="PluginConfig.cs" /> | ||||
|     <Compile Include="DevTools\DevDebugManager.cs" /> | ||||
|     <Compile Include="DevTools\DevDebugManagerUI.cs" /> | ||||
|  |  | |||
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										100
									
								
								DunGenPlus/DunGenPlus/Managers/EnemyManager.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										100
									
								
								DunGenPlus/DunGenPlus/Managers/EnemyManager.cs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,100 @@ | |||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| 
 | ||||
| namespace DunGenPlus.Managers { | ||||
|   public static class EnemyManager { | ||||
| 
 | ||||
|     internal static SelectableLevel previousLevel; | ||||
|     internal static List<SpawnableEnemyWithRarity> previouslyAddedEnemies = new List<SpawnableEnemyWithRarity>(); | ||||
|     internal static List<SpawnableEnemyWithRarity> previouslyModifiedEnemies = new List<SpawnableEnemyWithRarity>(); | ||||
|      | ||||
|     internal static void UndoPreviousChanges(){ | ||||
|       // | ||||
|       if (previousLevel != null){ | ||||
|         Plugin.logger.LogDebug($"Undoing changes of EnemyManager for {previousLevel.PlanetName}"); | ||||
|         var levelList = previousLevel.Enemies; | ||||
|          | ||||
|         if (previouslyAddedEnemies.Count > 0){ | ||||
|           // we doing it backwards since previously added items would be at the end of the list yuh? | ||||
|           for(var j = previouslyAddedEnemies.Count - 1; j >= 0; j--){ | ||||
|             var previousItem = previouslyAddedEnemies[j]; | ||||
|             for(var i = levelList.Count - 1; i >= 0; i--){ | ||||
|               var levelItem = levelList[i]; | ||||
|               if (levelItem == previousItem){ | ||||
|                 levelList.RemoveAt(i); | ||||
|                 Plugin.logger.LogDebug($"Properly removed temporary enemy {previousItem.enemyType.enemyName}"); | ||||
|                 goto RemovedItemCorrect; | ||||
|               } | ||||
|             } | ||||
| 
 | ||||
|             //  | ||||
|             Plugin.logger.LogWarning($"Couldn't find/remove temporary enemy {previousItem.enemyType.enemyName}"); | ||||
| 
 | ||||
|             RemovedItemCorrect: | ||||
|             continue; | ||||
|           } | ||||
|           previouslyAddedEnemies.Clear(); | ||||
|         } | ||||
| 
 | ||||
|         if (previouslyModifiedEnemies.Count > 0){ | ||||
|           for(var j = 0;  j < previouslyModifiedEnemies.Count; j++){ | ||||
|             var previousItem = previouslyModifiedEnemies[j]; | ||||
|             for(var i = 0;  i < levelList.Count; i++){ | ||||
|               if (levelList[i].enemyType == previousItem.enemyType){ | ||||
|                 levelList[i] = previousItem; | ||||
|                 Plugin.logger.LogDebug($"Properly fixed modified enemy {previousItem.enemyType.enemyName}"); | ||||
|                 goto ModifiedItemCorrect; | ||||
|               } | ||||
|             } | ||||
| 
 | ||||
|              //  | ||||
|             Plugin.logger.LogWarning($"Couldn't find/fix modified enemy {previousItem.enemyType.enemyName}"); | ||||
| 
 | ||||
|             ModifiedItemCorrect: | ||||
|             continue; | ||||
|           } | ||||
|           previouslyModifiedEnemies.Clear(); | ||||
|         } | ||||
| 
 | ||||
|         previousLevel = null; | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
|     internal static void Initialize(RoundManager roundManager){ | ||||
|       UndoPreviousChanges(); | ||||
|       previousLevel = roundManager.currentLevel; | ||||
|       Plugin.logger.LogDebug($"Initialized EnemyManager to {previousLevel.PlanetName}"); | ||||
|     } | ||||
| 
 | ||||
|     public static void AddEnemies(IEnumerable<SpawnableEnemyWithRarity> newEnemies){ | ||||
|       foreach(var item in newEnemies){ | ||||
|         AddEnemy(item); | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
|     public static void AddEnemy(SpawnableEnemyWithRarity newEnemy){ | ||||
|       var levelList = previousLevel.Enemies; | ||||
|       for(var i = 0; i < levelList.Count; ++i) { | ||||
|         if (levelList[i].enemyType == newEnemy.enemyType) { | ||||
| 
 | ||||
|           if (levelList[i].rarity == newEnemy.rarity){ | ||||
|             Plugin.logger.LogDebug($"Skipping {newEnemy.enemyType.enemyName} as it has the same rarity"); | ||||
|             return; | ||||
|           } | ||||
| 
 | ||||
|           previouslyModifiedEnemies.Add(levelList[i]); | ||||
|           levelList[i] = newEnemy; | ||||
|           Plugin.logger.LogDebug($"Modifying already existing enemy {newEnemy.enemyType.enemyName} to new weight {newEnemy.rarity}"); | ||||
|           return; | ||||
|         } | ||||
|       } | ||||
| 
 | ||||
|       previouslyAddedEnemies.Add(newEnemy); | ||||
|       levelList.Add(newEnemy); | ||||
|       Plugin.logger.LogDebug($"Adding temporary enemy {newEnemy.enemyType.enemyName} with weight {newEnemy.rarity}"); | ||||
|     } | ||||
| 
 | ||||
|   } | ||||
| } | ||||
							
								
								
									
										99
									
								
								DunGenPlus/DunGenPlus/Managers/ScrapItemManager.cs
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										99
									
								
								DunGenPlus/DunGenPlus/Managers/ScrapItemManager.cs
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,99 @@ | |||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Linq; | ||||
| using System.Text; | ||||
| 
 | ||||
| namespace DunGenPlus.Managers { | ||||
|   public static class ScrapItemManager { | ||||
| 
 | ||||
|     internal static SelectableLevel previousLevel; | ||||
|     internal static List<SpawnableItemWithRarity> previouslyAddedItems = new List<SpawnableItemWithRarity>(); | ||||
|     internal static List<SpawnableItemWithRarity> previouslyModifiedItems = new List<SpawnableItemWithRarity>(); | ||||
|      | ||||
|     internal static void UndoPreviousChanges(){ | ||||
|       // | ||||
|       if (previousLevel != null){ | ||||
|         Plugin.logger.LogDebug($"Undoing changes of ScrapItemManager for {previousLevel.PlanetName}"); | ||||
|         var levelList = previousLevel.spawnableScrap; | ||||
|          | ||||
|         if (previouslyAddedItems.Count > 0){ | ||||
|           // we doing it backwards since previously added items would be at the end of the list yuh? | ||||
|           for(var j = previouslyAddedItems.Count - 1; j >= 0; j--){ | ||||
|             var previousItem = previouslyAddedItems[j]; | ||||
|             for(var i = levelList.Count - 1; i >= 0; i--){ | ||||
|               var levelItem = levelList[i]; | ||||
|               if (levelItem == previousItem){ | ||||
|                 levelList.RemoveAt(i); | ||||
|                 Plugin.logger.LogDebug($"Properly removed temporary item {previousItem.spawnableItem.itemName}"); | ||||
|                 goto RemovedItemCorrect; | ||||
|               } | ||||
|             } | ||||
| 
 | ||||
|             //  | ||||
|             Plugin.logger.LogWarning($"Couldn't find/remove temporary item {previousItem.spawnableItem.itemName}"); | ||||
| 
 | ||||
|             RemovedItemCorrect: | ||||
|             continue; | ||||
|           } | ||||
|           previouslyAddedItems.Clear(); | ||||
|         } | ||||
| 
 | ||||
|         if (previouslyModifiedItems.Count > 0){ | ||||
|           for(var j = 0;  j < previouslyModifiedItems.Count; j++){ | ||||
|             var previousItem = previouslyModifiedItems[j]; | ||||
|             for(var i = 0;  i < levelList.Count; i++){ | ||||
|               if (levelList[i].spawnableItem == previousItem.spawnableItem){ | ||||
|                 levelList[i] = previousItem; | ||||
|                 Plugin.logger.LogDebug($"Properly fixed modified item {previousItem.spawnableItem.itemName}"); | ||||
|                 goto ModifiedItemCorrect; | ||||
|               } | ||||
|             } | ||||
| 
 | ||||
|              //  | ||||
|             Plugin.logger.LogWarning($"Couldn't find/fix modified item {previousItem.spawnableItem.itemName}"); | ||||
| 
 | ||||
|             ModifiedItemCorrect: | ||||
|             continue; | ||||
|           } | ||||
|           previouslyModifiedItems.Clear(); | ||||
|         } | ||||
| 
 | ||||
|         previousLevel = null; | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
|     internal static void Initialize(RoundManager roundManager){ | ||||
|       UndoPreviousChanges(); | ||||
|       previousLevel = roundManager.currentLevel; | ||||
|       Plugin.logger.LogDebug($"Initialized ScrapItemManager to {previousLevel.PlanetName}"); | ||||
|     } | ||||
| 
 | ||||
|     public static void AddItems(IEnumerable<SpawnableItemWithRarity> newItems){ | ||||
|       foreach(var item in newItems){ | ||||
|         AddItem(item); | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
|     public static void AddItem(SpawnableItemWithRarity newItem){ | ||||
|       var levelList = previousLevel.spawnableScrap; | ||||
|       for(var i = 0; i < levelList.Count; ++i) { | ||||
|         if (levelList[i].spawnableItem == newItem.spawnableItem) { | ||||
|           if (levelList[i].rarity == newItem.rarity){ | ||||
|             Plugin.logger.LogDebug($"Skipping {newItem.spawnableItem.itemName} as it has the same rarity"); | ||||
|             return; | ||||
|           } | ||||
| 
 | ||||
|           previouslyModifiedItems.Add(levelList[i]); | ||||
|           levelList[i] = newItem; | ||||
|           Plugin.logger.LogDebug($"Modifying already existing item {newItem.spawnableItem.itemName} to new weight {newItem.rarity}"); | ||||
|           return; | ||||
|         } | ||||
|       } | ||||
| 
 | ||||
|       previouslyAddedItems.Add(newItem); | ||||
|       levelList.Add(newItem); | ||||
|       Plugin.logger.LogDebug($"Adding temporary item {newItem.spawnableItem.itemName} with weight {newItem.rarity}"); | ||||
|     } | ||||
| 
 | ||||
|   } | ||||
| } | ||||
|  | @ -4,6 +4,7 @@ using System.Linq; | |||
| using System.Text; | ||||
| using System.Threading.Tasks; | ||||
| using DunGenPlus.DevTools; | ||||
| using DunGenPlus.Managers; | ||||
| using HarmonyLib; | ||||
| 
 | ||||
| 
 | ||||
|  | @ -12,9 +13,17 @@ namespace DunGenPlus.Patches { | |||
| 
 | ||||
|     [HarmonyPrefix] | ||||
|     [HarmonyPatch(typeof(LethalLevelLoader.Patches), "DungeonGeneratorGenerate_Prefix")] | ||||
|     public static bool DungeonGeneratorGenerate_Prefix_Prefix(){ | ||||
|     public static bool DungeonGeneratorGenerate_Prefix_Patches_Prefix(){ | ||||
|       return DevDebugManager.Instance == null; | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     [HarmonyPatch(typeof(LethalLevelLoader.EventPatches), "DungeonGeneratorGenerate_Prefix")] | ||||
|     [HarmonyPrefix] | ||||
|     public static void DungeonGeneratorGenerate_Prefix_EventPatches_Prefix(){ | ||||
|       ScrapItemManager.Initialize(LethalLevelLoader.Patches.RoundManager); | ||||
|       EnemyManager.Initialize(LethalLevelLoader.Patches.RoundManager); | ||||
|     } | ||||
| 
 | ||||
|   } | ||||
| } | ||||
|  |  | |||
|  | @ -2,6 +2,7 @@ | |||
| using DunGenPlus.Components.Scrap; | ||||
| using DunGenPlus.DevTools; | ||||
| using DunGenPlus.Generation; | ||||
| using DunGenPlus.Managers; | ||||
| using HarmonyLib; | ||||
| using System; | ||||
| using System.Collections; | ||||
|  | @ -23,6 +24,13 @@ namespace DunGenPlus.Patches { | |||
|       } | ||||
|     } | ||||
| 
 | ||||
|     [HarmonyPostfix] | ||||
|     [HarmonyPatch(typeof(RoundManager), "Start")] | ||||
|     public static void StartPatch(ref RoundManager __instance){ | ||||
|       ScrapItemManager.UndoPreviousChanges(); | ||||
|       EnemyManager.UndoPreviousChanges(); | ||||
|     } | ||||
| 
 | ||||
|     [HarmonyPrefix] | ||||
|     [HarmonyPatch(typeof(RoundManager), "waitForScrapToSpawnToSync")] | ||||
|     public static void waitForScrapToSpawnToSyncPatch (ref RoundManager __instance, ref NetworkObjectReference[] spawnedScrap, ref int[] scrapValues) { | ||||
|  |  | |||
|  | @ -15,6 +15,8 @@ namespace DunGenPlus.Patches { | |||
| 
 | ||||
|   internal class StartOfRoundPatch { | ||||
| 
 | ||||
|     /* | ||||
| 
 | ||||
|     public static readonly string[] validDungeonFlowTargets = new [] { | ||||
|       "Level1Flow", "Level2Flow", "Level1FlowExtraLarge", "Level1Flow3Exits" | ||||
|     }; | ||||
|  | @ -65,6 +67,7 @@ namespace DunGenPlus.Patches { | |||
|         } | ||||
|       } | ||||
|     } | ||||
|     */ | ||||
| 
 | ||||
|   } | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue