package mline import ( "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" "google.golang.org/protobuf/proto" ) //参数校验 func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.MlineChallengeOverReq) (code pb.ErrorCode) { if req.StageId == 0 { code = pb.ErrorCode_ReqParameterError return } return } ///挑战主线关卡 func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.MlineChallengeOverReq) (code pb.ErrorCode, data proto.Message) { var ( curChapter *pb.DBMline // 当前章节信息 stageConf *cfg.GameMainStageData isWin bool first bool // 判断是否是首通 update map[string]interface{} rsp *pb.MlineChallengeOverResp star int32 // 评星 ) rsp = &pb.MlineChallengeOverResp{} update = make(map[string]interface{}) code = this.ChallengeOverCheck(session, req) if 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 { code = pb.ErrorCode_MainlineNotFindChapter return } // 校验通过 code, isWin = this.module.battle.CheckBattleReport(session, req.Report) if code != pb.ErrorCode_Success { return } if !isWin { // 战斗失败返还扣除的体力 if v, ok := curChapter.Ps[req.StageId]; ok && v > 0 { if code = this.module.DispenseRes(session, stageConf.PsConsume, true); code != pb.ErrorCode_Success { // 返还预扣体力 return } } curChapter.Ps[req.StageId] = 0 // 清空预扣体力值 update["ps"] = curChapter.Ps this.module.modelMline.modifyMlineData(session.GetUserId(), curChapter.Id, update) //code = pb.ErrorCode_BattleNoWin rsp.Data = curChapter session.SendMsg(string(this.module.GetType()), MlineChallengeOverResp, rsp) // 数据推送 return } // 评星规则 if len(stageConf.Star) != len(stageConf.StarType) || len(stageConf.Star) != len(stageConf.StarValue) || len(stageConf.StarValue) != len(stageConf.StarType) { this.module.Errorf("配置错误, 参数数量不一致,StageId: %d", req.StageId) code = pb.ErrorCode_ConfigNoFound return } var szStar []int32 szStar = append(szStar, 1<<0) szStar = append(szStar, 1<<1) szStar = append(szStar, 1<<2) for i, v := range stageConf.StarType { if v == comm.MainStarType1 { star ^= szStar[i] } else if v == comm.MainStarType2 { if req.Report.Death <= stageConf.StarValue[i] { star ^= szStar[i] } } else if v == comm.MainStarType3 { if req.Report.Round <= stageConf.StarValue[i] { star ^= szStar[i] } } } // 判断是不是首通 if _, ok := curChapter.Star[req.StageId]; !ok { first = true curChapter.Star[req.StageId] = star // 星级赋值 update["star"] = curChapter.Star } // 判断星数 var ( totalStar int32 preStar int32 ) if curChapter.Star[req.StageId] != star { for _, v := range szStar { if star&v == v { totalStar++ } if curChapter.Star[req.StageId]&v == v { preStar++ } } if totalStar >= preStar { // 给最高星 curChapter.Star[req.StageId] = star update["star"] = curChapter.Star } } curChapter.Ps[req.StageId] = 0 // 清空预扣体力值 update["ps"] = curChapter.Ps curChapter.StageId = req.StageId update["stageId"] = curChapter.StageId if first { // 发奖 if rst, err := this.module.ModuleUser.GetUserExpand(session.GetUserId()); err == nil { // 统计主线进度 _mp := rst.Mline if _mp == nil { _mp = make(map[int32]int32, 1) _mp[curChapter.CType] = req.StageId } else { if v, ok := _mp[curChapter.CType]; ok { if v <= req.StageId { _mp[curChapter.CType] = req.StageId } } else { _mp[curChapter.CType] = req.StageId } } this.module.ModuleUser.ChangeUserExpand(session.GetUserId(), map[string]interface{}{ "mline": _mp, }) } if code = this.module.DispenseRes(session, stageConf.Firstaward, true); code != pb.ErrorCode_Success { this.module.Debugf("Mline first DispenseRes err:+%v", stageConf.Firstaward) } for _, v := range stageConf.Firstaward { rsp.Reward = append(rsp.Reward, &pb.UserAssets{ A: v.A, T: v.T, N: v.N, }) } } else { if code = this.module.DispenseRes(session, stageConf.Commonaward, true); code != pb.ErrorCode_Success { this.module.Debugf("Mline Commonaward DispenseRes err:+%v", stageConf.Commonaward) } for _, v := range stageConf.Commonaward { rsp.Reward = append(rsp.Reward, &pb.UserAssets{ A: v.A, T: v.T, N: v.N, }) } } // 加主角经验 // if stageConf.Exp > 0 { // res := make([]*cfg.Gameatn, 0) // res = append(res, &cfg.Gameatn{ // A: "attr", // T: "exp", // N: stageConf.Exp, // }) // if code = this.module.DispenseRes(session, res, true); code != pb.ErrorCode_Success { // this.module.Debugf("Mline Commonaward DispenseRes err:+%v", res) // } // } // 加英雄经验 if stageConf.HeroExp > 0 { if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 { for _, v := range req.Report.Info.Redflist[0].Team { if !v.Ishelp { // 助战英雄不加经验 this.module.ModuleHero.AddHeroExp(session, v.Oid, stageConf.HeroExp) } } } } this.module.modelMline.modifyMlineData(session.GetUserId(), curChapter.Id, update) rsp.Data = curChapter session.SendMsg(string(this.module.GetType()), MlineChallengeOverResp, rsp) // 数据推送 // 主线任务统计 Rtype60 this.module.ModuleRtask.SendToRtask(session, comm.Rtype60, 1) this.module.ModuleRtask.SendToRtask(session, comm.Rtype61, int32(req.StageId)) return }