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 (