61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
package arena
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/mgo"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
//参数校验
|
|
func (this *apiComp) BuyCheck(session comm.IUserSession, req *pb.ArenaBuyReq) (code pb.ErrorCode) {
|
|
if req.BuyNum == 0 {
|
|
code = pb.ErrorCode_ReqParameterError
|
|
}
|
|
return
|
|
}
|
|
|
|
///获取自己的排行榜信息
|
|
func (this *apiComp) Buy(session comm.IUserSession, req *pb.ArenaBuyReq) (code pb.ErrorCode, data proto.Message) {
|
|
var (
|
|
info *pb.DBArenaUser
|
|
challenge *cfg.GameArenaBuyChallengeData
|
|
need []*cfg.Gameatn
|
|
err error
|
|
)
|
|
if code = this.BuyCheck(session, req); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
if info, err = this.module.modelArena.queryPlayerInfo(session.GetUserId()); err != nil && err != mgo.MongodbNil {
|
|
code = pb.ErrorCode_CacheReadError
|
|
return
|
|
}
|
|
|
|
need = make([]*cfg.Gameatn, 0)
|
|
for i := int32(0); i < req.BuyNum; i++ {
|
|
if challenge, err = this.module.configure.GetchallengeData(info.Buynum + i + 1); err != nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
if challenge == nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
need = append(need, challenge.Need...)
|
|
}
|
|
|
|
if code = this.module.ConsumeRes(session, need, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
info.Buynum += req.BuyNum
|
|
info.Ticket += req.BuyNum
|
|
this.module.modelArena.Change(session.GetUserId(), map[string]interface{}{
|
|
"ticket": info.Ticket,
|
|
"buynum": info.Buynum,
|
|
})
|
|
session.SendMsg(string(this.module.GetType()), "buy", &pb.MoonfantasyBuyResp{Issucc: true, BattleNum: info.Ticket})
|
|
return
|
|
}
|