diff --git a/modules/hunting/api_buy.go b/modules/hunting/api_buy.go index 80926affa..24f4706d2 100644 --- a/modules/hunting/api_buy.go +++ b/modules/hunting/api_buy.go @@ -26,6 +26,7 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.HuntingBuyReq) (code mapData map[string]interface{} szCostRes []*cfg.Gameatn // 购买累计消耗 curCount int32 // 当前门票数量 + addCount int32 //获得数量 ) mapData = make(map[string]interface{}, 0) code = this.BuyCheck(session, req) @@ -81,18 +82,16 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.HuntingBuyReq) (code } } if curCount-amount > 0 { - res := &cfg.Gameatn{ - A: "item", - T: costRes.T, - N: curCount - amount, - } - if code = this.module.DispenseRes(session, []*cfg.Gameatn{res}, true); code != pb.ErrorCode_Success { - return - } + addCount = curCount - amount } } else { list.RecoveryTime = 0 } + addCount += req.Count + if amount+addCount > conf.VikingNum { + code = pb.ErrorCode_VikingBuyMaxCount + return + } mapData["recoveryTime"] = list.RecoveryTime for i := list.BuyCount + 1; i <= curByCount; i++ { @@ -121,6 +120,14 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.HuntingBuyReq) (code if code = this.module.ConsumeRes(session, sz, true); code != pb.ErrorCode_Success { return } + res := &cfg.Gameatn{ + A: "item", + T: costRes.T, + N: addCount, + } + if code = this.module.DispenseRes(session, []*cfg.Gameatn{res}, true); code != pb.ErrorCode_Success { + return + } list.BuyCount = curByCount mapData["buyCount"] = curByCount code = this.module.ModifyHuntingData(session.GetUserId(), mapData) diff --git a/modules/viking/api_buy.go b/modules/viking/api_buy.go index 89347a0bc..560b8653f 100644 --- a/modules/viking/api_buy.go +++ b/modules/viking/api_buy.go @@ -26,6 +26,7 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.VikingBuyReq) (code mapData map[string]interface{} curCount int32 // 当前门票数量 szcostRes []*cfg.Gameatn // 购买累计消耗 + addCount int32 //获得数量 ) mapData = make(map[string]interface{}, 0) code = this.BuyCheck(session, req) @@ -77,18 +78,17 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.VikingBuyReq) (code } } if curCount-amount > 0 { - res := &cfg.Gameatn{ - A: "item", - T: costRes.T, - N: curCount - amount, - } - if code = this.module.DispenseRes(session, []*cfg.Gameatn{res}, true); code != pb.ErrorCode_Success { - return - } + addCount = curCount - amount + } } else { list.RecoveryTime = 0 } + addCount += req.Count + if amount+addCount > conf.VikingNum { + code = pb.ErrorCode_VikingBuyMaxCount + return + } mapData["recoveryTime"] = list.RecoveryTime // 更新刷新时间 curByCount += req.Count // 当前需要购买的数量 @@ -123,6 +123,14 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.VikingBuyReq) (code if code = this.module.ConsumeRes(session, sz, true); code != pb.ErrorCode_Success { return } + res := &cfg.Gameatn{ + A: "item", + T: costRes.T, + N: addCount, + } + if code = this.module.DispenseRes(session, []*cfg.Gameatn{res}, true); code != pb.ErrorCode_Success { + return + } list.BuyCount = curByCount mapData["buyCount"] = curByCount code = this.module.ModifyVikingData(session.GetUserId(), mapData)