package generic import "mongo.games.com/game/gamesrv/slotspkg/slots/intf" // PluginJackpot is derived from generic.PluginBase type PluginJackpot struct { PluginBase } // CustomJackpotPools stores jackpot pools type CustomJackpotPools struct { Pools map[int64]int64 StartPoints map[int64]int64 } // CustomJackpotWin stores jackpot win results type CustomJackpotWin struct { Type int64 } // Customs implements generic.PluginBase.Customs func (p *PluginJackpot) Customs() []interface{} { return []interface{}{ &CustomJackpotPools{}, &CustomJackpotWin{}, } } // OnInit implements generic.PluginBase.OnInit func (p *PluginJackpot) OnInit(m intf.Master) { if !p.Inited(m) { p.InitPools(m) } custom := m.RootCustom(&CustomJackpotPools{}).(*CustomJackpotPools) if custom.Pools == nil { custom.Pools = map[int64]int64{} } p.setStartPoints(m) } // BeforeSpin implements generic.PluginBase.BeforeSpin func (p *PluginJackpot) BeforeSpin(m intf.Master) { if !p.Inited(m) { p.InitPools(m) } } // Inited returns if jackpot is inited func (p *PluginJackpot) Inited(m intf.Master) bool { return len(m.RootFeatures(&CustomJackpotPools{})) > 0 } // InitPools inits all pools before spin func (p *PluginJackpot) InitPools(m intf.Master) { pools := make(map[int64]int64) types := Descx(m).JackpotPrizeTypes() for _, typ := range types { pools[typ] = 0 } m.AddRootFeature(&CustomJackpotPools{ Pools: pools, }) } func (p *PluginJackpot) OnStepEnd(m intf.Master) { } // PipeInPools add some value to pool after bet func (p *PluginJackpot) PipeInPools(m intf.Master) { types := Descx(m).JackpotPrizeTypes() for _, typ := range types { if Descx(m).JackpotHasPipeIn(typ, m.Bet()) { pipeIn := p.GetPipeIn(m, typ) p.AppendPool(m, typ, pipeIn) } } } // WinPool wins a specific type pool func (p *PluginJackpot) WinPool(m intf.Master, typ int64) int64 { return p.kernelWinPool(m, typ, 1, true, true, m.Bet()) } func (p *PluginJackpot) WinPoolWithMulti(m intf.Master, typ int64, multi int64) int64 { return p.kernelWinPool(m, typ, multi, true, true, m.Bet()) } func (p *PluginJackpot) PureWinPool(m intf.Master, typ int64) int64 { return p.kernelWinPool(m, typ, 1, false, true, m.Bet()) } func (p *PluginJackpot) CalcWinPool(m intf.Master, typ int64) int64 { return p.kernelWinPool(m, typ, 1, false, false, m.Bet()) } func (p *PluginJackpot) CalcWinPoolWithBet(m intf.Master, typ int64, bet int64) int64 { return p.kernelWinPool(m, typ, 1, false, false, bet) } // kernelWinPool // typ: 赢取挡位 // multi: 额外倍数 // withFeature: 是否添加Feature,也就是是否内置赢钱 // withClear: 是否清空池子 func (p *PluginJackpot) kernelWinPool(m intf.Master, typ int64, multi int64, withFeature bool, withClear bool, bet int64) int64 { hasPipeIn := Descx(m).JackpotHasPipeIn(typ, bet) basePrize := Descx(m).JackpotBaseWin(typ, bet) * multi poolPrize := int64(0) if hasPipeIn { poolPrize = p.GetPool(m, typ) * multi if withClear { p.ClearPool(m, typ) } } prize := basePrize + poolPrize if withFeature { m.AddCursorFeature(&CustomJackpotWin{Type: typ}).SetWin(prize).SetLifetime(1) } return prize } // GetPool gets a specific type pool's value func (p *PluginJackpot) GetPool(m intf.Master, typ int64) int64 { pools := m.RootCustom(&CustomJackpotPools{}).(*CustomJackpotPools).Pools return pools[typ] } // ClearPool sets a specific type pool's value func (p *PluginJackpot) ClearPool(m intf.Master, typ int64) { pools := m.RootCustom(&CustomJackpotPools{}).(*CustomJackpotPools).Pools pools[typ] = 0 } func (p *PluginJackpot) AppendPool(m intf.Master, typ int64, n int64) { pools := m.RootCustom(&CustomJackpotPools{}).(*CustomJackpotPools).Pools pools[typ] += n } func (p *PluginJackpot) GetPipeIn(m intf.Master, typ int64) int64 { return Descx(m).JackpotPipeIn(typ, m.Bet()) } // setStartPoints sets start points into CustomJackpotPools func (p *PluginJackpot) setStartPoints(m intf.Master) { startPoints := Descx(m).JackpotStartPoints() m.RootCustom(&CustomJackpotPools{}).(*CustomJackpotPools).StartPoints = startPoints }