Skip to content

Commit

Permalink
Changed play-auto-pump to use pay-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
lostgeek committed Jul 2, 2019
1 parent c5020b8 commit 5e0fa8c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
15 changes: 9 additions & 6 deletions src/clj/game/core/actions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -310,20 +310,23 @@
[state side args]
(let [run (:run @state)
card (get-card state (:card args))
eid (make-eid state {:source card :source-type :ability})
run-ice (get-run-ices state)
ice-cnt (count run-ice)
ice-idx (dec (:position run 0))
in-range (and (pos? ice-cnt) (< -1 ice-idx ice-cnt))
current-ice (when (and run in-range) (get-card state (run-ice ice-idx)))
pumpabi (some #(when (:pump %) %) (:abilities (card-def card)))
pumpcst (when pumpabi (second (drop-while #(and (not= % :credit) (not= % "credit")) (:cost pumpabi))))
strdif (when current-ice (max 0 (- (or (:current-strength current-ice) (:strength current-ice))
(or (:current-strength card) (:strength card)))))
pumpnum (when strdif (int (Math/ceil (/ strdif (:pump pumpabi 1)))))]
(when (and pumpnum pumpcst (>= (get-in @state [:runner :credit]) (* pumpnum pumpcst)))
(dotimes [n pumpnum] (resolve-ability state side (dissoc pumpabi :msg) (get-card state card) nil))
(system-msg state side (str "spends " (* pumpnum pumpcst) " [Credits] to increase the strength of "
(:title card) " to " (:current-strength (get-card state card)))))))
pumpnum (when strdif (int (Math/ceil (/ strdif (:pump pumpabi 1)))))
total-pump-cost (merge-costs (repeat pumpnum (:cost pumpabi)))]
(when (can-pay? state side eid card total-pump-cost)
(wait-for (pay-sync state side (make-eid state eid) card total-pump-cost)
(dotimes [n pumpnum] (resolve-ability state side (dissoc pumpabi :cost :msg) (get-card state card) nil))
(system-msg state side (str (build-spend-msg async-result "increase")
"the strength of " (:title card) " to "
(:current-strength (get-card state card))))))))

(defn play-copy-ability
"Play an ability from another card's definition."
Expand Down
25 changes: 23 additions & 2 deletions test/clj/game_test/engine/costs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,26 @@
(play-from-hand state :runner "Daily Casts")
(is (last-log-contains? state #"Runner spends \[Click\] and pays 3 \[Credits\] to install Daily Casts.") "Install resource, three cost")
(run-on state :archives)
(is (last-log-contains? state #"Runner spends \[Click\] to make a run on Archives.") "Initiate run, zero cost"))))

(is (last-log-contains? state #"Runner spends \[Click\] to make a run on Archives.") "Initiate run, zero cost")))
(testing "Issue #4295: Auto-pumping Icebreaker with pay-credits prompt"
(do-game
(new-game {:runner {:hand ["Corroder" "Net Mercur" "Cloak"]}
:corp {:hand ["Fire Wall"]}})
(play-from-hand state :corp "Fire Wall" "HQ")
(take-credits state :corp)
(core/gain state :runner :credit 10)
(play-from-hand state :runner "Corroder")
(play-from-hand state :runner "Cloak")
(play-from-hand state :runner "Net Mercur")
(run-on state :hq)
(let [cre (:credit (get-runner))
cor (get-program state 0)
clo (get-program state 1)
nm (get-resource state 0)]
(is (= 2 (:current-strength (refresh cor))) "Corroder starts at 2 strength")
(core/play-dynamic-ability state :runner {:dynamic "auto-pump" :card (refresh cor)})
(click-card state :runner clo)
(println (last (:log @state)))
(click-prompt state :runner "Place 1 [Credits]")
(is (= 5 (:current-strength (refresh cor))) "Corroder is at 5 strength")
(is (= (- cre 2) (:credit (get-runner))) "Spent 2 (+1 from Cloak) to pump")))))

0 comments on commit 5e0fa8c

Please sign in to comment.