chapter_reward.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Code generated by excel export. DO NOT EDIT.
  2. package data
  3. import (
  4. "f1-game/internal/types"
  5. )
  6. var ChapterReward = &chapterRewardConfig{}
  7. func init() {
  8. _allList = append(_allList, ChapterReward)
  9. }
  10. type (
  11. ChapterRewardRow struct {
  12. ID int32 `json:"ID"` // 奖励库ID
  13. StarNum int32 `json:"StarNum"` // 所需星数
  14. Reward types.Assets `json:"Reward"` // 奖励
  15. }
  16. chapterRewardConfig struct {
  17. baseConfig
  18. list []*ChapterRewardRow // all list
  19. idListMaps map[int32][]*ChapterRewardRow // key:id
  20. idStarNumUniMaps map[int32]map[int32]*ChapterRewardRow // key:id, starNum
  21. }
  22. )
  23. func (p *chapterRewardConfig) Name() string {
  24. return "chapter_reward"
  25. }
  26. func (p *chapterRewardConfig) Init() {
  27. p.idListMaps = map[int32][]*ChapterRewardRow{}
  28. p.idStarNumUniMaps = map[int32]map[int32]*ChapterRewardRow{}
  29. }
  30. func (p *chapterRewardConfig) OnLoad(maps interface{}, reload bool) (int, error) {
  31. if reload && p.denyLoad {
  32. return 0, nil
  33. }
  34. var list []*ChapterRewardRow
  35. if err := DecodeData(maps, &list); err != nil {
  36. return 0, err
  37. }
  38. p.list = list
  39. idListMaps := map[int32][]*ChapterRewardRow{}
  40. for _, row := range list {
  41. idListMaps[row.ID] = append(idListMaps[row.ID], row)
  42. }
  43. p.idListMaps = idListMaps
  44. idStarNumUniMaps := map[int32]map[int32]*ChapterRewardRow{}
  45. for _, row := range list {
  46. itemMap := idStarNumUniMaps[row.ID]
  47. if itemMap == nil {
  48. itemMap = map[int32]*ChapterRewardRow{}
  49. idStarNumUniMaps[row.ID] = itemMap
  50. }
  51. itemMap[row.StarNum] = row
  52. }
  53. p.idStarNumUniMaps = idStarNumUniMaps
  54. return len(list), nil
  55. }
  56. // func (p *chapterRewardConfig) OnAfterLoad(_ bool) {
  57. // }
  58. func (p *chapterRewardConfig) List() []*ChapterRewardRow {
  59. return p.list
  60. }
  61. func (p *chapterRewardConfig) ListByID(id int32) ([]*ChapterRewardRow, bool) {
  62. value, found := p.idListMaps[id]
  63. return value, found
  64. }
  65. func (p *chapterRewardConfig) ListContainID(id int32) bool {
  66. _, found := p.idListMaps[id]
  67. return found
  68. }
  69. func (p *chapterRewardConfig) GetByIDStarNum(id int32, starNum int32) (*ChapterRewardRow, bool) {
  70. mapItem, found := p.idStarNumUniMaps[id]
  71. if !found {
  72. return nil, false
  73. }
  74. value, found := mapItem[starNum]
  75. return value, found
  76. }
  77. func (p *chapterRewardConfig) ContainIDStarNum(id int32, starNum int32) bool {
  78. mapItem, found := p.idStarNumUniMaps[id]
  79. if !found {
  80. return false
  81. }
  82. _, found = mapItem[starNum]
  83. return found
  84. }