Skip to content

Commit 9154788

Browse files
authored
Merge pull request #7982 from NBKelly/swap-sides
swap sides command
2 parents e926d08 + edc5837 commit 9154788

File tree

4 files changed

+70
-4
lines changed

4 files changed

+70
-4
lines changed

src/clj/game/core/commands.clj

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
[game.macros :refer [continue-ability effect msg req wait-for]]
3838
[game.utils :refer [dissoc-in enumerate-str quantify safe-split
3939
same-card? same-side? server-card string->num]]
40-
[jinteki.utils :refer [str->int]]))
40+
[jinteki.utils :refer [other-side str->int]]))
41+
42+
(defmulti lobby-command :command)
4143

4244
(defn- constrain-value
4345
"Constrain value to [min-value max-value]"
@@ -413,6 +415,28 @@
413415
:effect (effect (trash eid target {:unpreventable true}))}
414416
nil nil)))
415417

418+
(defn command-swap-sides
419+
[state side]
420+
(swap! state dissoc-in [side :command-info :ignore-swap-sides])
421+
(if (get-in @state [(other-side side) :command-info :ignore-swap-sides])
422+
(toast state side "your opponent has indicated that they do not wish to swap sides")
423+
(resolve-ability
424+
state (other-side side)
425+
{:prompt "Your opponent wishes to swap sides"
426+
:waiting-prompt true
427+
:choices ["Accept" "Decline" "Don't ask me again"]
428+
:effect (req (cond
429+
(= target "Decline")
430+
(toast state (other-side side) "your opponent does not wish to swap sides at this time")
431+
(= target "Don't ask me again")
432+
(do (toast state (other-side side) "your opponent does not wish to swap sides")
433+
(swap! state assoc-in [side :command-info :ignore-swap-sides] true))
434+
(= target "Accept")
435+
(do (system-msg state side "accepts the request to swap sides. Players swap sides")
436+
(lobby-command {:command :swap-sides
437+
:gameid (:gameid @state)}))))}
438+
nil nil)))
439+
416440
(defn parse-command
417441
[state text]
418442
(let [[command & args] (safe-split text #" ")
@@ -566,6 +590,7 @@
566590
(not (ice? c))))}
567591
:effect (effect (swap-installed (first targets) (second targets)))}
568592
(make-card {:title "/swap-installed command"}) nil))
593+
"/swap-sides" #(command-swap-sides %1 %2)
569594
"/tag" #(swap! %1 assoc-in [%2 :tag :base] (constrain-value value 0 1000))
570595
"/take-core" #(when (= %2 :runner) (damage %1 %2 (make-eid %1) :brain (constrain-value value 0 1000)
571596
{:card (make-card {:title "/damage command" :side %2})}))

src/clj/web/game.clj

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[clojure.stacktrace :as stacktrace]
66
[clojure.string :as str]
77
[cond-plus.core :refer [cond+]]
8-
[game.core.commands :refer [parse-command]]
8+
[game.core.commands :as commands :refer [parse-command]]
99
[game.core.diffs :as diffs]
1010
[game.core.say :refer [make-system-message]]
1111
[game.core.set-up :refer [init-game]]
@@ -418,3 +418,42 @@
418418
(app-state/deregister-user! uid)
419419
(when ?reply-fn (?reply-fn true))
420420
(lobby/log-delay! timestamp id)))
421+
422+
(defn switch-side
423+
"Returns a new player map with the player's :side set to a new side"
424+
[player]
425+
(if (= "Corp" (get-in player [:side]))
426+
(assoc player :side "Runner")
427+
(assoc player :side "Corp")))
428+
429+
(defn handle-swap-sides-in-prog [lobbies gameid]
430+
(if-let [lobby (get lobbies gameid)]
431+
(do
432+
(-> lobby
433+
;; note - original-players needs to be updated so that you rejoin the game
434+
;; on the correct side if you leave/rejoin
435+
(update :original-players #(mapv switch-side %))
436+
(update :players #(mapv switch-side %))
437+
(->> (assoc lobbies gameid))))
438+
lobbies))
439+
440+
(defn switch-side-for-lobby
441+
[gameid]
442+
(let [{:keys [state] :as lobby} (app-state/get-lobby gameid)
443+
old-runner (get-in @state [:runner :user])
444+
old-runner-options (get-in @state [:runner :options])]
445+
(swap! state assoc-in [:runner :user] (get-in @state [:corp :user]))
446+
(swap! state assoc-in [:runner :options] (get-in @state [:corp :options]))
447+
(swap! state assoc-in [:corp :user] old-runner)
448+
(swap! state assoc-in [:corp :options] old-runner-options)
449+
(lobby/lobby-thread
450+
(let [new-app-state (swap! app-state/app-state
451+
update :lobbies
452+
#(-> %
453+
(handle-swap-sides-in-prog gameid)))
454+
lobby? (get-in new-app-state [:lobbies gameid])]
455+
(lobby/send-lobby-state lobby?)
456+
(lobby/broadcast-lobby-list)))))
457+
458+
(defmethod commands/lobby-command :swap-sides [{:keys [gameid] :as args}]
459+
(switch-side-for-lobby gameid))

src/cljc/jinteki/utils.cljc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,9 @@
288288
{:name "/swap-installed"
289289
:usage "/swap-installed"
290290
:help "Swap the position of two installed non-ice (Corp only)"}
291+
{:name "/swap-sides"
292+
:usage "/swap-sides"
293+
:help "Request to swap sides with your opponent"}
291294
{:name "/tag"
292295
:has-args :required
293296
:usage "/tag n"

src/cljs/nr/gameboard/board.cljs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,8 +1885,7 @@
18851885
[:div.button-pane {:on-mouse-over #(card-preview-mouse-over % zoom-channel)
18861886
:on-mouse-out #(card-preview-mouse-out % zoom-channel)}
18871887
(cond
1888-
(and @prompt-state
1889-
(not= "run" @prompt-type))
1888+
(and @prompt-state (not= "run" (get-in @prompt-state [:prompt-type])))
18901889
[prompt-div me @prompt-state]
18911890
(or @run
18921891
@encounters)

0 commit comments

Comments
 (0)