-
Notifications
You must be signed in to change notification settings - Fork 5
/
Plugin.cs
404 lines (376 loc) · 18.9 KB
/
Plugin.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
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using BrutalCompany.Component;
using System.Collections.Generic;
using System.Security.Policy;
using UnityEngine;
using static UnityEngine.UIElements.UIR.Implementation.UIRStylePainter;
using Project1;
using System.Linq;
using Project1.Data;
using UnityEngine.UIElements;
using UnityEngine.SceneManagement;
namespace BrutalCompany
{
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin
{
public static bool loaded;
Harmony _harmony = new Harmony(MyPluginInfo.PLUGIN_GUID);
public static List<SelectableLevel> levelsModified = new List<SelectableLevel>();
public static Dictionary<SelectableLevel, float> levelHeatVal;
public static Dictionary<SelectableLevel, List<SpawnableEnemyWithRarity>> levelEnemySpawns;
public static Dictionary<SpawnableEnemyWithRarity, int> enemyRaritys;
public static Dictionary<SpawnableEnemyWithRarity, AnimationCurve> enemyPropCurves;
public static ManualLogSource mls;
private void Awake()
{
mls = BepInEx.Logging.Logger.CreateLogSource("BrutalCompany");
// Plugin startup logic
mls.LogInfo("Loaded Brutal Company and applying patches.");
_harmony.PatchAll(typeof(Plugin));
mls = Logger;
levelHeatVal = new Dictionary<SelectableLevel, float>();
enemyRaritys = new Dictionary<SpawnableEnemyWithRarity, int>();
levelEnemySpawns = new Dictionary<SelectableLevel, List<SpawnableEnemyWithRarity>>();
enemyPropCurves = new Dictionary<SpawnableEnemyWithRarity, AnimationCurve>();
}
public void OnDestroy()
{
//mls.LogMessage("ugh");
if (!loaded)
{
GameObject gameObject = new GameObject("QuotaChanger");
DontDestroyOnLoad(gameObject);
gameObject.AddComponent<QuotaAjuster>();
//mls.LogMessage("Created the gameobject!");
loaded = true;
//LC_API.ServerAPI.ModdedServer.SetServerModdedOnly();
}
}
[HarmonyPatch(typeof(RoundManager), nameof(RoundManager.LoadNewLevel))]
[HarmonyPrefix]
static bool ModifyLevel(ref SelectableLevel newLevel)
{
if (!levelHeatVal.ContainsKey(newLevel))
{
levelHeatVal.Add(newLevel, 0);
}
if (!levelEnemySpawns.ContainsKey(newLevel))
{
List<SpawnableEnemyWithRarity> spawns = new List<SpawnableEnemyWithRarity>();
foreach (var item in newLevel.Enemies)
{
spawns.Add(item);
}
levelEnemySpawns.Add(newLevel, spawns);
}
List<SpawnableEnemyWithRarity> spawnableEnemies;
levelEnemySpawns.TryGetValue(newLevel, out spawnableEnemies);
newLevel.Enemies = spawnableEnemies;
foreach (var level in levelHeatVal.Keys.ToList())
{
float hl;
levelHeatVal.TryGetValue(level, out hl);
levelHeatVal[level] = Mathf.Clamp(hl - 5f, 0, 100f);
}
float hl2;
levelHeatVal.TryGetValue(newLevel, out hl2);
foreach (var enemy in newLevel.Enemies)
{
if (!enemyRaritys.ContainsKey(enemy))
{
enemyRaritys.Add(enemy, enemy.rarity);
}
int rare = 0;
enemyRaritys.TryGetValue(enemy, out rare);
enemy.rarity = rare;
}
foreach (var enemy in newLevel.Enemies)
{
if (!enemyPropCurves.ContainsKey(enemy))
{
enemyPropCurves.Add(enemy, enemy.enemyType.probabilityCurve);
}
AnimationCurve prob = new AnimationCurve();
enemyPropCurves.TryGetValue(enemy, out prob);
enemy.enemyType.probabilityCurve = prob;
}
HUDManager.Instance.AddTextToChatOnServer("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
HUDManager.Instance.AddTextToChatOnServer("<color=orange>MOON IS AT " + hl2.ToString() + "% HEAT</color>");
if (hl2 > 49f)
{
HUDManager.Instance.AddTextToChatOnServer("<color=red>HEAT LEVEL IS DANGEROUSLY HIGH. <color=white>\nVISIT OTHER MOONS TO LOWER HEAT LEVEL.</color>");
}
int chanceForTurretHell = Random.Range(-5, 3);
int chanceforLandmineHell = Random.Range(-5, 3);
EventEnum eventRand = (EventEnum)Mathf.Clamp(Random.Range(-1, 13), 0, 99);
if (newLevel.sceneName == "CompanyBuilding")
{
eventRand = 0;
}
switch (eventRand)
{
default:
HUDManager.Instance.AddTextToChatOnServer("<color=green>Level event: NONE</color>");
break;
case EventEnum.None:
HUDManager.Instance.AddTextToChatOnServer("<color=green>Level event: NONE</color>");
break;
case EventEnum.Turret:
HUDManager.Instance.AddTextToChatOnServer("<color=red>Level event: TURRET HELL</color>");
break;
case EventEnum.Landmine:
HUDManager.Instance.AddTextToChatOnServer("<color=red>Level event: LANDMINE HELL</color>");
break;
case EventEnum.Hoarding:
HUDManager.Instance.AddTextToChatOnServer("<color=red>Level event: HOARDER TOWN</color>");
foreach (var item in newLevel.Enemies)
{
item.rarity = 0;
if (item.enemyType.enemyPrefab.GetComponent<HoarderBugAI>() != null)
{
item.rarity = 999;
}
}
break;
case EventEnum.Lasso:
HUDManager.Instance.AddTextToChatOnServer("<color=red>Level event: LASSO MAN IS REAL</color>");
bool gotLasso = false;
bool addedLasso = false;
foreach (var item in newLevel.Enemies)
{
if (item.enemyType.enemyPrefab.GetComponent<LassoManAI>() != null)
{
gotLasso = true;
}
}
if (!gotLasso)
{
foreach (var level in StartOfRound.Instance.levels)
{
foreach (var enemy in level.Enemies)
{
if (enemy.enemyType.enemyPrefab.GetComponent<LassoManAI>() != null)
{
if (!addedLasso)
{
addedLasso = true;
newLevel.Enemies.Add(enemy);
}
}
}
}
}
foreach (var item in newLevel.Enemies)
{
if (item.enemyType.enemyPrefab.GetComponent<LassoManAI>() != null)
{
item.rarity = 999;
item.enemyType.probabilityCurve = new AnimationCurve(new Keyframe(0, 10000));
}
}
break;
case EventEnum.Unfair:
HUDManager.Instance.AddTextToChatOnServer("<color=red>Level event: UNFAIR COMPANY</color>");
break;
case EventEnum.OopsAllSnareFlea:
HUDManager.Instance.AddTextToChatOnServer("<color=red>Level event: OOPS, ALL SNARE FLEAS!</color>");
foreach (var item in newLevel.Enemies)
{
item.rarity = 0;
if (item.enemyType.enemyPrefab.GetComponent<CentipedeAI>() != null)
{
item.rarity = 999;
}
}
break;
case EventEnum.BrackenAndCoil:
HUDManager.Instance.AddTextToChatOnServer("<color=red>Level event: THE WORST COMBO OF ALL TIME</color>");
foreach (var item in newLevel.Enemies)
{
item.rarity = 0;
if (item.enemyType.enemyPrefab.GetComponent<FlowermanAI>() != null)
{
item.rarity = 999;
}
if (item.enemyType.enemyPrefab.GetComponent<SpringManAI>() != null)
{
item.rarity = 999;
}
}
break;
case EventEnum.Chaos:
HUDManager.Instance.AddTextToChatOnServer("<color=red>Level event: CHAOS COMPANY</color>");
foreach (var item in newLevel.Enemies)
{
item.enemyType.probabilityCurve = new AnimationCurve(new Keyframe(0, 1000));
}
break;
case EventEnum.All:
HUDManager.Instance.AddTextToChatOnServer("<color=red>Level event: ALL</color>");
foreach (var item in newLevel.Enemies)
{
item.enemyType.probabilityCurve = new AnimationCurve(new Keyframe(0, 1000));
}
foreach (var item in newLevel.Enemies)
{
item.rarity = 0;
if (item.enemyType.enemyPrefab.GetComponent<FlowermanAI>() != null)
{
item.rarity = 999;
}
if (item.enemyType.enemyPrefab.GetComponent<SpringManAI>() != null)
{
item.rarity = 999;
}
}
foreach (var item in newLevel.Enemies)
{
item.rarity = 0;
if (item.enemyType.enemyPrefab.GetComponent<CentipedeAI>() != null)
{
item.rarity = 999;
}
}
foreach (var item in newLevel.Enemies)
{
if (item.enemyType.enemyPrefab.GetComponent<LassoManAI>() != null)
{
item.rarity = 999;
}
}
foreach (var item in newLevel.Enemies)
{
item.rarity = 0;
if (item.enemyType.enemyPrefab.GetComponent<HoarderBugAI>() != null)
{
item.rarity = 999;
}
}
int randItemCount2 = Random.Range(2, 9);
for (int i = 0; i < randItemCount2; i++)
{
int randomItemID = Random.Range(0, 3);
Terminal terminal = UnityEngine.Object.FindObjectOfType<Terminal>();
terminal.orderedItemsFromTerminal.Add(randomItemID);
}
Terminal terminal3 = UnityEngine.Object.FindObjectOfType<Terminal>();
int itemCount2 = terminal3.orderedItemsFromTerminal.Count;
terminal3.orderedItemsFromTerminal.Clear();
for (int i = 0; i < itemCount2; i++)
{
terminal3.orderedItemsFromTerminal.Add(0);
}
break;
case EventEnum.Delivery:
HUDManager.Instance.AddTextToChatOnServer("<color=green>Level event: DELIVERY!</color>");
int randItemCount = Random.Range(2, 9);
for (int i = 0; i < randItemCount; i++)
{
int randomItemID = Random.Range(0, 6);
Terminal terminal = UnityEngine.Object.FindObjectOfType<Terminal>();
terminal.orderedItemsFromTerminal.Add(randomItemID);
}
break;
case EventEnum.ReplaceItems:
HUDManager.Instance.AddTextToChatOnServer("<color=red>Level event: YOU BOUGHT WALKIES, RIGHT?</color>");
Terminal terminal2 = UnityEngine.Object.FindObjectOfType<Terminal>();
int itemCount = terminal2.orderedItemsFromTerminal.Count;
if (itemCount == 0)
{
itemCount = 1;
}
terminal2.orderedItemsFromTerminal.Clear();
for (int i = 0; i < itemCount; i++)
{
terminal2.orderedItemsFromTerminal.Add(0);
}
break;
}
SelectableLevel n = newLevel;
mls.LogWarning("Map Objects");
foreach (var item in n.spawnableMapObjects)
{
if (item.prefabToSpawn.GetComponentInChildren<Turret>() != null)
{
//mls.LogWarning("Got turret prefab in MapObjects. Changing number to spawn curve!");
if (eventRand == EventEnum.Turret | eventRand == EventEnum.All)
{
item.numberToSpawn = new UnityEngine.AnimationCurve(new UnityEngine.Keyframe(0f, 200f), new UnityEngine.Keyframe(1f, 25));
//mls.LogWarning("TURRET HELL ACTIVATED :3");
}
else
{
item.numberToSpawn = new UnityEngine.AnimationCurve(new UnityEngine.Keyframe(0f, 0f), new UnityEngine.Keyframe(1f, 10));
//mls.LogWarning("Got turret prefab in MapObjects. Changing number to spawn curve!");
}
}
else if (item.prefabToSpawn.GetComponentInChildren<Landmine>() != null)
{
//mls.LogWarning("Got landmine prefab in MapObjects. Changing number to spawn curve!");
if (eventRand == EventEnum.Landmine | eventRand == EventEnum.All)
{
item.numberToSpawn = new UnityEngine.AnimationCurve(new UnityEngine.Keyframe(0f, 300f), new UnityEngine.Keyframe(1f, 170f));
//mls.LogWarning("LANDMINE HELL ACTIVATED :3");
}
else
{
item.numberToSpawn = new UnityEngine.AnimationCurve(new UnityEngine.Keyframe(0f, 0f), new UnityEngine.Keyframe(1f, 70));
//mls.LogWarning("Got landmine prefab in MapObjects. Changing number to spawn curve!");
}
}
mls.LogInfo(item.prefabToSpawn.ToString());
}
mls.LogWarning("Enemies");
foreach (var item in n.Enemies)
{
mls.LogInfo(item.enemyType.enemyName + "--rarity = " + item.rarity.ToString());
}
mls.LogWarning("Daytime Enemies");
foreach (var item in n.DaytimeEnemies)
{
mls.LogInfo(item.enemyType.enemyName);
}
if (levelsModified.Contains(newLevel))
{
//mls.LogInfo("We already hellified this level, skipping hellifier!!!");
//HUDManager.Instance.AddTextToChatOnServer("<color=red>Brutal Company: Skipping level data change as we already did this one!</color>");
}
else
{
levelsModified.Add(newLevel);
n.minScrap += 0;
n.maxScrap += 45;
n.minTotalScrapValue += 0;
n.maxTotalScrapValue += 800;
n.daytimeEnemySpawnChanceThroughDay = new UnityEngine.AnimationCurve(new UnityEngine.Keyframe(0, 7f), new Keyframe(0.5f, 7));
n.maxEnemyPowerCount += 2000;
n.maxOutsideEnemyPowerCount += 20;
n.maxDaytimeEnemyPowerCount += 200;
newLevel = n;
// mls.LogInfo("New level values: Factory size - " + n.factorySizeMultiplier + " MinScrap - " + n.minScrap + " MaxScrap - " + n.maxScrap + " MinTotalScrapValue - " + n.minTotalScrapValue + " MaxTotalScrapValue - " + n.maxTotalScrapValue + " SpawnChance - " + n.enemySpawnChanceThroughoutDay);
//HUDManager.Instance.AddTextToChatOnServer("<color=red>Brutal Company: Done generating this levels data.</color>");
}
n.enemySpawnChanceThroughoutDay = new UnityEngine.AnimationCurve(new UnityEngine.Keyframe(0, 0.1f + hl2), new Keyframe(0.5f, 500 + hl2));
n.outsideEnemySpawnChanceThroughDay = new UnityEngine.AnimationCurve(new UnityEngine.Keyframe(0, -30f + hl2), new Keyframe(20f, -30 + hl2), new Keyframe(21f, 10 + hl2));
if (eventRand == EventEnum.Unfair | eventRand == EventEnum.All)
{
n.outsideEnemySpawnChanceThroughDay = new UnityEngine.AnimationCurve(new UnityEngine.Keyframe(0, 10 + hl2), new Keyframe(20f, 10 + hl2), new Keyframe(21f, 10 + hl2));
}
if (eventRand == EventEnum.Hoarding | eventRand == EventEnum.All)
{
n.enemySpawnChanceThroughoutDay = new UnityEngine.AnimationCurve(new UnityEngine.Keyframe(0, 500f + hl2));
}
if (eventRand == EventEnum.Chaos | eventRand == EventEnum.All)
{
n.enemySpawnChanceThroughoutDay = new UnityEngine.AnimationCurve(new UnityEngine.Keyframe(0, 500f + hl2));
}
levelHeatVal.TryGetValue(newLevel, out hl2);
levelHeatVal[newLevel] = Mathf.Clamp(hl2 + 30f, 0, 100f);
//HUDManager.Instance.AddTextToChatOnServer("<color=red>Brutal Company: Done with level generation!</color>");
return true;
}
}
}