Commit a2d4f770378e7a075f13d2bd8d4addd0fb483078
1 parent
4e75670c
fix: 首次通关记录到数据库
Showing
8 changed files
with
58 additions
and
39 deletions
 
Show diff stats
cmd/gameserver/action/RoleAction.go
| ... | ... | @@ -186,7 +186,7 @@ func RoleEndBattleRpc(role *models.RoleModel, msg components.IMessage) (int32, i | 
| 186 | 186 | return 1, nil | 
| 187 | 187 | } | 
| 188 | 188 | chapterInfo := csvdata.Get().TbRogueChapter.Get(req.ChapterId) | 
| 189 | - chapterCount, first := role.Role.PassChapters[req.ChapterId] | |
| 189 | + chapterCount, first := role.Role.Passchapters[req.ChapterId] | |
| 190 | 190 | carbonInfo, ok := chapterInfo.Carbons[req.CarbonId] | 
| 191 | 191 | if !ok { | 
| 192 | 192 | logger.Error("carbonInfo not exists") | 
| ... | ... | @@ -202,14 +202,14 @@ func RoleEndBattleRpc(role *models.RoleModel, msg components.IMessage) (int32, i | 
| 202 | 202 | |
| 203 | 203 | reward := make(common.IMapStringNum) | 
| 204 | 204 | if !first { | 
| 205 | - role.Role.PassChapters[req.ChapterId] = 1 | |
| 205 | + role.Role.Passchapters[req.ChapterId] = 1 | |
| 206 | 206 | for k, v := range common.StringToMapNum(carbonInfo.FirstAward) { | 
| 207 | 207 | reward[k] = v | 
| 208 | 208 | } | 
| 209 | 209 | } else { | 
| 210 | - role.Role.PassChapters[req.ChapterId] = chapterCount + 1 | |
| 211 | - role.UpdateProperty("pass_chapters", role.Role.PassChapters, false) | |
| 210 | + role.Role.Passchapters[req.ChapterId] = chapterCount + 1 | |
| 212 | 211 | } | 
| 212 | + role.SetProperty("passchapters", role.Role.Passchapters) | |
| 213 | 213 | |
| 214 | 214 | for k, v := range common.StringToMapNum(carbonInfo.NormalAward) { | 
| 215 | 215 | rv, ok := reward[k] | 
| ... | ... | @@ -232,15 +232,20 @@ func RoleEndBattleRpc(role *models.RoleModel, msg components.IMessage) (int32, i | 
| 232 | 232 | level, exp := role.UpLevel(amount) | 
| 233 | 233 | role.UpdateProperties(map[string]interface{}{"level": level, "exp": exp}, true) | 
| 234 | 234 | |
| 235 | + rsp := &pb.RoleEndBattleRsp{ | |
| 236 | + RoleLevel: level, | |
| 237 | + RoleExp: exp, | |
| 238 | + } | |
| 239 | + | |
| 235 | 240 | //team exp | 
| 236 | - heros := make([]*pb.Hero, 4) | |
| 241 | + heros := make([]*pb.Hero, 3) | |
| 237 | 242 | t := team.(*models.TeamModel).Team | 
| 238 | 243 | h1, ok := role.Heros[t.HeroId1] | 
| 239 | 244 | if ok { | 
| 240 | 245 | level, exp = h1.(*models.HeroModel).UpLevel(amount) | 
| 241 | 246 | h1.SetProperty("level", level) | 
| 242 | 247 | h1.SetProperty("exp", exp) | 
| 243 | - heros = append(heros, h1.(*models.HeroModel).Hero) | |
| 248 | + heros[0] = h1.(*models.HeroModel).Hero | |
| 244 | 249 | } | 
| 245 | 250 | |
| 246 | 251 | h2, ok := role.Heros[t.HeroId2] | 
| ... | ... | @@ -248,7 +253,7 @@ func RoleEndBattleRpc(role *models.RoleModel, msg components.IMessage) (int32, i | 
| 248 | 253 | level, exp = h2.(*models.HeroModel).UpLevel(amount) | 
| 249 | 254 | h2.SetProperty("level", level) | 
| 250 | 255 | h2.SetProperty("exp", exp) | 
| 251 | - heros = append(heros, h2.(*models.HeroModel).Hero) | |
| 256 | + heros[1] = h2.(*models.HeroModel).Hero | |
| 252 | 257 | } | 
| 253 | 258 | |
| 254 | 259 | h3, ok := role.Heros[t.HeroId3] | 
| ... | ... | @@ -256,16 +261,12 @@ func RoleEndBattleRpc(role *models.RoleModel, msg components.IMessage) (int32, i | 
| 256 | 261 | level, exp = h3.(*models.HeroModel).UpLevel(amount) | 
| 257 | 262 | h3.SetProperty("level", level) | 
| 258 | 263 | h3.SetProperty("exp", exp) | 
| 259 | - heros = append(heros, h3.(*models.HeroModel).Hero) | |
| 264 | + heros[2] = h3.(*models.HeroModel).Hero | |
| 260 | 265 | } | 
| 261 | 266 | |
| 262 | - rsp := &pb.RoleEndBattleRsp{ | |
| 263 | - RoleLevel: level, | |
| 264 | - RoleExp: exp, | |
| 265 | - RoleExpamount: amount, | |
| 266 | - Pass: req.Pass, | |
| 267 | - Reward: common.MapNumToString(reward), | |
| 268 | - Hero: heros, | |
| 269 | - } | |
| 267 | + rsp.RoleExpamount = amount | |
| 268 | + rsp.Pass = req.Pass | |
| 269 | + rsp.Reward = common.MapNumToString(reward) | |
| 270 | + rsp.Hero = heros | |
| 270 | 271 | return 0, rsp | 
| 271 | 272 | } | ... | ... | 
cmd/test/action/TestAction.go
| ... | ... | @@ -34,6 +34,9 @@ func RoleUpdatePropertyRsp(role *models.RoleTestModel, msg components.IMessage) | 
| 34 | 34 | func RoleUpdateItemsRsp(role *models.RoleTestModel, msg components.IMessage) { | 
| 35 | 35 | } | 
| 36 | 36 | |
| 37 | +func RoleUpdateChangeRsp(role *models.RoleTestModel, msg components.IMessage) { | |
| 38 | +} | |
| 39 | + | |
| 37 | 40 | func RoleClearItemsRsp(role *models.RoleTestModel, msg components.IMessage) { | 
| 38 | 41 | } | 
| 39 | 42 | |
| ... | ... | @@ -46,6 +49,7 @@ func RoleEndBattleRsp(role *models.RoleTestModel, msg components.IMessage) { | 
| 46 | 49 | logger.Error("rsp err: %v", err) | 
| 47 | 50 | return | 
| 48 | 51 | } | 
| 52 | + logger.Debug(rsp.Reward) | |
| 49 | 53 | } | 
| 50 | 54 | |
| 51 | 55 | func EquipmentDelRsp(role *models.RoleTestModel, msg components.IMessage) { | ... | ... | 
cmd/test/main.go
conf/conf.yml
| ... | ... | @@ -0,0 +1 @@ | 
| 1 | +package models | ... | ... | 
models/role.go
| ... | ... | @@ -24,7 +24,7 @@ type RoleModel struct { | 
| 24 | 24 | } | 
| 25 | 25 | |
| 26 | 26 | func RoleExistByUid(uid string) *RoleModel { | 
| 27 | - data := &pb.Role{Uid: uid, Incres: make(map[string]uint32), PassChapters: make(map[int32]int32)} | |
| 27 | + data := &pb.Role{Uid: uid, Incres: make(map[string]uint32), Passchapters: make(map[int32]int32)} | |
| 28 | 28 | |
| 29 | 29 | if err := mongoproxy.FindOne(mongoproxy.GetCollName(data), mongoproxy.GetBsonM("uid", uid), data); err != nil { | 
| 30 | 30 | logger.Error("Role not exist err: %v", err) | 
| ... | ... | @@ -46,7 +46,7 @@ func RoleExistByUid(uid string) *RoleModel { | 
| 46 | 46 | } | 
| 47 | 47 | |
| 48 | 48 | func NewRole(id string) *RoleModel { | 
| 49 | - data := &pb.Role{Id: id, Incres: make(map[string]uint32), PassChapters: make(map[int32]int32)} | |
| 49 | + data := &pb.Role{Id: id, Incres: make(map[string]uint32), Passchapters: make(map[int32]int32)} | |
| 50 | 50 | m := &RoleModel{ | 
| 51 | 51 | ISchema: NewSchema(id, data), | 
| 52 | 52 | Role: data, | ... | ... | 
models/role_test.go
| ... | ... | @@ -126,3 +126,10 @@ func TestRoleModel_IncreByKey(t *testing.T) { | 
| 126 | 126 | fmt.Println(ites) | 
| 127 | 127 | |
| 128 | 128 | } | 
| 129 | + | |
| 130 | +func TestSchema_Create(t *testing.T) { | |
| 131 | + _ = mongoproxy.ConnectMongo(common.GlobalConf.GameConf.MongoConf, common.GlobalConf.GameConf.ID) | |
| 132 | + role := NewRole("") | |
| 133 | + s := role.ISchema.(*Schema) | |
| 134 | + logger.Debug(s.protoIndex) | |
| 135 | +} | ... | ... | 
pb/models.pb.go
| ... | ... | @@ -493,7 +493,7 @@ type Role struct { | 
| 493 | 493 | Otherlimit uint32 `protobuf:"varint,18,opt,name=otherlimit,proto3" json:"otherlimit,omitempty"` | 
| 494 | 494 | Jewelrylimit uint32 `protobuf:"varint,19,opt,name=jewelrylimit,proto3" json:"jewelrylimit,omitempty"` | 
| 495 | 495 | Materiallimit uint32 `protobuf:"varint,20,opt,name=materiallimit,proto3" json:"materiallimit,omitempty"` | 
| 496 | - PassChapters map[int32]int32 `protobuf:"bytes,21,rep,name=pass_chapters,json=passChapters,proto3" json:"pass_chapters,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // 通关记录 | |
| 496 | + Passchapters map[int32]int32 `protobuf:"bytes,21,rep,name=passchapters,proto3" json:"passchapters,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // 通关记录 | |
| 497 | 497 | } | 
| 498 | 498 | |
| 499 | 499 | func (x *Role) Reset() { | 
| ... | ... | @@ -654,9 +654,9 @@ func (x *Role) GetMateriallimit() uint32 { | 
| 654 | 654 | return 0 | 
| 655 | 655 | } | 
| 656 | 656 | |
| 657 | -func (x *Role) GetPassChapters() map[int32]int32 { | |
| 657 | +func (x *Role) GetPasschapters() map[int32]int32 { | |
| 658 | 658 | if x != nil { | 
| 659 | - return x.PassChapters | |
| 659 | + return x.Passchapters | |
| 660 | 660 | } | 
| 661 | 661 | return nil | 
| 662 | 662 | } | 
| ... | ... | @@ -708,7 +708,7 @@ var file_models_proto_rawDesc = []byte{ | 
| 708 | 708 | 0x07, 0x68, 0x65, 0x72, 0x6f, 0x49, 0x64, 0x33, 0x22, 0x2f, 0x0a, 0x09, 0x49, 0x6e, 0x63, 0x72, | 
| 709 | 709 | 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, | 
| 710 | 710 | 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x76, 0x61, 0x6c, 0x18, 0x02, | 
| 711 | - 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x76, 0x61, 0x6c, 0x22, 0x9a, 0x05, 0x0a, 0x04, 0x52, 0x6f, | |
| 711 | + 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x76, 0x61, 0x6c, 0x22, 0x99, 0x05, 0x0a, 0x04, 0x52, 0x6f, | |
| 712 | 712 | 0x6c, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, | 
| 713 | 713 | 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, | 
| 714 | 714 | 0x03, 0x75, 0x69, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x64, 0x65, 0x76, 0x69, 0x63, 0x65, 0x18, 0x03, | 
| ... | ... | @@ -738,20 +738,20 @@ var file_models_proto_rawDesc = []byte{ | 
| 738 | 738 | 0x0d, 0x52, 0x0c, 0x6a, 0x65, 0x77, 0x65, 0x6c, 0x72, 0x79, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x12, | 
| 739 | 739 | 0x24, 0x0a, 0x0d, 0x6d, 0x61, 0x74, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x6c, 0x69, 0x6d, 0x69, 0x74, | 
| 740 | 740 | 0x18, 0x14, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0d, 0x6d, 0x61, 0x74, 0x65, 0x72, 0x69, 0x61, 0x6c, | 
| 741 | - 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x43, 0x0a, 0x0d, 0x70, 0x61, 0x73, 0x73, 0x5f, 0x63, 0x68, | |
| 742 | - 0x61, 0x70, 0x74, 0x65, 0x72, 0x73, 0x18, 0x15, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x6d, | |
| 743 | - 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2e, 0x52, 0x6f, 0x6c, 0x65, 0x2e, 0x50, 0x61, 0x73, 0x73, 0x43, | |
| 744 | - 0x68, 0x61, 0x70, 0x74, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0c, 0x70, 0x61, | |
| 745 | - 0x73, 0x73, 0x43, 0x68, 0x61, 0x70, 0x74, 0x65, 0x72, 0x73, 0x1a, 0x39, 0x0a, 0x0b, 0x49, 0x6e, | |
| 746 | - 0x63, 0x72, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, | |
| 747 | - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, | |
| 748 | - 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, | |
| 749 | - 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x3f, 0x0a, 0x11, 0x50, 0x61, 0x73, 0x73, 0x43, 0x68, 0x61, | |
| 750 | - 0x70, 0x74, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, | |
| 751 | - 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, | |
| 752 | - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, | |
| 753 | - 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, | |
| 754 | - 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, | |
| 741 | + 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x42, 0x0a, 0x0c, 0x70, 0x61, 0x73, 0x73, 0x63, 0x68, 0x61, | |
| 742 | + 0x70, 0x74, 0x65, 0x72, 0x73, 0x18, 0x15, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x6d, 0x6f, | |
| 743 | + 0x64, 0x65, 0x6c, 0x73, 0x2e, 0x52, 0x6f, 0x6c, 0x65, 0x2e, 0x50, 0x61, 0x73, 0x73, 0x63, 0x68, | |
| 744 | + 0x61, 0x70, 0x74, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0c, 0x70, 0x61, 0x73, | |
| 745 | + 0x73, 0x63, 0x68, 0x61, 0x70, 0x74, 0x65, 0x72, 0x73, 0x1a, 0x39, 0x0a, 0x0b, 0x49, 0x6e, 0x63, | |
| 746 | + 0x72, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, | |
| 747 | + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, | |
| 748 | + 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, | |
| 749 | + 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x3f, 0x0a, 0x11, 0x50, 0x61, 0x73, 0x73, 0x63, 0x68, 0x61, 0x70, | |
| 750 | + 0x74, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, | |
| 751 | + 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, | |
| 752 | + 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, | |
| 753 | + 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, 0x70, | |
| 754 | + 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, | |
| 755 | 755 | } | 
| 756 | 756 | |
| 757 | 757 | var ( | 
| ... | ... | @@ -776,11 +776,11 @@ var file_models_proto_goTypes = []interface{}{ | 
| 776 | 776 | (*Increment)(nil), // 5: models.Increment | 
| 777 | 777 | (*Role)(nil), // 6: models.Role | 
| 778 | 778 | nil, // 7: models.Role.IncresEntry | 
| 779 | - nil, // 8: models.Role.PassChaptersEntry | |
| 779 | + nil, // 8: models.Role.PasschaptersEntry | |
| 780 | 780 | } | 
| 781 | 781 | var file_models_proto_depIdxs = []int32{ | 
| 782 | 782 | 7, // 0: models.Role.incres:type_name -> models.Role.IncresEntry | 
| 783 | - 8, // 1: models.Role.pass_chapters:type_name -> models.Role.PassChaptersEntry | |
| 783 | + 8, // 1: models.Role.passchapters:type_name -> models.Role.PasschaptersEntry | |
| 784 | 784 | 2, // [2:2] is the sub-list for method output_type | 
| 785 | 785 | 2, // [2:2] is the sub-list for method input_type | 
| 786 | 786 | 2, // [2:2] is the sub-list for extension type_name | ... | ... |