From a2d4f770378e7a075f13d2bd8d4addd0fb483078 Mon Sep 17 00:00:00 2001 From: zqj <582132116@qq.com> Date: Mon, 6 Jun 2022 14:23:46 +0800 Subject: [PATCH] fix: 首次通关记录到数据库 --- cmd/gameserver/action/RoleAction.go | 33 +++++++++++++++++---------------- cmd/test/action/TestAction.go | 4 ++++ cmd/test/main.go | 3 ++- conf/conf.yml | 5 +++++ models/RoleLog.go | 1 + models/role.go | 4 ++-- models/role_test.go | 7 +++++++ pb/models.pb.go | 40 ++++++++++++++++++++-------------------- 8 files changed, 58 insertions(+), 39 deletions(-) create mode 100644 models/RoleLog.go diff --git a/cmd/gameserver/action/RoleAction.go b/cmd/gameserver/action/RoleAction.go index 322bd8b..28d28af 100644 --- a/cmd/gameserver/action/RoleAction.go +++ b/cmd/gameserver/action/RoleAction.go @@ -186,7 +186,7 @@ func RoleEndBattleRpc(role *models.RoleModel, msg components.IMessage) (int32, i return 1, nil } chapterInfo := csvdata.Get().TbRogueChapter.Get(req.ChapterId) - chapterCount, first := role.Role.PassChapters[req.ChapterId] + chapterCount, first := role.Role.Passchapters[req.ChapterId] carbonInfo, ok := chapterInfo.Carbons[req.CarbonId] if !ok { logger.Error("carbonInfo not exists") @@ -202,14 +202,14 @@ func RoleEndBattleRpc(role *models.RoleModel, msg components.IMessage) (int32, i reward := make(common.IMapStringNum) if !first { - role.Role.PassChapters[req.ChapterId] = 1 + role.Role.Passchapters[req.ChapterId] = 1 for k, v := range common.StringToMapNum(carbonInfo.FirstAward) { reward[k] = v } } else { - role.Role.PassChapters[req.ChapterId] = chapterCount + 1 - role.UpdateProperty("pass_chapters", role.Role.PassChapters, false) + role.Role.Passchapters[req.ChapterId] = chapterCount + 1 } + role.SetProperty("passchapters", role.Role.Passchapters) for k, v := range common.StringToMapNum(carbonInfo.NormalAward) { rv, ok := reward[k] @@ -232,15 +232,20 @@ func RoleEndBattleRpc(role *models.RoleModel, msg components.IMessage) (int32, i level, exp := role.UpLevel(amount) role.UpdateProperties(map[string]interface{}{"level": level, "exp": exp}, true) + rsp := &pb.RoleEndBattleRsp{ + RoleLevel: level, + RoleExp: exp, + } + //team exp - heros := make([]*pb.Hero, 4) + heros := make([]*pb.Hero, 3) t := team.(*models.TeamModel).Team h1, ok := role.Heros[t.HeroId1] if ok { level, exp = h1.(*models.HeroModel).UpLevel(amount) h1.SetProperty("level", level) h1.SetProperty("exp", exp) - heros = append(heros, h1.(*models.HeroModel).Hero) + heros[0] = h1.(*models.HeroModel).Hero } h2, ok := role.Heros[t.HeroId2] @@ -248,7 +253,7 @@ func RoleEndBattleRpc(role *models.RoleModel, msg components.IMessage) (int32, i level, exp = h2.(*models.HeroModel).UpLevel(amount) h2.SetProperty("level", level) h2.SetProperty("exp", exp) - heros = append(heros, h2.(*models.HeroModel).Hero) + heros[1] = h2.(*models.HeroModel).Hero } h3, ok := role.Heros[t.HeroId3] @@ -256,16 +261,12 @@ func RoleEndBattleRpc(role *models.RoleModel, msg components.IMessage) (int32, i level, exp = h3.(*models.HeroModel).UpLevel(amount) h3.SetProperty("level", level) h3.SetProperty("exp", exp) - heros = append(heros, h3.(*models.HeroModel).Hero) + heros[2] = h3.(*models.HeroModel).Hero } - rsp := &pb.RoleEndBattleRsp{ - RoleLevel: level, - RoleExp: exp, - RoleExpamount: amount, - Pass: req.Pass, - Reward: common.MapNumToString(reward), - Hero: heros, - } + rsp.RoleExpamount = amount + rsp.Pass = req.Pass + rsp.Reward = common.MapNumToString(reward) + rsp.Hero = heros return 0, rsp } diff --git a/cmd/test/action/TestAction.go b/cmd/test/action/TestAction.go index a9c3613..e189d22 100644 --- a/cmd/test/action/TestAction.go +++ b/cmd/test/action/TestAction.go @@ -34,6 +34,9 @@ func RoleUpdatePropertyRsp(role *models.RoleTestModel, msg components.IMessage) func RoleUpdateItemsRsp(role *models.RoleTestModel, msg components.IMessage) { } +func RoleUpdateChangeRsp(role *models.RoleTestModel, msg components.IMessage) { +} + func RoleClearItemsRsp(role *models.RoleTestModel, msg components.IMessage) { } @@ -46,6 +49,7 @@ func RoleEndBattleRsp(role *models.RoleTestModel, msg components.IMessage) { logger.Error("rsp err: %v", err) return } + logger.Debug(rsp.Reward) } func EquipmentDelRsp(role *models.RoleTestModel, msg components.IMessage) { diff --git a/cmd/test/main.go b/cmd/test/main.go index 7fcdfe0..96af54f 100644 --- a/cmd/test/main.go +++ b/cmd/test/main.go @@ -12,12 +12,13 @@ func main() { return } - tc.Login("1") + tc.Login("90007") pp := &pb.RoleEndBattleReq{ ChapterId: 1, CarbonId: 1, Pass: true, + TeamId: "10000011000002", } time.Sleep(2 * time.Second) diff --git a/conf/conf.yml b/conf/conf.yml index 533a4c7..057b915 100644 --- a/conf/conf.yml +++ b/conf/conf.yml @@ -64,6 +64,11 @@ logconf: maxdays: -1 append: true permit: "0660" + +test_client: + ip: "192.168.0.100" + port: 8849 + count: 1 # Conn: # net: "tcp" # addr: "127.0.0.1" diff --git a/models/RoleLog.go b/models/RoleLog.go new file mode 100644 index 0000000..2640e7f --- /dev/null +++ b/models/RoleLog.go @@ -0,0 +1 @@ +package models diff --git a/models/role.go b/models/role.go index 0cd5b18..68943b3 100644 --- a/models/role.go +++ b/models/role.go @@ -24,7 +24,7 @@ type RoleModel struct { } func RoleExistByUid(uid string) *RoleModel { - data := &pb.Role{Uid: uid, Incres: make(map[string]uint32), PassChapters: make(map[int32]int32)} + data := &pb.Role{Uid: uid, Incres: make(map[string]uint32), Passchapters: make(map[int32]int32)} if err := mongoproxy.FindOne(mongoproxy.GetCollName(data), mongoproxy.GetBsonM("uid", uid), data); err != nil { logger.Error("Role not exist err: %v", err) @@ -46,7 +46,7 @@ func RoleExistByUid(uid string) *RoleModel { } func NewRole(id string) *RoleModel { - data := &pb.Role{Id: id, Incres: make(map[string]uint32), PassChapters: make(map[int32]int32)} + data := &pb.Role{Id: id, Incres: make(map[string]uint32), Passchapters: make(map[int32]int32)} m := &RoleModel{ ISchema: NewSchema(id, data), Role: data, diff --git a/models/role_test.go b/models/role_test.go index cdf7348..4c3e4e0 100644 --- a/models/role_test.go +++ b/models/role_test.go @@ -126,3 +126,10 @@ func TestRoleModel_IncreByKey(t *testing.T) { fmt.Println(ites) } + +func TestSchema_Create(t *testing.T) { + _ = mongoproxy.ConnectMongo(common.GlobalConf.GameConf.MongoConf, common.GlobalConf.GameConf.ID) + role := NewRole("") + s := role.ISchema.(*Schema) + logger.Debug(s.protoIndex) +} diff --git a/pb/models.pb.go b/pb/models.pb.go index 7dc164e..1e4d926 100644 --- a/pb/models.pb.go +++ b/pb/models.pb.go @@ -493,7 +493,7 @@ type Role struct { Otherlimit uint32 `protobuf:"varint,18,opt,name=otherlimit,proto3" json:"otherlimit,omitempty"` Jewelrylimit uint32 `protobuf:"varint,19,opt,name=jewelrylimit,proto3" json:"jewelrylimit,omitempty"` Materiallimit uint32 `protobuf:"varint,20,opt,name=materiallimit,proto3" json:"materiallimit,omitempty"` - 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"` // 通关记录 + 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"` // 通关记录 } func (x *Role) Reset() { @@ -654,9 +654,9 @@ func (x *Role) GetMateriallimit() uint32 { return 0 } -func (x *Role) GetPassChapters() map[int32]int32 { +func (x *Role) GetPasschapters() map[int32]int32 { if x != nil { - return x.PassChapters + return x.Passchapters } return nil } @@ -708,7 +708,7 @@ var file_models_proto_rawDesc = []byte{ 0x07, 0x68, 0x65, 0x72, 0x6f, 0x49, 0x64, 0x33, 0x22, 0x2f, 0x0a, 0x09, 0x49, 0x6e, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x76, 0x61, 0x6c, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x76, 0x61, 0x6c, 0x22, 0x9a, 0x05, 0x0a, 0x04, 0x52, 0x6f, + 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x76, 0x61, 0x6c, 0x22, 0x99, 0x05, 0x0a, 0x04, 0x52, 0x6f, 0x6c, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 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{ 0x0d, 0x52, 0x0c, 0x6a, 0x65, 0x77, 0x65, 0x6c, 0x72, 0x79, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x24, 0x0a, 0x0d, 0x6d, 0x61, 0x74, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x18, 0x14, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0d, 0x6d, 0x61, 0x74, 0x65, 0x72, 0x69, 0x61, 0x6c, - 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x43, 0x0a, 0x0d, 0x70, 0x61, 0x73, 0x73, 0x5f, 0x63, 0x68, - 0x61, 0x70, 0x74, 0x65, 0x72, 0x73, 0x18, 0x15, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x6d, - 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2e, 0x52, 0x6f, 0x6c, 0x65, 0x2e, 0x50, 0x61, 0x73, 0x73, 0x43, - 0x68, 0x61, 0x70, 0x74, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0c, 0x70, 0x61, - 0x73, 0x73, 0x43, 0x68, 0x61, 0x70, 0x74, 0x65, 0x72, 0x73, 0x1a, 0x39, 0x0a, 0x0b, 0x49, 0x6e, - 0x63, 0x72, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, - 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x3f, 0x0a, 0x11, 0x50, 0x61, 0x73, 0x73, 0x43, 0x68, 0x61, - 0x70, 0x74, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, - 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, - 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, - 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6c, 0x69, 0x6d, 0x69, 0x74, 0x12, 0x42, 0x0a, 0x0c, 0x70, 0x61, 0x73, 0x73, 0x63, 0x68, 0x61, + 0x70, 0x74, 0x65, 0x72, 0x73, 0x18, 0x15, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x6d, 0x6f, + 0x64, 0x65, 0x6c, 0x73, 0x2e, 0x52, 0x6f, 0x6c, 0x65, 0x2e, 0x50, 0x61, 0x73, 0x73, 0x63, 0x68, + 0x61, 0x70, 0x74, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0c, 0x70, 0x61, 0x73, + 0x73, 0x63, 0x68, 0x61, 0x70, 0x74, 0x65, 0x72, 0x73, 0x1a, 0x39, 0x0a, 0x0b, 0x49, 0x6e, 0x63, + 0x72, 0x65, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x3f, 0x0a, 0x11, 0x50, 0x61, 0x73, 0x73, 0x63, 0x68, 0x61, 0x70, + 0x74, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x62, 0x3b, 0x70, + 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -776,11 +776,11 @@ var file_models_proto_goTypes = []interface{}{ (*Increment)(nil), // 5: models.Increment (*Role)(nil), // 6: models.Role nil, // 7: models.Role.IncresEntry - nil, // 8: models.Role.PassChaptersEntry + nil, // 8: models.Role.PasschaptersEntry } var file_models_proto_depIdxs = []int32{ 7, // 0: models.Role.incres:type_name -> models.Role.IncresEntry - 8, // 1: models.Role.pass_chapters:type_name -> models.Role.PassChaptersEntry + 8, // 1: models.Role.passchapters:type_name -> models.Role.PasschaptersEntry 2, // [2:2] is the sub-list for method output_type 2, // [2:2] is the sub-list for method input_type 2, // [2:2] is the sub-list for extension type_name -- libgit2 0.21.2