商队协议调整

This commit is contained in:
meixiongfeng 2023-09-26 15:29:45 +08:00
parent 7e3970ca2a
commit 2c77138db1
5 changed files with 41 additions and 40 deletions

View File

@ -159,18 +159,18 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe
buyValue = caravan.Items[k].Count * caravan.Items[k].Price buyValue = caravan.Items[k].Count * caravan.Items[k].Price
var price int32 var price int32
// 获取当前节点数据 // 获取当前节点数据
if len(caravan.Allgoods[k].Goods) == 0 { if len(caravan.Allgoods) == 0 {
errdata = &pb.ErrorData{ errdata = &pb.ErrorData{
Code: pb.ErrorCode_TrollCityUnSellItem, Code: pb.ErrorCode_TrollCityUnSellItem,
Title: pb.ErrorCode_TrollCityUnSellItem.ToString(), Title: pb.ErrorCode_TrollCityUnSellItem.ToString(),
} }
return return
} }
key := configure.Now().Hour() / (24 / len(caravan.Allgoods[k].Goods)) key := configure.Now().Hour() / (24 / len(caravan.Allgoods))
if _, ok := caravan.Allgoods[k].Goods[int32(key)]; !ok { if _, ok := caravan.Allgoods[int32(key)].Goods[k]; !ok {
key = 0 key = 0
} }
price = caravan.Allgoods[k].Goods[int32(key)] price = caravan.Allgoods[int32(key)].Goods[k]
for _, v := range cityInfo.Special { for _, v := range cityInfo.Special {
if v == k { if v == k {
bFound = true bFound = true

View File

@ -53,7 +53,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.CaravanGetListRe
} }
cityRtime = utils.GetZeroTime(configure.Now().Unix()) cityRtime = utils.GetZeroTime(configure.Now().Unix())
if cityRtime != list.Citystime { if cityRtime != list.Citystime {
list.Allgoods = make(map[string]*pb.GoodsInfo, 0) list.Allgoods = make(map[int32]*pb.GoodsInfo, 0)
// 刷新城市货物信息 // 刷新城市货物信息
this.module.InitCaravanItemData(session.GetUserId(), list) this.module.InitCaravanItemData(session.GetUserId(), list)
this.module.InitCaravanCityData(session.GetUserId(), list) this.module.InitCaravanCityData(session.GetUserId(), list)

View File

@ -42,7 +42,7 @@ func (this *modelCaravan) getCaravanList(uid string) (result *pb.DBCaravan, err
//Oldprice: map[string]int32{}, //Oldprice: map[string]int32{},
Group: make(map[int32]bool, 0), Group: make(map[int32]bool, 0),
Reward: make(map[int32]bool, 0), Reward: make(map[int32]bool, 0),
Allgoods: map[string]*pb.GoodsInfo{}, Allgoods: map[int32]*pb.GoodsInfo{},
Period: map[string]*pb.GoodPeriod{}, Period: map[string]*pb.GoodPeriod{},
} }
if err = this.Get(uid, result); err != nil && mgo.MongodbNil == err { if err = this.Get(uid, result); err != nil && mgo.MongodbNil == err {

View File

@ -138,22 +138,23 @@ func (this *Caravan) InitCaravanItemData(uid string, data *pb.DBCaravan) {
} }
items := this.configure.GetAllCaravanItem() items := this.configure.GetAllCaravanItem()
data.Allgoods = make(map[string]*pb.GoodsInfo, 0) data.Allgoods = make(map[int32]*pb.GoodsInfo, 0)
if data.Period == nil { if data.Period == nil {
data.Period = make(map[string]*pb.GoodPeriod) data.Period = make(map[string]*pb.GoodPeriod)
} }
for _, c := range items {
goodinfo := &pb.GoodsInfo{
Goods: make(map[int32]int32, 0),
}
var index int32 var index int32
for index = 0; index < this.configure.GetCityRefreshTime(); index++ {
goodinfo := &pb.GoodsInfo{
Goods: make(map[string]int32, 0),
}
for _, c := range items {
if _, ok := data.Period[c.Itemid]; !ok { if _, ok := data.Period[c.Itemid]; !ok {
data.Period[c.Itemid] = &pb.GoodPeriod{} data.Period[c.Itemid] = &pb.GoodPeriod{}
} }
for index = 0; index < this.configure.GetCityRefreshTime(); index++ {
var price int32 var price int32
price = c.Goodsprice price = c.Goodsprice
data.Period[c.Itemid].CurPeriod += 1 data.Period[c.Itemid].CurPeriod += 1
@ -195,9 +196,9 @@ func (this *Caravan) InitCaravanItemData(uid string, data *pb.DBCaravan) {
if price > c.Pricemax { // 设置最大值 if price > c.Pricemax { // 设置最大值
price = c.Pricemax price = c.Pricemax
} }
goodinfo.Goods[index] = price goodinfo.Goods[c.Itemid] = price
} }
data.Allgoods[c.Itemid] = goodinfo data.Allgoods[index] = goodinfo
} }
} }

View File

@ -183,7 +183,7 @@ type DBCaravan struct {
Rtime int64 `protobuf:"varint,14,opt,name=rtime,proto3" json:"rtime"` // 客户端不用这个时间 Rtime int64 `protobuf:"varint,14,opt,name=rtime,proto3" json:"rtime"` // 客户端不用这个时间
Group map[int32]bool `protobuf:"bytes,15,rep,name=group,proto3" json:"group" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` //服务器用 Group map[int32]bool `protobuf:"bytes,15,rep,name=group,proto3" json:"group" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` //服务器用
Reward map[int32]bool `protobuf:"bytes,16,rep,name=reward,proto3" json:"reward" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // 记录盈利奖励 Reward map[int32]bool `protobuf:"bytes,16,rep,name=reward,proto3" json:"reward" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // 记录盈利奖励
Allgoods map[string]*GoodsInfo `protobuf:"bytes,17,rep,name=allgoods,proto3" json:"allgoods" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` // key 货物ID Allgoods map[int32]*GoodsInfo `protobuf:"bytes,17,rep,name=allgoods,proto3" json:"allgoods" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` // key 周期
Period map[string]*GoodPeriod `protobuf:"bytes,18,rep,name=period,proto3" json:"period" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` // key 货物ID Period map[string]*GoodPeriod `protobuf:"bytes,18,rep,name=period,proto3" json:"period" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` // key 货物ID
} }
@ -331,7 +331,7 @@ func (x *DBCaravan) GetReward() map[int32]bool {
return nil return nil
} }
func (x *DBCaravan) GetAllgoods() map[string]*GoodsInfo { func (x *DBCaravan) GetAllgoods() map[int32]*GoodsInfo {
if x != nil { if x != nil {
return x.Allgoods return x.Allgoods
} }
@ -413,7 +413,7 @@ type GoodsInfo struct {
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
Goods map[int32]int32 `protobuf:"bytes,1,rep,name=goods,proto3" json:"goods" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // key 货物ID Goods map[string]int32 `protobuf:"bytes,1,rep,name=goods,proto3" json:"goods" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"varint,2,opt,name=value,proto3"` // key 货物ID
} }
func (x *GoodsInfo) Reset() { func (x *GoodsInfo) Reset() {
@ -448,7 +448,7 @@ func (*GoodsInfo) Descriptor() ([]byte, []int) {
return file_caravan_caravan_db_proto_rawDescGZIP(), []int{4} return file_caravan_caravan_db_proto_rawDescGZIP(), []int{4}
} }
func (x *GoodsInfo) GetGoods() map[int32]int32 { func (x *GoodsInfo) GetGoods() map[string]int32 {
if x != nil { if x != nil {
return x.Goods return x.Goods
} }
@ -630,7 +630,7 @@ var file_caravan_caravan_db_proto_rawDesc = []byte{
0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x76, 0x61, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x76, 0x61,
0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x47, 0x0a, 0x0d, 0x41, 0x6c, 0x6c, 0x67, 0x6f, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x1a, 0x47, 0x0a, 0x0d, 0x41, 0x6c, 0x6c, 0x67, 0x6f,
0x6f, 0x64, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x6f, 0x64, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18,
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x20, 0x0a, 0x05, 0x76, 0x61, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x20, 0x0a, 0x05, 0x76, 0x61,
0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x47, 0x6f, 0x6f, 0x64, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0a, 0x2e, 0x47, 0x6f, 0x6f, 0x64,
0x73, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01,
0x1a, 0x46, 0x0a, 0x0b, 0x50, 0x65, 0x72, 0x69, 0x6f, 0x64, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x1a, 0x46, 0x0a, 0x0b, 0x50, 0x65, 0x72, 0x69, 0x6f, 0x64, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12,
@ -648,7 +648,7 @@ var file_caravan_caravan_db_proto_rawDesc = []byte{
0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x47, 0x6f, 0x6f, 0x64, 0x73, 0x49, 0x6e, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x47, 0x6f, 0x6f, 0x64, 0x73, 0x49, 0x6e,
0x66, 0x6f, 0x2e, 0x47, 0x6f, 0x6f, 0x64, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x67, 0x66, 0x6f, 0x2e, 0x47, 0x6f, 0x6f, 0x64, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x67,
0x6f, 0x6f, 0x64, 0x73, 0x1a, 0x38, 0x0a, 0x0a, 0x47, 0x6f, 0x6f, 0x64, 0x73, 0x45, 0x6e, 0x74, 0x6f, 0x6f, 0x64, 0x73, 0x1a, 0x38, 0x0a, 0x0a, 0x47, 0x6f, 0x6f, 0x64, 0x73, 0x45, 0x6e, 0x74,
0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,
0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20,
0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xbf, 0x01, 0x28, 0x05, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xbf,
0x01, 0x0a, 0x0f, 0x43, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x52, 0x61, 0x6e, 0x6b, 0x49, 0x6e, 0x01, 0x0a, 0x0f, 0x43, 0x61, 0x72, 0x61, 0x76, 0x61, 0x6e, 0x52, 0x61, 0x6e, 0x6b, 0x49, 0x6e,