123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using ET;
- namespace GFGGame
- {
- public class ShopDataManager : SingletonBase<ShopDataManager>
- {
- public string[] refreshType = { "永久限购", "每日限购", "每周限购", "每月限购" };
- private Dictionary<int, int> _goodsDic = new Dictionary<int, int>();
- 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<ShopCfg> GetList(int storeId, int typeIndex, int scoreType)
- {
- List<ShopCfg> 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.CostIdReal;
- costNum = shopCfg.Price * count;
- buyNum = count;
- }
- private List<ShopCfg> SortItemListByScore(List<ShopCfg> 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;
- }
- /**************************************************************************************************************************/
- /// <summary>
- /// 根据商品id获取购买次数
- /// </summary>
- /// <param name="goodsId"></param>
- /// <returns></returns>
- public int GetGoodsBuyNumById(int goodsId)
- {
- return !_goodsDic.ContainsKey(goodsId) ? 0 : _goodsDic[goodsId];
- }
- //移除未上架商品
- public List<ShopCfg> RemoveNotOpenCfg(List<ShopCfg> shop)
- {
- List<ShopCfg> shopCfgs = new List<ShopCfg>();
- 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<ShopCfg> SortShopGoodsCfgs(List<ShopCfg> 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<int> GetShopCostIds(List<ShopCfg> shopCfgs)
- {
- List<int> costIds = new List<int>();
- for (int i = 0; i < shopCfgs.Count; i++)
- {
- if (shopCfgs[i].CostIdReal == 0) continue;
- if (costIds.IndexOf(shopCfgs[i].CostIdReal) < 0)
- {
- costIds.Add(shopCfgs[i].CostIdReal);
- }
- }
- return costIds;
- }
- /// <summary>
- /// 根据商品Id获取商品是否已解锁
- /// /// </summary>
- /// <param name="goodsId"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 根据商品Id获取商品解锁提示
- /// /// </summary>
- /// <param name="goodsId"></param>
- /// <returns></returns>
- 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 "";
- }
- /// <summary>
- /// 根据商品id获取下架时间
- /// </summary>
- /// <param name="goodsId"></param>
- /// <returns></returns>
- 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<ShopCfg> SortGiftBagCfgs(List<ShopCfg> 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<GiftBagCfg> GetNoneGiftCfg()
- // {
- // List<GiftBagCfg> giftBagCfgs = new List<GiftBagCfg>(GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.NONE));
- // return giftBagCfgs;
- // }
- // private GiftBagCfg GetStoryLvGiftCfg()
- // {
- // List<GiftBagCfg> 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<GiftBagCfg> 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<ShopExchangeCfg> GetExchangeCfgs()
- // {
- // List<ShopExchangeCfg> shopExchangeCfgs = new List<ShopExchangeCfg>(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;
- // }
- /// <summary>
- /// 返回活动商城是否显示
- /// /// </summary>
- public bool GetShopActivityIsShow(int shopType,int menuType)
- {
- List<ShopCfg> shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2(shopType, menuType);
- if (ShopDataManager.Instance.RemoveNotOpenCfg(shopCfgs).Count == 0)
- return false;
- else
- return true;
- }
- public bool GetShopIdCanBuyInShop(int menuType,List<int> shopListId)
- {
- List<ShopCfg> 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;
- }
- }
- }
|