package base import ( "encoding/json" "fmt" "math" "strconv" "strings" "sync" "time" "mongo.games.com/goserver/core/basic" "mongo.games.com/goserver/core/task" "mongo.games.com/game/common" "mongo.games.com/game/model" "mongo.games.com/game/protocol/server" "mongo.games.com/game/protocol/webapi" "mongo.games.com/game/srvdata" "mongo.games.com/goserver/core/logger" "mongo.games.com/goserver/core/module" ) const ( CoinPoolStatus_Normal = iota //库存下限 < 库存值 < 库存上限 CoinPoolStatus_Low //库存值 < 库存下限 CoinPoolStatus_High //库存上限 < 库存值 < 库存上限+偏移量 CoinPoolStatus_TooHigh //库存>库存上限+偏移量 ) var CoinPoolMgr = &CoinPoolManager{ CoinPool: new(sync.Map), ProfitPool: new(sync.Map), NoviceCoinPool: new(sync.Map), CoinPoolSetting: make(map[string]*webapi.CoinPoolSetting), curRunTime: make(map[string]int64), publicPond: new(sync.Map), bossPond: new(sync.Map), } func GetCoinPoolMgr() *CoinPoolManager { return CoinPoolMgr } const CoinPoolKeyToken = "-" const CoinPoolKeyTokenGroup = "+" type CoinPoolListener interface { OnSettingUpdate(oldSetting, newSetting *webapi.CoinPoolSetting) } type CoinPoolManager struct { //调控池 CoinPoolDBKey string CoinPool *sync.Map //收益池 ProfitPoolDBKey string ProfitPool *sync.Map //新手池 NoviceCoinPoolDBKey string NoviceCoinPool *sync.Map dirty bool // 水池配置 CoinPoolSetting map[string]*webapi.CoinPoolSetting //初始化值需要配置数据表DB_GameCoinPool // 重置水池的时间,水池索引:时间戳 curRunTime map[string]int64 listener []CoinPoolListener // 捕鱼 publicPond *sync.Map //公共池 bossPond *sync.Map //BOSS池 } func (this *CoinPoolManager) RegisterListener(l CoinPoolListener) { this.listener = append(this.listener, l) } func (this *CoinPoolManager) GenKey(gameFreeId int32, platform string, groupId int32) string { var key string if groupId != 0 { key = fmt.Sprintf("%v%v%v", gameFreeId, CoinPoolKeyTokenGroup, groupId) } else { key = fmt.Sprintf("%v%v%v", gameFreeId, CoinPoolKeyToken, platform) } return key } func (this *CoinPoolManager) SplitKey(key string) (gameFreeId, groupId int32, platform string, ok bool) { if strings.Contains(key, CoinPoolKeyToken) { datas := strings.Split(key, CoinPoolKeyToken) if len(datas) >= 2 { id, err := strconv.Atoi(datas[0]) if err == nil { gameFreeId = int32(id) } platform = datas[1] ok = true return } } else { datas := strings.Split(key, CoinPoolKeyTokenGroup) if len(datas) >= 2 { id, err := strconv.Atoi(datas[0]) if err == nil { gameFreeId = int32(id) } id, err = strconv.Atoi(datas[1]) if err == nil { groupId = int32(id) } ok = true return } } return } // AddProfitPool 增加收益池 func (this *CoinPoolManager) AddProfitPool(key string, coin int64) bool { setting := this.getCoinPoolSetting(key) if setting == nil || setting.GetSwitch() == 1 { return false } poolValue, ok := this.ProfitPool.Load(key) if !ok { this.ProfitPool.Store(key, coin) this.dirty = true return true } poolCoin, ok := poolValue.(int64) if !ok { return false } this.ProfitPool.Store(key, poolCoin+coin) this.dirty = true return true } // GetProfitPoolCoin 获取收益池水位 func (this *CoinPoolManager) GetProfitPoolCoin(gameFreeId int32, platform string, groupId int32) int64 { key := this.GenKey(gameFreeId, platform, groupId) poolValue, ok := this.ProfitPool.Load(key) if !ok { return 0 } poolCoin, ok := poolValue.(int64) if !ok { logger.Logger.Errorf("Error type convert in coinpoolmanager GetProfitPoolCoin:%v-%v", key, poolValue) return 0 } return poolCoin } // GetProfitRate 获取营收比例 func (this *CoinPoolManager) GetProfitRate(setting *webapi.CoinPoolSetting) int32 { if setting == nil { return 0 } // 营收比例 rate := setting.GetProfitRate() if rate != 0 { return rate } return 0 } // 获取调控池水位 func (this *CoinPoolManager) getCoinPoolCoin(key string) int64 { poolValue, ok := this.CoinPool.Load(key) if !ok { return 0 } poolCoin, ok := poolValue.(int64) if !ok { logger.Logger.Errorf("Error type convert in coinpoolmanager GetCoin:%v-%v", key, poolValue) return 0 } return poolCoin } // 获取调控池水位 func (this *CoinPoolManager) getNoviceCoinPoolCoin(key string) int64 { poolValue, ok := this.NoviceCoinPool.Load(key) if !ok { return 0 } poolCoin, ok := poolValue.(int64) if !ok { logger.Logger.Errorf("Error type convert in coinpoolmanager GetNoviceCoin:%v-%v", key, poolValue) return 0 } return poolCoin } // 减少调控池水位 // 返回当前水位 func (this *CoinPoolManager) popCoin(key string, coin int64) (bool, int64) { setting := this.getCoinPoolSetting(key) if setting == nil || setting.GetSwitch() == 1 { return false, 0 } poolValue, ok := this.CoinPool.Load(key) if !ok { return false, 0 } poolCoin, ok := poolValue.(int64) if !ok { logger.Logger.Errorf("Error type convert in coinpoolmanager popcoin:%v-%v", key, poolValue) return false, 0 } //if poolCoin < coin { // return false //} curValue := poolCoin - coin if curValue < -99999999 { curValue = -99999999 } this.CoinPool.Store(key, curValue) this.dirty = true logger.Logger.Infof("$$$$$$$$金币池 %v 取出 %v 金币,现有金币 %v.$$$$$$$$", key, coin, curValue) return true, curValue } // 减少调控池水位 // 返回当前水位 func (this *CoinPoolManager) popNoviceCoin(key string, coin int64) (bool, int64) { setting := this.getCoinPoolSetting(key) if setting == nil || setting.GetSwitch() == 1 { return false, 0 } poolValue, ok := this.NoviceCoinPool.Load(key) if !ok { return false, 0 } poolCoin, ok := poolValue.(int64) if !ok { logger.Logger.Errorf("Error type convert in coinpoolmanager popNoviceCoin:%v-%v", key, poolValue) return false, 0 } //if poolCoin < coin { // return false //} curValue := poolCoin - coin if curValue < -99999999 { curValue = -99999999 } this.NoviceCoinPool.Store(key, curValue) this.dirty = true logger.Logger.Infof("$$$$$$$$新手金币池 %v 取出 %v 金币,现有金币 %v.$$$$$$$$", key, coin, curValue) return true, curValue } // 增加调控池水位 // 返回当前水位 func (this *CoinPoolManager) pushCoin(key string, coin int64) int64 { setting := this.getCoinPoolSetting(key) if setting == nil || setting.GetSwitch() == 1 { return 0 } poolValue, ok := this.CoinPool.Load(key) if !ok { this.CoinPool.Store(key, coin) this.dirty = true logger.Logger.Infof("$$$$$$$$金币池 %v 放入 %v 金币,现有金币 %v.$$$$$$$$", key, coin, coin) return coin } poolCoin, ok := poolValue.(int64) if !ok { logger.Logger.Errorf("Coin pool push error type value:%v-%v", key, poolValue) return 0 } poolCoin += coin this.CoinPool.Store(key, poolCoin) this.dirty = true logger.Logger.Infof("$$$$$$$$金币池 %v 放入 %v 金币,现有金币 %v.$$$$$$$$", key, coin, poolCoin) return poolCoin } // 增加调控池水位 // 返回当前水位 func (this *CoinPoolManager) pushNoviceCoin(key string, coin int64) int64 { setting := this.getCoinPoolSetting(key) if setting == nil || setting.GetSwitch() == 1 { return 0 } poolValue, ok := this.NoviceCoinPool.Load(key) if !ok { this.NoviceCoinPool.Store(key, coin) this.dirty = true logger.Logger.Infof("$$$$$$$$新手金币池 %v 放入 %v 金币,现有金币 %v.$$$$$$$$", key, coin, coin) return coin } poolCoin, ok := poolValue.(int64) if !ok { logger.Logger.Errorf("NoviceCoin pool push error type value:%v-%v", key, poolValue) return 0 } poolCoin += coin this.NoviceCoinPool.Store(key, poolCoin) this.dirty = true logger.Logger.Infof("$$$$$$$$新手金币池 %v 放入 %v 金币,现有金币 %v.$$$$$$$$", key, coin, poolCoin) return poolCoin } // PopCoin 减少调控池水位 func (this *CoinPoolManager) PopCoin(gameFreeId, groupId int32, platform string, coin int64) bool { if coin == 0 { return true } key := this.GenKey(gameFreeId, platform, groupId) setting := this.getCoinPoolSetting(key) if setting == nil || setting.GetSwitch() == 1 { return true } poolVal := coin if coin < 0 { //负值为收益 rate := this.GetProfitRate(setting) if rate != 0 { //负值也生效??? profit := coin * int64(rate) / 1000 this.AddProfitPool(key, -profit) poolVal = coin - profit } } ok, _ := this.popCoin(key, poolVal) if ok { dbGameFree := srvdata.PBDB_GameFreeMgr.GetData(gameFreeId) if dbGameFree != nil && dbGameFree.GetSceneType() != -1 { //非试玩场 //保存数据 //this.ReportCoinPoolRecEvent(gameFreeId, groupId, platform, -coin, curPoolVal, false) setting := this.GetCoinPoolSetting(platform, gameFreeId, groupId) if setting != nil { poolValue, ok := this.CoinPool.Load(key) if ok { poolCoin, ok := poolValue.(int64) if ok { if setting.GetLowerLimit() > poolCoin { WarningCoinPool(Warning_CoinPoolLow, gameFreeId) } if poolCoin < 0 { WarningCoinPool(Warning_CoinPoolZero, gameFreeId) } } } } } return true } return false } // PushCoin 增加调控池水位 func (this *CoinPoolManager) PushCoin(gameFreeId, groupId int32, platform string, coin int64) { if coin == 0 { return } key := this.GenKey(gameFreeId, platform, groupId) setting := this.getCoinPoolSetting(key) if setting == nil || setting.GetSwitch() == 1 { return } poolVal := coin if coin > 0 { //处理收益池 rate := this.GetProfitRate(setting) if rate != 0 { //负值也生效??? profit := coin * int64(rate) / 1000 this.AddProfitPool(key, profit) poolVal = coin - profit } } this.pushCoin(key, poolVal) return } // GetCoin 获取调控池水位 func (this *CoinPoolManager) GetCoin(gameFreeId int32, platform string, groupId int32) int64 { key := this.GenKey(gameFreeId, platform, groupId) return this.getCoinPoolCoin(key) } // UpdateCoinPoolSetting 更新或添加水池配置 // worldsrv创建房间时发送,或后台修改水池后worldsrv发送给gamesrv func (this *CoinPoolManager) UpdateCoinPoolSetting(setting *webapi.CoinPoolSetting) { if setting != nil { key := this.GenKey(setting.GetGameFreeId(), setting.GetPlatform(), setting.GetGroupId()) // ResetTime if setting.GetResetTime() != 0 { runTime := time.Now().Unix() + setting.GetResetTime() this.curRunTime[key] = runTime } old, _ := this.CoinPoolSetting[key] this.CoinPoolSetting[key] = setting for _, v := range this.listener { v.OnSettingUpdate(old, setting) } // Switch if old.GetSwitch() != setting.GetSwitch() { } // 调控池初始化 initValue := setting.GetInitValue() if initValue != 0 { //初始化水池 _, ok := this.CoinPool.Load(key) if !ok { this.pushCoin(key, initValue) } } // 新手调控池初始化 initValue = setting.GetInitNoviceValue() if initValue != 0 { //初始化水池 _, ok := this.NoviceCoinPool.Load(key) if !ok { this.pushNoviceCoin(key, initValue) } } } } // ResetCoinPool 水位重置 // 后台请求worldsrv,worldsrv发送给gamesrv func (this *CoinPoolManager) ResetCoinPool(wgRcp *server.WGResetCoinPool) { if wgRcp != nil { key := this.GenKey(wgRcp.GetGameFreeId(), wgRcp.GetPlatform(), wgRcp.GetGroupId()) if setting, exist := this.CoinPoolSetting[key]; exist { switch wgRcp.GetPoolType() { case 1: //水池 value := wgRcp.GetValue() if value == -1 { initValue := setting.GetInitValue() if initValue != 0 { //初始化水池 value = initValue } } this.CoinPool.Store(key, value) logger.Logger.Infof("$$$$$$$$金币池 %v 重置金币 %v.$$$$$$$$", key, value) case 2: //营收池 value := int64(wgRcp.GetValue()) if value == -1 { value = 0 } this.ProfitPool.Store(key, value) logger.Logger.Infof("$$$$$$$$营收池 %v 重置金币 %v.$$$$$$$$", key, value) case 3: //水池&营收池 value := int64(wgRcp.GetValue()) if value == -1 { initValue := setting.GetInitValue() if initValue != 0 { //初始化水池 value = int64(initValue) } } this.CoinPool.Store(key, value) logger.Logger.Infof("$$$$$$$$金币池 %v 重置金币 %v.$$$$$$$$", key, value) value = int64(wgRcp.GetValue()) if value == -1 { value = 0 } this.ProfitPool.Store(key, value) logger.Logger.Infof("$$$$$$$$营收池 %v 重置金币 %v.$$$$$$$$", key, value) case 8: // 新手池 value := wgRcp.GetValue() if value == -1 { initValue := setting.GetInitNoviceValue() if initValue != 0 { //初始化水池 value = initValue } } this.NoviceCoinPool.Store(key, value) logger.Logger.Infof("$$$$$$$$新手金币池 %v 重置金币 %v.$$$$$$$$", key, value) } } } } func (this *CoinPoolManager) getCoinPoolSetting(key string) *webapi.CoinPoolSetting { if setting, exist := this.CoinPoolSetting[key]; exist { return setting } return nil } // GetCoinPoolSetting 获取水池配置 func (this *CoinPoolManager) GetCoinPoolSetting(platform string, gamefreeid, groupId int32) *webapi.CoinPoolSetting { key := this.GenKey(gamefreeid, platform, groupId) return this.getCoinPoolSetting(key) } // GetCoinPoolSettingByGame 获取水池配置 func (this *CoinPoolManager) GetCoinPoolSettingByGame(platform string, gameId, gameMode, groupId int32) (settings []*webapi.CoinPoolSetting) { ids, _ := srvdata.GameFreeMgr.GetGameFreeIds(gameId, gameMode) for _, id := range ids { setting := this.GetCoinPoolSetting(platform, id, groupId) if setting != nil { s := &webapi.CoinPoolSetting{ Platform: setting.GetPlatform(), GameFreeId: setting.GetGameFreeId(), ServerId: setting.GetServerId(), GroupId: setting.GetGroupId(), InitValue: setting.GetInitValue(), LowerLimit: setting.GetLowerLimit(), UpperLimit: setting.GetUpperLimit(), QuDu: setting.GetQuDu(), UpperOdds: setting.GetUpperOdds(), UpperOddsMax: setting.GetUpperOddsMax(), LowerOdds: setting.GetLowerOdds(), LowerOddsMax: setting.GetLowerOddsMax(), ProfitRate: setting.GetProfitRate(), InitNoviceValue: setting.GetInitNoviceValue(), CtrlRate: setting.GetCtrlRate(), ResetTime: setting.GetResetTime(), Switch: setting.GetSwitch(), CoinValue: this.GetCoin(id, platform, groupId), // 当前水位 ProfitPool: this.GetProfitPoolCoin(id, platform, groupId), // 收益池水位 NoviceCoinValue: this.GetNoviceCoin(id, platform, groupId), // 新手池水位 } settings = append(settings, s) } } return } func (this *CoinPoolManager) GetCoinPoolOdds(platform string, gamefreeid, groupId int32) int32 { var coin int64 var odds int32 key := this.GenKey(gamefreeid, platform, groupId) setting := this.getCoinPoolSetting(key) if setting != nil { coin = this.getCoinPoolCoin(key) if coin > setting.GetUpperLimit() { v := common.SliceMinValue([]int{800, int(float64(coin-setting.GetUpperLimit())/float64(setting.GetQuDu())* float64(setting.GetUpperOddsMax()-setting.GetUpperOdds()) + float64(setting.GetUpperOdds()))}) odds = int32(common.SliceMaxValue([]int{100, v})) } else if coin < setting.GetLowerLimit() { v := common.SliceMaxValue([]int{-800, int(float64(coin-setting.GetLowerLimit())/float64(setting.GetQuDu())* float64(setting.GetLowerOdds()-setting.GetLowerOddsMax()) + float64(setting.GetLowerOdds()))}) odds = int32(common.SliceMinValue([]int{-100, v})) } } logger.Logger.Tracef("TienLenSceneData 场次水池调控 platform:%v gamefreeid:%v groupId:%v Coin:%v, config:%v 概率:%v", platform, gamefreeid, groupId, coin, setting, odds) return odds } // ////////////////////////////////////////////////////////////////// // / Module Implement [beg] // ////////////////////////////////////////////////////////////////// func (this *CoinPoolManager) ModuleName() string { return "CoinPoolManager" } func (this *CoinPoolManager) Init() { // 调控池 this.CoinPoolDBKey = fmt.Sprintf("CoinPoolManager_Srv%v", common.GetSelfSrvId()) data := model.GetStrKVGameData(this.CoinPoolDBKey) coinPool := make(map[string]int64) err := json.Unmarshal([]byte(data), &coinPool) if err == nil { for key, value := range coinPool { this.CoinPool.Store(key, value) } } else { logger.Logger.Error("Unmarshal coin pool error:", err) } // 新手调控池 this.NoviceCoinPoolDBKey = fmt.Sprintf("NoviceCoinPoolManager_Srv%v", common.GetSelfSrvId()) data = model.GetStrKVGameData(this.NoviceCoinPoolDBKey) noviceCoinPool := make(map[string]int64) err = json.Unmarshal([]byte(data), &noviceCoinPool) if err == nil { for key, value := range noviceCoinPool { this.NoviceCoinPool.Store(key, value) } } else { logger.Logger.Error("Unmarshal novice coin pool error:", err) } // 收益池 this.ProfitPoolDBKey = fmt.Sprintf("ProfitPoolManager_Srv%v", common.GetSelfSrvId()) data = model.GetStrKVGameData(this.ProfitPoolDBKey) profitPool := make(map[string]int64) err = json.Unmarshal([]byte(data), &profitPool) if err == nil { for key, value := range profitPool { this.ProfitPool.Store(key, value) } } else { logger.Logger.Error("Unmarshal profit pool error:", err) } } func (this *CoinPoolManager) Update() { if this.dirty { this.dirty = false this.Save(true) } } func (this *CoinPoolManager) Shutdown() { this.Save(false) module.UnregisteModule(this) } func (this *CoinPoolManager) Save(asyn bool) { // 调控池 coinPool := make(map[string]int64) this.CoinPool.Range(func(key, value interface{}) bool { coinPool[key.(string)] = value.(int64) return true }) buff, err := json.Marshal(coinPool) if err == nil { if asyn { task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { return model.UptStrKVGameData(this.CoinPoolDBKey, string(buff)) }), nil, "UptStrKVGameData").Start() } else { model.UptStrKVGameData(this.CoinPoolDBKey, string(buff)) } } else { logger.Logger.Error("Marshal coin pool error:", err) } // 新手调控池 coinPool = make(map[string]int64) this.NoviceCoinPool.Range(func(key, value interface{}) bool { coinPool[key.(string)] = value.(int64) return true }) buff, err = json.Marshal(coinPool) if err == nil { if asyn { task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { return model.UptStrKVGameData(this.NoviceCoinPoolDBKey, string(buff)) }), nil, "UptStrKVGameData").Start() } else { model.UptStrKVGameData(this.NoviceCoinPoolDBKey, string(buff)) } } else { logger.Logger.Error("Marshal novice coin pool error:", err) } // 收益池 profitPool := make(map[string]int64) this.ProfitPool.Range(func(key, value interface{}) bool { profitPool[key.(string)] = value.(int64) return true }) buffProfit, err := json.Marshal(profitPool) if err == nil { if asyn { task.New(nil, task.CallableWrapper(func(o *basic.Object) interface{} { return model.UptStrKVGameData(this.ProfitPoolDBKey, string(buffProfit)) }), nil, "UptStrKVGameData").Start() } else { model.UptStrKVGameData(this.ProfitPoolDBKey, string(buffProfit)) } } else { logger.Logger.Error("Marshal profit pool error:", err) } } func (this *CoinPoolManager) OnMiniTimer() { } func (this *CoinPoolManager) OnHourTimer() { } func (this *CoinPoolManager) OnDayTimer() { logger.Logger.Info("(this *CoinPoolManager) OnDayTimer") } func (this *CoinPoolManager) OnWeekTimer() { logger.Logger.Info("(this *CoinPoolManager) OnWeekTimer") } func (this *CoinPoolManager) OnMonthTimer() { logger.Logger.Info("(this *CoinPoolManager) OnMonthTimer") // 每月1号清空营收池 //this.ClearProfitPool() } func (this *CoinPoolManager) GetTax() float64 { return 0 } func (this *CoinPoolManager) SetTax(tax float64) { } func init() { module.RegisteModule(CoinPoolMgr, time.Minute, 0) CoinPoolMgr.RegisterListener(new(CoinPoolFishListener)) } // GetCoinPoolStatesByPlatform 获取水池状态 func (this *CoinPoolManager) GetCoinPoolStatesByPlatform(platform string, games []*common.GamesIndex) (info map[int32]*common.CoinPoolStatesInfo) { info = make(map[int32]*common.CoinPoolStatesInfo) for _, g := range games { gameId := srvdata.PBDB_GameFreeMgr.GetData(g.GameFreeId).GetGameId() key := this.GenKey(g.GameFreeId, platform, g.GroupId) pool := this.CoinPoolSetting[key] if pool != nil { //在当前水池找到了 state, _ := this.GetCoinPoolStatus(platform, g.GameFreeId, pool.GetGroupId()) nowsate := int32(1) switch state { case CoinPoolStatus_Normal: nowsate = 1 case CoinPoolStatus_Low: nowsate = 2 case CoinPoolStatus_High: nowsate = 3 case CoinPoolStatus_TooHigh: nowsate = 4 } //当前水池的值 nowpool := &common.CoinPoolStatesInfo{} nowpool.GameId = gameId nowpool.GameFreeId = g.GameFreeId nowpool.CoinValue = int32(this.GetCoin(g.GameFreeId, platform, g.GroupId)) nowpool.States = nowsate info[g.GameFreeId] = nowpool } else { //在当前水池没有找到并且已经开启的游戏 给默认值 //def := srvdata.PBDB_GameCoinPoolMgr.GetData(g.GameFreeId) nowpool := &common.CoinPoolStatesInfo{} nowpool.GameId = gameId nowpool.GameFreeId = g.GameFreeId nowpool.States = 1 info[g.GameFreeId] = nowpool } } return } // PushCoinNovice 增加新手池水位 func (this *CoinPoolManager) PushCoinNovice(gameFreeId, groupId int32, platform string, coin int64) { if coin == 0 { return } key := this.GenKey(gameFreeId, platform, groupId) setting := this.getCoinPoolSetting(key) if setting == nil || setting.GetSwitch() == 1 { return } poolVal := coin if coin > 0 { //处理收益池 rate := this.GetProfitRate(setting) if rate != 0 { //负值也生效??? profit := coin * int64(rate) / 1000 this.AddProfitPool(key, profit) poolVal = coin - profit } } this.pushNoviceCoin(key, poolVal) return } // PopCoinNovice 减少新手池水位 func (this *CoinPoolManager) PopCoinNovice(gameFreeId, groupId int32, platform string, coin int64) bool { if coin == 0 { return true } key := this.GenKey(gameFreeId, platform, groupId) setting := this.getCoinPoolSetting(key) if setting == nil || setting.GetSwitch() == 1 { return true } poolVal := coin if coin < 0 { //负值为收益 rate := this.GetProfitRate(setting) if rate != 0 { //负值也生效??? profit := coin * int64(rate) / 1000 this.AddProfitPool(key, -profit) poolVal = coin - profit } } ok, _ := this.popNoviceCoin(key, poolVal) if ok { dbGameFree := srvdata.PBDB_GameFreeMgr.GetData(gameFreeId) if dbGameFree != nil && dbGameFree.GetSceneType() != -1 { //非试玩场 //保存数据 //this.ReportCoinPoolRecEvent(gameFreeId, groupId, platform, -coin, curPoolVal, false) setting := this.GetCoinPoolSetting(platform, gameFreeId, groupId) if setting != nil { poolValue, ok := this.NoviceCoinPool.Load(key) if ok { poolCoin, ok := poolValue.(int64) if ok { if int64(setting.GetLowerLimit()) > poolCoin { WarningCoinPool(Warning_CoinPoolLow, gameFreeId) } if poolCoin < 0 { WarningCoinPool(Warning_CoinPoolZero, gameFreeId) } } } } } return true } return false } // GetNoviceCoin 获取新手池水位 func (this *CoinPoolManager) GetNoviceCoin(gameFreeId int32, platform string, groupId int32) int64 { key := this.GenKey(gameFreeId, platform, groupId) return this.getNoviceCoinPoolCoin(key) } // IsMaxOutHaveEnough 判定是否满足出分,out 为负值是出分,正值为收分 func (this *CoinPoolManager) IsMaxOutHaveEnough(platform string, gameFreeId int32, groupId int32, out int64) bool { return false } // GetCoinPoolCtx 获取水池状态 func (this *CoinPoolManager) GetCoinPoolCtx(platform string, gamefreeid, groupId int32) model.CoinPoolCtx { setting := this.GetCoinPoolSetting(platform, gamefreeid, groupId) if setting == nil { return model.CoinPoolCtx{} } curCoin := this.GetCoin(gamefreeid, platform, groupId) state := CoinPoolStatus_Normal //switch { //case curCoin < int64(setting.GetLowerLimit()): // state = CoinPoolStatus_Low //case curCoin > int64(setting.GetUpperLimit()) && curCoin < int64(setting.GetUpperLimit()+setting.GetUpperOffsetLimit()): // state = CoinPoolStatus_High //case curCoin > int64(setting.GetUpperLimit()+setting.GetUpperOffsetLimit()): // state = CoinPoolStatus_TooHigh //} ctx := model.CoinPoolCtx{CurrValue: int32(curCoin), CurrMode: int32(state)} ctx.LowerLimit = setting.GetLowerLimit() ctx.UpperLimit = setting.GetUpperLimit() return ctx } func (this *CoinPoolManager) getCoinPoolStatus(platform string, gamefreeid, groupId int32, value int64) (int, int) { curCoin := this.GetCoin(gamefreeid, platform, groupId) if value < 0 { curCoin += value } setting := this.GetCoinPoolSetting(platform, gamefreeid, groupId) if setting == nil { return CoinPoolStatus_Normal, 10000 } return CoinPoolStatus_Normal, 10000 } // GetCoinPoolStatus 获取水池水位状态 func (this *CoinPoolManager) GetCoinPoolStatus(platform string, gamefreeid, groupId int32) (int, int) { return this.getCoinPoolStatus(platform, gamefreeid, groupId, 0) } // GetCoinPoolStatus2 获取减少水位后的水位状态 // value 减少值,需要带负号 func (this *CoinPoolManager) GetCoinPoolStatus2(platform string, gamefreeid, groupId int32, value int64) (int, int) { return this.getCoinPoolStatus(platform, gamefreeid, groupId, value) } // 增加BOSS池 func (this *CoinPoolManager) AddBossPond(sceneType int32, score int64) { value, ok := this.bossPond.Load(sceneType) if ok { sumValue := value.(int64) + score if sumValue > math.MaxInt64 { sumValue = math.MaxInt64 } this.bossPond.Store(sceneType, sumValue) } else { this.bossPond.Store(sceneType, score) } } // 获取当前BOSS池 func (this *CoinPoolManager) GetBossPond(sceneType int32) int64 { value, ok := this.bossPond.Load(sceneType) if ok { return value.(int64) } return 0 } // 增加公共奖池 暂时无用 func (this *CoinPoolManager) AddPublicPond(roomId int32, score int64) { value, ok := this.publicPond.Load(roomId) if ok { this.publicPond.Store(roomId, value.(int64)+score) } else { this.publicPond.Store(roomId, score) } } // 获取公共奖池 func (this *CoinPoolManager) GetPublicPond(roomId int32) int64 { value, ok := this.publicPond.Load(roomId) if ok { return value.(int64) } return 0 }