package enchant import ( "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" ) //参数校验 func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.EnchantChallengeOverReq) (errdata *pb.ErrorData) { if req.BossType <= 0 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), } return } return } ///挑战主线关卡 func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.EnchantChallengeOverReq) (errdata *pb.ErrorData) { var ( mapData map[string]interface{} bWin bool // 战斗是否胜利 score int32 // 通关获得分数 res []*cfg.Gameatn ) mapData = make(map[string]interface{}, 0) // reward = make([]*cfg.Gameatn, 0) errdata = this.ChallengeOverCheck(session, req) if errdata != nil { return // 参数校验失败直接返回 } enchant, err := this.module.modelEnchant.getEnchantList(session.GetUserId()) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_PagodaNotFound, Title: pb.ErrorCode_PagodaNotFound.ToString(), } return } cfgEnchant, err := this.module.configure.GetEnchantBossConfigData(req.BossType) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, // 道具数量不足 Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } // check errdata, bWin = this.module.battle.CheckBattleReport(session, req.Report) if errdata != nil { return } if !bWin { // 战斗失败了 直接返回 if errdata = this.module.ConsumeRes(session, cfgEnchant[0].PsMg, true); errdata != nil { return } session.SendMsg(string(this.module.GetType()), EnchantChallengeOverResp, &pb.EnchantChallengeOverResp{Data: enchant}) return } if errdata = this.module.ConsumeRes(session, cfgEnchant[0].PsConsume, true); errdata != nil { return } userinfo, 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 } key := req.BossType if enchant.BossTime[key] > req.Report.Costtime || enchant.BossTime[key] == 0 { enchant.BossTime[key] = req.Report.Costtime mapData["bossTime"] = enchant.BossTime // 更新时间 this.module.CheckRank(session.GetUserId(), req.BossType, req.Report, userinfo, req.Score) } enchant.Boss[req.BossType] = req.Score // 获得的积分 // 发放通关随机奖励 for _, v := range cfgEnchant { if score >= v.ScoreLow && score <= v.ScoreUp { for _, v1 := range v.RewardDrop { reward := this.module.ModuleTools.GetGroupDataByLottery(v1, userinfo.Vip, userinfo.Lv) res = append(res, reward...) } } } if len(res) > 0 { if errdata = this.module.DispenseRes(session, res, true); errdata != nil { return } go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { this.module.WriteUserLog(session.GetUserId(), comm.GMResAddType, "EnchantChallengeOverReq", res) }) } mapData["bossTime"] = enchant.BossTime mapData["boss"] = enchant.Boss errdata = this.module.ModifyEnchantData(session.GetUserId(), mapData) if session.GetUserId() != "" { // 恢复时间 if userexpand, err := this.module.ModuleUser.GetUserExpand(session.GetUserId()); err == nil { enchant.RecoveryTime = userexpand.Recovertimeunifiedticket } } session.SendMsg(string(this.module.GetType()), EnchantChallengeOverResp, &pb.EnchantChallengeOverResp{Data: enchant}) return }