GmAction.go
1.88 KB
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
// GM系统API
package gmaction
import (
"pro2d/models"
"pro2d/pb"
"strconv"
)
type GmAction struct{}
// GMParams GM系统API请求参数的基础类型
type GMParams map[string]string
/*
AddExp 增加经验
exp 增加经验数量
*/
func (gm *GmAction) AddExp(role *models.RoleModel, params GMParams) {
expIncrease, _ := strconv.Atoi(params["exp"])
exp := role.IncrProperty("exp", int64(expIncrease))
role.UpdateProperty("exp", exp, true)
}
/*
AddEquip 添加装备
id: 装备id
*/
func (gm *GmAction) AddEquip(role *models.RoleModel, params GMParams) {
//TODO 验证装备是否存在
id := params["id"]
tbId, _ := strconv.Atoi(id)
equip := &pb.Equipment{
Id: role.IncreEquipByKey(1),
RoleId: role.Role.Id,
TbId: int32(tbId),
Quality: 1,
}
role.AddEquip(equip)
}
/*
AddItem 添加物品
id: 物品id
count: 物品数量
*/
func (gm *GmAction) AddItem(role *models.RoleModel, params GMParams) {
id := params["id"]
count, _ := strconv.Atoi(params["count"])
role.AddItem(id, int32(count))
}
/*
UpdatePackLimit 更新背包限制
clotheslimit: 服饰限制数
weaponslimit: 武器限制数
jewelrylimit: 首饰限制数
materiallimit: 材料限制数
otherlimit: 其他限制数
*/
func (gm *GmAction) UpdatePackLimit(role *models.RoleModel, params GMParams) {
update := make(map[string]interface{}, 5)
c, ok := params["clotheslimit"]
if ok {
l, _ := strconv.Atoi(c)
update["clotheslimit"] = uint32(l)
}
w, ok := params["weaponslimit"]
if ok {
l, _ := strconv.Atoi(w)
update["weaponslimit"] = uint32(l)
}
o, ok := params["otherlimit"]
if ok {
l, _ := strconv.Atoi(o)
update["otherlimit"] = uint32(l)
}
o, ok = params["jewelrylimit"]
if ok {
l, _ := strconv.Atoi(o)
update["jewelrylimit"] = uint32(l)
}
o, ok = params["materiallimit"]
if ok {
l, _ := strconv.Atoi(o)
update["materiallimit"] = uint32(l)
}
role.UpdateProperties(update, true)
}