任务中多条件校验

This commit is contained in:
wh_zcy 2023-06-15 17:42:25 +08:00
parent edc845ca0e
commit 0d621cd9ae
5 changed files with 135 additions and 25 deletions

View File

@ -37,6 +37,11 @@ func (this *modelTask) getTaskRecord(uid string) (*pb.DBTujianTask, error) {
} }
func (this *modelTask) TCondFinishNotify(uid string, conds []*pb.ConIProgress) { func (this *modelTask) TCondFinishNotify(uid string, conds []*pb.ConIProgress) {
session, ok := this.module.GetUserSession(uid)
if !ok {
this.module.Errorln("TCondFinishNotify 获取session失败")
return
}
this.module.Debug("铁匠铺任务通知", log.Field{Key: "uid", Value: uid}, log.Field{Key: "conds", Value: conds}) this.module.Debug("铁匠铺任务通知", log.Field{Key: "uid", Value: uid}, log.Field{Key: "conds", Value: conds})
confList, err := this.module.configure.GetSmithyTasks() confList, err := this.module.configure.GetSmithyTasks()
if err != nil { if err != nil {
@ -62,6 +67,15 @@ func (this *modelTask) TCondFinishNotify(uid string, conds []*pb.ConIProgress) {
} }
if v.State == pb.BuriedItemFinishState_buried_finish { if v.State == pb.BuriedItemFinishState_buried_finish {
tt.Received = 1 tt.Received = 1
i, err := this.module.service.GetModule(comm.ModuleReddot)
if err != nil {
this.module.Error(err.Error())
return
}
if b, y := i.(comm.IReddot); y {
b.PushReddot(session, comm.Reddot17107)
}
} }
dt.Tasks = append(dt.Tasks, tt) dt.Tasks = append(dt.Tasks, tt)
if err := this.Add(uid, dt); err != nil { if err := this.Add(uid, dt); err != nil {

View File

@ -7,6 +7,7 @@ package smithy
import ( import (
"go_dreamfactory/comm" "go_dreamfactory/comm"
"go_dreamfactory/lego/base"
"go_dreamfactory/lego/core" "go_dreamfactory/lego/core"
"go_dreamfactory/modules" "go_dreamfactory/modules"
"go_dreamfactory/pb" "go_dreamfactory/pb"
@ -18,6 +19,7 @@ import (
type Smithy struct { type Smithy struct {
modules.ModuleBase modules.ModuleBase
service base.IRPCXService
modelTrade *modelTrade modelTrade *modelTrade
api *apiComp api *apiComp
configure *configureComp configure *configureComp
@ -36,7 +38,7 @@ func (this *Smithy) GetType() core.M_Modules {
func (this *Smithy) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) { func (this *Smithy) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
err = this.ModuleBase.Init(service, module, options) err = this.ModuleBase.Init(service, module, options)
this.service = service.(base.IRPCXService)
return return
} }

View File

@ -91,28 +91,47 @@ func (a *apiComp) Accept(session comm.IUserSession, req *pb.WorldtaskAcceptReq)
return return
} else { } else {
task.NpcStatus = 1 task.NpcStatus = 1
for _, cid := range curTaskConf.Completetask {
task.Conds = append(task.Conds, &pb.ConIProgress{
Conid: cid,
})
}
} }
break break
} else { } else {
if tasks.TaskMap == nil { if tasks.TaskMap == nil {
tasks.TaskMap = make(map[int32]*pb.Worldtask) tasks.TaskMap = make(map[int32]*pb.Worldtask)
} }
tasks.TaskMap[task.TaskId] = &pb.Worldtask{
task := &pb.Worldtask{
TaskId: req.TaskId, TaskId: req.TaskId,
TaskType: curTaskConf.Des, TaskType: curTaskConf.Des,
NpcStatus: 1, //接取 NpcStatus: 1, //接取
} }
for _, cid := range curTaskConf.Completetask {
task.Conds = append(task.Conds, &pb.ConIProgress{
Conid: cid,
})
}
tasks.TaskMap[task.TaskId] = task
} }
} }
} else { } else {
tasks = &pb.Worldtasks{ tasks = &pb.Worldtasks{
TaskMap: make(map[int32]*pb.Worldtask), TaskMap: make(map[int32]*pb.Worldtask),
} }
tasks.TaskMap[req.TaskId] = &pb.Worldtask{ task := &pb.Worldtask{
TaskId: req.TaskId, TaskId: req.TaskId,
TaskType: curTaskConf.Des, TaskType: curTaskConf.Des,
NpcStatus: 1, //接取 NpcStatus: 1, //接取
} }
for _, cid := range curTaskConf.Completetask {
task.Conds = append(task.Conds, &pb.ConIProgress{
Conid: cid,
})
}
tasks.TaskMap[req.TaskId] = task
myWorldtask.CurrentTasks[curTaskConf.Group] = tasks myWorldtask.CurrentTasks[curTaskConf.Group] = tasks
} }

View File

@ -122,7 +122,7 @@ func (this *apiComp) Finish(session comm.IUserSession, req *pb.WorldtaskFinishRe
errdata = &pb.ErrorData{ errdata = &pb.ErrorData{
Code: pb.ErrorCode_RtaskCondiNoReach, Code: pb.ErrorCode_RtaskCondiNoReach,
Title: pb.ErrorCode_RtaskCondiNoReach.ToString(), Title: pb.ErrorCode_RtaskCondiNoReach.ToString(),
Message: fmt.Sprintf("世界任务[%v] 条件[%v]未达成", req.TaskId, curTaskConf.Completetask), Message: fmt.Sprintf("世界任务[%v] 条件[%v]未达成", req.TaskId, cond.Conid),
} }
return return
} }

View File

@ -184,28 +184,28 @@ func (this *Worldtask) TCondFinishNotify(uid string, conds []*pb.ConIProgress) {
var currentTasks []*pb.CurrentTask var currentTasks []*pb.CurrentTask
for _, tasks := range taskConds { for _, tasks := range taskConds {
for _, t := range tasks { for _, t := range tasks {
curTaskConf, err := this.configure.getWorldtaskById(t.TaskId) // curTaskConf, err := this.configure.getWorldtaskById(t.TaskId)
if err != nil || curTaskConf == nil { // if err != nil || curTaskConf == nil {
return // return
} // }
var flag bool // var flag bool
if curTaskConf.DeliverNpc == 0 { // if curTaskConf.DeliverNpc == 0 {
//判断当前任务下的条件是否全部是完成状态 // //判断当前任务下的条件是否全部是完成状态
for _, s := range t.Conds { // for _, cond := range t.Conds {
if s.State == pb.BuriedItemFinishState_buried_finish { // if cond.State == pb.BuriedItemFinishState_buried_finish {
flag = true // flag = true
} else { // } else {
flag = false // flag = false
} // }
} // }
if flag { // if flag {
defer func() {
this.modelWorldtask.taskFinish(session, t.TaskId, userTask, curTaskConf)
this.modelWorldtask.taskFinishPush(session, userTask, curTaskConf)
}()
}
} // defer func() {
// this.modelWorldtask.taskFinish(session, t.TaskId, userTask, curTaskConf)
// this.modelWorldtask.taskFinishPush(session, userTask, curTaskConf)
// }()
// }
// }
currentTasks = append(currentTasks, t) currentTasks = append(currentTasks, t)
} }
} }
@ -214,6 +214,81 @@ func (this *Worldtask) TCondFinishNotify(uid string, conds []*pb.ConIProgress) {
session.SendMsg(string(this.GetType()), "changecondis", &pb.WorldtaskChangecondisPush{ session.SendMsg(string(this.GetType()), "changecondis", &pb.WorldtaskChangecondisPush{
Tasks: currentTasks, 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