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

basic functionality - swap sides command #7865

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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 src/clj/game/core/commands.clj
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@
(not (ice? c))))}
:effect (effect (swap-installed (first targets) (second targets)))}
(make-card {:title "/swap-installed command"}) nil))
"/swap-sides" #(true)
"/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})}))
Expand Down
56 changes: 54 additions & 2 deletions src/clj/web/game.clj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[cond-plus.core :refer [cond+]]
[game.core.commands :refer [parse-command]]
[game.core.diffs :as diffs]
[game.core.say :refer [make-system-message]]
[game.core.say :refer [make-message make-system-message]]
[game.core.set-up :refer [init-game]]
[game.main :as main]
[jinteki.preconstructed :as preconstructed]
Expand Down Expand Up @@ -55,14 +55,66 @@
(swap! state update :history conj (:hist-diff diffs))
(send-state-diffs lobby diffs))))

(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)]
(-> lobby
(update :players #(mapv switch-side %))
(->> (assoc lobbies gameid)))
lobbies))

;; TODO - 1) ensure two players are playing
;; 2) force the frontend to reload the interface
;; 3) ensure double consent happens
;; 4) log everything
;; 5) allow revoked consent
;; 6) clean up all this mess lmao
(defn swap-sides-in-progress-game
[{:keys [state gameid] :as lobby} side user message]
(let [lobby (app-state/get-lobby gameid)
uid (:username user)
old-corp-player (get-in @state [:corp :user])
old-runner-player (get-in @state [:runner :user])]
;; ideally this would be atomic
(swap! state assoc-in [:runner :user] old-corp-player)
(swap! state assoc-in [:corp :user] old-runner-player)
(let [new-app-state (swap! app-state/app-state
update :lobbies
#(-> %
(handle-swap-sides-in-prog gameid)
(lobby/handle-set-last-update gameid uid)))
lobby? (get-in new-app-state [:lobbies gameid])]
(lobby/send-lobby-state lobby?)
(lobby/broadcast-lobby-list))))


(defn- handle-special-commands
[{:keys [state gameid] :as lobby} side user message]
;; some special commands may need to manipulate the lobby itself
(println message)
(cond
(= message "/swap-sides")
(swap-sides-in-progress-game lobby side user message)


)
nil)

(defn handle-message-and-send-diffs!
"If the given message is a command, passes through to `update-and-send-diffs!`.
Otherwise, adds the message to the log and only diffs the `:log`."
[{state :state :as lobby} side user message]
(when (and state @state)
(let [message (if (= (str/trim message) "null") " null" message)]
(if (and side user (parse-command state message))
(update-and-send-diffs! main/handle-say lobby side user message)
(when-not (handle-special-commands lobby side user message)
(update-and-send-diffs! main/handle-say lobby side user message))
;; if side is nil, then it's a notification
(let [f (if (some? side) main/handle-say main/handle-notification)
old-state @state
Expand Down
Loading