-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCraft_Patch.cs
182 lines (169 loc) · 7.49 KB
/
Craft_Patch.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using static ErrorMessage;
namespace Tweaks_Fixes
{
class Craft_Patch
{
static bool crafting = false;
static List<Battery> batteriesUsedForCrafting = new List<Battery>();
static float timeDecayStart = 0f;
[HarmonyPatch(typeof(CrafterLogic), "Craft")]
class CrafterLogic_Craft_Patch
{
static void Prefix(CrafterLogic __instance, TechType techType, ref float craftTime)
{
//AddDebug("CrafterLogic Craft " + techType + " craftTime " + craftTime);
if (ConfigMenu.craftTimeMult.Value != 1f)
craftTime *= ConfigMenu.craftTimeMult.Value;
}
}
[HarmonyPatch(typeof(CrafterLogic), "NotifyCraftEnd")]
class CrafterLogic_NotifyCraftEnd_Patch
{
static void Postfix(CrafterLogic __instance, GameObject target, TechType techType)
{
//AddDebug("CrafterLogic NotifyCraftEnd timeDecayStart " + timeDecayStart);
if (timeDecayStart > 0)
{
//AddDebug("CrafterLogic NotifyCraftEnd timeDecayStart" + timeDecayStart);
Eatable eatable = target.GetComponent<Eatable>();
if (eatable)
eatable.timeDecayStart = timeDecayStart;
}
Battery battery = target.GetComponent<Battery>();
if (battery)
{
//Main.logger.LogDebug("CrafterLogic NotifyCraftEnd battery capacity " + battery._capacity);
//AddDebug("crafterOpen");
//if (ConfigMenu.batteryChargeMult.Value != 1f)
// battery._capacity *= ConfigMenu.batteryChargeMult.Value;
if (ConfigMenu.craftedBatteryCharge.Value != 1)
{
float mult = ConfigMenu.craftedBatteryCharge.Value * .01f;
battery._charge = battery._capacity * mult;
}
if (batteriesUsedForCrafting.Count == 2)
{
//AddDebug("batteries.Count == 2");
float averageCharge = Mathf.Lerp(batteriesUsedForCrafting[0].charge, batteriesUsedForCrafting[1].charge, .5f);
float newCharge = Util.NormalizeToRange(averageCharge, 0, batteriesUsedForCrafting[0].capacity, 0, battery._capacity);
if (newCharge < battery._charge)
battery._charge = newCharge;
}
}
timeDecayStart = 0f;
batteriesUsedForCrafting.Clear();
crafting = false;
}
}
[HarmonyPatch(typeof(Inventory))]
class Inventory_Patch
{
[HarmonyPrefix]
[HarmonyPatch("ConsumeResourcesForRecipe")]
static void Prefix(Inventory __instance, TechType techType, uGUI_IconNotifier.AnimationDone endFunc = null)
{
crafting = true;
//AddDebug("ConsumeResourcesForRecipe");
}
[HarmonyPostfix]
[HarmonyPatch("OnRemoveItem")]
static void OnRemoveItemPostfix(Inventory __instance, InventoryItem item)
{
//AddDebug("OnRemoveItem " + item.item.GetTechName());
if (crafting)
{
Battery battery = item.item.GetComponent<Battery>();
if (battery)
batteriesUsedForCrafting.Add(battery);
if (Util.IsEatableFish(item.item.gameObject))
{
Eatable eatable = item.item.GetComponent<Eatable>();
//AddDebug(" OnRemoveItem timeDecayStart " + eatable.timeDecayStart);
//AddDebug(" NotifyRemoveItem waterValue " + eatable.GetWaterValue() + " " + eatable.GetFoodValue());
//waterValueMult = eatable.GetWaterValue() / eatable.waterValue;
//foodValueMult = eatable.GetFoodValue() / eatable.foodValue;
timeDecayStart = eatable.timeDecayStart;
}
//else
// timeDecayStart = 0f;
}
}
}
[HarmonyPatch(typeof(Constructable), "GetConstructInterval")]
class Constructable_GetConstructInterval_Patch
{
static void Postfix(ref float __result)
{
if (NoCostConsoleCommand.main.fastBuildCheat)
return;
//AddDebug("GetConstructInterval " );
__result *= ConfigMenu.buildTimeMult.Value;
}
}
[HarmonyPatch(typeof(EnergyMixin), "OnCraftEnd")]
public class NoBattery
{
private static void Prefix(EnergyMixin __instance, TechType techType)
{ // applies to tools and vehicles
//AddDebug("EnergyMixin OnCraftEnd " + techType);
if (!ConfigToEdit.craftWithoutBattery.Value || techType == TechType.MapRoomCamera)
return;
__instance.defaultBattery = TechType.None;
}
}
/*
//[HarmonyPatch(typeof(CrafterLogic), "TryPickupSingle")]
class CrafterLogic_TryPickupSingle_Patch
{
static bool Prefix(CrafterLogic __instance, TechType techType, ref bool __result)
{
//craftingStart = false;
AddDebug("CrafterLogic TryPickupSingle");
Inventory main = Inventory.main;
bool flag = false;
GameObject original = CraftData.GetPrefabForTechType(techType);
if (original == null)
{
original = Utils.genericLootPrefab;
flag = true;
}
if (original != null)
{
Pickupable component1 = original.GetComponent<Pickupable>();
if (component1 != null)
{
Vector2int itemSize = CraftData.GetItemSize(component1.GetTechType());
if (main.HasRoomFor(itemSize.x, itemSize.y))
{
GameObject gameObject = UnityEngine.Object.Instantiate(original);
Pickupable pickupable = gameObject.GetComponent<Pickupable>();
if (flag)
pickupable.SetTechTypeOverride(techType, true);
main.ForcePickup(pickupable);
// ForcePickup now before NotifyCraftEnd
CrafterLogic.NotifyCraftEnd(gameObject, __instance.craftingTechType);
Player.main.PlayGrab();
__result = true;
return false;
}
AddMessage(Language.main.Get("InventoryFull"));
__result = false;
return false;
}
Debug.LogErrorFormat("Can't find Pickupable component on prefab for TechType.{0}", techType);
__result = true;
return false;
}
Debug.LogErrorFormat("Can't find prefab for TechType.{0}", techType);
__result = true;
return false;
}
}
/*/
}
}