exchange_slot.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Code generated by excel export. DO NOT EDIT.
  2. package data
  3. import (
  4. "f1-game/internal/enum"
  5. "f1-game/internal/types"
  6. )
  7. var ExchangeSlot = &exchangeSlotConfig{}
  8. func init() {
  9. _allList = append(_allList, ExchangeSlot)
  10. }
  11. type (
  12. ExchangeSlotRow struct {
  13. SlotType enum.ExchangeActType `json:"SlotType"` // 类型
  14. ExchangeType enum.ExchangeType `json:"ExchangeType"` // 交易所类型
  15. FreeCount int32 `json:"FreeCount"` // 免费数量
  16. Cost types.Assets `json:"Cost"` // 解锁消耗
  17. }
  18. exchangeSlotConfig struct {
  19. baseConfig
  20. list []*ExchangeSlotRow // all list
  21. slotTypeExchangeTypeUniMaps map[enum.ExchangeActType]map[enum.ExchangeType]*ExchangeSlotRow // key:slotType, exchangeType
  22. }
  23. )
  24. func (p *exchangeSlotConfig) Name() string {
  25. return "exchange_slot"
  26. }
  27. func (p *exchangeSlotConfig) Init() {
  28. p.slotTypeExchangeTypeUniMaps = map[enum.ExchangeActType]map[enum.ExchangeType]*ExchangeSlotRow{}
  29. }
  30. func (p *exchangeSlotConfig) OnLoad(maps interface{}, reload bool) (int, error) {
  31. if reload && p.denyLoad {
  32. return 0, nil
  33. }
  34. var list []*ExchangeSlotRow
  35. if err := DecodeData(maps, &list); err != nil {
  36. return 0, err
  37. }
  38. p.list = list
  39. slotTypeExchangeTypeUniMaps := map[enum.ExchangeActType]map[enum.ExchangeType]*ExchangeSlotRow{}
  40. for _, row := range list {
  41. itemMap := slotTypeExchangeTypeUniMaps[row.SlotType]
  42. if itemMap == nil {
  43. itemMap = map[enum.ExchangeType]*ExchangeSlotRow{}
  44. slotTypeExchangeTypeUniMaps[row.SlotType] = itemMap
  45. }
  46. itemMap[row.ExchangeType] = row
  47. }
  48. p.slotTypeExchangeTypeUniMaps = slotTypeExchangeTypeUniMaps
  49. return len(list), nil
  50. }
  51. // func (p *exchangeSlotConfig) OnAfterLoad(_ bool) {
  52. // }
  53. func (p *exchangeSlotConfig) List() []*ExchangeSlotRow {
  54. return p.list
  55. }
  56. func (p *exchangeSlotConfig) GetBySlotTypeExchangeType(slotType enum.ExchangeActType, exchangeType enum.ExchangeType) (*ExchangeSlotRow, bool) {
  57. mapItem, found := p.slotTypeExchangeTypeUniMaps[slotType]
  58. if !found {
  59. return nil, false
  60. }
  61. value, found := mapItem[exchangeType]
  62. return value, found
  63. }
  64. func (p *exchangeSlotConfig) ContainSlotTypeExchangeType(slotType enum.ExchangeActType, exchangeType enum.ExchangeType) bool {
  65. mapItem, found := p.slotTypeExchangeTypeUniMaps[slotType]
  66. if !found {
  67. return false
  68. }
  69. _, found = mapItem[exchangeType]
  70. return found
  71. }