79 lines
2.2 KiB
Go
79 lines
2.2 KiB
Go
package worldtask
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
)
|
|
|
|
// 任务完成条件
|
|
func (this *apiComp) CompleteCondiCheck(session comm.IUserSession, req *pb.WorldtaskCompleteCondiReq) (code pb.ErrorCode) {
|
|
if req.GroupId <= 0 || req.TaskId <= 0 || req.CondiId <= 0 {
|
|
code = *pb.ErrorCode_ReqParameterError.Enum()
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) CompleteCondi(session comm.IUserSession, req *pb.WorldtaskCompleteCondiReq) (code pb.ErrorCode, data *pb.ErrorData) {
|
|
if code = this.CompleteCondiCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
data = &pb.ErrorData{}
|
|
rsp := &pb.WorldtaskCompleteCondiResp{}
|
|
uid := session.GetUserId()
|
|
|
|
// 当前任务配置
|
|
curTaskConf, err := this.module.configure.getWorldtaskById(req.TaskId)
|
|
if err != nil || curTaskConf == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
if (len(curTaskConf.Completetask) == 1 && curTaskConf.Completetask[0] == 0) ||
|
|
len(curTaskConf.Completetask) == 0 {
|
|
code = pb.ErrorCode_WorldtaskNoProcess
|
|
data.Title = code.ToString()
|
|
data.Message = "无完成条件"
|
|
return
|
|
}
|
|
|
|
myWorldtask, err := this.module.modelWorldtask.getWorldtask(uid)
|
|
if err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
data.Title = code.ToString()
|
|
return
|
|
}
|
|
|
|
myWorldtask.Uid = uid
|
|
wt := myWorldtask.CurrentTask[req.GroupId]
|
|
|
|
conds, err := this.module.ModuleBuried.CheckCondition(uid, req.CondiId)
|
|
if err != nil {
|
|
code = pb.ErrorCode_ExternalModule
|
|
data.Title = code.ToString()
|
|
data.Message = comm.NewExternalModuleErr("buried", "CheckCondition", uid, req.CondiId).Error()
|
|
}
|
|
for _, cond := range conds {
|
|
if cond.State == pb.BuriedItemFinishState_buried_finish {
|
|
wt.CondiIds = append(wt.CondiIds, cond.Conid)
|
|
}
|
|
}
|
|
|
|
myWorldtask.CurrentTask[req.GroupId] = wt
|
|
|
|
update := map[string]interface{}{
|
|
"currentTask": myWorldtask.CurrentTask,
|
|
}
|
|
if err := this.module.modelWorldtask.Change(uid, update); err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
|
|
this.sendMsg(session, WorldtaskComplete, rsp)
|
|
|
|
//结束任务
|
|
if curTaskConf.DeliverNpc == 0 {
|
|
this.module.modelWorldtask.taskFinish(session, req.GroupId, req.TaskId, myWorldtask, curTaskConf)
|
|
this.module.modelWorldtask.taskFinishPush(session, req.GroupId, myWorldtask, curTaskConf)
|
|
}
|
|
return
|
|
}
|