Skip to content

Commit

Permalink
Merge pull request mtgred#3846 from jwarwick/tag_fix
Browse files Browse the repository at this point in the history
Fix tags in UI
  • Loading branch information
nealterrell authored Aug 24, 2018
2 parents 4c717a7 + e5baf6a commit 613ba1b
Show file tree
Hide file tree
Showing 29 changed files with 226 additions and 203 deletions.
2 changes: 1 addition & 1 deletion src/clj/game/cards/agendas.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[game.macros :refer [effect req msg wait-for continue-ability]]
[clojure.string :refer [split-lines split join lower-case includes? starts-with?]]
[clojure.stacktrace :refer [print-stack-trace]]
[jinteki.utils :refer [str->int other-side]]
[jinteki.utils :refer [str->int other-side is-tagged? count-tags]]
[jinteki.cards :refer [all-cards]]))

(defn ice-boost-agenda [subtype]
Expand Down
2 changes: 1 addition & 1 deletion src/clj/game/cards/assets.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[game.macros :refer [effect req msg wait-for continue-ability]]
[clojure.string :refer [split-lines split join lower-case includes? starts-with?]]
[clojure.stacktrace :refer [print-stack-trace]]
[jinteki.utils :refer [str->int other-side]]
[jinteki.utils :refer [str->int other-side is-tagged? count-tags]]
[jinteki.cards :refer [all-cards]]))

;;; Asset-specific helpers
Expand Down
2 changes: 1 addition & 1 deletion src/clj/game/cards/events.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[game.macros :refer [effect req msg wait-for continue-ability]]
[clojure.string :refer [split-lines split join lower-case includes? starts-with?]]
[clojure.stacktrace :refer [print-stack-trace]]
[jinteki.utils :refer [str->int other-side]]
[jinteki.utils :refer [str->int other-side is-tagged? count-tags]]
[jinteki.cards :refer [all-cards]]))

(defn- run-event
Expand Down
2 changes: 1 addition & 1 deletion src/clj/game/cards/hardware.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[game.macros :refer [effect req msg wait-for continue-ability]]
[clojure.string :refer [split-lines split join lower-case includes? starts-with?]]
[clojure.stacktrace :refer [print-stack-trace]]
[jinteki.utils :refer [str->int other-side]]
[jinteki.utils :refer [str->int other-side is-tagged? count-tags]]
[jinteki.cards :refer [all-cards]]))

(def card-definitions
Expand Down
2 changes: 1 addition & 1 deletion src/clj/game/cards/ice.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[game.macros :refer [effect req msg wait-for continue-ability]]
[clojure.string :refer [split-lines split join lower-case includes? starts-with?]]
[clojure.stacktrace :refer [print-stack-trace]]
[jinteki.utils :refer [str->int other-side]]
[jinteki.utils :refer [str->int other-side is-tagged? count-tags]]
[jinteki.cards :refer [all-cards]]))

;;;; Helper functions specific for ICE
Expand Down
2 changes: 1 addition & 1 deletion src/clj/game/cards/icebreakers.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[game.macros :refer [effect req msg wait-for continue-ability]]
[clojure.string :refer [split-lines split join lower-case includes? starts-with?]]
[clojure.stacktrace :refer [print-stack-trace]]
[jinteki.utils :refer [str->int other-side]]
[jinteki.utils :refer [str->int other-side is-tagged?]]
[jinteki.cards :refer [all-cards]]))

(def breaker-auto-pump
Expand Down
2 changes: 1 addition & 1 deletion src/clj/game/cards/identities.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[game.macros :refer [effect req msg wait-for continue-ability]]
[clojure.string :refer [split-lines split join lower-case includes? starts-with?]]
[clojure.stacktrace :refer [print-stack-trace]]
[jinteki.utils :refer [str->int other-side]]
[jinteki.utils :refer [str->int other-side is-tagged?]]
[jinteki.cards :refer [all-cards]]))

;;; Helper functions for Draft cards
Expand Down
2 changes: 1 addition & 1 deletion src/clj/game/cards/operations.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[game.macros :refer [effect req msg wait-for continue-ability]]
[clojure.string :refer [split-lines split join lower-case includes? starts-with?]]
[clojure.stacktrace :refer [print-stack-trace]]
[jinteki.utils :refer [str->int other-side]]
[jinteki.utils :refer [str->int other-side is-tagged? count-tags]]
[jinteki.cards :refer [all-cards]]))

(def card-definitions
Expand Down
2 changes: 1 addition & 1 deletion src/clj/game/cards/programs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[game.macros :refer [effect req msg wait-for continue-ability]]
[clojure.string :refer [split-lines split join lower-case includes? starts-with?]]
[clojure.stacktrace :refer [print-stack-trace]]
[jinteki.utils :refer [str->int other-side]]
[jinteki.utils :refer [str->int other-side is-tagged?]]
[jinteki.cards :refer [all-cards]]))

(def card-definitions
Expand Down
2 changes: 1 addition & 1 deletion src/clj/game/cards/resources.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[game.macros :refer [effect req msg wait-for continue-ability]]
[clojure.string :refer [split-lines split join lower-case includes? starts-with?]]
[clojure.stacktrace :refer [print-stack-trace]]
[jinteki.utils :refer [str->int other-side]]
[jinteki.utils :refer [str->int other-side is-tagged? count-tags]]
[jinteki.cards :refer [all-cards]]))

(defn- genetics-trigger?
Expand Down
2 changes: 1 addition & 1 deletion src/clj/game/cards/upgrades.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[game.macros :refer [effect req msg wait-for continue-ability]]
[clojure.string :refer [split-lines split join lower-case includes? starts-with?]]
[clojure.stacktrace :refer [print-stack-trace]]
[jinteki.utils :refer [str->int other-side]]
[jinteki.utils :refer [str->int other-side is-tagged?]]
[jinteki.cards :refer [all-cards]]))

(def card-definitions
Expand Down
2 changes: 1 addition & 1 deletion src/clj/game/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[clojure.java.io :as io]
[clojure.core.match :refer [match]]
[clojure.stacktrace :refer [print-stack-trace]]
[jinteki.utils :refer [str->int other-side]]
[jinteki.utils :refer [str->int other-side is-tagged?]]
[jinteki.cards :refer [all-cards]]
[game.quotes :as quotes]))

Expand Down
14 changes: 14 additions & 0 deletions src/clj/game/core/actions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@
(str "sets unused MU to " (available-mu state)
" (" (if (pos? delta) (str "+" delta) delta) ")")))

(defn- change-tags
"Change a player's base tag count"
[state delta]
(if (neg? delta)
(deduct state :runner [:tag (Math/abs delta)])
(gain state :runner :tag delta))
(system-msg state :runner
(str "sets Tags to " (get-in @state [:runner :tag :base])
" (" (if (pos? delta) (str "+" delta) delta) ")")))

(defn change
"Increase/decrease a player's property (clicks, credits, MU, etc.) by delta."
[state side {:keys [key delta]}]
Expand All @@ -83,6 +93,10 @@
(= :hand-size key)
(change-map state side key delta)

;; Tags need special treatment since they are a more complex map
(= :tag key)
(change-tags state delta)

:else
(do (if (neg? delta)
(deduct state side [key (- delta)])
Expand Down
2 changes: 1 addition & 1 deletion src/clj/game/core/events.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

(declare can-trigger? card-def clear-wait-prompt effect-completed event-title get-card get-nested-host get-remote-names
get-runnable-zones get-zones installed? make-eid register-effect-completed register-suppress resolve-ability
show-wait-prompt trigger-suppress unregister-suppress is-tagged?)
show-wait-prompt trigger-suppress unregister-suppress)

; Functions for registering and dispatching events.
(defn register-events
Expand Down
13 changes: 0 additions & 13 deletions src/clj/game/core/misc.clj
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,6 @@
([state n]
(gain state :runner :memory {:used n})))

(defn count-tags
"Counts number of tags runner has (real + additional)"
[state]
(+ (get-in @state [:runner :tag :base] 0)
(get-in @state [:runner :tag :additional] 0)))

(defn is-tagged?
"Returns truthy if runner is tagged"
[state]
(or (pos? (get-in @state [:runner :tag :is-tagged] 0))
(pos? (count-tags state))))


;;; Other helpers

(defn swap-agendas
Expand Down
12 changes: 12 additions & 0 deletions src/cljc/jinteki/utils.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@
(defn other-side [side]
(cond (= side :corp) :runner
(= side :runner) :corp))

(defn count-tags
"Counts number of tags runner has (real + additional)"
[state]
(+ (get-in @state [:runner :tag :base] 0)
(get-in @state [:runner :tag :additional] 0)))

(defn is-tagged?
"Returns truthy if runner is tagged"
[state]
(or (pos? (get-in @state [:runner :tag :is-tagged] 0))
(pos? (count-tags state))))
10 changes: 4 additions & 6 deletions src/cljs/nr/gameboard.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
(:require [cljs.core.async :refer [chan put! <!] :as async]
[clojure.string :refer [capitalize includes? join lower-case split]]
[differ.core :as differ]
[jinteki.utils :refer [str->int]]
[jinteki.utils :refer [str->int is-tagged?] :as utils]
[jinteki.cards :refer [all-cards]]
[nr.appstate :refer [app-state]]
[nr.auth :refer [avatar] :as auth]
[nr.cardbrowser :refer [add-symbols] :as cb]
[nr.utils :refer [influence-dot map-longest toastr-options]]
[nr.ws :as ws]
[reagent.core :as r]
[jinteki.utils :as utils]))
[reagent.core :as r]))

(defonce game-state (r/atom {}))
(defonce last-state (atom {}))
Expand Down Expand Up @@ -1519,7 +1518,7 @@
[cond-button "Remove Tag"
(and (pos? (:click @me))
(>= (:credit @me) (- 2 (or (:tag-remove-bonus @me) 0)))
(pos? (:tag @me)))
(pos? (get-in @me [:tag :base])))
#(send-command "remove-tag")]
[:div.run-button
[cond-button "Run" (and (pos? (:click @me))
Expand All @@ -1537,8 +1536,7 @@
(when (= side :corp)
[cond-button "Trash Resource" (and (pos? (:click @me))
(>= (:credit @me) (- 2 (or (:trash-cost-bonus @me) 0)))
(or (pos? (:tagged @opponent))
(pos? (:tag @opponent))))
(is-tagged? game-state))
#(send-command "trash-resource")])
[cond-button "Draw" (and (pos? (:click @me)) (not-empty (:deck @me))) #(send-command "draw")]
[cond-button "Gain Credit" (pos? (:click @me)) #(send-command "credit")]]))])})))
Expand Down
47 changes: 24 additions & 23 deletions test/clj/game_test/cards/agendas.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[game-test.core :refer :all]
[game-test.utils :refer :all]
[game-test.macros :refer :all]
[jinteki.utils :refer [count-tags]]
[clojure.test :refer :all]))

(use-fixtures :once load-all-cards (partial reset-card-defs "agendas"))
Expand Down Expand Up @@ -123,7 +124,7 @@
(run-successful state)
(click-prompt state :runner "Pay 1 [Credits] to trash")
(is (= 1 (count (:discard (get-corp)))) "trashed")
(is (zero? (core/count-tags state)) "Runner took 0 tags")
(is (zero? (count-tags state)) "Runner took 0 tags")
(take-credits state :runner)
(play-and-score state "AR-Enhanced Security")
(take-credits state :corp))
Expand All @@ -132,13 +133,13 @@
(run-successful state)
(click-prompt state :runner "Pay 1 [Credits] to trash")
(is (= 2 (count (:discard (get-corp)))) "trashed")
(is (= 1 (core/count-tags state)) "Runner took 1 tag"))
(is (= 1 (count-tags state)) "Runner took 1 tag"))
(testing "don't gain a tag from second trash"
(run-on state :remote3)
(run-successful state)
(click-prompt state :runner "Pay 1 [Credits] to trash")
(is (= 3 (count (:discard (get-corp)))) "trashed")
(is (= 1 (core/count-tags state)) "Runner took 0 tags"))))
(is (= 1 (count-tags state)) "Runner took 0 tags"))))

(deftest armed-intimidation
;; Armed Intimidation
Expand All @@ -147,7 +148,7 @@
(default-runner [(qty "Sure Gamble" 3) (qty "Diesel" 2)]))
(play-and-score state "Armed Intimidation")
(click-prompt state :runner "Take 2 tags")
(is (= 2 (core/count-tags state)) "Runner took 2 tags from Armed Intimidation tag choice")
(is (= 2 (count-tags state)) "Runner took 2 tags from Armed Intimidation tag choice")
(play-and-score state "Armed Intimidation")
(is (= 5 (count (:hand (get-runner)))) "Runner has 5 cards before Armed Intimidation meat damage")
(click-prompt state :runner "Suffer 5 meat damage")
Expand Down Expand Up @@ -280,22 +281,22 @@
(play-and-score state "Better Citizen Program")
(take-credits state :corp)
(core/gain state :runner :credit 10)
(is (zero? (core/count-tags state)) "Runner starts with 0 tags")
(is (zero? (count-tags state)) "Runner starts with 0 tags")
(play-from-hand state :runner "The Maker's Eye")
(click-prompt state :corp "Yes")
(is (= 1 (core/count-tags state)) "Runner takes 1 tag for playing a Run event")
(is (= 1 (count-tags state)) "Runner takes 1 tag for playing a Run event")
(run-successful state)
(play-from-hand state :runner "Wyrm")
(is (empty? (-> (get-corp) :prompt)) "Corp shouldn't get a prompt to use Better Citizen Program")
(is (= 1 (core/count-tags state)) "Runner doesn't gain a tag from installing an icebreaker after playing a Run event")
(is (= 1 (count-tags state)) "Runner doesn't gain a tag from installing an icebreaker after playing a Run event")
(take-credits state :runner)
(take-credits state :corp)
(play-from-hand state :runner "Wyrm")
(click-prompt state :corp "Yes")
(is (= 2 (core/count-tags state)) "Runner gains 1 tag for installing an Icebreaker")
(is (= 2 (count-tags state)) "Runner gains 1 tag for installing an Icebreaker")
(play-from-hand state :runner "The Maker's Eye")
(is (empty? (-> (get-corp) :prompt)) "Corp shouldn't get a prompt to use Better Citizen Program")
(is (= 2 (core/count-tags state)) "Runner doesn't gain a tag from playing a Run event after installing an Icebreaker")
(is (= 2 (count-tags state)) "Runner doesn't gain a tag from playing a Run event after installing an Icebreaker")
(run-successful state)))
(testing "Should only trigger on Run events. #3619"
(do-game
Expand All @@ -307,7 +308,7 @@
(play-from-hand state :runner "Mining Accident")
(click-prompt state :corp "Pay 5 [Credits]")
(is (empty? (-> (get-corp) :prompt)) "Corp shouldn't get a prompt to use Better Citizen Program")
(is (zero? (core/count-tags state)) "Runner should not gain a tag from playing a non-Run event"))))
(is (zero? (count-tags state)) "Runner should not gain a tag from playing a non-Run event"))))

(deftest bifrost-array
;; Bifrost Array
Expand Down Expand Up @@ -357,9 +358,9 @@
(new-game (default-corp [(qty "Breaking News" 3)])
(default-runner))
(play-and-score state "Breaking News")
(is (= 2 (core/count-tags state)) "Runner receives 2 tags from Breaking News")
(is (= 2 (count-tags state)) "Runner receives 2 tags from Breaking News")
(take-credits state :corp)
(is (zero? (core/count-tags state))) "Two tags removed at the end of the turn"))
(is (zero? (count-tags state))) "Two tags removed at the end of the turn"))

(deftest broad-daylight
;; Broad Daylight
Expand Down Expand Up @@ -783,7 +784,7 @@
(play-and-score state "Escalate Vitriol")
(let [ev-scored (get-scored state :corp 0)]
(dotimes [tag 10]
(is (zero? (core/count-tags state)) "Should start with 0 tags")
(is (zero? (count-tags state)) "Should start with 0 tags")
(is (zero? (:credit (get-corp))) "Should start with 0 credits")
(core/gain-tags state :runner tag)
(card-ability state :corp ev-scored 0)
Expand Down Expand Up @@ -897,9 +898,9 @@
(do-game
(new-game (default-corp ["Fly on the Wall"])
(default-runner))
(is (zero? (core/count-tags state)) "Runner starts with no tags")
(is (zero? (count-tags state)) "Runner starts with no tags")
(play-and-score state "Fly on the Wall")
(is (= 1 (core/count-tags state)) "Runner is tagged")))
(is (= 1 (count-tags state)) "Runner is tagged")))

(deftest firmware-updates
;; Firmware Updates
Expand Down Expand Up @@ -1306,15 +1307,15 @@
(is (= 1 (-> (get-corp) :prompt first :bonus)) "Should gain 1 bonus trace strength")
(click-prompt state :corp "0")
(click-prompt state :runner "0")
(is (= 1 (core/count-tags state)))
(is (= 1 (count-tags state)))
(run-jack-out state)
(run-on state "HQ")
(card-subroutine state :corp nh 0)
(is (= 1 (-> (get-corp) :prompt first :bonus))
"Should gain only 1 bonus trace strength regardless of number of runs in a turn")
(click-prompt state :corp "0")
(click-prompt state :runner "0")
(is (= 2 (core/count-tags state)))
(is (= 2 (count-tags state)))
(run-on state "R&D")
(card-ability state :corp io 1)
(is (zero? (-> (get-corp) :prompt first :bonus)) "Should gain 0 bonus trace strength, as it's an encounter ability"))))
Expand Down Expand Up @@ -1844,7 +1845,7 @@
(click-prompt state :corp "Yes")
(is (zero? (:agenda-point (get-corp))) "Forfeiting Posted Bounty nullifies agenda points")
(is (= 1 (:bad-publicity (get-corp))) "Forfeiting takes 1 bad publicity")
(is (= 1 (core/count-tags state)) "Runner receives 1 tag forfeiting Posted Bounty")))
(is (= 1 (count-tags state)) "Runner receives 1 tag forfeiting Posted Bounty")))
(testing "Choosing not to forfeit scores normally"
(do-game
(new-game (default-corp ["Posted Bounty"])
Expand All @@ -1853,7 +1854,7 @@
(click-prompt state :corp "No")
(is (= 1 (:agenda-point (get-corp))))
(is (zero? (:bad-publicity (get-corp))))
(is (zero? (core/count-tags state))))))
(is (zero? (count-tags state))))))

(deftest priority-requisition
;; Priority Requisition
Expand Down Expand Up @@ -2242,13 +2243,13 @@
(do-game
(new-game (default-corp ["Restructured Datapool"])
(default-runner))
(is (zero? (core/count-tags state)) "Runner should start with no tags")
(is (zero? (count-tags state)) "Runner should start with no tags")
(play-and-score state "Restructured Datapool")
(let [rd-scored (get-scored state :corp 0)]
(card-ability state :corp rd-scored 0)
(click-prompt state :corp "0")
(click-prompt state :runner "0")
(is (= 1 (core/count-tags state)) "Runner should gain a tag from Restructured Datapool ability"))))
(is (= 1 (count-tags state)) "Runner should gain a tag from Restructured Datapool ability"))))

(deftest self-destruct-chips
;; Self-Destruct Chips
Expand Down Expand Up @@ -2529,14 +2530,14 @@
(run-successful state)
(click-card state :runner tg1)
;; Accesses TGTBT but can't steal
(is (= 1 (core/count-tags state)) "Runner took 1 tag from accessing without stealing")
(is (= 1 (count-tags state)) "Runner took 1 tag from accessing without stealing")
(click-prompt state :runner "No action")
(click-card state :runner ohg))
(click-prompt state :runner "Pay 4 [Credits] to trash") ;; Trashes OHG
(run-empty-server state "Server 2")
;; Accesses TGTBT and can steal
(click-prompt state :runner "Steal")
(is (= 2 (core/count-tags state)) "Runner took 1 tag from accessing and stealing")))
(is (= 2 (count-tags state)) "Runner took 1 tag from accessing and stealing")))

(deftest the-cleaners
;; The Cleaners
Expand Down
Loading

0 comments on commit 613ba1b

Please sign in to comment.