From e08cec7a65033039c6e3b5962b03704c3e0b16da Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Mon, 15 May 2023 16:22:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=B7=E6=96=B0=E5=9F=8E=E5=B8=82=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=92=8C=E8=B4=A7=E7=89=A9=E4=BF=A1=E6=81=AF=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/caravan/api_getlist.go | 5 ++- modules/caravan/module.go | 75 ++++++++++++++++++++++++++++++++-- 2 files changed, 75 insertions(+), 5 deletions(-) diff --git a/modules/caravan/api_getlist.go b/modules/caravan/api_getlist.go index 573df03dd..dafeff707 100644 --- a/modules/caravan/api_getlist.go +++ b/modules/caravan/api_getlist.go @@ -29,7 +29,10 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.CaravanGetListRe return } } - + // 校验城市货物是否刷新 + this.module.refreshCaravanCityInfo(session.GetUserId(), list) + // 更新货物信息 + this.module.refreshCaravanItemInfo(session.GetUserId(), list) resp.Data = list session.SendMsg(string(this.module.GetType()), "getlist", resp) return diff --git a/modules/caravan/module.go b/modules/caravan/module.go index 2c4c0e5a2..94fbb8b9d 100644 --- a/modules/caravan/module.go +++ b/modules/caravan/module.go @@ -53,20 +53,24 @@ func (this *Caravan) InitCaravanCityData(uid string, data *pb.DBCaravan) { data.City = make(map[int32]*pb.CityInfo, 0) for _, v := range list { city := &pb.CityInfo{ - Like: []int32{}, - Unlike: []int32{}, - Count: map[int32]int32{}, + Like: []int32{}, // 城市卖给玩家的商品 (注意 这里有库存 必须初始化 Count 字段数据) + Unlike: []int32{}, // 城市想要玩家卖给他的商品库 + Count: map[int32]int32{}, // key 货物ID + Rtime: configure.Now().Unix(), // 初始化城市货物刷新时间 } if len(v.Special) > int(v.Citytypenum) { ids := utils.RandomNumbers(0, len(v.Special), int(v.Citytypenum)) for _, id := range ids { city.Like = append(city.Like, v.Special[id]) + } } else { city.Like = append(city.Like, v.Special...) } - + for _, v := range city.Like { + city.Count[v] = 40 // 配置暂无 后面走配置 + } city.Unlike = append(city.Like, v.Exspecial...) data.City[v.Id] = city @@ -103,3 +107,66 @@ func (this *Caravan) InitCaravanTicket(session comm.IUserSession, lv int32) (cod } return } + +// 刷新城市货物信息 +func (this *Caravan) refreshCaravanCityInfo(uid string, data *pb.DBCaravan) { + var ( + bChange bool + update map[string]interface{} + ) + update = make(map[string]interface{}) + for k, v := range data.City { + if c := this.configure.GetCaravanCity(k); c != nil { + if configure.Now().Unix()-v.Rtime >= int64(c.Checktime) { + v.Rtime = configure.Now().Unix() - (configure.Now().Unix()-v.Rtime)%int64(c.Checktime) + v.Count = make(map[int32]int32) // 初始化城市信息 + v.Like = []int32{} + v.Unlike = []int32{} + if len(c.Special) > int(c.Citytypenum) { + ids := utils.RandomNumbers(0, len(c.Special), int(c.Citytypenum)) + for _, id := range ids { + v.Like = append(v.Like, c.Special[id]) + + } + } else { + v.Like = append(v.Like, c.Special...) + } + for _, v1 := range v.Like { + v.Count[v1] = 40 // 配置暂无 后面走配置 + } + v.Unlike = append(v.Like, c.Exspecial...) + bChange = true + } + } + } + if bChange { + update["city"] = data.City + this.modelCaravan.modifyCaravanDataByObjId(uid, update) + } +} + +func (this *Caravan) refreshCaravanItemInfo(uid string, data *pb.DBCaravan) { + var ( + bChange bool + update map[string]interface{} + ) + for k, v := range data.Goods { + if c := this.configure.GetCaravanGoods(k); c != nil { + if configure.Now().Unix()-v.Time > int64(c.Changetime) { + bChange = true + subTime := configure.Now().Unix() - v.Time + icount := int32(subTime / int64(c.Changetime)) // 循环周期 + if v.CurPeriod+icount > v.Period { + // 随机出新的变动周期 + v.Period = comm.GetRandNum(c.Changeperiod[0], c.Changeperiod[1]) + v.CurPeriod = 0 + v.Time = configure.Now().Unix() - (subTime % int64(c.Changetime)) + } + } + } + } + if bChange { + update["goods"] = data.Goods + this.modelCaravan.modifyCaravanDataByObjId(uid, update) + } +}