shop_goods.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Code generated by excel export. DO NOT EDIT.
  2. package data
  3. import (
  4. "f1-game/internal/types"
  5. )
  6. var ShopGoods = &shopGoodsConfig{}
  7. func init() {
  8. _allList = append(_allList, ShopGoods)
  9. }
  10. type (
  11. ShopGoodsRow struct {
  12. ShopPoolID int32 `json:"ShopPoolID"` // 商品库ID
  13. GoodsID int32 `json:"GoodsID"` // 商品ID
  14. BuyCost types.Pair[int32, int32] `json:"BuyCost"` // 购买消耗
  15. BuyCondition types.Pair[int32, int32] `json:"BuyCondition"` // 购买条件
  16. BuyLimit int32 `json:"BuyLimit"` // 购买上限
  17. Rewards types.Pair[int32, int32] `json:"Rewards"` // 购买奖励
  18. }
  19. shopGoodsConfig struct {
  20. baseConfig
  21. list []*ShopGoodsRow // all list
  22. shopPoolIDListMaps map[int32][]*ShopGoodsRow // key:shopPoolID
  23. shopPoolIDGoodsIDUniMaps map[int32]map[int32]*ShopGoodsRow // key:shopPoolID, goodsID
  24. }
  25. )
  26. func (p *shopGoodsConfig) Name() string {
  27. return "shop_goods"
  28. }
  29. func (p *shopGoodsConfig) Init() {
  30. p.shopPoolIDListMaps = map[int32][]*ShopGoodsRow{}
  31. p.shopPoolIDGoodsIDUniMaps = map[int32]map[int32]*ShopGoodsRow{}
  32. }
  33. func (p *shopGoodsConfig) OnLoad(maps interface{}, reload bool) (int, error) {
  34. if reload && p.denyLoad {
  35. return 0, nil
  36. }
  37. var list []*ShopGoodsRow
  38. if err := DecodeData(maps, &list); err != nil {
  39. return 0, err
  40. }
  41. p.list = list
  42. shopPoolIDListMaps := map[int32][]*ShopGoodsRow{}
  43. for _, row := range list {
  44. shopPoolIDListMaps[row.ShopPoolID] = append(shopPoolIDListMaps[row.ShopPoolID], row)
  45. }
  46. p.shopPoolIDListMaps = shopPoolIDListMaps
  47. shopPoolIDGoodsIDUniMaps := map[int32]map[int32]*ShopGoodsRow{}
  48. for _, row := range list {
  49. itemMap := shopPoolIDGoodsIDUniMaps[row.ShopPoolID]
  50. if itemMap == nil {
  51. itemMap = map[int32]*ShopGoodsRow{}
  52. shopPoolIDGoodsIDUniMaps[row.ShopPoolID] = itemMap
  53. }
  54. itemMap[row.GoodsID] = row
  55. }
  56. p.shopPoolIDGoodsIDUniMaps = shopPoolIDGoodsIDUniMaps
  57. return len(list), nil
  58. }
  59. // func (p *shopGoodsConfig) OnAfterLoad(_ bool) {
  60. // }
  61. func (p *shopGoodsConfig) List() []*ShopGoodsRow {
  62. return p.list
  63. }
  64. func (p *shopGoodsConfig) ListByShopPoolID(shopPoolID int32) ([]*ShopGoodsRow, bool) {
  65. value, found := p.shopPoolIDListMaps[shopPoolID]
  66. return value, found
  67. }
  68. func (p *shopGoodsConfig) ListContainShopPoolID(shopPoolID int32) bool {
  69. _, found := p.shopPoolIDListMaps[shopPoolID]
  70. return found
  71. }
  72. func (p *shopGoodsConfig) GetByShopPoolIDGoodsID(shopPoolID int32, goodsID int32) (*ShopGoodsRow, bool) {
  73. mapItem, found := p.shopPoolIDGoodsIDUniMaps[shopPoolID]
  74. if !found {
  75. return nil, false
  76. }
  77. value, found := mapItem[goodsID]
  78. return value, found
  79. }
  80. func (p *shopGoodsConfig) ContainShopPoolIDGoodsID(shopPoolID int32, goodsID int32) bool {
  81. mapItem, found := p.shopPoolIDGoodsIDUniMaps[shopPoolID]
  82. if !found {
  83. return false
  84. }
  85. _, found = mapItem[goodsID]
  86. return found
  87. }