monster_pool.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Code generated by excel export. DO NOT EDIT.
  2. package data
  3. var MonsterPool = &monsterPoolConfig{}
  4. func init() {
  5. _allList = append(_allList, MonsterPool)
  6. }
  7. type (
  8. MonsterPoolRow struct {
  9. PoolID int32 `json:"PoolID"` // 怪物池ID
  10. GroupID int32 `json:"GroupID"` // 怪物组ID
  11. Weight int32 `json:"Weight"` // 权重
  12. }
  13. monsterPoolConfig struct {
  14. baseConfig
  15. list []*MonsterPoolRow // all list
  16. poolIDListMaps map[int32][]*MonsterPoolRow // key:poolID
  17. poolIDGroupIDUniMaps map[int32]map[int32]*MonsterPoolRow // key:poolID, groupID
  18. }
  19. )
  20. func (p *monsterPoolConfig) Name() string {
  21. return "monster_pool"
  22. }
  23. func (p *monsterPoolConfig) Init() {
  24. p.poolIDListMaps = map[int32][]*MonsterPoolRow{}
  25. p.poolIDGroupIDUniMaps = map[int32]map[int32]*MonsterPoolRow{}
  26. }
  27. func (p *monsterPoolConfig) OnLoad(maps interface{}, reload bool) (int, error) {
  28. if reload && p.denyLoad {
  29. return 0, nil
  30. }
  31. var list []*MonsterPoolRow
  32. if err := DecodeData(maps, &list); err != nil {
  33. return 0, err
  34. }
  35. p.list = list
  36. poolIDListMaps := map[int32][]*MonsterPoolRow{}
  37. for _, row := range list {
  38. poolIDListMaps[row.PoolID] = append(poolIDListMaps[row.PoolID], row)
  39. }
  40. p.poolIDListMaps = poolIDListMaps
  41. poolIDGroupIDUniMaps := map[int32]map[int32]*MonsterPoolRow{}
  42. for _, row := range list {
  43. itemMap := poolIDGroupIDUniMaps[row.PoolID]
  44. if itemMap == nil {
  45. itemMap = map[int32]*MonsterPoolRow{}
  46. poolIDGroupIDUniMaps[row.PoolID] = itemMap
  47. }
  48. itemMap[row.GroupID] = row
  49. }
  50. p.poolIDGroupIDUniMaps = poolIDGroupIDUniMaps
  51. return len(list), nil
  52. }
  53. // func (p *monsterPoolConfig) OnAfterLoad(_ bool) {
  54. // }
  55. func (p *monsterPoolConfig) List() []*MonsterPoolRow {
  56. return p.list
  57. }
  58. func (p *monsterPoolConfig) ListByPoolID(poolID int32) ([]*MonsterPoolRow, bool) {
  59. value, found := p.poolIDListMaps[poolID]
  60. return value, found
  61. }
  62. func (p *monsterPoolConfig) ListContainPoolID(poolID int32) bool {
  63. _, found := p.poolIDListMaps[poolID]
  64. return found
  65. }
  66. func (p *monsterPoolConfig) GetByPoolIDGroupID(poolID int32, groupID int32) (*MonsterPoolRow, bool) {
  67. mapItem, found := p.poolIDGroupIDUniMaps[poolID]
  68. if !found {
  69. return nil, false
  70. }
  71. value, found := mapItem[groupID]
  72. return value, found
  73. }
  74. func (p *monsterPoolConfig) ContainPoolIDGroupID(poolID int32, groupID int32) bool {
  75. mapItem, found := p.poolIDGroupIDUniMaps[poolID]
  76. if !found {
  77. return false
  78. }
  79. _, found = mapItem[groupID]
  80. return found
  81. }