1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
package game
import (
"fmt"
"thehouseoficarus/internal/net"
)
func (g *Game) executeSneak(sess *net.Session, args []string, rawInput string) {
g.doSneak(sess)
}
func (g *Game) doSneak(sess *net.Session) {
p := sess.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 := sess.Player
if 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
}
}
}
}
|