Skip to content

Commit

Permalink
Fix Divested Trust, forfeiting, and find-latest #4789
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahTheDuke committed Dec 20, 2019
1 parent f732fab commit 295eaba
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 34 deletions.
19 changes: 12 additions & 7 deletions src/clj/game/cards/agendas.clj
Original file line number Diff line number Diff line change
Expand Up @@ -474,23 +474,28 @@
:interactive (req true)
:effect (req (if (:winner @state)
(effect-completed state side eid)
(let [stolen-agenda target
(let [card (find-latest state card)
stolen-agenda (find-latest state target)
title (:title stolen-agenda)
prompt (str "Forfeit Divested Trust to add " title
" to HQ and gain 5[Credits]?")
message (str "add " title " to HQ and gain 5 [Credits]")]
message (str "add " title " to HQ and gain 5 [Credits]")
agenda-side (if (in-runner-scored? state side stolen-agenda)
:runner :corp)
card-side (if (in-runner-scored? state side card)
:runner :corp)]
(show-wait-prompt state :runner "Corp to use Divested Trust")
(continue-ability
state side
{:optional
{:prompt prompt
:yes-ability
{:msg message
:effect (effect (forfeit card)
(move stolen-agenda :hand)
(gain-agenda-point :runner (- (:agendapoints stolen-agenda)))
(gain-credits 5)
(effect-completed eid))}
:effect (req (forfeit state card-side card)
(move state side stolen-agenda :hand)
(gain-agenda-point state agenda-side (- (:agendapoints stolen-agenda)))
(gain-credits state side 5)
(effect-completed state side eid))}
:end-effect (effect (clear-wait-prompt :runner))}}
card nil))))}]}

Expand Down
26 changes: 10 additions & 16 deletions src/clj/game/cards/hardware.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1853,26 +1853,20 @@
:interactive (req true)
:req (req (not (empty? (:scored corp))))
:async true
:effect (req
(let [stolen target]
(continue-ability
state side
:effect (effect
(continue-ability
(let [stolen target]
{:optional
{:prompt (msg "Swap " (:title stolen) " for an agenda in the Corp's score area?")
:yes-ability
{:async true
:effect (req
(continue-ability
state side
{:prompt (str "Select a scored Corp agenda to swap with " (:title stolen))
:choices {:card #(in-corp-scored? state side %)}
:effect (req (let [scored target]
(swap-agendas state side scored stolen)
(system-msg state side (str "uses Turntable to swap "
(:title stolen) " for " (:title scored)))
(effect-completed state side eid)))}
card targets))}}}
card targets)))}]}
:prompt (str "Select a scored Corp agenda to swap with " (:title stolen))
:choices {:card #(in-corp-scored? state side %)}
:effect (effect (swap-agendas target stolen)
(system-msg (str "uses Turntable to swap "
(:title stolen) " for " (:title target)))
(effect-completed eid))}}})
card targets))}]}

"Ubax"
(let [ability {:req (req (:runner-phase-12 @state))
Expand Down
6 changes: 3 additions & 3 deletions src/clj/game/core/cards.clj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
(defn find-latest
"Returns the newest version of a card where-ever it may be"
[state card]
(let [side (-> card :side to-keyword)]
(find-cid (:cid card) (concat (all-installed state side)
(-> (map #(-> @state side %) [:hand :discard :deck :rfg :scored]) concat flatten)))))
(find-cid (:cid card) (concat (all-installed state (-> card :side to-keyword))
(-> (map #(-> @state :corp %) [:hand :discard :deck :rfg :scored]) concat flatten)
(-> (map #(-> @state :runner %) [:hand :discard :deck :rfg :scored]) concat flatten))))

(defn get-scoring-owner
"Returns the owner of the scoring area the card is in"
Expand Down
5 changes: 2 additions & 3 deletions src/clj/game/core/rules.clj
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,8 @@
(when (:msg args)
(system-msg state side (str "forfeits " (:title card))))
(gain-agenda-point state side (- (get-agenda-points state side card)))
(move state side card :rfg)
(wait-for (trigger-event-sync state side (keyword (str (name side) "-forfeit-agenda")) card)
(effect-completed state side eid)))))
(move state (to-keyword (:side card)) card :rfg)
(trigger-event-sync state side eid (keyword (str (name side) "-forfeit-agenda")) card))))

(defn gain-agenda-point
"Gain n agenda points and check for winner."
Expand Down
30 changes: 27 additions & 3 deletions test/clj/game_test/cards/agendas.clj
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,8 @@
(testing "Doesn't stop the runner from winning. Issue #4107"
(do-game
(new-game {:corp {:deck [(qty "Hedge Fund" 10)]
:hand ["Government Takeover" "Hostile Takeover" "Divested Trust"]}})
(core/gain state :corp :click 10)
:hand ["Government Takeover" "Hostile Takeover" "Divested Trust"]
:credits 20}})
(play-and-score state "Divested Trust")
(play-from-hand state :corp "Government Takeover" "New remote")
(take-credits state :corp)
Expand All @@ -748,7 +748,31 @@
(click-prompt state :runner "Steal")
(is (empty? (:prompt (get-corp))) "Corp doesn't get opportunity to use Divested Trust")
(is (= :runner (:winner @state)) "Runner should win")
(is (= "Agenda" (:reason @state)) "Win condition reports points"))))
(is (= "Agenda" (:reason @state)) "Win condition reports points")))
(testing "Interaction with Turntable. Issue #4789"
(do-game
(new-game {:corp {:deck [(qty "Hedge Fund" 10)]
:hand ["Government Takeover" "Divested Trust"]
:credits 20}
:runner {:hand ["Turntable"]}})
(play-and-score state "Divested Trust")
(play-from-hand state :corp "Government Takeover" "New remote")
(take-credits state :corp)
(play-from-hand state :runner "Turntable")
(run-empty-server state "Server 2")
(click-prompt state :runner "Steal")
(is (= "Swap Government Takeover for an agenda in the Corp's score area?"
(:msg (prompt-map :runner)))
"Runner has Turntable prompt")
(click-prompt state :runner "Yes")
(click-card state :runner "Divested Trust")
(click-prompt state :corp "Yes")
(is (zero? (:agenda-point (get-corp))) "Corp has 0 points")
(is (zero? (:agenda-point (get-runner))) "Runner has 0 points")
(is (empty? (:scored (get-corp))) "Corp has no cards scored")
(is (empty? (:scored (get-runner))) "Runner has no cards scored")
(is (find-card "Divested Trust" (:rfg (get-corp))) "Divested Trust should be rfg'd")
(is (find-card "Government Takeover" (:hand (get-corp))) "Gov Takeover should be in HQ"))))

(deftest domestic-sleepers
;; Domestic Sleepers
Expand Down
4 changes: 2 additions & 2 deletions test/clj/game_test/cards/operations.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2998,8 +2998,8 @@
(click-card state :corp c))
(if (= "Misdirection" title)
(is (not (empty? (:prompt (get-corp)))) "Scapenet doesn't work on non-virtual non-chip card.")
(is (= 1 (count (:rfg (get-runner)))) "Card removed from game."))
(is (find-card "Scapenet" (:discard (get-corp))))))))
(do (is (= 1 (count (:rfg (get-runner)))) "Card removed from game.")
(is (find-card "Scapenet" (:discard (get-corp))))))))))

(deftest scarcity-of-resources
;; Scarcity of Resources
Expand Down

0 comments on commit 295eaba

Please sign in to comment.