第一次创建商队数据 就进行货物刷新

This commit is contained in:
meixiongfeng 2023-08-30 00:16:08 +08:00
parent abdc8180ee
commit 8cb9c0f847

View File

@ -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) // 设置货物变更时间
}