-
Notifications
You must be signed in to change notification settings - Fork 0
/
Drop.go
76 lines (64 loc) · 2.06 KB
/
Drop.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 PPLCommand
import (
"strings"
"google.golang.org/grpc/status"
"rest.com.tw/tinymud/src/RestGo.MUD.Core.Command/Command/UserCommands"
"rest.com.tw/tinymud/src/RestGo.MUD.Core.Command/CommonServices/StructCollection"
"rest.com.tw/tinymud/src/RestGo.MUD.Core.Objects/BasicDefinition"
"rest.com.tw/tinymud/src/RestGo.MUD.Core.Objects/Room"
"rest.com.tw/tinymud/src/RestGo.MUD.Core.Objects/Room/RoomHelper"
"rest.com.tw/tinymud/src/RestGo.Util/utility"
)
type DropCommand struct{}
func (c *DropCommand) Settings() (Fullkey string, SupportFuzzyMatch bool) {
return "Drop", false
}
func init() {
UserCommands.RegisterCommand(&DropCommand{})
}
// drop xxx
func (c *DropCommand) Execute(args string, mudconn *StructCollection.MudClient) (quit bool) {
//拆解命令
actionNum, actionObjName, _, _ := utility.ParserGetPutCommand(args)
room, _ := RoomHelper.GetRoom(mudconn.User.RoomID)
if actionObjName == "" {
mudconn.SendMessage("你想丟掉什麼物品?")
return
}
if actionNum == 1 && strings.ToLower(actionObjName) == "all" {
c.DropAll(mudconn, room)
return
}
obj, err := mudconn.User.GetOut(actionNum, actionObjName)
if err != nil {
mudconn.SendMessage("你沒有那個東西。")
return
}
room.PutIn(obj)
mudconn.SendFMessage("你丟掉%s。", obj.GetObjectBasic().Name_CH)
return
}
func (*DropCommand) DropAll(mudconn *StructCollection.MudClient, room *Room.Room) {
if len(mudconn.User.Items) > 0 {
var itemsName []string
for _, v := range mudconn.User.Items {
itemsName = append(itemsName, v.GetObjectBasic().Name_EN)
}
for _, itemName := range itemsName {
obj, err := mudconn.User.GetOut(1, itemName)
if err != nil {
switch status.Code(err) {
case BasicDefinition.ObjectCannotMove:
mudconn.SendFMessage("你沒有辦法丟掉%s", obj.GetObjectBasic().Name_CH)
default:
mudconn.SendMessage("你身上沒有那個東西。")
}
} else {
room.PutIn(obj)
mudconn.SendFMessage("你丟掉%s。", obj.GetObjectBasic().Name_CH)
}
}
} else {
mudconn.SendMessage("你身上空空如也。")
}
}