diff --git a/comm/imodule.go b/comm/imodule.go index b054a7607..fcc0270c0 100644 --- a/comm/imodule.go +++ b/comm/imodule.go @@ -379,7 +379,7 @@ type ( // TaskcondNotify(session IUserSession, condId int32) error TaskCondFinishNotify(session IUserSession, condId int32) error // bingo所有任务 - BingoAllTask(session IUserSession) error + // BingoAllTask(session IUserSession) error // bingo任务 BingoJumpTask(session IUserSession, groupId, rtaskId int32) error // 查询我的世界任务 diff --git a/modules/gm/module.go b/modules/gm/module.go index 0430ae0a0..9db98e660 100644 --- a/modules/gm/module.go +++ b/modules/gm/module.go @@ -285,20 +285,7 @@ func (this *GM) CreateCmd(session comm.IUserSession, cmd string) (code pb.ErrorC log.Field{Key: "uid", Value: session.GetUserId()}, log.Field{Key: "0", Value: datas[1]}, ) - } else if len(datas) == 1 && (datas[0] == "alltask") { // 完成所有世界任务 - module, err := this.service.GetModule(comm.ModuleWorldtask) - if err != nil { - return - } - if wt, ok := module.(comm.IWorldtask); ok { - if err = wt.BingoAllTask(session); err != nil { - this.Error("bingo 世界任务", - log.Field{Key: "param", Value: datas}, - log.Field{Key: "err", Value: err.Error()}) - } - } - - } else if len(datas) == 1 && (datas[0] == "allgrowtask") { // 完成所有成长任务 + } else if len(datas) == 1 && (datas[0] == "allgrowtask") { // 完成所有成长任务 module, err := this.service.GetModule(comm.ModuleGrowtask) if err != nil { return diff --git a/modules/worldtask/api_completetask.go b/modules/worldtask/api_completetask.go index b4ab3fdff..dd339c9b0 100644 --- a/modules/worldtask/api_completetask.go +++ b/modules/worldtask/api_completetask.go @@ -41,6 +41,7 @@ func (this *apiComp) CompleteCondi(session comm.IUserSession, req *pb.WorldtaskC return } + myWorldtask.Uid = uid wt := myWorldtask.CurrentTask[req.GroupId] if m, err := this.module.service.GetModule(comm.ModuleRtask); err == nil { iwt, ok := m.(comm.IRtask) @@ -77,5 +78,10 @@ func (this *apiComp) CompleteCondi(session comm.IUserSession, req *pb.WorldtaskC session.SendMsg(string(this.module.GetType()), "completecondi", rsp) + //结束任务 + if curTaskConf.DeliverNpc == 0 { + this.module.modelWorldtask.taskFinish(session, req.GroupId, req.TaskId, myWorldtask, curTaskConf) + this.module.modelWorldtask.taskFinishPush(session, req.GroupId, myWorldtask, curTaskConf) + } return } diff --git a/modules/worldtask/module.go b/modules/worldtask/module.go index f88021989..c03c7b002 100644 --- a/modules/worldtask/module.go +++ b/modules/worldtask/module.go @@ -72,7 +72,7 @@ func (this *Worldtask) TaskCondFinishNotify(session comm.IUserSession, condId in if v == condId { //校验任务是否是当前任务 if task, ok := userTask.CurrentTask[c.Group]; ok { - if task.NpcStatus == 1 && c.Key == task.TaskId{ + if task.NpcStatus == 1 && c.Key == task.TaskId { finishedTaskIds[c.Group] = c.Key groupId = c.Group taskId = c.Key @@ -141,81 +141,72 @@ func (this *Worldtask) GetMyWorldtask(uid string) *pb.DBWorldtask { return wt } -func (this *Worldtask) BingoAllTask(session comm.IUserSession) error { - // uid := session.GetUserId() - // mytask := &pb.DBWorldtask{Uid: uid} - - // tasklist := this.worldtaskConf.GetDataList() - - // for _, conf := range tasklist { - // //世界任务配置 - // wt := &pb.Worldtask{ - // TaskId: conf.Key, - // TaskType: conf.Des, - // } - // mytask.TaskList = append(mytask.TaskList, wt) - // } - - // if err := this.modelWorldtask.Add(uid, mytask); err != nil { - // return err - // } - - // rsp := &pb.WorldtaskFinishIdsPush{ - // TaskList: mytask.TaskList, - // } - - return nil //session.SendMsg(string(this.GetType()), "finishids", rsp) -} - // bingo世界任务跳跃 支持回退 func (this *Worldtask) BingoJumpTask(session comm.IUserSession, groupId, taskId int32) error { - // uid := session.GetUserId() - // mytask, err := this.modelWorldtask.getWorldtask(uid) - // if err != nil { - // return err - // } - // mytask.Uid = uid - // // 更新数据 - // update := map[string]interface{}{} + uid := session.GetUserId() + // 更新数据 + update := make(map[string]interface{}) - // taskConf := this.worldtaskConf.GetDataMap()[taskId] - // if taskConf == nil { - // return fmt.Errorf("taskId: %v config is nil", taskId) - // } + mytask, err := this.modelWorldtask.getWorldtask(uid) + if err != nil { + return err + } - // //重置taskList - // mytask.TaskList = []*pb.Worldtask{} + if mytask == nil { + mytask = &pb.DBWorldtask{} + mytask.Uid = uid + if err := this.modelWorldtask.Add(uid, mytask); err != nil { + this.Error("添加世界任务失败", log.Field{Key: "uid", Value: uid}, log.Field{Key: "err", Value: err}) + return err + } + } - // //遍历 - // if taskConf.Ontxe != 0 && taskConf.IdAfter != 0 { - // for _, v := range this.worldtaskConf.GetDataList() { - // if v.Group == groupId && v.Key <= taskId { - // wt := &pb.Worldtask{ - // TaskId: v.Key, - // TaskType: v.Des, - // } - // mytask.TaskList = append(mytask.TaskList, wt) - // } + if _, ok := utils.Findx(mytask.TaskList, taskId); ok { + this.Error("GM 任务已完成", log.Field{Key: "taskId", Value: taskId}) + return comm.NewCustomError(pb.ErrorCode_WorldtaskFinihed) + } - // } - // } else { - // wt := &pb.Worldtask{ - // TaskId: taskId, - // TaskType: taskConf.Des, - // } - // mytask.TaskList = append(mytask.TaskList, wt) - // } - // update = map[string]interface{}{ - // "taskList": mytask.TaskList, - // } + taskConf := this.worldtaskConf.GetDataMap()[taskId] + if taskConf == nil { + return comm.NewCustomError(pb.ErrorCode_ConfigNoFound) + } - // if err := this.modelWorldtask.Change(uid, update); err != nil { - // return err - // } + //重置taskList + mytask.TaskList = []int32{} - // rsp := &pb.WorldtaskFinishIdsPush{ - // TaskList: mytask.TaskList, - // } + //遍历 + if taskConf.Ontxe != 0 && taskConf.IdAfter != 0 { + for _, v := range this.worldtaskConf.GetDataList() { + if v.Group == groupId && v.Key <= taskId && v.Des == 2 { //只做主线的des=2 + mytask.TaskList = append(mytask.TaskList, v.Key) + } + } + } else { + mytask.TaskList = append(mytask.TaskList, taskId) + } - return nil //session.SendMsg(string(this.GetType()), "finishids", rsp) + update = map[string]interface{}{ + "taskList": mytask.TaskList, + } + + //当前任务 + nextTaskIds := this.modelWorldtask.findNextTasks(taskId) + + if mytask.CurrentTask == nil { + mytask.CurrentTask = make(map[int32]*pb.Worldtask) + } + + if len(nextTaskIds) == 1 { + mytask.CurrentTask[groupId] = &pb.Worldtask{ + TaskId: nextTaskIds[0], + } + } + + if err := this.modelWorldtask.Change(uid, update); err != nil { + return err + } + + rsp := &pb.WorldtaskFinishIdsPush{} + + return session.SendMsg(string(this.GetType()), "finishids", rsp) }