GmAction.go
2.7 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
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
// GM系统API
package gmaction
import (
"pro2d/common"
"pro2d/common/logger"
"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.Data.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)
}
/*GMEmail 发送邮件
参数 &title= &stitle= &content= &attachments=
*/
func (gm *GmAction) GMEmail(role *models.RoleModel, params GMParams) {
title, ok := params["title"]
if !ok {
title = ""
}
stitle, ok := params["stitle"]
if !ok {
stitle = ""
}
content, ok := params["content"]
if !ok {
content = ""
}
attachments, ok := params["attachments"]
if !ok {
attachments = ""
}
id, err := common.GetNextEmail()
if err != nil {
logger.Error(err)
return
}
email := &pb.Email{
Id: id,
RoleId: role.Data.Id,
Title: title,
Stitle: stitle,
Content: content,
Attachments: attachments,
Status: 0,
CreateTime: common.Timex(),
}
m := models.NewEmailModelPB(email)
err = m.Create()
if err != nil {
logger.Error(err)
}
}