aboutsummaryrefslogtreecommitdiff
path: root/internal/game/game.go
diff options
context:
space:
mode:
authorhistoria <[not public]>2026-06-25 15:40:48 -0400
committerhistoria <[not public]>2026-06-25 15:40:48 -0400
commitabd612c15799f604e671e83dc7c410ed2b44185f (patch)
tree0597ca92350de73aac2a7cf26b2f2d6595dac0cc /internal/game/game.go
parent2725e2927a1595c7b100d942d1f14146252adeb7 (diff)
downloadthehouseoficarus-abd612c15799f604e671e83dc7c410ed2b44185f.tar.gz
slop refactor
Diffstat (limited to 'internal/game/game.go')
-rw-r--r--internal/game/game.go99
1 files changed, 58 insertions, 41 deletions
diff --git a/internal/game/game.go b/internal/game/game.go
index dfa5143..320304f 100644
--- a/internal/game/game.go
+++ b/internal/game/game.go
@@ -11,6 +11,7 @@ import (
"thehouseoficarus/internal/config"
"thehouseoficarus/internal/engine"
"thehouseoficarus/internal/game/hacking"
+ "thehouseoficarus/internal/item"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/object"
"thehouseoficarus/internal/player"
@@ -26,55 +27,71 @@ const (
ClassUnknown
)
+// Deps holds the long-lived data stores and engines a Game depends on. They are
+// constructed once at startup and never replaced. Deps is embedded in Game, so
+// game code accesses them directly (e.g. g.World, g.ItemStore).
+type Deps struct {
+ World *world.World
+ ObjectStore *object.ObjectStore
+ ItemStore *item.ItemStore
+ AccountStore *player.AccountStore
+ MobStore *world.MobStore
+ CraftIndex *CraftIndex
+ CourseStore *CourseStore
+ Ticks *engine.Engine
+ ColorConfig *config.ColorsConfig
+ DataDir string
+}
+
+// Game is the central orchestrator: it owns the data stores (via the embedded
+// Deps), the shared mutable game state (flags, combat tracker, command queue,
+// safespots), and the per-session runtime bookkeeping.
type Game struct {
- World *world.World
- ObjectStore *object.ObjectStore
- ItemStore *object.ItemStore
- AccountStore *player.AccountStore
- MobStore *world.MobStore
- CraftIndex *CraftIndex
- CourseStore *CourseStore
- Hub *net.Hub
- Ticks *engine.Engine
- Flags *FlagStore
- ColorConfig *config.ColorsConfig
- DataDir string
- ValidationConfig config.ValidationConfig
- restTimers map[string]uint64
- charsMu sync.Mutex
- loggedInChars map[string]*net.Session
- queue *CommandQueue
- pendingDepletions []pendingDepletion
+ Deps
+
+ Hub *net.Hub
+ Flags *FlagStore
+ Combat *combat.Tracker
+ queue *CommandQueue
+ safespot *SafespotManager
+ ValidationConfig config.ValidationConfig
+
+ // Per-tick / per-session runtime bookkeeping.
+ charsMu sync.Mutex
+ loggedInChars map[string]*net.Session
+ restTimers map[string]uint64
guardWatchTimers map[string]int
- farmTickCounter int
hackingStates map[string]*hacking.Session
- safespot *SafespotManager
- enterMu sync.Mutex
- enterSeqs map[string]*enterSeq
+ pendingDepletions []pendingDepletion
+ farmTickCounter int
+ enterMu sync.Mutex
+ enterSeqs map[string]*enterSeq
}
func New(dataDir string, colorConfig *config.ColorsConfig, valConfig config.ValidationConfig) *Game {
g := &Game{
- World: world.New(dataDir),
- ObjectStore: object.NewObjectStore(dataDir),
- ItemStore: object.NewItemStore(dataDir),
- AccountStore: player.NewAccountStore(dataDir),
- MobStore: world.NewMobStore(dataDir),
- CraftIndex: NewCraftIndex(),
- CourseStore: NewCourseStore(dataDir),
- Ticks: engine.New(),
- Flags: NewFlagStore(),
- ColorConfig: colorConfig,
- DataDir: dataDir,
+ Deps: Deps{
+ World: world.New(dataDir),
+ ObjectStore: object.NewObjectStore(dataDir),
+ ItemStore: item.NewItemStore(dataDir),
+ AccountStore: player.NewAccountStore(dataDir),
+ MobStore: world.NewMobStore(dataDir),
+ CraftIndex: NewCraftIndex(),
+ CourseStore: NewCourseStore(dataDir),
+ Ticks: engine.New(),
+ ColorConfig: colorConfig,
+ DataDir: dataDir,
+ },
+ Flags: NewFlagStore(),
+ Combat: combat.NewTracker(),
+ queue: NewCommandQueue(),
+ safespot: NewSafespotManager(),
ValidationConfig: valConfig,
- restTimers: make(map[string]uint64),
loggedInChars: make(map[string]*net.Session),
- queue: NewCommandQueue(),
- pendingDepletions: nil,
- guardWatchTimers: make(map[string]int),
- hackingStates: make(map[string]*hacking.Session),
- safespot: NewSafespotManager(),
- enterSeqs: make(map[string]*enterSeq),
+ restTimers: make(map[string]uint64),
+ guardWatchTimers: make(map[string]int),
+ hackingStates: make(map[string]*hacking.Session),
+ enterSeqs: make(map[string]*enterSeq),
}
g.CourseStore.LoadAll()
g.LoadMods()
@@ -299,7 +316,7 @@ func (g *Game) ProcessQueuedCommands() {
}
ss, _ := g.safespot.Get(p.Name)
isHiding := ss.Active
- isBusy := p.Action != nil || len(p.WalkSequence) > 0 || combat.GetCombat(p.Name) != nil || p.MoveTicks > 0 || isHiding
+ isBusy := p.Action != nil || len(p.WalkSequence) > 0 || g.Combat.Get(p.Name) != nil || p.MoveTicks > 0 || isHiding
_, isResting := g.restTimers[p.Name]
if !isResting && !isBusy && qc.Session.State == net.StateGame {
g.writePrompt(qc.Session)