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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
|
package game
import (
"fmt"
"strings"
"thehouseoficarus/internal/behavior"
"thehouseoficarus/internal/casino"
"thehouseoficarus/internal/net"
)
type commandHandler func(g *Game, sess *net.Session, args []string, rawInput string)
type commandDef struct {
handler commandHandler
class CommandClass
}
var commandRegistry = map[string]commandDef{
"get": {(*Game).executeGet, ClassActive},
"take": {(*Game).executeGet, ClassActive},
"grab": {(*Game).executeGet, ClassActive},
"pick": {(*Game).executeGet, ClassActive},
"drop": {(*Game).executeDrop, ClassActive},
"attack": {(*Game).executeAttack, ClassActive},
"kill": {(*Game).executeAttack, ClassActive},
"work": {(*Game).executeWork, ClassActive},
"play": {(*Game).executePlay, ClassActive},
"rebet": {(*Game).executeBet, ClassActive},
"draw": {func(g *Game, s *net.Session, _ []string, _ string) { g.executeTableAction(s, "draw") }, ClassActive},
"hold": {func(g *Game, s *net.Session, args []string, _ string) {
g.executeTableAction(s, "hold "+strings.Join(args, " "))
}, ClassInstant},
"deal": {func(g *Game, s *net.Session, args []string, _ string) {
if len(args) > 0 {
s.WriteLine("Use deal.")
return
}
g.executeTableAction(s, "deal")
}, ClassActive},
"paytable": {func(g *Game, s *net.Session, _ []string, _ string) { g.executeTableAction(s, "paytable") }, ClassInstant},
"denom": {func(g *Game, s *net.Session, args []string, _ string) {
g.executeTableAction(s, "denom "+strings.Join(args, " "))
}, ClassInstant},
"denomination": {func(g *Game, s *net.Session, args []string, _ string) {
g.executeTableAction(s, "denom "+strings.Join(args, " "))
}, ClassInstant},
"hands": {func(g *Game, s *net.Session, args []string, _ string) {
g.executeTableAction(s, "hands "+strings.Join(args, " "))
}, ClassInstant},
"feature": {func(g *Game, s *net.Session, args []string, _ string) {
g.executeTableAction(s, "feature "+strings.Join(args, " "))
}, ClassInstant},
"game": {func(g *Game, s *net.Session, args []string, _ string) {
g.executeTableAction(s, "game "+strings.Join(args, " "))
}, ClassInstant},
"roll": {func(g *Game, s *net.Session, _ []string, _ string) { g.executeTableAction(s, "roll") }, ClassActive},
"autoroll": {func(g *Game, s *net.Session, _ []string, _ string) { g.executeTableAction(s, "autoroll") }, ClassInstant},
"unbet": {func(g *Game, s *net.Session, _ []string, _ string) {
g.executeTableAction(s, "unbet")
}, ClassActive},
"table": {(*Game).executeTableStatus, ClassInstant},
"status": {(*Game).executeTableStatus, ClassInstant},
"rules": {(*Game).executeRules, ClassInstant},
"list": {(*Game).executeList, ClassInstant},
"watch": {(*Game).executeWatch, ClassInstant},
"decline": {func(g *Game, s *net.Session, _ []string, _ string) { g.executeTableAction(s, "decline") }, ClassActive},
"h": {func(g *Game, s *net.Session, _ []string, _ string) { g.executeTableAction(s, "hit") }, ClassActive},
"st": {func(g *Game, s *net.Session, _ []string, _ string) { g.executeTableAction(s, "stand") }, ClassActive},
"dd": {func(g *Game, s *net.Session, _ []string, _ string) { g.executeTableAction(s, "double") }, ClassActive},
"sp": {func(g *Game, s *net.Session, _ []string, _ string) { g.executeTableAction(s, "split") }, ClassActive},
"bet": {(*Game).executeBet, ClassActive},
"spin": {(*Game).executeSpin, ClassActive},
"autobet": {(*Game).executeAutoBet, ClassActive},
"autospin": {(*Game).executeAutoBet, ClassActive},
"hit": {func(g *Game, s *net.Session, _ []string, _ string) { g.executeTableAction(s, "hit") }, ClassActive},
"stand": {func(g *Game, s *net.Session, _ []string, _ string) { g.executeTableAction(s, "stand") }, ClassActive},
"double": {func(g *Game, s *net.Session, _ []string, _ string) { g.executeTableAction(s, "double") }, ClassActive},
"split": {func(g *Game, s *net.Session, _ []string, _ string) { g.executeTableAction(s, "split") }, ClassActive},
"insurance": {func(g *Game, s *net.Session, _ []string, _ string) { g.executeTableAction(s, "insurance") }, ClassActive},
"surrender": {func(g *Game, s *net.Session, _ []string, _ string) { g.executeTableAction(s, "surrender") }, ClassActive},
"style": {(*Game).executeStyle, ClassInstant},
"look": {(*Game).executeLook, ClassInstant},
"l": {(*Game).executeLook, ClassInstant},
"north": {(*Game).executeMove, ClassActive},
"n": {(*Game).executeMove, ClassActive},
"south": {(*Game).executeMove, ClassActive},
"s": {(*Game).executeMove, ClassActive},
"east": {(*Game).executeMove, ClassActive},
"e": {(*Game).executeMove, ClassActive},
"west": {(*Game).executeMove, ClassActive},
"w": {(*Game).executeMove, ClassActive},
"northeast": {(*Game).executeMove, ClassActive},
"ne": {(*Game).executeMove, ClassActive},
"northwest": {(*Game).executeMove, ClassActive},
"nw": {(*Game).executeMove, ClassActive},
"southeast": {(*Game).executeMove, ClassActive},
"se": {(*Game).executeMove, ClassActive},
"southwest": {(*Game).executeMove, ClassActive},
"sw": {(*Game).executeMove, ClassActive},
"up": {(*Game).executeMove, ClassActive},
"u": {(*Game).executeMove, ClassActive},
"down": {(*Game).executeMove, ClassActive},
"d": {(*Game).executeMove, ClassActive},
"say": {(*Game).executeSay, ClassInstant},
"global": {(*Game).executeGlobal, ClassInstant},
"who": {(*Game).executeWho, ClassInstant},
"sc": {(*Game).executeScore, ClassInstant},
"score": {(*Game).executeScore, ClassInstant},
"skills": {(*Game).executeSkills, ClassInstant},
"sk": {(*Game).executeSkills, ClassInstant},
"task": {(*Game).executeTask, ClassInstant},
"stats": {(*Game).executeStats, ClassInstant},
"tech": {(*Game).executeTech, ClassInstant},
"t": {(*Game).executeTech, ClassInstant},
"i": {(*Game).executeInventory, ClassInstant},
"inv": {(*Game).executeInventory, ClassInstant},
"inventory": {(*Game).executeInventory, ClassInstant},
"quit": {(*Game).executeQuit, ClassActive},
"description": {(*Game).executeDescription, ClassInstant},
"desc": {(*Game).executeDescription, ClassInstant},
"option": {(*Game).executeOption, ClassInstant},
"options": {(*Game).executeOption, ClassInstant},
"color": {(*Game).executeColor, ClassInstant},
"colors": {(*Game).executeColor, ClassInstant},
"colortable": {(*Game).executeColortable, ClassInstant},
"prompt": {(*Game).executePrompt, ClassInstant},
"exits": {(*Game).executeExits, ClassInstant},
"map": {(*Game).executeMap, ClassInstant},
"symbol": {(*Game).executeSymbol, ClassInstant},
"queued": {(*Game).executeQueued, ClassInstant},
"help": {(*Game).executeHelp, ClassInstant},
"mine": {(*Game).executeGather, ClassActive},
"chop": {(*Game).executeGather, ClassActive},
"fish": {(*Game).executeGather, ClassActive},
"cut": {(*Game).executeGather, ClassActive},
"pull": {(*Game).executeUse, ClassActive},
"push": {(*Game).executeUse, ClassActive},
"use": {(*Game).executeUse, ClassActive},
"cook": {(*Game).executeCook, ClassActive},
"smelt": {(*Game).executeSmelt, ClassActive},
"smith": {(*Game).executeSmith, ClassActive},
"craft": {(*Game).executeCraft, ClassActive},
"eat": {(*Game).executeEat, ClassFree},
"drink": {(*Game).executeDrink, ClassFree},
"fletch": {(*Game).executeFletch, ClassFree},
"clean": {(*Game).executeClean, ClassFree},
"mix": {(*Game).executeMix, ClassActive},
"id": {(*Game).executeIdentify, ClassActive},
"identify": {(*Game).executeIdentify, ClassActive},
"autotrigger": {(*Game).executeAutotrigger, ClassInstant},
"auto": {(*Game).executeAutotrigger, ClassInstant},
"mods": {(*Game).executeMods, ClassInstant},
"modlist": {(*Game).executeMods, ClassInstant},
"mod": {(*Game).executeMods, ClassInstant},
"modules": {(*Game).executeMods, ClassInstant},
"module": {(*Game).executeMods, ClassInstant},
"sneak": {(*Game).executeSneak, ClassInstant},
"trigger": {(*Game).executeTrigger, ClassActive},
"home": {(*Game).executeHome, ClassInstant},
"recall": {(*Game).executeHome, ClassInstant},
"talk": {(*Game).executeTalk, ClassActive},
"speak": {(*Game).executeTalk, ClassActive},
"ask": {(*Game).executeTalk, ClassActive},
"burn": {(*Game).executeBurn, ClassActive},
"stoke": {(*Game).executeStoke, ClassActive},
"alias": {(*Game).executeAlias, ClassInstant},
"unalias": {(*Game).executeUnalias, ClassInstant},
"search": {(*Game).executeSearch, ClassActive},
"steal": {(*Game).executeSteal, ClassActive},
"thieve": {(*Game).executeSteal, ClassActive},
"plant": {(*Game).executePlant, ClassActive},
"harvest": {(*Game).executeHarvest, ClassActive},
"rake": {(*Game).executeRake, ClassActive},
"water": {(*Game).executeWater, ClassActive},
"cure": {(*Game).executeCure, ClassActive},
"inspect": {(*Game).executeInspect, ClassInstant},
"walk": {(*Game).executeWalk, ClassActive},
"bank": {(*Game).executeBank, ClassActive},
"browse": {(*Game).executeShopList, ClassInstant},
"buy": {(*Game).executeShopBuy, ClassInstant},
"sell": {(*Game).executeShopSell, ClassInstant},
"construct": {(*Game).executeConstruct, ClassActive},
"make": {(*Game).executeConstruct, ClassActive},
"jack": {(*Game).executeJack, ClassActive},
"jackin": {(*Game).executeJack, ClassActive},
"eq": {(*Game).executeWear, ClassFree},
"equipment": {(*Game).executeWear, ClassFree},
"equip": {(*Game).executeWear, ClassFree},
"wear": {(*Game).executeWear, ClassFree},
"wield": {(*Game).executeWear, ClassFree},
"remove": {(*Game).executeRemove, ClassFree},
"unwear": {(*Game).executeRemove, ClassFree},
"unwield": {(*Game).executeRemove, ClassFree},
"aps": {(*Game).executeAps, ClassActive},
"verbs": {(*Game).executeVerbs, ClassInstant},
"what": {(*Game).executeVerbs, ClassInstant},
"syntax": {(*Game).executeVerbs, ClassInstant},
"commands": {(*Game).executeVerbs, ClassInstant},
"stop": {(*Game).executeStop, ClassInstant},
"hide": {(*Game).executeHide, ClassActive},
"safespot": {(*Game).executeHide, ClassActive},
"unhide": {(*Game).executeUnhide, ClassActive},
"unsafespot": {(*Game).executeUnhide, ClassActive},
"goto": {(*Game).executeGoto, ClassInstant},
"summon": {(*Game).executeSummon, ClassInstant},
"dig": {(*Game).executeDig, ClassInstant},
"setglobalflag": {(*Game).executeSetGlobalFlag, ClassInstant},
"setplayerflag": {(*Game).executeSetPlayerFlag, ClassInstant},
"reload": {(*Game).executeReload, ClassInstant},
"shutdown": {(*Game).executeShutdown, ClassInstant},
"room": {(*Game).executeRoom, ClassInstant},
"swapid": {(*Game).executeSwapID, ClassInstant},
"undig": {(*Game).executeUndig, ClassInstant},
"close": {(*Game).executeClose, ClassInstant},
"god": {(*Game).executeGod, ClassInstant},
"ungod": {(*Game).executeUnGod, ClassInstant},
"hideallexits": {(*Game).executeHideAllExits, ClassInstant},
}
func classifyCommand(cmd string) CommandClass {
if _, ok := casino.ParsePokerDigits(cmd); ok {
return ClassInstant
}
if _, ok := casino.ParsePaiGowDigits(cmd); ok {
return ClassInstant
}
if def, ok := commandRegistry[cmd]; ok {
return def.class
}
if _, ok := verbAliases[cmd]; ok {
return ClassActive
}
obstacleVerbsMu.RLock()
isObstacle := obstacleVerbs[cmd]
obstacleVerbsMu.RUnlock()
if isObstacle {
return ClassActive
}
return ClassUnknown
}
// casinoCommonVerbs are the generic controls a seated player may abbreviate
// at any casino game; they are not tied to one game's rules.
var casinoCommonVerbs = []string{"watch", "game", "table", "list", "stop", "rules"}
// casinoVerbsByGame scopes the rest of the abbreviable verbs to the game the
// player is actually in. A prefix can therefore never match another game's
// command: "sp" is split at a blackjack table, but spin at a Big 6 wheel,
// because "split" is not a Big 6 verb and "spin" is not a blackjack verb.
var casinoVerbsByGame = map[casino.GameName][]string{
casino.GameBlackjack: {"bet", "rebet", "unbet", "hit", "stand", "double", "split", "insurance", "surrender", "decline"},
casino.GameBaccarat: {"bet", "rebet", "unbet"},
casino.GameRoulette: {"bet", "rebet", "unbet"},
casino.GameCraps: {"bet", "rebet", "unbet", "roll", "autoroll"},
casino.GamePaiGow: {"bet", "rebet", "unbet"},
casino.GameVideoPoker: {"bet", "deal", "draw", "hold", "paytable", "denom", "denomination", "hands", "feature"},
casino.GameSlots: {"bet", "spin", "autospin", "autobet"},
casino.GameBigSix: {"bet", "rebet", "unbet", "spin"},
}
// casinoShortAliases maps the registry's terse aliases onto the verb they
// stand for. An alias only applies when its verb belongs to the current game;
// otherwise the letters are re-read as a fresh prefix, so "sp" is split at a
// blackjack table and spin at a Big 6 wheel.
var casinoShortAliases = map[string]string{
"h": "hit", "st": "stand", "dd": "double", "sp": "split",
}
// casinoVerbsFor returns the game-scoped verb vocabulary for a seated player,
// or nil when they are not in a casino game.
func (g *Game) casinoVerbsFor(name string) []string {
if g.Casino == nil {
return nil
}
table, playing := g.Casino.Participation(name)
if !playing {
return nil
}
var game casino.GameName
switch {
case table != nil:
game = table.Config.Game
default:
machine, ok := g.Casino.MachineFor(name)
if !ok {
return nil
}
game = machine.Config.Game
}
verbs := append([]string(nil), casinoCommonVerbs...)
return append(verbs, casinoVerbsByGame[game]...)
}
// casinoAbbreviation resolves a seated casino player's partial command to the
// closest verb that is actually relevant to the game they are in. Exact
// commands always win, so movement, look and the game's own real verbs are
// never shadowed; a short alias applies only when its verb belongs to this
// game; an ambiguous prefix resolves to nothing and falls through unchanged.
func (g *Game) casinoAbbreviation(sess *net.Session, cmd string) (string, bool) {
if sess == nil || sess.Player == nil || cmd == "" {
return "", false
}
verbs := g.casinoVerbsFor(sess.Player.Name)
if len(verbs) == 0 {
return "", false
}
// A real casino verb needs no abbreviation: the registry dispatches it.
for _, verb := range verbs {
if verb == cmd {
return "", false
}
}
if target, ok := casinoShortAliases[cmd]; ok {
for _, verb := range verbs {
if verb == target {
return target, true
}
}
// The alias names another game's verb: fall through and read the
// letters as a prefix of this game's vocabulary instead.
} else if _, ok := commandRegistry[cmd]; ok {
// Any other real command (movement, look, inventory, ...) wins over a
// casino prefix.
return "", false
}
match := ""
for _, verb := range verbs {
if !strings.HasPrefix(verb, cmd) {
continue
}
if match != "" && match != verb {
return "", false
}
match = verb
}
return match, match != ""
}
func (g *Game) executeCommand(sess *net.Session, cmd string, args []string, rawInput string) {
p := sess.Player
// Locked-sequence busy gate: a locked in-flight trigger sequence blocks every
// verb except quit/logout (and god-mode admins) until it completes.
if p != nil && !p.GodMode && g.playerLocked(p.Name) && cmd != "quit" && cmd != "logout" {
sess.WriteLine("You're busy — wait for the current action to finish.")
return
}
// Unlocked sequences are interruptable: any active/free verb cancels them
// before running. (Instant info commands like look/inventory/help do not.)
if p != nil {
switch classifyCommand(cmd) {
case ClassActive, ClassFree:
g.cancelUnlockedSequences(p.Name)
}
}
// Pai Gow owns these inputs only while seated; leave normal commands alone.
if p != nil && g.Casino != nil {
if t, playing := g.Casino.Participation(p.Name); playing && t != nil && t.Config.Game == casino.GamePaiGow {
numeric := cmd != "" && cmd[0] >= '0' && cmd[0] <= '9'
if numeric || cmd == "set" || cmd == "house" || cmd == "settle" || cmd == "autoset" {
g.executeTableAction(sess, strings.Join(append([]string{cmd}, args...), " "))
return
}
}
}
// Video poker: numeric tokens toggle holds and d draws, so both are
// intercepted before the shared registry (where d means "down").
_, pokerDigits := casino.ParsePokerDigits(cmd)
if p != nil && g.Casino != nil && (cmd == "d" || pokerDigits) {
if t, playing := g.Casino.Participation(p.Name); playing && t != nil && t.Config.Game == casino.GameVideoPoker {
if cmd == "d" {
if len(args) != 0 {
sess.WriteLine("Use d or draw.")
return
}
g.executeTableAction(sess, "draw")
return
}
g.executeTableAction(sess, strings.Join(append([]string{cmd}, args...), " "))
return
}
}
if def, ok := commandRegistry[cmd]; ok {
def.handler(g, sess, args, rawInput)
return
}
obstacleVerbsMu.RLock()
isObstacle := obstacleVerbs[cmd]
obstacleVerbsMu.RUnlock()
if isObstacle {
g.doObstacle(sess, cmd)
return
}
if a, ok := verbAliases[cmd]; ok {
g.cancelAction(p)
switch a {
case behavior.TypeGather:
if len(args) == 0 {
target := g.defaultTarget(p.RoomID, cmd)
if target == "" {
sess.WriteLine(fmt.Sprintf("%s what?", cmd))
return
}
g.startAction(sess, cmd, target)
} else {
g.startAction(sess, cmd, strings.Join(args, " "))
}
case behavior.TypeTalk:
if len(args) == 0 {
sess.WriteLine("Talk to whom?")
} else {
g.startAction(sess, "talk", strings.Join(args, " "))
}
default:
// No handler for this alias: never return silently, or a typo'd
// alias becomes an invisible no-op.
sess.WriteLine("Unknown command.")
}
return
}
sess.WriteLine("Unknown command.")
}
func (g *Game) executeGather(sess *net.Session, args []string, rawInput string) {
verb := strings.Fields(rawInput)[0]
p := sess.Player
g.cancelAction(p)
if len(args) == 0 {
target := g.defaultTarget(p.RoomID, verb)
if target == "" {
sess.WriteLine(fmt.Sprintf("%s what?", verb))
return
}
g.startAction(sess, verb, target)
} else {
g.startAction(sess, verb, strings.Join(args, " "))
}
}
func (g *Game) executeTalk(sess *net.Session, args []string, rawInput string) {
p := sess.Player
g.cancelAction(p)
if len(args) == 0 {
sess.WriteLine("Talk to whom?")
} else {
g.startAction(sess, "talk", strings.Join(args, " "))
}
}
|