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

Clean up set aside #7800

Merged
merged 3 commits into from
Oct 8, 2024
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
8 changes: 3 additions & 5 deletions src/clj/game/cards/resources.clj
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
[game.core.servers :refer [central->name is-central? is-remote?
protecting-same-server? remote->name target-server unknown->kw
zone->name zones->sorted-names]]
[game.core.set-aside :refer [set-aside get-set-aside set-aside-for-me]]
[game.core.set-aside :refer [set-aside set-aside-for-me]]
[game.core.shuffling :refer [shuffle!]]
[game.core.tags :refer [gain-tags lose-tags tag-prevent]]
[game.core.to-string :refer [card-str]]
Expand Down Expand Up @@ -3084,8 +3084,7 @@
{:cost-bonus -1
:no-toast true}))
(seq (:hosted card))))
:effect (req (set-aside state side eid (:hosted card))
(let [set-aside-cards (get-set-aside state side eid)]
:effect (req (let [set-aside-cards (set-aside state side eid (:hosted card))]
(wait-for (trash state side card {:cause :ability-cost :cause-card card})
(system-msg state side "trashed")
(continue-ability
Expand Down Expand Up @@ -3303,8 +3302,7 @@
:once-key :the-class-act-put-bottom
:async true
:effect
(req (set-aside-for-me state :runner eid (take (inc target) (:deck runner)))
(let [cards (get-set-aside state :runner eid)]
(req (let [cards (set-aside-for-me state :runner eid (take (inc target) (:deck runner)))]
(continue-ability
state side
{:waiting-prompt true
Expand Down
3 changes: 1 addition & 2 deletions src/clj/game/core/drawing.clj
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@
(effect-completed state side eid)
(let [to-draw (take draws-after-prevent (get-in @state [side :deck]))
set-aside-eid eid]
(set-aside-for-me state side set-aside-eid to-draw)
(let [drawn (get-set-aside state side set-aside-eid)
(let [drawn (set-aside-for-me state side set-aside-eid to-draw)
drawn-count (count drawn)]
(swap! state update-in [side :register :drawn-this-turn] (fnil #(+ % drawn-count) 0))
(if (not no-update-draw-stats)
Expand Down
18 changes: 11 additions & 7 deletions src/clj/game/core/set_aside.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@
[game.core.card :refer [in-set-aside?]]
[game.core.eid :refer [effect-completed]]
[game.core.moving :refer [move swap-cards]]
[game.utils :refer [dissoc-in]]
[clojure.string :as string]))

(defn set-aside
"move a group of cards to the set-aside zone. Does not call effect-completed on the eid"
([state side eid cards] (set-aside state side eid cards true true))
;(swap! state assoc-in [side :set-aside-tracking (:eid eid)] (map :cid cards))
;(doseq [c cards] (move state side c :set-aside))
;(effect-completed state side eid))
([state side eid cards corp-vis runner-vis]
(swap! state assoc-in [side :set-aside-tracking (:eid eid)] (map :cid cards))
(doseq [c cards]
(move state side (assoc c
:set-aside-visibility {:corp-can-see corp-vis :runner-can-see runner-vis}
:set-aside-eid eid) :set-aside))))
(mapv #(move state side (assoc % :set-aside-visibility {:corp-can-see corp-vis :runner-can-see runner-vis}
:set-aside-eid eid) :set-aside)
cards)))

(defn set-aside-for-me
"sets aside cards visible only to the player setting them aside"
Expand All @@ -35,6 +32,13 @@
(filter #(contains? cids (:cid %)))
(into []))))

(defn clean-set-aside!
"cleans stale entries out of the set aside tracker"
[state side]
(let [to-clear (filter #(empty? (get-set-aside state side {:eid %})) (keys (get-in @state [side :set-aside-tracking])))]
(doseq [eid to-clear]
(swap! state dissoc-in [side :set-aside-tracking eid]))))

;; adds a card into the set aside zone using a given cid (ie add it to the set of cards in a draw)
(defn add-to-set-aside
"Adds a card into an existing set-aside eid tracker"
Expand Down
2 changes: 2 additions & 0 deletions src/clj/game/core/turns.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
[game.core.ice :refer [update-all-ice update-breaker-strength]]
[game.core.moving :refer [move]]
[game.core.say :refer [system-msg]]
[game.core.set-aside :refer [clean-set-aside!]]
[game.core.toasts :refer [toast]]
[game.core.update :refer [update!]]
[game.core.winning :refer [flatline]]
Expand Down Expand Up @@ -143,6 +144,7 @@
(unregister-floating-events state side :end-of-next-run)
(unregister-lingering-effects state side (if (= side :runner) :until-runner-turn-ends :until-corp-turn-ends))
(unregister-floating-events state side (if (= side :runner) :until-runner-turn-ends :until-corp-turn-ends))
(clean-set-aside! state side)
(doseq [card (all-active-installed state :runner)]
;; Clear :installed :this-turn as turn has ended
(when (= :this-turn (installed? card))
Expand Down
Loading