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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
package game
import (
"fmt"
"thehouseoficarus/internal/combat"
"thehouseoficarus/internal/engine"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/object"
"thehouseoficarus/internal/player"
)
func (g *Game) doMove(sess *net.Session, dir string) {
p := sess.Player.(*player.Player)
exitDir := g.World.ResolveExit(dir)
if exitDir == "" {
sess.WriteLine("Go where?")
return
}
room, err := g.World.LoadRoom(p.RoomID)
if err != nil {
sess.WriteLine("You can't move from here.")
return
}
exitDef, ok := room.Exits[exitDir]
if !ok {
sess.WriteLine("You can't go that way.")
return
}
if exitDef.Condition != nil && !g.checkCondition(sess, exitDef.Condition) {
msg := exitDef.BlockedMessage
if msg == "" {
msg = fmt.Sprintf("The way %s is blocked.", exitDir)
}
sess.WriteLine(msg)
return
}
targetID := exitDef.Room
_, err = g.World.LoadRoom(targetID)
if err != nil {
sess.WriteLine("That path seems blocked.")
return
}
inCombat := combat.GetCombat(p.Name) != nil
if !inCombat && p.Action != nil {
g.CancelAction(p)
}
ticks := g.moveTicks(p)
p.MoveDirection = string(exitDir)
p.MoveTarget = targetID
if ticks <= 0 {
g.completeMove(sess, p)
return
}
p.MoveTicks = ticks
p.ActionState = &ActionState{Type: ActionMoving, Direction: string(exitDir)}
if inCombat && p.OptionBool("run_countdown") {
if p.MoveTicks > 1 {
sess.WriteLine(fmt.Sprintf("Running in %d ticks...", p.MoveTicks))
} else {
sess.WriteLine("Running next tick!")
}
}
}
var gracefulItems = map[string]bool{
"graceful_hat": true,
"graceful_torso": true,
"graceful_legs": true,
"graceful_gloves": true,
"graceful_boots": true,
"graceful_cape": true,
}
func (g *Game) moveTicks(p *player.Player) int {
if id, ok := p.Equipment[object.SlotBack]; ok && id == "cape_of_agility" {
return 0
}
count := 0
for _, id := range p.Equipment {
if gracefulItems[id] {
count++
}
}
base := 4.0 - float64(count)*0.25
if count == 6 {
base -= 0.5
}
return engine.ToTicks(base) - 1
}
func (g *Game) completeMove(sess *net.Session, p *player.Player) {
exitDir := p.MoveDirection
targetID := p.MoveTarget
p.ClearMoveState()
if combat.GetCombat(p.Name) != nil {
g.stopCombat(p.Name)
}
p.Action = nil
oldRoom := p.RoomID
p.RoomID = targetID
g.AccountStore.SaveCharacter(p)
g.World.SeedGroundItems(p.RoomID)
g.seedRoomMobs(p.RoomID)
g.seedRoomObjects(p.RoomID)
if g.Hub != nil {
for _, other := range g.Hub.PlayersInRoom(oldRoom) {
if other != sess {
other.WriteLine(fmt.Sprintf("\n%s leaves to the %s.", p.Name, exitDir))
}
}
g.Hub.EnterRoom(sess, targetID)
for _, other := range g.Hub.PlayersInRoom(targetID) {
if other != sess {
other.WriteLine(fmt.Sprintf("\n%s arrives.", p.Name))
}
}
}
sess.WriteLine(fmt.Sprintf("\nYou walk %s.", g.colorize(sess, "direction", exitDir)))
p.ActionState = &ActionState{Type: ActionMoving, Direction: exitDir}
if p.OptionBool("description") {
g.doLook(sess)
} else {
targetRoom, _ := g.World.LoadRoom(targetID)
if targetRoom != nil {
sess.WriteLine(g.colorize(sess, "room_name", targetRoom.Name))
}
}
if p.OptionBool("automap") {
g.doMap(sess)
}
g.RunEnterSteps(sess, targetID)
g.checkAggro(sess)
}
func (g *Game) seedRoomMobs(roomID int) {
room, err := g.World.LoadRoom(roomID)
if err != nil || len(room.Mobs) == 0 {
return
}
g.MobStore.SeedMobs(roomID, room.Mobs)
}
func (g *Game) seedRoomObjects(roomID int) {
room, err := g.World.LoadRoom(roomID)
if err != nil {
return
}
var ids []string
for _, obj := range room.Objects {
ids = append(ids, obj.ID)
}
g.World.EnsureObjectStates(roomID, ids)
for _, obj := range room.Objects {
def, err := g.ObjectStore.Load(obj.ID)
if err != nil {
continue
}
g.World.SetObjName(roomID, obj.ID, def.Name)
if len(obj.WanderRooms) > 0 {
g.World.SetObjWander(roomID, obj.ID, obj.WanderRooms, obj.WanderInterval)
}
if def.BehaviorID != "" {
cfg, err := g.BehaviorStore.LoadGather(def.BehaviorID)
if err == nil && cfg.DepleteTimer > 0 {
g.World.SetObjDepleteTimer(roomID, obj.ID, cfg.DepleteTimer)
}
}
}
}
|