| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- package slotpanda
- import (
- "bet24.com/log"
- coreservice "bet24.com/servers/coreservice/client"
- "bet24.com/servers/games/slotcommon/betlevel"
- "bet24.com/servers/games/slotcommon/slotcount"
- "bet24.com/servers/games/slotcommon/usermanager"
- "math/rand"
- )
- const (
- JackpotLevelNone = iota // 不产生jackpot
- JackpotLevelMini
- JackpotLevelMinor
- JackpotLevelMajor
- JackpotLevelGrand
- )
- type JackpotManager struct {
- jackpotSlotId int
- jackpotSlotCount int
- grandJackpotPercent int
- inGrandJackpotPercent int
- slotCounts *slotcount.MultipleSlotCountManager
- betLevelManager *betlevel.BetLevelManager
- isChipRoom bool
- }
- func newJackpotManager(slotId, count int, slotCounts *slotcount.MultipleSlotCountManager, levelManager *betlevel.BetLevelManager, isChipRoom bool) *JackpotManager {
- ret := new(JackpotManager)
- ret.jackpotSlotCount = count
- ret.jackpotSlotId = slotId
- ret.slotCounts = slotCounts
- ret.isChipRoom = isChipRoom
- ret.betLevelManager = levelManager
- ret.loadData()
- return ret
- }
- func (jm *JackpotManager) loadData() {
- // 从redis读取jackpot数量
- jm.inGrandJackpotPercent = 1
- jm.grandJackpotPercent = 10
- }
- func (jm *JackpotManager) getAmount() int {
- return coreservice.GetJackpotAmount(GAMEID, jm.isChipRoom)
- }
- func (jm *JackpotManager) isJackpot(slots []int) bool {
- bonusCount := 0
- for _, v := range slots {
- if v%100 == jm.jackpotSlotId {
- bonusCount++
- }
- }
- return bonusCount >= jm.jackpotSlotCount
- }
- func (jm *JackpotManager) addJackpot(slots []int, betAmount int, userId int) (bool, *Bonus) {
- bonusCount := 0
- for _, v := range slots {
- if v%100 == jm.jackpotSlotId {
- bonusCount++
- }
- }
- if bonusCount > 0 {
- jm.modifyAmount(betAmount*jm.inGrandJackpotPercent/100, userId)
- }
- // 触发bonus
- if bonusCount >= jm.jackpotSlotCount {
- return bonusCount > 0, jm.createBonus(slots, betAmount, userId)
- }
- return bonusCount > 0, nil
- }
- func (jm *JackpotManager) modifyAmount(amount int, userId int) {
- coreservice.ModifyJackpot(amount, GAMEID, userId, "dfdc bet", jm.isChipRoom)
- }
- func (jm *JackpotManager) obtainJackpot(betAmount int, jackpotLevel int, userId int) int {
- switch jackpotLevel {
- case JackpotLevelMini:
- return betAmount * 40
- case JackpotLevelMinor:
- return betAmount * 70
- case JackpotLevelMajor:
- return betAmount * 100
- case JackpotLevelGrand:
- amount := jm.getAmount() / 100 * jm.grandJackpotPercent
- log.Debug("JackpotManager grand jackpot %d", amount)
- jm.modifyAmount(-amount, userId)
- return betAmount*200 + amount
- }
- return 0
- }
- func (jm *JackpotManager) createBonus(slots []int, betAmount int, userId int) *Bonus {
- level := usermanager.GetUserReturnLevel(userId, GAMEID, betAmount)
- sc := jm.slotCounts.GetMgr(level)
- bonus := newBonus()
- bonus.RespinCount = 3
- bonus.leftRespinCount = bonus.RespinCount
- bonus.BetAmount = betAmount
- var initFrame Bonus_Frame
- for i := 0; i < len(slots); i++ {
- if slots[i]%100 == jm.jackpotSlotId {
- initFrame.addBonus(i, slots[i]/100)
- }
- }
- bonus.addFrame(initFrame)
- //betLevel := jm.betLevelManager.getBetLevel(betAmount)
- // 生成所有frame
- for {
- if bonus.leftRespinCount <= 0 {
- break
- }
- var frame Bonus_Frame
- for i := 0; i < 4; i++ {
- for j := 0; j < 15; j++ {
- pos := i*15 + j
- if bonus.isPass(pos) {
- continue
- }
- slotId := sc.GetOneSlot(level, j)
- if slotId == jm.jackpotSlotId {
- frame.addBonus(pos, jm.getRandomMultiple())
- }
- }
- }
- bonus.addFrame(frame)
- if bonus.getJackpotLevel() == JackpotLevelGrand {
- break
- }
- if frame.isEmpty() {
- bonus.leftRespinCount--
- } else {
- bonus.leftRespinCount = bonus.RespinCount
- }
- }
- bonus.JackpotLevel = bonus.getJackpotLevel()
- bonus.JackpotResult = jm.obtainJackpot(betAmount, bonus.JackpotLevel, userId)
- return bonus
- }
- func (jm *JackpotManager) getRandomMultiple() int {
- r := rand.Intn(100)
- if r < 30 {
- return 0
- }
- r -= 30
- if r < 12 {
- return 1
- }
- r -= 12
- if r < 10 {
- return 2
- }
- r -= 10
- if r < 9 {
- return 3
- }
- r -= 9
- if r < 9 {
- return 4
- }
- r -= 9
- if r < 7 {
- return 5
- }
- r -= 7
- if r < 6 {
- return 6
- }
- r -= 6
- if r < 6 {
- return 7
- }
- r -= 6
- if r < 5 {
- return 8
- }
- r -= 5
- if r < 4 {
- return 9
- }
- return 10
- }
|