package viking import ( "go_dreamfactory/comm" "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "strconv" "google.golang.org/protobuf/proto" ) //参数校验 func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.VikingChallengeOverReq) (code pb.ErrorCode) { if req.BossId <= 0 && req.Difficulty > 0 { code = pb.ErrorCode_ReqParameterError return } return } ///挑战完成 func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.VikingChallengeOverReq) (code pb.ErrorCode, data proto.Message) { var ( mapData map[string]interface{} newChallenge bool // 新的关卡 reward []*cfg.Gameatn asset []*pb.UserAssets costTime int32 // 战斗花费的时间 ) mapData = make(map[string]interface{}, 0) reward = make([]*cfg.Gameatn, 0) asset = make([]*pb.UserAssets, 0) code = this.ChallengeOverCheck(session, req) if code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } viking, err := this.module.modelViking.getVikingList(session.GetUserId()) if err != nil { code = pb.ErrorCode_VikingBoosType return } if viking.ChallengeCount > this.module.configure.GetGlobalConf().VikingNum+viking.BuyCount { code = pb.ErrorCode_VikingMaxChallengeCount return } cfg := this.module.configure.GetVikingBossConfigData(req.BossId, req.Difficulty) if cfg == nil { code = pb.ErrorCode_ConfigNoFound return } value, ok := viking.Boss[req.BossId] if !ok { // 类型校验 viking.Boss[req.BossId] = 0 } if value < req.Difficulty { if value+1 != req.Difficulty { code = pb.ErrorCode_VikingLvErr return } newChallenge = true viking.Boss[req.BossId]++ // 校验是不是达到最大难度 maxDifficulity := this.module.configure.GetMaxDifficultyByBossID(req.BossId) if viking.Boss[req.BossId] > maxDifficulity { viking.Boss[req.BossId] = maxDifficulity } mapData["boss"] = viking.Boss } if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 { costTime = req.Report.Costtime sz := make([]*pb.LineUp, 5) for i, v := range req.Report.Info.Redflist[0].Team { if v != nil { sz[i] = &pb.LineUp{ Cid: v.HeroID, Star: v.Star, Lv: v.Lv, } } } // 刷新难度最高的记录 this.module.modulerank.updateVikingRankList(session, req.Difficulty, req.BossId, req.Report.Info.Redflist[0].Leadpos, sz, req.Report.Costtime) } // 耗时校验 当前战斗胜利时间消耗小于之前刷新数据 code, _ = this.module.battle.CheckBattleReport(session, req.Report) if code != pb.ErrorCode_Success { return } conf := this.module.configure.GetGlobalConf() if conf != nil { if viking.LeftCount >= conf.VikingNum { viking.RecoveryTime = configure.Now().Unix() } } viking.LeftCount-- mapData["leftCount"] = viking.LeftCount viking.ChallengeCount++ mapData["challengeCount"] = viking.ChallengeCount // 写入排行榜 if newChallenge { this.module.modulerank.SetRankListData("vikingRank"+strconv.Itoa(int(req.BossId)), req.Difficulty<<16+costTime, session.GetUserId()) } // 时间写入 key := strconv.Itoa(int(req.BossId)) + "_" + strconv.Itoa(int(req.Difficulty)) if t, ok := viking.BossTime[key]; ok { if t < req.Report.Costtime { viking.BossTime[key] = t } } else { viking.BossTime[key] = req.Report.Costtime } mapData["bossTime"] = viking.BossTime // 更新时间 if newChallenge { // 新关卡挑战通过 发放首通奖励 if code = this.module.DispenseRes(session, cfg.Firstprize, true); code != pb.ErrorCode_Success { return } viking.Boss[req.BossId] += 1 mapData["boss"] = viking.Boss for _, v := range cfg.Firstprize { asset = append(asset, &pb.UserAssets{ A: v.A, T: v.T, N: v.N, }) } } else { reward = this.module.configure.GetDropReward(cfg.Drop) // 获取掉落奖励 if code = this.module.DispenseRes(session, reward, true); code != pb.ErrorCode_Success { return } for _, v := range reward { asset = append(asset, &pb.UserAssets{ A: v.A, T: v.T, N: v.N, }) } } code = this.module.ModifyVikingData(session.GetUserId(), mapData) // 发放通关随机奖励 session.SendMsg(string(this.module.GetType()), VikingChallengeOverResp, &pb.VikingChallengeOverResp{ Data: viking, Asset: asset, }) return }