package hunting import ( "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" "strconv" ) // 参数校验 func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.HuntingChallengeOverReq) (errdata *pb.ErrorData) { if req.BossType <= 0 && req.Difficulty > 0 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), } return } return } // /挑战主线关卡 func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.HuntingChallengeOverReq) (errdata *pb.ErrorData) { var ( mapData map[string]interface{} reward []*cfg.Gameatn bWin bool // 战斗是否胜利 tasks []*pb.BuriedParam = make([]*pb.BuriedParam, 0) del []string // 自动出售的装备 atno []*pb.UserAtno // atno 类型 res []*cfg.Gameatn // 最后获得的资源 oldDifficulty int32 // 记录 consumPs int32 changExp map[string]int32 szAtno []*pb.UserAtno // atno 类型 ) changExp = map[string]int32{} mapData = make(map[string]interface{}, 0) reward = make([]*cfg.Gameatn, 0) if errdata = this.ChallengeOverCheck(session, req); errdata != nil { return // 参数校验失败直接返回 } hunting, err := this.module.modelHunting.getHuntingList(session.GetUserId()) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_PagodaNotFound, Title: pb.ErrorCode_PagodaNotFound.ToString(), } return } cfgHunting, err := this.module.configure.GetHuntingBossConfigData(req.BossType, req.Difficulty) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } if req.Difficulty == 1 && hunting.Boss[req.BossType] == 0 { hunting.Boss[req.BossType] = 1 mapData["boss"] = hunting.Boss } if hunting.Boss[req.BossType] < req.Difficulty-1 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_HuntingLvErr, Title: pb.ErrorCode_HuntingLvErr.ToString(), } return } oldDifficulty = hunting.Boss[req.BossType] if hunting.Boss[req.BossType] < req.Difficulty { hunting.Boss[req.BossType] = req.Difficulty mapData["boss"] = hunting.Boss } errdata, bWin = this.module.battle.CheckBattleReport(session, req.Report) pskey := req.BossType<<8 + req.Difficulty consumPs = hunting.Ps[pskey] hunting.Ps[pskey] = 0 // 清空预扣体力值 mapData["ps"] = hunting.Ps if !bWin { // 战斗失败了 直接返回 if errdata = this.module.DispenseRes(session, cfgHunting.PsConsume, true); errdata != nil { // 返还预扣体力 return } hunting.Boss[req.BossType] = oldDifficulty mapData["boss"] = hunting.Boss errdata = this.module.ModifyHuntingData(session.GetUserId(), mapData) session.SendMsg(string(this.module.GetType()), HuntingChallengeOverResp, &pb.HuntingChallengeOverResp{Data: hunting}) return } key := strconv.Itoa(int(req.BossType)) + "_" + strconv.Itoa(int(req.Difficulty)) if hunting.BossTime[key] == 0 { // 新关卡挑战通过 发放首通奖励 res = append(res, cfgHunting.Firstprize...) for _, v := range cfgHunting.Firstprize { if _conf, err := this.module.configure.GetItemConfigureData(v.T); err == nil { if _conf.Usetype == comm.UseType8 { tasks = append(tasks, comm.GetBuriedParam(comm.Rtype154, v.N)) } } } } // 耗时校验 当前战斗胜利时间消耗小于之前刷新数据 if hunting.BossTime[key] == 0 || hunting.BossTime[key] > req.Report.Costtime { hunting.BossTime[key] = req.Report.Costtime mapData["bossTime"] = hunting.BossTime // 更新时间 this.module.CheckRank(session.GetUserId(), req.BossType, req.Difficulty, req.Report) } // 发放通关随机奖励 user, err := this.module.ModuleUser.GetUser(session.GetUserId()) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } reward = this.module.ModuleTools.GetGroupDataByLottery(cfgHunting.Drop, user.Vip, user.Lv) // 走新的掉落 b := this.module.ModuleActivity.HDCelebration(session, 1, req.BossType) for _, v := range reward { bFound := false if v.A == "equp" { for _, star := range req.Star { cfg := this.configure.GetEquipmentConfigureById(v.T) if cfg != nil && star == cfg.Color { // 自动出售 转换成其他道具 if len(cfg.Sale) != 0 { bFound = true del = append(del, cfg.Id) res = append(res, cfg.Sale...) if b { del = append(del, cfg.Id) res = append(res, cfg.Sale...) } } break } } } if !bFound { res = append(res, v) if b { res = append(res, v) } } } if errdata, atno = this.module.DispenseAtno(session, res, true); errdata != nil { return } szAtno = append(szAtno, atno...) // 加经验 if cfgHunting.Heroexp > 0 { var heroObjs []string 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.Oid != "" && !v.Ishelp { // 助战英雄不加经验 heroObjs = append(heroObjs, v.Oid) changExp[v.Oid] = cfgHunting.Heroexp } } } this.module.ModuleHero.AddHerosExp(session, heroObjs, cfgHunting.Heroexp) } errdata = this.module.ModifyHuntingData(session.GetUserId(), mapData) if atno, errdata = this.module.ModuleUser.ConsumePsAddExp(session, consumPs); errdata != nil { return } szAtno = append(szAtno, atno...) session.SendMsg(string(this.module.GetType()), HuntingChallengeOverResp, &pb.HuntingChallengeOverResp{ Data: hunting, Asset: szAtno, Sell: del, Heroexp: changExp, }) tasks = append(tasks, comm.GetBuriedParam(comm.Rtype80, 1, req.BossType, req.Difficulty)) // 随机任务统计 // this.module.ModuleRtask.SendToRtask(session, comm.Rtype81, req.Difficulty, req.BossType) // this.module.ModuleRtask.SendToRtask(session, comm.Rtype82, req.BossType) tasks = append(tasks, comm.GetBuriedParam(comm.Rtype81, req.Difficulty, req.BossType)) tasks = append(tasks, comm.GetBuriedParam(comm.Rtype82, 1, req.BossType)) // 狩猎副本掉落觉醒材料 for _, v := range reward { if _conf, err := this.module.configure.GetItemConfigureData(v.T); err == nil { if _conf.Usetype == comm.UseType8 { // this.module.ModuleRtask.SendToRtask(session, comm.Rtype154, v.N) tasks = append(tasks, comm.GetBuriedParam(comm.Rtype154, v.N)) } } } if req.Auto { tasks = append(tasks, comm.GetBuriedParam(comm.Rtype172, 1)) } tasks = append(tasks, comm.GetBuriedParam(comm.Rtype83, 1, req.BossType, req.Difficulty)) tasks = append(tasks, comm.GetBuriedParam(comm.Rtype202, consumPs)) tasks = append(tasks, comm.GetBuriedParam(comm.Rtype200, 1)) go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { this.module.ModuleBuried.TriggerBuried(session, tasks...) this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "HuntingChallengeOverReq", szAtno) }) return }