Commit 77da2da88777e9261bba2ae95150536a23bd0b28

Authored by zhangqijia
1 parent cdef950e

fix: add log

cmd/gameserver/action/EmailAction.go
... ... @@ -78,7 +78,7 @@ func EmailDrawRpc(role *models.RoleModel, msg components.IMessage) (int32, inter
78 78 }
79 79 }
80 80 }
81   - role.Award(reward)
  81 + role.Award(reward, &pb.LogConf{Desc: "draw_attach"})
82 82  
83 83 return 0, &pb.EmailDrawRsp{Ids: ids, Reward: common.MapNumToString(reward)}
84 84 }
... ...
cmd/gameserver/action/HeroAction.go
... ... @@ -77,7 +77,7 @@ func HeroUpLevelRpc(role *models.RoleModel, msg components.IMessage) (int32, int
77 77 return 5, nil
78 78 }
79 79  
80   - if !role.CostItem(fmt.Sprintf("%d", item.ID), count) {
  80 + if !role.CostItem(fmt.Sprintf("%d", item.ID), count, &pb.LogConf{Desc: "hero_action"}) {
81 81 return 6, nil
82 82 }
83 83  
... ...
cmd/gameserver/action/RoleAction.go
... ... @@ -126,7 +126,7 @@ func RoleClearItemsRpc(role *models.RoleModel, msg components.IMessage) (int32,
126 126 }
127 127 }
128 128  
129   - if !role.CostItems(bkup) {
  129 + if !role.CostItems(bkup, &pb.LogConf{Desc: "clear_items"}) {
130 130 logger.Error("cost err: %s", common.MapNumToString(bkup))
131 131 return 2, nil
132 132 }
... ... @@ -195,7 +195,7 @@ func RoleEndBattleRpc(role *models.RoleModel, msg components.IMessage) (int32, i
195 195 }
196 196 }
197 197 //award
198   - reward = role.Award(reward)
  198 + reward = role.Award(reward, &pb.LogConf{Desc: "in_battle", Int1: string(chapterInfo.ChapterId), Int2: string(chapterCount)})
199 199  
200 200 //exp
201 201 var amount int32
... ...
cmd/gameserver/gmaction/GmAction.go
... ... @@ -39,7 +39,7 @@ func (gm *GmAction) AddEquip(role *models.RoleModel, params GMParams) {
39 39 TbId: int32(tbId),
40 40 Quality: 1,
41 41 }
42   - role.AddEquip(equip)
  42 + role.AddEquip(equip, &pb.LogConf{Desc: "gm_actioin"})
43 43 }
44 44  
45 45 /*
... ... @@ -50,7 +50,7 @@ AddItem 添加物品
50 50 func (gm *GmAction) AddItem(role *models.RoleModel, params GMParams) {
51 51 id := params["id"]
52 52 count, _ := strconv.Atoi(params["count"])
53   - role.AddItem(id, int32(count))
  53 + role.AddItem(id, int32(count), &pb.LogConf{Desc: "gm_action"})
54 54 }
55 55  
56 56 /*
... ...
common/const.go
... ... @@ -52,3 +52,9 @@ const (
52 52 RingPosL = 4 // 左戒指
53 53 RingPosR = 5 // 右戒指
54 54 )
  55 +
  56 +const (
  57 + ItemTypeInterval = 10000
  58 + ItemType = 0
  59 + EquipType = 1
  60 +)
... ...
common/utils.go
... ... @@ -46,7 +46,7 @@ func RandomName(name [][]string) string {
46 46 return name[0][idx1] + name[1][idx2]
47 47 }
48 48  
49   -//英文字符串,第一个字符大写
  49 +// FirstCharToUpper 英文字符串,第一个字符大写
50 50 func FirstCharToUpper(key string) string {
51 51 first := strings.ToUpper(key[0:1])
52 52 return first + key[1:]
... ...
models/roleLog.go
... ... @@ -10,15 +10,19 @@ import (
10 10 )
11 11  
12 12 var LogType = map[string]string{
13   - "in_item": "common",
14   - "out_item": "common",
15   - "in_hero": "common",
16   - "out_hero": "common",
17   - "in_equip": "common",
18   - "out_equip": "common",
19   -
  13 + "in_battle": "common",
  14 + "out_battle": "common",
  15 + "in_item": "common",
  16 + "out_item": "common",
  17 + "in_hero": "common",
  18 + "out_hero": "common",
  19 + "in_equip": "common",
  20 + "out_equip": "common",
  21 +
  22 + "gm_action": "common",
20 23 "mail_action": "common",
21 24 "role_action": "common",
  25 + "hero_action": "common",
22 26 }
23 27  
24 28 func (m *RoleModel) MyLog(logType string, content *pb.LogConf) {
... ...
models/rolePlugin.go
... ... @@ -5,14 +5,16 @@ import (
5 5 "github.com/golang/protobuf/proto"
6 6 "go.mongodb.org/mongo-driver/bson"
7 7 "go.mongodb.org/mongo-driver/mongo/options"
  8 + "math"
8 9 "pro2d/common"
9 10 "pro2d/common/db/mongoproxy"
10 11 "pro2d/common/logger"
11 12 "pro2d/csvdata"
12 13 "pro2d/pb"
  14 + "strconv"
13 15 )
14 16  
15   -//背包系统
  17 +// GetItemCount 背包系统
16 18 func (m *RoleModel) GetItemCount(key string) int32 {
17 19 c, ok := m.Items[key]
18 20 if !ok {
... ... @@ -21,14 +23,14 @@ func (m *RoleModel) GetItemCount(key string) int32 {
21 23 return c
22 24 }
23 25  
24   -func (m *RoleModel) CostItem(key string, count int32) bool {
  26 +func (m *RoleModel) CostItem(key string, count int32, param *pb.LogConf) bool {
25 27 if count > m.GetItemCount(key) {
26 28 return false
27 29 }
28   - return m.AddItem(key, -count)
  30 + return m.AddItem(key, -count, param)
29 31 }
30 32  
31   -func (m *RoleModel) CostItems(params common.IMapStringNum) bool {
  33 +func (m *RoleModel) CostItems(params common.IMapStringNum, logconf *pb.LogConf) bool {
32 34 for k, v := range params {
33 35 if v > m.GetItemCount(k) {
34 36 return false
... ... @@ -37,10 +39,10 @@ func (m *RoleModel) CostItems(params common.IMapStringNum) bool {
37 39 params[k] = -v
38 40 }
39 41  
40   - return m.AddItems(params)
  42 + return m.AddItems(params, logconf)
41 43 }
42 44  
43   -func (m *RoleModel) AddItem(key string, count int32) bool {
  45 +func (m *RoleModel) AddItem(key string, count int32, param *pb.LogConf) bool {
44 46 c := m.GetItemCount(key)
45 47  
46 48 num := c + count
... ... @@ -48,9 +50,20 @@ func (m *RoleModel) AddItem(key string, count int32) bool {
48 50 m.Items[key] = num
49 51 } else {
50 52 delete(m.Items, key)
  53 + num = 0
51 54 }
52 55 m.SetProperty("items", common.MapNumToString(m.Items))
53 56  
  57 + id, _ := strconv.Atoi(key)
  58 + param.Cint1 = int64(id)
  59 + param.Cint2 = int64(math.Abs(float64(count)))
  60 + param.Cint3 = int64(num)
  61 + if count < 0 {
  62 + m.MyLog("out_item", param)
  63 + } else {
  64 + m.MyLog("in_item", param)
  65 + }
  66 +
54 67 rsp, err := proto.Marshal(&pb.RoleUpdateItemsNty{Items: fmt.Sprintf("%s=%d", key, num)})
55 68 if err != nil {
56 69 logger.Error(err.Error())
... ... @@ -63,7 +76,7 @@ func (m *RoleModel) AddItem(key string, count int32) bool {
63 76 return true
64 77 }
65 78  
66   -func (m *RoleModel) AddItems(params common.IMapStringNum) bool {
  79 +func (m *RoleModel) AddItems(params common.IMapStringNum, logconf *pb.LogConf) bool {
67 80 tmp := make(common.IMapString)
68 81 for k, v := range params {
69 82 c := m.GetItemCount(k)
... ... @@ -76,6 +89,16 @@ func (m *RoleModel) AddItems(params common.IMapStringNum) bool {
76 89 delete(m.Items, k)
77 90 }
78 91 tmp[k] = num
  92 +
  93 + id, _ := strconv.Atoi(k)
  94 + logconf.Cint1 = int64(id)
  95 + logconf.Cint2 = int64(math.Abs(float64(v)))
  96 + logconf.Cint3 = int64(num)
  97 + if v < 0 {
  98 + m.MyLog("out_item", logconf)
  99 + } else {
  100 + m.MyLog("in_item", logconf)
  101 + }
79 102 }
80 103  
81 104 m.SetProperty("items", common.MapNumToString(m.Items))
... ... @@ -115,10 +138,15 @@ func (m *RoleModel) UpdateTeam(teams []*pb.Team) {
115 138 }
116 139 }
117 140  
118   -func (m *RoleModel) AddEquip(equip *pb.Equipment) *EquipModel {
  141 +func (m *RoleModel) AddEquip(equip *pb.Equipment, conf *pb.LogConf) *EquipModel {
119 142 e := NewEquip(equip)
120 143 e.Create()
121 144 m.Equipments[equip.Id] = e
  145 +
  146 + conf.Int1 = e.Data.Id
  147 + conf.Int2 = string(e.Data.Pos)
  148 + conf.Cint1 = 1
  149 + m.MyLog("in_equip", conf)
122 150 m.EquipmentAddNotify(equip)
123 151 return e
124 152 }
... ... @@ -158,9 +186,43 @@ func (m *RoleModel) UpLevel(exp int32) (int32, int32) {
158 186 return level, exp
159 187 }
160 188  
161   -func (m *RoleModel) Award(award common.IMapStringNum) common.IMapStringNum {
162   - m.AddItems(award)
163   - return award
  189 +func (m *RoleModel) _award(itemId string, count int32, param *pb.LogConf) int32 {
  190 + id, err := strconv.Atoi(itemId)
  191 + if err != nil {
  192 + return 0
  193 + }
  194 + itemData := csvdata.Get().TbItemData.Get(int32(id))
  195 + if itemData == nil {
  196 + return 0
  197 + }
  198 +
  199 + curType := itemData.MType
  200 +
  201 + switch curType {
  202 + case common.EquipType:
  203 + equip := &pb.Equipment{
  204 + Id: m.IncreEquipByKey(1),
  205 + RoleId: m.Data.Id,
  206 + TbId: int32(id - common.ItemTypeInterval),
  207 + Quality: 1,
  208 + }
  209 + m.AddEquip(equip, param)
  210 + default:
  211 + m.AddItem(itemId, count, param)
  212 + }
  213 + return count
  214 +}
  215 +
  216 +func (m *RoleModel) Award(award common.IMapStringNum, param *pb.LogConf) common.IMapStringNum {
  217 + reward := make(common.IMapStringNum)
  218 + for itemId, rcount := range award {
  219 + count := m._award(itemId, rcount, param)
  220 + if count > 0 {
  221 + reward[itemId] = count
  222 + }
  223 + }
  224 + m.Update()
  225 + return reward
164 226 }
165 227  
166 228 func (m *RoleModel) EquipmentRefer(equipId, heroId string, refer bool, pos int32) int32 {
... ...
1   -Subproject commit cfe0c1d6fd5d7bcd6b0d5543359fcf2117db4dc2
  1 +Subproject commit b1df9ce3812425edc2a4470022bed2416e3250e9
... ...