| | |
| | | isLogin = false;
|
| | | }
|
| | |
|
| | | #region 解析本地数据
|
| | | public Dictionary<int, List<int>> storeRedRuleDict { get; private set; } //红点类型 1,免费商品 2,必买商品 3,坐骑灵宠 4,可购买物品(积分兑换)
|
| | | public Dictionary<int, List<int>> storePushDict { get; private set; } //1,每日弹1次2,只弹1次
|
| | | private void ParseFuncConfig()
|
| | | {
|
| | | storeRedRuleDict = new Dictionary<int, List<int>>();
|
| | | storePushDict = new Dictionary<int, List<int>>();
|
| | | FuncConfigConfig storeRedRules = Config.Instance.Get<FuncConfigConfig>("StoreRedRules");
|
| | | if(storeRedRules != null)
|
| | | {
|
| | | JsonData redRules = JsonMapper.ToObject(storeRedRules.Numerical1);
|
| | | foreach(var type in redRules.Keys)
|
| | | {
|
| | | int redType = 0;
|
| | | int.TryParse(type,out redType);
|
| | | JsonData shops = redRules[type];
|
| | | if (!storeRedRuleDict.ContainsKey(redType))
|
| | | {
|
| | | List<int> shopIdlist = new List<int>();
|
| | | if(shops.IsArray)
|
| | | {
|
| | | for(int i = 0; i < shops.Count; i++)
|
| | | {
|
| | | int shopId = 0;
|
| | | int.TryParse(shops[i].ToString(),out shopId);
|
| | | shopIdlist.Add(shopId);
|
| | | }
|
| | | }
|
| | | storeRedRuleDict.Add(redType,shopIdlist);
|
| | | }
|
| | | }
|
| | |
|
| | | JsonData pushRules = JsonMapper.ToObject(storeRedRules.Numerical2);
|
| | | foreach(var type in pushRules.Keys)
|
| | | {
|
| | | int pushType = 0;
|
| | | int.TryParse(type,out pushType);
|
| | | JsonData shops = pushRules[type];
|
| | | if (!storePushDict.ContainsKey(pushType))
|
| | | {
|
| | | List<int> shopIdlist = new List<int>();
|
| | | if (shops.IsArray)
|
| | | {
|
| | | for (int i = 0; i < shops.Count; i++)
|
| | | {
|
| | | int shopId = 0;
|
| | | int.TryParse(shops[i].ToString(), out shopId);
|
| | | shopIdlist.Add(shopId);
|
| | | }
|
| | | }
|
| | | storePushDict.Add(pushType, shopIdlist);
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | public Dictionary<int,List<StoreConfig>> storeTypeDict { get; private set; } |
| | | private void ParseStoreConfig()
|
| | | {
|
| | | storeTypeDict = new Dictionary<int, List<StoreConfig>>();
|
| | | List<StoreConfig> storeConfigs = Config.Instance.GetAllValues<StoreConfig>();
|
| | | for(int i = 0; i < storeConfigs.Count; i++)
|
| | | {
|
| | | var config = storeConfigs[i];
|
| | | if(config.ShopType != 0)
|
| | | {
|
| | | if(!storeTypeDict.ContainsKey(config.ShopType))
|
| | | {
|
| | | List<StoreConfig> configs = new List<StoreConfig>();
|
| | | configs.Add(config);
|
| | | storeTypeDict.Add(config.ShopType,configs);
|
| | | }
|
| | | else
|
| | | {
|
| | | storeTypeDict[config.ShopType].Add(config);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | foreach(var type in storeTypeDict.Keys)
|
| | | {
|
| | | var configs = storeTypeDict[type];
|
| | | configs.Sort(CompareByShopSort);
|
| | | }
|
| | | }
|
| | |
|
| | | public int CompareByShopSort(StoreConfig start, StoreConfig end)
|
| | | {
|
| | | int sort1 = start.ShopSort;
|
| | | int sort2 = end.ShopSort;
|
| | | if (sort1.CompareTo(sort2) != 0) return sort1.CompareTo(sort2);
|
| | |
|
| | | return 0;
|
| | | }
|
| | | #endregion
|
| | |
|
| | | #region 获取数据
|
| | | public bool TryGetRedTypeByShopId(int shopId, out int type)
|
| | | {
|
| | | type = 0;
|
| | | foreach (var key in storeRedRuleDict.Keys)
|
| | | {
|
| | | List<int> idlist = storeRedRuleDict[key];
|
| | | if (idlist.Contains(shopId))
|
| | | {
|
| | | type = key;
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | public bool TryGetPushTypeByShopId(int shopId, out int type)
|
| | | {
|
| | | type = 0;
|
| | | foreach (var key in storePushDict.Keys)
|
| | | {
|
| | | List<int> idlist = storePushDict[key];
|
| | | if (idlist.Contains(shopId))
|
| | | {
|
| | | type = key;
|
| | | return true;
|
| | | }
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | private Dictionary<int, List<StoreConfig>> showStoreTypeDict = new Dictionary<int, List<StoreConfig>>();
|
| | | public void UpdateShowStore()
|
| | | {
|
| | | showStoreTypeDict.Clear();
|
| | | foreach(var type in storeTypeDict.Keys)
|
| | | {
|
| | | var configs = storeTypeDict[type];
|
| | | List<StoreConfig> showConfigs = new List<StoreConfig>();
|
| | | if(!showStoreTypeDict.ContainsKey(type))
|
| | | {
|
| | | for (int i = 0; i < configs.Count; i++)
|
| | | {
|
| | | var config = configs[i];
|
| | | int remainNum = 0;
|
| | | bool isSellOut = TryGetIsSellOut(config, out remainNum);
|
| | | if(isSellOut && config.TheOnlyShop == 1)
|
| | | {
|
| | |
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | | |
| | | public bool TryGetIsSellOut(StoreConfig storeConfig, out int remainCnt)
|
| | | {
|
| | | int canBuyCnt = 0;
|
| | | int addBuyCnt = 0;
|
| | | remainCnt = 0;
|
| | | bool isLimitBuy = TryGetLimitBuy(storeConfig, out canBuyCnt, out addBuyCnt);
|
| | | if (!isLimitBuy) return false;
|
| | |
|
| | | int remainNum = canBuyCnt;
|
| | | BuyShopItemLimit shopItemLimit = GetBuyShopLimit((uint)storeConfig.ID);
|
| | | if (shopItemLimit != null)
|
| | | {
|
| | | remainNum -= shopItemLimit.BuyCnt;
|
| | | }
|
| | |
|
| | | if (remainNum <= 0)
|
| | | {
|
| | | return true;
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
|
| | | public bool TryGetLimitBuy(StoreConfig config, out int canBuyCnt, out int addBuyCnt)
|
| | | {
|
| | | canBuyCnt = 0;
|
| | | addBuyCnt = 0;
|
| | | if (config == null) return false;
|
| | |
|
| | | int[] canBuyNums = config.PurchaseNumber;
|
| | | if (canBuyNums == null || canBuyNums.Length < 1) return false;
|
| | |
|
| | | int curVipIndex = -1;
|
| | | int nexVipIndex = -1;
|
| | | bool isVipBuy = TryGetVipBuy(config, out curVipIndex, out nexVipIndex);
|
| | | if (isVipBuy)
|
| | | {
|
| | | if (curVipIndex != -1)
|
| | | {
|
| | | canBuyCnt = canBuyNums[curVipIndex];
|
| | | }
|
| | |
|
| | | if (nexVipIndex != -1)
|
| | | {
|
| | | addBuyCnt = canBuyNums[nexVipIndex] - canBuyCnt;
|
| | | }
|
| | | return true;
|
| | | }
|
| | | else
|
| | | {
|
| | | if (canBuyNums[0] != 0)
|
| | | {
|
| | | canBuyCnt = canBuyNums[0];
|
| | | return true;
|
| | | }
|
| | | else
|
| | | {
|
| | | return false;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | public bool TryGetVipBuy(StoreConfig config, out int curVipIndex, out int nextVipIndex)
|
| | | {
|
| | | curVipIndex = -1;
|
| | | nextVipIndex = -1;
|
| | | bool isVipBuy = false;
|
| | | if (config == null) return false;
|
| | |
|
| | | var vipLvs = config.VIPLV;
|
| | | if (vipLvs == null || vipLvs.Length < 1) return false;
|
| | |
|
| | | for(int i = 0; i < vipLvs.Length; i++)
|
| | | {
|
| | | var vipLv = vipLvs[i];
|
| | | if(vipLv != 0)
|
| | | {
|
| | | isVipBuy = true;
|
| | | }
|
| | | }
|
| | | |
| | | if (isVipBuy)
|
| | | {
|
| | | int playerVip = PlayerDatas.Instance.baseData.VIPLv;
|
| | | for (int i = vipLvs.Length - 1; i > -1; i--)
|
| | | {
|
| | | var vipLv = vipLvs[i];
|
| | | if (vipLv > playerVip)
|
| | | {
|
| | | nextVipIndex = i;
|
| | | }
|
| | | else if (vipLv <= playerVip)
|
| | | {
|
| | | curVipIndex = i;
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | return isVipBuy;
|
| | | }
|
| | | #endregion
|
| | |
|
| | | public string GetStoreRefreshTimeByType(int type)
|
| | | {
|
| | | if (resetTimeDict == null || !resetTimeDict.ContainsKey(type)) return string.Empty;
|