92 lines
2.1 KiB
Go
92 lines
2.1 KiB
Go
package main
|
|
|
|
import (
|
|
"mongo.games.com/game/common"
|
|
"mongo.games.com/game/protocol/webapi"
|
|
"mongo.games.com/goserver/core/logger"
|
|
"time"
|
|
|
|
"mongo.games.com/goserver/core/module"
|
|
)
|
|
|
|
var (
|
|
NormaIndex = []int{0, 1, 3, 5, 7, 8} // 普通奖位置
|
|
PoolIndex = []int{2, 4, 6} // 水池位置
|
|
)
|
|
|
|
var PushCoinPoolMangerInstance = &PushCoinPoolManager{
|
|
PlatformConfig: map[string]*PushCoinPool{},
|
|
}
|
|
|
|
func init() {
|
|
module.RegisteModule(PushCoinPoolMangerInstance, time.Hour, 0)
|
|
}
|
|
|
|
type PushCoinPool struct {
|
|
Pool1 *PushCoinPoolInfo
|
|
Pool2 *PushCoinPoolInfo
|
|
Pool3 *PushCoinPoolInfo
|
|
}
|
|
|
|
type PushCoinPoolInfo struct {
|
|
CurCoin int64 // 当前金币
|
|
Remain int64 // 剩余金币
|
|
Version int64 // 版本号, 达到上限后更新
|
|
}
|
|
|
|
type PushCoinPoolManager struct {
|
|
PlatformConfig map[string]*PushCoinPool
|
|
}
|
|
|
|
func (p *PushCoinPoolManager) ModuleName() string {
|
|
return "PushCoinPoolManager"
|
|
}
|
|
|
|
func (p *PushCoinPoolManager) Init() {
|
|
// 加载水池
|
|
}
|
|
|
|
func (p *PushCoinPoolManager) Update() {
|
|
|
|
}
|
|
|
|
func (p *PushCoinPoolManager) Shutdown() {
|
|
// 保存水池
|
|
module.UnregisteModule(p)
|
|
}
|
|
|
|
func (p *PushCoinPoolManager) Add(platform string, val int64) {
|
|
cfg, ok := p.PlatformConfig[platform]
|
|
if !ok {
|
|
cfg = &PushCoinPool{
|
|
Pool1: &PushCoinPoolInfo{},
|
|
Pool2: &PushCoinPoolInfo{},
|
|
Pool3: &PushCoinPoolInfo{},
|
|
}
|
|
p.PlatformConfig[platform] = cfg
|
|
}
|
|
|
|
conf := WelfareMgrSington.GetConfig(platform).PushCoinConfig
|
|
if conf.GetOn() != common.On {
|
|
return
|
|
}
|
|
|
|
f := func(i int, poolInfo *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)
|
|
}
|