61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
package arena
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/mgo"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
// 参数校验
|
|
func (this *apiComp) TaskReceiveCheck(session comm.IUserSession, req *pb.ArenaTaskReceiveReq) (errdata *pb.ErrorData) {
|
|
if req.Tid == 0 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// /获取自己的排行榜信息
|
|
func (this *apiComp) TaskReceive(session comm.IUserSession, req *pb.ArenaTaskReceiveReq) (errdata *pb.ErrorData) {
|
|
var (
|
|
// global *cfg.GameGlobalData
|
|
info *pb.DBArenaUser
|
|
need []*cfg.Gameatn
|
|
err error
|
|
atno []*pb.UserAtno
|
|
)
|
|
if errdata = this.TaskReceiveCheck(session, req); errdata != nil {
|
|
return
|
|
}
|
|
if info, err = this.module.modelArena.queryPlayerInfo(session.GetUserId()); err != nil && err != mgo.MongodbNil {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ConfigNoFound,
|
|
Title: pb.ErrorCode_CacheReadError.ToString(),
|
|
Message: err.Error(),
|
|
}
|
|
return
|
|
}
|
|
|
|
if info.Tasks[req.Tid] == 1 {
|
|
errdata = &pb.ErrorData{
|
|
Code: pb.ErrorCode_ReqParameterError,
|
|
Title: pb.ErrorCode_ReqParameterError.ToString(),
|
|
Message: fmt.Sprintf("%d received", req.Tid),
|
|
}
|
|
return
|
|
}
|
|
info.Tasks[req.Tid] = 1
|
|
|
|
session.SendMsg(string(this.module.GetType()), "buy", &pb.MoonfantasyBuyResp{Issucc: true, BattleNum: info.Buynum})
|
|
|
|
go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) {
|
|
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResAddType, "MoonfantasyBuyReq", atno)
|
|
this.module.WriteUserLog(session.GetUserId(), req, comm.GMResDelType, "MoonfantasyBuyReq", need) // 消耗资源
|
|
})
|
|
return
|
|
}
|