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">
<HintPath>$(GAME_MANAGED)/UnityEngine.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>$(GAME_MANAGED)/UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>$(GAME_MANAGED)/UnityEngine.CoreModule.dll</HintPath>
</Reference>

View File

@@ -5,6 +5,8 @@ using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using HarmonyLib.Tools;
using UnityEngine;
using UnityEngine.UI;
namespace BanquetForCyka {
[BepInPlugin(PluginGuid, PluginName, PluginVersion)]
@@ -82,56 +84,56 @@ namespace BanquetForCyka {
[HarmonyPatch(typeof(LevelUp), "ClickedStat")]
public class Actions_ClickedStat {
private static float originalStr;
private static float originalAgi;
private static float originalDex;
private static float originalPag;
private static float originalSen;
public static bool Prefix(ref LevelUp __instance, GameObject go) {
if (__instance.levelUpSkills || !__instance.open) {
return true; // Let original method handle this case
}
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);
string name = go.name;
if (__instance.statChosen1 != "" || name == __instance.statChosen1) {
return true; // Let original method handle this case
}
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;
}
float num = 0f;
if (name == "Strength") {
num = __instance.savedStr;
}
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) {
float deltaStr = __instance.character.stats.strength - originalStr;
float deltaAgi = __instance.character.stats.agility - originalAgi;
float deltaDex = __instance.character.stats.dexterity - originalDex;
float deltaPag = __instance.character.stats.pagan - originalPag;
float deltaSen = __instance.character.stats.sensory - originalSen;
Main.LogDebug("Original stat value: " + num, Main.debugStatEntry);
float result = Main.levelUpStatEntry.Evaluate(1f); // Evaluate the increase amount
Main.LogDebug("Modified increase amount: " + result, Main.debugStatEntry);
Main.LogDebug("Delta Str: " + deltaStr, Main.debugStatEntry);
Main.LogDebug("Delta Agi: " + deltaAgi, Main.debugStatEntry);
Main.LogDebug("Delta Dex: " + deltaDex, Main.debugStatEntry);
Main.LogDebug("Delta Pag: " + deltaPag, Main.debugStatEntry);
Main.LogDebug("Delta Sen: " + deltaSen, Main.debugStatEntry);
// Set the stat with the modified increase
__instance.character.stats.SetStat(name, num + result);
Links.x.characterSheet.GetStatNums();
Links.x.characterSheet.GetOutput();
float resultStr = Main.levelUpStatEntry.Evaluate(deltaStr);
float resultAgi = Main.levelUpStatEntry.Evaluate(deltaAgi);
float resultDex = Main.levelUpStatEntry.Evaluate(deltaDex);
float resultPag = Main.levelUpStatEntry.Evaluate(deltaPag);
float resultSen = Main.levelUpStatEntry.Evaluate(deltaSen);
// Update UI elements like the original method would
__instance.statTokenUse1.enabled = true;
__instance.statTokenCounter1.enabled = false;
__instance.statTokenUse1RT.anchoredPosition =
__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);
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;
return false; // Skip original method
}
}
@@ -144,4 +146,4 @@ namespace BanquetForCyka {
Main.LogDebug("Modified amount: " + __result, Main.debugLevelUpEntry);
}
}
}
}