-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeck_builder.py
More file actions
233 lines (206 loc) · 8.25 KB
/
Copy pathdeck_builder.py
File metadata and controls
233 lines (206 loc) · 8.25 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
import random
# Import all implimented decks
from base import deck as base_deck
from fe import deck as fe_deck
from crossover_1 import deck as c1_deck
from crossover_2 import deck as c2_deck
from hu import deck as hu_deck
from tt import deck as tt_deck
# For testing individual cards
from tt import cards as custom
# I have just implimented the personas of HU for now. They can be accessed if any_pick == True
# from hu import persona as hu_personas
from frames import card_frame
import globe
from constants import owners
# All available sets (never mutated - used as source of truth)
_all_sets = None
def _get_all_sets():
global _all_sets
if _all_sets is None:
_all_sets = [base_deck.this_set, fe_deck.this_set, hu_deck.this_set, tt_deck.this_set, c1_deck.this_set, c2_deck.this_set]
return _all_sets
# As sets are chosen, they are moved from decks to choosen_sets
decks = [base_deck.this_set, fe_deck.this_set, hu_deck.this_set, tt_deck.this_set, c1_deck.this_set, c2_deck.this_set]
choosen_sets = []
# Specifies weather small set personas muct be picked when playing with small sets
any_pick = True
# Returns the list of all available sets with metadata (for web UI)
def get_available_sets():
return [{"id": i, "name": s.name, "large": s.large_set} for i, s in enumerate(_get_all_sets())]
# Programmatic set selection for web API - accepts list of set indices
def choose_sets_programmatic(set_indices):
global decks, choosen_sets
all_s = _get_all_sets()
decks[:] = list(all_s)
choosen_sets.clear()
for idx in set_indices:
if 0 <= idx < len(all_s):
if all_s[idx] not in choosen_sets:
choosen_sets.append(all_s[idx])
# This is a terminal interface to choose which sets we are playing with.
# Right now, it must be called before everything else
# This should be changed to a gui interface...
def choose_sets():
print("Which sets would you like to play with? type 'play' to start game.")
for i, d in enumerate(decks):
print(f"{i} {d.name} (large set:{d.large_set})")
x = input()
if x == 'play':
if len(choosen_sets) == 0:
print("You must choose at least 1 set.")
return choose_sets()
return
else:
intx = -1
safe = True
try:
intx = int(x)
except:
print("?")
safe = False
if safe and intx >= 0 and intx < len(decks):
choosen_sets.append(decks.pop(intx))
return choose_sets()
# Once the sets are choosen, this loads and returns the avalable personas
# If any_pick == False and there is 1 or more small set (like crossover packs)
# Then only the personas from the smaller sets can be choosen
def get_personas():
small_sets = []
large_sets = []
# Goes thoguh all the choosen sets and loads the personas into either the small or large set lists
for d in choosen_sets:
if globe.DEBUG:
print(f"Loading {d.name}'s personas...", flush=True)
if d.large_set:
large_sets.extend(d.load_personas())
else:
small_sets.extend(d.load_personas())
# If any_pick, you can only choose between any of the small sets personas, if any
if not any_pick:
if len(small_sets) > 0:
return small_sets
else:
# if not any_pick, combines large sets, small sets, and the HU personas
large_sets.extend(small_sets)
return large_sets
# Assembles each players starting hand
def get_starting_deck(player):
assemble = []
for c in range(3):
assemble.append(card_frame.vunerability(player))
for c in range(7):
assemble.append(card_frame.punch(player))
# Shuffles here
random.shuffle(assemble)
# Any cards that are added here will be at the top of each players starting deck
# and will be drawn before their first turn. This is very usefull for testing cards.
# make sure that we cange where 'custom' points, it should point to the set of the cards we are testing
# assemble.append(custom.bunker(player))
# assemble.append(custom.catwoman(player))
# assemble.append(custom.green_arrows_bow(player))
# assemble.append(custom.eclipso(player))
# assemble.append(custom.belle_reve(player))
# assemble.append(custom.indigo_tribe_power_ring(player))
# for card, num in hu_deck.deck.items():
# assemble.append(card(player))
#
# assemble.append(custom.jervis_tetch(player))
# assemble.append(custom.mind_control_hat(player))
# assemble.append(tt_deck.cards.jaime_reyes(player))
# assemble.append(tt_deck.cards.hawk_and_dove(player))
# assemble.append(tt_deck.cards.azarath(player))
# assemble.append(tt_deck.cards.garfield_logan(player))
# assemble.append(tt_deck.cards.gizmo(player))
# assemble.append(tt_deck.cards.flight_wings(player))
return assemble
# For debug, sets what players discard pile starts as.
# Should be an empty list when not testing
def debug_discard(player):
assemble = []
return assemble
# Initialize weakness and kick stacks
# I was told these were the starting amounts
def initialize_weaknesses():
assemble = []
for c in range(20):
assemble.append(card_frame.weakness())
return assemble
def initialize_kicks():
assemble = []
for c in range(16):
assemble.append(card_frame.kick())
return assemble
# if there are any small sets, it only pulls SV's out of them
# the number of SV's to use is the least of the avalable sets of SV's
# Last SV is choosen, and then the rest of the SV's are choosen in the order they are given
# For example, in crossover 1 & 2 the SV's are suposed to be played in a specific order.
# This order is maintained, but each SV is individually pulled from a random set
def initialize_supervillains():
small_sets = []
large_sets = []
for d in choosen_sets:
if globe.DEBUG:
print(f"Loading {d.name}'s SV's...", flush=True)
if d.large_set:
large_sets.append(d.load_supervilains())
else:
small_sets.append(d.load_supervilains())
# If there are any small sets, we will prioritize adding them
# Otherwise we will add SV's from the large sets
prioritize = large_sets
if len(small_sets) > 0:
prioritize = small_sets
# Messy way of finding the smallest set
smallest_villain_amount = 99
for d in prioritize:
smallest_villain_amount = min(smallest_villain_amount, len(d))
assemble : list[card_frame.card] = []
# If there are more than 1 set to choose from...
if len(prioritize) > 1:
# Set last SV
assemble.append(random.choice(prioritize)[0])
for d in prioritize:
d.pop(0)
# Set the rest of the SV's counting down
while len(assemble) < smallest_villain_amount:
count_from_end = smallest_villain_amount - len(assemble)
assemble.append(random.choice(prioritize)[-count_from_end])
else:
assemble = prioritize[0]
for c in assemble:
c.owner_type = owners.VILLAINDECK
return assemble
# Initializes the main deck
def initialize_deck():
small_sets_cards = []
# large_sets = []
assemble = []
for d in choosen_sets:
if globe.DEBUG:
print(f"Loading {d.name}'s deck...", flush=True)
if d.large_set:
assemble.extend(d.load_deck())
else:
small_sets_cards.extend(d.load_deck())
# All large sets should be shuffled (although there may be none)
random.shuffle(assemble)
random.shuffle(small_sets_cards)
# If there are no cards from large sets, then we are only playing with the small sets
# I allow this, for experimentation, but really this is not a good way to play.
# The deck will run out of cards very fast.
if len(assemble) == 0:
return small_sets_cards
elif len(small_sets_cards) > 0:
# If there are sa mix of small set(s) and large set(s) then we split
# The small sets in the top half of the large sets
# Split the deck
bottom_split = assemble[:int(len(assemble) / 2)]
top_split = assemble[int(len(assemble) / 2):]
# Shuffle the small sets into the top half
top_split.extend(small_sets_cards)
random.shuffle(top_split)
# Put the deck back togeather
assemble = bottom_split
assemble.extend(top_split)
return assemble