update
This commit is contained in:
parent
62834cc22c
commit
e60d7fb163
@ -59,9 +59,11 @@ func (a *apiComp) Accept(session comm.IUserSession, req *pb.WorldtaskAcceptReq)
|
||||
session.SendMsg(string(a.module.GetType()), "accept", rsp)
|
||||
|
||||
//判断是否要结束任务
|
||||
if (len(curTaskConf.Completetask) == 1 && curTaskConf.Completetask[0] == 0) ||
|
||||
len(curTaskConf.Completetask) == 0 {
|
||||
|
||||
if (len(curTaskConf.Completetask) == 1 && curTaskConf.Completetask[0] == 0 ||
|
||||
len(curTaskConf.Completetask) == 0) && curTaskConf.DeliverNpc == 0 {
|
||||
//结束任务
|
||||
a.module.modelWorldtask.taskFinish(session, req.GroupId, req.TaskId, myWorldtask, curTaskConf)
|
||||
a.module.modelWorldtask.taskFinishPush(session, myWorldtask, curTaskConf)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -23,6 +23,14 @@ func (this *apiComp) CompleteCondi(session comm.IUserSession, req *pb.WorldtaskC
|
||||
}
|
||||
rsp := &pb.WorldtaskCompleteCondiResp{}
|
||||
uid := session.GetUserId()
|
||||
|
||||
// 当前任务配置
|
||||
curTaskConf, err := this.module.configure.getWorldtaskById(req.TaskId)
|
||||
if err != nil || curTaskConf == nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return
|
||||
}
|
||||
|
||||
myWorldtask, err := this.module.modelWorldtask.getWorldtask(uid)
|
||||
if err != nil {
|
||||
this.module.Error("获取玩家世界任务失败", log.Field{Key: "uid", Value: uid}, log.Field{Key: "err", Value: err.Error()})
|
||||
@ -65,5 +73,12 @@ 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, myWorldtask, curTaskConf)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
"go_dreamfactory/pb"
|
||||
"go_dreamfactory/utils"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
@ -73,13 +74,16 @@ func (this *apiComp) Finish(session comm.IUserSession, req *pb.WorldtaskFinishRe
|
||||
updateCheckCond := func(userTask *pb.DBWorldtask, nextTaskId int32) *pb.DBWorldtask {
|
||||
//检查下个任务的完成条件
|
||||
nextTaskConf, err := this.module.configure.getWorldtaskById(nextTaskId)
|
||||
if err != nil || curTaskConf == nil {
|
||||
if err != nil {
|
||||
code = pb.ErrorCode_ConfigNoFound
|
||||
return nil
|
||||
}
|
||||
if nextTaskConf == nil {
|
||||
return nil
|
||||
}
|
||||
if nextTaskConf.Des == 1 || nextTaskConf.Des == 4 {
|
||||
return nil
|
||||
}
|
||||
|
||||
if userTask.CurrentTask == nil {
|
||||
userTask.CurrentTask = make(map[int32]*pb.Worldtask)
|
||||
@ -131,6 +135,7 @@ func (this *apiComp) Finish(session comm.IUserSession, req *pb.WorldtaskFinishRe
|
||||
}
|
||||
userTask.CurrentTask[nextTaskConf.Group] = nwt
|
||||
update["currentTask"] = userTask.CurrentTask
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,13 +178,13 @@ func (this *apiComp) Finish(session comm.IUserSession, req *pb.WorldtaskFinishRe
|
||||
}
|
||||
} else {
|
||||
// 章节完成
|
||||
// if _, ok := utils.Findx(userTask.Chapters, req.GroupId); !ok {
|
||||
// userTask.Chapters = append(userTask.Chapters, req.GroupId)
|
||||
// update := map[string]interface{}{
|
||||
// "chapters": userTask.Chapters,
|
||||
// }
|
||||
// this.module.modelWorldtask.Change(uid, update)
|
||||
// }
|
||||
if _, ok := utils.Findx(userTask.Chapters, req.GroupId); !ok {
|
||||
userTask.Chapters = append(userTask.Chapters, req.GroupId)
|
||||
update := map[string]interface{}{
|
||||
"chapters": userTask.Chapters,
|
||||
}
|
||||
this.module.modelWorldtask.Change(uid, update)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,3 +148,138 @@ func (this *ModelWorldtask) findNextTasks(parentTaskId int32) (taskIds []int32)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (this *ModelWorldtask) updateCheckCond(uid string, userTask *pb.DBWorldtask, nextTaskId int32) *pb.DBWorldtask {
|
||||
//检查下个任务的完成条件
|
||||
nextTaskConf, err := this.moduleWorldtask.configure.getWorldtaskById(nextTaskId)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if nextTaskConf == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if userTask.CurrentTask == nil {
|
||||
userTask.CurrentTask = make(map[int32]*pb.Worldtask)
|
||||
}
|
||||
|
||||
update := make(map[string]interface{})
|
||||
if (len(nextTaskConf.Completetask) == 1 && nextTaskConf.Completetask[0] == 0) ||
|
||||
len(nextTaskConf.Completetask) == 0 {
|
||||
wt := &pb.Worldtask{
|
||||
TaskId: nextTaskId,
|
||||
TaskType: nextTaskConf.Des,
|
||||
CondiIds: []int32{},
|
||||
}
|
||||
userTask.CurrentTask[nextTaskConf.Group] = wt
|
||||
update["currentTask"] = userTask.CurrentTask
|
||||
} else {
|
||||
for _, condiId := range nextTaskConf.Completetask {
|
||||
if condiId == 0 {
|
||||
continue
|
||||
}
|
||||
nwt, ok := userTask.CurrentTask[nextTaskConf.Group]
|
||||
if ok {
|
||||
nwt.TaskId = nextTaskId
|
||||
nwt.TaskType = nextTaskConf.Des
|
||||
} else {
|
||||
nwt = &pb.Worldtask{
|
||||
TaskId: nextTaskId,
|
||||
TaskType: nextTaskConf.Des,
|
||||
}
|
||||
}
|
||||
if m, err := this.service.GetModule(comm.ModuleRtask); err == nil {
|
||||
iwt, ok := m.(comm.IRtask)
|
||||
if ok {
|
||||
if mc := iwt.CheckCondi(uid, condiId); mc != pb.ErrorCode_Success {
|
||||
this.moduleWorldtask.Debug("任务完成条件不满足",
|
||||
log.Field{Key: "uid", Value: uid},
|
||||
log.Field{Key: "taskId", Value: nextTaskId},
|
||||
log.Field{Key: "condiId", Value: condiId},
|
||||
)
|
||||
} else {
|
||||
if ok {
|
||||
nwt.CondiIds = append(nwt.CondiIds, condiId)
|
||||
} else {
|
||||
condiIds := []int32{condiId}
|
||||
nwt.CondiIds = condiIds
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
userTask.CurrentTask[nextTaskConf.Group] = nwt
|
||||
update["currentTask"] = userTask.CurrentTask
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if len(update) > 0 {
|
||||
if err := this.Change(uid, update); err != nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return userTask
|
||||
}
|
||||
|
||||
func (this *ModelWorldtask) taskFinishPush(session comm.IUserSession, userTask *pb.DBWorldtask, curTaskConf *cfg.GameWorldTaskData) {
|
||||
nextTaskIds := this.findNextTasks(curTaskConf.Key)
|
||||
this.moduleWorldtask.Debug("nextTaskIds", log.Field{Key: "nextTaskIds", Value: nextTaskIds})
|
||||
|
||||
nextTask := make(map[int32]*pb.Worldtask)
|
||||
for _, next := range nextTaskIds {
|
||||
ut := this.updateCheckCond(session.GetUserId(), userTask, next)
|
||||
if ut != nil {
|
||||
for k, v := range ut.CurrentTask {
|
||||
nextTask[k] = &pb.Worldtask{
|
||||
TaskId: v.TaskId,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if curTaskConf.IdAfter != 0 {
|
||||
// 任务完成推送
|
||||
session.SendMsg(string(this.moduleWorldtask.GetType()), WorldtaskNexttaskPush, &pb.WorldtaskNexttaskPush{
|
||||
NextTask: nextTask,
|
||||
})
|
||||
} else {
|
||||
// 章节完成
|
||||
// if _, ok := utils.Findx(userTask.Chapters, req.GroupId); !ok {
|
||||
// userTask.Chapters = append(userTask.Chapters, req.GroupId)
|
||||
// update := map[string]interface{}{
|
||||
// "chapters": userTask.Chapters,
|
||||
// }
|
||||
// this.module.modelWorldtask.Change(uid, update)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
func (this *ModelWorldtask) taskFinish(session comm.IUserSession, groupId, taskId int32, userTask *pb.DBWorldtask, curTaskConf *cfg.GameWorldTaskData) {
|
||||
if err := this.finishTask(groupId, taskId, userTask); err != nil {
|
||||
this.moduleWorldtask.Error("完成任务失败",
|
||||
log.Field{Key: "uid", Value: session.GetUserId()},
|
||||
log.Field{Key: "groupId", Value: groupId},
|
||||
log.Field{Key: "taskId", Value: taskId},
|
||||
log.Field{Key: "err", Value: err.Error()},
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
//判断是否配置了通知module
|
||||
if len(curTaskConf.Module) == 0 {
|
||||
this.moduleWorldtask.DispenseRes(session, curTaskConf.Reword, true)
|
||||
} else {
|
||||
for _, m := range curTaskConf.Module {
|
||||
i, err := this.service.GetModule(core.M_Modules(m))
|
||||
if err != nil {
|
||||
this.moduleWorldtask.Errorln(err)
|
||||
continue
|
||||
}
|
||||
|
||||
if ic, ok := i.(comm.ITaskComplete); ok {
|
||||
ic.TaskComplete(session, taskId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ func (this *Worldtask) TaskCondFinishNotify(session comm.IUserSession, condId in
|
||||
finishedTaskIds := make(map[int32]int32) //达成的任务条件
|
||||
for _, c := range this.worldtaskConf.GetDataList() {
|
||||
for _, v := range c.Completetask {
|
||||
if v == condId {
|
||||
if v == condId {
|
||||
finishedTaskIds[c.Group] = c.Key
|
||||
groupId = c.Group
|
||||
taskId = c.Key
|
||||
@ -107,7 +107,9 @@ func (this *Worldtask) TaskCondFinishNotify(session comm.IUserSession, condId in
|
||||
TaskId: taskId,
|
||||
CondiIds: wt.CondiIds,
|
||||
})
|
||||
this.Debug("推送完成条件", log.Field{Key: "condiIds", Value: taskId})
|
||||
this.Debug("推送完成条件",
|
||||
log.Field{Key: "condiIds", Value: wt.CondiIds},
|
||||
log.Field{Key: "taskId", Value: taskId})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user