using System; using System.Collections.Generic; using System.Linq; using ET; namespace GFGGame { public class ShopDataManager : SingletonBase { public string[] refreshType = { "永久限购", "每日限购", "每周限购", "每月限购" }; // private Dictionary _rechargeDic = new Dictionary(); private Dictionary _goodsDic = new Dictionary(); // private Dictionary _exchangeDic = new Dictionary(); public void Clear() { // _rechargeDic.Clear(); _goodsDic.Clear(); // _exchangeDic.Clear(); } // public void UpdateRechargeData(int rechargeId, int num) // { // if (!_rechargeDic.ContainsKey(rechargeId)) // { // _rechargeDic.Add(rechargeId, num); // } // else // { // _rechargeDic[rechargeId] = num; // } // } public void UpdateGiftData(int giftId, int num) { if (!_goodsDic.ContainsKey(giftId)) { _goodsDic.Add(giftId, num); } else { _goodsDic[giftId] = num; } } // public void UpdateExchangeData(int exchangeId, int num) // { // if (!_exchangeDic.ContainsKey(exchangeId)) // { // _exchangeDic.Add(exchangeId, num); // } // else // { // _exchangeDic[exchangeId] = 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); break; case ConstStoreId.GALLERY_STORE_ID: shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2AndtypeIndex(ConstStoreTabId.STORE_EXCHANGE, ConstStoreSubId.STORE_EXCHANGE_GALLERY, typeIndex); 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 GetRechargeBuyNumById(int rechargeId) // { // return !_rechargeDic.ContainsKey(rechargeId) ? 0 : _rechargeDic[rechargeId]; // } /// /// 根据商品id获取购买次数 /// /// /// public int GetGoodsBuyNumById(int goodsId) { return !_goodsDic.ContainsKey(goodsId) ? 0 : _goodsDic[goodsId]; } // /// // /// 根据充值id获取购买次数 // /// // /// // /// // public int GetExchangeBuyNumById(int exchangeId) // { // return !_exchangeDic.ContainsKey(exchangeId) ? 0 : _exchangeDic[exchangeId]; // } public List GetGiftBagCfgs() { // List giftBagCfgs = new List(); // List noneGiftBagCfgs = GetNoneGiftCfg(); // giftBagCfgs = giftBagCfgs.Concat(noneGiftBagCfgs).ToList(); // GiftBagCfg StoryLvGiftCfg = GetStoryLvGiftCfg(); // if (StoryLvGiftCfg != null) giftBagCfgs.Add(StoryLvGiftCfg); // GiftBagCfg RoleLvGiftCfg = GetRoleLvGiftCfg(); // if (RoleLvGiftCfg != null) giftBagCfgs.Add(RoleLvGiftCfg); // giftBagCfgs = RemoveNotOpenCfg(giftBagCfgs); // SortGiftBagCfgs(giftBagCfgs); // return giftBagCfgs; return null; } 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 disCountA - disCountB; if (a.price != b.price) return a.price - b.price; return 0; }); return shopCfgs; } //获取商品折扣百分比 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); } private List RemoveNotOpenCfg(List giftBagCfgs) { for (int i = giftBagCfgs.Count - 1; i >= 0; i--) { if (giftBagCfgs[i].startTime != "" && !TimeUtil.IsBeforeCurTime(giftBagCfgs[i].startTime) || giftBagCfgs[i].endTime != "" && !TimeUtil.IsLaterCurTime(giftBagCfgs[i].endTime)) { giftBagCfgs.RemoveAt(i); } } return giftBagCfgs; } 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; // } /// /// 根据商品Id获取商品是否解锁解锁 /// /// /// /// public bool GetShopGoodsStateById(int goodsId) { ShopCfg cfg = ShopCfgArray.Instance.GetCfg(goodsId); if (cfg.lockType == LockType.NONE) { return true; } else if (cfg.lockType == LockType.STORY_LV) { return InstanceZonesDataManager.CheckLevelPass(cfg.lockValue); } else if (cfg.lockType == LockType.ROLE_LV) { return GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) >= cfg.lockValue; } else if (cfg.lockType == LockType.MONTH_CARD_TYPE) { return RoleDataManager.CheckIsMonthCardOpenByType(cfg.lockValue); } else if (cfg.lockType == LockType.AREND_GRADE) { return ArenaDataManager.Instance.Grade >= cfg.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) { return string.Format("飞花令达到{0}段位解锁", shopCfg.lockValue); } 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); } } }