RechargeDataManager.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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 RefreshType
  20. {
  21. public static int NONE = 0;
  22. public static int DAY = 1;
  23. public static int WEEK = 2;
  24. public static int MONTH = 3;
  25. }
  26. public class CostType
  27. {
  28. public static int FREE = 0;
  29. public static int MONEY = 1;
  30. public static int RMB = 2;
  31. public static int ITEM = 3;
  32. }
  33. public class RechargeDataManager : SingletonBase<RechargeDataManager>
  34. {
  35. public string[] refreshType = { "", "日", "周", "月" };
  36. private Dictionary<int, int> _rechargeDic = new Dictionary<int, int>();
  37. private Dictionary<int, int> _giftDic = new Dictionary<int, int>();
  38. private Dictionary<int, int> _exchangeDic = new Dictionary<int, int>();
  39. public void Clear()
  40. {
  41. _rechargeDic.Clear();
  42. _giftDic.Clear();
  43. _exchangeDic.Clear();
  44. }
  45. public void UpdateRechargeData(int rechargeId, int num)
  46. {
  47. if (!_rechargeDic.ContainsKey(rechargeId))
  48. {
  49. _rechargeDic.Add(rechargeId, num);
  50. }
  51. else
  52. {
  53. _rechargeDic[rechargeId] = num;
  54. }
  55. }
  56. public void UpdateGiftData(int giftId, int num)
  57. {
  58. if (!_giftDic.ContainsKey(giftId))
  59. {
  60. _giftDic.Add(giftId, num);
  61. }
  62. else
  63. {
  64. _giftDic[giftId] = num;
  65. }
  66. }
  67. public void UpdateExchangeData(int exchangeId, int num)
  68. {
  69. if (!_exchangeDic.ContainsKey(exchangeId))
  70. {
  71. _exchangeDic.Add(exchangeId, num);
  72. }
  73. else
  74. {
  75. _exchangeDic[exchangeId] = num;
  76. }
  77. }
  78. /// <summary>
  79. /// 根据充值id获取购买次数
  80. /// </summary>
  81. /// <param name="rechargeId"></param>
  82. /// <returns></returns>
  83. public int GetRechargeBuyNumById(int rechargeId)
  84. {
  85. return !_rechargeDic.ContainsKey(rechargeId) ? 0 : _giftDic[rechargeId];
  86. }
  87. /// <summary>
  88. /// 根据礼包id获取购买次数
  89. /// </summary>
  90. /// <param name="giftId"></param>
  91. /// <returns></returns>
  92. public int GetGiftBuyNumById(int giftId)
  93. {
  94. return !_giftDic.ContainsKey(giftId) ? 0 : _giftDic[giftId];
  95. }
  96. /// <summary>
  97. /// 根据充值id获取购买次数
  98. /// </summary>
  99. /// <param name="exchangeId"></param>
  100. /// <returns></returns>
  101. public int GetExchangeBuyNumById(int exchangeId)
  102. {
  103. return !_exchangeDic.ContainsKey(exchangeId) ? 0 : _giftDic[exchangeId];
  104. }
  105. public List<GiftBagCfg> GetGiftBagCfgs()
  106. {
  107. List<GiftBagCfg> giftBagCfgs = new List<GiftBagCfg>();
  108. List<GiftBagCfg> noneGiftBagCfgs = GetNoneGiftCfg();
  109. giftBagCfgs = giftBagCfgs.Concat(noneGiftBagCfgs).ToList<GiftBagCfg>();
  110. GiftBagCfg StoryLvGiftCfg = GetStoryLvGiftCfg();
  111. if (StoryLvGiftCfg != null) giftBagCfgs.Add(StoryLvGiftCfg);
  112. GiftBagCfg RoleLvGiftCfg = GetRoleLvGiftCfg();
  113. if (RoleLvGiftCfg != null) giftBagCfgs.Add(RoleLvGiftCfg);
  114. SortGiftBagCfgs(giftBagCfgs);
  115. return giftBagCfgs;
  116. }
  117. private List<GiftBagCfg> SortGiftBagCfgs(List<GiftBagCfg> giftBagCfgs)
  118. {
  119. giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  120. {
  121. // if (GetGiftBuyNumById(a.id) < a.maxBuyNum && GetGiftBuyNumById(b.id) < b.maxBuyNum)
  122. // {
  123. // return -1;
  124. // }
  125. // else if (GetGiftBuyNumById(a.id) < a.maxBuyNum && GetGiftBuyNumById(b.id) < b.maxBuyNum)
  126. int buyTypeA = a.maxBuyNum - GetGiftBuyNumById(a.id) > 0 ? 1 : a.maxBuyNum - GetGiftBuyNumById(a.id) == 0 ? 0 : -1;
  127. int buyTypeB = b.maxBuyNum - GetGiftBuyNumById(b.id) > 0 ? 1 : b.maxBuyNum - GetGiftBuyNumById(b.id) == 0 ? 0 : -1;
  128. return buyTypeA.CompareTo(buyTypeB);
  129. });
  130. return giftBagCfgs;
  131. }
  132. private List<GiftBagCfg> GetNoneGiftCfg()
  133. {
  134. List<GiftBagCfg> giftBagCfgs = new List<GiftBagCfg>(GiftBagCfgArray.Instance.GetCfgs(LockType.NONE));
  135. for (int i = giftBagCfgs.Count - 1; i >= 0; i--)
  136. {
  137. if (giftBagCfgs[i].startTime != "" && !TimeUtil.IsBeforeCurTime(giftBagCfgs[i].startTime) || giftBagCfgs[i].endTime != "" && !TimeUtil.IsLaterCurTime(giftBagCfgs[i].endTime))
  138. {
  139. giftBagCfgs.RemoveAt(i);
  140. }
  141. }
  142. return giftBagCfgs;
  143. }
  144. private GiftBagCfg GetStoryLvGiftCfg()
  145. {
  146. List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgs(LockType.STORY_LV);
  147. if (giftBagCfgs.Count == 0) return null;
  148. giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  149. {
  150. if (a.storyLevelId.CompareTo(b.storyLevelId) != 0)
  151. {
  152. return a.storyLevelId.CompareTo(b.storyLevelId);
  153. }
  154. return -1;
  155. });
  156. for (int i = 0; i < giftBagCfgs.Count; i++)
  157. {
  158. if (GetGiftStateById(giftBagCfgs[i].id) && (GetGiftBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  159. }
  160. return giftBagCfgs[0];
  161. }
  162. private GiftBagCfg GetRoleLvGiftCfg()
  163. {
  164. List<GiftBagCfg> giftBagCfgs = GiftBagCfgArray.Instance.GetCfgs(LockType.ROLE_LV);
  165. if (giftBagCfgs.Count == 0) return null;
  166. giftBagCfgs.Sort((GiftBagCfg a, GiftBagCfg b) =>
  167. {
  168. if (a.lv.CompareTo(b.lv) != 0)
  169. {
  170. return a.lv.CompareTo(b.lv);
  171. }
  172. return -1;
  173. });
  174. for (int i = 0; i < giftBagCfgs.Count; i++)
  175. {
  176. if (GetGiftStateById(giftBagCfgs[i].id) && (GetGiftBuyNumById(giftBagCfgs[i].id) < giftBagCfgs[i].maxBuyNum)) return giftBagCfgs[i];
  177. }
  178. return giftBagCfgs[0];
  179. }
  180. /// <summary>
  181. /// 根据礼包Id获取礼包解锁状态
  182. /// /// </summary>
  183. /// <param name="giftId"></param>
  184. /// <returns></returns>
  185. public bool GetGiftStateById(int giftId)
  186. {
  187. GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(giftId);
  188. if (cfg.lockType == LockType.NONE)
  189. {
  190. return true;
  191. }
  192. else if (cfg.lockType == LockType.STORY_LV)
  193. {
  194. return InstanceZonesDataManager.CheckLevelPass(cfg.storyLevelId);
  195. }
  196. else
  197. {
  198. return GameGlobal.myNumericComponent.GetAsInt(NumericType.Lvl) >= cfg.lv;
  199. }
  200. }
  201. /// <summary>
  202. /// 根据礼包id获取剩余刷新时间
  203. /// </summary>
  204. /// <param name="giftId"></param>
  205. /// <returns></returns>
  206. public string GetRefreshTime(int giftId)
  207. {
  208. int endTime = 0;
  209. GiftBagCfg cfg = GiftBagCfgArray.Instance.GetCfg(giftId);
  210. if (cfg.refreshType == RefreshType.NONE)
  211. {
  212. return "";
  213. }
  214. else if (cfg.refreshType == RefreshType.DAY)
  215. {
  216. endTime = TimeUtil.GetTomorrowTime(GlobalCfgArray.globalCfg.refreshTime);
  217. }
  218. else if (cfg.refreshType == RefreshType.WEEK)
  219. {
  220. endTime = TimeUtil.GetNextWeekTime(GlobalCfgArray.globalCfg.refreshTime);
  221. }
  222. if (cfg.refreshType == RefreshType.MONTH)
  223. {
  224. endTime = TimeUtil.GetNextMonthTime(GlobalCfgArray.globalCfg.refreshTime);
  225. }
  226. return TimeUtil.FormattingTime(TimeHelper.ServerNowSecs, endTime);
  227. }
  228. }
  229. }