Skip to content

Commit d19dac9

Browse files
authored
Merge pull request #8448 from NBKelly/unique-trashes-by-timestamp
rules test to ensure uniques trash correctly even when hosting is involved
2 parents 57c735b + fca8ae5 commit d19dac9

File tree

6 files changed

+51
-17
lines changed

6 files changed

+51
-17
lines changed

src/clj/game/core/engine.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@
11601160
(reduce-kv
11611161
(fn [acc _title cards]
11621162
(if (< 1 (count cards))
1163-
(conj! acc (butlast cards))
1163+
(conj! acc (butlast (sort-by :timestamp cards)))
11641164
acc))
11651165
(transient []))
11661166
persistent!

src/clj/game/core/hosting.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
[game.core.initializing :refer [card-init]]
99
[game.core.memory :refer [init-mu-cost]]
1010
[game.core.update :refer [update! update-hosted!]]
11-
[game.utils :refer [remove-once same-card?]]))
11+
[game.utils :refer [make-timestamp remove-once same-card?]]))
1212

1313
(defn remove-from-host
1414
"Removes a card from its host."
@@ -54,6 +54,7 @@
5454
:host (dissoc card :hosted)
5555
:facedown facedown
5656
:zone [:onhost] ;; hosted cards should not be in :discard or :hand etc
57+
:timestamp (make-timestamp)
5758
:previous-zone (:zone target))
5859
;; Update any cards hosted by the target, so their :host has the updated zone.
5960
target (update target :hosted #(map (fn [h] (assoc h :host target)) %))

src/clj/game/core/initializing.clj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
[game.core.props :refer [add-counter]]
1616
[game.core.update :refer [update!]]
1717
[game.macros :refer [req]]
18-
[game.utils :refer [make-cid server-card to-keyword]]
18+
[game.utils :refer [make-cid make-timestamp server-card to-keyword]]
1919
[jinteki.utils :refer [make-label]]))
2020

2121
(defn subroutines-init
@@ -199,6 +199,7 @@
199199
:subroutines (subroutines-init (assoc card :cid cid) cdef)
200200
:abilities (ability-init cdef)
201201
:x-fn (:x-fn cdef)
202+
:timestamp (make-timestamp)
202203
:poison (:poison cdef)
203204
:highlight-in-discard (:highlight-in-discard cdef)
204205
:printed-title (:title card))

src/clj/game/core/moving.clj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
[game.core.update :refer [update!]]
2222
[game.core.winning :refer [check-win-by-agenda]]
2323
[game.macros :refer [wait-for when-let*]]
24-
[game.utils :refer [dissoc-in make-cid remove-once same-card? same-side? to-keyword]]
24+
[game.utils :refer [dissoc-in make-cid make-timestamp remove-once same-card? same-side? to-keyword]]
2525
[medley.core :refer [insert-nth]]))
2626

2727
(defn- trim-cause-card
@@ -62,7 +62,6 @@
6262
"Get the moved cards with correct abilities and keys hooked up / removed etc."
6363
[state side {:keys [zone host installed] :as card} to]
6464
(let [zone (if host (map to-keyword (:zone host)) zone)
65-
6665
src-zone (first zone)
6766
target-zone (if (vector? to) (first to) to)
6867
same-zone? (= src-zone target-zone)
@@ -141,10 +140,16 @@
141140
(contains? #{:deck :hand :discard} target-zone))
142141
(make-cid)
143142
(:cid c))
143+
timestamp (if (or (and (not (contains? #{:deck :hand :discard} src-zone))
144+
(contains? #{:deck :hand :discard} target-zone))
145+
(and (not installed) to-installed))
146+
(make-timestamp)
147+
(:timestamp c))
144148
moved-card (assoc c :zone dest
145149
:host nil
146150
:hosted hosted
147151
:cid cid
152+
:timestamp timestamp
148153
:previous-zone (:zone c))
149154
;; Set up abilities for stolen agendas
150155
moved-card (if (and (= :scored (first dest))

src/clj/game/utils.clj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
(:require
33
[jinteki.cards :refer [all-cards]]
44
[clojure.string :as str]
5-
[clj-uuid :as uuid]))
5+
[clj-uuid :as uuid]
6+
[cljc.java-time.instant :as inst]))
67

78
(defn make-cid []
89
(uuid/to-string (uuid/v4)))
910

11+
(defn make-timestamp []
12+
(inst/now))
13+
1014
(defn server-card
1115
([title] (server-card title true))
1216
([title strict?]

test/clj/game/core/rules_test.clj

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,46 @@
5050
:credits 100}})
5151
(take-credits state :corp)
5252
(play-from-hand state :runner "Kati Jones")
53+
(card-ability state :runner (get-resource state 0) 0)
54+
(is (= 3 (get-counters (get-resource state 0) :credit)) "Placed 3")
5355
(play-from-hand state :runner "Kati Jones")
56+
(is (= 0 (get-counters (get-resource state 0) :credit)) "Correct kati was trashed")
5457
(is (find-card "Kati Jones" (get-resource state)))
5558
(is (last-log-contains? state "Kati Jones is trashed."))))
5659

5760
(deftest installing-second-unique-on-off-campus-apartment-trashes-first-test
58-
(do-game
59-
(new-game {:runner {:hand [(qty "Kati Jones" 2) "Off-Campus Apartment"]
60-
:credits 100}})
61-
(take-credits state :corp)
62-
(play-from-hand state :runner "Kati Jones")
63-
(play-from-hand state :runner "Off-Campus Apartment")
64-
(let [oca (get-resource state 1)]
65-
(play-from-hand state :runner "Kati Jones")
66-
(click-prompt state :runner "Off-Campus Apartment")
67-
(is (find-card "Kati Jones" (:hosted (refresh oca))))
61+
(testing "Should trash the kati in the rig"
62+
(do-game
63+
(new-game {:runner {:hand [(qty "Kati Jones" 2) "Off-Campus Apartment"]
64+
:credits 100}})
65+
(take-credits state :corp)
66+
(play-cards state :runner "Off-Campus Apartment" ["Kati Jones" "The Rig"] ["Kati Jones" "Off-Campus Apartment"])
67+
(is (find-card "Kati Jones" (:hosted (get-resource state 0))))
68+
(is (= "Kati Jones" (:title (get-discarded state :runner))))
69+
(is (last-log-contains? state "Kati Jones is trashed."))))
70+
(testing "Should trash the kati on OCA"
71+
(do-game
72+
(new-game {:runner {:hand [(qty "Kati Jones" 2) "Off-Campus Apartment"]
73+
:credits 100}})
74+
(take-credits state :corp)
75+
(play-cards state :runner "Off-Campus Apartment" ["Kati Jones" "Off-Campus Apartment"] ["Kati Jones" "The Rig"])
76+
(is (= "Kati Jones" (:title (get-resource state 1))))
77+
(is (not (find-card "Kati Jones" (:hosted (get-resource state 0)))))
78+
(is (= "Kati Jones" (:title (get-discarded state :runner))))
79+
(is (last-log-contains? state "Kati Jones hosted on .* is trashed."))))
80+
(testing "Should trash the loaded kati on OCA"
81+
(do-game
82+
(new-game {:runner {:hand [(qty "Kati Jones" 2) "Off-Campus Apartment"]
83+
:credits 100}})
84+
(take-credits state :corp)
85+
(play-cards state :runner "Off-Campus Apartment" ["Kati Jones" "Off-Campus Apartment"])
86+
(card-ability state :runner (first (:hosted (get-resource state 0))) 0)
87+
(is (= 3 (get-counters (first (:hosted (get-resource state 0))) :credit)) "Placed 3")
88+
(play-cards state :runner ["Kati Jones" "Off-Campus Apartment"])
89+
(is (= 0 (get-counters (first (:hosted (get-resource state 0))) :credit)) "Correct kati trash")
90+
(is (find-card "Kati Jones" (:hosted (get-resource state 0))))
6891
(is (= "Kati Jones" (:title (get-discarded state :runner))))
69-
(is (last-log-contains? state "Kati Jones is trashed.")))))
92+
(is (last-log-contains? state "Kati Jones hosted on .* is trashed.")))))
7093

7194
(deftest installing-second-hivemind-trashes-hosted-hivemind-test
7295
(do-game

0 commit comments

Comments
 (0)