Implement auto loot

This commit is contained in:
2024-12-31 15:21:57 +01:00
parent 983aaa68e6
commit cd104d142e
3 changed files with 30 additions and 8 deletions

View File

@@ -13,6 +13,7 @@ namespace CykaRaider {
public static ConfigEntry<int> lootTimeAdder;
public static ConfigEntry<float> maxStackMultiplier;
public static ConfigEntry<bool> autoLoot;
public static ConfigEntry<bool> debugMode;
@@ -20,6 +21,7 @@ namespace CykaRaider {
debugMode = Config.Bind("General", "Debug Mode", false, new ConfigDescription("Debug Mode"));
lootTimeAdder = Config.Bind("General", "Loot Time Adder", 0, new ConfigDescription("Loot Time Adder"));
maxStackMultiplier = Config.Bind("General", "Max Stack Multiplier", 1f, new ConfigDescription("Max Stack Multiplier"));
autoLoot = Config.Bind("General", "Auto Loot", false, new ConfigDescription("Auto Loot"));
Logger.LogInfo("Cyka mod loaded");
HarmonyFileLog.Enabled = true;

View File

@@ -52,6 +52,9 @@
<Reference Include="UnityEngine.CoreModule">
<HintPath>$(GAME_MANAGED)/UnityEngine.CoreModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>$(GAME_MANAGED)/UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="XRL">
<HintPath>$(GAME_MANAGED)/Assembly-CSharp.dll</HintPath>
</Reference>

View File

@@ -1,5 +1,6 @@
using System;
using System;
using HarmonyLib;
using UnityEngine.UI;
namespace CykaRaider
{
@@ -23,18 +24,34 @@ namespace CykaRaider
[HarmonyPostfix]
[HarmonyPatch(typeof(DataHub), "GetFixedData")]
static void xpMultiplier(DataHub __instance) {
for (int i = 0; i < __instance.itemDataDic.Count; i++) {
var itemData = __instance.itemDataDic[i];
if (itemData.maxStack > 0) {
static void maxStackMultiplier(DataHub __instance) {
foreach (var itemData in __instance.itemDataDic) {
if (itemData.Value.maxStack > 0) {
if (Main.debugMode.Value)
Console.WriteLine("CykaRaider: GetFixedData: Old maxStack {0}", itemData.maxStack);
itemData.maxStack = (int)(itemData.maxStack * Main.maxStackMultiplier.Value);
Console.WriteLine("CykaRaider: GetFixedData: Old maxStack {0}", itemData.Value.maxStack);
itemData.Value.maxStack = (int)(itemData.Value.maxStack * Main.maxStackMultiplier.Value);
if (Main.debugMode.Value)
Console.WriteLine("CykaRaider: GetFixedData: New maxStack {0}", itemData.maxStack);
Console.WriteLine("CykaRaider: GetFixedData: New maxStack {0}", itemData.Value.maxStack);
}
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(MyBagControl), "GetAllButtonShow")]
static void autoLoot(MyBagControl __instance) {
if (Main.autoLoot.Value) {
if (Main.debugMode.Value)
Console.WriteLine("CykaRaider: autoLoot: AutoLoot is enabled");
var trav = Traverse.Create(__instance);
var button = trav.Field("getAll_BT").GetValue<Button>();
button.onClick.Invoke();
if (Main.debugMode.Value)
Console.WriteLine("CykaRaider: autoLoot: Button clicked");
__instance.BeClosed();
if (Main.debugMode.Value)
Console.WriteLine("CykaRaider: autoLoot: Bag closed");
}
}
// [HarmonyPrefix]
// [HarmonyPatch(typeof(XRL.World.Parts.Experience), "HandleEvent")]
// static void xpMultiplier(ref AwardedXPEvent E) {