package story import ( "go_dreamfactory/comm" "go_dreamfactory/pb" "sort" "google.golang.org/protobuf/proto" ) //参数校验 func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.StoryChallengeReq) (code pb.ErrorCode) { return } ///挑战主线关卡 func (this *apiComp) Challenge(session comm.IUserSession, req *pb.StoryChallengeReq) (code pb.ErrorCode, data proto.Message) { var ( rsp = &pb.DBStory{} curChapter *pb.DBStory ) defer func() { session.SendMsg(string(this.module.GetType()), StoryChallengeResp, &pb.StoryChallengeResp{Data: rsp}) }() code = this.ChallengeCheck(session, req) if code != pb.ErrorCode_Success { return // 参数校验失败直接返回 } list, err := this.module.modelStory.getStoryList(session.GetUserId()) if err != nil { code = pb.ErrorCode_DBError return } sort.SliceStable(list, func(i, j int) bool { // 排序 return list[i].ChapterId > list[j].ChapterId }) curChapter = list[len(list)-1] if curChapter == nil { code = pb.ErrorCode_StoryNotFindChapter // 没有找到主线关卡信息 return } // 先校验是不是分支 chaptConfig := this.module.configure.GetStoryChapter(int32(req.ChapterId)) // 根据配置文件找 if chaptConfig == nil { code = pb.ErrorCode_ConfigNoFound return } // 根据难度找对应的配置文件 if chaptConfig.Intensity == "1" { // 这里安临时配置读取 后面会修改 con := this.module.configure.GetStoryEasyChapter(int32(req.StoryId)) // 根据配置文件找 if con != nil { code = pb.ErrorCode_ConfigNoFound return } if con.Area == 2 { //分支 // 只需要校验小关ID 是不是大于当前ID就可以 if curChapter.StoryId < int32(req.StoryId) { //必须大于前置关卡才可以挑战 code = pb.ErrorCode_StoryIDFailed return } } } // TODU 调用战斗逻辑 if curChapter.ChapterId == int32(req.ChapterId) && curChapter.StoryId == int32(req.StoryId) { update := map[string]interface{}{ "storyId": req.StoryId, } err = this.module.modelStory.modifyStoryData(session.GetUserId(), curChapter.Id, update) } // 发奖 (奖励数据还没配置,后续补充) return }