Skip to content

Commit d18e406

Browse files
authored
Merge pull request #7953 from NBKelly/commit-multiple-creds-with-one-click
Commit multiple creds with one click
2 parents fce6661 + 3095183 commit d18e406

File tree

3 files changed

+61
-35
lines changed

3 files changed

+61
-35
lines changed

src/clj/game/core/actions.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,14 @@
258258
(defn select
259259
"Attempt to select the given card to satisfy the current select prompt. Calls resolve-select
260260
if the max number of cards has been selected."
261-
[state side {:keys [card]}]
261+
[state side {:keys [card shift-key-held]}]
262262
(let [target (get-card state card)
263263
prompt (first (get-in @state [side :selected]))
264264
ability (:ability prompt)
265265
card-req (:req prompt)
266266
card-condition (:card prompt)
267267
cid (:not-self prompt)]
268+
(swap! state assoc-in [side :shift-key-select] shift-key-held)
268269
(when (and (not= (:cid target) cid)
269270
(cond
270271
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
@@ -119,14 +119,18 @@
119119
([provider-func outereid] (pick-credit-providing-cards provider-func outereid nil 0 (hash-map)))
120120
([provider-func outereid target-count] (pick-credit-providing-cards provider-func outereid target-count 0 (hash-map)))
121121
([provider-func outereid target-count stealth-target] (pick-credit-providing-cards provider-func outereid target-count stealth-target (hash-map)))
122-
([provider-func outereid target-count stealth-target selected-cards]
122+
([provider-func outereid target-count stealth-target selected-cards] (pick-credit-providing-cards provider-func outereid target-count stealth-target selected-cards nil))
123+
([provider-func outereid target-count stealth-target selected-cards pre-chosen]
123124
(let [counter-count (reduce + 0 (map #(:number (second %) 0) selected-cards))
124125
selected-stealth (filter #(has-subtype? (:card (second %)) "Stealth") selected-cards)
125126
stealth-count (reduce + 0 (map #(:number (second %) 0) selected-stealth))
126127
provider-cards (if (= (- counter-count target-count) (- stealth-count stealth-target))
127128
(filter #(has-subtype? % "Stealth") (provider-func))
128129
(provider-func))
129130
provider-cards (filter #(not (get-in (card-def %) [:interactions :pay-credits :cost-reduction])) provider-cards)
131+
;; note - this allows holding the shift key while clicking a card to keep picking that card while possible
132+
;; ie: taking 5cr from miss bones with one click, instead of waiting for 5 server round-trips
133+
should-auto-repeat? (fn [state side] (get-in @state [side :shift-key-select] nil))
130134
pay-rest (req
131135
(if (and (<= (- target-count counter-count) (get-in @state [side :credit]))
132136
(<= stealth-target stealth-count))
@@ -160,29 +164,49 @@
160164
(zero? (count provider-cards))) ; no more additional credit sources found
161165
{:async true
162166
:effect pay-rest}
163-
{:async true
164-
:prompt (str "Choose a credit providing card ("
165-
counter-count (when (and target-count (pos? target-count))
166-
(str " of " target-count))
167-
" [Credits]"
168-
(if (pos? stealth-target)
169-
(str ", " (min stealth-count stealth-target) " of " stealth-target " stealth")
170-
"")
171-
")")
172-
:choices {:card #(in-coll? (map :cid provider-cards) (:cid %))}
173-
:effect (req (let [pay-credits-type (-> target card-def :interactions :pay-credits :type)
174-
pay-function (if (= :custom pay-credits-type)
175-
(-> target card-def :interactions :pay-credits :custom)
176-
(take-counters-of-type pay-credits-type))
177-
custom-ability ^:ignore-async-check {:async true
178-
:effect pay-function}
179-
neweid (make-eid state outereid)
180-
providing-card target]
181-
(wait-for (resolve-ability state side neweid custom-ability providing-card [card])
182-
(continue-ability state side
183-
(pick-credit-providing-cards
184-
provider-func eid target-count stealth-target
185-
(update selected-cards (:cid providing-card)
186-
#(assoc % :card providing-card :number (+ (:number % 0) async-result))))
187-
card targets))))
188-
:cancel-effect pay-rest}))))
167+
(if (and pre-chosen (in-coll? (map :cid provider-cards) (:cid pre-chosen)))
168+
{:async true
169+
:effect (req (let [target pre-chosen
170+
pay-credits-type (-> target card-def :interactions :pay-credits :type)
171+
pay-function (if (= :custom pay-credits-type)
172+
(-> target card-def :interactions :pay-credits :custom)
173+
(take-counters-of-type pay-credits-type))
174+
custom-ability ^:ignore-async-check {:async true
175+
:effect pay-function}
176+
neweid (make-eid state outereid)
177+
providing-card target]
178+
(wait-for (resolve-ability state side neweid custom-ability providing-card [card])
179+
(continue-ability state side
180+
(pick-credit-providing-cards
181+
provider-func eid target-count stealth-target
182+
(update selected-cards (:cid providing-card)
183+
#(assoc % :card providing-card :number (+ (:number % 0) async-result)))
184+
target)
185+
card targets))))}
186+
{:async true
187+
:prompt (str "Choose a credit providing card ("
188+
counter-count (when (and target-count (pos? target-count))
189+
(str " of " target-count))
190+
" [Credits]"
191+
(if (pos? stealth-target)
192+
(str ", " (min stealth-count stealth-target) " of " stealth-target " stealth")
193+
"")
194+
")")
195+
:choices {:card #(in-coll? (map :cid provider-cards) (:cid %))}
196+
:effect (req (let [pay-credits-type (-> target card-def :interactions :pay-credits :type)
197+
pay-function (if (= :custom pay-credits-type)
198+
(-> target card-def :interactions :pay-credits :custom)
199+
(take-counters-of-type pay-credits-type))
200+
custom-ability ^:ignore-async-check {:async true
201+
:effect pay-function}
202+
neweid (make-eid state outereid)
203+
providing-card target]
204+
(wait-for (resolve-ability state side neweid custom-ability providing-card [card])
205+
(continue-ability state side
206+
(pick-credit-providing-cards
207+
provider-func eid target-count stealth-target
208+
(update selected-cards (:cid providing-card)
209+
#(assoc % :card providing-card :number (+ (:number % 0) async-result)))
210+
(when (should-auto-repeat? state side) target))
211+
card targets))))
212+
:cancel-effect pay-rest})))))

src/cljs/nr/gameboard/board.cljs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,13 @@
170170
(:poison card)
171171
(:highlight-in-discard card))))
172172

173-
(defn handle-card-click [{:keys [type zone] :as card}]
173+
(defn handle-card-click [{:keys [type zone] :as card} shift-key-held]
174174
(let [side (:side @game-state)]
175175
(when (not-spectator?)
176176
(cond
177177
;; Selecting card
178178
(= (get-in @game-state [side :prompt-state :prompt-type]) "select")
179-
(send-command "select" {:card (card-for-click card)})
179+
(send-command "select" {:card (card-for-click card) :shift-key-held shift-key-held})
180180

181181
;; Card is an identity of player's side
182182
(and (= (:type card) "Identity")
@@ -189,7 +189,7 @@
189189
(not (any-prompt-open? side))
190190
(= "hand" (first zone))
191191
(playable? card))
192-
(send-command "play" {:card (card-for-click card)})
192+
(send-command "play" {:card (card-for-click card) :shift-key-held shift-key-held})
193193

194194
;; Corp clicking on a corp card
195195
(and (= side :corp)
@@ -202,7 +202,8 @@
202202
(if (= (:cid card) (:source @card-menu))
203203
(do (send-command "generate-install-list" nil)
204204
(close-card-menu))
205-
(do (send-command "generate-install-list" {:card (card-for-click card)})
205+
(do (send-command "generate-install-list" {:card (card-for-click card)
206+
:shift-key-held shift-key-held})
206207
(open-card-menu (:cid card)))))
207208

208209
:else
@@ -722,13 +723,13 @@
722723
(put-game-card-in-channel card zoom-channel))
723724
:on-mouse-leave #(put! zoom-channel false)
724725
:on-click #(when (not disable-click)
725-
(handle-card-click card))
726+
(handle-card-click card (.-shiftKey %)))
726727
:on-key-down #(when (and (= "Enter" (.-key %))
727728
(not disable-click))
728-
(handle-card-click card))
729+
(handle-card-click card (.-shiftKey %)))
729730
:on-key-up #(when (and (= " " (.-key %))
730731
(not disable-click))
731-
(handle-card-click card))}
732+
(handle-card-click card (.-shiftKey %)))}
732733
(if (or (not code) flipped facedown)
733734
(let [facedown-but-known (or (not (or (not code) flipped facedown))
734735
(spectator-view-hidden?)

0 commit comments

Comments
 (0)