Fix up stat handling in LevelUp patch
This commit is contained in:
		| @@ -74,6 +74,9 @@ | |||||||
|     <Reference Include="UnityEngine"> |     <Reference Include="UnityEngine"> | ||||||
|       <HintPath>$(GAME_MANAGED)/UnityEngine.dll</HintPath> |       <HintPath>$(GAME_MANAGED)/UnityEngine.dll</HintPath> | ||||||
|     </Reference> |     </Reference> | ||||||
|  |     <Reference Include="UnityEngine.UI"> | ||||||
|  |       <HintPath>$(GAME_MANAGED)/UnityEngine.UI.dll</HintPath> | ||||||
|  |     </Reference> | ||||||
|     <Reference Include="UnityEngine.CoreModule"> |     <Reference Include="UnityEngine.CoreModule"> | ||||||
|       <HintPath>$(GAME_MANAGED)/UnityEngine.CoreModule.dll</HintPath> |       <HintPath>$(GAME_MANAGED)/UnityEngine.CoreModule.dll</HintPath> | ||||||
|     </Reference> |     </Reference> | ||||||
|   | |||||||
| @@ -5,6 +5,8 @@ using BepInEx; | |||||||
| using BepInEx.Configuration; | using BepInEx.Configuration; | ||||||
| using HarmonyLib; | using HarmonyLib; | ||||||
| using HarmonyLib.Tools; | using HarmonyLib.Tools; | ||||||
|  | using UnityEngine; | ||||||
|  | using UnityEngine.UI; | ||||||
|  |  | ||||||
| namespace BanquetForCyka { | namespace BanquetForCyka { | ||||||
|     [BepInPlugin(PluginGuid, PluginName, PluginVersion)] |     [BepInPlugin(PluginGuid, PluginName, PluginVersion)] | ||||||
| @@ -82,56 +84,56 @@ namespace BanquetForCyka { | |||||||
|  |  | ||||||
|     [HarmonyPatch(typeof(LevelUp), "ClickedStat")] |     [HarmonyPatch(typeof(LevelUp), "ClickedStat")] | ||||||
|     public class Actions_ClickedStat { |     public class Actions_ClickedStat { | ||||||
|         private static float originalStr; |         public static bool Prefix(ref LevelUp __instance, GameObject go) { | ||||||
|         private static float originalAgi; |             if (__instance.levelUpSkills || !__instance.open) { | ||||||
|         private static float originalDex; |                 return true;  // Let original method handle this case | ||||||
|         private static float originalPag; |             } | ||||||
|         private static float originalSen; |  | ||||||
|  |  | ||||||
|         public static void Prefix(ref LevelUp __instance) { |             string name = go.name; | ||||||
|             Main.LogDebug("Original Str: " + __instance.character.stats.strength, Main.debugStatEntry); |             if (__instance.statChosen1 != "" || name == __instance.statChosen1) { | ||||||
|             Main.LogDebug("Original Agi: " + __instance.character.stats.agility, Main.debugStatEntry); |                 return true;  // Let original method handle this case | ||||||
|             Main.LogDebug("Original Dex: " + __instance.character.stats.dexterity, Main.debugStatEntry); |             } | ||||||
|             Main.LogDebug("Original Pag: " + __instance.character.stats.pagan, Main.debugStatEntry); |  | ||||||
|             Main.LogDebug("Original Sen: " + __instance.character.stats.sensory, Main.debugStatEntry); |  | ||||||
|  |  | ||||||
|             originalStr = __instance.character.stats.strength; |             float num = 0f; | ||||||
|             originalAgi = __instance.character.stats.agility; |             if (name == "Strength") { | ||||||
|             originalDex = __instance.character.stats.dexterity; |                 num = __instance.savedStr; | ||||||
|             originalPag = __instance.character.stats.pagan; |             } | ||||||
|             originalSen = __instance.character.stats.sensory; |             if (name == "Agility") { | ||||||
|         } |                 num = __instance.savedAgl; | ||||||
|  |             } | ||||||
|  |             if (name == "Dexterity") { | ||||||
|  |                 num = __instance.savedDex; | ||||||
|  |             } | ||||||
|  |             if (name == "Aura") { | ||||||
|  |                 num = __instance.savedAur; | ||||||
|  |             } | ||||||
|  |             if (name == "Pagan") { | ||||||
|  |                 num = __instance.savedPag; | ||||||
|  |             } | ||||||
|  |             if (name == "Sensory") { | ||||||
|  |                 num = __instance.savedSen; | ||||||
|  |             } | ||||||
|  |  | ||||||
|         public static void Postfix(ref LevelUp __instance) { |             Main.LogDebug("Original stat value: " + num, Main.debugStatEntry); | ||||||
|             float deltaStr = __instance.character.stats.strength - originalStr; |             float result = Main.levelUpStatEntry.Evaluate(1f);  // Evaluate the increase amount | ||||||
|             float deltaAgi = __instance.character.stats.agility - originalAgi; |             Main.LogDebug("Modified increase amount: " + result, Main.debugStatEntry); | ||||||
|             float deltaDex = __instance.character.stats.dexterity - originalDex; |  | ||||||
|             float deltaPag = __instance.character.stats.pagan - originalPag; |  | ||||||
|             float deltaSen = __instance.character.stats.sensory - originalSen; |  | ||||||
|  |  | ||||||
|             Main.LogDebug("Delta Str: " + deltaStr, Main.debugStatEntry); |             // Set the stat with the modified increase | ||||||
|             Main.LogDebug("Delta Agi: " + deltaAgi, Main.debugStatEntry); |             __instance.character.stats.SetStat(name, num + result); | ||||||
|             Main.LogDebug("Delta Dex: " + deltaDex, Main.debugStatEntry); |             Links.x.characterSheet.GetStatNums(); | ||||||
|             Main.LogDebug("Delta Pag: " + deltaPag, Main.debugStatEntry); |             Links.x.characterSheet.GetOutput(); | ||||||
|             Main.LogDebug("Delta Sen: " + deltaSen, Main.debugStatEntry); |  | ||||||
|  |  | ||||||
|             float resultStr = Main.levelUpStatEntry.Evaluate(deltaStr); |             // Update UI elements like the original method would | ||||||
|             float resultAgi = Main.levelUpStatEntry.Evaluate(deltaAgi); |             __instance.statTokenUse1.enabled = true; | ||||||
|             float resultDex = Main.levelUpStatEntry.Evaluate(deltaDex); |             __instance.statTokenCounter1.enabled = false; | ||||||
|             float resultPag = Main.levelUpStatEntry.Evaluate(deltaPag); |             __instance.statTokenUse1RT.anchoredPosition = | ||||||
|             float resultSen = Main.levelUpStatEntry.Evaluate(deltaSen); |                 __instance.skillTrs[__instance.GetTransformIndex(name, true)].anchoredPosition; | ||||||
|  |             __instance.statChosen1 = name; | ||||||
|  |             __instance.dragIndicator.SetActive(false); | ||||||
|  |             __instance.draggingToken = false; | ||||||
|  |             __instance.dragToken = null; | ||||||
|  |  | ||||||
|             Main.LogDebug("Result Str: " + resultStr, Main.debugStatEntry); |             return false;  // Skip original method | ||||||
|             Main.LogDebug("Result Agi: " + resultAgi, Main.debugStatEntry); |  | ||||||
|             Main.LogDebug("Result Dex: " + resultDex, Main.debugStatEntry); |  | ||||||
|             Main.LogDebug("Result Pag: " + resultPag, Main.debugStatEntry); |  | ||||||
|             Main.LogDebug("Result Sen: " + resultSen, Main.debugStatEntry); |  | ||||||
|  |  | ||||||
|             __instance.character.stats.strength = resultStr; |  | ||||||
|             __instance.character.stats.agility = resultAgi; |  | ||||||
|             __instance.character.stats.dexterity = resultDex; |  | ||||||
|             __instance.character.stats.pagan = resultPag; |  | ||||||
|             __instance.character.stats.sensory = resultSen; |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -144,4 +146,4 @@ namespace BanquetForCyka { | |||||||
|             Main.LogDebug("Modified amount: " + __result, Main.debugLevelUpEntry); |             Main.LogDebug("Modified amount: " + __result, Main.debugLevelUpEntry); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user