diff --git a/modules/hunting/api_buy.go b/modules/hunting/api_buy.go index 33333ca89..58ba062f7 100644 --- a/modules/hunting/api_buy.go +++ b/modules/hunting/api_buy.go @@ -25,6 +25,7 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.HuntingBuyReq) (code costRes []*cfg.Gameatn mapData map[string]interface{} ) + mapData = make(map[string]interface{}, 0) code = this.BuyCheck(session, req) if code != pb.ErrorCode_Success { return // 参数校验失败直接返回 @@ -57,13 +58,26 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.HuntingBuyReq) (code } costRes = append(costRes, _cfg.Need...) } + sz := make([]*cfg.Gameatn, 0) + for _, v := range costRes { + bFound := false + for _, v1 := range sz { + if v.A == v1.A && v.T == v1.T { + v1.N += v.N + bFound = true + } + } + if !bFound { + sz = append(sz, v) + } + } // 消耗校验 - if code = this.module.CheckRes(session, costRes); code != pb.ErrorCode_Success { + if code = this.module.CheckRes(session, sz); code != pb.ErrorCode_Success { return } //消耗 - if code = this.module.ConsumeRes(session, costRes, true); code != pb.ErrorCode_Success { + if code = this.module.ConsumeRes(session, sz, true); code != pb.ErrorCode_Success { return } list.BuyCount = curByCount diff --git a/modules/viking/api_buy.go b/modules/viking/api_buy.go index d6522b1ef..6270406e9 100644 --- a/modules/viking/api_buy.go +++ b/modules/viking/api_buy.go @@ -25,6 +25,7 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.VikingBuyReq) (code costRes []*cfg.Gameatn mapData map[string]interface{} ) + mapData = make(map[string]interface{}, 0) code = this.BuyCheck(session, req) if code != pb.ErrorCode_Success { return // 参数校验失败直接返回 @@ -48,7 +49,7 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.VikingBuyReq) (code curByCount = list.BuyCount } curByCount += req.Count // 当前需要购买的数量 - // + // 消耗资源整合 for i := list.BuyCount + 1; i <= curByCount; i++ { _cfg := this.configure.GetBuyChallengeCount(i) if _cfg == nil { @@ -57,13 +58,26 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.VikingBuyReq) (code } costRes = append(costRes, _cfg.Need...) } + sz := make([]*cfg.Gameatn, 0) + for _, v := range costRes { + bFound := false + for _, v1 := range sz { + if v.A == v1.A && v.T == v1.T { + v1.N += v.N + bFound = true + } + } + if !bFound { + sz = append(sz, v) + } + } // 消耗校验 - if code = this.module.CheckRes(session, costRes); code != pb.ErrorCode_Success { + if code = this.module.CheckRes(session, sz); code != pb.ErrorCode_Success { return } //消耗 - if code = this.module.ConsumeRes(session, costRes, true); code != pb.ErrorCode_Success { + if code = this.module.ConsumeRes(session, sz, true); code != pb.ErrorCode_Success { return } list.BuyCount = curByCount