JackPot.go 4.1 KB

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