using System; using System.Collections.Generic; using System.Linq; using ET; namespace GFGGame { public class ShopDataManager : SingletonBase { public string[] refreshType = { "永久限购", "每日限购", "每周限购", "每月限购" }; private Dictionary _goodsDic = new Dictionary(); public void Clear() { _goodsDic.Clear(); } public void UpdateGoodsData(int giftId, int num) { if (!_goodsDic.ContainsKey(giftId)) { _goodsDic.Add(giftId, num); } else { _goodsDic[giftId] = num; } } /************************************************************************************************************/ public List GetList(int storeId, int typeIndex, int scoreType) { List shopCfgs = null; switch (storeId) { case ConstStoreId.CLOTHING_STORE_ID: shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2AndtypeIndex(ConstStoreTabId.FU_ZHUANG_DIAN, ConstStoreSubId.FU_ZHUANG_DIAN, typeIndex.ToString()); break; case ConstStoreId.GALLERY_STORE_ID: shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2AndtypeIndex(ConstStoreTabId.STORE_EXCHANGE, ConstStoreSubId.STORE_EXCHANGE_GALLERY, typeIndex.ToString()); break; } SortItemListByScore(shopCfgs, scoreType); return shopCfgs; } public void GetMoneyIdAndNum(int buyId, int count, int shopType, out int costId, out int costNum, out int buyNum) { ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(buyId); costId = shopCfg.costId; costNum = shopCfg.price * count; buyNum = count; } private List SortItemListByScore(List arrayList, int scoreType) { arrayList.Sort((ShopCfg a, ShopCfg b) => { long numA = ItemDataManager.GetItemNum(a.itemId); long numB = ItemDataManager.GetItemNum(b.itemId); bool hasA = numA > 0; bool hasB = numB > 0; if (hasA && !hasB) { return 1; } else if (!hasA && hasB) { return -1; } else if (scoreType > 0 && !hasA && !hasB) { int scoreA = ItemDataManager.GetItemAdditionScore(a.itemId, scoreType); int scoreB = ItemDataManager.GetItemAdditionScore(b.itemId, scoreType); if (scoreB > scoreA) { return 1; } else if (scoreB < scoreA) { return -1; } } return a.itemId.CompareTo(b.itemId); }); return arrayList; } /**************************************************************************************************************************/ /// /// 根据商品id获取购买次数 /// /// /// public int GetGoodsBuyNumById(int goodsId) { return !_goodsDic.ContainsKey(goodsId) ? 0 : _goodsDic[goodsId]; } //移除未上架商品 public List RemoveNotOpenCfg(List shop) { List shopCfgs = new List(); for (int i = shop.Count - 1; i >= 0; i--) { if (!string.IsNullOrEmpty(shop[i].startTime) && !TimeUtil.IsBeforeCurTime(shop[i].startTime) || !string.IsNullOrEmpty(shop[i].endTime) && !TimeUtil.IsLaterCurTime(shop[i].endTime)) { continue; } shopCfgs.Add(shop[i]); } return shopCfgs; } //商品排序 public List SortShopGoodsCfgs(List shopCfgs) { shopCfgs.Sort((ShopCfg a, ShopCfg b) => { //未售罄的>已售罄的 int buyTypeA = (a.maxBuyNum == 0 || a.maxBuyNum - GetGoodsBuyNumById(a.id) > 0) ? 1 : -1; int buyTypeB = (b.maxBuyNum == 0 || b.maxBuyNum - GetGoodsBuyNumById(b.id) > 0) ? 1 : -1; if (buyTypeA > buyTypeB) return -1; if (buyTypeA < buyTypeB) return 1; return a.id - b.id; }); return shopCfgs; } //获取商店所有消耗品id列表 public List GetShopCostIds(List shopCfgs) { List costIds = new List(); for (int i = 0; i < shopCfgs.Count; i++) { if (shopCfgs[i].costId == 0) continue; if (costIds.IndexOf(shopCfgs[i].costId) < 0) { costIds.Add(shopCfgs[i].costId); } } return costIds; } /// /// 根据商品Id获取商品是否已解锁 /// /// /// /// public bool GetShopGoodsStateById(int goodsId) { ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(goodsId); if (shopCfg.lockType == LockType.NONE) { return true; } else if (shopCfg.lockType == LockType.STORY_LV) { return InstanceZonesDataManager.CheckLevelPass(shopCfg.lockValue); } else if (shopCfg.lockType == LockType.ROLE_LV) { return GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) >= shopCfg.lockValue; } else if (shopCfg.lockType == LockType.MONTH_CARD_TYPE) { return RoleDataManager.CheckIsMonthCardOpenByType(shopCfg.lockValue); } else if (shopCfg.lockType == LockType.AREND_GRADE) { int lockValue = shopCfg.lockValue; if (shopCfg.menu1 == ConstStoreTabId.STORE_ARENA && shopCfg.menu2 != ConstStoreSubId.STORE_ARENA_ITEM) { bool isDown = ArenaDataManager.Instance.SeasonId - GlobalCfgArray.globalCfg.seasonReduce > 0; lockValue = isDown ? Math.Max(1, shopCfg.lockValue - GlobalCfgArray.globalCfg.rankReduce) : shopCfg.lockValue; } return ArenaDataManager.Instance.Grade >= lockValue; } return true; } /// /// 根据商品Id获取商品解锁提示 /// /// /// /// public string GetShopGoodsStateTips(int goodsId) { ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(goodsId); if (shopCfg.lockType == LockType.STORY_LV) { StoryLevelCfg storyLevelCfg = StoryLevelCfgArray.Instance.GetCfg(shopCfg.lockValue); return string.Format("通关{0}-{1}解锁", StoryUtil.GetChapterOrder(storyLevelCfg.chapterId), storyLevelCfg.order); } else if (shopCfg.lockType == LockType.ROLE_LV) { return string.Format("角色达到{0}级解锁", shopCfg.lockValue); } else if (shopCfg.lockType == LockType.MONTH_CARD_TYPE) { return string.Format("开通{0}解锁", shopCfg.lockValue == MonthCardType.Gold ? "红包卡" : "福气卡"); } else if (shopCfg.lockType == LockType.AREND_GRADE) { int lockValue = shopCfg.lockValue; if (shopCfg.menu1 == ConstStoreTabId.STORE_ARENA && shopCfg.menu2 != ConstStoreSubId.STORE_ARENA_ITEM) { bool isDown = ArenaDataManager.Instance.SeasonId - GlobalCfgArray.globalCfg.seasonReduce > 0; lockValue = isDown ? Math.Max(1, shopCfg.lockValue - GlobalCfgArray.globalCfg.rankReduce) : shopCfg.lockValue; } ArenaRankCfg arenaRankCfg = ArenaRankCfgArray.Instance.GetCfg(lockValue); return string.Format("飞花令段位达到{0}解锁", arenaRankCfg.gradeName); } return ""; } /// /// 根据商品id获取下架时间 /// /// /// public string GetEndTime(int goodsId) { long endTime = 0; ShopCfg cfg = ShopCfgArray.Instance.GetCfg(goodsId); if (cfg.endTime == "") return ""; endTime = TimeUtil.DateTimeToTimestamp(cfg.endTime); return TimeUtil.FormattingTime(TimeHelper.ServerNow(), endTime); } //获取商品折扣百分比 public int GetShopGoodsDiscount(int goodsId) { ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(goodsId); if (shopCfg.price == 0) return 0; return (int)(((double)shopCfg.originalPrice / (double)shopCfg.price) * 100); } // public List SortGiftBagCfgs(List shopCfgs) // { // shopCfgs.Sort((ShopCfg a, ShopCfg b) => // { // //未售罄的>未解锁>已售罄的 // int buyTypeA = (a.maxBuyNum == 0 || a.maxBuyNum - GetGoodsBuyNumById(a.id) > 0) ? 1 : -1; // int buyTypeB = (b.maxBuyNum == 0 || b.maxBuyNum - GetGoodsBuyNumById(b.id) > 0) ? 1 : -1; // if (buyTypeA > buyTypeB) return -1; // if (buyTypeA < buyTypeB) return 1; // //解锁状态 // int lockA = GetShopGoodsStateById(a.id) ? 1 : -1; // int lockB = GetShopGoodsStateById(b.id) ? 1 : -1; // if (lockA > lockB) return -1; // if (lockA < lockB) return 1; // //免费>钻石>现金>道具 // if (a.costType < b.costType) return -1; // if (a.costType > b.costType) return 1; // //有下架时间的 > 没有下架时间的 // int endTimeA = a.endTime != "" ? 1 : -1; // int endTimeB = b.endTime != "" ? 1 : -1; // if (endTimeA > endTimeB) return -1; // if (endTimeA < endTimeB) return 1; // //折扣打的>折扣小的 // int disCountA = GetShopGoodsDiscount(a.id); // int disCountB = GetShopGoodsDiscount(b.id); // if (disCountA > disCountB) return -1; // if (disCountA < disCountB) return 1; // //价格低的>价格高的 // if (a.price != b.price) return a.price - b.price; // return 0; // }); // return shopCfgs; // } // private List GetNoneGiftCfg() // { // List giftBagCfgs = new List(GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.NONE)); // return giftBagCfgs; // } // private GiftBagCfg GetStoryLvGiftCfg() // { // List giftBagCfgs = GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.STORY_LV); // if (giftBagCfgs.Count == 0) return null; // giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) => // { // if (a.storyLevelId.CompareTo(b.storyLevelId) != 0) // { // return a.storyLevelId.CompareTo(b.storyLevelId); // } // return -1; // }); // for (int i = 0; i < giftBagCfgs.Count; i++) // { // if (GetShopGoodsStateById(giftBagCfgs[i].id) && (GetGoodsBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i]; // } // return giftBagCfgs[0]; // } // private GiftBagCfg GetRoleLvGiftCfg() // { // List giftBagCfgs = GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.ROLE_LV); // if (giftBagCfgs.Count == 0) return null; // giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) => // { // if (a.lv.CompareTo(b.lv) != 0) // { // return a.lv.CompareTo(b.lv); // } // return -1; // }); // for (int i = 0; i < giftBagCfgs.Count; i++) // { // if (GetShopGoodsStateById(giftBagCfgs[i].id) && (GetGoodsBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i]; // } // return giftBagCfgs[0]; // } // public List GetExchangeCfgs() // { // List shopExchangeCfgs = new List(ShopExchangeCfgArray.Instance.dataArray); // shopExchangeCfgs.Sort((ShopExchangeCfg a, ShopExchangeCfg b) => // { // //未售罄的>已售罄的 // int buyTypeA = (a.maxLimit == 0 || a.maxLimit - GetExchangeBuyNumById(a.id) > 0) ? 1 : -1; // int buyTypeB = (b.maxLimit == 0 || b.maxLimit - GetExchangeBuyNumById(b.id) > 0) ? 1 : -1; // if (buyTypeA > buyTypeB) return -1; // if (buyTypeA < buyTypeB) return 1; // return 0; // }); // return shopExchangeCfgs; // } /// /// 返回活动商城是否显示 /// /// public bool GetShopActivityIsShow(int menuType) { List shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2(ConstStoreTabId.STORE_GIFT_BAG, menuType); if (ShopDataManager.Instance.RemoveNotOpenCfg(shopCfgs).Count == 0) return false; else return true; } public bool GetShopIdCanBuyInShop(int menuType,List shopListId) { List shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2(ConstStoreTabId.STORE_GIFT_BAG, menuType); if (ShopDataManager.Instance.RemoveNotOpenCfg(shopCfgs).Count == 0) return false; foreach (var shopId in shopListId) { int buyNum = ShopDataManager.Instance.GetGoodsBuyNumById(shopId); foreach (var cfg in shopCfgs) { if (cfg.id == shopId && buyNum < cfg.maxBuyNum) return true; } } return false; } } }