forked from PlayersCommittee/gemp-swccg-public
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutinni_maker.py
More file actions
executable file
·393 lines (321 loc) · 10.4 KB
/
utinni_maker.py
File metadata and controls
executable file
·393 lines (321 loc) · 10.4 KB
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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
#!/usr/bin/env python3
import json
import os.path
from pathlib import Path
import sqlite3
import re
import os
from colorama import (
init,
Fore,
Back,
Style
)
import urllib
def parse_side_json(side_json):
global valid_cards
global allowed
global verboten
for card in side_json['cards']:
front = card['front']
subtype = ""
if "subType" in front:
subtype = front["subType"]
icons = []
if 'icons' in card:
icons = card['icons']
if 'icons' in front:
icons = front['icons']
includecard = True
if 'lightSideIcons' in front:
##
## Locations must have both light and dark icons.
##
if front['lightSideIcons'] > 0 and front['darkSideIcons'] > 0:
includecard=True
else:
includecard=False
#print(" - NO FORCE: "+front['title'])
##
## Although these cards have no force generation,
## create an exception that allows them to be used with a Sandcrawler and Suction Tube.
##
if front['type'] == 'Location':
if 'Sandcrawler' in front['title']:
includecard=True
##
## Exception for Rancor pit.
## Rancor pit can be, possibly,
## the only way to counter the Kalit+Luke's Hunting Rifle combo.
## Or at least it is the funniest.
##
if 'Rancor' in front['title']:
includecard=True
##
## No point in Jedi Tests
##
if 'Jedi Test' in front['type']:
includecard=False
##
## ALL Jawas are welcome
##
if 'Character' in front['type']:
if 'Alien' in subtype:
if 'characteristics' in front:
if 'Jawa' in front['characteristics']:
includecard=True
else:
includecard=False
else:
includecard=False
elif 'Droid' in subtype:
includecard=True
else:
includecard=False
if ('Starship' in front['type']):
##
## Unique named pilots, like "Zuckuss In Mist Hunter", are not permitted.
##
if " In " in front['title']:
includecard=False
##
## No ships with permanent pilots are allowed.
## While we could assume that the "permanent pilot" is a Jawa,
## it is unlikely that the Jawas were able to steal any of the ships that have them.
##
if "Pilot" in icons:
includecard=False
##
## No capital starships permitted
##
if "Capital" in subtype:
includecard=False
##
## No TIE Fighters, X-Wings, A-Wings, X-Wings, U-Wings, or B-Wings.
##
if ("TIE" in subtype) or ("X-Wing" in subtype) or ("A-Wing" in subtype) or ("B-Wing" in subtype) or ("U-Wing" in subtype) or ("Blue Squadron" in front['title']) or ("Zeta-Class" in subtype):
includecard=False
##
## no ships with permanent pilots
##
if "Permanent pilot" in front['gametext']:
includecard=False
if front['type'] == 'Vehicle':
##
## No combat vehicles permitted.
## Only allow Creature and Transport vehicles
##
if "Combat" in subtype:
includecard=False
##
## No Ewok Vehicles
##
if "Ewok" in front['title']:
includecard=False
if front['type'] == 'Effect':
##
## Political Effects require senators
## There are no Jawa sentors, so these are useless.
##
if "Political" in subtype:
includecard=False
if 'Weapon' in front['type']:
##
## While not strictly "banned", these weapons are useless to a Jawa
##
if "Death Star" in subtype:
includecard=False
if "Superlaser" in front['title']:
includecard=False
if "TIE" in front['title']:
includecard=False
if "SFS" in front['title']:
includecard=False
if "-wing" in front['title']:
includecard=False
if "AAT" in front['title']:
includecard=False
if "AT-AT Cannon" in front["title"]:
includecard=False
if "AT-ST Dual Cannon" in front["title"]:
includecard=False
if "STAP" in front['title']:
includecard=False
if "Stolen Stormtrooper Blaster Rifle" in front['title']:
includecard=False
if "Energy Shell" in front['title']:
includecard=False
if "Proton Torpedos" in front['title']:
includecard=False
if "Ewok" in front['title']:
includecard=False
if "'s Blaster" in front['title']:
includecard=False
if "'s Lightsaber" in front['title']:
includecard=False
if "'s Shoto Lightsaber" in front['title']:
includecard=False
if "Double-Bladed Lightsaber" in front['title']:
includecard=False
if "Battle Droid" in front['title']:
includecard=False
if "Droid Starfighter" in front['title']:
includecard=False
if "Tarpals" in front['title']:
includecard=False
if "Electropole" in front['title']:
includecard=False
if "Chewbacca's Bowcaster" in front['title']:
includecard=False
if "Darksaber" in front['title']:
includecard=False
if "F-110" in front['title']:
includecard=False
if "Stun Rifle" in front['title']:
includecard=False
if "Gaderffi Stick" in front['title']:
includecard=False
if "Gamorrean" in front['title']:
includecard=False
if "Turbolaser" in front['title']:
includecard=False
if "Neural Inhibitor" in front['title']:
includecard=False
if "Ion Canon" in front['title']:
includecard=False
if "Luke's Blaster Pistol" in front['title']:
includecard=False
if "Orbital Mine" in front['title']:
includecard=False
if "Zuckuss' Snare Rifle" in front['title']:
includecard=False
##
## Bossk's Mortar Gun can be deployed on a Warrior
##
if "Bossk's Mortar Gun" in front['title']:
includecard=True
##
## Dengar's Blaster Carbine can be deployed on a Warrior
##
if "Dengar's Blaster Carbine" in front['title']:
includecard=True
##
## Dengar's Modified Riot Gun can not be deployed
##
if "Dengar's Modified Riot Gun" in front['title']:
includecard=False
if 'Droid' in subtype:
##
## Permanent Weapons are only allowed on Jawas.
## No Droids with "Permanent weapon" permitted.
##
if "Permanent weapon" in icons:
includecard=False
##
## No droids which are immune to restraining bolts are permitted.
## Any droid which has presence is immune to a restraining bolt.
##
if "Presence" in icons:
includecard=False
##
## While not neccesarily explicitly Jawas, they CAN be Jawas if the right objective in play.
## As Light Side has Offworld Jawas available,
## don't make it a *thing* and just assume the alien rabble/mob are always Jawas.
##
if ('Alien Rabble' in front['title']) or ('Alien Mob' in front['title']):
includecard=True
cardtype = subtype + " " + front['type']
if (subtype == ""):
cardtype = front['type']
setid = card['set']
setabbr = sets[setid]
side = card['side'].replace("Light", "LS").replace("Dark", "DS")
if includecard:
print(Fore.GREEN+" * "+Fore.GREEN+side+" "+Fore.WHITE+"["+Fore.BLUE+setabbr+Fore.WHITE+"] "+Fore.WHITE+"("+Fore.CYAN+cardtype+Fore.WHITE+") "+Fore.GREEN+front['title'])
valid_cards.append(card['gempId'])
allowed.append(side+" "+"["+setabbr+"] "+"("+cardtype+") <a href=\""+front['imageUrl']+"\">"+front['title']+"</a>")
else:
print(Fore.RED+" - "+Fore.RED+side+" "+Fore.WHITE+"["+Fore.MAGENTA+setabbr+Fore.WHITE+"] "+Fore.WHITE+"("+Fore.YELLOW+cardtype+Fore.WHITE+") "+Fore.RED+front['title'])
verboten.append(side+" "+"["+setabbr+"] "+"("+cardtype+") <a href=\""+front['imageUrl']+"\">"+front['title']+"</a>")
verboten_for_gemp.append(card['gempId'])
init()
global sets
sets = {}
global valid_cards
valid_cards=[]
global allowed
allowed = []
global verboten
verboten = []
global set_ids_for_gemp
set_ids_for_gemp = []
global verboten_for_gemp
verboten_for_gemp = []
from urllib.request import urlopen
source_json_urls = {
"Dark": {"url":"https://raw.githubusercontent.com/swccgpc/swccg-card-json/main/Dark.json"},
"Light": {"url":"https://raw.githubusercontent.com/swccgpc/swccg-card-json/main/Light.json"},
"sets": {"url":"https://raw.githubusercontent.com/swccgpc/swccg-card-json/main/sets.json"},
}
print("\nLoading JSON Files:")
for n in source_json_urls:
url = source_json_urls[n]['url']
print(" * ["+n+"]: "+url)
with urlopen(url) as response:
response_json = json.loads(response.read())
response_code = response.status
if (response_code == 200):
#print(type(response_json))
source_json_urls[n]['json'] = response_json
else:
raise Exception("Failed to load json")
print("")
print("Parsing sets json")
for s in source_json_urls['sets']['json']:
print(" * [",s['id'],"]:",s['abbr'])
setid = s['id']
sets[setid] = s['abbr']
if (setid not in ["200d", "1000d"]):
if int(setid) < 1000:
set_ids_for_gemp.append(int(setid))
print("Parsing Dark json")
parse_side_json(source_json_urls['Dark']['json'])
print("Parsing Light json")
parse_side_json(source_json_urls['Light']['json'])
print("Sorting collections")
valid_cards.sort()
set_ids_for_gemp.sort()
allowed.sort()
verboten.sort()
verboten_for_gemp.sort()
print("Updating swccgFormats.json for gemp")
swccgFormats_json_file = "gemp-swccg-server/src/main/resources/swccgFormats.json"
swccgFormats_json = None
##
## Load the existing swccgFormats.json file in to memory
##
with open(swccgFormats_json_file) as fh:
##
## File is read in as a list.
## Join the list as a string.
## Parse the json string to create a dict
##
swccgFormats_json_data = "".join(fh.readlines())
swccgFormats_json = json.loads(swccgFormats_json_data)
##
## Set the Utinni banned card list in the existing swccgFormats.json data
##
if type(swccgFormats_json) != None:
i = 0
for f in swccgFormats_json:
if "utinni" in f['name'].lower():
print(f)
swccgFormats_json[i]['banned'] = verboten_for_gemp
swccgFormats_json[i]['set'] = set_ids_for_gemp
i = i + 1
##
## Update the swccgFormats.json file
##
with open("gemp-swccg-server/src/main/resources/swccgFormats.json", "w") as fh:
fh.write(json.dumps(swccgFormats_json, indent=4, sort_keys=True))
print("\ndone.\n")