-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLevelModuleExposeWaves.cs
55 lines (48 loc) · 1.77 KB
/
LevelModuleExposeWaves.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
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using ThunderRoad;
namespace TOR {
public class LevelModuleExposeWaves : LevelModule {
public HashSet<int> waveBackups;
public int factionId;
public override IEnumerator OnLoadCoroutine() {
EventManager.onLevelLoad += OnLevelLoad;
EventManager.onLevelUnload += OnLevelUnload;
yield break;
}
public override void OnUnload() {
base.OnUnload();
EventManager.onLevelLoad -= OnLevelLoad;
EventManager.onLevelUnload -= OnLevelUnload;
}
void OnLevelLoad(LevelData levelData, LevelData.Mode mode, EventTime eventTime) {
if (eventTime == EventTime.OnStart) {
UnrestrictWaves();
}
}
private void OnLevelUnload(LevelData levelData, LevelData.Mode mode, EventTime eventTime) {
if (eventTime == EventTime.OnStart) {
RestoreWaves();
}
}
public void UnrestrictWaves() {
waveBackups = new HashSet<int>();
var waves = Catalog.GetDataList(Category.Wave);
foreach (var wave in waves.Cast<WaveData>()) {
if (!wave.alwaysAvailable && wave.waveSelectors != null && wave.waveSelectors.Count > 0) {
waveBackups.Add(wave.hashId);
wave.alwaysAvailable = true;
}
}
}
public void RestoreWaves() {
if (waveBackups == null) return;
var waves = Catalog.GetDataList(Category.Wave);
foreach (var wave in waves.Cast<WaveData>()) {
wave.alwaysAvailable = false;
}
waveBackups = null;
}
}
}