ShopDataManager.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using ET;
  5. namespace GFGGame
  6. {
  7. public class RechargeStoreType
  8. {
  9. public static int RECHARGE = 0;
  10. public static int GIFT = 1;
  11. public static int EXCHANGE = 2;
  12. }
  13. public class LockType
  14. {
  15. public static int NONE = 0;
  16. public static int STORY_LV = 1;
  17. public static int ROLE_LV = 2;
  18. }
  19. public class CostType
  20. {
  21. public static int FREE = 0;
  22. public static int ITEM = 1;
  23. public static int RMB = 2;
  24. }
  25. public class ShopDataManager : SingletonBase<ShopDataManager>
  26. {
  27. public string[] refreshType = { "永久限购", "每日限购", "每周限购", "每月限购" };
  28. private Dictionary<int, int> _rechargeDic = new Dictionary<int, int>();
  29. private Dictionary<int, int> _giftDic = new Dictionary<int, int>();
  30. private Dictionary<int, int> _exchangeDic = new Dictionary<int, int>();
  31. public void Clear()
  32. {
  33. _rechargeDic.Clear();
  34. _giftDic.Clear();
  35. _exchangeDic.Clear();
  36. }
  37. public void UpdateRechargeData(int rechargeId, int num)
  38. {
  39. if (!_rechargeDic.ContainsKey(rechargeId))
  40. {
  41. _rechargeDic.Add(rechargeId, num);
  42. }
  43. else
  44. {
  45. _rechargeDic[rechargeId] = num;
  46. }
  47. }
  48. public void UpdateGiftData(int giftId, int num)
  49. {
  50. if (!_giftDic.ContainsKey(giftId))
  51. {
  52. _giftDic.Add(giftId, num);
  53. }
  54. else
  55. {
  56. _giftDic[giftId] = num;
  57. }
  58. }
  59. public void UpdateExchangeData(int exchangeId, int num)
  60. {
  61. if (!_exchangeDic.ContainsKey(exchangeId))
  62. {
  63. _exchangeDic.Add(exchangeId, num);
  64. }
  65. else
  66. {
  67. _exchangeDic[exchangeId] = num;
  68. }
  69. }
  70. /************************************************************************************************************/
  71. // /// <summary>
  72. // ///
  73. // /// </summary>
  74. // /// <param name="type">StoreTabCfg:index,ShopCfg:menu1</param>
  75. // /// <param name="subType">StoreTabCfg:subTab[1] ,ShopCfg:menu1</param>
  76. // /// <returns></returns>
  77. // public List<ShopCfg> GetShopCfgs(string functonId, int menu2)
  78. // {
  79. // StoreTabCfg tabCfg = StoreTabCfgArray.Instance.GetCfgByfunctionId(functonId);
  80. // List<ShopCfg> clothingShopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2(tabCfg.index, menu2);
  81. // return clothingShopCfgs;
  82. // }
  83. public List<ShopCfg> GetList(int storeId, int typeIndex, int scoreType)
  84. {
  85. List<ShopCfg> shopCfgs = null;
  86. switch (storeId)
  87. {
  88. case ConstStoreId.CLOTHING_STORE_ID:
  89. shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2AndtypeIndex(ConstStoreTabId.FU_ZHUANG_DIAN, ConstStoreSubId.FU_ZHUANG_DIAN, typeIndex);
  90. break;
  91. case ConstStoreId.GALLERY_STORE_ID:
  92. shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2AndtypeIndex(ConstStoreTabId.STORE_EXCHANGE, ConstStoreSubId.STORE_EXCHANGE_GALLERY, typeIndex);
  93. break;
  94. }
  95. SortItemListByScore(shopCfgs, scoreType);
  96. return shopCfgs;
  97. }
  98. public void GetMoneyIdAndNum(int buyId, int count, int shopType, out int costId, out int costNum, out int buyNum)
  99. {
  100. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(buyId);
  101. costId = shopCfg.costId;
  102. costNum = shopCfg.price * count;
  103. buyNum = count;
  104. }
  105. private List<ShopCfg> SortItemListByScore(List<ShopCfg> arrayList, int scoreType)
  106. {
  107. arrayList.Sort((ShopCfg a, ShopCfg b) =>
  108. {
  109. long numA = ItemDataManager.GetItemNum(a.itemId);
  110. long numB = ItemDataManager.GetItemNum(b.itemId);
  111. bool hasA = numA > 0;
  112. bool hasB = numB > 0;
  113. if (hasA && !hasB)
  114. {
  115. return 1;
  116. }
  117. else if (!hasA && hasB)
  118. {
  119. return -1;
  120. }
  121. else if (scoreType > 0 && !hasA && !hasB)
  122. {
  123. int scoreA = ItemDataManager.GetItemAdditionScore(a.itemId, scoreType);
  124. int scoreB = ItemDataManager.GetItemAdditionScore(b.itemId, scoreType);
  125. if (scoreB > scoreA)
  126. {
  127. return 1;
  128. }
  129. else if (scoreB < scoreA)
  130. {
  131. return -1;
  132. }
  133. }
  134. return a.itemId.CompareTo(b.itemId);
  135. });
  136. return arrayList;
  137. }
  138. /**************************************************************************************************************************/
  139. /// <summary>
  140. /// 根据充值id获取购买次数
  141. /// </summary>
  142. /// <param name="rechargeId"></param>
  143. /// <returns></returns>
  144. public int GetRechargeBuyNumById(int rechargeId)
  145. {
  146. return !_rechargeDic.ContainsKey(rechargeId) ? 0 : _rechargeDic[rechargeId];
  147. }
  148. /// <summary>
  149. /// 根据礼包id获取购买次数
  150. /// </summary>
  151. /// <param name="giftId"></param>
  152. /// <returns></returns>
  153. public int GetGiftBuyNumById(int giftId)
  154. {
  155. return !_giftDic.ContainsKey(giftId) ? 0 : _giftDic[giftId];
  156. }
  157. /// <summary>
  158. /// 根据充值id获取购买次数
  159. /// </summary>
  160. /// <param name="exchangeId"></param>
  161. /// <returns></returns>
  162. public int GetExchangeBuyNumById(int exchangeId)
  163. {
  164. return !_exchangeDic.ContainsKey(exchangeId) ? 0 : _exchangeDic[exchangeId];
  165. }
  166. public List<GiftBagCfg> GetGiftBagCfgs()
  167. {
  168. List<GiftBagCfg> giftBagCfgs = new List<GiftBagCfg>();
  169. List<GiftBagCfg> noneGiftBagCfgs = GetNoneGiftCfg();
  170. giftBagCfgs = giftBagCfgs.Concat(noneGiftBagCfgs).ToList<GiftBagCfg>();
  171. GiftBagCfg StoryLvGiftCfg = GetStoryLvGiftCfg();
  172. if (StoryLvGiftCfg != null) giftBagCfgs.Add(StoryLvGiftCfg);
  173. GiftBagCfg RoleLvGiftCfg = GetRoleLvGiftCfg();
  174. if (RoleLvGiftCfg != null) giftBagCfgs.Add(RoleLvGiftCfg);
  175. giftBagCfgs = RemoveNotOpenCfg(giftBagCfgs);
  176. SortGiftBagCfgs(giftBagCfgs);
  177. return giftBagCfgs;
  178. }
  179. private List<GiftBagCfg> SortGiftBagCfgs(List<GiftBagCfg> giftBagCfgs)
  180. {
  181. giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  182. {
  183. //未售罄的>未解锁>已售罄的
  184. int buyTypeA = (a.maxBuyNum == 0 || a.maxBuyNum - GetGiftBuyNumById(a.id) > 0) ? 1 : -1;
  185. int buyTypeB = (b.maxBuyNum == 0 || b.maxBuyNum - GetGiftBuyNumById(b.id) > 0) ? 1 : -1;
  186. if (buyTypeA > buyTypeB) return -1;
  187. if (buyTypeA < buyTypeB) return 1;
  188. //解锁状态
  189. int lockA = GetGiftStateById(a.id) ? 1 : -1;
  190. int lockB = GetGiftStateById(b.id) ? 1 : -1;
  191. if (lockA > lockB) return -1;
  192. if (lockA < lockB) return 1;
  193. //免费>钻石>现金>道具
  194. if (a.costType < b.costType) return -1;
  195. if (a.costType > b.costType) return 1;
  196. //有下架时间的 > 没有下架时间的
  197. int endTimeA = a.endTime != "" ? 1 : -1;
  198. int endTimeB = b.endTime != "" ? 1 : -1;
  199. if (endTimeA > endTimeB) return -1;
  200. if (endTimeA < endTimeB) return 1;
  201. int descA = a.desc == "" ? 0 : int.Parse(a.desc);
  202. int descB = b.desc == "" ? 0 : int.Parse(b.desc);
  203. if (descA != descB) return descA - descB;
  204. if (a.price != b.price) return a.price - b.price;
  205. return 0;
  206. });
  207. return giftBagCfgs;
  208. }
  209. private List<GiftBagCfg> RemoveNotOpenCfg(List<GiftBagCfg> giftBagCfgs)
  210. {
  211. for (int i = giftBagCfgs.Count - 1; i >= 0; i--)
  212. {
  213. if (giftBagCfgs[i].startTime != "" && !TimeUtil.IsBeforeCurTime(giftBagCfgs[i].startTime) || giftBagCfgs[i].endTime != "" && !TimeUtil.IsLaterCurTime(giftBagCfgs[i].endTime))
  214. {
  215. giftBagCfgs.RemoveAt(i);
  216. }
  217. }
  218. return giftBagCfgs;
  219. }
  220. private List<GiftBagCfg> GetNoneGiftCfg()
  221. {
  222. List<GiftBagCfg> giftBagCfgs = new List<GiftBagCfg>(GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.NONE));
  223. return giftBagCfgs;
  224. }
  225. private GiftBagCfg GetStoryLvGiftCfg()
  226. {
  227. List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.STORY_LV);
  228. if (giftBagCfgs.Count == 0) return null;
  229. giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  230. {
  231. if (a.storyLevelId.CompareTo(b.storyLevelId) != 0)
  232. {
  233. return a.storyLevelId.CompareTo(b.storyLevelId);
  234. }
  235. return -1;
  236. });
  237. for (int i = 0; i < giftBagCfgs.Count; i++)
  238. {
  239. if (GetGiftStateById(giftBagCfgs[i].id) && (GetGiftBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  240. }
  241. return giftBagCfgs[0];
  242. }
  243. private GiftBagCfg GetRoleLvGiftCfg()
  244. {
  245. List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.ROLE_LV);
  246. if (giftBagCfgs.Count == 0) return null;
  247. giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  248. {
  249. if (a.lv.CompareTo(b.lv) != 0)
  250. {
  251. return a.lv.CompareTo(b.lv);
  252. }
  253. return -1;
  254. });
  255. for (int i = 0; i < giftBagCfgs.Count; i++)
  256. {
  257. if (GetGiftStateById(giftBagCfgs[i].id) && (GetGiftBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  258. }
  259. return giftBagCfgs[0];
  260. }
  261. public List<ShopExchangeCfg> GetExchangeCfgs()
  262. {
  263. List<ShopExchangeCfg> shopExchangeCfgs = new List<ShopExchangeCfg>(ShopExchangeCfgArray.Instance.dataArray);
  264. shopExchangeCfgs.Sort((ShopExchangeCfg a, ShopExchangeCfg b) =>
  265. {
  266. //未售罄的>已售罄的
  267. int buyTypeA = (a.maxLimit == 0 || a.maxLimit - GetExchangeBuyNumById(a.id) > 0) ? 1 : -1;
  268. int buyTypeB = (b.maxLimit == 0 || b.maxLimit - GetExchangeBuyNumById(b.id) > 0) ? 1 : -1;
  269. if (buyTypeA > buyTypeB) return -1;
  270. if (buyTypeA < buyTypeB) return 1;
  271. return 0;
  272. });
  273. return shopExchangeCfgs;
  274. }
  275. /// <summary>
  276. /// 根据礼包Id获取礼包解锁状态
  277. /// /// </summary>
  278. /// <param name="giftId"></param>
  279. /// <returns></returns>
  280. public bool GetGiftStateById(int giftId)
  281. {
  282. GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(giftId);
  283. if (cfg.lockType == LockType.NONE)
  284. {
  285. return true;
  286. }
  287. else if (cfg.lockType == LockType.STORY_LV)
  288. {
  289. return InstanceZonesDataManager.CheckLevelPass(cfg.storyLevelId);
  290. }
  291. else
  292. {
  293. return GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) >= cfg.lv;
  294. }
  295. }
  296. /// <summary>
  297. /// 根据礼包id获取下架时间
  298. /// </summary>
  299. /// <param name="giftId"></param>
  300. /// <returns></returns>
  301. public string GetEndTime(int giftId)
  302. {
  303. long endTime = 0;
  304. GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(giftId);
  305. if (cfg.endTime == "") return "";
  306. endTime = TimeUtil.DateTimeToTimestamp(cfg.endTime);
  307. return TimeUtil.FormattingTime(TimeHelper.ServerNow(), endTime);
  308. }
  309. }
  310. }