-
Notifications
You must be signed in to change notification settings - Fork 3
/
actions.py
95 lines (80 loc) · 2.95 KB
/
actions.py
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
from playfield import *
# File to hold all the viable actions.
## DECK RELATED FUNCTIONS ##
# Set the deck for player
def set_deck(pf, player, deck):
pf.DECK[player] = deck[0]
pf.EXTD[player] = deck[1]
# Set our internal working deck by expansion
pf.WKDECK[player] = cu.expand_cards(deck[0])
pf.WKEXTD[player] = cu.expand_cards(deck[1])
return pf.DECK[player], pf.EXTD[player]
# Shuffle the deck
def shuffle_deck(pf, player):
rand.shuffle(pf.DECK[player])
# Function to draw from a deck to hand. Returns cards that was drawn.
# Returns none if deck is empty
def draw(pf, player):
def _draw():
maxc = len(pf.WKDECK[player])
if maxc == 0:
return None
ind = rand.randint(0, maxc - 1)
chose = pf.WKDECK[player].pop(ind)
pf.HAND[player].append(chose)
pf.AS.append(_draw)
## Action Related Card Functions ##
# All these functions must only have 4 parameters
# Player, cardind relative to a set of cards, field position
# and cardfaceindex for the flipping of the card if applicable.
#
# Yes, that means that you are able to set a spell but put it face up
# or you can set a card face up in hand. This leave interpretation
# in the future or for custom rules in card decks.
# Summon a card from deck to hand. Does not check validity rules.
def normal_summon(pf, player, cardind, fpos, cardfaceind=FACE_UP_ATK):
def _normal_summon():
pf.FIELD[player][fpos].insert(0, pf.HAND[player].pop(cardind))
pf.FIELD[player][fpos][0]["cardface"] = cardfaceind
pf.PREV_NORM_SUMMON = pf.ROUND_CNT
return pf.FIELD[player][fpos]
pf.AS.append(_normal_summon)
# Similar to normal summon but does not tick the normal summon ticker.
def special_summon(pf, player, cardind, fpos, cardfaceind = FACE_UP_ATK):
def _special_summon():
pf.FIELD[player][fpos].insert(0, pf.HAND[player].pop(cardind))
pf.FIELD[player][fpos][0]["cardface"] = cardfaceind
pf.PREV_NORM_SUMMON = pf.ROUND_CNT
return pf.FIELD[player][fpos]
pf.AS.append(_special_summon)
# Play a spell from hand
def play_spell(pf, player, handind, fpos, cardfaceind = FACE_UP_SPELL):
pass
# Activate a spell from the field
def activate_spell(pf, player, spellind, fpos, cardfaceind = FACE_UP_SPELL):
pass
# SPELL RELATED FUNCTIONS
# Set a spell card, sets a roundset
# flag in order to keep track of setting.
def set_spell(pf, player, handind, fpos, cardfaceind = FACE_DOWN_SPELL):
def _set_spell():
pf.SPELL[player][fpos].insert(0, pf.HAND[player].pop(handind))
pf.SPELL[player][fpos]["cardface"] = cardfaceind
pf.AS.append(_set_spell)
ACTION_LIST = {
"hand": {
"monster": {
"Normal Summon": normal_summon,
},
"spell": {
"Set Spell": set_spell,
"Play Spell": play_spell,
},
"trap": {
"Set Trap": set_spell,
"Play Trap": play_spell,
}
},
"play": {
}
}