From 94db272d64b2343241c9ef7ac3caa9dc42c255a4 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Wed, 17 Aug 2022 10:38:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=AD=A6=E9=A6=86=E8=A7=A3?= =?UTF-8?q?=E9=94=81=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/martialhall/api_unlock.go | 70 ++++++++++ modules/martialhall/configure.go | 21 ++- modules/martialhall/modelMartialhall.go | 17 +++ pb/errorcode.pb.go | 12 +- pb/martialhall_msg.pb.go | 164 ++++++++++++++++++++++-- 5 files changed, 267 insertions(+), 17 deletions(-) create mode 100644 modules/martialhall/api_unlock.go diff --git a/modules/martialhall/api_unlock.go b/modules/martialhall/api_unlock.go new file mode 100644 index 000000000..5bbb94872 --- /dev/null +++ b/modules/martialhall/api_unlock.go @@ -0,0 +1,70 @@ +package martialhall + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" + + "google.golang.org/protobuf/proto" +) + +//参数校验 +func (this *apiComp) UnLockCheck(session comm.IUserSession, req *pb.MartialhallUnLockReq) (code pb.ErrorCode) { + + return +} + +///练功请求 +func (this *apiComp) UnLock(session comm.IUserSession, req *pb.MartialhallUnLockReq) (code pb.ErrorCode, data proto.Message) { + var ( + err error + mart *pb.DBMartialhall + mdata *cfg.Gamekungfu_unlockData + pillar *pb.DBPillar + filed string + ) + if mart, err = this.module.modelMartialhall.queryUserMartialhall(session.GetUserId()); err != nil { + code = pb.ErrorCode_DBError + return + } + if mdata, err = this.module.configure.getunlock(req.Pillar); err != nil { + code = pb.ErrorCode_ConfigNoFound + return + } + + switch req.Pillar { + case 1: + pillar = mart.Pillar1 + filed = "pillar1" + break + case 2: + pillar = mart.Pillar2 + filed = "pillar2" + break + case 3: + pillar = mart.Pillar3 + filed = "pillar3" + break + case 4: + pillar = mart.Pillar4 + filed = "pillar4" + break + case 5: + pillar = mart.Pillar5 + filed = "pillar5" + break + } + if pillar.Isunlock { + code = pb.ErrorCode_MartialhallUnlocked + return + } + pillar.Isunlock = true + if code = this.module.ConsumeRes(session, mdata.Consume, true); code != pb.ErrorCode_Success { + return + } + this.module.modelMartialhall.Change(session.GetUserId(), map[string]interface{}{ + filed: pillar, + }) + session.SendMsg(string(this.module.GetType()), "unlock", &pb.MartialhallUpgradeResp{Info: mart}) + return +} diff --git a/modules/martialhall/configure.go b/modules/martialhall/configure.go index 306e65cdf..ac0af004e 100644 --- a/modules/martialhall/configure.go +++ b/modules/martialhall/configure.go @@ -22,6 +22,7 @@ type configureComp struct { //组件初始化接口 func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { this.MCompConfigure.Init(service, module, comp, options) + this.module = module.(*Martialhall) this.LoadConfigure(game_kungfu_unlock, cfg.NewGamekungfu_unlock) this.LoadConfigure(game_kungfu_masterworker, cfg.NewGamekungfu_masterworker) return @@ -37,7 +38,25 @@ func (this *configureComp) getMasterworker(lv int32) (result *cfg.Gamekungfu_mas return } else { if result, ok = v.(*cfg.Gamekungfu_masterworker).GetDataMap()[lv]; !ok { - err = fmt.Errorf("not found:%s ", lv) + err = fmt.Errorf("not found:%d ", lv) + this.module.Errorln(err) + return + } + } + return +} + +func (this *configureComp) getunlock(pillar int32) (result *cfg.Gamekungfu_unlockData, err error) { + var ( + v interface{} + ok bool + ) + if v, err = this.GetConfigure(game_kungfu_unlock); err != nil { + this.module.Errorln(err) + return + } else { + if result, ok = v.(*cfg.Gamekungfu_unlock).GetDataMap()[pillar]; !ok { + err = fmt.Errorf("not found:%d ", pillar) this.module.Errorln(err) return } diff --git a/modules/martialhall/modelMartialhall.go b/modules/martialhall/modelMartialhall.go index 59c56a340..c94d8ac3b 100644 --- a/modules/martialhall/modelMartialhall.go +++ b/modules/martialhall/modelMartialhall.go @@ -7,6 +7,7 @@ import ( "go_dreamfactory/modules" "go_dreamfactory/pb" + "go.mongodb.org/mongo-driver/bson/primitive" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/x/bsonx" ) @@ -35,6 +36,22 @@ func (this *modelMartialhall) queryUserMartialhall(uid string) (result *pb.DBMar if err = this.Get(uid, result); err != nil && err != mgo.MongodbNil { this.module.Errorln(err) } + if err == mgo.MongodbNil { + result = &pb.DBMartialhall{ + Id: primitive.NewObjectID().Hex(), + Uid: uid, + Lv: 1, + Pillar1: &pb.DBPillar{}, + Pillar2: &pb.DBPillar{}, + Pillar3: &pb.DBPillar{}, + Pillar4: &pb.DBPillar{}, + Pillar5: &pb.DBPillar{}, + } + if err = this.Add(uid, result); err != nil { + this.module.Errorln(err) + return + } + } err = nil return } diff --git a/pb/errorcode.pb.go b/pb/errorcode.pb.go index 56f3ad204..d019bd9c4 100644 --- a/pb/errorcode.pb.go +++ b/pb/errorcode.pb.go @@ -142,9 +142,10 @@ const ( ErrorCode_PagodaLevlErr ErrorCode = 1901 // 挑战关卡数据不匹配 ErrorCode_PagodaGetRewardErr ErrorCode = 1902 // 重复领取 ErrorCode_PagodaConditionErr ErrorCode = 1903 // 条件不足 - // + // martialhall ErrorCode_MartialhallNotUnlocked ErrorCode = 2000 //没有解锁 ErrorCode_MartialhallInUse ErrorCode = 2001 //已经在使用 + ErrorCode_MartialhallUnlocked ErrorCode = 2002 //已解锁 ) // Enum value maps for ErrorCode. @@ -261,6 +262,7 @@ var ( 1903: "PagodaConditionErr", 2000: "MartialhallNotUnlocked", 2001: "MartialhallInUse", + 2002: "MartialhallUnlocked", } ErrorCode_value = map[string]int32{ "Success": 0, @@ -374,6 +376,7 @@ var ( "PagodaConditionErr": 1903, "MartialhallNotUnlocked": 2000, "MartialhallInUse": 2001, + "MartialhallUnlocked": 2002, } ) @@ -408,7 +411,7 @@ var File_errorcode_proto protoreflect.FileDescriptor var file_errorcode_proto_rawDesc = []byte{ 0x0a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2a, 0xbf, 0x12, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, + 0x6f, 0x2a, 0xd9, 0x12, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x10, 0x0a, 0x12, 0x1b, 0x0a, 0x17, 0x4e, 0x6f, 0x46, 0x69, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, @@ -556,8 +559,9 @@ var file_errorcode_proto_rawDesc = []byte{ 0x1b, 0x0a, 0x16, 0x4d, 0x61, 0x72, 0x74, 0x69, 0x61, 0x6c, 0x68, 0x61, 0x6c, 0x6c, 0x4e, 0x6f, 0x74, 0x55, 0x6e, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x10, 0xd0, 0x0f, 0x12, 0x15, 0x0a, 0x10, 0x4d, 0x61, 0x72, 0x74, 0x69, 0x61, 0x6c, 0x68, 0x61, 0x6c, 0x6c, 0x49, 0x6e, 0x55, 0x73, 0x65, - 0x10, 0xd1, 0x0f, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x10, 0xd1, 0x0f, 0x12, 0x18, 0x0a, 0x13, 0x4d, 0x61, 0x72, 0x74, 0x69, 0x61, 0x6c, 0x68, 0x61, + 0x6c, 0x6c, 0x55, 0x6e, 0x6c, 0x6f, 0x63, 0x6b, 0x65, 0x64, 0x10, 0xd2, 0x0f, 0x42, 0x06, 0x5a, + 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/pb/martialhall_msg.pb.go b/pb/martialhall_msg.pb.go index 932fc1c52..bf449770d 100644 --- a/pb/martialhall_msg.pb.go +++ b/pb/martialhall_msg.pb.go @@ -401,6 +401,110 @@ func (x *MartialhallUpgradeResp) GetInfo() *DBMartialhall { return nil } +///解锁 请求 +type MartialhallUnLockReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Pillar int32 `protobuf:"varint,1,opt,name=pillar,proto3" json:"pillar"` //柱子 +} + +func (x *MartialhallUnLockReq) Reset() { + *x = MartialhallUnLockReq{} + if protoimpl.UnsafeEnabled { + mi := &file_martialhall_martialhall_msg_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MartialhallUnLockReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MartialhallUnLockReq) ProtoMessage() {} + +func (x *MartialhallUnLockReq) ProtoReflect() protoreflect.Message { + mi := &file_martialhall_martialhall_msg_proto_msgTypes[8] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MartialhallUnLockReq.ProtoReflect.Descriptor instead. +func (*MartialhallUnLockReq) Descriptor() ([]byte, []int) { + return file_martialhall_martialhall_msg_proto_rawDescGZIP(), []int{8} +} + +func (x *MartialhallUnLockReq) GetPillar() int32 { + if x != nil { + return x.Pillar + } + return 0 +} + +///解锁 请求 回应 +type MartialhallUnLockResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Issucc bool `protobuf:"varint,1,opt,name=issucc,proto3" json:"issucc"` + Info *DBMartialhall `protobuf:"bytes,2,opt,name=info,proto3" json:"info"` +} + +func (x *MartialhallUnLockResp) Reset() { + *x = MartialhallUnLockResp{} + if protoimpl.UnsafeEnabled { + mi := &file_martialhall_martialhall_msg_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *MartialhallUnLockResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MartialhallUnLockResp) ProtoMessage() {} + +func (x *MartialhallUnLockResp) ProtoReflect() protoreflect.Message { + mi := &file_martialhall_martialhall_msg_proto_msgTypes[9] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use MartialhallUnLockResp.ProtoReflect.Descriptor instead. +func (*MartialhallUnLockResp) Descriptor() ([]byte, []int) { + return file_martialhall_martialhall_msg_proto_rawDescGZIP(), []int{9} +} + +func (x *MartialhallUnLockResp) GetIssucc() bool { + if x != nil { + return x.Issucc + } + return false +} + +func (x *MartialhallUnLockResp) GetInfo() *DBMartialhall { + if x != nil { + return x.Info + } + return nil +} + var File_martialhall_martialhall_msg_proto protoreflect.FileDescriptor var file_martialhall_martialhall_msg_proto_rawDesc = []byte{ @@ -433,8 +537,17 @@ var file_martialhall_martialhall_msg_proto_rawDesc = []byte{ 0x3c, 0x0a, 0x16, 0x4d, 0x61, 0x72, 0x74, 0x69, 0x61, 0x6c, 0x68, 0x61, 0x6c, 0x6c, 0x55, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x22, 0x0a, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x44, 0x42, 0x4d, 0x61, 0x72, 0x74, - 0x69, 0x61, 0x6c, 0x68, 0x61, 0x6c, 0x6c, 0x52, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x42, 0x06, 0x5a, - 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x69, 0x61, 0x6c, 0x68, 0x61, 0x6c, 0x6c, 0x52, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x22, 0x2e, 0x0a, + 0x14, 0x4d, 0x61, 0x72, 0x74, 0x69, 0x61, 0x6c, 0x68, 0x61, 0x6c, 0x6c, 0x55, 0x6e, 0x4c, 0x6f, + 0x63, 0x6b, 0x52, 0x65, 0x71, 0x12, 0x16, 0x0a, 0x06, 0x70, 0x69, 0x6c, 0x6c, 0x61, 0x72, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x70, 0x69, 0x6c, 0x6c, 0x61, 0x72, 0x22, 0x53, 0x0a, + 0x15, 0x4d, 0x61, 0x72, 0x74, 0x69, 0x61, 0x6c, 0x68, 0x61, 0x6c, 0x6c, 0x55, 0x6e, 0x4c, 0x6f, + 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x12, 0x16, 0x0a, 0x06, 0x69, 0x73, 0x73, 0x75, 0x63, 0x63, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x06, 0x69, 0x73, 0x73, 0x75, 0x63, 0x63, 0x12, 0x22, + 0x0a, 0x04, 0x69, 0x6e, 0x66, 0x6f, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x44, + 0x42, 0x4d, 0x61, 0x72, 0x74, 0x69, 0x61, 0x6c, 0x68, 0x61, 0x6c, 0x6c, 0x52, 0x04, 0x69, 0x6e, + 0x66, 0x6f, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( @@ -449,7 +562,7 @@ func file_martialhall_martialhall_msg_proto_rawDescGZIP() []byte { return file_martialhall_martialhall_msg_proto_rawDescData } -var file_martialhall_martialhall_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 8) +var file_martialhall_martialhall_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 10) var file_martialhall_martialhall_msg_proto_goTypes = []interface{}{ (*MartialhallInfoReq)(nil), // 0: MartialhallInfoReq (*MartialhallInfoResp)(nil), // 1: MartialhallInfoResp @@ -459,16 +572,19 @@ var file_martialhall_martialhall_msg_proto_goTypes = []interface{}{ (*MartialhallReceiveResp)(nil), // 5: MartialhallReceiveResp (*MartialhallUpgradeReq)(nil), // 6: MartialhallUpgradeReq (*MartialhallUpgradeResp)(nil), // 7: MartialhallUpgradeResp - (*DBMartialhall)(nil), // 8: DBMartialhall + (*MartialhallUnLockReq)(nil), // 8: MartialhallUnLockReq + (*MartialhallUnLockResp)(nil), // 9: MartialhallUnLockResp + (*DBMartialhall)(nil), // 10: DBMartialhall } var file_martialhall_martialhall_msg_proto_depIdxs = []int32{ - 8, // 0: MartialhallInfoResp.info:type_name -> DBMartialhall - 8, // 1: MartialhallUpgradeResp.info:type_name -> DBMartialhall - 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 - 2, // [2:2] is the sub-list for extension extendee - 0, // [0:2] is the sub-list for field type_name + 10, // 0: MartialhallInfoResp.info:type_name -> DBMartialhall + 10, // 1: MartialhallUpgradeResp.info:type_name -> DBMartialhall + 10, // 2: MartialhallUnLockResp.info:type_name -> DBMartialhall + 3, // [3:3] is the sub-list for method output_type + 3, // [3:3] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name } func init() { file_martialhall_martialhall_msg_proto_init() } @@ -574,6 +690,30 @@ func file_martialhall_martialhall_msg_proto_init() { return nil } } + file_martialhall_martialhall_msg_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MartialhallUnLockReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_martialhall_martialhall_msg_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MartialhallUnLockResp); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -581,7 +721,7 @@ func file_martialhall_martialhall_msg_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_martialhall_martialhall_msg_proto_rawDesc, NumEnums: 0, - NumMessages: 8, + NumMessages: 10, NumExtensions: 0, NumServices: 0, },