上传代码

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
}
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,115 +149,170 @@ 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)
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
}
}
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
// if curTaskConf.DeliverNpc == 0 {
// //判断当前任务下的条件是否全部是完成状态
// for _, cond := range t.Conds {
// if cond.State == pb.BuriedItemFinishState_buried_finish {
// flag = true
// } else {
// flag = false
// break
// }
// }
// if flag {
// defer func() {
// if curTaskConf.DeliverNpc == 0 {
// if flag {
// 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,
@ -289,7 +344,7 @@ func (this *Worldtask) TCondFinishNotify(uid string, conds []*pb.ConIProgress) {
// }
// }
}
// }
return
}