上传代码

This commit is contained in:
liwei 2023-06-17 01:32:19 +08:00
parent 953b8504f4
commit e85a870156
2 changed files with 183 additions and 128 deletions

View File

@ -125,8 +125,8 @@ func (this *Worldtask) TCondFinishNotify(uid string, conds []*pb.ConIProgress) {
return return
} }
taskConds := make(map[int32][]*pb.CurrentTask) // taskConds := make(map[int32][]*pb.CurrentTask)
finishedCondIds := []*pb.ConIProgress{} // finishedCondIds := []*pb.ConIProgress{}
// for _, cond := range conds { // for _, cond := range conds {
// if cfg, ok := this.configure.worldtaskConf[cond.Conid]; ok { // 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 _, cfg := range worldtaskConf.GetDataList() {
for _, condId := range cfg.Completetask { for _, condId := range cfg.Completetask {
for _, cond := range conds { for _, cond := range conds {
if condId == cond.Conid { //&& cond.State == pb.BuriedItemFinishState_buried_finish { 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 { // if task, ok := userTask.CurrentTasks[cfg.Group]; ok {
var currentTasks []*pb.CurrentTask // tasks[cfg.Key] = cfg.Completetask
for _, t := range task.TaskMap { // var currentTasks []*pb.CurrentTask
if cfg.Key == t.TaskId { // for _, t := range task.TaskMap {
finishedCondIds = append(finishedCondIds, cond) // if cfg.Key == t.TaskId {
currentTasks = append(currentTasks, &pb.CurrentTask{ // finishedCondIds = append(finishedCondIds, cond)
GroupId: cfg.Group, // currentTasks = append(currentTasks, &pb.CurrentTask{
TaskId: cfg.Key, // GroupId: cfg.Group,
Conds: finishedCondIds, // TaskId: cfg.Key,
}) // Conds: finishedCondIds,
} // })
} // }
if currentTasks != nil { // }
taskConds[cfg.Group] = currentTasks // if currentTasks != nil {
} // taskConds[cfg.Group] = currentTasks
} // }
// }
break
} }
} }
} }
} }
if len(finishedCondIds) == 0 { if len(allconds) == 0 {
// this.Debug("未匹配到完成的条件") // this.Debug("未匹配到完成的条件")
return return
} }
var currentTasks []*pb.CurrentTask allconds = utils.RemoveDuplicate(allconds)
for _, tasks := range taskConds { allpass := make(map[int32]*pb.ConIProgress)
for _, t := range tasks { if len(allconds) != len(conds) {
// curTaskConf, err := this.configure.getWorldtaskById(t.TaskId) if conds, err = this.ModuleBuried.CheckCondition(uid, allconds...); err != nil {
// if err != nil || curTaskConf == nil { log.Errorf("调用接口错误:%s", err.Error())
// return 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 { for _, v := range conds {
session.SendMsg(string(this.GetType()), "changecondis", &pb.WorldtaskChangecondisPush{ allpass[v.Conid] = v
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)
// }
// }
// }
// }
// }
} }
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 return
} }

View File

@ -17,8 +17,8 @@ import (
) )
/* /*
服务类型:mainte 服务类型:mainte
服务描述:数据库维护以及GM后台接口 服务 服务描述:数据库维护以及GM后台接口 服务
*/ */
var ( var (
conf = flag.String("conf", "./conf/mainte.yaml", "获取需要启动的服务配置文件") //启动服务的Id conf = flag.String("conf", "./conf/mainte.yaml", "获取需要启动的服务配置文件") //启动服务的Id
@ -47,12 +47,12 @@ func NewService(ops ...rpcx.Option) core.IService {
return s return s
} }
//worker 的服务对象定义 // worker 的服务对象定义
type Service struct { type Service struct {
services.ServiceBase services.ServiceBase
} }
//初始化worker需要的一些系统工具 // 初始化worker需要的一些系统工具
func (this *Service) InitSys() { func (this *Service) InitSys() {
this.ServiceBase.InitSys() this.ServiceBase.InitSys()