slotcount.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package wildapeslot
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "os"
  7. "bet24.com/log"
  8. )
  9. type SlotCount struct {
  10. SlotID int
  11. Count int
  12. }
  13. type SlotColumn struct {
  14. SlotCounts []SlotCount
  15. pool []int
  16. }
  17. //把多个slotid放到一个数组,再随机取
  18. func (sc *SlotColumn) makePool() {
  19. sc.pool = []int{}
  20. for _, v := range sc.SlotCounts {
  21. for i := 0; i < v.Count; i++ {
  22. sc.pool = append(sc.pool, v.SlotID)
  23. }
  24. }
  25. }
  26. func (sc *SlotColumn) getSlot() int {
  27. return sc.pool[rand.Intn(len(sc.pool))]
  28. }
  29. type SlotLevel struct {
  30. Columns []SlotColumn
  31. }
  32. type SlotCountManager struct {
  33. levels []SlotLevel
  34. WinAmount int
  35. }
  36. func newSlotCountManager(confFile string) *SlotCountManager {
  37. log.Color(LogColor, "newSlotCountManager")
  38. ret := new(SlotCountManager)
  39. ret.loadData(confFile)
  40. return ret
  41. }
  42. func newSlotCountManagerByConfig(winAmount int, counts [][][]int) *SlotCountManager {
  43. log.Color(LogColor, "newSlotCountManagerByConfig")
  44. ret := new(SlotCountManager)
  45. ret.WinAmount = winAmount
  46. ret.loadDataByConfig(counts)
  47. return ret
  48. }
  49. func (scm *SlotCountManager) loadDataByConfig(counts [][][]int) {
  50. for _, level := range counts {
  51. // level
  52. var sl SlotLevel
  53. for _, column := range level {
  54. var sc SlotColumn
  55. for i := 0; i < len(column); i++ {
  56. if column[i] == 0 {
  57. continue
  58. }
  59. sc.SlotCounts = append(sc.SlotCounts, SlotCount{SlotID: i, Count: column[i]})
  60. }
  61. sc.makePool()
  62. sl.Columns = append(sl.Columns, sc)
  63. }
  64. scm.levels = append(scm.levels, sl)
  65. }
  66. }
  67. func (scm *SlotCountManager) loadData(confFile string) {
  68. var counts [][][]int
  69. data, err := os.ReadFile(fmt.Sprintf("slotconf/%s.json", confFile))
  70. if err != nil {
  71. data, err = os.ReadFile("slotconf/wildapeslot_count.json")
  72. if err != nil {
  73. log.Error("SlotCountManager.loadData read %s.json failed", confFile)
  74. }
  75. }
  76. err = json.Unmarshal(data, &counts)
  77. if err != nil {
  78. log.Error("SlotCountManager.loadData Unmarshal %s.json failed err:%v", confFile, err)
  79. return
  80. }
  81. scm.loadDataByConfig(counts)
  82. }
  83. //免费的时候FreeSpinInfo也会调这里
  84. func (scm *SlotCountManager) get15Slots(betLevel int, isFree bool, isBonus bool) []int {
  85. rowCount := ROW_COUNT
  86. if isFree || isBonus {
  87. rowCount = FREE_ROW_COUNT
  88. }
  89. ret := make([]int, rowCount*COLUMN_COUNT)
  90. if betLevel >= len(scm.levels) {
  91. betLevel = len(scm.levels) - 1
  92. }
  93. level := scm.levels[betLevel]
  94. for r := 0; r < rowCount; r++ {
  95. for c := 0; c < COLUMN_COUNT; c++ {
  96. //循环获取直到不是apeid的
  97. id := scm.getNoFreeSlot(&level.Columns[c], isFree, isBonus)
  98. ret[r*COLUMN_COUNT+c] = id
  99. }
  100. }
  101. return ret
  102. }
  103. func (scm *SlotCountManager) getNoFreeSlot(sc *SlotColumn, isFree bool, isBonus bool) int {
  104. var id int
  105. for {
  106. id = sc.getSlot()
  107. if !isFree && !isBonus { //普通滚动不出wild
  108. if id == MAGIC_ID {
  109. continue
  110. } else {
  111. break
  112. }
  113. } else if id != FREE_ID && id != BONUS_ID { //特殊滚动不出bonus和free
  114. break
  115. }
  116. }
  117. return id
  118. }