drawConfig.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // this file is auto create by program, don't edit manually
  2. package data
  3. import (
  4. mhayaError "github.com/mhaya/error"
  5. mhayaLogger "github.com/mhaya/logger"
  6. )
  7. type drawConfig struct {
  8. maps map[int]*DrawConfigRow
  9. }
  10. type DrawConfigRow struct {
  11. ID int // #规则ID
  12. Type int // 规则类型(1新手2基础)
  13. Order int //排序
  14. Reward []ItemReward //奖励
  15. Weight int // 权重
  16. HourTotalCondition int // 每小时最多中奖次数条件
  17. DailyTotalCondition int // 每天最多中奖次数
  18. WeeklyTotalCondition int // 每周最多中奖次数
  19. PersonTotalCondition int // 个人最多中奖次数条件
  20. }
  21. func (p *drawConfig) Name() string {
  22. return "drawConfig"
  23. }
  24. func (p *drawConfig) Init() {
  25. p.maps = make(map[int]*DrawConfigRow)
  26. }
  27. func (p *drawConfig) OnLoad(maps interface{}, _ bool) (int, error) {
  28. list, ok := maps.([]interface{})
  29. if !ok {
  30. return 0, mhayaError.Error("maps convert to []interface{} error.")
  31. }
  32. loadMaps := make(map[int]*DrawConfigRow)
  33. for index, data := range list {
  34. loadConfig := &DrawConfigRow{}
  35. err := DecodeData(data, loadConfig)
  36. if err != nil {
  37. mhayaLogger.Warnf("decode error. [row = %d, %v], err = %s", index+1, loadConfig, err)
  38. continue
  39. }
  40. loadMaps[loadConfig.ID] = loadConfig
  41. }
  42. p.maps = loadMaps
  43. return len(list), nil
  44. }
  45. func (p *drawConfig) OnAfterLoad(_ bool) {
  46. }
  47. func (p *drawConfig) GetMap() map[int]*DrawConfigRow {
  48. return p.maps
  49. }
  50. func (p *drawConfig) GetByType(tp int) map[int]*DrawConfigRow {
  51. var result = make(map[int]*DrawConfigRow)
  52. for k, row := range p.maps {
  53. if row.Type == tp {
  54. result[k] = row
  55. }
  56. }
  57. return result
  58. }
  59. func (p *drawConfig) Get(pk int) (*DrawConfigRow, bool) {
  60. i, found := p.maps[pk]
  61. return i, found
  62. }
  63. func (p *drawConfig) Contain(pk int) bool {
  64. _, found := p.Get(pk)
  65. return found
  66. }