Skip to content

Commit

Permalink
Remove ugly-counter-hack
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahTheDuke committed Mar 29, 2024
1 parent f1a554c commit cae1845
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 51 deletions.
9 changes: 3 additions & 6 deletions src/clj/game/cards/ice.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2666,15 +2666,11 @@
(defcard "Lycian Multi-Munition"
(letfn [(ice-subtype-choice [choices]
{:prompt "Choose an ice subtype"
:waiting-prompt true
:choices choices
:async true
:effect (req (if (= target "Done")
(effect-completed state side eid)
(let [new-choices (->> choices
(remove #{target})
(cons "Done")
distinct)]
(let [new-choices (remove #{target} choices)]
;; note this is a lingering ability and persists so
;; long as the card is rezzed
;; if the card is hushed, it will not derez, so the subtypes will stay!
Expand All @@ -2691,7 +2687,8 @@
(ice-subtype-choice new-choices)
card nil))))})]
{:on-rez {:async true
:effect (effect (continue-ability (ice-subtype-choice ["Barrier" "Code Gate" "Sentry"]) card nil))}
:waiting-prompt true
:effect (effect (continue-ability (ice-subtype-choice ["Barrier" "Code Gate" "Sentry" "Done"]) card nil))}
:derez-effect {:effect (req (unregister-effects-for-card state side card #(= :gain-subtype (:type %))))}
:static-abilities [{:type :gain-subtype
:req (req (and (same-card? card target) (:subtype-target card)))
Expand Down
27 changes: 14 additions & 13 deletions src/clj/game/core/access.clj
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,20 @@

; Pay credits (from pool or cards) to trash
(= target (first trash-cost-str))
(wait-for (pay state side (make-eid state trash-eid) card [(->c :credit trash-cost)])
(when (:breach @state)
(swap! state assoc-in [:breach :did-trash] true))
(when (:run @state)
(swap! state assoc-in [:run :did-trash] true)
(when must-trash?
(swap! state assoc-in [:run :did-access] true)))
(swap! state assoc-in [:runner :register :trashed-card] true)
(system-msg state side (str (:msg async-result) " to trash "
(:title card) " from "
(name-zone :corp (get-zone card))))
(wait-for (trash state side card {:accessed true})
(access-end state side eid (first async-result) {:trashed true})))
(let [card (update! state side (assoc c :seen true))]
(wait-for (pay state side (make-eid state trash-eid) card [(->c :credit trash-cost)])
(when (:breach @state)
(swap! state assoc-in [:breach :did-trash] true))
(when (:run @state)
(swap! state assoc-in [:run :did-trash] true)
(when must-trash?
(swap! state assoc-in [:run :did-access] true)))
(swap! state assoc-in [:runner :register :trashed-card] true)
(system-msg state side (str (:msg async-result) " to trash "
(:title card) " from "
(name-zone :corp (get-zone card))))
(wait-for (trash state side card {:accessed true})
(access-end state side eid (first async-result) {:trashed true}))))

; Use access ability
(some #(= % target) ability-strs)
Expand Down
33 changes: 7 additions & 26 deletions src/clj/game/core/engine.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
(:require
[clj-uuid :as uuid]
[clojure.stacktrace :refer [print-stack-trace]]
[clojure.string :as str]
[cond-plus.core :refer [cond+]]
[game.core.board :refer [clear-empty-remotes all-installed-runner-type all-active-installed]]
[game.core.card :refer [active? facedown? faceup? get-card get-cid get-title in-discard? in-hand? installed? rezzed? program? console? unique?]]
Expand Down Expand Up @@ -322,28 +321,6 @@
(ability-effect state side eid card targets)
(effect-completed state side eid)))

(defn- ugly-counter-hack
"This is brought over from the old do-ability because using `get-card` or `find-latest`
currently doesn't work properly with `pay-counters`"
[card cost]
;; TODO: Remove me some day
(let [counter-costs
(->> cost
(merge-costs)
(filter #(#{:advancement :agenda :power :virus :bad-publicity} (:cost/type %)))
(seq))]
(if counter-costs
(reduce
(fn [card {counter-type :cost/type
counter-amount :cost/amount}]
(let [counter (if (= :advancement counter-type)
[:advance-counter]
[:counter counter-type])]
(update-in card counter - counter-amount)))
card
counter-costs)
card)))

(defn merge-costs-paid
([cost-paid]
(into {} (map (fn [[k {:keys [type value targets]}]]
Expand All @@ -365,15 +342,19 @@
([cost-paid1 cost-paid2 & costs-paid]
(reduce merge-costs-paid (merge-costs-paid cost-paid1 cost-paid2) costs-paid)))

(defn- do-paid-ability [state side {:keys [eid cost] :as ability} card targets async-result]
(defn- do-paid-ability [state side {:keys [eid] :as ability} card targets async-result]
(let [payment-str (:msg async-result)
cost-paid (merge-costs-paid (:cost-paid eid) (:cost-paid async-result))
ability (assoc-in ability [:eid :cost-paid] cost-paid)]
ability (assoc-in ability [:eid :cost-paid] cost-paid)
;; After paying costs, counters will be removed, so fetch the latest version.
;; We still want the card if the card is trashed, so default to given
;; when the latest is gone.
card (or (get-card state card) card)]
;; Print the message
(print-msg state side ability card targets payment-str)
;; Trigger the effect
(register-once state side ability card)
(do-effect state side ability (ugly-counter-hack card cost) targets)
(do-effect state side ability card targets)
;; If the ability isn't async, complete it
(when-not (:async ability)
(effect-completed state side eid))))
Expand Down
3 changes: 2 additions & 1 deletion src/clj/game/core/runs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@
([state side eid server card] (make-run state side eid server card nil))
([state side eid server card {:keys [click-run ignore-costs] :as args}]
(let [cost-args (assoc args :server (unknown->kw server))
costs (total-run-cost state side card cost-args)]
costs (total-run-cost state side card cost-args)
card (or (get-card state card) card)]
(if-not (and (can-run? state :runner)
(can-run-server? state server)
(can-pay? state :runner eid card "a run" costs))
Expand Down
12 changes: 7 additions & 5 deletions test/clj/game/core/rules_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,23 @@
(deftest trash-seen-and-unseen
;; Trash installed assets that are both seen and unseen by runner
(do-game
(new-game {:corp {:deck [(qty "PAD Campaign" 3)]}})
(play-from-hand state :corp "PAD Campaign" "New remote")
(new-game {:corp {:deck [(qty "Ice Wall" 7)]
:hand ["PAD Campaign" "Sandburg" "NGO Front"]}})
(play-from-hand state :corp "PAD Campaign" "New remote")
(play-from-hand state :corp "Sandburg" "New remote")
(take-credits state :corp 1)
(run-empty-server state "Server 1")
(click-prompt state :runner "No action")
;; run and trash the second asset
(run-empty-server state "Server 2")
(click-prompt state :runner "Pay 4 [Credits] to trash")
(take-credits state :runner 2)
(play-from-hand state :corp "PAD Campaign" "Server 1")
(play-from-hand state :corp "NGO Front" "Server 1")
(is (= "The PAD Campaign in Server 1 will now be trashed." (:msg (prompt-map :corp))))
(click-prompt state :corp "OK")
(is (= 2 (count (:discard (get-corp)))) "Trashed existing asset")
(is (:seen (first (get-in @state [:corp :discard]))) "Asset trashed by runner is Seen")
(is (not (:seen (second (get-in @state [:corp :discard]))))
(is (:seen (find-card "Sandburg" (:discard (get-corp)))) "Asset trashed by runner is Seen")
(is (not (:seen (find-card "PAD Campaign" (:discard (get-corp)))))
"Asset trashed by corp is Unseen")
(is (not (:seen (get-content state :remote1 0))) "New asset is unseen")))

Expand Down

0 comments on commit cae1845

Please sign in to comment.