-
Notifications
You must be signed in to change notification settings - Fork 1
/
Gravsphere_Patch.cs
110 lines (98 loc) · 3.5 KB
/
Gravsphere_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
using HarmonyLib;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using static ErrorMessage;
namespace Tweaks_Fixes
{ // not tested with more than 1 grav trap
//[HarmonyPatch(typeof(GasPod))]
class GasPod_Patch
{
//[HarmonyPatch(nameof(GasPod.OnDrop))]
public static void Prefix(GasPod __instance)
{
if (Gravsphere_Patch.gasPods.Contains(__instance))
{
//AddDebug("GasPod.OnDrop ");
Gravsphere_Patch.gasPods.Remove(__instance);
__instance.grabbedByPropCannon = false;
}
}
}
[HarmonyPatch(typeof(Gravsphere))]
public class Gravsphere_Patch
{
static public Gravsphere gravSphere;
static public HashSet<Pickupable> gravSphereFish = new HashSet<Pickupable>();
static public HashSet<GasPod> gasPods = new HashSet<GasPod>();
//static public HashSet<Pickupable> gravSphereFish = new HashSet<Pickupable>();
static public HashSet<TechType> gravTrappable = new HashSet<TechType>();
[HarmonyPostfix] [HarmonyPatch(nameof(Gravsphere.IsValidTarget))]
public static void IsValidTarget(Gravsphere __instance, GameObject obj, ref bool __result)
{
if (__result)
return;
TechType t = CraftData.GetTechType(obj);
if (t != TechType.None && gravTrappable.Contains(t))
__result = true;
}
[HarmonyPostfix] [HarmonyPatch(nameof(Gravsphere.AddAttractable))]
public static void AddAttractable(Gravsphere __instance, Rigidbody r)
{
gravSphere = __instance;
GasPod gp = r.gameObject.GetComponent<GasPod>();
if (gp)
{
gp.grabbedByPropCannon = true;
gasPods.Add(gp);
}
else
{
Pickupable p = r.GetComponent<Pickupable>();
//AddDebug("AddAttractable ");
if (p)
{
gravSphereFish.Add(p);
}
}
}
[HarmonyPostfix] [HarmonyPatch(nameof(Gravsphere.ClearAll))]
public static void ClearAll(Gravsphere __instance)
{
//AddDebug("ClearAll ");
foreach (GasPod gp in gasPods)
{
gp.grabbedByPropCannon = false;
}
gasPods = new HashSet<GasPod>();
gravSphereFish = new HashSet<Pickupable>();
}
[HarmonyPrefix] [HarmonyPatch(nameof(Gravsphere.OnTriggerEnter))]
public static bool OnTriggerEnter(Gravsphere __instance, Collider collider)
{
InventoryItem item = Inventory.main.quickSlots.heldItem;
if (item != null && item.item.transform.root.gameObject == collider.transform.root.gameObject)
{
//AddDebug("OnTriggerEnter heldItem ");
return false;
}
return true;
}
[HarmonyPatch(typeof(Pickupable), "Pickup")]
class Pickupable_Pickup_Patch
{
public static void Postfix(Pickupable __instance)
{
if (gravSphereFish.Contains(__instance))
{
int num = gravSphere.attractableList.IndexOf(__instance.GetComponent<Rigidbody>());
if (num == -1)
return;
//AddDebug("Pick up gravSphere");
gravSphere.removeList.Add(num);
}
}
}
}
}