刷新城市信息和货物信息接口

This commit is contained in:
meixiongfeng 2023-05-15 16:22:33 +08:00
parent b55b98e1ad
commit e08cec7a65
2 changed files with 75 additions and 5 deletions

View File

@ -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

View File

@ -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)
}
}