JackPot.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. package slotpanda
  2. import (
  3. "bet24.com/log"
  4. coreservice "bet24.com/servers/coreservice/client"
  5. "bet24.com/servers/micros/slotsservice/handler/slotcommon/betlevel"
  6. "bet24.com/servers/micros/slotsservice/handler/slotcommon/slotcount"
  7. "math/rand"
  8. )
  9. const (
  10. JackpotLevelNone = iota // 不产生jackpot
  11. JackpotLevelMini
  12. JackpotLevelMinor
  13. JackpotLevelMajor
  14. JackpotLevelGrand
  15. )
  16. type JackpotManager struct {
  17. jackpotSlotId int
  18. jackpotSlotCount int
  19. grandJackpotPercent int
  20. inGrandJackpotPercent int
  21. slotCounts *slotcount.MultipleSlotCountManager
  22. betLevelManager *betlevel.BetLevelManager
  23. }
  24. func newJackpotManager(slotId, count int, slotCounts *slotcount.MultipleSlotCountManager, levelManager *betlevel.BetLevelManager) *JackpotManager {
  25. ret := new(JackpotManager)
  26. ret.jackpotSlotCount = count
  27. ret.jackpotSlotId = slotId
  28. ret.slotCounts = slotCounts
  29. ret.betLevelManager = levelManager
  30. ret.loadData()
  31. return ret
  32. }
  33. func (jm *JackpotManager) loadData() {
  34. // 从redis读取jackpot数量
  35. jm.inGrandJackpotPercent = 1
  36. jm.grandJackpotPercent = 10
  37. }
  38. func (jm *JackpotManager) getAmount(isChipRoom bool) int {
  39. return coreservice.GetJackpotAmount(GAMEID, isChipRoom)
  40. }
  41. func (jm *JackpotManager) isJackpot(slots []int) bool {
  42. bonusCount := 0
  43. for _, v := range slots {
  44. if v%100 == jm.jackpotSlotId {
  45. bonusCount++
  46. }
  47. }
  48. return bonusCount >= jm.jackpotSlotCount
  49. }
  50. func (jm *JackpotManager) addJackpot(slots []int, betAmount int, userId int, isChipRoom bool) (bool, *Bonus) {
  51. bonusCount := 0
  52. for _, v := range slots {
  53. if v%100 == jm.jackpotSlotId {
  54. bonusCount++
  55. }
  56. }
  57. if bonusCount > 0 {
  58. jm.modifyAmount(betAmount*jm.inGrandJackpotPercent/100, userId, isChipRoom)
  59. }
  60. // 触发bonus
  61. if bonusCount >= jm.jackpotSlotCount {
  62. return bonusCount > 0, jm.createBonus(slots, betAmount, userId, isChipRoom)
  63. }
  64. return bonusCount > 0, nil
  65. }
  66. func (jm *JackpotManager) modifyAmount(amount int, userId int, isChipRoom bool) {
  67. coreservice.ModifyJackpot(amount, GAMEID, userId, "slotpanda bet", isChipRoom)
  68. }
  69. func (jm *JackpotManager) obtainJackpot(betAmount int, jackpotLevel int, userId int, isChipRoom bool) int {
  70. switch jackpotLevel {
  71. case JackpotLevelMini:
  72. return betAmount * 40
  73. case JackpotLevelMinor:
  74. return betAmount * 70
  75. case JackpotLevelMajor:
  76. return betAmount * 100
  77. case JackpotLevelGrand:
  78. amount := jm.getAmount(isChipRoom) / 100 * jm.grandJackpotPercent
  79. log.Debug("JackpotManager grand jackpot %d", amount)
  80. jm.modifyAmount(-amount, userId, isChipRoom)
  81. return betAmount*200 + amount
  82. }
  83. return 0
  84. }
  85. func (jm *JackpotManager) createBonus(slots []int, betAmount int, userId int, isChipRoom bool) *Bonus {
  86. level := 0
  87. sc := jm.slotCounts.GetMgr(level)
  88. bonus := newBonus()
  89. bonus.RespinCount = 3
  90. bonus.leftRespinCount = bonus.RespinCount
  91. bonus.BetAmount = betAmount
  92. var initFrame Bonus_Frame
  93. for i := 0; i < len(slots); i++ {
  94. if slots[i]%100 == jm.jackpotSlotId {
  95. initFrame.addBonus(i, slots[i]/100)
  96. }
  97. }
  98. bonus.addFrame(initFrame)
  99. //betLevel := jm.betLevelManager.getBetLevel(betAmount)
  100. // 生成所有frame
  101. for {
  102. if bonus.leftRespinCount <= 0 {
  103. break
  104. }
  105. var frame Bonus_Frame
  106. for i := 0; i < 4; i++ {
  107. for j := 0; j < 15; j++ {
  108. pos := i*15 + j
  109. if bonus.isPass(pos) {
  110. continue
  111. }
  112. slotId := sc.GetOneSlot(level, j)
  113. if slotId == jm.jackpotSlotId {
  114. frame.addBonus(pos, jm.getRandomMultiple())
  115. }
  116. }
  117. }
  118. bonus.addFrame(frame)
  119. if bonus.getJackpotLevel() == JackpotLevelGrand {
  120. break
  121. }
  122. if frame.isEmpty() {
  123. bonus.leftRespinCount--
  124. } else {
  125. bonus.leftRespinCount = bonus.RespinCount
  126. }
  127. }
  128. bonus.JackpotLevel = bonus.getJackpotLevel()
  129. bonus.JackpotResult = jm.obtainJackpot(betAmount, bonus.JackpotLevel, userId, isChipRoom)
  130. return bonus
  131. }
  132. func (jm *JackpotManager) getRandomMultiple() int {
  133. r := rand.Intn(100)
  134. if r < 30 {
  135. return 0
  136. }
  137. r -= 30
  138. if r < 12 {
  139. return 1
  140. }
  141. r -= 12
  142. if r < 10 {
  143. return 2
  144. }
  145. r -= 10
  146. if r < 9 {
  147. return 3
  148. }
  149. r -= 9
  150. if r < 9 {
  151. return 4
  152. }
  153. r -= 9
  154. if r < 7 {
  155. return 5
  156. }
  157. r -= 7
  158. if r < 6 {
  159. return 6
  160. }
  161. r -= 6
  162. if r < 6 {
  163. return 7
  164. }
  165. r -= 6
  166. if r < 5 {
  167. return 8
  168. }
  169. r -= 5
  170. if r < 4 {
  171. return 9
  172. }
  173. return 10
  174. }