-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworld_cmd.go
76 lines (69 loc) · 1.68 KB
/
world_cmd.go
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
package main
import (
"strings"
)
func cmdLook(player *characterData, input string) {
if player.room == nil {
player.send("You are floating in the nil.")
return
}
if input == "" {
lookRoom(player)
} else {
player.send("Who? What? Huh?")
}
}
func cmdGo(player *characterData, input string) {
input = strings.ToLower(input)
if player.room == nil {
player.send("There is nowhere to go.")
return
}
if input == "" {
player.send("Go what direction?")
return
}
for _, exit := range player.room.Exits {
if exit.Direction == DIR_CUSTOM {
if strings.HasPrefix(strings.ToLower(exit.DirName), input) {
player.send("You go %v", exit.DirName)
player.goExit(exit)
cmdLook(player, "")
return
}
} else {
dirStr := dirToText[exit.Direction]
dirName := strings.ToLower(dirStr)
if strings.HasPrefix(dirName, input) {
player.send("You go %v{x", dirToTextColor[exit.Direction])
player.goExit(exit)
cmdLook(player, "")
return
}
}
}
player.send("Go where?")
}
func (player *characterData) goExit(exit *exitData) {
if player.room != nil && exit != nil && exit.pRoom != nil {
var dirStr string
if exit.Direction == DIR_CUSTOM {
dirStr = exit.DirName
} else {
dirStr = dirToTextColor[exit.Direction]
}
player.sendToRoom("%v leaves %v{x", player.Name, dirStr)
player.leaveRoom()
player.room = exit.pRoom
player.room.players = append(player.room.players, player)
player.Loc = exit.ToRoom
if exit.Direction == DIR_CUSTOM {
dirStr = exit.DirName
} else {
newDir := exit.Direction.revDir()
dirStr = dirToTextColor[newDir]
}
player.sendToRoom("%v arrives from the %v{x", player.Name, dirStr)
player.dirty = true
}
}