diff options
Diffstat (limited to 'internal/game/game.go')
| -rw-r--r-- | internal/game/game.go | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/internal/game/game.go b/internal/game/game.go index 700877b..cac0ec9 100644 --- a/internal/game/game.go +++ b/internal/game/game.go @@ -7,6 +7,7 @@ import ( "sync" "time" + "thehouseoficarus/internal/casino" "thehouseoficarus/internal/combat" "thehouseoficarus/internal/config" "thehouseoficarus/internal/engine" @@ -31,13 +32,13 @@ const ( // 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 + 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 ConstantColorConfig *config.ColorsConfig @@ -53,6 +54,7 @@ type Game struct { Hub *net.Hub GlobalFlags *GlobalFlagStore Combat *combat.Tracker + Casino *casino.Manager flagIndex *flagTriggerIndex queue *CommandQueue safespot *SafespotManager @@ -83,7 +85,7 @@ func New(dataDir string, colorConfig *config.ColorsConfig, constantColorConfig * ObjectStore: object.NewObjectStore(dataDir), ItemStore: item.NewItemStore(dataDir), AccountStore: player.NewAccountStore(dataDir), - MobStore: world.NewMobStore(dataDir), + MobStore: world.NewMobStore(dataDir), CraftIndex: NewCraftIndex(), CourseStore: NewCourseStore(dataDir), Ticks: engine.New(), @@ -93,6 +95,7 @@ func New(dataDir string, colorConfig *config.ColorsConfig, constantColorConfig * }, GlobalFlags: NewGlobalFlagStore(), Combat: combat.NewTracker(), + Casino: casino.NewManager(time.Now().UnixNano()), flagIndex: newFlagTriggerIndex(), queue: NewCommandQueue(), safespot: NewSafespotManager(), @@ -131,6 +134,11 @@ func (g *Game) SetHub(hub *net.Hub) { } } }) + hub.OnDisconnect(func(sess *net.Session) { + if sess.Player != nil { + g.emitCasinoEvents(g.Casino.MarkDisconnected(sess.Player.Name)) + } + }) g.GlobalFlags.OnChange(func(name string, value any) { g.fireGlobalFlagTriggers(name, value) }) @@ -339,8 +347,9 @@ func (g *Game) ProcessQueuedCommands() { ss, _ := g.safespot.Get(p.Name) isHiding := ss.Active isBusy := p.Action != nil || len(p.WalkSequence) > 0 || g.Combat.Get(p.Name) != nil || p.MoveTicks > 0 || isHiding + isCasinoSpin := g.Casino != nil && g.Casino.MachineBusy(p.Name) _, isResting := g.restTimers[p.Name] - if !isResting && !isBusy && qc.Session.State == net.StateGame { + if !isResting && !isBusy && !isCasinoSpin && qc.Session.State == net.StateGame { g.writePrompt(qc.Session) } } |
