package pagoda import ( "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" ) // 参数校验 func (this *apiComp) ChallengeCycleOverCheck(session comm.IUserSession, req *pb.PagodaChallengeCycleOverReq) (errdata *pb.ErrorData) { if req.Floor <= 0 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), } return } return } // 六合塔挑战 func (this *apiComp) ChallengeCycleOver(session comm.IUserSession, req *pb.PagodaChallengeCycleOverReq) (errdata *pb.ErrorData) { var ( mapData map[string]interface{} list *pb.DBPagodaCycle isWin bool err error atno []*pb.UserAtno // 通关奖励 award []*cfg.Gameatn res []*cfg.Gameatn changExp map[string]int32 costTime int32 // 耗时 new bool // 是否首次挑战 fresh bool // 刷新记录 ) changExp = make(map[string]int32, 0) mapData = make(map[string]interface{}, 0) if errdata = this.ChallengeCycleOverCheck(session, req); errdata != nil { return // 参数校验失败直接返回 } list, err = this.module.modelCyclePagoda.getPagodaCycleList(session.GetUserId()) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_PagodaNotFound, Title: pb.ErrorCode_PagodaNotFound.ToString(), } return } conf, err := this.module.configure.GetPagodaCirculateConf(list.Itype, req.Floor) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_PagodaNotFound, Title: pb.ErrorCode_PagodaNotFound.ToString(), Message: err.Error(), } return } // 校验通过 errdata, isWin = this.module.battle.CheckBattleReport(session, req.Report) if errdata != nil { return } if !isWin { // 战斗失败直接返回 errdata = &pb.ErrorData{ Code: pb.ErrorCode_BattleNoWin, Title: pb.ErrorCode_BattleNoWin.ToString(), } return } costTime = req.Report.Costtime if _, ok := list.Data[conf.Floors]; !ok { list.Data[conf.Floors] = &pb.CycleData{} } if list.Data[conf.Floors].Consttime == 0 { list.Data[conf.Floors].Consttime = costTime fresh = true list.Maxfloor = req.Floor mapData["maxfloor"] = list.Maxfloor } list.Battlecount += 1 mapData["data"] = list.Data mapData["battlecount"] = list.Battlecount if err = this.module.modelCyclePagoda.ModifyPagodaCycleData(session.GetUserId(), mapData); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } } if list.Data[conf.Floors].Consttime > costTime { list.Data[conf.Floors].Consttime = costTime fresh = true } var score int32 score = 10000*list.Maxfloor + (10000 - costTime) 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, }) } } } list.Data[conf.Floors].Line = &pb.LineData{ Leadpos: Leadpos, Line: szLine, } if new { if conf.Floors == 1 { // 写数据 this.module.modelCyclePagoda.addCrossPagodaCycle(session.GetUserId(), list) } res = append(res, conf.KeyReward...) // 首通奖励 } // 校验是否刷新记录 if fresh || new { this.module.modelCyclePagoda.SetCyclePagodaRankList(score, session.GetUserId()) mapData["data"] = list.Data user, err := this.module.ModuleUser.GetUser(session.GetUserId()) if err == nil { mapData["uinfo"] = comm.GetUserBaseInfo(user) } this.module.modelCyclePagoda.ModifyCrossPagodaCycleData(session.GetUserId(), mapData) } if conf.Exp > 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) } } } if changExp, award, errdata = this.module.ModuleHero.AddHerosExp(session, heroObjs, conf.Exp); errdata != nil { return } res = append(res, award...) } res = append(res, conf.Reward...) // 通关奖励 if errdata, atno = this.module.DispenseAtno(session, res, true); errdata != nil { return } session.SendMsg(string(this.module.GetType()), "challengecycleover", &pb.PagodaChallengeCycleOverResp{ Data: list, Reward: atno, Heroexp: changExp, }) return }