Skip to content

Commit

Permalink
Merge pull request #7209 from butzopower/envelopment-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahTheDuke authored Nov 12, 2023
2 parents 1f34d95 + 2c1aa3b commit 7a07754
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
10 changes: 6 additions & 4 deletions src/clj/game/cards/ice.clj
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,12 @@
(:variable %))
(:subroutines card))
new-card (assoc card :subroutines old-subs)
new-subs (->> (range total)
(reduce (fn [ice _] (add-sub ice sub (:cid ice) args)) new-card)
:subroutines
(into []))
new-subs (if (pos? total)
(->> (range total)
(reduce (fn [ice _] (add-sub ice sub (:cid ice) args)) new-card)
:subroutines
(into []))
(into [] (map-indexed (fn [idx sub] (assoc sub :index idx)) (:subroutines new-card))))
new-card (assoc new-card :subroutines new-subs)]
(update! state :corp new-card)
(trigger-event state side :subroutines-changed (get-card state new-card)))))
Expand Down
2 changes: 0 additions & 2 deletions src/clj/game/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,6 @@
reset-all-ice
reset-all-subs
reset-all-subs!
reset-sub
reset-sub!
resolve-subroutine
resolve-subroutine!
resolve-unbroken-subs!
Expand Down
11 changes: 2 additions & 9 deletions src/clj/game/core/ice.clj
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,11 @@
[state ice]
(update! state :corp (dont-resolve-all-subroutines ice)))

(defn reset-sub
[ice sub]
(assoc ice :subroutines (assoc (:subroutines ice) (:index sub) (dissoc sub :broken :fired :resolve))))

(defn reset-sub!
[state ice sub]
(update! state :corp (reset-sub ice sub)))

(defn reset-all-subs
"Mark all broken/fired subroutines as unbroken/unfired"
[ice]
(reduce reset-sub ice (:subroutines ice)))
(letfn [(reset-sub [sub] (dissoc sub :broken :fired :resolve))]
(update ice :subroutines #(into [] (map reset-sub %)))))

(defn reset-all-subs!
"Marks all broken subroutines as unbroken, update!s state"
Expand Down
13 changes: 13 additions & 0 deletions test/clj/game/cards/ice_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2050,6 +2050,19 @@
(is (empty? (:discard (get-corp))))
(is (not (:run @state)) "Run ended")))

(deftest envelopment-sub-indexed-correctly-7201
;; Envelopment should only have one trash subroutine at index 0 after running out of counters
(do-game
(new-game {:corp {:hand ["Envelopment"] :credits 10}})
(play-from-hand state :corp "Envelopment" "HQ")
(rez state :corp (get-ice state :hq 0))
(take-credits state :corp)
(dotimes [_ 4]
(take-credits state :runner)
(take-credits state :corp))
(is (= 1 (count (:subroutines (get-ice state :hq 0)))))
(is (= 0 (:index (first (:subroutines (get-ice state :hq 0))))))))

(deftest excalibur
;; Excalibur - Prevent Runner from making another run this turn
(do-game
Expand Down

0 comments on commit 7a07754

Please sign in to comment.