-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAction.adept
273 lines (221 loc) · 10.5 KB
/
Action.adept
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
import 'main.adept'
// isaac@spawn ~ fire_guy rightof 0
// isaac@play smite 2
// andy@spawn ~ ice_guy rightof 0
// isaac@end
// andy@end
// (attackphase)
// isaac@attack 3 2 99
// isaac@attack 5 2 99
// isaac@end
// andy@play smite 5 99
// andy@attack 2 5 99
// andy@end
// (battlephase)
// (drawphase)
// isaac@draw
// andy@draw
// (next spawn phase)
// isaac@spawn ~ fire_guy rightof 0
// isaac@play popup_shield 3 99
// andy@spawn ~ ice_guy rightof 0
// isaac@end
// andy@steal ~
// isaac@lost andy fire_guy
struct Action (command_text String) {
func commit() Action {
a POD Action
a.command_text = this.command_text.commit()
return a
}
func clone() Action {
a POD Action
a.command_text = this.command_text.clone()
return a
}
func __assign__(other POD Action) {
this.command_text = other.command_text
}
func apply(inout state *GameState, out particles *<*CardParticle> List, out should_reschedule *bool, out should_update_statuses *bool) successful {
*should_reschedule = false
*should_update_statuses = false
at_symbol long = this.command_text.first('@'ub)
if at_symbol == -1, return false
subject_name StringView = this.command_text.span(0, at_symbol)
rest StringView = this.command_text.range(at_symbol, this.command_text.length)
tokens <String> List = rest.split(" ")
subject *Player = state.getPlayer(subject_name)
me *Player = state.getThisPlayer()
is_me bool = subject == me
if tokens.get(0) == "@end" {
if tokens.length != 1 {
print("ERROR: Action.apply() on @end command with mismatching arity -> '%'" % this.command_text)
return false
}
if subject.done {
*should_reschedule = true
return false
}
subject.done = true
return true
} else if tokens.get(0) == "@spawn" {
if tokens.length != 5 {
print("ERROR: Action.apply() on @spawn command with mismatching arity -> '%'" % this.command_text)
return false
}
network_object_id StringView = tokens.get(1)
card_blueprint_identifier StringView = tokens.get(2)
position_relation StringView = tokens.get(3)
position_reference StringView = tokens.get(4)
unless network_object_id.isIntegerLike() {
print("ERROR: Action.apply() on @spawn command got position reference as not an integer -> '%'" % this.command_text)
return false
}
unless position_relation == "leftof" || position_relation == "rightof" {
print("ERROR: Action.apply() on @spawn command got position relation not 'leftof' or 'rightof' -> '%'" % this.command_text)
return false
}
unless position_reference.isIntegerLike() {
print("ERROR: Action.apply() on @spawn command got position reference as not an integer -> '%'" % this.command_text)
return false
}
subject.spawnCard(card_blueprint_identifier, network_object_id.toUlong(), position_relation, position_reference.toUlong(), particles, is_me, state.global_dancing)
sfx.play(sfx.spawn)
if subject && !is_me {
// Reduce the number of dummy cards in the opponents hand
subject.hand.reduce(1)
}
*should_update_statuses = true
return true
} else if tokens.get(0) == "@attack" {
if tokens.length != 4 {
print("ERROR: Action.apply() on @attack command with mismatching arity -> '%'" % this.command_text)
return false
}
aggressor StringView = tokens.get(1)
victim StringView = tokens.get(2)
randomness StringView = tokens.get(3)
unless aggressor.isIntegerLike() {
print("ERROR: Action.apply() on attack command got aggressor as not an integer -> '%'" % this.command_text)
return false
}
unless victim.isIntegerLike() {
print("ERROR: Action.apply() on attack command got victim as not an integer -> '%'" % this.command_text)
return false
}
unless randomness.isIntegerLike() {
print("ERROR: Action.apply() on attack command got randomness as not an integer -> '%'" % this.command_text)
return false
}
state.attack_orders.add(attackOrder(aggressor.toUlong(), victim.toUlong(), randomness.toUlong()))
return true
} else if tokens.get(0) == "@play" || tokens.get(0) == "@playnow" {
if tokens.length != 4 {
print("ERROR: Action.apply() on % command with mismatching arity -> '%'" % tokens.get(0) % this.command_text)
return false
}
blueprint_name StringView = tokens.get(1)
victim StringView = tokens.get(2)
randomness StringView = tokens.get(3)
unless subject {
print("ERROR: Action.apply() on play command with subject that doesn't exist -> '%'" % this.command_text)
return false
}
blueprint *CardBlueprint = gamedata.deck.getCardBlueprint(blueprint_name)
unless blueprint {
print("ERROR: Action.apply() on play command got card that doesn't exist -> '%'" % this.command_text)
return false
}
unless victim.isIntegerLike() {
print("ERROR: Action.apply() on play command got victim as not an integer -> '%'" % this.command_text)
return false
}
unless randomness.isIntegerLike() {
print("ERROR: Action.apply() on play command got randomness as not an integer -> '%'" % this.command_text)
return false
}
if tokens.get(0) == "@playnow" {
victim_instance *CardInstance = state.getCardOnBoardByNetworkId(victim.toUlong())
state.doSpell(subject.player_id, blueprint, victim_instance, particles, randomness.toUlong())
} else {
state.spell_orders.add(spellOrder(subject.player_id, blueprint, victim.toUlong(), randomness.toUlong()))
}
return true
} else if tokens.get(0) == "@draw" {
if tokens.length != 1 {
print("ERROR: Action.apply() on @draw command with mismatching arity -> '%'" % this.command_text)
return false
}
unless is_me {
subject.drawCardsFromDeck(1, false, state.global_mana)
}
return true
} else if tokens.get(0) == "@steal" {
if tokens.length != 2 {
print("ERROR: Action.apply() on @steal command with mismatching arity -> '%'" % this.command_text)
return false
}
randomness StringView = tokens.get(1)
if gamedata.gamekind == GameKind::VERSUS_AI && !subject_name.equals(gamedata.ai_name) {
// Handle AI player in versus AI games
ai *Player = state.getPlayer(gamedata.ai_name)
if ai && ai.hand.length != 0 {
hand_index usize = randomness.toUlong() % ai.hand.length
gamedata.manager.writeOutgoing(ai.name + "@lost " + subject.name + " " + ai.hand.getPointer(hand_index).name + "\n")
ai.hand.remove(hand_index)
}
}
if !is_me && me.hand.length != 0 {
hand_index usize = randomness.toUlong() % me.hand.length
gamedata.manager.writeOutgoing(me.name + "@lost " + subject.name + " " + me.hand.getPointer(hand_index).name + "\n")
me.hand.remove(hand_index)
}
return true
} else if tokens.get(0) == "@lost" {
if tokens.length != 3 {
print("ERROR: Action.apply() on @lost command with mismatching arity -> '%'" % this.command_text)
return false
}
to_who StringView = tokens.get(1)
which_card StringView = tokens.get(2)
if gamedata.gamekind == GameKind::VERSUS_AI && to_who == gamedata.ai_name {
// Handle AI player in versus AI games
ai *Player = state.getPlayer(gamedata.ai_name)
if ai, ai.drawCardFromDeck(which_card)
} else if to_who == me.name {
me.drawCardFromDeck(which_card)
} else {
to_player *Player = state.getPlayer(to_who)
if to_player, to_player.drawCardsFromDeck(1, false, state.global_mana)
}
return true
} else if tokens.get(0) == "@trap" {
if tokens.length != 3 {
print("ERROR: Action.apply() on @lost command with mismatching arity -> '%'" % this.command_text)
return false
}
blueprint_name StringView = tokens.get(1)
rigged_network_id StringView = tokens.get(2)
state.addTrap(gamedata.deck.getCardBlueprint(blueprint_name), rigged_network_id.toUlong())
} else {
print("WARNING: Unrecognized gameplay action '%'" % this.command_text)
return false
}
return true
}
func isUrgent bool {
at_symbol long = this.command_text.first('@'ub)
if at_symbol == -1, return false
rest String = this.command_text.range(at_symbol, this.command_text.length)
space_symbol long = rest.first(' 'ub)
command_type String = space_symbol ? rest.range(0, space_symbol) : rest
if command_type == "@playnow" || command_type == "@steal" || command_type == "@lost", return true
return false
}
}
func action(command_text String) Action {
command_text.make()
a POD Action
a.command_text = command_text.commit()
return a
}