-
Notifications
You must be signed in to change notification settings - Fork 4
/
VoidSpikesBiome.cs
373 lines (307 loc) · 12.8 KB
/
VoidSpikesBiome.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.IO;
using SMLHelper.V2.Assets;
using SMLHelper.V2.Handlers;
using SMLHelper.V2.Crafting;
using SMLHelper.V2.Interfaces;
using SMLHelper.V2.Json;
using SMLHelper.V2.Utility;
using UnityEngine;
using ReikaKalseki.DIAlterra;
namespace ReikaKalseki.SeaToSea {
public class VoidSpikesBiome : CustomBiome { //FIXME: 3. disappearing spikes 4. custom levi
public static readonly Vector3 end500m = new Vector3(360, -550, 320);//new Vector3(925, -550, -2050);//new Vector3(895, -500, -1995);
public static readonly Vector3 end900m = new Vector3(800, -950, -120);//new Vector3(400, -950, -2275);//new Vector3(457, -900, -2261);
public static readonly double length = Vector3.Distance(end500m, end900m);
public static readonly Vector3 signalLocation = new Vector3(1725, 0, -1250);//new Vector3(1725, 0, -997-100);
//public static readonly double gap = Vector3.Distance(end500m, signalLocation);
private static readonly Vector3 travel = new Vector3(1, 0, -1).setLength(1500);
public static readonly Vector3 voidEndpoint500m = (signalLocation+travel).setY(end500m.y); //2785, -550, -2310
public static readonly Vector3 voidEndpoint900m = voidEndpoint500m+(end900m-end500m); //3225, -950, -2750
public static readonly float biomeVolumeRadius = 200;
public static readonly string biomeName = "Void Spikes";
public static readonly float waterTemperature = 18;
//public static Color? waterColor;
public static readonly Vector3 waterColorFalloff = new Vector3(8, 4, 1);
public static readonly float murkiness = 4.0F;
public static readonly float fogStart = 20;
public static readonly int CLUSTER_COUNT = 120;//104;//88;
public static readonly string PDA_KEY = "voidpod";
public static readonly VoidSpikesBiome instance = new VoidSpikesBiome();
private readonly AtmoFX atmoFX = new AtmoFX();
private readonly VoidSpikes generator;
private readonly VoidDebris debris;
private VoidSpikeWreck wreck;
private VoidSpikes.SpikeCluster entryPoint;
private SignalManager.ModSignal signal;
private bool delayTeleportOutUntilEnterSeamoth = false;
private bool delayTeleportInUntilEnterSeamoth = false;
private VoidSpikesBiome() : base(biomeName, 0.4F) {
generator = new VoidSpikes((end500m+end900m)/2);
generator.count = CLUSTER_COUNT;
//generator.scaleXZ = 16;
//generator.scaleY = 6;
generator.generateLeviathan = false;
generator.generateAux = true;
generator.fishCount = generator.count*20;
generator.positionValidity = isValidSpikeLocation;
//generator.depthCallback = getSpikeDepth;
generator.spikeLocationProvider = getSpikeLocation;
generator.shouldRerollCounts = false;
debris = new VoidDebris(signalLocation+Vector3.down*0.2F);
}
public override VanillaMusic[] getMusicOptions() {
return new VanillaMusic[]{VanillaMusic.DUNES, VanillaMusic.BKELP, VanillaMusic.KOOSH, VanillaMusic.DEEPGRAND};
}
public override float getSunScale(float orig) {
return 0;
}
public override float getFogStart(float orig) {
return fogStart;
}
public override float getMurkiness(float orig) {
return murkiness;
}
public override Vector3 getColorFalloff(Vector3 orig) {
return waterColorFalloff;
}
public override Color getWaterColor(Color orig) {
return orig;
}
public override void register() {
//SpikeCache.load();
//GenUtil.registerWorldgen(generator);
int seed = SNUtil.getInstallSeed();
IEnumerable<WorldGenerator> gens = generator.split(seed);
foreach (VoidSpikes.SpikeCluster gen in gens) {
GenUtil.registerWorldgen(gen);
if (entryPoint == null || Vector3.Distance(gen.position, end500m) < Vector3.Distance(entryPoint.position, end500m)) {
entryPoint = gen;
}
}
wreck = new VoidSpikeWreck(entryPoint.getRootLocation()+Vector3.up*0.1F);
entryPoint.needsCenterSpace = true;
entryPoint.additionalGen = wreck.generate;
GenUtil.registerWorldgen(debris);
XMLLocale.LocaleEntry e = SeaToSeaMod.signalLocale.getEntry("voidpod");
signal = SignalManager.createSignal(e);
//signal.pdaEntry.addSubcategory("AuroraSurvivors");
signal.addRadioTrigger(e.getField<string>("sound"));
signal.register("32e48451-8e81-428e-9011-baca82e9cd32", signalLocation);
signal.addWorldgen(UnityEngine.Random.rotationUniform);
atmoFX.Patch();
GenUtil.registerWorldgen(PDAManager.getPage(PDA_KEY).getPDAClassID(), signalLocation+Vector3.down*1.25F, UnityEngine.Random.rotationUniform);
//GenUtil.registerWorldgen(leviathan.ClassID, end900m, Vector3.zero);
for (float i = -100; i <= length+100; i += biomeVolumeRadius*0.5F) {
addAtmoFX(end500m+(end900m-end500m).normalized*i);
}
addAtmoFX(end900m);
debris.init();
//IngameMenuHandler.Main.RegisterOnSaveEvent(SpikeCache.save);
}
public override mset.Sky getSky() {
return WorldUtil.getSkybox(VanillaBiomes.VOID.getIDs().First());
}
public override bool isCaveBiome() {
return false;
}
public override bool existsInSeveralPlaces() {
return false;
}
private void addAtmoFX(Vector3 pos) {
GenUtil.registerWorldgen(atmoFX.ClassID, pos, Quaternion.identity, go => go.transform.localScale = Vector3.one*(100+biomeVolumeRadius));
}
public void tickPlayer(Player ep) {
Vector3 pos = ep.transform.position;
//SNUtil.writeToChat("Dist @ "+pos+" = "+dist);
/*
if (dist < biomeVolumeRadius+75) {
while (AtmosphereDirector.main.priorityQueue.Count > 0)
AtmosphereDirector.main.PopSettings(AtmosphereDirector.main.priorityQueue[AtmosphereDirector.main.priorityQueue.Count-1]);
AtmosphereDirector.main.PushSettings(AtmosphereDirector.main.defaultSettings);
}*/
VoidSpikeLeviathanSystem.instance.tick(ep);
if (ep.currentSub == null && UnityEngine.Random.Range(0, (int)(10/Time.timeScale)) == 0) {
if (Vector3.Distance(pos, end500m) <= biomeVolumeRadius/2) {
if (SeaToSeaMod.config.getBoolean(C2CConfig.ConfigEntries.PROMPTS))
PDAMessagePrompts.instance.trigger(PDAMessages.getAttr(PDAMessages.Messages.VoidSpike).key);
}
else {
tickTeleportCheck(ep);
}
}
}
internal void tickTeleportCheck(MonoBehaviour go) {
Vector3 pos = go.transform.position;
double dist = getDistanceToBiome(pos, false);
float f1 = biomeVolumeRadius+25;
if (dist >= f1 && dist <= f1+20) {
Vector3 tgt = (voidEndpoint500m+(pos-end500m).addLength(30)).setY(pos.y);
if (go is Player && !delayTeleportOutUntilEnterSeamoth) {
SNUtil.teleportPlayer((Player)go, tgt);
SNUtil.log("Teleported player back from biome: "+tgt);
}
else if (go is C2CMoth) {
delayTeleportOutUntilEnterSeamoth = true;
}
}
else {
dist = MathUtil.getDistanceToLineSegment(pos, voidEndpoint500m, voidEndpoint900m);
if (dist <= f1) {
Vector3 tgt = (end500m+(pos-voidEndpoint500m).addLength(-30)).setY(pos.y);
if (go is Player && !delayTeleportInUntilEnterSeamoth) {
SNUtil.teleportPlayer((Player)go, tgt);
SNUtil.log("Teleported player to biome: "+tgt);
foreach (GameObject levi in VoidGhostLeviathansSpawner.main.spawnedCreatures) {
Vector3 delta = levi.transform.position-tgt;
levi.transform.position = tgt+delta;
}
}
else if (go is C2CMoth) {
delayTeleportInUntilEnterSeamoth = true;
}
}
}
}
public void onSeamothEntered(SeaMoth sm, Player ep) {
Vector3 pos = sm.transform.position;
if (delayTeleportInUntilEnterSeamoth) {
Vector3 tgt = (voidEndpoint500m+(pos-end500m).addLength(30)).setY(pos.y);
//SNUtil.writeToChat("Delayed tele in");
ep.transform.position = tgt;
sm.transform.position = tgt;
SNUtil.log("Teleported player to biome: "+tgt);
delayTeleportInUntilEnterSeamoth = false;
}
else if (delayTeleportOutUntilEnterSeamoth) {
//SNUtil.writeToChat("Delayed tele out");
Vector3 tgt = (end500m+(pos-voidEndpoint500m).addLength(-30)).setY(pos.y);
ep.transform.position = tgt;
sm.transform.position = tgt;
SNUtil.log("Teleported player back from biome: "+tgt);
delayTeleportOutUntilEnterSeamoth = false;
}
}
public void onWorldStart() {
//AtmosphereDirector.main.debug = true;
if (isInBiome(Player.main.transform.position) && !anySeamothsInBiome()) {
delayTeleportOutUntilEnterSeamoth = true;
}
}
internal bool anySeamothsInBiome() {
foreach (SeaMoth sm in UnityEngine.Object.FindObjectsOfType<SeaMoth>()) {
if (Vector3.Distance(sm.transform.position, end500m) <= biomeVolumeRadius+40)
return true;
}
return false;
}
public void activateSignal() {
SNUtil.log("Activating void signal");
signal.activate(18);
}
public void fireRadio() {
signal.fireRadio();
}
public bool isRadioFired() {
return signal.isRadioFired();
}
public string getSignalKey() {
return signal.storyGate;
}
private bool isValidSpikeLocation(Vector3 vec) {
return isInBiome(vec) && GenUtil.allowableGenBounds.Contains(vec+new Vector3(0, 0, -40)); //safety buffer
}
public override bool isInBiome(Vector3 vec) {
//SNUtil.log("Checking spike validity @ "+vec+" (dist = "+dist+")/200; D500="+Vector3.Distance(end500m, vec)+"; D900="+Vector3.Distance(end900m, vec));
return vec.y < -320 && getDistanceToBiome(vec, false) <= biomeVolumeRadius+150;
}
public override double getDistanceToBiome(Vector3 vec) {
return getDistanceToBiome(vec, true);
}
public double getDistanceToBiome(Vector3 vec, bool includeVoidSide) {
double ret = MathUtil.getDistanceToLineSegment(vec, end500m, end900m);// endcap dist either < L
if (includeVoidSide)
ret = Math.Min(ret, MathUtil.getDistanceToLineSegment(vec, voidEndpoint500m, voidEndpoint900m));
return ret;
}
private double getSpikeDepth(Vector3 vec) {
double d1 = Vector3.Distance(end500m, vec)/length;
//double d2 = Vector3.Distance(end900m, vec)/length;
double interp = MathUtil.linterpolate(d1, 0, length, end500m.y, end900m.y);
return MathUtil.getRandomPlusMinus((float)interp, 40F);
}
private Vector3 getSpikeLocation() {
Vector3 init = MathUtil.interpolate(end500m, end900m, UnityEngine.Random.Range(0F, 1F));
if (UnityEngine.Random.Range(0, 9) == 0)
init = end900m;
return MathUtil.getRandomVectorAround(init, new Vector3(160, 40, 160));
}
public bool isPlayerInLeviathanZone(Vector3 pos) {
return isInBiome(pos) && Vector3.Distance(pos, end900m) <= biomeVolumeRadius*1.5F;
}
public Vector3 getPDALocation() {
return wreck.getPDALocation();
}
public static void checkAndAddWaveBob(SkyApplier c) {
checkAndAddWaveBob(c.gameObject, false);
}
internal static WaveBob checkAndAddWaveBob(GameObject go, bool force) {
if (C2CHooks.skipWaveBob)
return null;
if (!force) {
double distsq = (go.transform.position-signalLocation).sqrMagnitude;
if (distsq > 18*18)
return null;
if (go.GetComponentInParent<Creature>() != null || go.GetComponentInParent<Player>() != null)
return null;
if (go.GetComponentInParent<Vehicle>() != null)
return null;
}
WaveBob b = go.EnsureComponent<WaveBob>();
b.rootPosition = go.transform.position;
b.speed = UnityEngine.Random.Range(1.75F, 2.5F);
b.amplitude = UnityEngine.Random.Range(0.15F, 0.3F);
b.speed2Ratio = UnityEngine.Random.Range(2.5F, 3F);
b.amplitude2Ratio = UnityEngine.Random.Range(0.05F, 0.1F);
if (b.rootPosition.y <= -1.25) {
b.amplitude *= 0.25F;
b.speed *= 0.5F;
}
if (go.GetComponentInChildren<BlueprintHandTarget>() != null) {
b.amplitude *= 0.5F;
b.speed *= 0.4F;
}
LargeWorldEntity lw = go.EnsureComponent<LargeWorldEntity>();
if (lw.cellLevel != LargeWorldEntity.CellLevel.Global)
lw.cellLevel = LargeWorldEntity.CellLevel.Batch;
return b;
}
public static GameObject spawnEntity(string pfb) {
GameObject go = ObjectUtil.createWorldObject(pfb);
if (go == null)
return go;
//DestroyDetector dd = go.EnsureComponent<DestroyDetector>();
LargeWorldEntity lw = go.EnsureComponent<LargeWorldEntity>();
//lw.cellLevel = LargeWorldEntity.CellLevel.Global;
return go;
}
}
class AtmoFX : GenUtil.CustomPrefabImpl {
internal AtmoFX() : base("voidspikeFX", "58b3c65d-1915-497d-b652-f6beba004def") { //blood kelp
}
public override void prepareGameObject(GameObject go, Renderer[] r) {
LargeWorldEntity lw = go.EnsureComponent<LargeWorldEntity>();
lw.cellLevel = LargeWorldEntity.CellLevel.Batch;
AtmosphereVolume vol = go.EnsureComponent<AtmosphereVolume>();
vol.affectsVisuals = true;
vol.enabled = true;
vol.fogMaxDistance = 100;
vol.fogStartDistance = 20;
vol.fogColor = new Color(vol.fogColor.r*0.75F, vol.fogColor.g, Mathf.Min(1, vol.fogColor.b*1.25F), vol.fogColor.a);
vol.overrideBiome = VoidSpikesBiome.biomeName;
}
}
}