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{} reward []*cfg.Gameatn asset []*pb.UserAssets bWin bool // 战斗是否胜利 ) 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 } vikingCfg := this.module.configure.GetVikingBossConfigData(req.BossId, req.Difficulty) if vikingCfg == nil { code = pb.ErrorCode_ConfigNoFound return } costRes := this.module.configure.GetGlobalConf().VikingExpeditionCos if costRes == nil { code = pb.ErrorCode_ConfigNoFound return } if code = this.module.CheckRes(session, []*cfg.Gameatn{costRes}); code != pb.ErrorCode_Success { return } value, ok := viking.Boss[req.BossId] if !ok { // 类型校验 viking.Boss[req.BossId] = 1 } if value < req.Difficulty { code = pb.ErrorCode_HuntingLvErr return } // 校验是不是达到最大难度 maxDifficulity := this.module.configure.GetMaxDifficultyByBossID(req.BossId) if viking.Boss[req.BossId] > maxDifficulity { viking.Boss[req.BossId] = maxDifficulity } mapData["boss"] = viking.Boss // 校验门票数量够不够 if code = this.module.ConsumeRes(session, []*cfg.Gameatn{costRes}, true); code != pb.ErrorCode_Success { return } amount := int32(this.module.ModuleItems.QueryItemAmount(session.GetUserId(), costRes.T)) // 获取当前数量 conf := this.module.configure.GetGlobalConf() if conf != nil { if amount < conf.VikingNum && viking.RecoveryTime == 0 { viking.RecoveryTime = configure.Now().Unix() mapData["recoveryTime"] = viking.RecoveryTime code = this.module.ModifyVikingData(session.GetUserId(), mapData) } } code, bWin = this.module.battle.CheckBattleReport(session, req.Report) if !bWin { // 战斗失败了 直接返回 code = pb.ErrorCode_BattleNoWin return } key := strconv.Itoa(int(req.BossId)) + "_" + strconv.Itoa(int(req.Difficulty)) if viking.BossTime[key] == 0 { // 新关卡挑战通过 发放首通奖励 viking.Boss[req.BossId]++ mapData["boss"] = viking.Boss if code = this.module.DispenseRes(session, vikingCfg.Firstprize, true); code != pb.ErrorCode_Success { return } for _, v := range vikingCfg.Firstprize { asset = append(asset, &pb.UserAssets{ A: v.A, T: v.T, N: v.N, }) } } this.module.CheckRank(session.GetUserId(), req.BossId, req.Difficulty, viking, req.Report) reward = this.module.configure.GetDropReward(vikingCfg.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, }) } mapData["bossTime"] = viking.BossTime // 更新时间 code = this.module.ModifyVikingData(session.GetUserId(), mapData) session.SendMsg(string(this.module.GetType()), VikingChallengeOverResp, &pb.VikingChallengeOverResp{ Data: viking, Asset: asset, }) if user := this.module.ModuleUser.GetUser(session.GetUserId()); user != nil { this.chat.SendSysChatToWorld(comm.ChatSystem14, nil, req.BossId, req.Difficulty, user.Name) } else { this.module.Errorf("no found userdata uid:%s", session.GetUserId()) } // 随机任务统计 this.module.ModuleRtask.SendToRtask(session, comm.Rtype73, req.Difficulty, req.BossId, 1) this.module.ModuleRtask.SendToRtask(session, comm.Rtype74, req.Difficulty, req.BossId) this.module.ModuleRtask.SendToRtask(session, comm.Rtype78, req.Difficulty, req.BossId, req.Report.Costtime) 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.ModuleRtask.SendToRtask(session, comm.Rtype79, req.Difficulty, req.BossId) break } } } return }