diff options
Diffstat (limited to 'Requirements.cs')
-rw-r--r-- | Requirements.cs | 117 |
1 files changed, 96 insertions, 21 deletions
diff --git a/Requirements.cs b/Requirements.cs index 987a299..81ecf36 100644 --- a/Requirements.cs +++ b/Requirements.cs | |||
@@ -50,9 +50,16 @@ namespace ManifoldGardenArchipelago | |||
50 | 50 | ||
51 | public abstract class Requirement | 51 | public abstract class Requirement |
52 | { | 52 | { |
53 | public enum Decision | ||
54 | { | ||
55 | Maybe, | ||
56 | No, | ||
57 | Yes, | ||
58 | } | ||
59 | |||
53 | public RequirementReferences references = new(); | 60 | public RequirementReferences references = new(); |
54 | 61 | ||
55 | public abstract bool Check(); | 62 | public abstract Decision Check(); |
56 | } | 63 | } |
57 | 64 | ||
58 | public class AndRequirement : Requirement | 65 | public class AndRequirement : Requirement |
@@ -69,9 +76,19 @@ namespace ManifoldGardenArchipelago | |||
69 | } | 76 | } |
70 | } | 77 | } |
71 | 78 | ||
72 | public override bool Check() | 79 | public override Decision Check() |
73 | { | 80 | { |
74 | return _requirements.All(x => x.Check()); | 81 | foreach (var requirement in _requirements) |
82 | { | ||
83 | Decision decision = requirement.Check(); | ||
84 | |||
85 | if (decision != Decision.Yes) | ||
86 | { | ||
87 | return decision; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | return Decision.Yes; | ||
75 | } | 92 | } |
76 | 93 | ||
77 | public override string ToString() | 94 | public override string ToString() |
@@ -94,9 +111,19 @@ namespace ManifoldGardenArchipelago | |||
94 | } | 111 | } |
95 | } | 112 | } |
96 | 113 | ||
97 | public override bool Check() | 114 | public override Decision Check() |
98 | { | 115 | { |
99 | return _requirements.Any(x => x.Check()); | 116 | foreach (var requirement in _requirements) |
117 | { | ||
118 | Decision decision = requirement.Check(); | ||
119 | |||
120 | if (decision != Decision.No) | ||
121 | { | ||
122 | return decision; | ||
123 | } | ||
124 | } | ||
125 | |||
126 | return Decision.No; | ||
100 | } | 127 | } |
101 | 128 | ||
102 | public override string ToString() | 129 | public override string ToString() |
@@ -116,9 +143,9 @@ namespace ManifoldGardenArchipelago | |||
116 | references.items.Add(itemName); | 143 | references.items.Add(itemName); |
117 | } | 144 | } |
118 | 145 | ||
119 | public override bool Check() | 146 | public override Decision Check() |
120 | { | 147 | { |
121 | return Plugin.archipelagoManager.HasItem(_itemName); | 148 | return Plugin.archipelagoManager.HasItem(_itemName) ? Decision.Yes : Decision.No; |
122 | } | 149 | } |
123 | 150 | ||
124 | public override string ToString() | 151 | public override string ToString() |
@@ -138,9 +165,9 @@ namespace ManifoldGardenArchipelago | |||
138 | references.scenes.Add(sceneName); | 165 | references.scenes.Add(sceneName); |
139 | } | 166 | } |
140 | 167 | ||
141 | public override bool Check() | 168 | public override Decision Check() |
142 | { | 169 | { |
143 | return Plugin.slotSave.VisitedScenes.Contains(_sceneName); | 170 | return Plugin.slotSave.VisitedScenes.Contains(_sceneName) ? Decision.Yes : Decision.No; |
144 | } | 171 | } |
145 | 172 | ||
146 | public override string ToString() | 173 | public override string ToString() |
@@ -161,9 +188,16 @@ namespace ManifoldGardenArchipelago | |||
161 | references.buttons.Add(button); | 188 | references.buttons.Add(button); |
162 | } | 189 | } |
163 | 190 | ||
164 | public override bool Check() | 191 | public override Decision Check() |
165 | { | 192 | { |
166 | return Plugin.slotSave.ActivatedButtons.Contains(_button); | 193 | if (Plugin.slotSave.ActivatedButtons.TryGetValue(_button, out bool value)) |
194 | { | ||
195 | return value ? Decision.Yes : Decision.No; | ||
196 | } | ||
197 | else | ||
198 | { | ||
199 | return Decision.Maybe; | ||
200 | } | ||
167 | } | 201 | } |
168 | 202 | ||
169 | public override string ToString() | 203 | public override string ToString() |
@@ -184,9 +218,16 @@ namespace ManifoldGardenArchipelago | |||
184 | references.sockets.Add(socket); | 218 | references.sockets.Add(socket); |
185 | } | 219 | } |
186 | 220 | ||
187 | public override bool Check() | 221 | public override Decision Check() |
188 | { | 222 | { |
189 | return Plugin.slotSave.ActivatedSockets.Contains(_socket); | 223 | if (Plugin.slotSave.ActivatedSockets.TryGetValue(_socket, out bool value)) |
224 | { | ||
225 | return value ? Decision.Yes : Decision.No; | ||
226 | } | ||
227 | else | ||
228 | { | ||
229 | return Decision.Maybe; | ||
230 | } | ||
190 | } | 231 | } |
191 | 232 | ||
192 | public override string ToString() | 233 | public override string ToString() |
@@ -207,9 +248,16 @@ namespace ManifoldGardenArchipelago | |||
207 | references.pads.Add(pad); | 248 | references.pads.Add(pad); |
208 | } | 249 | } |
209 | 250 | ||
210 | public override bool Check() | 251 | public override Decision Check() |
211 | { | 252 | { |
212 | return Plugin.slotSave.ActivatedPads.Contains(_pad); | 253 | if (Plugin.slotSave.ActivatedPads.TryGetValue(_pad, out bool value)) |
254 | { | ||
255 | return value ? Decision.Yes : Decision.No; | ||
256 | } | ||
257 | else | ||
258 | { | ||
259 | return Decision.Maybe; | ||
260 | } | ||
213 | } | 261 | } |
214 | 262 | ||
215 | public override string ToString() | 263 | public override string ToString() |
@@ -230,9 +278,16 @@ namespace ManifoldGardenArchipelago | |||
230 | references.waterwheels.Add(waterwheel); | 278 | references.waterwheels.Add(waterwheel); |
231 | } | 279 | } |
232 | 280 | ||
233 | public override bool Check() | 281 | public override Decision Check() |
234 | { | 282 | { |
235 | return Plugin.slotSave.ActivatedWaterwheels.Contains(_waterwheel); | 283 | if (Plugin.slotSave.ActivatedWaterwheels.TryGetValue(_waterwheel, out bool value)) |
284 | { | ||
285 | return value ? Decision.Yes : Decision.No; | ||
286 | } | ||
287 | else | ||
288 | { | ||
289 | return Decision.Maybe; | ||
290 | } | ||
236 | } | 291 | } |
237 | 292 | ||
238 | public override string ToString() | 293 | public override string ToString() |
@@ -253,9 +308,16 @@ namespace ManifoldGardenArchipelago | |||
253 | references.spheres.Add(sphere); | 308 | references.spheres.Add(sphere); |
254 | } | 309 | } |
255 | 310 | ||
256 | public override bool Check() | 311 | public override Decision Check() |
257 | { | 312 | { |
258 | return Plugin.slotSave.ActivatedSpheres.Contains(_sphere); | 313 | if (Plugin.slotSave.ActivatedSpheres.TryGetValue(_sphere, out bool value)) |
314 | { | ||
315 | return value ? Decision.Yes : Decision.No; | ||
316 | } | ||
317 | else | ||
318 | { | ||
319 | return Decision.Maybe; | ||
320 | } | ||
259 | } | 321 | } |
260 | 322 | ||
261 | public override string ToString() | 323 | public override string ToString() |
@@ -275,9 +337,22 @@ namespace ManifoldGardenArchipelago | |||
275 | references = requirement.references; | 337 | references = requirement.references; |
276 | } | 338 | } |
277 | 339 | ||
278 | public override bool Check() | 340 | public override Decision Check() |
279 | { | 341 | { |
280 | return !_requirement.Check(); | 342 | Decision subdec = _requirement.Check(); |
343 | |||
344 | if (subdec == Decision.Yes) | ||
345 | { | ||
346 | return Decision.No; | ||
347 | } | ||
348 | else if (subdec == Decision.No) | ||
349 | { | ||
350 | return Decision.Yes; | ||
351 | } | ||
352 | else | ||
353 | { | ||
354 | return Decision.Maybe; | ||
355 | } | ||
281 | } | 356 | } |
282 | 357 | ||
283 | public override string ToString() | 358 | public override string ToString() |