From 19c7bfdb84de9e231f469da6ef79fe81530466e3 Mon Sep 17 00:00:00 2001 From: zhaocy Date: Tue, 19 Jul 2022 16:23:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=A1=E7=89=8C=E6=94=BB=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/robot/robot.go | 1 - cmd/robot/task.go | 11 ++- modules/task/api.go | 1 + modules/task/api_strategy.go | 39 +++++++++ modules/task/model_task.go | 50 +++++++++--- modules/task/module.go | 5 +- pb/errorcode.pb.go | 10 ++- pb/proto/errorcode.proto | 1 + pb/proto/task/task_msg.proto | 9 +++ pb/task_msg.pb.go | 153 ++++++++++++++++++++++++++++++++--- 10 files changed, 247 insertions(+), 33 deletions(-) create mode 100644 modules/task/api_strategy.go diff --git a/cmd/robot/robot.go b/cmd/robot/robot.go index 6922be61c..8b23f81b4 100644 --- a/cmd/robot/robot.go +++ b/cmd/robot/robot.go @@ -216,7 +216,6 @@ func (r *Robot) handleRsp(id string) { zlog.Fatalf("unmarshal err:%v", err) } - zlog.Debugf("1 %v.%v", msg.MainType, msg.SubType) uuid, _ := r.findTestCase(msg) if uuid == "" { uuid = id diff --git a/cmd/robot/task.go b/cmd/robot/task.go index 39984cb1c..e6020d0c4 100644 --- a/cmd/robot/task.go +++ b/cmd/robot/task.go @@ -29,7 +29,7 @@ var ( fmt.Printf("%v \n", v) } }, - enabled: true, + // enabled: true, next: func(robot *Robot, rsp proto.Message) { tcs := []*TestCase{} if v, ok := rsp.(*pb.TaskListResp); ok { @@ -75,6 +75,15 @@ var ( }, rsp: &pb.TaskActiveReceiveResp{}, // enabled: true, + }, { + desc: "卡牌攻略", + mainType: string(comm.ModuleTask), + subType: task.TaskSubTypeStrategy, + req: &pb.TaskDoStrategyReq{ + HeroCfgId: 13001, + }, + rsp: &pb.TaskDoStrategyResp{}, + enabled: true, }, } ) diff --git a/modules/task/api.go b/modules/task/api.go index 557faf09e..78e35d5b2 100644 --- a/modules/task/api.go +++ b/modules/task/api.go @@ -10,6 +10,7 @@ const ( TaskSubTypeReceive = "receive" //领取 TaskSubTypeActiveList = "activelist" //活跃度列表 TaskSubTypeActiveReceive = "activereceive" //活跃度领取 + TaskSubTypeStrategy = "strategy" //卡牌攻略 ) type apiComp struct { diff --git a/modules/task/api_strategy.go b/modules/task/api_strategy.go new file mode 100644 index 000000000..2bb90b51e --- /dev/null +++ b/modules/task/api_strategy.go @@ -0,0 +1,39 @@ +package task + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" + + "google.golang.org/protobuf/proto" +) + +//卡牌攻略 +func (this *apiComp) StrategyCheck(session comm.IUserSession, req *pb.TaskDoStrategyReq) (code pb.ErrorCode) { + if req.HeroCfgId == 0 { + code = pb.ErrorCode_ReqParameterError + } + return +} + +//进入卡牌攻略 +func (this *apiComp) Strategy(session comm.IUserSession, req *pb.TaskDoStrategyReq) (code pb.ErrorCode, data proto.Message) { + if code = this.StrategyCheck(session, req); code != pb.ErrorCode_Success { + return + } + + resp := &pb.TaskDoStrategyResp{} + + taskIds, err := this.moduleTask.modelTask.inStrategy(session.GetUserId(), req.HeroCfgId) + if err != nil { + code = pb.ErrorCode_SystemError + return + } + + resp.TaskIds = taskIds + + err = session.SendMsg(string(this.moduleTask.GetType()), TaskSubTypeStrategy, resp) + if err != nil { + code = pb.ErrorCode_SystemError + } + return +} diff --git a/modules/task/model_task.go b/modules/task/model_task.go index 5fbd16fb9..9ff88465d 100644 --- a/modules/task/model_task.go +++ b/modules/task/model_task.go @@ -43,10 +43,6 @@ func (this *ModelTask) getTaskList(uid string, taskTag comm.TaskTag) (list []*pb //初始化任务 func (this *ModelTask) initTaskByTag(uid string, taskTag comm.TaskTag) error { - taskList := this.getTaskList(uid, taskTag) - if len(taskList) > 0 { - return fmt.Errorf("clear data before init task") - } if data, err := this.moduleTask.configure.getTaskByTag(int32(taskTag)); err == nil { for _, cnf := range data { objId := primitive.NewObjectID().Hex() @@ -133,7 +129,7 @@ func (this *ModelTask) taskHandle(uid string, taskType comm.TaskType, taskParam if taskParam.First != conf.ConditionCondition { continue } - //检查进度,完成了执行处理器 + //检查进度,执行处理器 if v, ok := this.checkTaskProgress(uid, conf); ok { if err := this.finishHandle(v, comm.TaskTag(conf.IdTag), conf); err != nil { return err @@ -177,12 +173,40 @@ func (this *ModelTask) clearTask(uid string, taskTag comm.TaskTag) error { return nil } -//初始化攻略任务 -// func (this *ModelTask) initStrategyTask(uid string, taskTag comm.TaskTag) error { -// ids, err := this.Redis.HGetAllToMapString(fmt.Sprintf("task:%v_%v", uid, comm.TASK_STRATEGY)) -// if err != nil { -// return err -// } - +//进入卡牌攻略 +func (this *ModelTask) inStrategy(uid string, heroCfgId int32) (taskIds []int32, err error) { + //检查此英雄攻略是否完成 + taskList := this.getTaskList(uid, comm.TASK_STRATEGY) + allFinished := true + for _, v := range taskList { + conf, err := this.moduleTask.configure.getTaskById(v.TaskId) + if err != nil { + this.moduleTask.Errorf("get task[%v] config err %v", v.TaskId, err) + return nil, err + } + if conf != nil { + if conf.ConditionCondition == heroCfgId && v.Status != 1 { + allFinished = false + break + } + } + } -// } + if !allFinished { + //重置状态 + for _, v := range taskList { + if v.Status != 0 { + update := map[string]interface{}{ + "status": 0, + } + if err = this.modifyUserTask(uid, comm.TASK_STRATEGY, v.Id, update); err != nil { + this.moduleTask.Errorf("doStrategy err %v", err) + break + } + } + taskIds = append(taskIds, v.TaskId) + } + } + + return +} diff --git a/modules/task/module.go b/modules/task/module.go index aa79d7533..830b23033 100644 --- a/modules/task/module.go +++ b/modules/task/module.go @@ -56,6 +56,7 @@ func (this *ModuleTask) InitTaskAll(uid string) { this.InitTask(uid, comm.TASK_DAILY) this.InitTask(uid, comm.TASK_WEEKLY) this.InitTask(uid, comm.TASK_ACHIEVE) + this.InitTask(uid, comm.TASK_STRATEGY) this.modelTaskActive.initActiveRewardByTag(uid, comm.TASK_DAILY) this.modelTaskActive.initActiveRewardByTag(uid, comm.TASK_WEEKLY) @@ -90,6 +91,6 @@ func (this *ModuleTask) CreateTaskForStrategy(uid string, heroCfgId int32) { ids := make(map[string]string) ids, _ = this.modelTask.Redis.HGetAllToMapString(fmt.Sprintf("task:%v_%v", uid, comm.TASK_STRATEGY)) fmt.Println(ids) - // - + // + } diff --git a/pb/errorcode.pb.go b/pb/errorcode.pb.go index 69eeacd38..cddb495d0 100644 --- a/pb/errorcode.pb.go +++ b/pb/errorcode.pb.go @@ -104,6 +104,7 @@ const ( ErrorCode_TaskActiveNofound ErrorCode = 1605 //未找到用户活跃度配置 ErrorCode_TaskActiveNoenough ErrorCode = 1606 //活跃值未达标 ErrorCode_TaskNoFinished ErrorCode = 1607 //任务未完成 + ErrorCode_TaskFinished ErrorCode = 1608 //已完成 ) // Enum value maps for ErrorCode. @@ -183,6 +184,7 @@ var ( 1605: "TaskActiveNofound", 1606: "TaskActiveNoenough", 1607: "TaskNoFinished", + 1608: "TaskFinished", } ErrorCode_value = map[string]int32{ "Success": 0, @@ -259,6 +261,7 @@ var ( "TaskActiveNofound": 1605, "TaskActiveNoenough": 1606, "TaskNoFinished": 1607, + "TaskFinished": 1608, } ) @@ -293,7 +296,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, 0x85, 0x0c, 0x0a, 0x09, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x12, + 0x6f, 0x2a, 0x98, 0x0c, 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, @@ -389,8 +392,9 @@ var file_errorcode_proto_rawDesc = []byte{ 0x65, 0x4e, 0x6f, 0x66, 0x6f, 0x75, 0x6e, 0x64, 0x10, 0xc5, 0x0c, 0x12, 0x17, 0x0a, 0x12, 0x54, 0x61, 0x73, 0x6b, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x4e, 0x6f, 0x65, 0x6e, 0x6f, 0x75, 0x67, 0x68, 0x10, 0xc6, 0x0c, 0x12, 0x13, 0x0a, 0x0e, 0x54, 0x61, 0x73, 0x6b, 0x4e, 0x6f, 0x46, 0x69, - 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, 0x10, 0xc7, 0x0c, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, - 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, 0x10, 0xc7, 0x0c, 0x12, 0x11, 0x0a, 0x0c, 0x54, 0x61, 0x73, + 0x6b, 0x46, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, 0x10, 0xc8, 0x0c, 0x42, 0x06, 0x5a, 0x04, + 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/pb/proto/errorcode.proto b/pb/proto/errorcode.proto index 848284554..974a1ed31 100644 --- a/pb/proto/errorcode.proto +++ b/pb/proto/errorcode.proto @@ -89,4 +89,5 @@ enum ErrorCode { TaskActiveNofound = 1605; //未找到用户活跃度配置 TaskActiveNoenough = 1606; //活跃值未达标 TaskNoFinished = 1607; //任务未完成 + TaskFinished = 1608; //已完成 } \ No newline at end of file diff --git a/pb/proto/task/task_msg.proto b/pb/proto/task/task_msg.proto index 576e8907a..a392e8e68 100644 --- a/pb/proto/task/task_msg.proto +++ b/pb/proto/task/task_msg.proto @@ -34,4 +34,13 @@ message TaskActiveReceiveReq { message TaskActiveReceiveResp { int32 taskTag = 1; string id = 2; +} + +//攻略 +message TaskDoStrategyReq { + int32 heroCfgId = 1; //英雄ID +} + +message TaskDoStrategyResp { + repeated int32 taskIds = 1; //任务ID } \ No newline at end of file diff --git a/pb/task_msg.pb.go b/pb/task_msg.pb.go index 2ecc72a1e..84f548afd 100644 --- a/pb/task_msg.pb.go +++ b/pb/task_msg.pb.go @@ -432,6 +432,101 @@ func (x *TaskActiveReceiveResp) GetId() string { return "" } +//攻略 +type TaskDoStrategyReq struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + HeroCfgId int32 `protobuf:"varint,1,opt,name=heroCfgId,proto3" json:"heroCfgId"` //英雄ID +} + +func (x *TaskDoStrategyReq) Reset() { + *x = TaskDoStrategyReq{} + if protoimpl.UnsafeEnabled { + mi := &file_task_task_msg_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TaskDoStrategyReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TaskDoStrategyReq) ProtoMessage() {} + +func (x *TaskDoStrategyReq) ProtoReflect() protoreflect.Message { + mi := &file_task_task_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 TaskDoStrategyReq.ProtoReflect.Descriptor instead. +func (*TaskDoStrategyReq) Descriptor() ([]byte, []int) { + return file_task_task_msg_proto_rawDescGZIP(), []int{8} +} + +func (x *TaskDoStrategyReq) GetHeroCfgId() int32 { + if x != nil { + return x.HeroCfgId + } + return 0 +} + +type TaskDoStrategyResp struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + TaskIds []int32 `protobuf:"varint,1,rep,packed,name=taskIds,proto3" json:"taskIds"` //任务ID +} + +func (x *TaskDoStrategyResp) Reset() { + *x = TaskDoStrategyResp{} + if protoimpl.UnsafeEnabled { + mi := &file_task_task_msg_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *TaskDoStrategyResp) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TaskDoStrategyResp) ProtoMessage() {} + +func (x *TaskDoStrategyResp) ProtoReflect() protoreflect.Message { + mi := &file_task_task_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 TaskDoStrategyResp.ProtoReflect.Descriptor instead. +func (*TaskDoStrategyResp) Descriptor() ([]byte, []int) { + return file_task_task_msg_proto_rawDescGZIP(), []int{9} +} + +func (x *TaskDoStrategyResp) GetTaskIds() []int32 { + if x != nil { + return x.TaskIds + } + return nil +} + var File_task_task_msg_proto protoreflect.FileDescriptor var file_task_task_msg_proto_rawDesc = []byte{ @@ -465,8 +560,14 @@ var file_task_task_msg_proto_rawDesc = []byte{ 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x52, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x52, 0x65, 0x73, 0x70, 0x12, 0x18, 0x0a, 0x07, 0x74, 0x61, 0x73, 0x6b, 0x54, 0x61, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x07, 0x74, 0x61, 0x73, 0x6b, 0x54, 0x61, 0x67, 0x12, 0x0e, 0x0a, 0x02, 0x69, - 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, - 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x31, 0x0a, 0x11, 0x54, + 0x61, 0x73, 0x6b, 0x44, 0x6f, 0x53, 0x74, 0x72, 0x61, 0x74, 0x65, 0x67, 0x79, 0x52, 0x65, 0x71, + 0x12, 0x1c, 0x0a, 0x09, 0x68, 0x65, 0x72, 0x6f, 0x43, 0x66, 0x67, 0x49, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x09, 0x68, 0x65, 0x72, 0x6f, 0x43, 0x66, 0x67, 0x49, 0x64, 0x22, 0x2e, + 0x0a, 0x12, 0x54, 0x61, 0x73, 0x6b, 0x44, 0x6f, 0x53, 0x74, 0x72, 0x61, 0x74, 0x65, 0x67, 0x79, + 0x52, 0x65, 0x73, 0x70, 0x12, 0x18, 0x0a, 0x07, 0x74, 0x61, 0x73, 0x6b, 0x49, 0x64, 0x73, 0x18, + 0x01, 0x20, 0x03, 0x28, 0x05, 0x52, 0x07, 0x74, 0x61, 0x73, 0x6b, 0x49, 0x64, 0x73, 0x42, 0x06, + 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -481,7 +582,7 @@ func file_task_task_msg_proto_rawDescGZIP() []byte { return file_task_task_msg_proto_rawDescData } -var file_task_task_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 8) +var file_task_task_msg_proto_msgTypes = make([]protoimpl.MessageInfo, 10) var file_task_task_msg_proto_goTypes = []interface{}{ (*TaskReceiveReq)(nil), // 0: TaskReceiveReq (*TaskReceiveResp)(nil), // 1: TaskReceiveResp @@ -491,17 +592,19 @@ var file_task_task_msg_proto_goTypes = []interface{}{ (*TaskActiveListResp)(nil), // 5: TaskActiveListResp (*TaskActiveReceiveReq)(nil), // 6: TaskActiveReceiveReq (*TaskActiveReceiveResp)(nil), // 7: TaskActiveReceiveResp - (*DBTask)(nil), // 8: DBTask - (*DBTaskActive)(nil), // 9: DBTaskActive + (*TaskDoStrategyReq)(nil), // 8: TaskDoStrategyReq + (*TaskDoStrategyResp)(nil), // 9: TaskDoStrategyResp + (*DBTask)(nil), // 10: DBTask + (*DBTaskActive)(nil), // 11: DBTaskActive } var file_task_task_msg_proto_depIdxs = []int32{ - 8, // 0: TaskListResp.list:type_name -> DBTask - 9, // 1: TaskActiveListResp.list:type_name -> DBTaskActive - 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: TaskListResp.list:type_name -> DBTask + 11, // 1: TaskActiveListResp.list:type_name -> DBTaskActive + 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 } func init() { file_task_task_msg_proto_init() } @@ -607,6 +710,30 @@ func file_task_task_msg_proto_init() { return nil } } + file_task_task_msg_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TaskDoStrategyReq); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_task_task_msg_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*TaskDoStrategyResp); 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{ @@ -614,7 +741,7 @@ func file_task_task_msg_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_task_task_msg_proto_rawDesc, NumEnums: 0, - NumMessages: 8, + NumMessages: 10, NumExtensions: 0, NumServices: 0, },