From 8cb9c0f8475144926a0b65646a3e199ed593aa2f Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Wed, 30 Aug 2023 00:16:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AC=AC=E4=B8=80=E6=AC=A1=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E5=95=86=E9=98=9F=E6=95=B0=E6=8D=AE=20=E5=B0=B1=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E8=B4=A7=E7=89=A9=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/caravan/module.go | 45 ++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/modules/caravan/module.go b/modules/caravan/module.go index c2b83e0dc..cc010de28 100644 --- a/modules/caravan/module.go +++ b/modules/caravan/module.go @@ -133,22 +133,51 @@ func (this *Caravan) InitCaravanItemData(uid string, data *pb.DBCaravan) { var changeTime int32 items := this.configure.GetAllCaravanItem() data.Goods = make(map[string]*pb.Goods, 0) - for _, v := range items { + for _, c := range items { if changeTime == 0 { - changeTime = v.Changetime - + changeTime = c.Changetime } goods := &pb.Goods{ Period: 0, // 变动周期 CurPeriod: 1, // 当前变动周期 Price: 0, // 当前价格 } - if len(v.Changeperiod) == 2 { - goods.Period = comm.GetRandNum(v.Changeperiod[0], v.Changeperiod[1]) - goods.Price = v.Goodsprice - data.Goods[v.Itemid] = goods + if len(c.Changeperiod) == 2 { + goods.Period = comm.GetRandNum(c.Changeperiod[0], c.Changeperiod[1]) + goods.Price = c.Goodsprice + // data.Goods[c.Itemid] = goods } - data.Oldprice[v.Itemid] = v.Goodsprice + bUp := false + ipos := comm.GetRandW(c.PriceChangeWeight) + if ipos == 1 { + if comm.GetRandW(c.PriceChangeWeightOne) == 0 { + bUp = true + } + } else if ipos == 2 { + if comm.GetRandW(c.PriceChangeWeightTwo) == 0 { + bUp = true + } + } else if ipos == 3 { + if comm.GetRandW(c.PriceChangeWeightThree) == 0 { + bUp = true + } + } + + if bUp { // 价格上涨 + goods.Price = int32(math.Floor(float64(goods.Price) * (1.0 + float64(c.FluctuationRange)/1000.0))) + } else { + goods.Price = int32(math.Floor(float64(goods.Price) * (1.0 - float64(c.FluctuationRange)/1000.0))) + } + + if goods.Price < c.Pricemin { // 设置最小值 + goods.Price = c.Pricemin + } + + if goods.Price > c.Pricemax { // 设置最大值 + goods.Price = c.Pricemax + } + data.Goods[c.Itemid] = goods + data.Oldprice[c.Itemid] = c.Goodsprice } data.Itemtime = configure.Now().Unix() + int64(changeTime) // 设置货物变更时间 }