-
Notifications
You must be signed in to change notification settings - Fork 1
/
Geyser_Patch.cs
181 lines (160 loc) · 7.48 KB
/
Geyser_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
using HarmonyLib;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tweaks_Fixes;
using UnityEngine;
namespace Tweaks_Fixes
{
[HarmonyPatch(typeof(Geyser))]
class Geyser_Patch
{
public static GameObject fishToCook;
public static Dictionary<Geyser, Vector3> eruptionForce = new Dictionary<Geyser, Vector3>();
public static Dictionary<Geyser, Vector3> rotationForce = new Dictionary<Geyser, Vector3>();
[HarmonyPrefix]
[HarmonyPatch("Start")]
static bool StartPrefix(Geyser __instance)
{
foreach (Transform childTransform in __instance.transform)
{
if (childTransform.name != "Model")
UnityEngine.Object.Destroy(childTransform.gameObject);
}
GameObject go = Utils.SpawnZeroedAt(__instance.warningSmokeParticles, __instance.transform);
__instance.warningSmokeEmitter = go.GetComponent<ParticleSystem>();
go = Utils.SpawnZeroedAt(__instance.eruptionParticles, __instance.transform);
__instance.eruptionEmitter = go.GetComponent<ParticleSystem>();
__instance.warningSmokeEmitter.Play();
__instance.eruptionEmitter.Stop();
float eruptionIntervalVariance = ConfigToEdit.lavaGeyserEruptionInterval.Value * .5f;
float nextEruptTime = ConfigToEdit.lavaGeyserEruptionInterval.Value + UnityEngine.Random.value * eruptionIntervalVariance;
__instance.Invoke("Erupt", UnityEngine.Random.value * nextEruptTime);
//Main.logger.LogDebug("Geyser Start nextEruptTime " + nextEruptTime);
if (Geyser.consoleCmdRegged)
return false;
DevConsole.RegisterConsoleCommand(__instance, "erupt");
Geyser.consoleCmdRegged = true;
return false;
}
[HarmonyPostfix]
[HarmonyPatch("Start")]
static void StartPostfix(Geyser __instance)
{
int x = (int)__instance.transform.position.x;
int y = (int)__instance.transform.position.y;
int z = (int)__instance.transform.position.z;
//Main.logger.LogDebug("Geyser Start " + x + " " + z);
bool fix = x == 961 && z == 470 || x == 965 && z == 625 || x == -175 && z == 1024 || x == -153 && z == 956 || x == -70 && z == 1024 || x == -67 && z == 1066 || x == -80 && z == 968 || x == -78 && z == 930 || x == -32 && z == 973;
if (fix)
{ // remove safe spot at bottom of geyser
CapsuleCollider cc = __instance.GetComponent<CapsuleCollider>();
if (cc) // 24
cc.height = 30;
}
if (ConfigToEdit.removeLavaGeyserRockParticles.Value)
__instance.StartCoroutine(RemoveRockParticles(__instance));
}
[HarmonyPrefix]
[HarmonyPatch("Erupt")]
static bool EruptPrefix(Geyser __instance)
{
if (__instance.erupting || !__instance.gameObject.activeInHierarchy)
return false;
Vector3 force = CalculateGeyserForce();
eruptionForce[__instance] = force;
float rot = UnityEngine.Random.Range(-force.y, force.y);
rotationForce[__instance] = new Vector3(rot * UnityEngine.Random.value, 0, rot * UnityEngine.Random.value);
//AddDebug("Erupt " + eruptionForce[__instance]);
__instance.erupting = true;
__instance.eruptionEmitter.Play();
__instance.warningSmokeEmitter.Stop();
Utils.PlayEnvSound("event:/env/geyser_erupt", __instance.transform.position);
__instance.Invoke("EndErupt", __instance.eruptionLength);
return false;
}
[HarmonyPostfix]
[HarmonyPatch("Erupt")]
static void EruptPostfix(Geyser __instance)
{
float eruptionIntervalvariance = ConfigToEdit.lavaGeyserEruptionInterval.Value * .5f;
float nextEruptTime = ConfigToEdit.lavaGeyserEruptionInterval.Value + UnityEngine.Random.value * eruptionIntervalvariance;
__instance.Invoke("Erupt", nextEruptTime);
}
private static IEnumerator RemoveRockParticles(Geyser geyser)
{
yield return new WaitForSeconds(1);
Transform t = geyser.transform.Find("xGeyser_Warning(Clone)/xMeshFrag");
if (t)
{
UnityEngine.Object.Destroy(t.gameObject);
//t.gameObject.SetActive(false);
//Main.logger.LogDebug("Geyser xGeyser_Warning activeInHierarchy " + t.gameObject.activeInHierarchy);
}
t = geyser.transform.Find("xGeyser_Warning(Clone)/xAshes");
if (t)
UnityEngine.Object.Destroy(t.gameObject);
t = geyser.transform.Find("xGeyserShort_Eruption(Clone)/xMeshFrag");
if (t)
UnityEngine.Object.Destroy(t.gameObject);
t = geyser.transform.Find("xGeyser_Eruption(Clone)/xMeshFrag");
if (t)
UnityEngine.Object.Destroy(t.gameObject);
t = geyser.transform.Find("xGeyser_Eruption(Clone)/xAshes");
if (t)
UnityEngine.Object.Destroy(t.gameObject);
t = geyser.transform.Find("xGeyserShort_Eruption(Clone)/xAshes");
if (t)
UnityEngine.Object.Destroy(t.gameObject);
}
[HarmonyPostfix]
[HarmonyPatch("OnTriggerStay")]
static void OnTriggerStayPostfix(Geyser __instance, Collider other)
{
if (!__instance.erupting)
return;
GameObject go = Util.GetEntityRoot(other.gameObject);
if (!go)
go = other.gameObject;
//AddDebug("Geyser OnTriggerStay " + go.name);
if (Util.IsEatableFish(go) && Util.IsDead(go))
{
if (fishToCook == go)
{ // wait 1 frame so we dont get 2 cooked fishes when geyser kills fish
fishToCook = null;
//Main.logger.LogDebug("Geyser OnTriggerStay " + go.name);
Player.main.StartCoroutine(Util.Cook(go));
}
else
fishToCook = go;
}
//if (other.gameObject.tag == "Player")
// AddDebug("Geyser OnTriggerStay " + other.gameObject.tag);
//Rigidbody rb = other.GetComponentInChildren<Rigidbody>();
if (ConfigToEdit.lavaGeyserEruptionForce.Value == 0)
return;
Rigidbody rb = go.GetComponentInChildren<Rigidbody>();
if (rb != null)
{
if (eruptionForce.ContainsKey(__instance))
{
//AddDebug("Geyser AddForce " + rb.name + " " + rb.mass);
rb.AddForce(eruptionForce[__instance]);
}
if (rotationForce.ContainsKey(__instance))
rb.AddTorque(rotationForce[__instance]);
}
}
private static Vector3 CalculateGeyserForce()
{
float force = ConfigToEdit.lavaGeyserEruptionForce.Value;
float xForce = UnityEngine.Random.Range(-force, force) * UnityEngine.Random.value;
float yForce = force + force * UnityEngine.Random.value;
float zForce = UnityEngine.Random.Range(-force, force) * UnityEngine.Random.value;
return new Vector3(xForce, yForce, zForce);
}
}
}