summary refs log tree commit diff stats
path: root/Requirements.cs
blob: 987a29954848961bb6b13a7deca7a4873ec3dc1d (plain) (blame)
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
using System.Collections.Generic;
using System.Linq;

namespace ManifoldGardenArchipelago
{
    public struct RequirementReferences
    {
        public RequirementReferences() { }

        public readonly HashSet<string> scenes = [];
        public readonly HashSet<SceneItemReference> buttons = [];
        public readonly HashSet<SceneItemReference> sockets = [];
        public readonly HashSet<SceneItemReference> pads = [];
        public readonly HashSet<SceneItemReference> waterwheels = [];
        public readonly HashSet<SceneItemReference> spheres = [];
        public readonly HashSet<string> items = [];

        public void Merge(RequirementReferences other)
        {
            foreach (var item in other.scenes)
            {
                scenes.Add(item);
            }
            foreach (var item in other.buttons)
            {
                buttons.Add(item);
            }
            foreach (var item in other.sockets)
            {
                sockets.Add(item);
            }
            foreach (var item in other.pads)
            {
                pads.Add(item);
            }
            foreach (var item in other.waterwheels)
            {
                waterwheels.Add(item);
            }
            foreach (var item in other.spheres)
            {
                spheres.Add(item);
            }
            foreach (var item in other.items)
            {
                items.Add(item);
            }
        }
    }

    public abstract class Requirement
    {
        public RequirementReferences references = new();

        public abstract bool Check();
    }

    public class AndRequirement : Requirement
    {
        private readonly List<Requirement> _requirements;

        public AndRequirement(List<Requirement> requirements)
        {
            _requirements = requirements;

            foreach (var subreq in _requirements)
            {
                references.Merge(subreq.references);
            }
        }

        public override bool Check()
        {
            return _requirements.All(x => x.Check());
        }

        public override string ToString()
        {
            return "And(" + string.Join(", ", _requirements.Select((req) => req.ToString())) + ")";
        }
    }

    public class OrRequirement : Requirement
    {
        private readonly List<Requirement> _requirements;

        public OrRequirement(List<Requirement> requirements)
        {
            _requirements = requirements;

            foreach (var subreq in _requirements)
            {
                references.Merge(subreq.references);
            }
        }

        public override bool Check()
        {
            return _requirements.Any(x => x.Check());
        }

        public override string ToString()
        {
            return "Or(" + string.Join(", ", _requirements.Select((req) => req.ToString())) + ")";
        }
    }

    public class ItemRequirement : Requirement
    {
        private readonly string _itemName;

        public ItemRequirement(string itemName)
        {
            _itemName = itemName;

            references.items.Add(itemName);
        }

        public override bool Check()
        {
            return Plugin.archipelagoManager.HasItem(_itemName);
        }

        public override string ToString()
        {
            return $"Item({_itemName})";
        }
    }

    public class EntryRequirement : Requirement
    {
        private readonly string _sceneName;

        public EntryRequirement(string sceneName)
        {
            _sceneName = sceneName;

            references.scenes.Add(sceneName);
        }

        public override bool Check()
        {
            return Plugin.slotSave.VisitedScenes.Contains(_sceneName);
        }

        public override string ToString()
        {
            return $"Entry({_sceneName})";
        }
    }

    public class ButtonRequirement : Requirement
    {
        private readonly SceneItemReference _button;

        public ButtonRequirement(SceneItemReference button)
        {
            _button = button;

            references.scenes.Add(button.scene);
            references.buttons.Add(button);
        }

        public override bool Check()
        {
            return Plugin.slotSave.ActivatedButtons.Contains(_button);
        }

        public override string ToString()
        {
            return $"Button{_button}";
        }
    }

    public class SocketRequirement : Requirement
    {
        private readonly SceneItemReference _socket;

        public SocketRequirement(SceneItemReference socket)
        {
            _socket = socket;

            references.scenes.Add(socket.scene);
            references.sockets.Add(socket);
        }

        public override bool Check()
        {
            return Plugin.slotSave.ActivatedSockets.Contains(_socket);
        }

        public override string ToString()
        {
            return $"Socket{_socket}";
        }
    }

    public class PadRequirement : Requirement
    {
        private readonly SceneItemReference _pad;

        public PadRequirement(SceneItemReference pad)
        {
            _pad = pad;

            references.scenes.Add(pad.scene);
            references.pads.Add(pad);
        }

        public override bool Check()
        {
            return Plugin.slotSave.ActivatedPads.Contains(_pad);
        }

        public override string ToString()
        {
            return $"Pad{_pad}";
        }
    }

    public class WaterwheelRequirement : Requirement
    {
        private readonly SceneItemReference _waterwheel;

        public WaterwheelRequirement(SceneItemReference waterwheel)
        {
            _waterwheel = waterwheel;

            references.scenes.Add(waterwheel.scene);
            references.waterwheels.Add(waterwheel);
        }

        public override bool Check()
        {
            return Plugin.slotSave.ActivatedWaterwheels.Contains(_waterwheel);
        }

        public override string ToString()
        {
            return $"Waterwheel{_waterwheel}";
        }
    }

    public class SphereRequirement : Requirement
    {
        private readonly SceneItemReference _sphere;

        public SphereRequirement(SceneItemReference sphere)
        {
            _sphere = sphere;

            references.scenes.Add(sphere.scene);
            references.spheres.Add(sphere);
        }

        public override bool Check()
        {
            return Plugin.slotSave.ActivatedSpheres.Contains(_sphere);
        }

        public override string ToString()
        {
            return $"Sphere{_sphere}";
        }
    }

    public class InvertedRequirement : Requirement
    {
        private readonly Requirement _requirement;

        public InvertedRequirement(Requirement requirement)
        {
            _requirement = requirement;

            references = requirement.references;
        }

        public override bool Check()
        {
            return !_requirement.Check();
        }

        public override string ToString()
        {
            return $"Not({_requirement})";
        }
    }
}