Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add :psi to eid, Net Mercur pay-credits req #4383

Merged
merged 2 commits into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/clj/game/cards/events.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1607,7 +1607,7 @@

"Net Celebrity"
{:recurring 1
:interactions {:pay-credits {:req (req (:run @state))
:interactions {:pay-credits {:req (req run)
:type :recurring}}}

"Networking"
Expand Down
8 changes: 4 additions & 4 deletions src/clj/game/cards/resources.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1042,8 +1042,7 @@
(when (not (pos? (get-counters (get-card state card) :credit)))
(trash state :runner card {:unpreventable true}))))}]
:events (trash-on-empty :credit)
; See Net Mercur for why this implementation was chosen
:interactions {:pay-credits {:req (req (:run @state))
:interactions {:pay-credits {:req (req run)
:type :credit}}}

"Globalsec Security Clearance"
Expand Down Expand Up @@ -1481,8 +1480,9 @@
card nil))}}
; Normally this should be (req true), but having pay-credits prompts on
; literally every interaction would get tiresome. Therefore Net Mercur will
; only ask for payments during a run and on traces.
:interactions {:pay-credits {:req (req (or (:run @state)
; only ask for payments during a run, traces, and psi games
:interactions {:pay-credits {:req (req (or run
(= :psi (:source-type eid))
(= :trace (:source-type eid))))
:type :credit}}}

Expand Down
49 changes: 25 additions & 24 deletions src/clj/game/core/abilities.clj
Original file line number Diff line number Diff line change
Expand Up @@ -313,22 +313,21 @@
(defn psi-game
"Starts a psi game by showing the psi prompt to both players. psi is a map containing
:equal and :not-equal abilities which will be triggered in resolve-psi accordingly."
([state side card psi] (psi-game state side (make-eid state) card psi))
([state side card psi] (psi-game state side (make-eid state {:source-type :psi}) card psi))
([state side eid card psi]
(swap! state assoc :psi {})
(register-once state psi card)
(system-msg state (:player psi :corp) (str "uses " (:title card) " to start a psi game"))
(doseq [s [:corp :runner]]
(let [all-amounts (range (min 3 (inc (get-in @state [s :credit]))))
valid-amounts (remove #(or (any-flag-fn? state :corp :prevent-secretly-spend %)
(any-flag-fn? state :runner :prevent-secretly-spend %))
all-amounts)]

(show-prompt-with-dice state s card (str "Choose an amount to spend for " (:title card))
(map #(str % " [Credits]") valid-amounts)
#(resolve-psi state s eid card psi (str->int (first (split % #" "))))
{:priority 2
:prompt-type :psi})))))
(let [eid (assoc eid :source-type :psi)]
(doseq [s [:corp :runner]]
(let [all-amounts (range (min 3 (inc (total-available-credits state s eid card))))
valid-amounts (remove #(or (any-flag-fn? state :corp :prevent-secretly-spend %)
(any-flag-fn? state :runner :prevent-secretly-spend %))
all-amounts)]
(show-prompt-with-dice state s card (str "Choose an amount to spend for " (:title card))
(map #(str % " [Credits]") valid-amounts)
#(resolve-psi state s eid card psi (str->int (first (split % #" "))))
{:priority 2
:prompt-type :psi}))))))

(defn resolve-psi
"Resolves a psi game by charging credits to both sides and invoking the appropriate
Expand All @@ -337,16 +336,18 @@
(swap! state assoc-in [:psi side] bet)
(let [opponent (if (= side :corp) :runner :corp)]
(if-let [opponent-bet (get-in @state [:psi opponent])]
(do (clear-wait-prompt state opponent)
(deduct state opponent [:credit opponent-bet])
(system-msg state opponent (str "spends " opponent-bet " [Credits]"))
(deduct state side [:credit bet])
(system-msg state side (str "spends " bet " [Credits]"))
(wait-for (trigger-event-simult state side :reveal-spent-credits nil (get-in @state [:psi :corp]) (get-in @state [:psi :runner]))
(wait-for
(pay-sync state opponent (make-eid state eid) card [:credit opponent-bet])
(system-msg state opponent async-result)
(wait-for
(pay-sync state side (make-eid state eid) card [:credit bet])
(system-msg state side async-result)
(clear-wait-prompt state opponent)
(wait-for (trigger-event-simult state side (make-eid state eid) :reveal-spent-credits nil (get-in @state [:psi :corp]) (get-in @state [:psi :runner]))
(if-let [ability (if (= bet opponent-bet) (:equal psi) (:not-equal psi))]
(let [card-side (if (corp? card) :corp :runner)]
(continue-ability state card-side (assoc ability :async true) card nil))
(effect-completed state side eid))))
(effect-completed state side eid)))))
(show-wait-prompt
state side (str (string/capitalize (name opponent)) " to choose psi game credits")))))

Expand Down Expand Up @@ -380,8 +381,8 @@
strength)
trigger-trace (select-keys trace [:player :other :base :bonus :link :priority :ability :strength])]
(wait-for (pay-sync state other (make-eid state eid) card [:credit boost])
(system-msg state other (str "spends " boost
" [Credits] to increase " (if (corp-start? trace) "link" "trace")
(system-msg state other (str async-result
" to increase " (if (corp-start? trace) "link" "trace")
" strength to " (if (corp-start? trace)
runner-strength
corp-strength)))
Expand Down Expand Up @@ -421,8 +422,8 @@
((fnil + 0 0) link boost))
trace (assoc trace :strength strength)]
(wait-for (pay-sync state player (make-eid state eid) card [:credit boost])
(system-msg state player (str "spends " boost
" [Credits] to increase " (if (corp-start? trace) "trace" "link")
(system-msg state player (str async-result
" to increase " (if (corp-start? trace) "trace" "link")
" strength to " strength))
(clear-wait-prompt state other)
(show-wait-prompt state player
Expand Down
23 changes: 22 additions & 1 deletion test/clj/game_test/cards/resources.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,28 @@
"Used 1 credit from Ghost Runner"
(card-ability state :runner refr 1)
(click-card state :runner gr))
(is (not-empty (:discard (get-runner))) "Empty Ghost Runner trashed")))))
(is (not-empty (:discard (get-runner))) "Empty Ghost Runner trashed"))))
(testing "Can be used in psi games. Issue #1149"
(do-game
(new-game {:corp {:deck [(qty "Hedge Fund" 5)]
:hand ["Snowflake"]}
:runner {:hand ["Ghost Runner"]
:credits 1}})
(play-from-hand state :corp "Snowflake" "HQ")
(core/rez state :corp (get-ice state :hq 0))
(take-credits state :corp)
(play-from-hand state :runner "Ghost Runner")
(run-on state :hq)
(let [sf (get-ice state :hq 0)
gr (get-resource state 0)]
(card-subroutine state :corp sf 0)
(is (zero? (:credit (get-runner))) "Runner has 0 credits")
(click-prompt state :corp "0 [Credits]")
(click-prompt state :runner "2 [Credits]")
(click-card state :runner gr)
(click-card state :runner gr)
(is (zero? (:credit (get-runner))) "Runner still has 0 credits")
(is (= 1 (get-counters (refresh gr) :credit)) "Ghost Runner now has only 1 credit")))))

(deftest globalsec-security-clearance
;; Globalsec Security Clearance - Ability, click lost on use
Expand Down