70 lines
2.1 KiB
Go
70 lines
2.1 KiB
Go
package arena
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/sys/mgo"
|
|
"go_dreamfactory/pb"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
//参数校验
|
|
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 *pb.ErrorData) {
|
|
var (
|
|
// global *cfg.GameGlobalData
|
|
info *pb.DBArenaUser
|
|
challenge *cfg.GameArenaBuyChallengeData
|
|
need []*cfg.Gameatn
|
|
maxbuy, vipbuy int
|
|
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
|
|
}
|
|
this.module.modelArena.recoverTicket(session, info)
|
|
|
|
if maxbuy, err = this.module.configure.GetchallengeDataCount(); err != nil {
|
|
code = pb.ErrorCode_ConfigNoFound
|
|
return
|
|
}
|
|
vipbuy = int(this.module.privilege.GetCountByPrivilegeId(session.GetUserId(), comm.PrivilegeType5))
|
|
need = make([]*cfg.Gameatn, 0)
|
|
for i := int32(0); i < req.BuyNum; i++ {
|
|
if int(info.Buynum+i+1) > maxbuy+vipbuy {
|
|
code = pb.ErrorCode_ArenaTicketBuyUp
|
|
return
|
|
}
|
|
if challenge, err = this.module.configure.GetchallengeData(info.Buynum + i + 1); err != nil || 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
|
|
if code = this.module.DispenseRes(session, []*cfg.Gameatn{{A: comm.ItemType, T: comm.ArenaTicket, N: req.BuyNum}}, true); code != pb.ErrorCode_Success {
|
|
return
|
|
}
|
|
// info.Ticket += req.BuyNum
|
|
if err = this.module.modelArena.updateArenaUserInfo(info); err != nil {
|
|
code = pb.ErrorCode_DBError
|
|
return
|
|
}
|
|
session.SendMsg(string(this.module.GetType()), "buy", &pb.MoonfantasyBuyResp{Issucc: true, BattleNum: info.Buynum})
|
|
return
|
|
}
|