diff --git a/modules/dispatch/api_notice.go b/modules/dispatch/api_notice.go index 90164cfe2..f80529975 100644 --- a/modules/dispatch/api_notice.go +++ b/modules/dispatch/api_notice.go @@ -6,7 +6,6 @@ import ( "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "go_dreamfactory/utils" - "sort" "google.golang.org/protobuf/proto" ) @@ -76,10 +75,6 @@ func (a *apiComp) Notice(session comm.IUserSession, req *pb.DispatchNoticeReq) ( a.module.modelDispatch.updateNotice(session.GetUserId(), d) } - // 排序 - sort.SliceStable(d.Nb.Tasks, func(i, j int) bool { - return d.Nb.Tasks[i].TaskId < d.Nb.Tasks[j].TaskId - }) rsp.Dispatch = d.Nb session.SendMsg(string(a.module.GetType()), "notice", rsp) return diff --git a/modules/dispatch/api_refresh.go b/modules/dispatch/api_refresh.go index 6469fa2e7..75bc6ebda 100644 --- a/modules/dispatch/api_refresh.go +++ b/modules/dispatch/api_refresh.go @@ -58,14 +58,13 @@ func (a *apiComp) Refresh(session comm.IUserSession, req *pb.DispatchRefreshReq) } //刷新公告(随机新的任务 包括未领取和正在进行的任务) - taskIds, err := a.module.modelDispatch.taskRandom(session.GetUserId(), d) + tasks, err := a.module.modelDispatch.taskRandom(session.GetUserId(), d) if err != nil { return } - // a.module.Debug("刷新", log.Field{Key: "taskIds", Value: taskIds}) //更新公告任务 - if err := a.module.modelDispatch.updateTasks(session.GetUserId(), d.Nb, taskIds); err != nil { + if err := a.module.modelDispatch.updateTasks(session.GetUserId(), d.Nb, tasks); err != nil { a.module.Debug("更新公告失败", log.Field{Key: "uid", Value: session.GetUserId()}) return } diff --git a/modules/dispatch/model_dispatch.go b/modules/dispatch/model_dispatch.go index d0501342a..1cffd0d68 100644 --- a/modules/dispatch/model_dispatch.go +++ b/modules/dispatch/model_dispatch.go @@ -113,22 +113,22 @@ func (this *modelDispatch) taskRandom(uid string, dispatch *pb.DBDispatch) (task n = len(dispatch.Nb.Tasks) if n == 0 { + dispatch.Nb.Tasks = make([]*pb.DispatchTask, 6) //随机任务 - tasks = this.randomTask(dispatch, noticeNum) + for i := 0; i < noticeNum; i++ { + dispatch.Nb.Tasks[i] = this.addOneRandomTask(dispatch) + } + tasks = dispatch.Nb.Tasks } else { - // var randCount int for i := 0; i < len(dispatch.Nb.Tasks); i++ { //只随机未接取的任务 if dispatch.Nb.Tasks[i].Status == 0 { - //删除 - // dispatch.Nb.Tasks = append(dispatch.Nb.Tasks[:i], dispatch.Nb.Tasks[i+1:]...) - dispatch.Nb.Tasks[i] = this.addOneRandomTask(dispatch) - // i-- - // randCount++ + // 替换 + t := this.addOneRandomTask(dispatch) + dispatch.Nb.Tasks[i] = t } } - //追加随机 - // tasks = append(tasks, this.addRandomTask(dispatch, randCount)...) + tasks = dispatch.Nb.Tasks } return @@ -141,16 +141,10 @@ func (this *modelDispatch) randomTask(dispatch *pb.DBDispatch, n int) (tasks []* if rid == 0 { return nil } - // if len(tasks) == 0 { - // tasks = append(tasks, &pb.DispatchTask{ - // TaskId: rid, - // }) - // total++ - // } else { //去重 exist := false for _, v := range dispatch.Nb.Tasks { - if v.TaskId == rid { + if v != nil && v.TaskId == rid { exist = true } } @@ -161,8 +155,6 @@ func (this *modelDispatch) randomTask(dispatch *pb.DBDispatch, n int) (tasks []* }) total++ } - // } - } //更新任务持续截至时间 @@ -200,7 +192,6 @@ func (this *modelDispatch) addRandomTask(dispatch *pb.DBDispatch, n int) (tasks // 替换指定的已完成任务 func (this *modelDispatch) replaceTask(uid string, taskId int32, dispatch *pb.DBDispatch) (tasks []*pb.DispatchTask, oldTask *pb.DispatchTask) { - // var randCount int for i := 0; i < len(dispatch.Nb.Tasks); i++ { //替换状态是完成的任务 if dispatch.Nb.Tasks[i].Status == 2 { @@ -210,13 +201,10 @@ func (this *modelDispatch) replaceTask(uid string, taskId int32, dispatch *pb.DB oldTask = dispatch.Nb.Tasks[i] //替换 dispatch.Nb.Tasks[i] = this.addOneRandomTask(dispatch) - // i-- - // randCount++ break } } - - // tasks = append(tasks, this.addRandomTask(dispatch, randCount)...) + tasks = dispatch.Nb.Tasks return } diff --git a/modules/worldtask/model_worldtask.go b/modules/worldtask/model_worldtask.go index 5a33ee321..e3fba5c7c 100644 --- a/modules/worldtask/model_worldtask.go +++ b/modules/worldtask/model_worldtask.go @@ -106,31 +106,31 @@ func (this *ModelWorldtask) finishTask(groupId, taskId int32, task *pb.DBWorldta return err } - if module, err := this.service.GetModule(comm.ModuleLinestory); err == nil { - if iLinestory, ok := module.(comm.ILinestory); ok { - if err := iLinestory.TaskFinishNotify(task.Uid, taskId, groupId); err != nil { - log.Debug("世界任务完成通知支线剧情任务", - log.Field{Key: "uid", Value: task.Uid}, - log.Field{Key: "groupId", Value: groupId}, - log.Field{Key: "taskId", Value: taskId}, - log.Field{Key: "err", Value: err.Error()}, - ) - } - } - } + // if module, err := this.service.GetModule(comm.ModuleLinestory); err == nil { + // if iLinestory, ok := module.(comm.ILinestory); ok { + // if err := iLinestory.TaskFinishNotify(task.Uid, taskId, groupId); err != nil { + // log.Debug("世界任务完成通知支线剧情任务", + // log.Field{Key: "uid", Value: task.Uid}, + // log.Field{Key: "groupId", Value: groupId}, + // log.Field{Key: "taskId", Value: taskId}, + // log.Field{Key: "err", Value: err.Error()}, + // ) + // } + // } + // } - if module, err := this.service.GetModule(comm.ModuleLibrary); err == nil { - if iLibrary, ok := module.(comm.ILibrary); ok { - if err := iLibrary.TaskFinishNotify(task.Uid, taskId, groupId); err != nil { - log.Debug("世界任务完成通知羁绊剧情任务", - log.Field{Key: "uid", Value: task.Uid}, - log.Field{Key: "fetterId", Value: groupId}, - log.Field{Key: "taskId", Value: taskId}, - log.Field{Key: "err", Value: err.Error()}, - ) - } - } - } + // if module, err := this.service.GetModule(comm.ModuleLibrary); err == nil { + // if iLibrary, ok := module.(comm.ILibrary); ok { + // if err := iLibrary.TaskFinishNotify(task.Uid, taskId, groupId); err != nil { + // log.Debug("世界任务完成通知羁绊剧情任务", + // log.Field{Key: "uid", Value: task.Uid}, + // log.Field{Key: "fetterId", Value: groupId}, + // log.Field{Key: "taskId", Value: taskId}, + // log.Field{Key: "err", Value: err.Error()}, + // ) + // } + // } + // } return nil } @@ -238,12 +238,16 @@ func (this *ModelWorldtask) taskFinishPush(session comm.IUserSession, groupId in } } - if curTaskConf.IdAfter != 0 { - // 任务完成推送 - session.SendMsg(string(this.moduleWorldtask.GetType()), WorldtaskNexttaskPush, &pb.WorldtaskNexttaskPush{ - NextTask: nextTask, - }) - } else { + if nextTaskIds == nil { + nextTask[groupId] = &pb.Worldtask{} //表示没有下一个任务 + } + + // 任务完成推送 + session.SendMsg(string(this.moduleWorldtask.GetType()), WorldtaskNexttaskPush, &pb.WorldtaskNexttaskPush{ + NextTask: nextTask, + }) + + if curTaskConf.IdAfter == 0 { // 章节完成 if _, ok := userTask.Chapters[groupId]; !ok { if userTask.Chapters == nil {