From 6550da4cc01f5f071deaca311f40876618d28653 Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Mon, 3 Apr 2023 16:24:32 +0800 Subject: [PATCH 1/3] =?UTF-8?q?update=E6=97=A5=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/worldtask/api_mine.go | 45 ++++++++++++ modules/worldtask/model_worldtask.go | 49 ++++++++++++- modules/worldtask/module.go | 101 --------------------------- pb/worldtask_db.pb.go | 73 ++++++++++++------- 4 files changed, 140 insertions(+), 128 deletions(-) diff --git a/modules/worldtask/api_mine.go b/modules/worldtask/api_mine.go index 49dca91c1..4d118bf2a 100644 --- a/modules/worldtask/api_mine.go +++ b/modules/worldtask/api_mine.go @@ -15,6 +15,13 @@ func (this *apiComp) MineCheck(session comm.IUserSession, req *pb.WorldtaskMineR func (this *apiComp) Mine(session comm.IUserSession, req *pb.WorldtaskMineReq) (code pb.ErrorCode, data proto.Message) { uid := session.GetUserId() + + user := this.module.ModuleUser.GetUser(uid) + if user == nil { + code = pb.ErrorCode_UserNofound + return + } + myWorldtask, err := this.module.modelWorldtask.getWorldtask(uid) if err != nil { this.module.Error("获取玩家世界任务失败", log.Field{Key: "uid", Value: uid}, log.Field{Key: "err", Value: err.Error()}) @@ -22,6 +29,44 @@ func (this *apiComp) Mine(session comm.IUserSession, req *pb.WorldtaskMineReq) ( return } + if myWorldtask.CurrentTask == nil { + myWorldtask.CurrentTask = make(map[int32]*pb.Worldtask) + } + + update := make(map[string]interface{}) + // 日常 + dailyIds := this.module.randomTask(user.Lv, 1, myWorldtask) + for _, v := range dailyIds { + gwtd, err := this.module.configure.getWorldtaskById(v) + if err != nil || gwtd == nil { + continue + } + myWorldtask.CurrentTask[gwtd.Group] = &pb.Worldtask{ + TaskId: v, + TaskType: gwtd.Des, + } + } + + //周常 + weekIds := this.module.randomTask(user.Lv, 2, myWorldtask) + for _, v := range weekIds { + gwtd, err := this.module.configure.getWorldtaskById(v) + if err != nil || gwtd == nil { + continue + } + myWorldtask.CurrentTask[gwtd.Group] = &pb.Worldtask{ + TaskId: v, + TaskType: gwtd.Des, + } + } + + update["currentTask"] = myWorldtask.CurrentTask + + if err := this.module.modelWorldtask.Change(uid, update); err != nil { + code = pb.ErrorCode_DBError + return + } + rsp := &pb.WorldtaskMineResp{ Task: myWorldtask, } diff --git a/modules/worldtask/model_worldtask.go b/modules/worldtask/model_worldtask.go index ccb742cbf..6ca53446c 100644 --- a/modules/worldtask/model_worldtask.go +++ b/modules/worldtask/model_worldtask.go @@ -8,6 +8,7 @@ import ( "go_dreamfactory/modules" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" + "go_dreamfactory/utils" "go.mongodb.org/mongo-driver/mongo" ) @@ -206,6 +207,7 @@ func (this *ModelWorldtask) updateCheckCond(uid string, userTask *pb.DBWorldtask return userTask } +// 任务完成推送 func (this *ModelWorldtask) taskFinishPush(session comm.IUserSession, groupId int32, userTask *pb.DBWorldtask, curTaskConf *cfg.GameWorldTaskData) { nextTaskIds := this.findNextTasks(curTaskConf.Key) this.moduleWorldtask.Debug("nextTaskIds", log.Field{Key: "nextTaskIds", Value: nextTaskIds}) @@ -249,6 +251,7 @@ func (this *ModelWorldtask) taskFinishPush(session comm.IUserSession, groupId in }) } +// 任务完成 func (this *ModelWorldtask) taskFinish(session comm.IUserSession, groupId, taskId int32, userTask *pb.DBWorldtask, curTaskConf *cfg.GameWorldTaskData) { if err := this.finishTask(groupId, taskId, userTask); err != nil { this.moduleWorldtask.Error("完成任务失败", @@ -273,5 +276,49 @@ func (this *ModelWorldtask) taskFinish(session comm.IUserSession, groupId, taskI ic.TaskComplete(session, taskId) } } - +} + +func (this *Worldtask) filterTask(userLv, des int32, wt *pb.DBWorldtask) (taskIds []int32) { + if des != 1 || des != 4 { + return + } + gwt, err := this.configure.getWorldtaskCfg() + if err != nil { + return + } + + for _, v := range gwt.GetDataList() { + // 主角等级 + if v.Des == des && userLv >= v.Lock && userLv <= v.Lockend { + if v.Ontxe != 0 { + //前置 + if _, ok := utils.Findx(wt.TaskList, v.Ontxe); ok { + taskIds = append(taskIds, v.Key) + } + } + } + } + return +} + +// 随机日常、周常任务 +func (this *Worldtask) randomTask(userLv, des int32, wt *pb.DBWorldtask) (taskIds []int32) { + var num int32 + if des == 1 { + num = this.configure.GetGlobalConf().DailyNum + } else if des == 4 { + num = this.configure.GetGlobalConf().WeekNum + } + + tIds := this.filterTask(userLv, des, wt) + if len(tIds) < int(num) { + num = int32(len(tIds)) + } + idx := utils.RandomNumbers(0, len(tIds), int(num)) + + for i := 0; i < len(idx); i++ { + taskIds = append(taskIds, tIds[i]) + } + + return } diff --git a/modules/worldtask/module.go b/modules/worldtask/module.go index 225dd4e86..f88021989 100644 --- a/modules/worldtask/module.go +++ b/modules/worldtask/module.go @@ -131,107 +131,6 @@ func (this *Worldtask) TaskCondFinishNotify(session comm.IUserSession, condId in return nil } -// 任务条件达成通知 -// Deprecated -// func (this *Worldtask) TaskcondNotify(session comm.IUserSession, condId int32) error { -// uid := session.GetUserId() - -// finishedTaskIds := make(map[int32]int32) //达成的任务条件 -// for _, c := range this.worldtaskConf.GetDataList() { -// for _, v := range c.Completetask { -// if v == condId { -// finishedTaskIds[c.Group] = c.Key -// } -// } -// } - -// if len(finishedTaskIds) == 0 { -// //this.Debug("没有匹配到任务世界任务", log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "condId", Value: condId}) -// return nil -// } -// this.Debug("世界任务完成通知-查找到世界任务", log.Field{Key: "uid", Value: uid}, log.Field{Key: "condId", Value: condId}, log.Field{Key: "params", Value: finishedTaskIds}) -// //下一个任务ID -// var nextTaskId int32 -// // 获取用户信息 -// user := this.ModuleUser.GetUser(uid) -// if user == nil { -// return comm.NewCustomError(pb.ErrorCode_UserSessionNobeing) -// } - -// // 玩家世界任务 -// userTask, err := this.modelWorldtask.getWorldtask(uid) -// if err != nil { -// this.Error("获取玩家世界任务", log.Field{Key: "uid", Value: uid}, log.Field{Key: "condId", Value: condId}) -// return err -// } - -// if userTask.Uid != "" { -// //查找任务ID根据condId 可能会找出不同的任务 -// for groupId, taskId := range finishedTaskIds { -// logFields := []log.Field{{Key: "uid", Value: uid}, {Key: "group", Value: groupId}, {Key: "taskId", Value: taskId}, {Key: "condId", Value: condId}} -// // 判断任务是否已完成 -// if this.modelWorldtask.isFinished(taskId, userTask.TaskList) { -// this.Debug("世界任务已完成", logFields...) -// continue -// } -// taskConf, err := this.configure.getWorldtaskById(taskId) -// if err != nil { -// this.Error("world_task config not found", logFields...) -// return err -// } -// logFields = append(logFields, log.Field{Key: "id_after", Value: taskConf.IdAfter}, log.Field{Key: "des", Value: taskConf.Des}) -// if taskConf != nil { -// if taskConf.Des == 2 { //只有世界任务才校验前置 -// if !this.modelWorldtask.IsPreFinished(userTask, taskConf) { -// this.Debug("世界任务前置任务未完成", logFields...) -// continue -// } -// } -// nextTaskId = taskConf.IdAfter - -// // 判断玩家等级要求 -// if taskConf.Des == 2 { -// if user.Lv < taskConf.Lock { -// logFields = append(logFields, log.Field{Key: "当前lv", Value: user.Lv}, log.Field{Key: "期望等级", Value: taskConf.Lock}) -// this.Debug("等级不满足", logFields...) -// return comm.NewCustomError(pb.ErrorCode_WorldtaskLvNotEnough) -// } -// } - -// //完成任务 -// if err := this.modelWorldtask.finishTask(groupId, taskId, userTask); err != nil { -// logFields = append(logFields, log.Field{Key: "err", Value: err.Error()}) -// this.Error("世界任务完成", logFields...) -// return err -// } -// this.Debug("任务条件达成完成", logFields...) -// //发奖 -// if code := this.DispenseRes(session, taskConf.Reword, true); code != pb.ErrorCode_Success { -// logFields = append(logFields, log.Field{Key: "reward", Value: taskConf.Reword}, log.Field{Key: "code", Value: code}) -// this.Error("资源发放", logFields...) -// } - -// if nextTaskId != 0 && taskConf.Des == 2 { -// if err := session.SendMsg(string(this.GetType()), "nexttask", &pb.WorldtaskNexttaskPush{ -// // NextTaskId: nextTaskId, -// }); err != nil { -// logFields = append(logFields, log.Field{Key: "err", Value: err.Error()}) -// log.Error("任务条件达成推送", logFields...) -// } else { -// this.Debug("推送任务", log.Field{Key: "NextTaskId", Value: nextTaskId}) -// } -// } else { -// this.Debug("已经是最后一个任务了", logFields...) -// } - -// } -// } - -// } - -// return nil -// } - // 获取我的世界任务 func (this *Worldtask) GetMyWorldtask(uid string) *pb.DBWorldtask { wt, err := this.modelWorldtask.getWorldtask(uid) diff --git a/pb/worldtask_db.pb.go b/pb/worldtask_db.pb.go index 6971d71ea..2c469d97d 100644 --- a/pb/worldtask_db.pb.go +++ b/pb/worldtask_db.pb.go @@ -25,10 +25,12 @@ type DBWorldtask struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid" bson:"uid"` //玩家ID - TaskList []int32 `protobuf:"varint,3,rep,packed,name=taskList,proto3" json:"taskList" bson:"taskList"` // 任务列表 - CurrentTask map[int32]*Worldtask `protobuf:"bytes,4,rep,name=currentTask,proto3" json:"currentTask" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3" bson:"currentTask"` //正在进行的任务 - Chapters map[int32]int32 `protobuf:"bytes,5,rep,name=chapters,proto3" json:"chapters" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3" bson:"chapters"` //key章节ID v状态 1已解锁2已领取 + Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid" bson:"uid"` //玩家ID + TaskList []int32 `protobuf:"varint,3,rep,packed,name=taskList,proto3" json:"taskList" bson:"taskList"` // 任务列表 + CurrentTask map[int32]*Worldtask `protobuf:"bytes,4,rep,name=currentTask,proto3" json:"currentTask" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3" bson:"currentTask"` //正在进行的任务 + Chapters map[int32]int32 `protobuf:"bytes,5,rep,name=chapters,proto3" json:"chapters" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3" bson:"chapters"` //key章节ID v状态 1已解锁2已领取 + DaliyRefreshTime int64 `protobuf:"varint,6,opt,name=daliyRefreshTime,proto3" json:"daliyRefreshTime" bson:"daliyRefreshTime"` + WeekRefreshTime int64 `protobuf:"varint,7,opt,name=weekRefreshTime,proto3" json:"weekRefreshTime" bson:"weekRefreshTime"` } func (x *DBWorldtask) Reset() { @@ -91,6 +93,20 @@ func (x *DBWorldtask) GetChapters() map[int32]int32 { return nil } +func (x *DBWorldtask) GetDaliyRefreshTime() int64 { + if x != nil { + return x.DaliyRefreshTime + } + return 0 +} + +func (x *DBWorldtask) GetWeekRefreshTime() int64 { + if x != nil { + return x.WeekRefreshTime + } + return 0 +} + type Worldtask struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -174,8 +190,8 @@ var File_worldtask_worldtask_db_proto protoreflect.FileDescriptor var file_worldtask_worldtask_db_proto_rawDesc = []byte{ 0x0a, 0x1c, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x74, 0x61, 0x73, 0x6b, 0x2f, 0x77, 0x6f, 0x72, 0x6c, - 0x64, 0x74, 0x61, 0x73, 0x6b, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xbd, - 0x02, 0x0a, 0x0b, 0x44, 0x42, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x74, 0x61, 0x73, 0x6b, 0x12, 0x10, + 0x64, 0x74, 0x61, 0x73, 0x6b, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x93, + 0x03, 0x0a, 0x0b, 0x44, 0x42, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x74, 0x61, 0x73, 0x6b, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x75, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x74, 0x61, 0x73, 0x6b, 0x4c, 0x69, 0x73, 0x74, 0x18, 0x03, 0x20, 0x03, 0x28, 0x05, 0x52, 0x08, 0x74, 0x61, 0x73, 0x6b, 0x4c, 0x69, 0x73, 0x74, 0x12, 0x3f, 0x0a, 0x0b, @@ -186,26 +202,31 @@ var file_worldtask_worldtask_db_proto_rawDesc = []byte{ 0x08, 0x63, 0x68, 0x61, 0x70, 0x74, 0x65, 0x72, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x44, 0x42, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x74, 0x61, 0x73, 0x6b, 0x2e, 0x43, 0x68, 0x61, 0x70, 0x74, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x63, 0x68, 0x61, - 0x70, 0x74, 0x65, 0x72, 0x73, 0x1a, 0x4a, 0x0a, 0x10, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, - 0x54, 0x61, 0x73, 0x6b, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x20, 0x0a, 0x05, 0x76, - 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x57, 0x6f, 0x72, - 0x6c, 0x64, 0x74, 0x61, 0x73, 0x6b, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, - 0x01, 0x1a, 0x3b, 0x0a, 0x0d, 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, 0x22, 0x99, - 0x01, 0x0a, 0x09, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x74, 0x61, 0x73, 0x6b, 0x12, 0x16, 0x0a, 0x06, - 0x74, 0x61, 0x73, 0x6b, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x74, 0x61, - 0x73, 0x6b, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x74, 0x61, 0x73, 0x6b, 0x54, 0x79, 0x70, 0x65, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x74, 0x61, 0x73, 0x6b, 0x54, 0x79, 0x70, 0x65, - 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x70, 0x63, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x05, 0x20, - 0x01, 0x28, 0x05, 0x52, 0x09, 0x6e, 0x70, 0x63, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, - 0x0a, 0x08, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x49, 0x64, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x05, - 0x52, 0x08, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x49, 0x64, 0x73, 0x12, 0x1e, 0x0a, 0x0a, 0x64, 0x65, - 0x6c, 0x69, 0x76, 0x65, 0x72, 0x4e, 0x70, 0x63, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, - 0x64, 0x65, 0x6c, 0x69, 0x76, 0x65, 0x72, 0x4e, 0x70, 0x63, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, - 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x70, 0x74, 0x65, 0x72, 0x73, 0x12, 0x2a, 0x0a, 0x10, 0x64, 0x61, 0x6c, 0x69, 0x79, 0x52, 0x65, + 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x10, 0x64, 0x61, 0x6c, 0x69, 0x79, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x69, 0x6d, + 0x65, 0x12, 0x28, 0x0a, 0x0f, 0x77, 0x65, 0x65, 0x6b, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, + 0x54, 0x69, 0x6d, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0f, 0x77, 0x65, 0x65, 0x6b, + 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x54, 0x69, 0x6d, 0x65, 0x1a, 0x4a, 0x0a, 0x10, 0x43, + 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x54, 0x61, 0x73, 0x6b, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, + 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, + 0x79, 0x12, 0x20, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x0a, 0x2e, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x74, 0x61, 0x73, 0x6b, 0x52, 0x05, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x3b, 0x0a, 0x0d, 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, 0x22, 0x99, 0x01, 0x0a, 0x09, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x74, 0x61, + 0x73, 0x6b, 0x12, 0x16, 0x0a, 0x06, 0x74, 0x61, 0x73, 0x6b, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x06, 0x74, 0x61, 0x73, 0x6b, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x74, 0x61, + 0x73, 0x6b, 0x54, 0x79, 0x70, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x74, 0x61, + 0x73, 0x6b, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x70, 0x63, 0x53, 0x74, 0x61, + 0x74, 0x75, 0x73, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x6e, 0x70, 0x63, 0x53, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x49, 0x64, 0x73, + 0x18, 0x06, 0x20, 0x03, 0x28, 0x05, 0x52, 0x08, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x49, 0x64, 0x73, + 0x12, 0x1e, 0x0a, 0x0a, 0x64, 0x65, 0x6c, 0x69, 0x76, 0x65, 0x72, 0x4e, 0x70, 0x63, 0x18, 0x07, + 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x64, 0x65, 0x6c, 0x69, 0x76, 0x65, 0x72, 0x4e, 0x70, 0x63, + 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( From d1dcc03e3a08fb541fe145d133fac977a1e0a2ed Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Mon, 3 Apr 2023 19:20:19 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=96=B0=E7=89=88=E6=97=A5=E5=91=A8?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/json/game_worldtask.json | 24 ++++++------- modules/gateway/agent.go | 3 +- modules/worldtask/api_accept.go | 5 +-- modules/worldtask/api_completetask.go | 4 +-- modules/worldtask/api_mine.go | 50 +++++++++++++++++---------- modules/worldtask/model_worldtask.go | 4 +-- 6 files changed, 53 insertions(+), 37 deletions(-) diff --git a/bin/json/game_worldtask.json b/bin/json/game_worldtask.json index c6619acf1..b9d9d847e 100644 --- a/bin/json/game_worldtask.json +++ b/bin/json/game_worldtask.json @@ -729,7 +729,7 @@ "lockend": 5, "ontxe": 20010, "id_after": 0, - "group": 110, + "group": 111, "des": 1, "icon": "", "task_Tname": { @@ -765,7 +765,7 @@ "lockend": 5, "ontxe": 20010, "id_after": 0, - "group": 110, + "group": 112, "des": 1, "icon": "", "task_Tname": { @@ -801,7 +801,7 @@ "lockend": 20, "ontxe": 20010, "id_after": 0, - "group": 110, + "group": 113, "des": 1, "icon": "", "task_Tname": { @@ -837,7 +837,7 @@ "lockend": 20, "ontxe": 20010, "id_after": 0, - "group": 110, + "group": 114, "des": 1, "icon": "", "task_Tname": { @@ -873,7 +873,7 @@ "lockend": 20, "ontxe": 20010, "id_after": 0, - "group": 110, + "group": 115, "des": 1, "icon": "", "task_Tname": { @@ -909,7 +909,7 @@ "lockend": 20, "ontxe": 20010, "id_after": 0, - "group": 110, + "group": 116, "des": 1, "icon": "", "task_Tname": { @@ -981,7 +981,7 @@ "lockend": 5, "ontxe": 20010, "id_after": 0, - "group": 410, + "group": 411, "des": 4, "icon": "", "task_Tname": { @@ -1017,7 +1017,7 @@ "lockend": 5, "ontxe": 20010, "id_after": 0, - "group": 410, + "group": 412, "des": 4, "icon": "", "task_Tname": { @@ -1053,7 +1053,7 @@ "lockend": 20, "ontxe": 20010, "id_after": 0, - "group": 410, + "group": 413, "des": 4, "icon": "", "task_Tname": { @@ -1089,7 +1089,7 @@ "lockend": 20, "ontxe": 20010, "id_after": 0, - "group": 410, + "group": 414, "des": 4, "icon": "", "task_Tname": { @@ -1125,7 +1125,7 @@ "lockend": 20, "ontxe": 20010, "id_after": 0, - "group": 410, + "group": 415, "des": 4, "icon": "", "task_Tname": { @@ -1161,7 +1161,7 @@ "lockend": 20, "ontxe": 20010, "id_after": 0, - "group": 410, + "group": 416, "des": 4, "icon": "", "task_Tname": { diff --git a/modules/gateway/agent.go b/modules/gateway/agent.go index b14188b33..74b540bbf 100644 --- a/modules/gateway/agent.go +++ b/modules/gateway/agent.go @@ -321,7 +321,8 @@ func (this *Agent) messageDistribution(msg *pb.UserMessage) (err error) { } stime := time.Now() // this.gateway.Debugf("----------3 agent:%s uId:%s MainType:%s SubType:%s ", this.sessionId, this.uId, msg.MainType, msg.SubType) - ctx, _ := context.WithTimeout(context.Background(), time.Second*5) + // ctx, _ := context.WithTimeout(context.Background(), time.Second*5) + ctx := context.Background() if len(serviceTag) == 0 { // this.gateway.Debugf("----------4 agent:%s uId:%s MainType:%s SubType:%s ", this.sessionId, this.uId, msg.MainType, msg.SubType) if err = this.gateway.Service().RpcCall(ctx, servicePath, string(comm.Rpc_GatewayRoute), req, reply); err != nil { diff --git a/modules/worldtask/api_accept.go b/modules/worldtask/api_accept.go index f0f68e47c..9deafab93 100644 --- a/modules/worldtask/api_accept.go +++ b/modules/worldtask/api_accept.go @@ -58,8 +58,9 @@ func (a *apiComp) Accept(session comm.IUserSession, req *pb.WorldtaskAcceptReq) session.SendMsg(string(a.module.GetType()), "accept", rsp) //判断是否要结束任务 - if (len(curTaskConf.Completetask) == 1 && curTaskConf.Completetask[0] == 0 || - len(curTaskConf.Completetask) == 0) && curTaskConf.DeliverNpc == 0 { + if ((len(curTaskConf.Completetask) == 1 && curTaskConf.Completetask[0] == 0) || + len(curTaskConf.Completetask) == 0) && + curTaskConf.DeliverNpc == 0 { //结束任务 a.module.modelWorldtask.taskFinish(session, req.GroupId, req.TaskId, myWorldtask, curTaskConf) a.module.modelWorldtask.taskFinishPush(session, req.GroupId, myWorldtask, curTaskConf) diff --git a/modules/worldtask/api_completetask.go b/modules/worldtask/api_completetask.go index b448a2c55..8f5391346 100644 --- a/modules/worldtask/api_completetask.go +++ b/modules/worldtask/api_completetask.go @@ -30,8 +30,8 @@ func (this *apiComp) CompleteCondi(session comm.IUserSession, req *pb.WorldtaskC code = pb.ErrorCode_ConfigNoFound return } - if (len(curTaskConf.Completetask) == 1 && curTaskConf.Completetask[0] == 0 || - len(curTaskConf.Completetask) == 0) && curTaskConf.DeliverNpc == 0 { + if (len(curTaskConf.Completetask) == 1 && curTaskConf.Completetask[0] == 0) || + len(curTaskConf.Completetask) == 0 { code = pb.ErrorCode_WorldtaskNoProcess return } diff --git a/modules/worldtask/api_mine.go b/modules/worldtask/api_mine.go index 4d118bf2a..487060f3d 100644 --- a/modules/worldtask/api_mine.go +++ b/modules/worldtask/api_mine.go @@ -4,10 +4,16 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" + "go_dreamfactory/sys/configure" "google.golang.org/protobuf/proto" ) +var ( + dailyDes int32 = 1 + weekDes int32 = 4 +) + // 我的世界任务 func (this *apiComp) MineCheck(session comm.IUserSession, req *pb.WorldtaskMineReq) (code pb.ErrorCode) { return @@ -33,31 +39,39 @@ func (this *apiComp) Mine(session comm.IUserSession, req *pb.WorldtaskMineReq) ( myWorldtask.CurrentTask = make(map[int32]*pb.Worldtask) } + now := configure.Now().Unix() update := make(map[string]interface{}) + // 日常 - dailyIds := this.module.randomTask(user.Lv, 1, myWorldtask) - for _, v := range dailyIds { - gwtd, err := this.module.configure.getWorldtaskById(v) - if err != nil || gwtd == nil { - continue - } - myWorldtask.CurrentTask[gwtd.Group] = &pb.Worldtask{ - TaskId: v, - TaskType: gwtd.Des, + if now-myWorldtask.DaliyRefreshTime >= 3600*24 { + dailyIds := this.module.randomTask(user.Lv, dailyDes, myWorldtask) + for _, v := range dailyIds { + gwtd, err := this.module.configure.getWorldtaskById(v) + if err != nil || gwtd == nil { + continue + } + myWorldtask.CurrentTask[gwtd.Group] = &pb.Worldtask{ + TaskId: v, + TaskType: gwtd.Des, + } } + update["daliyRefreshTime"] = configure.Now().Unix() } //周常 - weekIds := this.module.randomTask(user.Lv, 2, myWorldtask) - for _, v := range weekIds { - gwtd, err := this.module.configure.getWorldtaskById(v) - if err != nil || gwtd == nil { - continue - } - myWorldtask.CurrentTask[gwtd.Group] = &pb.Worldtask{ - TaskId: v, - TaskType: gwtd.Des, + if now-myWorldtask.WeekRefreshTime >= 3600*24*7 { + weekIds := this.module.randomTask(user.Lv, weekDes, myWorldtask) + for _, v := range weekIds { + gwtd, err := this.module.configure.getWorldtaskById(v) + if err != nil || gwtd == nil { + continue + } + myWorldtask.CurrentTask[gwtd.Group] = &pb.Worldtask{ + TaskId: v, + TaskType: gwtd.Des, + } } + update["weekRefreshTime"] = configure.Now().Unix() } update["currentTask"] = myWorldtask.CurrentTask diff --git a/modules/worldtask/model_worldtask.go b/modules/worldtask/model_worldtask.go index 6ca53446c..6069a72ef 100644 --- a/modules/worldtask/model_worldtask.go +++ b/modules/worldtask/model_worldtask.go @@ -279,7 +279,7 @@ func (this *ModelWorldtask) taskFinish(session comm.IUserSession, groupId, taskI } func (this *Worldtask) filterTask(userLv, des int32, wt *pb.DBWorldtask) (taskIds []int32) { - if des != 1 || des != 4 { + if des != 1 && des != 4 { return } gwt, err := this.configure.getWorldtaskCfg() @@ -291,7 +291,7 @@ func (this *Worldtask) filterTask(userLv, des int32, wt *pb.DBWorldtask) (taskId // 主角等级 if v.Des == des && userLv >= v.Lock && userLv <= v.Lockend { if v.Ontxe != 0 { - //前置 + //寻找前置 if _, ok := utils.Findx(wt.TaskList, v.Ontxe); ok { taskIds = append(taskIds, v.Key) } From 4a18a075f570ba35291405ceb141257651d40b99 Mon Sep 17 00:00:00 2001 From: wh_zcy Date: Tue, 4 Apr 2023 12:13:50 +0800 Subject: [PATCH 3/3] update --- modules/worldtask/api_accept.go | 19 +++++++++++++++++++ modules/worldtask/api_finish.go | 15 +++++++-------- modules/worldtask/model_worldtask.go | 14 +++++++------- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/modules/worldtask/api_accept.go b/modules/worldtask/api_accept.go index 9deafab93..fc0c191eb 100644 --- a/modules/worldtask/api_accept.go +++ b/modules/worldtask/api_accept.go @@ -20,6 +20,12 @@ func (a *apiComp) Accept(session comm.IUserSession, req *pb.WorldtaskAcceptReq) return } uid := session.GetUserId() + user := a.module.ModuleUser.GetUser(uid) + if user == nil { + code = pb.ErrorCode_UserSessionNobeing + return + } + myWorldtask, err := a.module.modelWorldtask.getWorldtask(uid) if err != nil { a.module.Error("获取玩家世界任务失败", log.Field{Key: "uid", Value: uid}, log.Field{Key: "err", Value: err.Error()}) @@ -34,6 +40,19 @@ func (a *apiComp) Accept(session comm.IUserSession, req *pb.WorldtaskAcceptReq) return } + // 判断玩家等级要求 + if user.Lv < curTaskConf.Lock { + code = pb.ErrorCode_WorldtaskLvNotEnough + return + } + + // 前置任务ID 只有世界任务才校验前置 + if !a.module.modelWorldtask.IsPreFinished(req.GroupId, myWorldtask, curTaskConf) { + a.module.Debug("前置任务未完成", log.Field{Key: "uid", Value: uid}, log.Field{Key: "preTaskId", Value: curTaskConf.Ontxe}, log.Field{Key: "taskId", Value: curTaskConf.Key}) + code = pb.ErrorCode_WorldtaskLastUnFinished + return + } + if myWorldtask.CurrentTask == nil { myWorldtask.CurrentTask = make(map[int32]*pb.Worldtask) } diff --git a/modules/worldtask/api_finish.go b/modules/worldtask/api_finish.go index 5456ac386..513c65f02 100644 --- a/modules/worldtask/api_finish.go +++ b/modules/worldtask/api_finish.go @@ -184,18 +184,17 @@ func (this *apiComp) Finish(session comm.IUserSession, req *pb.WorldtaskFinishRe } else { // 章节完成 if _, ok := userTask.Chapters[req.GroupId]; !ok { + delete(userTask.CurrentTask, req.GroupId) if userTask.Chapters == nil { - delete(userTask.CurrentTask, req.GroupId) userTask.Chapters = make(map[int32]int32) - userTask.Chapters[req.GroupId] = 1 //已解锁待领取 - update := map[string]interface{}{ - "chapters": userTask.Chapters, - "currentTask": userTask.CurrentTask, - } - this.module.modelWorldtask.Change(uid, update) } + userTask.Chapters[req.GroupId] = 1 //已解锁待领取 + update := map[string]interface{}{ + "chapters": userTask.Chapters, + "currentTask": userTask.CurrentTask, + } + this.module.modelWorldtask.Change(uid, update) } - } } diff --git a/modules/worldtask/model_worldtask.go b/modules/worldtask/model_worldtask.go index 6069a72ef..a8ac21112 100644 --- a/modules/worldtask/model_worldtask.go +++ b/modules/worldtask/model_worldtask.go @@ -231,16 +231,16 @@ func (this *ModelWorldtask) taskFinishPush(session comm.IUserSession, groupId in if curTaskConf.IdAfter == 0 { // 章节完成 if _, ok := userTask.Chapters[groupId]; !ok { + delete(userTask.CurrentTask, groupId) if userTask.Chapters == nil { - delete(userTask.CurrentTask, groupId) userTask.Chapters = make(map[int32]int32) - userTask.Chapters[groupId] = 1 //已解锁待领取 - update := map[string]interface{}{ - "chapters": userTask.Chapters, - "currentTask": userTask.CurrentTask, - } - this.Change(session.GetUserId(), update) } + userTask.Chapters[groupId] = 1 //已解锁待领取 + update := map[string]interface{}{ + "chapters": userTask.Chapters, + "currentTask": userTask.CurrentTask, + } + this.Change(session.GetUserId(), update) } }