package mline import ( "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" ) //参数校验 func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.MlineChallengeOverReq) (errdata *pb.ErrorData) { if req.StageId == 0 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), } return } return } ///挑战主线关卡 func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.MlineChallengeOverReq) (errdata *pb.ErrorData) { var ( curChapter *pb.DBMline // 当前章节信息 stageConf *cfg.GameMainStageData isWin bool first bool // 判断是否是首通 update map[string]interface{} rsp *pb.MlineChallengeOverResp star int32 // 评星 tasks []*pb.BuriedParam = make([]*pb.BuriedParam, 0) err error consumPs int32 ) rsp = &pb.MlineChallengeOverResp{} update = make(map[string]interface{}) if errdata = this.ChallengeOverCheck(session, req); errdata != nil { return // 参数校验失败直接返回 } if stageConf, err = this.module.configure.GetMainStageConf(req.StageId); err != nil { // 配置文件校验 errdata = &pb.ErrorData{ Code: pb.ErrorCode_MainlineNotFindChapter, Title: pb.ErrorCode_MainlineNotFindChapter.ToString(), Message: err.Error(), } return } list, _ := this.module.modelMline.getMainlineList(session.GetUserId()) for _, v := range list { if stageConf.Chapterid == v.ChapterId { curChapter = v break } } if curChapter == nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_MainlineNotFindChapter, Title: pb.ErrorCode_MainlineNotFindChapter.ToString(), } return } // 校验通过 errdata, isWin = this.module.battle.CheckBattleReport(session, req.Report) if errdata != nil { return } // if v, ok := curChapter.Ps[req.StageId]; !ok || v == 0 { // errdata = &pb.ErrorData{ // Code: pb.ErrorCode_HuntingLvErr, // Title: pb.ErrorCode_HuntingLvErr.ToString(), // Message: fmt.Sprintf("关卡体力参数异常,uid:%s,预扣体力:%d", session.GetUserId(), v), // } // return // } consumPs = curChapter.Ps[req.StageId] curChapter.Ps[req.StageId] = 0 // 清空预扣体力值 update["ps"] = curChapter.Ps if !isWin { // 战斗失败返还扣除的体力 if errdata = this.module.DispenseRes(session, stageConf.PsConsume, true); errdata != nil { // 返还预扣体力 return } this.module.modelMline.modifyMlineData(session.GetUserId(), curChapter.Id, update) 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) errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), } 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.StageId = req.StageId update["stageId"] = curChapter.StageId if first { // 发奖 if rst, err := this.module.ModuleUser.GetUserExpand(session.GetUserId()); err == nil { // 统计主线进度 _mp := rst.Mline 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 errdata = this.module.DispenseRes(session, stageConf.Firstaward, true); errdata != nil { 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 errdata = this.module.DispenseRes(session, stageConf.Commonaward, true); errdata != nil { 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, }) } } user := this.module.ModuleUser.GetUser(session.GetUserId()) if lotteryward := this.module.ModuleTools.GetGroupDataByLottery(stageConf.Lotteryward, user.Vip, user.Lv); len(lotteryward) > 0 { if errdata = this.module.DispenseRes(session, lotteryward, true); errdata != nil { this.module.Debugf("Mline lotteryward DispenseRes err:+%v", lotteryward) } for _, v := range lotteryward { rsp.Reward = append(rsp.Reward, &pb.UserAssets{ A: v.A, T: v.T, N: v.N, }) } } // 加英雄经验 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) } } } } rsp.HeroExp = stageConf.HeroExp rsp.UserExp, _ = this.module.ModuleUser.ConsumePsAddExp(session, consumPs) this.module.modelMline.modifyMlineData(session.GetUserId(), curChapter.Id, update) rsp.Data = curChapter session.SendMsg(string(this.module.GetType()), MlineChallengeOverResp, rsp) // 数据推送 // 校验功能开启 module, err2 := this.module.service.GetModule(comm.ModuleSys) if err2 == nil { if isys, ok := module.(comm.ISys); ok { isys.CheckLvUpCond(session, req.StageId) // 校验新功能是否开启 } } // 主线任务统计 Rtype60 tasks = append(tasks, comm.GetBuriedParam(comm.Rtype60, 1)) tasks = append(tasks, comm.GetBuriedParam(comm.Rtype61, 1, int32(req.StageId))) var ( ChapterStar int32 allStar int32 ) for _, v1 := range curChapter.Star { star := 0 for _, v := range szStar { if v1&v == v { ChapterStar++ star++ } } } tasks = append(tasks, comm.GetBuriedParam(comm.Rtype158, ChapterStar, curChapter.ChapterId, curChapter.CType)) for _, v2 := range list { for _, v1 := range v2.Star { for _, v := range szStar { if v1&v == v { allStar++ } } } } // this.module.ModuleRtask.SendToRtask(session, comm.Rtype160, allStar) tasks = append(tasks, comm.GetBuriedParam(comm.Rtype160, allStar, stageConf.Chapterid)) go this.module.ModuleBuried.TriggerBuried(session.GetUserId(), tasks...) return }