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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
package game
import (
"strings"
"thehouseoficarus/internal/behavior"
"thehouseoficarus/internal/casino"
"thehouseoficarus/internal/net"
"thehouseoficarus/internal/world"
)
var alwaysAvailable = []string{
"look",
"say",
"global",
"who",
"exits",
"map",
"walk",
"score", "stats",
"inventory",
"equip",
"remove",
"style",
"tech",
"option",
"color", "colortable",
"prompt",
"alias", "unalias",
"help",
"queued",
"stop",
"aps",
"autotrigger",
"trigger",
"sneak",
"mods",
"identify",
"eat", "drink",
"fletch",
"clean",
"burn", "stoke",
"search",
"get",
"drop",
}
func (g *Game) executeVerbs(sess *net.Session, args []string, rawInput string) {
p := sess.Player
// A seated casino player has no room verbs: the only valid commands are
// the game's live hints, so what/verbs shows those instead of exits and
// objects that cannot be used mid-hand.
if g.Casino != nil {
if table, playing := g.Casino.Participation(p.Name); playing {
if table != nil {
g.showCasinoHints(sess, table.Hints(p.Name))
} else if machine, ok := g.Casino.MachineFor(p.Name); ok {
g.showCasinoHints(sess, machine.Hints())
}
return
}
}
showAll := len(args) == 1 && strings.ToLower(args[0]) == "all"
seen := make(map[string]bool)
var sectionObjs []string
var sectionMobs []string
var sectionExits []string
var sectionGround []string
for _, st := range g.World.AllObjInstances(p.RoomID) {
def, _, err := g.resolveObjectDef(p.RoomID, st.DefID)
if err != nil || (def.Hidden && !p.GodMode) {
continue
}
name := strings.ToLower(def.Name)
bt := def.BehaviorType()
if bt == "gather" && def.Gather != nil {
for verb, skill := range verbSkill {
if strings.EqualFold(def.Gather.Skill, skill) {
addUnique(§ionObjs, &seen, verb+" "+name)
}
}
}
if bt == "talk" {
addUnique(§ionObjs, &seen, "talk "+name)
}
for _, ui := range def.OnUse {
if ui.ItemID == "" && (ui.Condition == nil || g.checkCondition(sess, ui.Condition)) {
addUnique(§ionObjs, &seen, "use "+name)
break
}
}
recipes := g.stationRecipes(p, def.ID)
if len(recipes) > 0 {
addUnique(§ionObjs, &seen, "use "+name)
for _, r := range recipes {
c := r.FirstCraft()
key := c.Subtype
if key == "" {
key = c.Type
}
if info, ok := productionTypes[key]; ok {
if info.ActionType != behavior.TypeCombine && info.ActionType != behavior.TypeFletch && info.ActionType != behavior.TypeMix {
addUnique(§ionObjs, &seen, string(info.ActionType))
}
}
for _, c := range r.FirstCraft().Ingredients {
for _, itemID := range c.Items {
if itemDef, err := g.ItemStore.Load(itemID); err == nil {
addUnique(§ionObjs, &seen, "use "+itemDef.Name+" on "+name)
}
}
}
}
}
for _, ui := range def.OnUse {
if ui.ItemID != "" && (ui.Condition == nil || g.checkCondition(sess, ui.Condition)) {
if itemDef, err := g.ItemStore.Load(ui.ItemID); err == nil {
addUnique(§ionObjs, &seen, "use "+itemDef.Name+" on "+name)
}
}
}
if def.Steal != nil && len(def.Steal.Drops) > 0 {
addUnique(§ionObjs, &seen, "steal "+name)
}
addUnique(§ionObjs, &seen, "look "+name)
}
for _, m := range g.MobStore.MobsInRoom(p.RoomID) {
mName := strings.ToLower(m.Name)
if !m.Protected {
addUnique(§ionMobs, &seen, "attack "+mName)
}
if m.IsTalkable() {
addUnique(§ionMobs, &seen, "talk "+mName)
}
if len(m.StealDrops) > 0 {
addUnique(§ionMobs, &seen, "steal "+mName)
}
addUnique(§ionMobs, &seen, "look "+mName)
}
if room, err := g.World.LoadRoom(p.RoomID); err == nil {
var exitDirs []string
for _, dir := range world.ExitOrder {
ed, ok := room.Exits[dir]
if !ok {
continue
}
if !g.exitDisplayState(sess, p.RoomID, dir, ed).Visible {
continue
}
exitDirs = append(exitDirs, string(dir))
}
if len(exitDirs) > 0 {
sectionExits = append(sectionExits, strings.Join(exitDirs, ", "))
}
}
ground := g.World.GroundItems(p.RoomID)
if len(ground) > 0 {
for itemID := range ground {
if def, err := g.ItemStore.Load(itemID); err == nil {
addUnique(§ionGround, &seen, "get "+def.Name)
}
}
addUnique(§ionGround, &seen, "get all")
}
if info := g.CourseStore.GetObstacle(p.RoomID); info != nil {
addUnique(§ionGround, &seen, info.Verb)
}
if g.canUseBank(p) {
addUnique(§ionObjs, &seen, "bank")
}
if g.findTerminalInRoom(p.RoomID) != "" {
addUnique(§ionObjs, &seen, "jack")
}
hasRoomCmds := len(sectionObjs) > 0 || len(sectionMobs) > 0 || len(sectionExits) > 0 || len(sectionGround) > 0
if hasRoomCmds {
if len(sectionObjs) > 0 {
sess.WriteLine("Objects:")
writeCmdLines(sess, sectionObjs)
}
if len(sectionMobs) > 0 {
sess.WriteLine("Mobs:")
writeCmdLines(sess, sectionMobs)
}
if len(sectionExits) > 0 {
sess.WriteLine("Exits:")
writeCmdLines(sess, sectionExits)
}
if len(sectionGround) > 0 {
sess.WriteLine("Ground:")
writeCmdLines(sess, sectionGround)
}
} else {
sess.WriteLine("There is nothing notable to interact with here.")
}
if showAll {
sess.WriteLine("")
sess.WriteLine("Always available:")
writeCmdLineStrings(sess, alwaysAvailable)
} else {
sess.WriteLine("")
sess.WriteLine(`Type "verbs all" to see all available commands.`)
}
}
// showCasinoHints prints the live command hints for a seated player. It is
// the casino branch of the what/verbs command, so a casino never lists room
// exits that are not valid options while seated.
func (g *Game) showCasinoHints(sess *net.Session, commands []casino.MenuCommand) {
if len(commands) == 0 {
sess.WriteLine(g.colorize(sess, "casino_action", "No commands are available right now."))
return
}
sess.WriteLine(g.casinoMenuCommands(sess, commands))
}
func addUnique(list *[]string, seen *map[string]bool, cmd string) {
if (*seen)[cmd] {
return
}
(*seen)[cmd] = true
*list = append(*list, cmd)
}
func writeCmdLines(sess *net.Session, cmds []string) {
wrapCmdLines(sess, cmds, " ")
}
func writeCmdLineStrings(sess *net.Session, cmds []string) {
wrapCmdLines(sess, cmds, " ")
}
func wrapCmdLines(sess *net.Session, cmds []string, prefix string) {
const width = 70
var current string
for _, cmd := range cmds {
if current == "" {
current = prefix + cmd
} else if len(current)+len(cmd)+2 <= width {
current += ", " + cmd
} else {
sess.WriteLine(current)
current = prefix + cmd
}
}
if current != "" {
sess.WriteLine(current)
}
}
|