package model import ( "mongo.games.com/game/common" "mongo.games.com/game/protocol/shop" "mongo.games.com/game/protocol/webapi" "strconv" ) /* 通用模型定义在这里,如果需要自定义可以内嵌在新结构体中 */ const ( OpAll = 0 OpTurnplate = 1 OpBlindBox = 2 OpFirstPay = 3 OpContinuousPay = 4 OpPhoneLottery = 5 OpCollect = 6 OpDiamondLottery = 7 ) const ( WelfareNil = 0 // 不处理 WelfareOpen = 1 // 开启 WelfareClose = 2 // 关闭 ) type ShopInfo struct { Id int32 // 商品ID Page int32 // 页面 1,金币页面 2,钻石页面 3,道具页面 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,道具类型 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 // 首冲翻倍 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.Amount, }) } 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 } 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), } 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, } } 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 }