From 2ee66ded5a54eb774c3c1c6aba1c93874714b8ff Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 12 Oct 2022 10:49:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8B=B1=E9=9B=84=E7=BE=81?= =?UTF-8?q?=E7=BB=8A=E7=BB=8F=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/library/api.go | 1 + modules/library/api_usegift.go | 47 ++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 modules/library/api_usegift.go diff --git a/modules/library/api.go b/modules/library/api.go index 5744673be..e1c9b5a72 100644 --- a/modules/library/api.go +++ b/modules/library/api.go @@ -7,6 +7,7 @@ import ( const ( LibraryGetListResp = "getlist" + LibraryUseGiftResp = "usegift" LibraryGetFetterListResp = "getfetterlist" LibraryChallengeResp = "challenge" LibrarySkillLvResp = "skilllv" diff --git a/modules/library/api_usegift.go b/modules/library/api_usegift.go new file mode 100644 index 000000000..21fdf58e5 --- /dev/null +++ b/modules/library/api_usegift.go @@ -0,0 +1,47 @@ +package library + +import ( + "go_dreamfactory/comm" + "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" + + "google.golang.org/protobuf/proto" +) + +//参数校验 +func (this *apiComp) UseGiftCheck(session comm.IUserSession, req *pb.LibraryUseGiftReq) (code pb.ErrorCode) { + if req.Heroid == "" || len(req.Items) == 0 { + code = pb.ErrorCode_ReqParameterError + } + return +} + +func (this *apiComp) UseGift(session comm.IUserSession, req *pb.LibraryUseGiftReq) (code pb.ErrorCode, data proto.Message) { + var ( + res []*cfg.Gameatn + ) + code = this.UseGiftCheck(session, req) + if code != pb.ErrorCode_Success { + return // 参数校验失败直接返回 + } + rsp := &pb.LibraryUseGiftResp{} + _heroObj := this.module.modelFetter.getOneHeroFetter(session.GetUserId(), req.Heroid) + if _heroObj == nil { + code = pb.ErrorCode_HeroNoExist // 没找到对应的英雄信息 + return + } + for k, v := range req.Items { // 校验数量 + res = append(res, &cfg.Gameatn{ + A: "item", + T: k, + N: v, + }) + } + if code = this.module.CheckRes(session, res); code != pb.ErrorCode_Success { // 道具不够直接返回 + return + } + + session.SendMsg(string(this.module.GetType()), LibraryUseGiftResp, rsp) + + return +}