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

async validation via context-free grammar #7922

Merged
merged 36 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1737a4f
instaparse based grammer for picking up (some of) our async errors vi…
NBKelly Jan 23, 2025
4dd9e1c
helheim async fixed
NBKelly Jan 23, 2025
0459904
uninstall async
NBKelly Jan 23, 2025
5097bf9
SYNC BRE Async
NBKelly Jan 23, 2025
dd71896
dummy box async fixed
NBKelly Jan 23, 2025
75f89e5
caltesting async
NBKelly Jan 23, 2025
badc535
instaparse import, handle when req is deferred elsewhere
NBKelly Jan 23, 2025
9cc0de1
modified to pick up (some) cases where things SHOULD be marked async
NBKelly Jan 23, 2025
e21ce52
async fixed for upgrades
NBKelly Jan 23, 2025
ff51457
nicer formatting for output
NBKelly Jan 23, 2025
4c58a72
whitespace/padding
NBKelly Jan 23, 2025
9eaecfa
resources are async where they should be
NBKelly Jan 23, 2025
e776c12
stim dealer, other resources fixed
NBKelly Jan 23, 2025
0a286f3
check cancel-effects for async too
NBKelly Jan 23, 2025
f063f4b
asyncs to the programs that needed them
NBKelly Jan 23, 2025
79f3ee3
insta to dev dependency
NBKelly Jan 23, 2025
bf4af91
async fixes for programs
NBKelly Jan 23, 2025
5025fe1
spacing
NBKelly Jan 23, 2025
697d100
operations async fixed
NBKelly Jan 23, 2025
ceda4c4
async fixes for ice
NBKelly Jan 23, 2025
ac48dab
async fixes for identities
NBKelly Jan 23, 2025
c848a2e
async changes for hardware
NBKelly Jan 23, 2025
7c84b71
async changes for events
NBKelly Jan 23, 2025
d563ff2
async changes for assets
NBKelly Jan 23, 2025
8ba8ede
agendas async fixes
NBKelly Jan 23, 2025
d1253a5
runner basic draw wasn't async...
NBKelly Jan 23, 2025
aa94f09
updated terminals
NBKelly Jan 23, 2025
beb470b
Merge branch 'master' of github.com:NBKelly/netrunner into instaparse…
NBKelly Jan 23, 2025
ca2246c
engram flush
NBKelly Jan 23, 2025
3681c8e
handle both sides of if, branches for conds, and assert that cancel-e…
NBKelly Jan 23, 2025
6e02ab7
cloud eater more async issues
NBKelly Jan 23, 2025
3e13a7c
project atlas cancel-effect async
NBKelly Jan 23, 2025
bacc836
handle cond, condp, if-let, when...
NBKelly Jan 23, 2025
6e2f8f2
slightly more comprehensive test, a few more fixes, some reformatting…
NBKelly Jan 24, 2025
e689211
sanity checking
NBKelly Jan 24, 2025
b54a654
typo blocking compile
NBKelly Jan 24, 2025
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
1 change: 1 addition & 0 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
[com.clojure-goes-fast/clj-async-profiler "0.5.1"]
[rewrite-clj "1.1.45"]
[criterium "0.4.6"]
[instaparse "1.5.0"]
[integrant/repl "0.3.2"]
[lambdaisland/kaocha "1.68.1059"]
[thheller/shadow-cljs "2.16.8"]]
Expand Down
28 changes: 19 additions & 9 deletions src/clj/game/cards/agendas.clj
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@
:cost [(->c :trash-from-deck 1) (->c :agenda 1)]
:once :per-turn
:msg "add 1 card from Archives to HQ"
:async true
:effect (effect (continue-ability (corp-recur) card nil))}]})

(defcard "Bellona"
Expand Down Expand Up @@ -630,7 +631,8 @@
:psi {:req (req (= :hq (target-server context))
(first-event? state side :successful-run
#(= :hq (target-server (first %)))))
:not-equal {:effect (effect (register-lingering-effect
:not-equal {:async true
:effect (effect (register-lingering-effect
card
{:type :corp-choose-hq-access
:duration :end-of-run
Expand Down Expand Up @@ -703,9 +705,11 @@
:waiting-prompt true
:prompt "Choose a card to derez"
:choices {:card #(rezzed? %)}
:async true
:cancel-effect (effect (system-msg (str "declines to use " (:title card)))
(effect-completed eid))
:effect (effect (derez target {:source-card card}))}})
:effect (effect (derez target {:source-card card})
(effect-completed eid))}})

(defcard "Eden Fragment"
{:static-abilities [{:type :ignore-install-cost
Expand Down Expand Up @@ -865,8 +869,7 @@
:msg "add 1 card in HQ to the top of R&D"
:choices {:card #(and (in-hand? %)
(corp? %))}
:effect (effect (move target :deck {:front true})
(effect-completed eid))}
:effect (effect (move target :deck {:front true}))}
card nil))))}]})

(defcard "Fly on the Wall"
Expand Down Expand Up @@ -1044,6 +1047,7 @@
:msg "do 1 net damage"
:req (req (:run @state))
:once :per-run
:async true
:effect (effect (damage eid :net 1 {:card card}))}]})

(defcard "Hybrid Release"
Expand Down Expand Up @@ -1497,6 +1501,7 @@
{:on-score {:interactive (req true)
:req (req (pos? (count (:scored runner))))
:msg (msg "do " (count (:scored runner)) " net damage")
:async true
:effect (effect (damage eid :net (count (:scored runner)) {:card card}))}})

(defcard "Post-Truth Dividend"
Expand Down Expand Up @@ -1534,6 +1539,7 @@
:req (req tagged)
:cost [(->c :click 1)]
:keep-menu-open :while-clicks-left
:async true
:effect (effect (damage eid :meat 1 {:card card}))
:msg "do 1 meat damage"}]})

Expand Down Expand Up @@ -1579,7 +1585,8 @@
:req (req (pos? (get-counters card :agenda)))
:msg (msg "add " (:title target) " to HQ from R&D")
:choices (req (cancellable (:deck corp) :sorted))
:cancel-effect (effect (system-msg (str "declines to use " (:title card))))
:cancel-effect (effect (system-msg (str "declines to use " (:title card)))
(effect-completed eid))
:effect (effect (shuffle! :deck)
(move target :hand))}]})

Expand Down Expand Up @@ -1802,7 +1809,8 @@
(update-all-agenda-points state)
(check-win-by-agenda state side)
(effect-completed state side eid)))
:cancel-effect (effect (system-msg (str "declines to use " (:title card))))}})
:cancel-effect (effect (system-msg (str "declines to use " (:title card)))
(effect-completed state side eid))}})

(defcard "Regulatory Capture"
{:advancement-requirement (req (- (min 4 (count-bad-pub state))))})
Expand Down Expand Up @@ -1962,10 +1970,11 @@
(effect-completed state side eid))))}]})

(defcard "Sentinel Defense Program"
{:events [{:event :pre-resolve-damage
:req (req (and (= target :brain)
(pos? (last targets))))
{:events [{:event :damage
:req (req (and (pos? (:amount context))
(= (:damage-type context) :brain)))
:msg "do 1 net damage"
:async true
:effect (effect (damage eid :net 1 {:card card}))}]})

(defcard "Show of Force"
Expand Down Expand Up @@ -2200,6 +2209,7 @@
:on-access {:psi {:req (req (not installed))
:not-equal
{:msg "prevent itself from being stolen"
:async true
:effect (effect (register-run-flag!
card :can-steal
(fn [_ _ c] (not (same-card? c card))))
Expand Down
22 changes: 18 additions & 4 deletions src/clj/game/cards/assets.clj
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@
:prompt "Draw 2 cards?"
:player :corp
:yes-ability {:msg "draw 2 cards"
:async true
:effect (effect (draw eid 2))}}}})

(defcard "Capital Investors"
Expand Down Expand Up @@ -709,6 +710,7 @@
:waiting-prompt true
:choices {:card #(and (ice? %)
(get-counters % :advancement))}
:async true
:effect (effect
(continue-ability
(let [from-ice target]
Expand Down Expand Up @@ -1472,6 +1474,7 @@
{:abilities [ability]
:leave-play cleanup
:events [{:event :corp-spent-click
:async true
:effect (req (let [{:keys [action value ability-idx]} context
bac-cid (get-in @state [:corp :basic-action-card :cid])
cause (if (keyword? action)
Expand All @@ -1484,17 +1487,20 @@
clicks-spent (+ (get-in card [:seen-this-turn cause] 0) value)
card (update! state side (assoc-in card [:seen-this-turn cause] clicks-spent))]
; can be >= 3 because :once :per-turn on ability
(when (>= clicks-spent 3)
(resolve-ability state side ability card nil))))}
(if (>= clicks-spent 3)
(resolve-ability state side eid ability card nil)
(effect-completed state side eid))))}
{:event :corp-turn-ends
:effect cleanup}]}))

(defcard "Kala Ghoda Real TV"
{:derezzed-events [corp-rez-toast]
:flags {:corp-phase-12 (req true)}
:abilities [{:msg "look at the top card of the stack"
:async true
:effect (effect (continue-ability
{:prompt (req (->> runner :deck first :title (str "The top card of the stack is ")))
:waiting-prompt true
:choices ["OK"]}
card nil))}
{:async true
Expand Down Expand Up @@ -1560,6 +1566,7 @@
:choices {:req (req (and (agenda? target)
(<= (:agendapoints target) (cost-value eid :x-power))))}
:msg (msg "reveal " (:title target) " from HQ")
:async true
:effect (req (wait-for (reveal state side target)
(let [title (:title target)]
(register-turn-flag!
Expand Down Expand Up @@ -1941,6 +1948,7 @@
:prompt "Draw 1 card?"
:yes-ability
{:msg "draw 1 card"
:async true
:effect (effect (draw :corp eid 1))}}}]
{:events [(-> ability
(assoc :event :runner-lose-tag)
Expand Down Expand Up @@ -2176,12 +2184,14 @@
:async true
:req (req true)
:effect (req (add-counter state side card :power 1)
(gain-credits state :corp eid 3)
(damage-prevent state :corp :net 1))}
(wait-for (gain-credits state :corp 3)
(damage-prevent state :corp :net 1)
(effect-completed state side eid)))}
{:action true
:msg (msg "deal " (get-counters card :power) " net damage")
:label "deal net damage"
:cost [(->c :click 2) (->c :trash-can)]
:async true
:effect (effect (damage eid :net (get-counters card :power) {:card card}))}]})

(defcard "Primary Transmission Dish"
Expand Down Expand Up @@ -2258,6 +2268,7 @@
:choices {:card #(and (ice? %)
(not (rezzed? %)))}
:msg (msg "rez " (:title target))
:waiting-prompt true
:effect (req (let [agenda (last (:rfg corp))
ap (:agendapoints agenda 0)]
(wait-for (rez state side target {:no-warning true :cost-bonus (* ap -2)})
Expand All @@ -2267,6 +2278,7 @@
{:abilities [{:label "Forfeit agenda to rez up to 3 pieces of ice with a 2 [Credit] discount per agenda point"
:req (req (pos? (count (:scored corp))))
:cost [(->c :forfeit)]
:async true
:effect (req (continue-ability state side (rez-ice 1) card nil))}]}))

(defcard "Raman Rai"
Expand Down Expand Up @@ -2438,6 +2450,7 @@
ability {:once :per-turn
:req (req (:corp-phase-12 @state))
:label "Remove 1 counter (start of turn)"
:async true
:effect (req (add-counter state side card :power -1)
(if (zero? (get-counters (get-card state card) :power))
(wait-for (trash state side card {:cause-card card})
Expand Down Expand Up @@ -3194,6 +3207,7 @@
:label "Gain 3 [Credits]"
:msg "gain 3 [Credits]"
:keep-menu-open :while-power-tokens-left
:async true
:effect (req (gain-credits state side eid 3))}
{:action true
:cost [(->c :click 1) (->c :power 5)]
Expand Down
1 change: 1 addition & 0 deletions src/clj/game/cards/basic.clj
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
:req (req (not-empty (:deck runner)))
:cost [(->c :click)]
:msg "draw 1 card"
:async true
:effect (req (trigger-event state side :runner-click-draw {:card (-> @state side :deck (nth 0))})
(swap! state update-in [:stats side :click :draw] (fnil inc 0))
(play-sfx state side "click-card")
Expand Down
13 changes: 7 additions & 6 deletions src/clj/game/cards/events.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1638,22 +1638,22 @@
["Done"])
:async true
:effect
(req (letfn [(log-and-trash-cards [cards]
(req (letfn [(log-and-trash-cards [cards eid]
(system-msg state side
(str "uses " (get-title card)
" to trash "
(enumerate-str (map :title cards))
" from the top of the stack"))
(trash-cards state side eid cards {:unpreventable true :cause-card card}))]
(if (= target "Done")
(log-and-trash-cards top-ten)
(log-and-trash-cards top-ten eid)
(let [number-of-shuffles (count (turn-events state :runner :runner-shuffle-deck))]
(wait-for (runner-install state side (make-eid state {:source card :source-type :runner-install})
target {:cost-bonus -5
:msg-keys {:display-origin true
:install-source card}})
(if (= number-of-shuffles (count (turn-events state :runner :runner-shuffle-deck)))
(log-and-trash-cards (remove #(same-card? % target) top-ten))
(log-and-trash-cards (remove #(same-card? % target) top-ten) eid)
(do (system-msg state side "does not have to trash cards because the stack was shuffled")
(effect-completed state side eid))))))))}
card nil))})
Expand Down Expand Up @@ -2311,7 +2311,8 @@
" from the heap into the stack, and draws 1 card"))
(shuffle! state :runner :deck)
(draw state :runner eid 1))}
{:effect (effect
{:async true
:effect (effect
(do (system-msg state :runner "shuffles the stack and draws 1 card")
(shuffle! state :runner :deck)
(draw state :runner eid 1)))})
Expand Down Expand Up @@ -3765,6 +3766,7 @@
:events [{:event :run-ends
:req (req this-card-run)
:msg "take 1 core damage"
:async true
:effect (effect (damage eid :brain 1 {:unpreventable true
:card card}))}]})

Expand Down Expand Up @@ -4078,8 +4080,7 @@

(defcard "Uninstall"
{:on-play
{:async true
:change-in-game-state (req (some #(and (not (facedown? %))
{:change-in-game-state (req (some #(and (not (facedown? %))
(or (hardware? %) (program? %)))
(all-installed state :runner)))
:choices {:card #(and (installed? %)
Expand Down
Loading
Loading