package pagoda import ( "go_dreamfactory/comm" "go_dreamfactory/pb" ) // 参数校验 func (this *apiComp) ChallengeRaceOverCheck(session comm.IUserSession, req *pb.PagodaChallengeRaceOverReq) (errdata *pb.ErrorData) { if req.Cid <= 0 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), } return } return } // 六合塔挑战 func (this *apiComp) ChallengeRaceOver(session comm.IUserSession, req *pb.PagodaChallengeRaceOverReq) (errdata *pb.ErrorData) { var ( mapData map[string]interface{} list *pb.DBPagodaRace isWin bool err error atno []*pb.UserAtno // 通关奖励 changExp map[string]int32 costTime int32 // 耗时 star int32 // 当前星级 new bool // 是否首次挑战 ) changExp = make(map[string]int32, 0) mapData = make(map[string]interface{}, 0) if errdata = this.ChallengeRaceOverCheck(session, req); errdata != nil { return // 参数校验失败直接返回 } conf, err := this.module.configure.GetPagodaRaceConfById(req.Cid) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_PagodaNotFound, Title: pb.ErrorCode_PagodaNotFound.ToString(), Message: err.Error(), } return } list, err = this.module.modelRacePagoda.getPagodaRaceList(session.GetUserId()) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_PagodaNotFound, Title: pb.ErrorCode_PagodaNotFound.ToString(), } 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 { if list.Maxfloor+1 == conf.Floors { list.Data[conf.Floors] = &pb.RaceData{ Consttime: costTime, Star: star, } list.Maxfloor = conf.Floors mapData["maxfloor"] = list.Maxfloor new = true } } list.Battlecount += 1 mapData["data"] = list.Data mapData["battlecount"] = list.Battlecount if new { var score int32 score = 10000*list.Maxfloor + (10000 - costTime) this.module.modelRacePagoda.SetRacePagodaRankList(score, session.GetUserId()) } if err = this.module.modelRacePagoda.ModifyPagodaRaceDataByObjId(session.GetUserId(), mapData); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } } 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, errdata = this.module.ModuleHero.AddHerosExp(session, heroObjs, conf.Exp); errdata != nil { return } } // 通关奖励 if errdata, atno = this.module.DispenseAtno(session, conf.Reward, true); errdata != nil { return } session.SendMsg(string(this.module.GetType()), PagodaChallengeRaceOverResp, &pb.PagodaChallengeRaceOverResp{ Data: list, Reward: atno, Heroexp: changExp, }) return }