package viking import ( "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" "strconv" ) // 参数校验 func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.VikingChallengeOverReq) (errdata *pb.ErrorData) { if req.BossId <= 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.VikingChallengeOverReq) (errdata *pb.ErrorData) { var ( mapData map[string]interface{} reward []*cfg.Gameatn bWin bool // 战斗是否胜利 atno []*pb.UserAtno // atno 类型 del []string // 自动出售的装备 changExp map[string]int32 res []*cfg.Gameatn // 最后获得的资源 bHelp bool oldDifficulty int32 // 记录通关之前的难度 consumPs int32 szAtno []*pb.UserAtno // atno 类型 ) changExp = make(map[string]int32, 0) mapData = make(map[string]interface{}, 0) reward = make([]*cfg.Gameatn, 0) if errdata = this.ChallengeOverCheck(session, req); errdata != nil { return // 参数校验失败直接返回 } viking, err := this.module.modelViking.getVikingList(session.GetUserId()) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_VikingBoosType, Title: pb.ErrorCode_VikingBoosType.ToString(), } return } vikingCfg, err := this.module.configure.GetVikingBossConfigData(req.BossId, 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 && viking.Boss[req.BossId] == 0 { viking.Boss[req.BossId] = 1 mapData["boss"] = viking.Boss } if viking.Boss[req.BossId] < req.Difficulty-1 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_VikingLvErr, Title: pb.ErrorCode_VikingLvErr.ToString(), } return } oldDifficulty = viking.Boss[req.BossId] if viking.Boss[req.BossId] < req.Difficulty { viking.Boss[req.BossId] = req.Difficulty mapData["boss"] = viking.Boss } pskey := req.BossId<<8 + req.Difficulty errdata, bWin = this.module.battle.CheckBattleReport(session, req.Report) consumPs = viking.Ps[pskey] viking.Ps[pskey] = 0 // 清空预扣体力值 mapData["ps"] = viking.Ps if !bWin { // 战斗失败了 直接返回 if errdata = this.module.DispenseRes(session, vikingCfg.PsConsume, true); errdata != nil { // 返还预扣体力 return } viking.Boss[req.BossId] = oldDifficulty mapData["boss"] = viking.Boss errdata = this.module.ModifyVikingData(session.GetUserId(), mapData) session.SendMsg(string(this.module.GetType()), VikingChallengeOverResp, &pb.VikingChallengeOverResp{ Data: viking, }) go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { this.module.WriteUserLog(session.GetUserId(), "VikingChallengeOverReq", vikingCfg.PsConsume) }) return } key := strconv.Itoa(int(req.BossId)) + "_" + strconv.Itoa(int(req.Difficulty)) if viking.BossTime[key] == 0 { // 新关卡挑战通过 发放首通奖励 res = append(res, vikingCfg.Firstprize...) // if errdata = this.module.DispenseAtno(session, vikingCfg.Firstprize, true); errdata != nil { // return // } } if viking.BossTime[key] == 0 || viking.BossTime[key] > req.Report.Costtime { viking.BossTime[key] = req.Report.Costtime mapData["bossTime"] = viking.BossTime // 更新时间 this.module.CheckRank(session.GetUserId(), req.BossId, req.Difficulty, req.Report) } if req.Auto == 1 { viking.Round = make(map[int32]int32) viking.Round[req.Auto] = req.Report.Round mapData["round"] = viking.Round } else if req.Auto > 1 { viking.Round[req.Auto] = req.Report.Round mapData["round"] = viking.Round } // 连续自动战斗 if len(viking.Round) == 10 { var total int32 for _, v := range viking.Round { total += v } szLine := make([]*pb.LineUp, 0) var Leadpos int32 if req.Report != nil && req.Report.Info != nil && len(req.Report.Info.Redflist) > 0 { Leadpos = req.Report.Info.Redflist[0].Leadpos for _, v := range req.Report.Info.Redflist[0].Team { if v != nil { szLine = append(szLine, &pb.LineUp{ Cid: v.HeroID, Star: v.Star, Lv: v.Lv, }) } } } this.module.CheckSeasonRank(session.GetUserId(), req.BossId, req.Difficulty, Leadpos, szLine, total) } 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(vikingCfg.Drop, user.Vip, user.Lv) b := this.module.ModuleActivity.HDCelebration(session, 2, req.BossId) // 星级校验 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 atno, errdata = this.module.ModuleUser.ConsumePsAddExp(session, consumPs); errdata != nil { return } szAtno = append(szAtno, atno...) if errdata, atno = this.module.DispenseAtno(session, res, true); errdata != nil { return } szAtno = append(szAtno, atno...) if errdata = this.module.ModifyVikingData(session.GetUserId(), mapData); errdata != nil { return } // 加经验 if vikingCfg.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.HeroID != "" { if !v.Ishelp { // 助战英雄不加经验 heroObjs = append(heroObjs, v.Oid) } else { bHelp = true } } } } this.module.ModuleHero.AddHerosExp(session, heroObjs, vikingCfg.Heroexp) } session.SendMsg(string(this.module.GetType()), VikingChallengeOverResp, &pb.VikingChallengeOverResp{ Data: viking, Asset: szAtno, Sell: del, Heroexp: changExp, }) if user, err := this.module.ModuleUser.GetUser(session.GetUserId()); err == nil { this.chat.SendSysChatToWorld(comm.ChatSystem14, nil, req.BossId, req.Difficulty, user.Name) } else { this.module.Errorf("no found userdata uid:%s", session.GetUserId()) } // 随机任务统计 var tasks []*pb.BuriedParam tasks = append(tasks, comm.GetBuriedParam(comm.Rtype73, 1, req.BossId, req.Difficulty)) //szTask = append(szTask, comm.GetBuriedParam(comm.Rtype74, req.BossId, req.Difficulty)) tasks = append(tasks, comm.GetBuriedParam(comm.Rtype78, req.BossId, req.Report.Costtime/1000, req.Difficulty)) 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 { // 判断是否有助战 tasks = append(tasks, comm.GetBuriedParam(comm.Rtype79, req.Difficulty, req.BossId)) break } } } if req.Auto > 0 { tasks = append(tasks, comm.GetBuriedParam(comm.Rtype75, 1, req.BossId, req.Difficulty)) tasks = append(tasks, comm.GetBuriedParam(comm.Rtype172, 1)) tasks = append(tasks, comm.GetBuriedParam(comm.Rtype181, 1, req.BossId, req.Difficulty)) } tasks = append(tasks, comm.GetBuriedParam(comm.Rtype237, consumPs)) tasks = append(tasks, comm.GetBuriedParam(comm.Rtype201, consumPs)) tasks = append(tasks, comm.GetBuriedParam(comm.Rtype76, 1, req.BossId)) if bHelp { tasks = append(tasks, comm.GetBuriedParam(comm.Rtype180, req.BossId, 1)) } if len(tasks) > 0 { go this.module.AsynHandleSession(session.Clone(), func(session comm.IUserSession) { this.module.ModuleBuried.TriggerBuried(session, tasks...) this.module.WriteUserLog(session.GetUserId(), "VikingChallengeOverReq", szAtno) }) } return }