Patch_GameScript_GetItemLevel2.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using GadgetCore.API;
  2. using GadgetCore.Util;
  3. using HarmonyLib;
  4. using System;
  5. using System.Reflection;
  6. namespace ItemLevelExtension.Patches
  7. {
  8. [HarmonyPatch(typeof(GameScript))]
  9. [HarmonyPatch("GetItemLevel2")]
  10. [HarmonyGadget("ItemLevelExtension")]
  11. public static class Patch_GameScript_GetItemLevel2
  12. {
  13. [HarmonyPrefix]
  14. public static bool Prefix(GameScript __instance, int exp, ref float[] __result)
  15. {
  16. int level = 1;
  17. int nextLevelPrice = 100;
  18. int i = 0;
  19. while (exp > nextLevelPrice)
  20. {
  21. exp -= nextLevelPrice;
  22. i++;
  23. nextLevelPrice += 75 + i * 100;
  24. level++;
  25. if (level == Core.settingMaxItemLevel)
  26. {
  27. break;
  28. }
  29. }
  30. if (level > Core.settingMaxItemLevel)
  31. level = Core.settingMaxItemLevel;
  32. float progress;
  33. if (level == Core.settingMaxItemLevel)
  34. progress = 1.75f;
  35. else
  36. progress = ((float)exp) / nextLevelPrice * 1.75f;
  37. __result = new float[] { level, progress };
  38. return false;
  39. }
  40. }
  41. }