-
Notifications
You must be signed in to change notification settings - Fork 0
/
button_discard.ttslua
150 lines (137 loc) · 5.07 KB
/
button_discard.ttslua
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
discard_zone_GUID = "7093af"
action_pool_GUID = "d6a3af"
function onload(save_state)
discard_zone = getObjectFromGUID(discard_zone_GUID)
action_pool = getObjectFromGUID(action_pool_GUID)
action_pool_pos = action_pool.getPosition()
self.createButton(
{
click_function = "pressed",
label = "discard",
function_owner = self,
position = {0, 0.3, 1},
rotation = {0, 180, 0},
width = 1500,
height = 600,
font_size = 500
}
)
end
function pressed()
-- consumes nothing, discards jokers in the discard pile,
-- shuffles the pile, and moves it to the action card pool.
discard_zone_objects = discard_zone.getObjects()
discarded = do_discards_from_discard_zone()
if discarded ~= false then
shuffle_discards()
move_discards_to_action_pool()
end
end
function move_discards_to_action_pool()
-- consumes nothing and moves the card or deck in the discard pile to the
-- action pool, if there is a card or deck.
objects_in_discard_zone = discard_zone.getObjects()
if #objects_in_discard_zone > 1 then
printToColor("I can only move one item at a time to the action pile...", "Black")
return false
elseif #objects_in_discard_zone < 1 then
printToColor("Can't move nothing to the action pile...", "Black")
return false
end
object_to_shuffle = objects_in_discard_zone[1]
if not should_be_sent_to_action_pool_P(object_to_shuffle) then
printToColor("That doesn't belong in the action pool, I'm leaving it here.", "Black")
return false
end
return objects_in_discard_zone[1].setPositionSmooth(action_pool_pos)
end
function should_be_sent_to_action_pool_P(obj)
-- consumes an object and returns true if it should be sent to
-- the action pool, false otherwise.
return can_do_discard_P(obj)
end
function can_be_shuffled_P(obj)
-- consumes a n object and produces true if the object can be
-- shuffled, false otherwise
local quasitype = Global.call('get_quasi_type', obj)
if quasitype == "Deck" then return true end
return false
end
function shuffle_discards()
-- consumes nothing and shuffles the deck in the discard zone,
-- if there is a deck in the discard zone.
objects_in_discard_zone = discard_zone.getObjects()
if #objects_in_discard_zone > 1 then
printToColor("I can only shuffle a single item! Please feed me a deck", "Black")
return false
elseif #objects_in_discard_zone < 1 then
printToColor("I need something to shuffle! Give me a deck!", "Black")
return false
end
object_to_shuffle = objects_in_discard_zone[1]
if not can_be_shuffled_P(object_to_shuffle) then
printToColor("That can't be shuffled! give me a deck...", "Black")
return false
end
return objects_in_discard_zone[1].shuffle()
end
function can_do_discard_P(obj)
discardables = {"CardCustom", "Deck"}
object_quasitype = Global.call("get_quasi_type", obj)
for _, val in ipairs(discardables) do
if val == object_quasitype then
return true
end
end
return false
end
function do_discards_from_discard_zone()
-- consumes nothing, gets a list of all the objects in the
-- discard zone, and destroys all the assimilation cards it sees.
-- assumes that there is at least one, and only one object, a deck
-- or a card, in the zone.
discard_zone_objects = discard_zone.getObjects()
if #discard_zone_objects < 1 then
printToColor("Give me something to discard! A deck or a card by preference.", "Black")
return false
elseif #discard_zone_objects > 1 then
printToColor("There must only be one object, a card or a deck, in the discard pile. Aborting...", "Black")
return false
elseif not can_do_discard_P(discard_zone_objects[1]) then
printToColor("I can't discard that, give me a deck or a card.", "Black")
return false
end
card_or_deck_in_discard_zone = discard_zone_objects[1]
return object_do_discards(card_or_deck_in_discard_zone)
end
function object_do_discards(obj)
-- consumes a card or a deck and destroys all the jokers it touches
local item_class = Global.call("get_quasi_type", obj)
if item_class == "CardCustom" then
return card_do_discards(obj)
elseif item_class == "Deck" then
return deck_do_discards(obj)
else
return false
end
end
function card_do_discards(card)
-- examines a card and destroys it if it's a joker.
if Global.call("is_a_joker", card) then
destroyObject(card)
end
return true
end
function deck_do_discards(deck)
-- examines a deck and destroys all its jokers.
for _, card_desc in pairs(deck.getObjects()) do
if Global.call("card_desc_is_a_joker", card_desc) then
take_params = {
guid = card_desc.guid,
callback_function = card_do_discards
}
local joker_card = deck.takeObject(take_params)
end
end
return true
end