From 2e7050e6eea8667d89ee8cecab9d8b7ec5ff6f11 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 4 Jul 2022 20:17:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E6=B6=88=E8=80=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/hero/api_strengthen.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/modules/hero/api_strengthen.go b/modules/hero/api_strengthen.go index 2612ccbf7..5532579e3 100644 --- a/modules/hero/api_strengthen.go +++ b/modules/hero/api_strengthen.go @@ -4,6 +4,7 @@ import ( "go_dreamfactory/comm" "go_dreamfactory/lego/sys/log" "go_dreamfactory/pb" + cfg "go_dreamfactory/sys/configure/structs" "google.golang.org/protobuf/proto" ) @@ -22,13 +23,11 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren var ( curLv int32 - curExp int32 // 当前英雄的经验 - costRes map[string]int32 // 当前需要消资源的数量 - addExp int32 // 需要增加的经验 - curRes map[string]int32 + curExp int32 // 当前英雄的经验 + addExp int32 // 需要增加的经验 + costRes map[string][]*cfg.Game_atn // 需要消耗的资源 ) - curRes = make(map[string]int32, 0) - costRes = make(map[string]int32, 0) + costRes = make(map[string][]*cfg.Game_atn, 0) _hero, err := this.module.GetHero(session.GetUserId(), req.HeroObjID) // 校验升级的对象是否存在 defer func() { if code == pb.ErrorCode_Success { @@ -101,13 +100,16 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren break } for _, v := range _data.Gold { - _curRes := this.module.ModuleUser.QueryAttributeValue(session.GetUserId(), v.T) - if _curRes < v.N { - code = pb.ErrorCode_GoldNoEnough - return + if _, ok := costRes[v.T]; !ok { + costRes[v.T] = append(costRes[v.T], v) + } else { + for _, v1 := range costRes[v.T] { + if v1.T == v.T && v1.A == v.A { + v1.N += v.N + } + } } - curRes[v.T] = _curRes - costRes[v.T] += v.N + } } } @@ -128,8 +130,8 @@ func (this *apiComp) StrengthenUplv(session comm.IUserSession, req *pb.HeroStren return } // 消耗道具 - for k, v := range costRes { - code = this.module.ModuleUser.AddAttributeValue(session.GetUserId(), k, int32(curRes[k]-v)) // 减少金币 + for _, v := range costRes { + code = this.module.CheckConsumeRes(session.GetUserId(), v) if code != pb.ErrorCode_Success { return }