ShopDataManager.cs 12 KB

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