package arena import ( "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "time" ) //参数校验 func (this *apiComp) PlotCheck(session comm.IUserSession, req *pb.ArenaPlotReq) (code pb.ErrorCode) { return } ///获取自己的排行榜信息 func (this *apiComp) Plot(session comm.IUserSession, req *pb.ArenaPlotReq) (code pb.ErrorCode, data *pb.ErrorData) { var ( npc *cfg.GameArenaChallengeNpcData info *pb.DBArenaUser record *pb.DBBattleRecord index int32 cd pb.ErrorCode err error ) defer func() { if cd == pb.ErrorCode_Success { session.SendMsg(string(this.module.GetType()), "plot", &pb.ArenaPlotResp{ Code: cd, Pid: req.Pid, Info: &pb.BattleInfo{ Id: record.Id, Title: record.Title, Rulesid: npc.BattleReadyID, Btype: record.Btype, Ptype: record.Ptype, RedCompId: record.RedCompId, Redflist: record.Redflist, BlueCompId: record.BlueCompId, Buleflist: record.Buleflist, }, }) } else { session.SendMsg(string(this.module.GetType()), "plot", &pb.ArenaPlotResp{Code: cd}) } }() if cd = this.PlotCheck(session, req); cd != pb.ErrorCode_Success { return } if npc, err = this.module.configure.getChallengenpc(req.Pid); err != nil { cd = pb.ErrorCode_ConfigNoFound return } if info, err = this.module.modelArena.queryPlayerInfo(session.GetUserId()); err != nil { cd = pb.ErrorCode_DBError return } this.module.modelArena.recoverTicket(session, info) if cd = this.module.ConsumeRes(session, []*cfg.Gameatn{this.module.ModuleTools.GetGlobalConf().ArenaTicketCos}, true); cd != pb.ErrorCode_Success { return } // if info.Ticket > this.module.ModuleTools.GetGlobalConf().ArenaTicketCos { // info.Ticket -= this.module.ModuleTools.GetGlobalConf().ArenaTicketCos // } else { // code = pb.ErrorCode_ArenaTicketNotEnough // return // } if info.Npc[req.Pid] != nil { ndata := info.Npc[req.Pid] if !configure.Now().After(time.Unix(ndata.Cd, 0)) { //已经过了cd时间 code = pb.ErrorCode_ArenaTicketNpcInCd return } index = ndata.Index } if cd, record = this.module.battle.CreatePveBattle(session, &pb.BattlePVEReq{ Ptype: pb.PlayType_arena, Format: req.Battle, Mformat: []int32{npc.MonsterformatId[index]}, }); cd == pb.ErrorCode_Success { if err = this.module.modelArena.updateArenaUserInfo(info); err != nil { code = pb.ErrorCode_DBError return } } return }