85 lines
2.2 KiB
Go
85 lines
2.2 KiB
Go
package mainline
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) TaskReceiveCheck(session comm.IUserSession, req *pb.MainlineTaskReceiveReq) (errdata *pb.ErrorData) {
|
|
|
|
return
|
|
}
|
|
|
|
func (this *apiComp) TaskReceive(session comm.IUserSession, req *pb.MainlineTaskReceiveReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
dtask *pb.DBMainTask
|
|
conf *cfg.GameMainAchievementData
|
|
|
|
progress []*pb.ConIProgress
|
|
award []*pb.UserAtno
|
|
err error
|
|
)
|
|
if errdata = this.TaskReceiveCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if conf, err = this.module.configure.getMainAchievementTask(req.Id); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
if dtask, err = this.module.modelTask.getUserDTasks(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if dtask.Tasks[req.Id] == 1 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: fmt.Sprintf("%d received", req.Id),
|
|
}
|
|
return
|
|
}
|
|
|
|
if progress, err = this.module.ModuleBuried.CheckCondition(session, conf.Taskid); err != nil {
|
|
return
|
|
}
|
|
|
|
for _, v := range progress {
|
|
if v.State == pb.BuriedItemFinishState_buried_unfinish {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: "task no finish",
|
|
}
|
|
return
|
|
}
|
|
}
|
|
|
|
if errdata, award = this.module.DispenseAtno(session, conf.Reword, true); errdata != nil {
|
|
return
|
|
}
|
|
|
|
dtask.Tasks[req.Id] = 1
|
|
this.module.modelTask.Change(session.GetUserId(), map[string]interface{}{
|
|
"tasks": dtask.Tasks,
|
|
})
|
|
session.SendMsg(string(this.module.GetType()), "taskreceive", &pb.MainlineTaskReceiveResp{Id: req.Id, Award: award})
|
|
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "MainlineTaskReceiveReq", award)
|
|
})
|
|
return
|
|
}
|