diff --git a/modules/modulebase.go b/modules/modulebase.go index f1f54d30d..f8918b461 100644 --- a/modules/modulebase.go +++ b/modules/modulebase.go @@ -218,7 +218,7 @@ func (this *ModuleBase) DispenseRes(uid string, res []*cfg.Game_atn) (code pb.Er this.ModuleItems.AddItem(source, uid, int32(resID), v.N) } else if v.A == comm.HeroType { //卡片资源 resID, _ = strconv.Atoi(v.T) - this.ModuleHero.ConsumeCard(uid, int32(resID), v.N) + this.ModuleHero.CreateHero(uid, int32(resID), v.N) } else if v.A == comm.EquipmentType { resID, _ = strconv.Atoi(v.T) this.ModuleEquipment.AddNewEquipments(source, uid, map[int32]uint32{int32(resID): uint32(v.N)}) diff --git a/modules/story/api_challenge.go b/modules/story/api_challenge.go index 6230bbb02..4623a129f 100644 --- a/modules/story/api_challenge.go +++ b/modules/story/api_challenge.go @@ -10,18 +10,22 @@ import ( //参数校验 func (this *apiComp) ChallengeCheck(session comm.IUserSession, req *pb.StoryChallengeReq) (code pb.ErrorCode) { - + if req.ChapterId == 0 || req.StoryId == 0 { + code = pb.ErrorCode_ReqParameterError + return + } return } ///挑战主线关卡 func (this *apiComp) Challenge(session comm.IUserSession, req *pb.StoryChallengeReq) (code pb.ErrorCode, data proto.Message) { var ( - rsp = &pb.DBStory{} - curChapter *pb.DBStory + curChapter *pb.DBStory // 当前章节信息 + bBranch bool // 当前挑战关卡是不是分支 ) + bBranch = false defer func() { - session.SendMsg(string(this.module.GetType()), StoryChallengeResp, &pb.StoryChallengeResp{Data: rsp}) + session.SendMsg(string(this.module.GetType()), StoryChallengeResp, &pb.StoryChallengeResp{Data: curChapter}) }() code = this.ChallengeCheck(session, req) @@ -33,11 +37,12 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.StoryChallenge code = pb.ErrorCode_DBError return } - sort.SliceStable(list, func(i, j int) bool { // 排序 + sort.SliceStable(list, func(i, j int) bool { // 倒序排序 return list[i].ChapterId > list[j].ChapterId }) - - curChapter = list[len(list)-1] + if len(list) > 0 { + curChapter = list[0] // 取第一条(第一条肯定是最新的) + } if curChapter == nil { code = pb.ErrorCode_StoryNotFindChapter // 没有找到主线关卡信息 return @@ -56,6 +61,7 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.StoryChallenge return } if con.Area == 2 { //分支 + bBranch = true // 只需要校验小关ID 是不是大于当前ID就可以 if curChapter.StoryId < int32(req.StoryId) { //必须大于前置关卡才可以挑战 code = pb.ErrorCode_StoryIDFailed @@ -63,13 +69,18 @@ func (this *apiComp) Challenge(session comm.IUserSession, req *pb.StoryChallenge } } } - // TODU 调用战斗逻辑 + // TODO 调用战斗逻辑 + if bBranch { + curChapter.BranchID = append(curChapter.BranchID, int32(req.ChapterId)) // 记录分支关卡 + } if curChapter.ChapterId == int32(req.ChapterId) && curChapter.StoryId == int32(req.StoryId) { update := map[string]interface{}{ - "storyId": req.StoryId, + "storyId": req.StoryId, + "branchID": curChapter.BranchID, } err = this.module.modelStory.modifyStoryData(session.GetUserId(), curChapter.Id, update) } // 发奖 (奖励数据还没配置,后续补充) + return } diff --git a/modules/user/api_res.go b/modules/user/api_res.go index 88f7e5605..f11d64639 100644 --- a/modules/user/api_res.go +++ b/modules/user/api_res.go @@ -3,12 +3,13 @@ package user import ( "go_dreamfactory/comm" "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" "google.golang.org/protobuf/proto" ) func (this *apiComp) AddResCheck(session comm.IUserSession, req *pb.UserAddResReq) (code pb.ErrorCode) { - if req.ResType == "" || req.Count <= 0 { + if req.Res.A == "" || req.Res.T == "" || req.Res.N > 0 { code = pb.ErrorCode_ReqParameterError } return @@ -33,22 +34,14 @@ func (this *apiComp) AddRes(session comm.IUserSession, req *pb.UserAddResReq) (c code = pb.ErrorCode_UserSessionNobeing return } - - count := req.Count - - switch req.ResType { - case comm.ResGold: - count += user.Gold - case comm.ResExp: - count += user.Exp + res := make([]*cfg.Game_atn, 0) + atn := &cfg.Game_atn{ + A: req.Res.A, + T: req.Res.T, + N: req.Res.N, } - code = this.module.AddAttributeValue(session.GetUserId(), req.ResType, count) - if code != pb.ErrorCode_Success { - return - } - - rsp.ResType = req.ResType - rsp.Count = count - + res = append(res, atn) + code = this.module.DispenseRes(session.GetUserId(), res) + rsp.Res = req.Res return } diff --git a/pb/proto/user/user_msg.proto b/pb/proto/user/user_msg.proto index cd8642b23..221e358e0 100644 --- a/pb/proto/user/user_msg.proto +++ b/pb/proto/user/user_msg.proto @@ -2,7 +2,7 @@ syntax = "proto3"; option go_package = ".;pb"; import "errorcode.proto"; import "user/user_db.proto"; - +import "comm.proto"; //用户登录 message UserLoginReq { string account = 1; //账号 @@ -32,11 +32,10 @@ message UserCreateResp {} //添加用户资源 message UserAddResReq { - string resType = 1; //资源类型 - int32 count = 2; //资源数量 + UserAssets res = 1; //资源类型 } message UserAddResResp { - string resType = 1; //资源类型 - int32 count = 2; //资源数量 + UserAssets res = 1; //资源类型 } + diff --git a/pb/user_msg.pb.go b/pb/user_msg.pb.go index a40aff39d..4115f7259 100644 --- a/pb/user_msg.pb.go +++ b/pb/user_msg.pb.go @@ -372,8 +372,7 @@ type UserAddResReq struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - ResType string `protobuf:"bytes,1,opt,name=resType,proto3" json:"resType"` //资源类型 - Count int32 `protobuf:"varint,2,opt,name=count,proto3" json:"count"` //资源数量 + Res *UserAssets `protobuf:"bytes,1,opt,name=res,proto3" json:"res"` //资源类型 } func (x *UserAddResReq) Reset() { @@ -408,18 +407,11 @@ func (*UserAddResReq) Descriptor() ([]byte, []int) { return file_user_user_msg_proto_rawDescGZIP(), []int{7} } -func (x *UserAddResReq) GetResType() string { +func (x *UserAddResReq) GetRes() *UserAssets { if x != nil { - return x.ResType + return x.Res } - return "" -} - -func (x *UserAddResReq) GetCount() int32 { - if x != nil { - return x.Count - } - return 0 + return nil } type UserAddResResp struct { @@ -427,8 +419,7 @@ type UserAddResResp struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - ResType string `protobuf:"bytes,1,opt,name=resType,proto3" json:"resType"` //资源类型 - Count int32 `protobuf:"varint,2,opt,name=count,proto3" json:"count"` //资源数量 + Res *UserAssets `protobuf:"bytes,1,opt,name=res,proto3" json:"res"` //资源类型 } func (x *UserAddResResp) Reset() { @@ -463,18 +454,11 @@ func (*UserAddResResp) Descriptor() ([]byte, []int) { return file_user_user_msg_proto_rawDescGZIP(), []int{8} } -func (x *UserAddResResp) GetResType() string { +func (x *UserAddResResp) GetRes() *UserAssets { if x != nil { - return x.ResType + return x.Res } - return "" -} - -func (x *UserAddResResp) GetCount() int32 { - if x != nil { - return x.Count - } - return 0 + return nil } var File_user_user_msg_proto protoreflect.FileDescriptor @@ -483,39 +467,37 @@ var file_user_user_msg_proto_rawDesc = []byte{ 0x0a, 0x13, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x6d, 0x73, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0f, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x63, 0x6f, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x12, 0x75, 0x73, 0x65, 0x72, 0x2f, 0x75, 0x73, 0x65, - 0x72, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x3a, 0x0a, 0x0c, 0x55, 0x73, - 0x65, 0x72, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, - 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, - 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x05, 0x52, 0x03, 0x73, 0x69, 0x64, 0x22, 0x2c, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x4c, 0x6f, - 0x67, 0x69, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1b, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x07, 0x2e, 0x44, 0x42, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, - 0x64, 0x61, 0x74, 0x61, 0x22, 0x3d, 0x0a, 0x0f, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x67, 0x69, - 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, - 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, - 0x74, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, - 0x73, 0x69, 0x64, 0x22, 0x4c, 0x0a, 0x10, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x67, 0x69, 0x73, - 0x74, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1e, 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x0a, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, - 0x65, 0x52, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, - 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, - 0x74, 0x22, 0x2e, 0x0a, 0x0c, 0x55, 0x73, 0x65, 0x72, 0x4c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, - 0x70, 0x12, 0x1e, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x0a, 0x2e, 0x43, 0x61, 0x63, 0x68, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x64, 0x61, 0x74, - 0x61, 0x22, 0x2b, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, - 0x65, 0x71, 0x12, 0x1a, 0x0a, 0x08, 0x4e, 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x4e, 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x10, - 0x0a, 0x0e, 0x55, 0x73, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, - 0x22, 0x3f, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x41, 0x64, 0x64, 0x52, 0x65, 0x73, 0x52, 0x65, - 0x71, 0x12, 0x18, 0x0a, 0x07, 0x72, 0x65, 0x73, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x07, 0x72, 0x65, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x63, - 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, - 0x74, 0x22, 0x40, 0x0a, 0x0e, 0x55, 0x73, 0x65, 0x72, 0x41, 0x64, 0x64, 0x52, 0x65, 0x73, 0x52, - 0x65, 0x73, 0x70, 0x12, 0x18, 0x0a, 0x07, 0x72, 0x65, 0x73, 0x54, 0x79, 0x70, 0x65, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x72, 0x65, 0x73, 0x54, 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, - 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x63, 0x6f, - 0x75, 0x6e, 0x74, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x33, + 0x72, 0x5f, 0x64, 0x62, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, + 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x3a, 0x0a, 0x0c, 0x55, 0x73, 0x65, 0x72, 0x4c, 0x6f, + 0x67, 0x69, 0x6e, 0x52, 0x65, 0x71, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, + 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x12, 0x10, 0x0a, 0x03, 0x73, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x73, + 0x69, 0x64, 0x22, 0x2c, 0x0a, 0x0d, 0x55, 0x73, 0x65, 0x72, 0x4c, 0x6f, 0x67, 0x69, 0x6e, 0x52, + 0x65, 0x73, 0x70, 0x12, 0x1b, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x07, 0x2e, 0x44, 0x42, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, + 0x22, 0x3d, 0x0a, 0x0f, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, + 0x52, 0x65, 0x71, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x10, 0x0a, + 0x03, 0x73, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x73, 0x69, 0x64, 0x22, + 0x4c, 0x0a, 0x10, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x52, + 0x65, 0x73, 0x70, 0x12, 0x1e, 0x0a, 0x04, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0e, 0x32, 0x0a, 0x2e, 0x45, 0x72, 0x72, 0x6f, 0x72, 0x43, 0x6f, 0x64, 0x65, 0x52, 0x04, 0x43, + 0x6f, 0x64, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x2e, 0x0a, + 0x0c, 0x55, 0x73, 0x65, 0x72, 0x4c, 0x6f, 0x61, 0x64, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1e, 0x0a, + 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x43, 0x61, + 0x63, 0x68, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x2b, 0x0a, + 0x0d, 0x55, 0x73, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x12, 0x1a, + 0x0a, 0x08, 0x4e, 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x08, 0x4e, 0x69, 0x63, 0x6b, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x10, 0x0a, 0x0e, 0x55, 0x73, + 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x22, 0x2e, 0x0a, 0x0d, + 0x55, 0x73, 0x65, 0x72, 0x41, 0x64, 0x64, 0x52, 0x65, 0x73, 0x52, 0x65, 0x71, 0x12, 0x1d, 0x0a, + 0x03, 0x72, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x55, 0x73, 0x65, + 0x72, 0x41, 0x73, 0x73, 0x65, 0x74, 0x73, 0x52, 0x03, 0x72, 0x65, 0x73, 0x22, 0x2f, 0x0a, 0x0e, + 0x55, 0x73, 0x65, 0x72, 0x41, 0x64, 0x64, 0x52, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x12, 0x1d, + 0x0a, 0x03, 0x72, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x55, 0x73, + 0x65, 0x72, 0x41, 0x73, 0x73, 0x65, 0x74, 0x73, 0x52, 0x03, 0x72, 0x65, 0x73, 0x42, 0x06, 0x5a, + 0x04, 0x2e, 0x3b, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -544,16 +526,19 @@ var file_user_user_msg_proto_goTypes = []interface{}{ (*DBUser)(nil), // 9: DBUser (ErrorCode)(0), // 10: ErrorCode (*CacheUser)(nil), // 11: CacheUser + (*UserAssets)(nil), // 12: UserAssets } var file_user_user_msg_proto_depIdxs = []int32{ 9, // 0: UserLoginResp.data:type_name -> DBUser 10, // 1: UserRegisterResp.Code:type_name -> ErrorCode 11, // 2: UserLoadResp.data:type_name -> CacheUser - 3, // [3:3] is the sub-list for method output_type - 3, // [3:3] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name + 12, // 3: UserAddResReq.res:type_name -> UserAssets + 12, // 4: UserAddResResp.res:type_name -> UserAssets + 5, // [5:5] is the sub-list for method output_type + 5, // [5:5] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name } func init() { file_user_user_msg_proto_init() } @@ -563,6 +548,7 @@ func file_user_user_msg_proto_init() { } file_errorcode_proto_init() file_user_user_db_proto_init() + file_comm_proto_init() if !protoimpl.UnsafeEnabled { file_user_user_msg_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*UserLoginReq); i {