package main import ( "time" "mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/module" "mongo.games.com/game/common" "mongo.games.com/game/model" "mongo.games.com/game/protocol/webapi" ) var ( NormaIndex = []int{0, 1, 3, 5, 7, 8} // 普通奖位置 PoolIndex = []int{2, 4, 6} // 水池位置 ) var PushCoinPoolMangerInstance = &PushCoinPoolManager{ PlatformConfig: map[string]*model.PushCoinPool{}, } func init() { module.RegisteModule(PushCoinPoolMangerInstance, time.Hour, 0) } type PushCoinPoolManager struct { PlatformConfig map[string]*model.PushCoinPool } func (p *PushCoinPoolManager) ModuleName() string { return "PushCoinPoolManager" } func (p *PushCoinPoolManager) Init() { // 加载水池 for _, v := range PlatformMgrSingleton.GetPlatforms() { d, err := model.PushCoinLoad(v.IdStr) if err != nil { panic(err) } d.Platform = v.IdStr p.PlatformConfig[v.IdStr] = d } } func (p *PushCoinPoolManager) save(d *model.PushCoinPool) { err := model.PushCoinSave(d) if err != nil { logger.Logger.Errorf("save PushCoinPool error: %v", err) } } func (p *PushCoinPoolManager) Update() { } func (p *PushCoinPoolManager) Shutdown() { // 保存水池 for _, v := range p.PlatformConfig { p.save(v) } module.UnregisteModule(p) } func (p *PushCoinPoolManager) Add(platform string, val int64) { cfg, ok := p.PlatformConfig[platform] if !ok { cfg = model.NewPushCoinPool(platform) p.PlatformConfig[platform] = cfg } conf := WelfareMgrSington.GetConfig(platform).PushCoinConfig if conf.GetOn() != common.On { return } f := func(i int, poolInfo *model.PushCoinPoolInfo, pool *webapi.PushCoinPool, rate float64) { if pool != nil && pool.GetOn() == common.On { change := int64(float64(val) * rate) poolInfo.CurCoin += change if poolInfo.CurCoin >= pool.GetUpperLimit() { poolInfo.Remain = pool.GetUpperLimit() poolInfo.CurCoin -= pool.GetUpperLimit() poolInfo.Version++ } logger.Logger.Tracef("推币机 水池%v PoolInfo:%+v Change:%v Value:%v Rate:%v Limit:%v", i, poolInfo, change, val, rate, pool.GetUpperLimit()) } } f(1, cfg.Pool1, conf.GetPool1(), 0.05) f(2, cfg.Pool2, conf.GetPool2(), 0.005) f(3, cfg.Pool3, conf.GetPool3(), 0.001) }