From e75b401909ef12858861e0b08b9f60750ab41ba6 Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Fri, 25 Nov 2022 14:25:14 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=AD=E4=B9=B0=E6=8A=BD=E5=8D=A1=E9=98=B6?= =?UTF-8?q?=E6=A2=AF=E6=B6=88=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/hero/api_buy.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/modules/hero/api_buy.go b/modules/hero/api_buy.go index 4b7f4ca37..8ce82ca57 100644 --- a/modules/hero/api_buy.go +++ b/modules/hero/api_buy.go @@ -28,6 +28,8 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.HeroBuyReq) (code pb give []*cfg.Gameatn totalCount int32 // 当前购买的总次数 update map[string]interface{} + price []int32 // 购买所需的价钱 + totalCost float32 // 购买打折系数 ) update = make(map[string]interface{}) if code = this.BuyCheck(session, req); code != pb.ErrorCode_Success { @@ -45,9 +47,14 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.HeroBuyReq) (code pb return } global = this.module.configure.GetGlobalConf() + for _, v := range conf.Salelist { + price = append(price, v) + } if req.BuyType == global.DrawCardSupplement1 { totalCount = record.Onebuy + req.BuyCount update["onebuy"] = totalCount // 记录购买的数据 + // 重新计算价格 + } else if req.BuyType == global.DrawCardSupplement10 { totalCount = record.Tenbuy + req.BuyCount update["tenbuy"] = totalCount @@ -59,12 +66,20 @@ func (this *apiComp) Buy(session comm.IUserSession, req *pb.HeroBuyReq) (code pb code = pb.ErrorCode_ShopGoodsIsSoldOut return } + + for i := record.Onebuy; i < req.BuyCount; i++ { + + if i >= int32(len(price)) { + totalCost += float32(price[len(price)-1]) / 1000 + } + totalCost += float32(price[i]) / 1000 + } need = make([]*cfg.Gameatn, len(conf.Need)) for i, v := range conf.Need { need[i] = &cfg.Gameatn{ A: v.A, T: v.T, - N: int32(math.Ceil(float64(v.N)*float64(conf.Sale)/float64(1000))) * req.BuyCount, + N: int32(math.Ceil(float64(v.N) * float64(totalCost))), } } // 消耗