StoreDataManager.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 StoreDataManager : SingletonBase<StoreDataManager>
  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. /// <summary>
  71. /// 根据充值id获取购买次数
  72. /// </summary>
  73. /// <param name="rechargeId"></param>
  74. /// <returns></returns>
  75. public int GetRechargeBuyNumById(int rechargeId)
  76. {
  77. return !_rechargeDic.ContainsKey(rechargeId) ? 0 : _rechargeDic[rechargeId];
  78. }
  79. /// <summary>
  80. /// 根据礼包id获取购买次数
  81. /// </summary>
  82. /// <param name="giftId"></param>
  83. /// <returns></returns>
  84. public int GetGiftBuyNumById(int giftId)
  85. {
  86. return !_giftDic.ContainsKey(giftId) ? 0 : _giftDic[giftId];
  87. }
  88. /// <summary>
  89. /// 根据充值id获取购买次数
  90. /// </summary>
  91. /// <param name="exchangeId"></param>
  92. /// <returns></returns>
  93. public int GetExchangeBuyNumById(int exchangeId)
  94. {
  95. return !_exchangeDic.ContainsKey(exchangeId) ? 0 : _exchangeDic[exchangeId];
  96. }
  97. public List<GiftBagCfg> GetGiftBagCfgs()
  98. {
  99. List<GiftBagCfg> giftBagCfgs = new List<GiftBagCfg>();
  100. List<GiftBagCfg> noneGiftBagCfgs = GetNoneGiftCfg();
  101. giftBagCfgs = giftBagCfgs.Concat(noneGiftBagCfgs).ToList<GiftBagCfg>();
  102. GiftBagCfg StoryLvGiftCfg = GetStoryLvGiftCfg();
  103. if (StoryLvGiftCfg != null) giftBagCfgs.Add(StoryLvGiftCfg);
  104. GiftBagCfg RoleLvGiftCfg = GetRoleLvGiftCfg();
  105. if (RoleLvGiftCfg != null) giftBagCfgs.Add(RoleLvGiftCfg);
  106. giftBagCfgs = RemoveNotOpenCfg(giftBagCfgs);
  107. SortGiftBagCfgs(giftBagCfgs);
  108. return giftBagCfgs;
  109. }
  110. private List<GiftBagCfg> SortGiftBagCfgs(List<GiftBagCfg> giftBagCfgs)
  111. {
  112. giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  113. {
  114. //未售罄的>未解锁>已售罄的
  115. int buyTypeA = (a.maxBuyNum == 0 || a.maxBuyNum - GetGiftBuyNumById(a.id) > 0) ? 1 : -1;
  116. int buyTypeB = (b.maxBuyNum == 0 || b.maxBuyNum - GetGiftBuyNumById(b.id) > 0) ? 1 : -1;
  117. if (buyTypeA > buyTypeB) return -1;
  118. if (buyTypeA < buyTypeB) return 1;
  119. //解锁状态
  120. int lockA = GetGiftStateById(a.id) ? 1 : -1;
  121. int lockB = GetGiftStateById(b.id) ? 1 : -1;
  122. if (lockA > lockB) return -1;
  123. if (lockA < lockB) return 1;
  124. //免费>钻石>现金>道具
  125. if (a.costType < b.costType) return -1;
  126. if (a.costType > b.costType) return 1;
  127. //有下架时间的 > 没有下架时间的
  128. int endTimeA = a.endTime != "" ? 1 : -1;
  129. int endTimeB = b.endTime != "" ? 1 : -1;
  130. if (endTimeA > endTimeB) return -1;
  131. if (endTimeA < endTimeB) return 1;
  132. int descA = a.desc == "" ? 0 : int.Parse(a.desc);
  133. int descB = b.desc == "" ? 0 : int.Parse(b.desc);
  134. if (descA != descB) return descA - descB;
  135. if (a.price != b.price) return a.price - b.price;
  136. return 0;
  137. });
  138. return giftBagCfgs;
  139. }
  140. private List<GiftBagCfg> RemoveNotOpenCfg(List<GiftBagCfg> giftBagCfgs)
  141. {
  142. for (int i = giftBagCfgs.Count - 1; i >= 0; i--)
  143. {
  144. if (giftBagCfgs[i].startTime != "" && !TimeUtil.IsBeforeCurTime(giftBagCfgs[i].startTime) || giftBagCfgs[i].endTime != "" && !TimeUtil.IsLaterCurTime(giftBagCfgs[i].endTime))
  145. {
  146. giftBagCfgs.RemoveAt(i);
  147. }
  148. }
  149. return giftBagCfgs;
  150. }
  151. private List<GiftBagCfg> GetNoneGiftCfg()
  152. {
  153. List<GiftBagCfg> giftBagCfgs = new List<GiftBagCfg>(GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.NONE));
  154. return giftBagCfgs;
  155. }
  156. private GiftBagCfg GetStoryLvGiftCfg()
  157. {
  158. List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.STORY_LV);
  159. if (giftBagCfgs.Count == 0) return null;
  160. giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  161. {
  162. if (a.storyLevelId.CompareTo(b.storyLevelId) != 0)
  163. {
  164. return a.storyLevelId.CompareTo(b.storyLevelId);
  165. }
  166. return -1;
  167. });
  168. for (int i = 0; i < giftBagCfgs.Count; i++)
  169. {
  170. if (GetGiftStateById(giftBagCfgs[i].id) && (GetGiftBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  171. }
  172. return giftBagCfgs[0];
  173. }
  174. private GiftBagCfg GetRoleLvGiftCfg()
  175. {
  176. List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgsBylockType(LockType.ROLE_LV);
  177. if (giftBagCfgs.Count == 0) return null;
  178. giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  179. {
  180. if (a.lv.CompareTo(b.lv) != 0)
  181. {
  182. return a.lv.CompareTo(b.lv);
  183. }
  184. return -1;
  185. });
  186. for (int i = 0; i < giftBagCfgs.Count; i++)
  187. {
  188. if (GetGiftStateById(giftBagCfgs[i].id) && (GetGiftBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  189. }
  190. return giftBagCfgs[0];
  191. }
  192. public List<ShopExchangeCfg> GetExchangeCfgs()
  193. {
  194. List<ShopExchangeCfg> shopExchangeCfgs = new List<ShopExchangeCfg>(ShopExchangeCfgArray.Instance.dataArray);
  195. shopExchangeCfgs.Sort((ShopExchangeCfg a, ShopExchangeCfg b) =>
  196. {
  197. //未售罄的>已售罄的
  198. int buyTypeA = (a.maxLimit == 0 || a.maxLimit - GetExchangeBuyNumById(a.id) > 0) ? 1 : -1;
  199. int buyTypeB = (b.maxLimit == 0 || b.maxLimit - GetExchangeBuyNumById(b.id) > 0) ? 1 : -1;
  200. if (buyTypeA > buyTypeB) return -1;
  201. if (buyTypeA < buyTypeB) return 1;
  202. return 0;
  203. });
  204. return shopExchangeCfgs;
  205. }
  206. /// <summary>
  207. /// 根据礼包Id获取礼包解锁状态
  208. /// /// </summary>
  209. /// <param name="giftId"></param>
  210. /// <returns></returns>
  211. public bool GetGiftStateById(int giftId)
  212. {
  213. GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(giftId);
  214. if (cfg.lockType == LockType.NONE)
  215. {
  216. return true;
  217. }
  218. else if (cfg.lockType == LockType.STORY_LV)
  219. {
  220. return InstanceZonesDataManager.CheckLevelPass(cfg.storyLevelId);
  221. }
  222. else
  223. {
  224. return GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) >= cfg.lv;
  225. }
  226. }
  227. /// <summary>
  228. /// 根据礼包id获取下架时间
  229. /// </summary>
  230. /// <param name="giftId"></param>
  231. /// <returns></returns>
  232. public string GetEndTime(int giftId)
  233. {
  234. long endTime = 0;
  235. GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(giftId);
  236. if (cfg.endTime == "") return "";
  237. endTime = TimeUtil.DateTimeToTimestamp(cfg.endTime);
  238. return TimeUtil.FormattingTime(TimeHelper.ServerNow(), endTime);
  239. }
  240. }
  241. }