diff --git a/modules/caravan/api_buyorsell.go b/modules/caravan/api_buyorsell.go index c1b02f111..7b763b3c9 100644 --- a/modules/caravan/api_buyorsell.go +++ b/modules/caravan/api_buyorsell.go @@ -159,18 +159,18 @@ func (this *apiComp) BuyOrSell(session comm.IUserSession, req *pb.CaravanBuyOrSe buyValue = caravan.Items[k].Count * caravan.Items[k].Price var price int32 // 获取当前节点数据 - if len(caravan.Allgoods[k].Goods) == 0 { + if len(caravan.Allgoods) == 0 { errdata = &pb.ErrorData{ Code: pb.ErrorCode_TrollCityUnSellItem, Title: pb.ErrorCode_TrollCityUnSellItem.ToString(), } return } - key := configure.Now().Hour() / (24 / len(caravan.Allgoods[k].Goods)) - if _, ok := caravan.Allgoods[k].Goods[int32(key)]; !ok { + key := configure.Now().Hour() / (24 / len(caravan.Allgoods)) + if _, ok := caravan.Allgoods[int32(key)].Goods[k]; !ok { key = 0 } - price = caravan.Allgoods[k].Goods[int32(key)] + price = caravan.Allgoods[int32(key)].Goods[k] for _, v := range cityInfo.Special { if v == k { bFound = true diff --git a/modules/caravan/api_getlist.go b/modules/caravan/api_getlist.go index 77f3701a7..b95eb636b 100644 --- a/modules/caravan/api_getlist.go +++ b/modules/caravan/api_getlist.go @@ -53,7 +53,7 @@ func (this *apiComp) GetList(session comm.IUserSession, req *pb.CaravanGetListRe } cityRtime = utils.GetZeroTime(configure.Now().Unix()) 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.InitCaravanCityData(session.GetUserId(), list) diff --git a/modules/caravan/model_caravan.go b/modules/caravan/model_caravan.go index 9e62b770f..aab292d93 100644 --- a/modules/caravan/model_caravan.go +++ b/modules/caravan/model_caravan.go @@ -42,7 +42,7 @@ func (this *modelCaravan) getCaravanList(uid string) (result *pb.DBCaravan, err //Oldprice: map[string]int32{}, Group: 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{}, } if err = this.Get(uid, result); err != nil && mgo.MongodbNil == err { diff --git a/modules/caravan/module.go b/modules/caravan/module.go index a36fa0c39..05998dd39 100644 --- a/modules/caravan/module.go +++ b/modules/caravan/module.go @@ -138,22 +138,23 @@ func (this *Caravan) InitCaravanItemData(uid string, data *pb.DBCaravan) { } items := this.configure.GetAllCaravanItem() - data.Allgoods = make(map[string]*pb.GoodsInfo, 0) + data.Allgoods = make(map[int32]*pb.GoodsInfo, 0) if data.Period == nil { data.Period = make(map[string]*pb.GoodPeriod) } - for _, c := range items { + var index int32 + for index = 0; index < this.configure.GetCityRefreshTime(); index++ { + goodinfo := &pb.GoodsInfo{ - Goods: make(map[int32]int32, 0), - } - var index int32 - - if _, ok := data.Period[c.Itemid]; !ok { - data.Period[c.Itemid] = &pb.GoodPeriod{} + Goods: make(map[string]int32, 0), } - for index = 0; index < this.configure.GetCityRefreshTime(); index++ { + for _, c := range items { + + if _, ok := data.Period[c.Itemid]; !ok { + data.Period[c.Itemid] = &pb.GoodPeriod{} + } var price int32 price = c.Goodsprice data.Period[c.Itemid].CurPeriod += 1 @@ -195,9 +196,9 @@ func (this *Caravan) InitCaravanItemData(uid string, data *pb.DBCaravan) { if price > c.Pricemax { // 设置最大值 price = c.Pricemax } - goodinfo.Goods[index] = price + goodinfo.Goods[c.Itemid] = price } - data.Allgoods[c.Itemid] = goodinfo + data.Allgoods[index] = goodinfo } } diff --git a/pb/caravan_db.pb.go b/pb/caravan_db.pb.go index 100f642c6..93cb7a0a0 100644 --- a/pb/caravan_db.pb.go +++ b/pb/caravan_db.pb.go @@ -167,24 +167,24 @@ type DBCaravan struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID - Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //用户ID - Items map[string]*BagInfo `protobuf:"bytes,3,rep,name=items,proto3" json:"items" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` // 背包数据 - City map[int32]*CityInfo `protobuf:"bytes,4,rep,name=city,proto3" json:"city" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` // 城市信息 - Lv int32 `protobuf:"varint,5,opt,name=lv,proto3" json:"lv"` // 商队等级 - Profit int64 `protobuf:"varint,6,opt,name=profit,proto3" json:"profit"` // 虚拟货利润 - Resettime int64 `protobuf:"varint,7,opt,name=resettime,proto3" json:"resettime"` // 赛季结算时间 - Curcity int32 `protobuf:"varint,8,opt,name=curcity,proto3" json:"curcity"` // 当前城市 - Taskid int32 `protobuf:"varint,9,opt,name=taskid,proto3" json:"taskid"` // 对应对应世界任务组 worldtask - Eventid int32 `protobuf:"varint,10,opt,name=eventid,proto3" json:"eventid"` // 特殊事件ID(事件配置唯一id) - Tasktime int64 `protobuf:"varint,11,opt,name=tasktime,proto3" json:"tasktime"` // 任务触发时间 - Baglimit int32 `protobuf:"varint,12,opt,name=baglimit,proto3" json:"baglimit"` // 背包上限 - Citystime int64 `protobuf:"varint,13,opt,name=citystime,proto3" json:"citystime"` // 城市刷新时间 固定每天0点刷新 - 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"` //服务器用 - 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 - 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 + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id" bson:"_id"` //ID + Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid" bson:"uid"` //用户ID + Items map[string]*BagInfo `protobuf:"bytes,3,rep,name=items,proto3" json:"items" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` // 背包数据 + City map[int32]*CityInfo `protobuf:"bytes,4,rep,name=city,proto3" json:"city" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` // 城市信息 + Lv int32 `protobuf:"varint,5,opt,name=lv,proto3" json:"lv"` // 商队等级 + Profit int64 `protobuf:"varint,6,opt,name=profit,proto3" json:"profit"` // 虚拟货利润 + Resettime int64 `protobuf:"varint,7,opt,name=resettime,proto3" json:"resettime"` // 赛季结算时间 + Curcity int32 `protobuf:"varint,8,opt,name=curcity,proto3" json:"curcity"` // 当前城市 + Taskid int32 `protobuf:"varint,9,opt,name=taskid,proto3" json:"taskid"` // 对应对应世界任务组 worldtask + Eventid int32 `protobuf:"varint,10,opt,name=eventid,proto3" json:"eventid"` // 特殊事件ID(事件配置唯一id) + Tasktime int64 `protobuf:"varint,11,opt,name=tasktime,proto3" json:"tasktime"` // 任务触发时间 + Baglimit int32 `protobuf:"varint,12,opt,name=baglimit,proto3" json:"baglimit"` // 背包上限 + Citystime int64 `protobuf:"varint,13,opt,name=citystime,proto3" json:"citystime"` // 城市刷新时间 固定每天0点刷新 + 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"` //服务器用 + 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[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 } func (x *DBCaravan) Reset() { @@ -331,7 +331,7 @@ func (x *DBCaravan) GetReward() map[int32]bool { return nil } -func (x *DBCaravan) GetAllgoods() map[string]*GoodsInfo { +func (x *DBCaravan) GetAllgoods() map[int32]*GoodsInfo { if x != nil { return x.Allgoods } @@ -413,7 +413,7 @@ type GoodsInfo struct { sizeCache protoimpl.SizeCache 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() { @@ -448,7 +448,7 @@ func (*GoodsInfo) Descriptor() ([]byte, []int) { 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 { 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, 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, - 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, 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, @@ -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, 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, - 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, 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,