diff options
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 + } + } + } +} |
