package mline import ( "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" "go.mongodb.org/mongo-driver/bson/primitive" ) //参数校验 func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.MlineChallengeReq) (code pb.ErrorCode) { if req.StageId == 0 { code = pb.ErrorCode_ReqParameterError } return } ///挑战主线关卡 func (this *apiComp) Challenge(session comm.IUserSession, req *pb.MlineChallengeReq) (code pb.ErrorCode, data *pb.ErrorData) { var ( curChapter *pb.DBMline // 当前章节信息 ps int32 // 消耗的体力 psAnt *cfg.Gameatn stageConf *cfg.GameMainStageData ) if code = this.ChallengeCheck(session, req); code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } if stageConf = this.module.configure.GetMainStageConf(req.StageId); stageConf == nil { // 配置文件校验 code = pb.ErrorCode_MainlineNotFindChapter return } list, _ := this.module.modelMline.getMainlineList(session.GetUserId()) for _, v := range list { if stageConf.Chapterid == v.ChapterId { curChapter = v break } } if curChapter == nil { // 校验是不是新的数据 //preStage := this.module.configure.GetMainStageConf(stageConf.Previoustage) // 新章节数据校验 preStageConf := this.module.configure.GetMainStageConf(stageConf.Previoustage) if preStageConf == nil { // 配置文件校验 code = pb.ErrorCode_MainlineNotFindChapter return } for _, v := range list { if preStageConf.Chapterid == v.ChapterId { // 有上一章节数据 if _, ok := v.Star[preStageConf.Id]; ok { newData := &pb.DBMline{ Id: primitive.NewObjectID().Hex(), Uid: session.GetUserId(), CType: stageConf.Episodetype, ChapterId: stageConf.Chapterid, StageId: stageConf.Id, Star: map[int32]int32{}, Award: map[int32]bool{}, Ps: map[int32]int32{}, } curChapter = newData this.module.modelMline.addNewChapter(session.GetUserId(), newData) break } } } } if curChapter == nil { code = pb.ErrorCode_MainlineNotFindChapter return } if v1, ok := curChapter.Ps[req.StageId]; ok && v1 == 0 { if code = this.module.ConsumeRes(session, stageConf.PsMg, true); code != pb.ErrorCode_Success { // 扣1点 return } } else { 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 code = this.module.ConsumeRes(session, []*cfg.Gameatn{psAnt}, true); code != pb.ErrorCode_Success { return } curChapter.Ps[req.StageId] = ps this.module.modelMline.modifyMlineData(session.GetUserId(), curChapter.Id, map[string]interface{}{ "ps": curChapter.Ps, }) } code, record := this.module.battle.CreatePveBattle(session, &pb.BattlePVEReq{ Ptype: pb.PlayType_mainline, Title: "", Format: req.Battle, Mformat: stageConf.FormatList, }) if code != pb.ErrorCode_Success { return } session.SendMsg(string(this.module.GetType()), MlineChallengeResp, &pb.MlineChallengeResp{ 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, }, StageId: req.StageId, }) return }