Fix up stat handling in LevelUp patch

This commit is contained in:
2025-05-21 20:46:48 +02:00
parent 71163fc589
commit 15460ab629
2 changed files with 50 additions and 45 deletions

View File

@@ -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>

View File

@@ -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) {
Main.LogDebug("Original Str: " + __instance.character.stats.strength, Main.debugStatEntry);
Main.LogDebug("Original Agi: " + __instance.character.stats.agility, Main.debugStatEntry);
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;
originalAgi = __instance.character.stats.agility;
originalDex = __instance.character.stats.dexterity;
originalPag = __instance.character.stats.pagan;
originalSen = __instance.character.stats.sensory;
} }
public static void Postfix(ref LevelUp __instance) { string name = go.name;
float deltaStr = __instance.character.stats.strength - originalStr; if (__instance.statChosen1 != "" || name == __instance.statChosen1) {
float deltaAgi = __instance.character.stats.agility - originalAgi; return true; // Let original method handle this case
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); float num = 0f;
Main.LogDebug("Delta Agi: " + deltaAgi, Main.debugStatEntry); if (name == "Strength") {
Main.LogDebug("Delta Dex: " + deltaDex, Main.debugStatEntry); num = __instance.savedStr;
Main.LogDebug("Delta Pag: " + deltaPag, Main.debugStatEntry); }
Main.LogDebug("Delta Sen: " + deltaSen, Main.debugStatEntry); 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;
}
float resultStr = Main.levelUpStatEntry.Evaluate(deltaStr); Main.LogDebug("Original stat value: " + num, Main.debugStatEntry);
float resultAgi = Main.levelUpStatEntry.Evaluate(deltaAgi); float result = Main.levelUpStatEntry.Evaluate(1f); // Evaluate the increase amount
float resultDex = Main.levelUpStatEntry.Evaluate(deltaDex); Main.LogDebug("Modified increase amount: " + result, Main.debugStatEntry);
float resultPag = Main.levelUpStatEntry.Evaluate(deltaPag);
float resultSen = Main.levelUpStatEntry.Evaluate(deltaSen);
Main.LogDebug("Result Str: " + resultStr, Main.debugStatEntry); // Set the stat with the modified increase
Main.LogDebug("Result Agi: " + resultAgi, Main.debugStatEntry); __instance.character.stats.SetStat(name, num + result);
Main.LogDebug("Result Dex: " + resultDex, Main.debugStatEntry); Links.x.characterSheet.GetStatNums();
Main.LogDebug("Result Pag: " + resultPag, Main.debugStatEntry); Links.x.characterSheet.GetOutput();
Main.LogDebug("Result Sen: " + resultSen, Main.debugStatEntry);
__instance.character.stats.strength = resultStr; // Update UI elements like the original method would
__instance.character.stats.agility = resultAgi; __instance.statTokenUse1.enabled = true;
__instance.character.stats.dexterity = resultDex; __instance.statTokenCounter1.enabled = false;
__instance.character.stats.pagan = resultPag; __instance.statTokenUse1RT.anchoredPosition =
__instance.character.stats.sensory = resultSen; __instance.skillTrs[__instance.GetTransformIndex(name, true)].anchoredPosition;
__instance.statChosen1 = name;
__instance.dragIndicator.SetActive(false);
__instance.draggingToken = false;
__instance.dragToken = null;
return false; // Skip original method
} }
} }