diff options
| author | workhorse <workhorse@localhost.localdomain> | 2026-06-19 03:57:06 -0400 |
|---|---|---|
| committer | workhorse <workhorse@localhost.localdomain> | 2026-06-19 03:57:06 -0400 |
| commit | 52a3ce6a4b4a254dc5d3067979a09e93c060fa20 (patch) | |
| tree | 167c62990013733bc8669c1387078bc86ea48db5 /internal/game/cmd_sneak.go | |
| parent | fbd1c30d7b9777c9df6653f0c393afa7a7dfa519 (diff) | |
| download | thehouseoficarus-52a3ce6a4b4a254dc5d3067979a09e93c060fa20.tar.gz | |
feat: shops and rough assassin skill
Diffstat (limited to 'internal/game/cmd_sneak.go')
| -rw-r--r-- | internal/game/cmd_sneak.go | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/internal/game/cmd_sneak.go b/internal/game/cmd_sneak.go new file mode 100644 index 0000000..97aab8a --- /dev/null +++ b/internal/game/cmd_sneak.go @@ -0,0 +1,71 @@ +package game + +import ( + "fmt" + + "thehouseoficarus/internal/net" + "thehouseoficarus/internal/player" +) + +func (g *Game) doSneak(sess *net.Session) { + p := sess.Player.(*player.Player) + p.Sneaking = !p.Sneaking + if p.Sneaking { + p.SneakNotified = make(map[string]bool) + sess.WriteLine("You begin sneaking.") + } else { + p.SneakNotified = nil + sess.WriteLine("You stop sneaking.") + } +} + +func (g *Game) SneakTick() { + if g.Hub == nil { + return + } + + for key := range g.guardWatchTimers { + g.guardWatchTimers[key]++ + } + + for _, sess := range g.Hub.AllSessions() { + p, ok := sess.Player.(*player.Player) + if !ok || p == nil || !p.Sneaking { + continue + } + + objs := g.World.AllObjInstances(p.RoomID) + for _, st := range objs { + objDef, err := g.ObjectStore.Load(st.DefID) + if err != nil || objDef.GuardMob == "" { + continue + } + + guard := g.findGuardInRoom(p.RoomID, objDef.GuardMob) + if guard == nil { + continue + } + + timerKey := fmt.Sprintf("%d:%s", p.RoomID, st.DefID) + if _, exists := g.guardWatchTimers[timerKey]; !exists { + g.guardWatchTimers[timerKey] = 0 + } + + watching := g.isGuardWatching(p.RoomID, st.DefID) + + if p.SneakNotified == nil { + p.SneakNotified = make(map[string]bool) + } + + lastState, known := p.SneakNotified[timerKey] + if !known || lastState != watching { + if watching { + sess.WriteLine(fmt.Sprintf("The %s is watching the %s.", guard.Name, objDef.Name)) + } else { + sess.WriteLine(fmt.Sprintf("The %s looks away from the %s.", guard.Name, objDef.Name)) + } + p.SneakNotified[timerKey] = watching + } + } + } +} |
