From e85a87015641704605c25242448f8136539077b2 Mon Sep 17 00:00:00 2001 From: liwei <2211068034@qq.com> Date: Sat, 17 Jun 2023 01:32:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/worldtask/module.go | 303 +++++++++++++++++++++--------------- services/mainte/main.go | 8 +- 2 files changed, 183 insertions(+), 128 deletions(-) diff --git a/modules/worldtask/module.go b/modules/worldtask/module.go index 3165c19c2..461aded03 100644 --- a/modules/worldtask/module.go +++ b/modules/worldtask/module.go @@ -125,8 +125,8 @@ func (this *Worldtask) TCondFinishNotify(uid string, conds []*pb.ConIProgress) { return } - taskConds := make(map[int32][]*pb.CurrentTask) - finishedCondIds := []*pb.ConIProgress{} + // taskConds := make(map[int32][]*pb.CurrentTask) + // finishedCondIds := []*pb.ConIProgress{} // for _, cond := range conds { // if cfg, ok := this.configure.worldtaskConf[cond.Conid]; ok { @@ -149,147 +149,202 @@ func (this *Worldtask) TCondFinishNotify(uid string, conds []*pb.ConIProgress) { // } // } // } - + tasks := map[int32][]int32{} + taskgroup := map[int32]int32{} + allconds := []int32{} for _, cfg := range worldtaskConf.GetDataList() { for _, condId := range cfg.Completetask { for _, cond := range conds { if condId == cond.Conid { //&& cond.State == pb.BuriedItemFinishState_buried_finish { + tasks[cfg.Key] = cfg.Completetask + taskgroup[cfg.Key] = cfg.Group + allconds = append(allconds, cfg.Completetask...) //校验任务是否是当前任务 - if task, ok := userTask.CurrentTasks[cfg.Group]; ok { - var currentTasks []*pb.CurrentTask - for _, t := range task.TaskMap { - if cfg.Key == t.TaskId { - finishedCondIds = append(finishedCondIds, cond) - currentTasks = append(currentTasks, &pb.CurrentTask{ - GroupId: cfg.Group, - TaskId: cfg.Key, - Conds: finishedCondIds, - }) - } - } - if currentTasks != nil { - taskConds[cfg.Group] = currentTasks - } - } + // if task, ok := userTask.CurrentTasks[cfg.Group]; ok { + // tasks[cfg.Key] = cfg.Completetask + // var currentTasks []*pb.CurrentTask + // for _, t := range task.TaskMap { + // if cfg.Key == t.TaskId { + // finishedCondIds = append(finishedCondIds, cond) + // currentTasks = append(currentTasks, &pb.CurrentTask{ + // GroupId: cfg.Group, + // TaskId: cfg.Key, + // Conds: finishedCondIds, + // }) + // } + // } + // if currentTasks != nil { + // taskConds[cfg.Group] = currentTasks + // } + // } + break } } } } - if len(finishedCondIds) == 0 { + if len(allconds) == 0 { // this.Debug("未匹配到完成的条件") return } - var currentTasks []*pb.CurrentTask - for _, tasks := range taskConds { - for _, t := range tasks { - // curTaskConf, err := this.configure.getWorldtaskById(t.TaskId) - // if err != nil || curTaskConf == nil { - // return - // } - // var flag bool - // if curTaskConf.DeliverNpc == 0 { - // //判断当前任务下的条件是否全部是完成状态 - // for _, cond := range t.Conds { - // if cond.State == pb.BuriedItemFinishState_buried_finish { - // flag = true - // } else { - // flag = false - // } - // } - // if flag { - - // defer func() { - // this.modelWorldtask.taskFinish(session, t.TaskId, userTask, curTaskConf) - // this.modelWorldtask.taskFinishPush(session, userTask, curTaskConf) - // }() - // } - // } - currentTasks = append(currentTasks, t) + allconds = utils.RemoveDuplicate(allconds) + allpass := make(map[int32]*pb.ConIProgress) + if len(allconds) != len(conds) { + if conds, err = this.ModuleBuried.CheckCondition(uid, allconds...); err != nil { + log.Errorf("调用接口错误:%s", err.Error()) + return } } - if len(currentTasks) > 0 { - session.SendMsg(string(this.GetType()), "changecondis", &pb.WorldtaskChangecondisPush{ - Tasks: currentTasks, - }) - - for _, task := range currentTasks { - curTaskConf, err := this.configure.getWorldtaskById(task.TaskId) - if err != nil || curTaskConf == nil { - return - } - - var newconds []*pb.ConIProgress - if tasks, ok := userTask.CurrentTasks[task.GroupId]; ok { - if t, ok := tasks.TaskMap[task.TaskId]; ok { - //更新cond - - for _, t1 := range task.Conds { - for _, t2 := range t.Conds { - if t1.Conid == t2.Conid { - // t2 = t1 - newconds = append(newconds, t1) - } else { - newconds = append(newconds, t2) - } - } - } - t.Conds = newconds - - //判断所有的条件是都是 - var flag bool - for _, cond := range t.Conds { - if cond.State == pb.BuriedItemFinishState_buried_finish { - flag = true - } else { - flag = false - break - } - } - - if curTaskConf.DeliverNpc == 0 { - if flag { - this.modelWorldtask.taskFinish(session, t.TaskId, userTask, curTaskConf) - this.modelWorldtask.taskFinishPush(session, userTask, curTaskConf) - } - } - } - } - } - - update := map[string]interface{}{ - "currentTasks": userTask.CurrentTasks, - } - this.modelWorldtask.Change(uid, update) - - // for _, task := range currentTasks { - // curTaskConf, err := this.configure.getWorldtaskById(task.TaskId) - // if err != nil || curTaskConf == nil { - // return - // } - // var flag bool - // if curTaskConf.DeliverNpc == 0 { - // if tasks, ok := userTask.CurrentTasks[task.GroupId]; ok { - // if t, ok := tasks.TaskMap[task.TaskId]; ok { - // for _, cond := range t.Conds { - // if cond.State == pb.BuriedItemFinishState_buried_finish { - // flag = true - // } else { - // flag = false - // } - // } - // if flag { - // this.modelWorldtask.taskFinish(session, t.TaskId, userTask, curTaskConf) - // this.modelWorldtask.taskFinishPush(session, userTask, curTaskConf) - // } - // } - // } - // } - // } + for _, v := range conds { + allpass[v.Conid] = v } + fishtask := []int32{} + var currentTasks []*pb.CurrentTask = make([]*pb.CurrentTask, 0, len(tasks)) + for k, onds := range tasks { + ok := true + ctask := &pb.CurrentTask{ + GroupId: taskgroup[k], + TaskId: k, + Conds: make([]*pb.ConIProgress, 0), + } + + for _, v := range onds { + ctask.Conds = append(ctask.Conds, allpass[v]) + if allpass[v].State != pb.BuriedItemFinishState_buried_finish { + ok = false + } + } + currentTasks = append(currentTasks, ctask) + if ok { + fishtask = append(fishtask, k) + } + + } + session.SendMsg(string(this.GetType()), "changecondis", &pb.WorldtaskChangecondisPush{ + Tasks: currentTasks, + }) + if len(fishtask) > 0 { + for _, v := range fishtask { + curTaskConf, _ := this.configure.getWorldtaskById(v) + if curTaskConf.DeliverNpc == 0 { + this.modelWorldtask.taskFinish(session, v, userTask, curTaskConf) + this.modelWorldtask.taskFinishPush(session, userTask, curTaskConf) + } + } + } + + // var currentTasks []*pb.CurrentTask + // for _, tasks := range taskConds { + // for _, t := range tasks { + // // curTaskConf, err := this.configure.getWorldtaskById(t.TaskId) + // // if err != nil || curTaskConf == nil { + // // return + // // } + // // var flag bool + // // if curTaskConf.DeliverNpc == 0 { + // // //判断当前任务下的条件是否全部是完成状态 + // // for _, cond := range t.Conds { + // // if cond.State == pb.BuriedItemFinishState_buried_finish { + // // flag = true + // // } else { + // // flag = false + // // } + // // } + // // if flag { + + // // defer func() { + // // this.modelWorldtask.taskFinish(session, t.TaskId, userTask, curTaskConf) + // // this.modelWorldtask.taskFinishPush(session, userTask, curTaskConf) + // // }() + // // } + // // } + // currentTasks = append(currentTasks, t) + // } + // } + + // if len(currentTasks) > 0 { + // session.SendMsg(string(this.GetType()), "changecondis", &pb.WorldtaskChangecondisPush{ + // Tasks: currentTasks, + // }) + + // for _, task := range currentTasks { + // curTaskConf, err := this.configure.getWorldtaskById(task.TaskId) + // if err != nil || curTaskConf == nil { + // return + // } + + // var newconds []*pb.ConIProgress + // if tasks, ok := userTask.CurrentTasks[task.GroupId]; ok { + // if t, ok := tasks.TaskMap[task.TaskId]; ok { + // //更新cond + + // for _, t1 := range task.Conds { + // for _, t2 := range t.Conds { + // if t1.Conid == t2.Conid { + // // t2 = t1 + // newconds = append(newconds, t1) + // } else { + // newconds = append(newconds, t2) + // } + // } + // } + // t.Conds = newconds + + // //判断所有的条件是都是 + // var flag bool + // for _, cond := range t.Conds { + // if cond.State == pb.BuriedItemFinishState_buried_finish { + // flag = true + // } else { + // flag = false + // break + // } + // } + + // if curTaskConf.DeliverNpc == 0 { + // if flag { + // this.modelWorldtask.taskFinish(session, t.TaskId, userTask, curTaskConf) + // this.modelWorldtask.taskFinishPush(session, userTask, curTaskConf) + // } + // } + // } + // } + // } + + update := map[string]interface{}{ + "currentTasks": userTask.CurrentTasks, + } + this.modelWorldtask.Change(uid, update) + + // for _, task := range currentTasks { + // curTaskConf, err := this.configure.getWorldtaskById(task.TaskId) + // if err != nil || curTaskConf == nil { + // return + // } + // var flag bool + // if curTaskConf.DeliverNpc == 0 { + // if tasks, ok := userTask.CurrentTasks[task.GroupId]; ok { + // if t, ok := tasks.TaskMap[task.TaskId]; ok { + // for _, cond := range t.Conds { + // if cond.State == pb.BuriedItemFinishState_buried_finish { + // flag = true + // } else { + // flag = false + // } + // } + // if flag { + // this.modelWorldtask.taskFinish(session, t.TaskId, userTask, curTaskConf) + // this.modelWorldtask.taskFinishPush(session, userTask, curTaskConf) + // } + // } + // } + // } + // } + + // } return } diff --git a/services/mainte/main.go b/services/mainte/main.go index a8e4bd3f3..0599bb1fa 100644 --- a/services/mainte/main.go +++ b/services/mainte/main.go @@ -17,8 +17,8 @@ import ( ) /* - 服务类型:mainte - 服务描述:数据库维护以及GM后台接口 服务 +服务类型:mainte +服务描述:数据库维护以及GM后台接口 服务 */ var ( conf = flag.String("conf", "./conf/mainte.yaml", "获取需要启动的服务配置文件") //启动服务的Id @@ -47,12 +47,12 @@ func NewService(ops ...rpcx.Option) core.IService { return s } -//worker 的服务对象定义 +// worker 的服务对象定义 type Service struct { services.ServiceBase } -//初始化worker需要的一些系统工具 +// 初始化worker需要的一些系统工具 func (this *Service) InitSys() { this.ServiceBase.InitSys()