From 4a43b7e9e22f9f4c8b665bfc50bc667d5ecfc0ec Mon Sep 17 00:00:00 2001 From: NB Kelly Date: Sun, 2 Mar 2025 10:15:03 +1300 Subject: [PATCH 1/5] wip swap sides command --- src/clj/game/core/commands.clj | 44 +++++++++++++++++++++++++++++++++- src/clj/web/game.clj | 34 +++++++++++++++++++++++++- 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/src/clj/game/core/commands.clj b/src/clj/game/core/commands.clj index 2047492446..c481708b28 100644 --- a/src/clj/game/core/commands.clj +++ b/src/clj/game/core/commands.clj @@ -37,7 +37,9 @@ [game.macros :refer [continue-ability effect msg req wait-for]] [game.utils :refer [dissoc-in enumerate-str quantify safe-split same-card? same-side? server-card string->num]] - [jinteki.utils :refer [str->int]])) + [jinteki.utils :refer [other-side str->int]])) + +(defmulti lobby-command :command) (defn- constrain-value "Constrain value to [min-value max-value]" @@ -413,6 +415,45 @@ :effect (effect (trash eid target {:unpreventable true}))} nil nil))) +(defn command-swap-sides + [state side] + (lobby-command {:command :swap-sides + :gameid (:gameid @state)}) + (let [old-runner (get-in @state [:runner :user]) + old-runner-options (get-in @state [:runner :options])] + ;;(system-msg state side "accepts the request to swap sides. Players swap sides") + (swap! state assoc-in [:runner :user] (get-in @state [:corp :user])) + (swap! state assoc-in [:runner :options] (get-in @state [:corp :options])) + (swap! state assoc-in [:corp :user] old-runner) + (swap! state assoc-in [:corp :options] old-runner-options) + (println (get-in @state [side :prompt])))) + ;; if you're requesting, you can't be ignoring too + ;; (swap! state dissoc-in [side :command-info :ignore-swap-sides]) + ;; (if (get-in @state [(other-side side) :command-info :ignore-swap-sides]) + ;; ;; TODO - toast + ;; nil + ;; (resolve-ability + ;; state (other-side side) + ;; {:prompt "Your opponent wishes to swap sides" + ;; :waiting-prompt true + ;; :choices ["Accept" "Decline" "Don't ask me again"] + ;; :effect (req (cond + ;; (= target "Decline") + ;; nil + ;; (= target "Don't ask me again") + ;; (swap! state assoc-in [side :command-info :ignore-swap-sides] true) + ;; (= target "Accept") + ;; (let [old-runner (get-in @state [:runner :user]) + ;; old-runner-options (get-in @state [:runner :options])] + ;; (system-msg state side "accepts the request to swap sides. Players swap sides") + ;; (lobby-command {:command :swap-sides + ;; :gameid (:gameid @state)}) + ;; (swap! state assoc-in [:runner :user] (get-in @state [:corp :user])) + ;; (swap! state assoc-in [:runner :options] (get-in @state [:corp :options])) + ;; (swap! state assoc-in [:corp :user] old-runner) + ;; (swap! state assoc-in [:corp :options] old-runner-options))))} + ;; nil nil))) + (defn parse-command [state text] (let [[command & args] (safe-split text #" ") @@ -566,6 +607,7 @@ (not (ice? c))))} :effect (effect (swap-installed (first targets) (second targets)))} (make-card {:title "/swap-installed command"}) nil)) + "/swap-sides" #(command-swap-sides %1 %2) "/tag" #(swap! %1 assoc-in [%2 :tag :base] (constrain-value value 0 1000)) "/take-core" #(when (= %2 :runner) (damage %1 %2 (make-eid %1) :brain (constrain-value value 0 1000) {:card (make-card {:title "/damage command" :side %2})})) diff --git a/src/clj/web/game.clj b/src/clj/web/game.clj index fcc805c6fb..e1342afc35 100644 --- a/src/clj/web/game.clj +++ b/src/clj/web/game.clj @@ -5,7 +5,7 @@ [clojure.stacktrace :as stacktrace] [clojure.string :as str] [cond-plus.core :refer [cond+]] - [game.core.commands :refer [parse-command]] + [game.core.commands :as commands :refer [parse-command]] [game.core.diffs :as diffs] [game.core.say :refer [make-system-message]] [game.core.set-up :refer [init-game]] @@ -418,3 +418,35 @@ (app-state/deregister-user! uid) (when ?reply-fn (?reply-fn true)) (lobby/log-delay! timestamp id))) + +(defn switch-side + "Returns a new player map with the player's :side set to a new side" + [player] + (if (= "Corp" (get-in player [:side])) + (assoc player :side "Runner") + (assoc player :side "Corp"))) + +(defn handle-swap-sides-in-prog [lobbies gameid] + (if-let [lobby (get lobbies gameid)] + (do + (-> lobby + ;; note - original-players needs to be updated so that you rejoin the game + ;; on the correct side if you leave/rejoin + (update :original-players #(mapv switch-side %)) + (update :players #(mapv switch-side %)) + (->> (assoc lobbies gameid)))) + lobbies)) + +(defn switch-side-for-lobby + [gameid] + (let [lobby (app-state/get-lobby gameid) + new-app-state (swap! app-state/app-state + update :lobbies + #(-> % + (handle-swap-sides-in-prog gameid))) + lobby? (get-in new-app-state [:lobbies gameid])] + (lobby/send-lobby-state lobby?) + (lobby/broadcast-lobby-list))) + +(defmethod commands/lobby-command :swap-sides [{:keys [gameid] :as args}] + (switch-side-for-lobby gameid)) From ce2699d6245a954f2e4b933a755ed5451c5d26fa Mon Sep 17 00:00:00 2001 From: NB Kelly Date: Sun, 2 Mar 2025 10:48:24 +1300 Subject: [PATCH 2/5] directly query rather than use a track for this --- src/clj/game/core/prompts.clj | 2 +- src/cljs/nr/gameboard/board.cljs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/clj/game/core/prompts.clj b/src/clj/game/core/prompts.clj index 64b5614989..a8740bc099 100644 --- a/src/clj/game/core/prompts.clj +++ b/src/clj/game/core/prompts.clj @@ -49,7 +49,7 @@ {:eid (select-keys eid [:eid]) :card card :prompt-type :waiting - :msg (str "Waiting for " + :msg (str "Waiting for " (if (true? waiting-prompt) (str (side-str side) " to make a decision") waiting-prompt))})) diff --git a/src/cljs/nr/gameboard/board.cljs b/src/cljs/nr/gameboard/board.cljs index 35f7fe85e0..96d5abfbbc 100644 --- a/src/cljs/nr/gameboard/board.cljs +++ b/src/cljs/nr/gameboard/board.cljs @@ -1869,8 +1869,7 @@ [:div.button-pane {:on-mouse-over #(card-preview-mouse-over % zoom-channel) :on-mouse-out #(card-preview-mouse-out % zoom-channel)} (cond - (and @prompt-state - (not= "run" @prompt-type)) + (and @prompt-state (not= "run" (get-in @prompt-state [:prompt-type]))) [prompt-div me @prompt-state] (or @run @encounters) From 4fe54936a6b8c550e6a92077822a442482b002c7 Mon Sep 17 00:00:00 2001 From: NB Kelly Date: Sun, 2 Mar 2025 10:56:18 +1300 Subject: [PATCH 3/5] command now works nicely --- src/clj/game/core/commands.clj | 61 ++++++++++++++-------------------- 1 file changed, 25 insertions(+), 36 deletions(-) diff --git a/src/clj/game/core/commands.clj b/src/clj/game/core/commands.clj index c481708b28..143b85cd06 100644 --- a/src/clj/game/core/commands.clj +++ b/src/clj/game/core/commands.clj @@ -417,42 +417,31 @@ (defn command-swap-sides [state side] - (lobby-command {:command :swap-sides - :gameid (:gameid @state)}) - (let [old-runner (get-in @state [:runner :user]) - old-runner-options (get-in @state [:runner :options])] - ;;(system-msg state side "accepts the request to swap sides. Players swap sides") - (swap! state assoc-in [:runner :user] (get-in @state [:corp :user])) - (swap! state assoc-in [:runner :options] (get-in @state [:corp :options])) - (swap! state assoc-in [:corp :user] old-runner) - (swap! state assoc-in [:corp :options] old-runner-options) - (println (get-in @state [side :prompt])))) - ;; if you're requesting, you can't be ignoring too - ;; (swap! state dissoc-in [side :command-info :ignore-swap-sides]) - ;; (if (get-in @state [(other-side side) :command-info :ignore-swap-sides]) - ;; ;; TODO - toast - ;; nil - ;; (resolve-ability - ;; state (other-side side) - ;; {:prompt "Your opponent wishes to swap sides" - ;; :waiting-prompt true - ;; :choices ["Accept" "Decline" "Don't ask me again"] - ;; :effect (req (cond - ;; (= target "Decline") - ;; nil - ;; (= target "Don't ask me again") - ;; (swap! state assoc-in [side :command-info :ignore-swap-sides] true) - ;; (= target "Accept") - ;; (let [old-runner (get-in @state [:runner :user]) - ;; old-runner-options (get-in @state [:runner :options])] - ;; (system-msg state side "accepts the request to swap sides. Players swap sides") - ;; (lobby-command {:command :swap-sides - ;; :gameid (:gameid @state)}) - ;; (swap! state assoc-in [:runner :user] (get-in @state [:corp :user])) - ;; (swap! state assoc-in [:runner :options] (get-in @state [:corp :options])) - ;; (swap! state assoc-in [:corp :user] old-runner) - ;; (swap! state assoc-in [:corp :options] old-runner-options))))} - ;; nil nil))) + (swap! state dissoc-in [side :command-info :ignore-swap-sides]) + (if (get-in @state [(other-side side) :command-info :ignore-swap-sides]) + (toast state side "your opponent has indicated that they do not wish to swap sides") + (resolve-ability + state (other-side side) + {:prompt "Your opponent wishes to swap sides" + :waiting-prompt true + :choices ["Accept" "Decline" "Don't ask me again"] + :effect (req (cond + (= target "Decline") + (toast state (other-side side) "your opponent does not wish to swap sides at this time") + (= target "Don't ask me again") + (do (toast state (other-side side) "your opponent does not wish to swap sides") + (swap! state assoc-in [side :command-info :ignore-swap-sides] true)) + (= target "Accept") + (let [old-runner (get-in @state [:runner :user]) + old-runner-options (get-in @state [:runner :options])] + (system-msg state side "accepts the request to swap sides. Players swap sides") + (lobby-command {:command :swap-sides + :gameid (:gameid @state)}) + (swap! state assoc-in [:runner :user] (get-in @state [:corp :user])) + (swap! state assoc-in [:runner :options] (get-in @state [:corp :options])) + (swap! state assoc-in [:corp :user] old-runner) + (swap! state assoc-in [:corp :options] old-runner-options))))} + nil nil))) (defn parse-command [state text] From d28f95af828b13c3d92d82a81ca2a61644dd2f1c Mon Sep 17 00:00:00 2001 From: NB Kelly Date: Sun, 2 Mar 2025 11:02:08 +1300 Subject: [PATCH 4/5] documentation for command --- src/cljc/jinteki/utils.cljc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cljc/jinteki/utils.cljc b/src/cljc/jinteki/utils.cljc index 9f97faad14..492601cb0e 100644 --- a/src/cljc/jinteki/utils.cljc +++ b/src/cljc/jinteki/utils.cljc @@ -288,6 +288,9 @@ {:name "/swap-installed" :usage "/swap-installed" :help "Swap the position of two installed non-ice (Corp only)"} + {:name "/swap-sides" + :usage "/swap-sides" + :help "Request to swap sides with your opponent"} {:name "/tag" :has-args :required :usage "/tag n" From edc5837f73b652284da9f25e67806a398ba819d5 Mon Sep 17 00:00:00 2001 From: NB Kelly Date: Tue, 4 Mar 2025 16:14:41 +1300 Subject: [PATCH 5/5] moved logic into the command --- src/clj/game/core/commands.clj | 12 +++--------- src/clj/web/game.clj | 23 +++++++++++++++-------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/clj/game/core/commands.clj b/src/clj/game/core/commands.clj index 143b85cd06..9ea087fed1 100644 --- a/src/clj/game/core/commands.clj +++ b/src/clj/game/core/commands.clj @@ -432,15 +432,9 @@ (do (toast state (other-side side) "your opponent does not wish to swap sides") (swap! state assoc-in [side :command-info :ignore-swap-sides] true)) (= target "Accept") - (let [old-runner (get-in @state [:runner :user]) - old-runner-options (get-in @state [:runner :options])] - (system-msg state side "accepts the request to swap sides. Players swap sides") - (lobby-command {:command :swap-sides - :gameid (:gameid @state)}) - (swap! state assoc-in [:runner :user] (get-in @state [:corp :user])) - (swap! state assoc-in [:runner :options] (get-in @state [:corp :options])) - (swap! state assoc-in [:corp :user] old-runner) - (swap! state assoc-in [:corp :options] old-runner-options))))} + (do (system-msg state side "accepts the request to swap sides. Players swap sides") + (lobby-command {:command :swap-sides + :gameid (:gameid @state)}))))} nil nil))) (defn parse-command diff --git a/src/clj/web/game.clj b/src/clj/web/game.clj index e1342afc35..4f9501be35 100644 --- a/src/clj/web/game.clj +++ b/src/clj/web/game.clj @@ -439,14 +439,21 @@ (defn switch-side-for-lobby [gameid] - (let [lobby (app-state/get-lobby gameid) - new-app-state (swap! app-state/app-state - update :lobbies - #(-> % - (handle-swap-sides-in-prog gameid))) - lobby? (get-in new-app-state [:lobbies gameid])] - (lobby/send-lobby-state lobby?) - (lobby/broadcast-lobby-list))) + (let [{:keys [state] :as lobby} (app-state/get-lobby gameid) + old-runner (get-in @state [:runner :user]) + old-runner-options (get-in @state [:runner :options])] + (swap! state assoc-in [:runner :user] (get-in @state [:corp :user])) + (swap! state assoc-in [:runner :options] (get-in @state [:corp :options])) + (swap! state assoc-in [:corp :user] old-runner) + (swap! state assoc-in [:corp :options] old-runner-options) + (lobby/lobby-thread + (let [new-app-state (swap! app-state/app-state + update :lobbies + #(-> % + (handle-swap-sides-in-prog gameid))) + lobby? (get-in new-app-state [:lobbies gameid])] + (lobby/send-lobby-state lobby?) + (lobby/broadcast-lobby-list))))) (defmethod commands/lobby-command :swap-sides [{:keys [gameid] :as args}] (switch-side-for-lobby gameid))