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

Create Records for state, corp and runner, and various related sub-maps #4288

Merged
merged 3 commits into from
Jul 14, 2019
Merged
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
2 changes: 1 addition & 1 deletion src/clj/game/cards/identities.clj
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@
:msg (msg "draw " (- 5 (count (:hand corp))) " cards")
:effect (req (draw state side (- 5 (count (:hand corp))))
(update! state side (dissoc card :fill-hq))
(swap! state dissoc :turn-events))}]})
(swap! state assoc :turn-events nil))}]})

"Nisei Division: The Next Generation"
{:events {:reveal-spent-credits
Expand Down
6 changes: 5 additions & 1 deletion src/clj/game/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
[game.core.toasts :refer [toast show-error-toast]]
[game.utils :refer :all]
[game.macros :refer [effect req msg wait-for continue-ability]]
[game.core.state :refer :all]
[game.core.player :refer :all]
[clj-time.core :as t]
[clojure.string :as string :refer [split-lines split join lower-case includes? starts-with?]]
[clojure.java.io :as io]
Expand All @@ -17,7 +19,9 @@
[tasks.nrdb :refer [replace-collection update-config]]
[tasks.altart :refer [add-art]]
[game.quotes :as quotes])
(:import [game.core.card Card]))
(:import [game.core.state State]
[game.core.player Corp Runner]
[game.core.card Card]))

(load "core/events") ; triggering of events
(load "core/cards") ; retrieving and updating cards
Expand Down
2 changes: 1 addition & 1 deletion src/clj/game/core/abilities.clj
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@

(defn reset-trace-modifications
[state]
(swap! state dissoc :trace)
(swap! state assoc :trace nil)
(swap! state dissoc-in [:bonus :trace]))

(defn init-trace
Expand Down
2 changes: 1 addition & 1 deletion src/clj/game/core/io.clj
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@
[state side]
(when-let [click-state (:click-state @state)]
(when (= (:active-player @state) side)
(reset! state (dissoc (assoc click-state :log (:log @state) :click-state click-state) :run))
(reset! state (assoc click-state :log (:log @state) :click-state click-state :run nil))
(doseq [s [:runner :corp]]
(toast state s "Game reset to start of click")))))

Expand Down
117 changes: 117 additions & 0 deletions src/clj/game/core/player.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
(ns game.core.player)

(defrecord HandSize
[base mod])

(defrecord Corp
[user
identity
options
deck
deck-id
hand
discard
scored
rfg
play-area
servers
click
click-per-turn
credit
bad-publicity
toast
hand-size
agenda-point
agenda-point-req
keep
quote])

(defrecord Servers
[hq rd archives])

(defrecord BadPublicity
[base additional])

(defn new-corp
[user c-identity options deck deck-id c-quote]
(map->Corp
{:user user
:identity c-identity
:options options
:deck deck
:deck-id deck-id
:hand []
:discard [] :scored [] :rfg [] :play-area []
:servers (map->Servers {:hq {} :rd {} :archives {}})
:click 0 :click-per-turn 3
:credit 5
:bad-publicity (map->BadPublicity {:base 0 :additional 0})
:toast []
:hand-size (map->HandSize {:base 5 :mod 0})
:agenda-point 0 :agenda-point-req 7
:keep false
:quote c-quote}))

(defrecord Runner
[user
identity
options
deck
deck-id
hand
discard
scored
rfg
play-area
rig
toast
click
click-per-turn
credit
run-credit
link
tag
memory
hand-size
agenda-point
agenda-point-req
hq-access
rd-access
rd-access-fn
brain-damage
keep
quote])

(defrecord Rig
[program resource hardware])

(defrecord Tags
[base additional is-tagged])

(defrecord Memory
[base mod used])

(defn new-runner
[user r-identity options deck deck-id r-quote]
(map->Runner
{:user user
:identity r-identity
:options options
:deck deck
:deck-id deck-id
:hand []
:discard [] :scored [] :rfg [] :play-area []
:rig (map->Rig {:program [] :resource [] :hardware []})
:toast []
:click 0 :click-per-turn 4
:credit 5 :run-credit 0
:link 0
:tag (map->Tags {:base 0 :additional 0 :is-tagged 0})
:memory (map->Memory {:base 4 :mod 0 :used 0})
:hand-size (map->HandSize {:base 5 :mod 0})
:agenda-point 0 :agenda-point-req 7
:hq-access 1 :rd-access 1
:rd-access-fn seq
:brain-damage 0
:keep false
:quote r-quote}))
53 changes: 53 additions & 0 deletions src/clj/game/core/state.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
(ns game.core.state)

(defrecord State
[active-player
bonus
click-state
corp
effect-completed
eid
end-run
end-time
end-turn
events
gameid
log
loser
losing-deck-id
losing-user
options
per-run
per-turn
psi
reason
rid
room
run
runner
sfc-current-id
sfx
sfx-current-id
stack
stats
trace
trash
turn
turn-events
turn-state
typing
winner
winning-deck-id
winning-user])

(defn new-state
[gameid room now spectatorhands corp runner]
(map->State
{:gameid gameid :log [] :active-player :runner :end-turn true
:room room
:rid 0 :turn 0 :eid 0
:sfx [] :sfx-current-id 0
:stats {:time {:started now}}
:options {:spectatorhands spectatorhands}
:corp corp
:runner runner}))
53 changes: 8 additions & 45 deletions src/clj/game/core/turns.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
(declare all-active card-flag-fn? clear-turn-register! create-deck hand-size keep-hand mulligan
make-card turn-message)

(def game-states (atom {}))

(defn- card-implemented
"Checks if the card is implemented. Looks for a valid return from `card-def`.
If implemented also looks for `:implementation` key which may contain special notes.
Expand Down Expand Up @@ -60,48 +58,13 @@
corp-quote (quotes/make-quote corp-identity runner-identity)
runner-quote (quotes/make-quote runner-identity corp-identity)]
(atom
{:gameid gameid :log [] :active-player :runner :end-turn true
:room room
:rid 0 :turn 0 :eid 0
:sfx [] :sfx-current-id 0
:stats {:time {:started (t/now)}}
:options {:spectatorhands spectatorhands}
:corp {:user (:user corp) :identity corp-identity
:options corp-options
:deck (zone :deck corp-deck)
:deck-id corp-deck-id
:hand []
:discard [] :scored [] :rfg [] :play-area []
:servers {:hq {} :rd {} :archives {}}
:click 0 :click-per-turn 3
:credit 5
:bad-publicity {:base 0 :additional 0}
:toast []
:hand-size {:base 5 :mod 0}
:agenda-point 0 :agenda-point-req 7
:keep false
:quote corp-quote}
:runner {:user (:user runner) :identity runner-identity
:options runner-options
:deck (zone :deck runner-deck)
:deck-id runner-deck-id
:hand []
:discard [] :scored [] :rfg [] :play-area []
:rig {:program [] :resource [] :hardware []}
:toast []
:click 0 :click-per-turn 4
:credit 5 :run-credit 0
:link 0
;; is-tagged is a number in case there are multiple "runner is tagged" effects
:tag {:base 0 :additional 0 :is-tagged 0}
:memory {:base 4 :mod 0 :used 0}
:hand-size {:base 5 :mod 0}
:agenda-point 0 :agenda-point-req 7
:hq-access 1 :rd-access 1
:rd-access-fn seq
:brain-damage 0
:keep false
:quote runner-quote}})))
(new-state
gameid
room
(t/now)
spectatorhands
(new-corp (:user corp) corp-identity corp-options (zone :deck corp-deck) corp-deck-id corp-quote)
(new-runner (:user runner) runner-identity runner-options (zone :deck runner-deck) runner-deck-id runner-quote)))))

(defn init-game
"Initializes a new game with the given players vector."
Expand Down Expand Up @@ -290,7 +253,7 @@
(swap! state update-in [side :register] dissoc :cannot-draw)
(swap! state update-in [side :register] dissoc :drawn-this-turn)
(clear-turn-register! state)
(swap! state dissoc :turn-events)
(swap! state assoc :turn-events nil)
(when-let [extra-turns (get-in @state [side :extra-turns])]
(when (pos? extra-turns)
(start-turn state side nil)
Expand Down
2 changes: 1 addition & 1 deletion src/clj/game/main.clj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(ns game.main
(:require [cheshire.core :refer [parse-string generate-string]]
[cheshire.generate :refer [add-encoder encode-str]]
[game.core :refer [card-is-public? game-states] :as core]
[game.core :refer [card-is-public?] :as core]
[game.core.toasts :refer [toast]]
[game.core.card :refer [private-card]]
[differ.core :as differ]))
Expand Down