go_dreamfactory/modules/worldtask/api_mine.go

94 lines
2.3 KiB
Go

package worldtask
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/pb"
"go_dreamfactory/utils"
)
var (
dailyDes int32 = 1
weekDes int32 = 4
)
// 我的世界任务
func (this *apiComp) MineCheck(session comm.IUserSession, req *pb.WorldtaskMineReq) (errdata *pb.ErrorData) {
return
}
func (this *apiComp) Mine(session comm.IUserSession, req *pb.WorldtaskMineReq) (errdata *pb.ErrorData) {
uid := session.GetUserId()
user := this.module.ModuleUser.GetUser(uid)
if user == nil {
errdata = &pb.ErrorData{
Code: pb.ErrorCode_UserNofound,
Title: pb.ErrorCode_UserNofound.ToString(),
Message: "战斗记录是空",
}
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()})
errdata = &pb.ErrorData{
Code: pb.ErrorCode_DBError,
Title: pb.ErrorCode_DBError.ToString(),
Message: err.Error(),
}
return
}
if myWorldtask.CurrentTask == nil {
myWorldtask.CurrentTask = make(map[int32]*pb.Worldtask)
}
//查询当前所有任务组下的完成条件数据
var condIds []int32
condMap := make(map[int32][]int32)
for k, v := range myWorldtask.CurrentTask {
cfg, err := this.module.configure.getWorldtaskById(v.TaskId)
if err != nil {
code = pb.ErrorCode_ConfigNoFound
data.Title = code.ToString()
data.Message = err.Error()
return
}
if ((len(cfg.Completetask) == 1 && cfg.Completetask[0] > 0) &&
len(cfg.Completetask) > 0) {
condIds = append(condIds, cfg.Completetask...)
condMap[k] = cfg.Completetask
}
}
condIds = utils.RemoveDuplicate(condIds)
conds, err := this.module.ModuleBuried.CheckCondition(uid, condIds...)
if err != nil {
code = pb.ErrorCode_ExternalModule
data.Title = code.ToString()
data.Message = comm.NewExternalModuleErr("buried", "CheckCondition", condIds).Error()
return
}
for k, v := range condMap {
mw := myWorldtask.CurrentTask[k]
for _, cond := range conds {
if _, ok := utils.Findx(v, cond.Conid); ok {
mw.Conds = append(mw.Conds, cond)
}
}
}
this.module.modelWorldtask.updateRandomTask(uid, myWorldtask)
rsp := &pb.WorldtaskMineResp{
Task: myWorldtask,
}
this.sendMsg(session, WorldtaskSubtypeMine, rsp)
return
}