| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297 |
- package slotpanda
- import (
- "bet24.com/log"
- "bet24.com/servers/games/slotcommon/slotcount"
- "bet24.com/servers/games/slotcommon/usermanager"
- "encoding/json"
- "math/rand"
- )
- type FreeSlotChange struct {
- SlotId int
- Chance int
- }
- // 每组的15个slot信息
- type FreeSlots struct {
- Slots []int // 实际Slot
- ChangedRows []int // 被变换的列
- Lines []Result // 中奖连线
- WinAmount int
- }
- type FreeSpinResult struct {
- BetAmount int
- Slots []FreeSlots
- TotalFreeCount int // 总free次数
- LeftFreeCount int // 当前free次数
- MaxScatter int // 最大数量
- CurScatter int // 当前数量
- ReFreeInner int // 当scatter满了后,产生新的轮盘
- ReFreeOuter int
- }
- func (fr *FreeSpinResult) getWinAmount() int {
- ret := 0
- for _, v := range fr.Slots {
- ret += v.WinAmount
- }
- return ret
- }
- func (fr *FreeSpinResult) getDesc() string {
- d, _ := json.Marshal(fr.Slots)
- return string(d)
- }
- type FreeSpinInfo struct {
- userId int
- freeSlotCount *slotcount.MultipleSlotCountManager
- slotmgr *slotmanager
- winShapes []WinShape
- wins []Win
- Changes []FreeSlotChange
- BetAmount int
- TotalCount int
- LeftCount int
- MaxScatter int // 最大数量
- CurScatter int // 当前数量
- scatterId int
- bonusId int
- wildId int
- level int
- fromAd bool
- }
- func newFreeSpinInfo(userId int, freeSlotCount *slotcount.MultipleSlotCountManager, winShapes []WinShape, wins []Win, slotmgr *slotmanager, changes []FreeSlotChange) *FreeSpinInfo {
- ret := new(FreeSpinInfo)
- ret.userId = userId
- ret.freeSlotCount = freeSlotCount
- ret.winShapes = winShapes
- ret.wins = wins
- ret.slotmgr = slotmgr
- ret.MaxScatter = 100
- ret.scatterId = slotmgr.getScatterSlotId()
- ret.bonusId = slotmgr.getBonusSlotId()
- ret.wildId = slotmgr.getWildSlotId()
- ret.Changes = changes
- return ret
- }
- func (f *FreeSpinInfo) addFreeSpin(freeSpinCount, beAmount int, level int, fromAd bool) {
- log.Release("slotpanda.FreeSpinInfo.addFreeSpin %d", freeSpinCount)
- f.LeftCount = freeSpinCount
- f.BetAmount = beAmount
- f.CurScatter = 0
- f.TotalCount = freeSpinCount
- f.level = level
- f.fromAd = fromAd
- }
- func (f *FreeSpinInfo) useFreeSpin() (bool, FreeSpinResult, bool) {
- var ret FreeSpinResult
- if f.LeftCount <= 0 {
- return false, ret, false
- }
- level := usermanager.GetUserReturnLevel(f.userId, GAMEID, 0)
- sc := f.freeSlotCount.GetMgr(level)
- f.LeftCount--
- ret.MaxScatter = f.MaxScatter
- ret.CurScatter = f.CurScatter
- ret.TotalFreeCount = f.TotalCount
- ret.LeftFreeCount = f.LeftCount
- ret.BetAmount = f.BetAmount
- // 产生4组
- // 变化为同一个素材
- changedSlotId := f.getChangeSlot()
- for i := 0; i < 4; i++ {
- var fs FreeSlots
- slots := sc.Get15Slots(f.level)
- // 随机一列发
- faLineCount := 1
- r := rand.Intn(100)
- if r < 50 {
- faLineCount = 1
- } else if r < 85 {
- faLineCount = 2
- } else {
- faLineCount = 3
- }
- firstFaLine := -1
- for i := 0; i < faLineCount; i++ {
- line := rand.Intn(5)
- for {
- if line == firstFaLine {
- line = rand.Intn(5)
- } else {
- break
- }
- }
- /*
- if changedSlotId == -1 {
- changedSlotId = slots[line]
- }
- // 如果素材为scatter,bonus,wild,则不能变成一列,需要重新找一个新的元素
- if changedSlotId == f.scatterId || changedSlotId == f.bonusId || changedSlotId == f.wildId {
- changedSlotId = -1
- continue
- }
- */
- firstFaLine = line
- slots[line] = changedSlotId
- slots[line+5] = slots[line]
- slots[line+10] = slots[line]
- fs.ChangedRows = append(fs.ChangedRows, line)
- }
- fs.Slots = slots
- // 添加scatter
- for _, v := range slots {
- if v == f.scatterId {
- inner, outer := f.addScatter()
- if inner > 0 {
- ret.ReFreeInner = inner
- ret.ReFreeOuter = outer
- }
- }
- }
- // 计算结果
- shapeCount := len(f.winShapes)
- for k, v := range f.winShapes {
- // 查看每条连线的数量
- s := make([]Slot, RESULT_COUNT)
- for i := 0; i < 15; i++ {
- s[i] = f.slotmgr.getSlot(slots[i])
- }
- slotID, slotCount, _ := v.getCount(s)
- // 查看结果
- result := f.getOneResult(slotID, slotCount, k)
- if result != nil {
- // 中奖了
- fs.WinAmount += f.BetAmount * result.WinRate / shapeCount
- fs.Lines = append(fs.Lines, *result)
- }
- }
- ret.Slots = append(ret.Slots, fs)
- }
- return true, ret, f.fromAd
- }
- func (f *FreeSpinInfo) getFreeCount() int {
- return f.LeftCount
- }
- func (f *FreeSpinInfo) addScatter() (int, int) {
- f.CurScatter++
- if f.CurScatter >= f.MaxScatter {
- f.CurScatter = 0
- inner, outer := f.getMultiple()
- f.TotalCount += inner * outer
- f.LeftCount += inner * outer
- log.Release("slotpanda.FreeSpinInfo.addScatter %d", f.TotalCount)
- return inner, outer
- }
- return 0, 0
- }
- // 获得免费奖励
- func (f *FreeSpinInfo) initFree(betAmount int, slots []int) (int, int) {
- scatterCount := 0
- for _, v := range slots {
- if v == f.scatterId {
- scatterCount++
- }
- }
- if scatterCount < 3 {
- return 0, 0
- }
- f.BetAmount = betAmount
- inner, outer := f.getMultiple()
- f.TotalCount = inner * outer
- f.LeftCount = f.TotalCount
- f.CurScatter = 0
- f.fromAd = false
- log.Release("slotpanda.FreeSpinInfo.initFree %d", f.TotalCount)
- return inner, outer
- }
- func (f *FreeSpinInfo) removeFreeTimes(times int) {
- f.TotalCount -= times
- f.LeftCount -= times
- if f.TotalCount < 0 {
- f.TotalCount = 0
- }
- if f.LeftCount < 0 {
- f.LeftCount = 0
- }
- }
- func (f *FreeSpinInfo) getMultiple() (inner, outer int) {
- inner = rand.Intn(3) + 1
- r := rand.Intn(100)
- if r < 35 {
- outer = 4
- return
- }
- r -= 35
- if r < 35 {
- outer = 8
- return
- }
- r -= 35
- if r < 20 {
- outer = 12
- return
- }
- outer = 16
- return
- }
- func (f *FreeSpinInfo) getOneResult(slotID, slotCount, shapeID int) *Result {
- for _, v := range f.wins {
- if v.SlotID != slotID {
- continue
- }
- for _, rate := range v.Rates {
- if rate.Count == slotCount {
- return &Result{SlotID: slotID, SlotCount: slotCount, WinShapeID: shapeID, WinRate: rate.Win}
- }
- }
- }
- return nil
- }
- func (f *FreeSpinInfo) getChangeSlot() int {
- if len(f.Changes) == 0 {
- return 3
- }
- total := 0
- for _, v := range f.Changes {
- total += v.Chance
- }
- r := rand.Intn(total)
- for _, v := range f.Changes {
- if r < v.Chance {
- return v.SlotId
- }
- r -= v.Chance
- }
- log.Release("FreeSpinInfo.getChangeSlot should not come here")
- return 3
- }
|