ladderconfig.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package ladder
  2. import (
  3. "encoding/json"
  4. "os"
  5. "time"
  6. "bet24.com/log"
  7. item "bet24.com/servers/micros/item_inventory/proto"
  8. pb "bet24.com/servers/micros/ladderservice/proto"
  9. platformconfig "bet24.com/servers/micros/platformconfig/proto"
  10. )
  11. const config_key = "ladderservice_config"
  12. var ladderConf *ladderconfig
  13. func getLadderConfig() *ladderconfig {
  14. if ladderConf == nil {
  15. ladderConf = new(ladderconfig)
  16. ladderConf.ctor()
  17. }
  18. return ladderConf
  19. }
  20. type ladderconfig struct {
  21. ConsecutiveWinPoints []pb.ConsecutiveWinPoint // 连胜额外点数配置
  22. WinPoint int // 赢点数
  23. LosePoint int // 输点数
  24. ConsecutiveCardPrice item.ItemPack // 连胜卡配置
  25. LadderConfigs []pb.LadderConfig // 段位详细配置
  26. InitialPoint int // 初始点数
  27. lastConfigString string
  28. }
  29. func (lc *ladderconfig) ctor() {
  30. log.Debug("ladder.ladderconfig.ctor()")
  31. lc.loadConfig()
  32. }
  33. func (lc *ladderconfig) loadConfig() {
  34. time.AfterFunc(10*time.Minute, lc.loadConfig)
  35. configString := platformconfig.GetConfig(config_key)
  36. if configString == "" {
  37. data, err := os.ReadFile("serviceconf/ladderservice_config.json")
  38. if err != nil {
  39. log.Release("ladderconfig.loadConfig.loadData read json failed")
  40. return
  41. }
  42. configString = string(data)
  43. platformconfig.SetConfig(config_key, configString)
  44. }
  45. if configString == lc.lastConfigString {
  46. return
  47. }
  48. lc.lastConfigString = configString
  49. err := json.Unmarshal([]byte(configString), &lc)
  50. if err != nil {
  51. log.Release("ladderconfig.loadConfig Unmarshal config [%s] err:%v", configString, err)
  52. return
  53. }
  54. }
  55. func (lc *ladderconfig) dump() {
  56. log.Release("-------------------------------")
  57. log.Release("ladderconfig.dump")
  58. defer func() {
  59. log.Release("+++++++++++++++++++++++++++++++")
  60. log.Release("")
  61. }()
  62. log.Release(lc.lastConfigString)
  63. }
  64. func (lc *ladderconfig) getConsecutiveWinAdditionalPoint(count int) int {
  65. configCount := len(lc.ConsecutiveWinPoints)
  66. if configCount == 0 {
  67. return 0
  68. }
  69. if count >= lc.ConsecutiveWinPoints[configCount-1].Count {
  70. return lc.ConsecutiveWinPoints[configCount-1].AddictionalPoint
  71. }
  72. for _, v := range lc.ConsecutiveWinPoints {
  73. if v.Count == count {
  74. return v.AddictionalPoint
  75. }
  76. }
  77. return 0
  78. }
  79. func (lc *ladderconfig) getMaxConsecutiveWinCount() int {
  80. count := len(lc.ConsecutiveWinPoints)
  81. if count == 0 {
  82. log.Release("ladderconfig.getMaxConsecutiveWinCount no config")
  83. return 0
  84. }
  85. return lc.ConsecutiveWinPoints[count-1].Count
  86. }
  87. func (lc *ladderconfig) getLadderInfo() string {
  88. return lc.lastConfigString
  89. }