package mainline import ( "fmt" "go_dreamfactory/comm" "go_dreamfactory/pb" cfg "go_dreamfactory/sys/configure/structs" ) // 参数校验 func (this *apiComp) ReceiveAwardCheck(session comm.IUserSession, req *pb.MainlineReceiveAwardReq) (errdata *pb.ErrorData) { return } // /获取主线关卡信息 func (this *apiComp) ReceiveAward(session comm.IUserSession, req *pb.MainlineReceiveAwardReq) (errdata *pb.ErrorData) { var ( info *pb.DBMainline award *pb.DBMainlineAward chapterconf *cfg.GameMainChapterData awardConfs []*cfg.GameMainStarrewardData awardid int32 pass int32 ok bool err error ) errdata = this.ReceiveAwardCheck(session, req) if errdata != nil { return // 参数校验失败直接返回 } info, err = this.module.modelMline.getMainlineData(session.GetUserId()) if err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_DBError, Title: pb.ErrorCode_DBError.ToString(), Message: err.Error(), } return } if req.Rtype == 0 { if award, ok = info.Chapteraward[req.Chapter]; !ok || award.Stage < req.Stage { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), Message: fmt.Sprintf("chapter:%d stage:%d no arrive", req.Chapter, req.Stage), } return } if chapterconf, err = this.module.configure.GetMainChapterConf(req.Chapter); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } awardid = chapterconf.Starreward } else if req.Rtype == 1 { if award, ok = info.Exploreaward[req.Chapter]; !ok || award.Stage < req.Stage { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), Message: fmt.Sprintf("chapter:%d stage:%d no arrive", req.Chapter, req.Stage), } return } if chapterconf, err = this.module.configure.GetMainChapterConf(req.Chapter); err != nil { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: err.Error(), } return } awardid = chapterconf.Starreward } else { if award, ok = info.Groupaward[req.Group]; !ok || award.Stage < req.Stage { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ReqParameterError, Title: pb.ErrorCode_ReqParameterError.ToString(), Message: fmt.Sprintf("group:%d stage:%d no arrive", req.Group, req.Stage), } return } } if pass, ok = award.Award[req.Stage]; ok && pass == 2 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_MainlineRepeatReward, Title: pb.ErrorCode_MainlineRepeatReward.ToString(), Message: fmt.Sprintf("progress:%d stage:%d repeatreward", req.Chapter, req.Stage), } return } if awardConfs, ok = this.module.configure.getrewardMap()[awardid]; !ok { errdata = &pb.ErrorData{ Code: pb.ErrorCode_ConfigNoFound, Title: pb.ErrorCode_ConfigNoFound.ToString(), Message: fmt.Sprintf("no found awardid:%d", awardid), } return } ok = false for _, v := range awardConfs { if v.Starnum == req.Stage { ok = true } } session.SendMsg(string(this.module.GetType()), "receiveaward", &pb.MainlineReceiveAwardResp{}) return }