package mainline import ( "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" ) // 参数校验 func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.MainlineChallengeReq) (errdata *pb.ErrorData) { if req.Level == 0 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), } } return } // /挑战主线关卡 func (this *apiComp) Challenge(session comm.IUserSession, req *pb.MainlineChallengeReq) (errdata *pb.ErrorData) { var ( curChapter *pb.DBMline // 当前章节信息 ps int32 // 消耗的体力 psAnt *cfg.Gameatn stageConf *cfg.GameMainStageData // 当前章节数据 err error ) if errdata = this.ChallengeCheck(session, req); errdata != nil { return // 参数校验失败直接返回 } if stageConf, err = this.module.configure.GetMainStageConf(req.Level); err != nil { // 配置文件校验 errdata = &pb.ErrorData{ Code: pb.ErrorCode_MainlineNotFindChapter, Title: pb.ErrorCode_MainlineNotFindChapter.ToString(), Message: err.Error(), } return } if v1, ok := curChapter.Ps[req.Level]; !ok || v1 == 0 { for _, v := range stageConf.PsConsume { if v.A == "attr" && v.T == "ps" { ps += v.N } } for _, v := range stageConf.PsMg { if v.A == "attr" && v.T == "ps" { ps += v.N } } psAnt = &cfg.Gameatn{ // 构建一个atn 对象 A: "attr", T: "ps", N: ps, } if errdata = this.module.ConsumeRes(session, []*cfg.Gameatn{psAnt}, true); errdata != nil { return } curChapter.Ps[req.Level] = ps } errdata, record := this.module.battle.CreatePveBattle(session, &pb.BattlePVEReq{ Ptype: pb.PlayType_mainline, Title: "", Format: req.Battle, Mformat: stageConf.FormatList, }) if errdata != nil { return } session.SendMsg(string(this.module.GetType()), MlineChallengeResp, &pb.MainlineChallengeResp{ Info: &pb.BattleInfo{ Id: record.Id, Title: record.Title, Rulesid: stageConf.BattleReadyID, Btype: record.Btype, Ptype: record.Ptype, RedCompId: record.RedCompId, Redflist: record.Redflist, BlueCompId: record.BlueCompId, Buleflist: record.Buleflist, }, Level: req.Level, }) return }