diff options
Diffstat (limited to 'Requirements.cs')
-rw-r--r-- | Requirements.cs | 288 |
1 files changed, 288 insertions, 0 deletions
diff --git a/Requirements.cs b/Requirements.cs new file mode 100644 index 0000000..987a299 --- /dev/null +++ b/Requirements.cs | |||
@@ -0,0 +1,288 @@ | |||
1 | using System.Collections.Generic; | ||
2 | using System.Linq; | ||
3 | |||
4 | namespace ManifoldGardenArchipelago | ||
5 | { | ||
6 | public struct RequirementReferences | ||
7 | { | ||
8 | public RequirementReferences() { } | ||
9 | |||
10 | public readonly HashSet<string> scenes = []; | ||
11 | public readonly HashSet<SceneItemReference> buttons = []; | ||
12 | public readonly HashSet<SceneItemReference> sockets = []; | ||
13 | public readonly HashSet<SceneItemReference> pads = []; | ||
14 | public readonly HashSet<SceneItemReference> waterwheels = []; | ||
15 | public readonly HashSet<SceneItemReference> spheres = []; | ||
16 | public readonly HashSet<string> items = []; | ||
17 | |||
18 | public void Merge(RequirementReferences other) | ||
19 | { | ||
20 | foreach (var item in other.scenes) | ||
21 | { | ||
22 | scenes.Add(item); | ||
23 | } | ||
24 | foreach (var item in other.buttons) | ||
25 | { | ||
26 | buttons.Add(item); | ||
27 | } | ||
28 | foreach (var item in other.sockets) | ||
29 | { | ||
30 | sockets.Add(item); | ||
31 | } | ||
32 | foreach (var item in other.pads) | ||
33 | { | ||
34 | pads.Add(item); | ||
35 | } | ||
36 | foreach (var item in other.waterwheels) | ||
37 | { | ||
38 | waterwheels.Add(item); | ||
39 | } | ||
40 | foreach (var item in other.spheres) | ||
41 | { | ||
42 | spheres.Add(item); | ||
43 | } | ||
44 | foreach (var item in other.items) | ||
45 | { | ||
46 | items.Add(item); | ||
47 | } | ||
48 | } | ||
49 | } | ||
50 | |||
51 | public abstract class Requirement | ||
52 | { | ||
53 | public RequirementReferences references = new(); | ||
54 | |||
55 | public abstract bool Check(); | ||
56 | } | ||
57 | |||
58 | public class AndRequirement : Requirement | ||
59 | { | ||
60 | private readonly List<Requirement> _requirements; | ||
61 | |||
62 | public AndRequirement(List<Requirement> requirements) | ||
63 | { | ||
64 | _requirements = requirements; | ||
65 | |||
66 | foreach (var subreq in _requirements) | ||
67 | { | ||
68 | references.Merge(subreq.references); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | public override bool Check() | ||
73 | { | ||
74 | return _requirements.All(x => x.Check()); | ||
75 | } | ||
76 | |||
77 | public override string ToString() | ||
78 | { | ||
79 | return "And(" + string.Join(", ", _requirements.Select((req) => req.ToString())) + ")"; | ||
80 | } | ||
81 | } | ||
82 | |||
83 | public class OrRequirement : Requirement | ||
84 | { | ||
85 | private readonly List<Requirement> _requirements; | ||
86 | |||
87 | public OrRequirement(List<Requirement> requirements) | ||
88 | { | ||
89 | _requirements = requirements; | ||
90 | |||
91 | foreach (var subreq in _requirements) | ||
92 | { | ||
93 | references.Merge(subreq.references); | ||
94 | } | ||
95 | } | ||
96 | |||
97 | public override bool Check() | ||
98 | { | ||
99 | return _requirements.Any(x => x.Check()); | ||
100 | } | ||
101 | |||
102 | public override string ToString() | ||
103 | { | ||
104 | return "Or(" + string.Join(", ", _requirements.Select((req) => req.ToString())) + ")"; | ||
105 | } | ||
106 | } | ||
107 | |||
108 | public class ItemRequirement : Requirement | ||
109 | { | ||
110 | private readonly string _itemName; | ||
111 | |||
112 | public ItemRequirement(string itemName) | ||
113 | { | ||
114 | _itemName = itemName; | ||
115 | |||
116 | references.items.Add(itemName); | ||
117 | } | ||
118 | |||
119 | public override bool Check() | ||
120 | { | ||
121 | return Plugin.archipelagoManager.HasItem(_itemName); | ||
122 | } | ||
123 | |||
124 | public override string ToString() | ||
125 | { | ||
126 | return $"Item({_itemName})"; | ||
127 | } | ||
128 | } | ||
129 | |||
130 | public class EntryRequirement : Requirement | ||
131 | { | ||
132 | private readonly string _sceneName; | ||
133 | |||
134 | public EntryRequirement(string sceneName) | ||
135 | { | ||
136 | _sceneName = sceneName; | ||
137 | |||
138 | references.scenes.Add(sceneName); | ||
139 | } | ||
140 | |||
141 | public override bool Check() | ||
142 | { | ||
143 | return Plugin.slotSave.VisitedScenes.Contains(_sceneName); | ||
144 | } | ||
145 | |||
146 | public override string ToString() | ||
147 | { | ||
148 | return $"Entry({_sceneName})"; | ||
149 | } | ||
150 | } | ||
151 | |||
152 | public class ButtonRequirement : Requirement | ||
153 | { | ||
154 | private readonly SceneItemReference _button; | ||
155 | |||
156 | public ButtonRequirement(SceneItemReference button) | ||
157 | { | ||
158 | _button = button; | ||
159 | |||
160 | references.scenes.Add(button.scene); | ||
161 | references.buttons.Add(button); | ||
162 | } | ||
163 | |||
164 | public override bool Check() | ||
165 | { | ||
166 | return Plugin.slotSave.ActivatedButtons.Contains(_button); | ||
167 | } | ||
168 | |||
169 | public override string ToString() | ||
170 | { | ||
171 | return $"Button{_button}"; | ||
172 | } | ||
173 | } | ||
174 | |||
175 | public class SocketRequirement : Requirement | ||
176 | { | ||
177 | private readonly SceneItemReference _socket; | ||
178 | |||
179 | public SocketRequirement(SceneItemReference socket) | ||
180 | { | ||
181 | _socket = socket; | ||
182 | |||
183 | references.scenes.Add(socket.scene); | ||
184 | references.sockets.Add(socket); | ||
185 | } | ||
186 | |||
187 | public override bool Check() | ||
188 | { | ||
189 | return Plugin.slotSave.ActivatedSockets.Contains(_socket); | ||
190 | } | ||
191 | |||
192 | public override string ToString() | ||
193 | { | ||
194 | return $"Socket{_socket}"; | ||
195 | } | ||
196 | } | ||
197 | |||
198 | public class PadRequirement : Requirement | ||
199 | { | ||
200 | private readonly SceneItemReference _pad; | ||
201 | |||
202 | public PadRequirement(SceneItemReference pad) | ||
203 | { | ||
204 | _pad = pad; | ||
205 | |||
206 | references.scenes.Add(pad.scene); | ||
207 | references.pads.Add(pad); | ||
208 | } | ||
209 | |||
210 | public override bool Check() | ||
211 | { | ||
212 | return Plugin.slotSave.ActivatedPads.Contains(_pad); | ||
213 | } | ||
214 | |||
215 | public override string ToString() | ||
216 | { | ||
217 | return $"Pad{_pad}"; | ||
218 | } | ||
219 | } | ||
220 | |||
221 | public class WaterwheelRequirement : Requirement | ||
222 | { | ||
223 | private readonly SceneItemReference _waterwheel; | ||
224 | |||
225 | public WaterwheelRequirement(SceneItemReference waterwheel) | ||
226 | { | ||
227 | _waterwheel = waterwheel; | ||
228 | |||
229 | references.scenes.Add(waterwheel.scene); | ||
230 | references.waterwheels.Add(waterwheel); | ||
231 | } | ||
232 | |||
233 | public override bool Check() | ||
234 | { | ||
235 | return Plugin.slotSave.ActivatedWaterwheels.Contains(_waterwheel); | ||
236 | } | ||
237 | |||
238 | public override string ToString() | ||
239 | { | ||
240 | return $"Waterwheel{_waterwheel}"; | ||
241 | } | ||
242 | } | ||
243 | |||
244 | public class SphereRequirement : Requirement | ||
245 | { | ||
246 | private readonly SceneItemReference _sphere; | ||
247 | |||
248 | public SphereRequirement(SceneItemReference sphere) | ||
249 | { | ||
250 | _sphere = sphere; | ||
251 | |||
252 | references.scenes.Add(sphere.scene); | ||
253 | references.spheres.Add(sphere); | ||
254 | } | ||
255 | |||
256 | public override bool Check() | ||
257 | { | ||
258 | return Plugin.slotSave.ActivatedSpheres.Contains(_sphere); | ||
259 | } | ||
260 | |||
261 | public override string ToString() | ||
262 | { | ||
263 | return $"Sphere{_sphere}"; | ||
264 | } | ||
265 | } | ||
266 | |||
267 | public class InvertedRequirement : Requirement | ||
268 | { | ||
269 | private readonly Requirement _requirement; | ||
270 | |||
271 | public InvertedRequirement(Requirement requirement) | ||
272 | { | ||
273 | _requirement = requirement; | ||
274 | |||
275 | references = requirement.references; | ||
276 | } | ||
277 | |||
278 | public override bool Check() | ||
279 | { | ||
280 | return !_requirement.Check(); | ||
281 | } | ||
282 | |||
283 | public override string ToString() | ||
284 | { | ||
285 | return $"Not({_requirement})"; | ||
286 | } | ||
287 | } | ||
288 | } | ||