package pagoda import ( "go_dreamfactory/comm" "go_dreamfactory/pb" "go.mongodb.org/mongo-driver/bson/primitive" "google.golang.org/protobuf/proto" ) //参数校验 func (this *apiComp) ChallengeOverCheck(session comm.IUserSession, req *pb.PagodaChallengeOverReq) (code pb.ErrorCode) { if req.LevelID <= 0 && req.PagodaType != 0 { code = pb.ErrorCode_ReqParameterError return } return } ///挑战主线关卡 func (this *apiComp) ChallengeOver(session comm.IUserSession, req *pb.PagodaChallengeOverReq) (code pb.ErrorCode, data proto.Message) { var ( mapData map[string]interface{} pagoda *pb.DBPagoda seasonPagoda *pb.DBSeasonPagoda ) mapData = make(map[string]interface{}, 0) code = this.ChallengeOverCheck(session, req) if code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } // 校验是不是通关了普通塔 expand, err := this.module.ModuleUser.GetUserExpand(session.GetUserId()) if err != nil { code = pb.ErrorCode_DBError return } conf := this.module.configure.GetPagodaConfigData(req.PagodaType, req.LevelID) if conf == nil { code = pb.ErrorCode_PagodaNotFound return } if !expand.CompletePagoda { pagoda, err = this.module.modelPagoda.getPagodaList(session.GetUserId()) if err != nil { code = pb.ErrorCode_PagodaNotFound return } if pagoda.Type != conf.PagodaType || conf.PreLevel != pagoda.PagodaId { code = pb.ErrorCode_PagodaLevlErr // 挑战关卡数据不匹配 return } } else { // 塔数据校验 seasonPagoda, err = this.module.modelSeasonPagoda.getSeasonPagodaList(session.GetUserId()) if err != nil { code = pb.ErrorCode_PagodaNotFound return } if seasonPagoda.Type != req.PagodaType || conf.PreLevel != seasonPagoda.PagodaId { code = pb.ErrorCode_PagodaLevlErr // 挑战关卡数据不匹配 return } } // 校验通过 if !expand.CompletePagoda { // 普通塔 pagoda.Type = req.PagodaType mapData["pagodaId"] = conf.LayerNum mapData["type"] = pagoda.Type // 通关奖励 code = this.module.DispenseRes(session, conf.Reward, true) if code != pb.ErrorCode_Success { return } pagoda.PagodaId = conf.LayerNum // 更新层数 mapData["pagodaId"] = conf.LayerNum code = this.module.ModifyPagodaData(session.GetUserId(), mapData) session.SendMsg(string(this.module.GetType()), PagodaChallengeOverResp, &pb.PagodaChallengeOverResp{Data: pagoda}) if user := this.module.ModuleUser.GetUser(session.GetUserId()); user != nil { this.chat.SendSysChatToWorld(comm.EquipmentUpgradeNotice, nil, pagoda.PagodaId, user.Name) } else { this.module.Errorf("no found userdata uid:%s", session.GetUserId()) } // 普通塔通关了 Nomalcfg := this.module.configure.GetPagodaConfigData(comm.PagodaType, pagoda.PagodaId+1) if Nomalcfg == nil { // 创建赛季塔数据 // 修改expand 数据 update := map[string]interface{}{ "completePagoda": true, } this.module.ModuleUser.ChangeUserExpand(session.GetUserId(), update) seasonPagoda := &pb.DBSeasonPagoda{} seasonPagoda.Id = primitive.NewObjectID().Hex() seasonPagoda.Uid = session.GetUserId() seasonPagoda.PagodaId = 0 // 初始数据0层 seasonPagoda.Type = 201 this.module.modelSeasonPagoda.addNewSeasonPagoda(session.GetUserId(), seasonPagoda) // 推送新的 pagoda.PagodaId = seasonPagoda.PagodaId pagoda.Type = seasonPagoda.Type session.SendMsg(string(this.module.GetType()), PagodaGetListResp, &pb.PagodaGetListResp{Data: pagoda}) } } else { // 记录爬塔明细数据 if req.Report != nil && len(req.Report.Info.Redflist) > 0 { sz := make([]*pb.LineUp, 5) for i, v := range req.Report.Info.Redflist[0].Team { if v != nil { sz[i] = &pb.LineUp{ Cid: v.HeroID, Star: v.Star, Lv: v.Lv, } } } this.module.modulerank.addPagodaRankList(session, seasonPagoda, req.Report.Info.Redflist[0].Leadpos, sz, req.Report.Costtime) } // 挑战处理 seasonPagoda.PagodaId = conf.LayerNum mapData["pagodaId"] = conf.LayerNum code = this.module.ModifySeasonPagodaData(session.GetUserId(), mapData) session.SendMsg(string(this.module.GetType()), PagodaChallengeOverResp, &pb.PagodaChallengeOverResp{Data: pagoda}) } // 任务相关 if req.PagodaType == comm.PagodaType { this.module.ModuleRtask.SendToRtask(session, comm.Rtype58, 1) this.module.ModuleRtask.SendToRtask(session, comm.Rtype59, pagoda.PagodaId) } return }