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 }