95 lines
2.5 KiB
Go
95 lines
2.5 KiB
Go
package wtask
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) AcceptCheck(session comm.IUserSession, req *pb.WTaskAcceptReq) (errdata *pb.ErrorData) {
|
|
|
|
return
|
|
}
|
|
|
|
// /获取系统公告
|
|
func (this *apiComp) Accept(session comm.IUserSession, req *pb.WTaskAcceptReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
wtask *pb.DBWTask
|
|
conf *cfg.GameWorldTaskData
|
|
progress []*pb.DBWTaskItem
|
|
update map[string]interface{} = make(map[string]interface{})
|
|
ok bool
|
|
err error
|
|
)
|
|
if errdata = this.AcceptCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
|
|
if conf, err = this.module.configure.gettaskconfconfigure(req.Tid); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_ConfigNoFound.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if wtask, err = this.module.modelwtask.getUserWTasks(session.GetUserId()); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
ok = false
|
|
for _, v := range wtask.Activations {
|
|
if req.Tid == v {
|
|
ok = true
|
|
}
|
|
}
|
|
|
|
if !ok {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: fmt.Sprintf("task:%d no fund in Activations:%v", req.Tid, wtask.Activations),
|
|
}
|
|
return
|
|
}
|
|
|
|
for i, v := range wtask.Activations {
|
|
if v == req.Tid {
|
|
wtask.Activations = append(wtask.Activations[0:i], wtask.Activations[i+1:]...)
|
|
break
|
|
}
|
|
}
|
|
wtask.Accepts = append(wtask.Accepts, req.Tid)
|
|
update["activations"] = wtask.Activations
|
|
update["accepts"] = wtask.Accepts
|
|
if err = this.module.ModuleBuried.ActiveCondition(session.GetUserId(), conf.Completetask...); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ExternalModule,
|
|
Title: pb.ErrorCode_ExternalModule.ToString(),
|
|
Message: fmt.Sprintf("ModuleBuried.ActiveCondition uid:%s condiIds:%v", session.GetUserId(), conf.Completetask),
|
|
}
|
|
return
|
|
}
|
|
if progress, errdata = this.module.pushtaskprogress(session, wtask, false); errdata != nil {
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "accept", &pb.WTaskAcceptResp{Tid: req.Tid, Activations: wtask.Activations, Accepts: progress})
|
|
|
|
if err = this.module.modelwtask.Change(session.GetUserId(), update); err != nil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_DBError,
|
|
Title: pb.ErrorCode_DBError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
return
|
|
}
|