-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cs
332 lines (296 loc) · 16.5 KB
/
Main.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
using SRML;
using SRML.SR;
using SRML.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
using LargoLibrary;
using System.Diagnostics;
using UnityEngine.Assertions.Must;
using MonomiPark.SlimeRancher.DataModel;
using System.Security.Policy;
using System.Runtime.CompilerServices;
using System.IO;
using MonomiPark.SlimeRancher.Regions;
namespace MoreLargos
{
public class Main : ModEntryPoint
{
private static int bottomColorNameId = Shader.PropertyToID("_BottomColor");
private static int middleColorNameId = Shader.PropertyToID("_MiddleColor");
private static int topColorNameId = Shader.PropertyToID("_TopColor");
private static Version RequiredLLVersion = new Version(1, 3);
public static SlimeAppearanceDirector mainMenuDirector;
public static SlimeAppearanceDirector saveGameDirector;
public static SlimeDiet.EatMapEntry referenceEatMap;
public static List<LargoObject> largoObjects = new List<LargoObject>();
public override void PreLoad()
{
HarmonyInstance.PatchAll();
}
public override void Load()
{
if (!SRModLoader.IsModPresent("largolibrary"))
{
throw new Exception("Largo Library is not present, but is required!");
}
if (LargoLibrary.Main.Version == null || RequiredLLVersion > LargoLibrary.Main.Version)
{
throw new Exception("Largo Library version is under the required version! Required version: " + RequiredLLVersion.ToString());
}
SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(Identifiable.Id.PUDDLE_SLIME).Diet.Produces = new Identifiable.Id[1]
{
Identifiable.Id.PUDDLE_PLORT
};
SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(Identifiable.Id.FIRE_SLIME).Diet.Produces = new Identifiable.Id[1]
{
Identifiable.Id.FIRE_PLORT
};
SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(Identifiable.Id.QUICKSILVER_SLIME).Diet.Produces = new Identifiable.Id[1]
{
Identifiable.Id.QUICKSILVER_PLORT
};
SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(Identifiable.Id.GLITCH_SLIME).Diet.Produces = new Identifiable.Id[1]
{
Identifiable.Id.NONE
};
foreach (SlimeDiet.EatMapEntry entry in SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(Identifiable.Id.PINK_SLIME).Diet.EatMap)
{
if (entry.becomesId == Identifiable.Id.PINK_TABBY_LARGO)
{
referenceEatMap = entry;
break;
}
}
SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(Identifiable.Id.PUDDLE_SLIME).CanLargofy = true;
SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(Identifiable.Id.FIRE_SLIME).CanLargofy = true;
SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(Identifiable.Id.QUICKSILVER_SLIME).CanLargofy = true;
SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(Identifiable.Id.LUCKY_SLIME).CanLargofy = true;
SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(Identifiable.Id.GLITCH_SLIME).CanLargofy = true;
Type type = typeof(Id);
FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
foreach (FieldInfo field in fields)
{
if (field.Name.Contains("_PUDDLE_SLIME"))
{
largoObjects.Add(new LargoObject
{
sharedSlimeId = Identifiable.Id.PUDDLE_SLIME,
baseSlimeId = (Identifiable.Id)Enum.Parse(typeof(Identifiable.Id), Enum.Parse(typeof(Identifiable.Id), field.Name, true).ToString().Replace("_PUDDLE", ""), true),
largoId = (Identifiable.Id)Enum.Parse(typeof(Identifiable.Id), field.Name, true)
});
}
else if (field.Name.Contains("_FIRE_SLIME"))
{
largoObjects.Add(new LargoObject
{
sharedSlimeId = Identifiable.Id.FIRE_SLIME,
baseSlimeId = (Identifiable.Id)Enum.Parse(typeof(Identifiable.Id), Enum.Parse(typeof(Identifiable.Id), field.Name, true).ToString().Replace("_FIRE", ""), true),
largoId = (Identifiable.Id)Enum.Parse(typeof(Identifiable.Id), field.Name, true)
});
}
else if (field.Name.Contains("_GLITCH_SLIME"))
{
largoObjects.Add(new LargoObject
{
sharedSlimeId = Identifiable.Id.GLITCH_SLIME,
baseSlimeId = (Identifiable.Id)Enum.Parse(typeof(Identifiable.Id), Enum.Parse(typeof(Identifiable.Id), field.Name, true).ToString().Replace("_GLITCH", ""), true),
largoId = (Identifiable.Id)Enum.Parse(typeof(Identifiable.Id), field.Name, true)
});
}
else if (field.Name.Contains("_LUCKY_SLIME"))
{
largoObjects.Add(new LargoObject
{
sharedSlimeId = Identifiable.Id.LUCKY_SLIME,
baseSlimeId = (Identifiable.Id)Enum.Parse(typeof(Identifiable.Id), Enum.Parse(typeof(Identifiable.Id), field.Name, true).ToString().Replace("_LUCKY", ""), true),
largoId = (Identifiable.Id)Enum.Parse(typeof(Identifiable.Id), field.Name, true)
});
}
else if (field.Name.Contains("_GOLD_SLIME"))
{
largoObjects.Add(new LargoObject
{
sharedSlimeId = Identifiable.Id.GOLD_SLIME,
baseSlimeId = (Identifiable.Id)Enum.Parse(typeof(Identifiable.Id), Enum.Parse(typeof(Identifiable.Id), field.Name, true).ToString().Replace("_GOLD", ""), true),
largoId = (Identifiable.Id)Enum.Parse(typeof(Identifiable.Id), field.Name, true)
});
}
}
foreach (LargoObject largoObject in largoObjects)
{
switch (largoObject.sharedSlimeId)
{
case Identifiable.Id.PUDDLE_SLIME:
CreatePuddleLargo(largoObject.sharedSlimeId, largoObject.baseSlimeId, largoObject.largoId);
break;
case Identifiable.Id.FIRE_SLIME:
CreateFireLargo(largoObject.sharedSlimeId, largoObject.baseSlimeId, largoObject.largoId);
break;
case Identifiable.Id.GLITCH_SLIME:
CreateGlitchLargo(largoObject.sharedSlimeId, largoObject.baseSlimeId, largoObject.largoId);
break;
case Identifiable.Id.LUCKY_SLIME:
CreateLuckyLargo(largoObject.sharedSlimeId, largoObject.baseSlimeId, largoObject.largoId);
break;
case Identifiable.Id.GOLD_SLIME:
CreateGoldLargo(largoObject.sharedSlimeId, largoObject.baseSlimeId, largoObject.largoId);
break;
};
}
//SlimeEat.foodGroupIds.TryGetValue(SlimeEat.FoodGroup.PLORTS, out Identifiable.Id[] plortArray);
//List<Identifiable.Id> plortList = plortArray.ToList();
//plortList.Add(Identifiable.Id.PUDDLE_PLORT);
//plortList.Add(Identifiable.Id.FIRE_PLORT);
//SlimeEat.foodGroupIds.Remove(SlimeEat.FoodGroup.PLORTS);
//SlimeEat.foodGroupIds.Add(SlimeEat.FoodGroup.PLORTS, plortList.ToArray());
}
public override void PostLoad()
{
Identifiable.Id id = Identifiable.Id.NONE;
foreach (LargoObject largoObject in largoObjects)
{
if (largoObject.largoId.ToString() != "PUDDLE_PUDDLE_SLIME")
{
if (SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(largoObject.baseSlimeId).Diet.Produces.Length != 0)
{
SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(largoObject.sharedSlimeId).Diet.EatMap.Add(new SlimeDiet.EatMapEntry
{
becomesId = largoObject.largoId,
eats = SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(largoObject.baseSlimeId).Diet.Produces[0],
driver = referenceEatMap.driver,
minDrive = referenceEatMap.minDrive,
extraDrive = referenceEatMap.extraDrive
});
}
if (SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(largoObject.sharedSlimeId).Diet.Produces.Length != 0)
{
SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(largoObject.baseSlimeId).Diet.EatMap.Add(new SlimeDiet.EatMapEntry
{
becomesId = largoObject.largoId,
eats = SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(largoObject.sharedSlimeId).Diet.Produces[0],
driver = referenceEatMap.driver,
minDrive = referenceEatMap.minDrive,
extraDrive = referenceEatMap.extraDrive
});
}
}
GameObject largoGameobject = SRSingleton<GameContext>.Instance.LookupDirector.GetPrefab(largoObject.largoId);
if (largoGameobject.GetComponent<LuckySlimeFlee>() != null)
{
UnityEngine.Object.Destroy(largoGameobject.GetComponent<LuckySlimeFlee>());
}
if (largoGameobject.GetComponent<GoldSlimeFlee>() != null)
{
UnityEngine.Object.Destroy(largoGameobject.GetComponent<GoldSlimeFlee>());
}
if (largoGameobject.GetComponent<GlitchSlimeFlee>() != null)
{
UnityEngine.Object.Destroy(largoGameobject.GetComponent<GlitchSlimeFlee>());
}
}
}
public static bool CreatePuddleLargo(Identifiable.Id slime1, Identifiable.Id slime2, Identifiable.Id largoId)
{
bool result = LargoGenerator.CreateLargo(slime1, slime2, largoId);
GameObject largoObject = SRSingleton<GameContext>.Instance.LookupDirector.GetPrefab(largoId);
GameObject puddleObject = SRSingleton<GameContext>.Instance.LookupDirector.GetPrefab(Identifiable.Id.PUDDLE_SLIME);
if (largoObject.GetComponent<KeepUpright>() != null)
{
UnityEngine.Object.Destroy(largoObject.GetComponent<KeepUpright>());
}
if (largoObject.GetComponents<SphereCollider>().Length >= 1)
{
foreach (SphereCollider sphereCollider in largoObject.GetComponents<SphereCollider>())
{
if (!sphereCollider.isTrigger)
{
UnityEngine.Object.DestroyImmediate(sphereCollider);
}
}
}
else
{
UnityEngine.Object.DestroyImmediate(largoObject.GetComponent<SphereCollider>());
}
largoObject.AddComponent<SphereCollider>().GetCopyOf(puddleObject.GetComponent<SphereCollider>());
return result;
}
public static bool CreateFireLargo(Identifiable.Id slime1, Identifiable.Id slime2, Identifiable.Id largoId)
{
bool result = LargoGenerator.CreateLargo(slime1, slime2, largoId);
GameObject largoObject = SRSingleton<GameContext>.Instance.LookupDirector.GetPrefab(largoId);
GameObject fireObject = SRSingleton<GameContext>.Instance.LookupDirector.GetPrefab(Identifiable.Id.FIRE_SLIME);
if (largoObject.GetComponent<KeepUpright>() != null)
{
UnityEngine.Object.Destroy(largoObject.GetComponent<KeepUpright>());
}
if (largoObject.GetComponents<SphereCollider>().Length > 1)
{
foreach (SphereCollider sphereCollider in largoObject.GetComponents<SphereCollider>())
{
if (!sphereCollider.isTrigger)
{
UnityEngine.Object.DestroyImmediate(sphereCollider);
}
}
}
else
{
UnityEngine.Object.DestroyImmediate(largoObject.GetComponent<SphereCollider>());
}
largoObject.AddComponent<SphereCollider>().GetCopyOf(fireObject.GetComponent<SphereCollider>());
return result;
}
public static bool CreateGlitchLargo(Identifiable.Id slime1, Identifiable.Id slime2, Identifiable.Id largoId)
{
bool result = LargoGenerator.CreateLargo(slime1, slime2, largoId, true);
GameObject largoObject = SRSingleton<GameContext>.Instance.LookupDirector.GetPrefab(largoId);
GameObject glitchObject = SRSingleton<GameContext>.Instance.LookupDirector.GetPrefab(Identifiable.Id.GLITCH_SLIME);
if (largoObject.GetComponent<KeepUpright>() != null)
{
UnityEngine.Object.Destroy(largoObject.GetComponent<KeepUpright>());
}
if (largoObject.GetComponent<KeepPuddleUpright>() != null)
{
UnityEngine.Object.Destroy(largoObject.GetComponent<KeepPuddleUpright>());
}
if (largoObject.GetComponents<SphereCollider>().Length > 1)
{
foreach (SphereCollider sphereCollider in largoObject.GetComponents<SphereCollider>())
{
if (!sphereCollider.isTrigger)
{
UnityEngine.Object.DestroyImmediate(sphereCollider);
}
}
}
else
{
UnityEngine.Object.DestroyImmediate(largoObject.GetComponent<SphereCollider>());
}
largoObject.AddComponent<SphereCollider>().GetCopyOf(glitchObject.GetComponent<SphereCollider>());
SlimeAppearance glitchLargoAppearance = SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(largoId).AppearancesDefault[0];
SlimeAppearance slimeAppearance = SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(slime2).AppearancesDefault[0];
return result;
}
public static bool CreateLuckyLargo(Identifiable.Id slime1, Identifiable.Id slime2, Identifiable.Id largoId)
{
bool result = LargoGenerator.CreateLargo(slime1, slime2, largoId);
SlimeAppearance luckyLargoAppearance = SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(largoId).AppearancesDefault[0];
SlimeAppearance luckyAppearance = SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(Identifiable.Id.LUCKY_SLIME).AppearancesDefault[0];
luckyLargoAppearance.Structures[2] = luckyAppearance.Structures[2];
return result;
}
public static bool CreateGoldLargo(Identifiable.Id slime1, Identifiable.Id slime2, Identifiable.Id largoId)
{
bool result = LargoGenerator.CreateLargo(slime1, slime2, largoId, true);
SlimeAppearance goldLargoAppearance = SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(largoId).AppearancesDefault[0];
SlimeAppearance goldAppearance = SRSingleton<GameContext>.Instance.SlimeDefinitions.GetSlimeByIdentifiableId(Identifiable.Id.GOLD_SLIME).AppearancesDefault[0];
goldLargoAppearance.Structures[0] = goldAppearance.Structures[0];
return result;
}
}
}