package model import ( "slices" "strconv" "mongo.games.com/goserver/core/logger" "mongo.games.com/game/common" "mongo.games.com/game/protocol/gamehall" "mongo.games.com/game/protocol/shop" "mongo.games.com/game/protocol/webapi" ) /* 通用模型定义在这里,如果需要自定义可以内嵌在新结构体中 */ const ( OpAll = 0 OpTurnplate = 1 OpBlindBox = 2 OpFirstPay = 3 OpContinuousPay = 4 OpPhoneLottery = 5 OpCollect = 6 OpNian = 7 OpConsume = 8 // 累计消耗活动 OpPushCoin = 9 // 推金币活动 ) const ( WelfareNil = 0 // 不处理 WelfareOpen = 1 // 开启 WelfareClose = 2 // 关闭 ) type ShopInfo struct { Id int32 // 商品ID Page int32 // 页面 1,金币页面 2,钻石页面 3,道具页面 4,房卡 Order int32 // 排序 页面内商品的位置排序 Location []int32 // 显示位置 第1位,竖版大厅 第2位,Tienlen1级选场 第3位,捕鱼1级选场 Picture string // 图片id Name string // 名称 Label []int32 // 标签 Ad int32 // 是否观看广告 0不看 AdTime int32 // 观看几次广告 RepeatTimes int32 // 领取次数 CoolingTime []int32 // 观看冷却时间 Type int32 // 获得类型 1,金币 2,钻石 3,道具类型 4,房卡 Amount int64 // 获得数量 AddArea []int32 // 加送百分比(比如加送10%,就配置110) ItemId int32 // 获得道具ID AddItemInfo []*shop.ItemInfo // 获得道具 ConstType int32 // 购买消耗类型 1,金币 2,钻石 3,美金 4,柬埔寨币 CostArea []int32 // 消耗数量区间 VipLevel int32 //Vip等级限制 Ratio int32 //权重 EndTime int32 //新手礼包结束时间间隔 //缓存数据 AdLookedNum int32 //已经观看的次数 AdReceiveNum int32 //已经领取的次数 RemainingTime int32 LastLookTime int32 RoleAdded int32 PetAdded int32 RoleAddedId int32 //加成人物ID PetAddedId int32 //加成宠物ID FirstSwitch bool // 首冲翻倍 FirstGiveSwitch bool // 首冲翻倍时加赠是否翻倍 AmountFinal int64 // 实际获得数量 } func (this *ShopInfo) GetName() string { return this.Name + "|" + strconv.Itoa(int(this.Id)) } func (this *ShopInfo) GetItems() []ItemInfo { var ret []ItemInfo if this.ItemId > 0 { ret = append(ret, ItemInfo{ ItemId: this.ItemId, ItemNum: this.AmountFinal, }) } for _, v := range this.AddItemInfo { ret = append(ret, ItemInfo{ ItemId: v.ItemId, ItemNum: v.ItemNum, }) } return ret } type AllConfig struct { // 平台配置 Platform *webapi.Platform // 客户端游戏入口开关 EntrySwitch map[int32]*webapi.EntrySwitch // 公告 CommonNotices *webapi.CommonNoticeList // 七日签到 *webapi.Welfare7SignDateList // 转盘 *webapi.WelfareTurnplateDateList // 盲盒 *webapi.WelfareBlindBoxDataList BlindBoxCycle int32 // 首充 *webapi.WelfareFirstPayDataList FirstPayCycle int32 // 连续充值 *webapi.WelfareContinuousPayDataList ContinuousPayCycle int32 // 积分换手机 *webapi.WelfarePhoneLotteryStatus // 集卡活动 *webapi.WelfareCollectConfig // 个人水池 *webapi.PlayerPool // 游戏调控全局配置 *webapi.GameConfig // 兑换商品 *webapi.ExchangeShopList // 商店 ShopInfos map[int32]*ShopInfo // 商品id:商品信息 // 渠道开关 ChannelSwitch map[int32]*webapi.ChannelSwitchConfig // 邀请活动 *webapi.ActInviteConfig // 赛季通行证活动 *webapi.ActPermitConfig PermitStartTs int64 // 开始时间戳 PermitEndTs int64 // 结束时间戳 *webapi.DiamondLotteryConfig // 道具配置 *webapi.ItemConfig // 皮肤配置 *webapi.SkinConfig //排行榜配置 *webapi.RankTypeConfig //获奖记录配置 *webapi.AwardLogConfig // 新手引导配置 *webapi.GuideConfig //娃娃机配置 *webapi.MachineConfig MatchAudience map[int32]*webapi.MatchAudience // 比赛观众列表 key: 玩家id // 小精灵配置 *webapi.SpiritConfig // 房卡场房间类型 RoomType map[int32]*webapi.RoomType // key: 房间类型id // 房卡场房间配置 RoomConfig map[int32]*webapi.RoomConfig // key: 房间配置id RoomTypeMap map[int32][]*webapi.RoomConfig // key: 房间类型id:房间配置 // 系统房间配置 RoomConfigSystem map[int32]*webapi.RoomConfigSystem // 客户端升级奖励配置 *webapi.ClientUpgrade //弹窗配置 *webapi.PopUpWindowConfig // 竞技馆抽奖活动 *webapi.LotteryConfig // 竞技馆抽奖展示配置 LotteryShows map[int64]*webapi.ShowLottery // 竞技馆抽奖必中配置 LotteryUser map[int64]*webapi.UserLottery // 存钱罐消耗获得 *webapi.GamePigBankDiamondConfig // 存钱罐属性 *webapi.GamePigBankPropConfig //年兽配置 *webapi.ActivityNianConfig *webapi.NianRankReward // 红包配置 *webapi.RedPacketConfig // 累计消耗活动配置 *webapi.ConsumeConfig // 推金币活动配置 *webapi.PushCoinConfig } type GlobalConfig struct { // 包对应的平台,包标识 PackageList map[string]*webapi.AppInfo // 超管平台游戏开关,游戏id GameStatus map[int32]bool } type ConfigMgr struct { platform map[string]*AllConfig global *GlobalConfig } func NewConfigMgr() *ConfigMgr { return &ConfigMgr{ platform: make(map[string]*AllConfig), } } func (cm *ConfigMgr) GetConfig(platform string) *AllConfig { c, ok := cm.platform[platform] if !ok { c = &AllConfig{ // todo 初始化默认值 EntrySwitch: make(map[int32]*webapi.EntrySwitch), ShopInfos: make(map[int32]*ShopInfo), ChannelSwitch: make(map[int32]*webapi.ChannelSwitchConfig), MatchAudience: make(map[int32]*webapi.MatchAudience), RoomType: make(map[int32]*webapi.RoomType), RoomConfig: make(map[int32]*webapi.RoomConfig), RoomTypeMap: make(map[int32][]*webapi.RoomConfig), RoomConfigSystem: make(map[int32]*webapi.RoomConfigSystem), LotteryUser: make(map[int64]*webapi.UserLottery), LotteryShows: make(map[int64]*webapi.ShowLottery), } cm.platform[platform] = c } return c } func (cm *ConfigMgr) GetGlobalConfig() *GlobalConfig { if cm.global == nil { cm.global = &GlobalConfig{ // todo 初始化默认值 PackageList: make(map[string]*webapi.AppInfo), GameStatus: make(map[int32]bool), } } return cm.global } func (cm *ConfigMgr) GetConfigs() map[string]*AllConfig { return cm.platform } // IsOn 活动开关 // tp 活动类型 // playerLastChannel 玩家当前登录渠道包 func (cm *ConfigMgr) IsOn(plt string, tp int32, playerLastChannel string) bool { cm.GetConfig(plt) conf := cm.GetConfig(plt).ChannelSwitch[tp] if !GameParamData.CloseChannelSwitch && (conf == nil || !common.InSliceString(conf.OnChannelName, playerLastChannel)) { return false } return true } // UpdateItemShop 更新商品信息 func (cm *ConfigMgr) UpdateItemShop(list *webapi.ItemShopList) { if list == nil { return } shopInfos := make(map[int32]*ShopInfo) for _, itemShop := range list.List { var itemInfo []*shop.ItemInfo for key, value := range itemShop.Award { itemInfo = append(itemInfo, &shop.ItemInfo{ ItemId: int32(key), ItemNum: value, }) } shopInfos[itemShop.Id] = &ShopInfo{ Id: itemShop.Id, ItemId: itemShop.ItemId, Page: itemShop.Page, Order: itemShop.Order, Type: itemShop.Type, Location: itemShop.Location, Picture: itemShop.Picture, Name: itemShop.Name, Ad: itemShop.Ad, AdTime: itemShop.AdTime, RepeatTimes: itemShop.RepeatTimes, CoolingTime: itemShop.CoolingTime, Label: itemShop.Label, AddArea: itemShop.AddArea, Amount: int64(itemShop.Amount), ConstType: itemShop.ConstType, CostArea: itemShop.CostArea, AddItemInfo: itemInfo, VipLevel: itemShop.VipLevel, Ratio: itemShop.Ratio, EndTime: itemShop.EndTime, FirstSwitch: itemShop.FirstSwitch, FirstGiveSwitch: itemShop.OnFirstGiveDouble == common.On, } } cm.GetConfig(list.Platform).ShopInfos = shopInfos } // GetShopInfo 获取商品信息 func (cm *ConfigMgr) GetShopInfo(plt string, shopId int32) *ShopInfo { if shops := cm.GetConfig(plt).ShopInfos; shops != nil { if info, ok1 := shops[shopId]; ok1 { return info } } return nil } func (cm *ConfigMgr) GetPermitLevel(plt, channel string, score int64) int64 { cfg := cm.GetConfig(plt).ActPermitConfig if cfg == nil { return 0 } level := 0 for _, v := range cfg.Configs { if v.Channel == channel { for _, vv := range v.LevelConfig { if score >= vv.Score { level = int(vv.Rank) } else { break } } break } } return int64(level) } func (cm *ConfigMgr) GetPermitConfig(plt, channel string) *webapi.PermitChannelConfig { cfg := cm.GetConfig(plt).ActPermitConfig if cfg == nil { return nil } for _, v := range cfg.Configs { if v.Channel == channel { return v } } return nil } func (cm *ConfigMgr) GetSkinInfo(plt string, skinId int32) *webapi.SkinItem { cfg := cm.GetConfig(plt).SkinConfig if cfg == nil { return nil } for _, v := range cfg.GetItems() { if v.GetId() == skinId { return v } } return nil } func (cm *ConfigMgr) GetSkinLevel(plt string, skinId, level int32) *webapi.SkinLevel { cfg := cm.GetConfig(plt).SkinConfig if cfg == nil { return nil } for _, v := range cfg.GetItems() { if v.GetId() == skinId { for _, vv := range v.GetLevels() { if vv.GetLevel() == level { return vv } } break } } return nil } func (cm *ConfigMgr) GetSkinMaxLevel(plt string, skinId int32) int32 { cfg := cm.GetConfig(plt).SkinConfig if cfg == nil { return 0 } var level int32 for _, v := range cfg.GetItems() { if v.GetId() == skinId { for _, vv := range v.GetLevels() { if vv.GetLevel() > level { level = vv.GetLevel() } } break } } return level } func (cm *ConfigMgr) GetSkinSkillMaxLevel(plt string, skinId int32) int32 { cfg := cm.GetConfig(plt).SkinConfig if cfg == nil { return 0 } var level int32 for _, v := range cfg.GetItems() { if v.GetId() == skinId { for _, vv := range v.GetLevels() { if vv.GetSkillLevel() > level { level = vv.GetSkillLevel() } } break } } return level } func (cm *ConfigMgr) AddMatchAudience(d *webapi.MatchAudience) { cfg := cm.GetConfig(d.Platform) cfg.MatchAudience[d.GetSnId()] = d } func (cm *ConfigMgr) DelMatchAudience(plt string, snid int32) { logger.Logger.Tracef("del match audience plt:%s, snid:%d", plt, snid) delete(cm.GetConfig(plt).MatchAudience, snid) } // IsMatchAudience 是不是比赛场观众 func (cm *ConfigMgr) IsMatchAudience(plt string, snId int32) bool { _, ok := cm.GetConfig(plt).MatchAudience[snId] return ok } func (cm *ConfigMgr) UpdateRoomType(data *webapi.RoomType) { cm.GetConfig(data.GetPlatform()).RoomType[data.GetId()] = data } func (cm *ConfigMgr) DelRoomType(plt string, id int32) { delete(cm.GetConfig(plt).RoomType, id) } func (cm *ConfigMgr) UpdateRoomConfig(data *webapi.RoomConfig) { cm.GetConfig(data.GetPlatform()).RoomConfig[data.GetId()] = data d := cm.GetConfig(data.GetPlatform()).RoomTypeMap[data.GetRoomType()] if d == nil { d = make([]*webapi.RoomConfig, 0) } has := false for k, v := range d { if v.GetId() == data.GetId() { d[k] = data has = true break } } if !has { d = append(d, data) } cm.GetConfig(data.GetPlatform()).RoomTypeMap[data.GetRoomType()] = d } func (cm *ConfigMgr) DelRoomConfig(plt string, id int32) { d := cm.GetConfig(plt).RoomConfig[id] if d != nil { b := cm.GetConfig(plt).RoomTypeMap[d.GetRoomType()] for i, v := range b { if v.GetId() == id { b = append(b[:i], b[i+1:]...) cm.GetConfig(plt).RoomTypeMap[d.GetRoomType()] = b break } } } delete(cm.GetConfig(plt).RoomConfig, id) } func (cm *ConfigMgr) GetRoomConfig(plt string, lastChannel string) *gamehall.SCRoomConfig { pack := &gamehall.SCRoomConfig{} for _, v := range cm.GetConfig(plt).RoomType { if v.GetOn() != common.On { continue } var list []*gamehall.RoomConfigInfo for _, vv := range cm.GetConfig(plt).RoomTypeMap[v.GetId()] { if vv.GetOn() != common.On { continue } if lastChannel != "" && !slices.Contains(vv.GetOnChannelName(), lastChannel) { continue } var cost, reward []*gamehall.ItemInfo for _, item := range vv.GetCost() { cost = append(cost, &gamehall.ItemInfo{ Id: item.GetItemId(), Num: int32(item.GetItemNum()), }) } for _, item := range vv.GetReward() { reward = append(reward, &gamehall.ItemInfo{ Id: item.GetItemId(), Num: int32(item.GetItemNum()), }) } list = append(list, &gamehall.RoomConfigInfo{ Id: vv.GetId(), Name: vv.GetName(), RoomType: vv.GetRoomType(), On: vv.GetOn(), SortId: vv.GetSortId(), Cost: cost, Reward: reward, OnChannelName: vv.GetOnChannelName(), GameFreeId: vv.GetGameFreeId(), Round: vv.GetRound(), PlayerNum: vv.GetPlayerNum(), NeedPassword: vv.GetNeedPassword(), CostType: vv.GetCostType(), Voice: vv.GetVoice(), ImageURI: vv.GetImageURI(), }) } pack.List = append(pack.List, &gamehall.RoomTypeInfo{ Id: v.GetId(), Name: v.GetName(), On: v.GetOn(), SortId: v.GetSortId(), List: list, }) } return pack } func (cm *ConfigMgr) GetLotteryConfig(plt string, id int64) *webapi.LotteryInfo { d := cm.GetConfig(plt) if d != nil && d.LotteryConfig != nil { for _, v := range d.LotteryConfig.GetList() { if v.GetId() == id { return v } } } return nil } func (cm *ConfigMgr) CustomIsOn(plt string, configId int32) bool { cfg := cm.GetConfig(plt).RoomConfig[configId] if cfg == nil || cfg.GetOn() != common.On { return false } cfgT := cm.GetConfig(plt).RoomType[cfg.GetRoomType()] if cfgT == nil || cfgT.GetOn() != common.On { return false } return true } func (cm *ConfigMgr) GetPigBankDiamondArr(plt string) []*webapi.PigBankDiamondInfo { cfg := cm.GetConfig(plt).GamePigBankDiamondConfig if cfg == nil { return nil } return cfg.DiamondInfo } func (cm *ConfigMgr) GetPigBankPropArr(plt string) []*webapi.PigBankPropInfo { cfg := cm.GetConfig(plt).GamePigBankPropConfig if cfg == nil { return nil } return cfg.PropInfo }