Skip to content

Commit 3095183

Browse files
committed
pick multiple credits with one click
1 parent 9e174a0 commit 3095183

File tree

2 files changed

+53
-28
lines changed

2 files changed

+53
-28
lines changed

src/clj/game/core/actions.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,14 @@
257257
(defn select
258258
"Attempt to select the given card to satisfy the current select prompt. Calls resolve-select
259259
if the max number of cards has been selected."
260-
[state side {:keys [card]}]
260+
[state side {:keys [card shift-key-held]}]
261261
(let [target (get-card state card)
262262
prompt (first (get-in @state [side :selected]))
263263
ability (:ability prompt)
264264
card-req (:req prompt)
265265
card-condition (:card prompt)
266266
cid (:not-self prompt)]
267+
(swap! state assoc-in [side :shift-key-select] shift-key-held)
267268
(when (and (not= (:cid target) cid)
268269
(cond
269270
card-condition (card-condition target)

src/clj/game/core/pick_counters.clj

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,18 @@
130130
([provider-func outereid] (pick-credit-providing-cards provider-func outereid nil 0 (hash-map)))
131131
([provider-func outereid target-count] (pick-credit-providing-cards provider-func outereid target-count 0 (hash-map)))
132132
([provider-func outereid target-count stealth-target] (pick-credit-providing-cards provider-func outereid target-count stealth-target (hash-map)))
133-
([provider-func outereid target-count stealth-target selected-cards]
133+
([provider-func outereid target-count stealth-target selected-cards] (pick-credit-providing-cards provider-func outereid target-count stealth-target selected-cards nil))
134+
([provider-func outereid target-count stealth-target selected-cards pre-chosen]
134135
(let [counter-count (reduce + 0 (map #(:number (second %) 0) selected-cards))
135136
selected-stealth (filter #(has-subtype? (:card (second %)) "Stealth") selected-cards)
136137
stealth-count (reduce + 0 (map #(:number (second %) 0) selected-stealth))
137138
provider-cards (if (= (- counter-count target-count) (- stealth-count stealth-target))
138139
(filter #(has-subtype? % "Stealth") (provider-func))
139140
(provider-func))
140141
provider-cards (filter #(not (get-in (card-def %) [:interactions :pay-credits :cost-reduction])) provider-cards)
142+
;; note - this allows holding the shift key while clicking a card to keep picking that card while possible
143+
;; ie: taking 5cr from miss bones with one click, instead of waiting for 5 server round-trips
144+
should-auto-repeat? (fn [state side] (get-in @state [side :shift-key-select] nil))
141145
pay-rest (req
142146
(if (and (<= (- target-count counter-count) (get-in @state [side :credit]))
143147
(<= stealth-target stealth-count))
@@ -171,29 +175,49 @@
171175
(zero? (count provider-cards))) ; no more additional credit sources found
172176
{:async true
173177
:effect pay-rest}
174-
{:async true
175-
:prompt (str "Choose a credit providing card ("
176-
counter-count (when (and target-count (pos? target-count))
177-
(str " of " target-count))
178-
" [Credits]"
179-
(if (pos? stealth-target)
180-
(str ", " (min stealth-count stealth-target) " of " stealth-target " stealth")
181-
"")
182-
")")
183-
:choices {:card #(in-coll? (map :cid provider-cards) (:cid %))}
184-
:effect (req (let [pay-credits-type (-> target card-def :interactions :pay-credits :type)
185-
pay-function (if (= :custom pay-credits-type)
186-
(-> target card-def :interactions :pay-credits :custom)
187-
(take-counters-of-type pay-credits-type))
188-
custom-ability ^:ignore-async-check {:async true
189-
:effect pay-function}
190-
neweid (make-eid state outereid)
191-
providing-card target]
192-
(wait-for (resolve-ability state side neweid custom-ability providing-card [card])
193-
(continue-ability state side
194-
(pick-credit-providing-cards
195-
provider-func eid target-count stealth-target
196-
(update selected-cards (:cid providing-card)
197-
#(assoc % :card providing-card :number (+ (:number % 0) async-result))))
198-
card targets))))
199-
:cancel-effect pay-rest}))))
178+
(if (and pre-chosen (in-coll? (map :cid provider-cards) (:cid pre-chosen)))
179+
{:async true
180+
:effect (req (let [target pre-chosen
181+
pay-credits-type (-> target card-def :interactions :pay-credits :type)
182+
pay-function (if (= :custom pay-credits-type)
183+
(-> target card-def :interactions :pay-credits :custom)
184+
(take-counters-of-type pay-credits-type))
185+
custom-ability ^:ignore-async-check {:async true
186+
:effect pay-function}
187+
neweid (make-eid state outereid)
188+
providing-card target]
189+
(wait-for (resolve-ability state side neweid custom-ability providing-card [card])
190+
(continue-ability state side
191+
(pick-credit-providing-cards
192+
provider-func eid target-count stealth-target
193+
(update selected-cards (:cid providing-card)
194+
#(assoc % :card providing-card :number (+ (:number % 0) async-result)))
195+
target)
196+
card targets))))}
197+
{:async true
198+
:prompt (str "Choose a credit providing card ("
199+
counter-count (when (and target-count (pos? target-count))
200+
(str " of " target-count))
201+
" [Credits]"
202+
(if (pos? stealth-target)
203+
(str ", " (min stealth-count stealth-target) " of " stealth-target " stealth")
204+
"")
205+
")")
206+
:choices {:card #(in-coll? (map :cid provider-cards) (:cid %))}
207+
:effect (req (let [pay-credits-type (-> target card-def :interactions :pay-credits :type)
208+
pay-function (if (= :custom pay-credits-type)
209+
(-> target card-def :interactions :pay-credits :custom)
210+
(take-counters-of-type pay-credits-type))
211+
custom-ability ^:ignore-async-check {:async true
212+
:effect pay-function}
213+
neweid (make-eid state outereid)
214+
providing-card target]
215+
(wait-for (resolve-ability state side neweid custom-ability providing-card [card])
216+
(continue-ability state side
217+
(pick-credit-providing-cards
218+
provider-func eid target-count stealth-target
219+
(update selected-cards (:cid providing-card)
220+
#(assoc % :card providing-card :number (+ (:number % 0) async-result)))
221+
(when (should-auto-repeat? state side) target))
222+
card targets))))
223+
:cancel-effect pay-rest})))))

0 commit comments

Comments
 (0)