Skip to content

Commit a4bafb7

Browse files
committed
feat: legacy bad pub option
1 parent ce3d1e2 commit a4bafb7

File tree

7 files changed

+52
-12
lines changed

7 files changed

+52
-12
lines changed

src/clj/game/core/runs.clj

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,12 @@
159159
(wait-for
160160
(gain-run-credits state side
161161
(make-eid state eid)
162-
(get-in @state [:runner :next-run-credit] 0))
163-
(swap! state assoc-in [:run :bad-publicity-available] (count-bad-pub state))
162+
(+ (get-in @state [:runner :next-run-credit] 0)
163+
(if (get-in @state [:options :legacy-bad-pub])
164+
(count-bad-pub state)
165+
0)))
166+
(when-not (get-in @state [:options :legacy-bad-pub])
167+
(swap! state assoc-in [:run :bad-publicity-available] (count-bad-pub state)))
164168
(swap! state assoc-in [:runner :next-run-credit] 0)
165169
(swap! state update-in [:runner :register :made-run] conj (first s))
166170
(swap! state update-in [:stats side :runs :started] (fnil inc 0))

src/clj/game/core/set_up.clj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979

8080
(defn- init-game-state
8181
"Initialises the game state"
82-
[{:keys [players gameid timer spectatorhands api-access save-replay room] :as game}]
82+
[{:keys [players gameid timer spectatorhands api-access save-replay legacy-bad-pub room] :as game}]
8383
(let [corp (some #(when (corp? %) %) players)
8484
runner (some #(when (runner? %) %) players)
8585
corp-deck (create-deck (:deck corp))
@@ -108,7 +108,8 @@
108108
{:timer timer
109109
:spectatorhands spectatorhands
110110
:api-access api-access
111-
:save-replay save-replay}
111+
:save-replay save-replay
112+
:legacy-bad-pub legacy-bad-pub}
112113
(new-corp (:user corp) corp-identity corp-options (map #(assoc % :zone [:deck]) corp-deck) corp-deck-id corp-quote)
113114
(new-runner (:user runner) runner-identity runner-options (map #(assoc % :zone [:deck]) runner-deck) runner-deck-id runner-quote)))))
114115

src/clj/web/lobby.clj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
[{uid :uid
106106
user :user
107107
{:keys [gameid now
108-
allow-spectator api-access format mute-spectators password room save-replay
108+
allow-spectator api-access format legacy-bad-pub mute-spectators password room save-replay
109109
precon gateway-type side singleton spectatorhands timer title open-decklists description]
110110
:or {gameid (random-uuid)
111111
now (inst/now)}} :options}]
@@ -134,6 +134,7 @@
134134
:save-replay save-replay
135135
:spectatorhands spectatorhands
136136
:singleton (when (some #{format} `("standard" "startup" "casual" "eternal")) singleton)
137+
:legacy-bad-pub (when (some #{format} '("casual" "eternal" "preconstructed" "chimera")) legacy-bad-pub)
137138
:timer timer
138139
:title title}))
139140

@@ -200,6 +201,7 @@
200201
:date
201202
:format
202203
:gameid
204+
:legacy-bad-pub
203205
:precon
204206
:messages
205207
:mute-spectators

src/cljs/nr/new_game.cljs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
:api-access
1515
:description
1616
:format
17+
:legacy-bad-pub
1718
:password
1819
:room
1920
:save-replay
@@ -250,7 +251,15 @@
250251
{:style {:display (if (:api-access @options) "block" "none")}}
251252
[tr-element :p [:lobby_api-access-details "This allows access to information about your game to 3rd party extensions. Requires an API Key to be created in Settings."]]]])
252253

253-
(defn options-section [options user]
254+
(defn legacy-bad-pub [options fmt-state]
255+
(when (#{"casual" "eternal" "preconstructed" "chimera"} @fmt-state)
256+
[:p
257+
[:label
258+
[:input {:type "checkbox" :checked (:legacy-bad-pub @options)
259+
:on-change #(swap! options assoc :legacy-bad-pub (.. % -target -checked))}]
260+
"Legacy bad publicity"]]))
261+
262+
(defn options-section [options user fmt-state]
254263
[:section
255264
[tr-element :h3 [:lobby_options "Options"]]
256265
[allow-spectators options]
@@ -259,7 +268,8 @@
259268
[password-input options]
260269
[add-timer options]
261270
[save-replay options]
262-
[api-access options user]])
271+
[api-access options user]
272+
[legacy-bad-pub options fmt-state]])
263273

264274
(defn create-new-game [lobby-state user]
265275
(r/with-let [state (r/atom {:flash-message ""
@@ -271,6 +281,7 @@
271281
:title (str (:username @user) "'s game")})
272282
options (r/atom {:allow-spectator true
273283
:api-access false
284+
:legacy-bad-pub false
274285
:password ""
275286
:protected false
276287
:save-replay (not= "casual" (:room @lobby-state))
@@ -301,4 +312,4 @@
301312
[side-section side]
302313
[format-section fmt options gateway-type precon]
303314
[description-section description]
304-
[options-section options user]]])))
315+
[options-section options user fmt]]])))

src/cljs/nr/pending_game.cljs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
@players))])
176176

177177
(defn options-list [current-game]
178-
(let [{:keys [allow-spectator api-access password
178+
(let [{:keys [allow-spectator api-access legacy-bad-pub password
179179
save-replay spectatorhands timer]} @current-game]
180180
[:<>
181181
[tr-element :h3 [:lobby_options "Options"]]
@@ -196,7 +196,9 @@
196196
[tr-element :p [:lobby_save-replay-unshared "Only your latest 15 unshared games will be kept, so make sure to either download or share the match afterwards."]]
197197
[tr-element :p [:lobby_save-replay-beta "BETA Functionality: Be aware that we might need to reset the saved replays, so make sure to download games you want to keep. Also, please keep in mind that we might need to do future changes to the site that might make replays incompatible."]]]])
198198
(when api-access
199-
[tr-element :li [:lobby_api-access "Allow API access to game information"]])]]))
199+
[tr-element :li [:lobby_api-access "Allow API access to game information"]])
200+
(when legacy-bad-pub
201+
[tr-element :li [:lobby_legacy-bad-publicity "Legacy bad publicity"]])]]))
200202

201203
(defn spectator-list [current-game]
202204
(let [{:keys [allow-spectator spectators]} @current-game]

test/clj/game/core/rules_test.clj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,24 @@
391391
(select-bad-pub state 1)
392392
(is (= 5 (:credit (get-runner))) "1 BP credit spent to trash CVS")))
393393

394+
(deftest legacy-bad-publicity-credits
395+
;; With legacy-bad-pub option, bad pub credits are added as run-credits
396+
;; and bad-publicity-available is not tracked on the run
397+
(do-game
398+
(new-game {:corp {:deck [(qty "Cyberdex Virus Suite" 3)]
399+
:bad-pub 1}
400+
:options {:legacy-bad-pub true}})
401+
(is (= 1 (count-bad-pub state)) "Corp starts with 1 BP")
402+
(play-from-hand state :corp "Cyberdex Virus Suite" "New remote")
403+
(take-credits state :corp)
404+
(run-on state :remote1)
405+
(is (= 1 (:run-credit (get-runner))) "Runner gained 1 run credit from bad pub")
406+
(is (nil? (get-in @state [:run :bad-publicity-available])) "No bad-publicity-available tracking in legacy mode")
407+
(run-continue state)
408+
(click-prompt state :corp "No")
409+
(click-prompt state :runner "Pay 1 [Credits] to trash")
410+
(is (zero? (:run-credit (get-runner))) "Run credits cleared after run ends")))
411+
394412
(deftest run-psi-bad-publicity-credits
395413
;; Should pay from Bad Pub for Psi games during run #2374
396414
(do-game

test/clj/game/test_framework.clj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@
350350
:start-as (:start-as options)
351351
:dont-start-turn (:dont-start-turn options)
352352
:dont-start-game (:dont-start-game options)
353-
:format (or (:format options) :casual)})
353+
:format (or (:format options) :casual)
354+
:legacy-bad-pub (:legacy-bad-pub options)})
354355

355356
(defn stack-deck
356357
"Stacks the top of the deck with the named cards in order, if possible"
@@ -374,10 +375,11 @@
374375
"Init a new game using given corp and runner. Keep starting hands (no mulligan) and start Corp's turn."
375376
([] (new-game nil))
376377
([players]
377-
(let [{:keys [corp runner mulligan start-as dont-start-turn dont-start-game format]} (make-decks players)
378+
(let [{:keys [corp runner mulligan start-as dont-start-turn dont-start-game format legacy-bad-pub]} (make-decks players)
378379
state (core/init-game
379380
{:gameid 1
380381
:format format
382+
:legacy-bad-pub legacy-bad-pub
381383
:players [{:side "Corp"
382384
:user {:username "Corp"}
383385
:deck {:identity (:identity corp)

0 commit comments

Comments
 (0)