CollectPartDataManager.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. using ET;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using System.Text.RegularExpressions;
  7. using cfg.GfgCfg;
  8. namespace GFGGame
  9. {
  10. public class CollectPartDataManager : SingletonBase<CollectPartDataManager>
  11. {
  12. //部位数量
  13. public const int Count = 8;
  14. //普通最高段位
  15. public int MaxNormalRank = 5;
  16. //特殊最高段位
  17. public int MaxSpecialRank = 3;
  18. //最高等级
  19. public int MaxLevel = 9;
  20. //加成比值
  21. public int AddtitionRatio = 100;
  22. //搭配部位分类
  23. public Dictionary<int, List<float>> partScoreListDic = new Dictionary<int, List<float>>();
  24. //部位名
  25. public Dictionary<int, string> partNameDic = new Dictionary<int, string>()
  26. { [1] = "连衣裙或上下装及内搭",
  27. [2] = "发型",
  28. [3] = "外套",
  29. [4] = "袜子",
  30. [5] = "鞋子",
  31. [6] = "饰品",
  32. [7] = "手持物",
  33. [99] = "所有",
  34. };
  35. //部位图片
  36. public Dictionary<int, string> partImage = new Dictionary<int, string>
  37. {
  38. [1] = "part1",
  39. [2] = "hz_fenleitu_1",
  40. [3] = "hz_fenleitu_12",
  41. [4] = "hz_fenleitu_7",
  42. [5] = "hz_fenleitu_8",
  43. [6] = "hz_fenleitu_9",
  44. [7] = "hz_fenleitu_10",
  45. [99] = "part99",
  46. };
  47. //数据
  48. public Dictionary<int, List<int>> CollectPartDataDic = new Dictionary<int, List<int>>();
  49. //临时数据,后续通过服务器获取
  50. public void UpdateDic()
  51. {
  52. CollectPartDataDic.Clear();
  53. CollegeBoostCfg collectcfg;
  54. for (int i = 1; i <= Count; i++)
  55. {
  56. List<int> item = new List<int>() { 3, 9 };
  57. if (i == Count)
  58. {
  59. collectcfg = CommonDataManager.Tables.TblCollegeBoostCfg.Get(99, item[0], item[1]);
  60. if (collectcfg == null)
  61. {
  62. item.Add(0);
  63. }
  64. else
  65. {
  66. item.Add(collectcfg.Value);
  67. }
  68. if (CollectPartDataDic.ContainsKey(99))
  69. {
  70. CollectPartDataDic[99] = item;
  71. }
  72. else
  73. {
  74. CollectPartDataDic.Add(99, item);
  75. }
  76. }
  77. else
  78. {
  79. collectcfg = CommonDataManager.Tables.TblCollegeBoostCfg.Get(i, item[0], item[1]);
  80. if (collectcfg == null)
  81. {
  82. item.Add(0);
  83. }
  84. else
  85. {
  86. item.Add(collectcfg.Value);
  87. }
  88. if (CollectPartDataDic.ContainsKey(i))
  89. {
  90. CollectPartDataDic[i] = item;
  91. }
  92. else
  93. {
  94. CollectPartDataDic.Add(i, item);
  95. }
  96. }
  97. }
  98. }
  99. /// <summary>
  100. /// 穿戴部件的搭配加成
  101. /// </summary>
  102. public float GetEquipScoresWithPartId(int itemID)
  103. {
  104. List<CollegeSubTypesCfg> typeCfgs = CommonDataManager.Tables.TblCollegeSubTypesCfg.DataList ;
  105. float addNum = 0;
  106. for (int j = 0; j < typeCfgs.Count; j++)
  107. {
  108. CollegeSubTypesCfg cfg = typeCfgs[j];
  109. for (int k = 0; k < cfg.SubTypes.Count; k++)
  110. {
  111. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(itemID);
  112. if (itemCfg.SubType == cfg.SubTypes[k])
  113. {
  114. int partIndex = cfg.AdditionSite;
  115. int partIndexCommon = 0;
  116. partIndexCommon = partIndex;
  117. int level = CollectPartDataDic[partIndex][0];
  118. int levelNum = CollectPartDataDic[partIndex][1];
  119. if(levelNum == 0)
  120. {
  121. addNum += 0;
  122. break;
  123. }
  124. CollegeBoostCfg collegeCfg = CommonDataManager.Tables.TblCollegeBoostCfg.Get(partIndex, level, levelNum);
  125. addNum += (float)collegeCfg.Value / 10000;
  126. break;
  127. }
  128. }
  129. }
  130. return addNum + 1;
  131. }
  132. //判断部分是否可以升级
  133. public bool CheckPartCanUP(int pardId)
  134. {
  135. int rankIndex = CollectPartDataDic[pardId][0];
  136. int rankLv = CollectPartDataDic[pardId][1];
  137. if (rankLv + 1 > CollectPartDataManager.Instance.MaxLevel)
  138. {
  139. rankIndex += 1;
  140. rankLv = 1;
  141. }
  142. else
  143. {
  144. rankLv += 1;
  145. }
  146. CollegeBoostCfg collegeBoostCfg = CommonDataManager.Tables.TblCollegeBoostCfg.Get(pardId,rankIndex,rankLv);
  147. if (collegeBoostCfg == null)
  148. {
  149. return false;
  150. }
  151. for (int i = 0; i < collegeBoostCfg.Consume.Count; i++)
  152. {
  153. ItemCfg itemCfg = CommonDataManager.Tables.TblItemCfg.GetOrDefault(collegeBoostCfg.Consume[i].ItemId);
  154. ItemData itemCount;
  155. long count;
  156. if (itemCfg.ItemType == ConstItemType.DRESS_UP)
  157. {
  158. count = ItemDataManager.GetItemNum(collegeBoostCfg.Consume[i].ItemId);
  159. }
  160. else
  161. {
  162. if (BagDataManager.Instance.GetBagData().TryGetValue(collegeBoostCfg.Consume[i].ItemId, out itemCount))
  163. {
  164. count = itemCount.num;
  165. }
  166. else
  167. {
  168. count = 0;
  169. }
  170. }
  171. if(count < collegeBoostCfg.Consume[i].Count)
  172. {
  173. return false;
  174. }
  175. }
  176. return true;
  177. }
  178. //判断所有已开启部位是否可以升级
  179. public bool CheckAllOpenPartCanUP()
  180. {
  181. if(!FunctionOpenDataManager.Instance.CheckIsFunOpenById(typeof(ClothingSelectView).Name, false))
  182. {
  183. return false;
  184. }
  185. foreach(var item in CollectPartDataDic)
  186. {
  187. if(IsOpenRank(item.Key))
  188. {
  189. if(CheckPartCanUP(item.Key))
  190. {
  191. return true;
  192. }
  193. }
  194. }
  195. return false;
  196. }
  197. public bool IsOpenRank(int partIndex, int levelNum = 9)
  198. {
  199. List<int> openList;
  200. bool isRank = false;
  201. bool isLevel = false;
  202. bool isPassStory = false;
  203. CollegeRankOpenCfg openitem = CommonDataManager.Tables.TblCollegeRankOpenCfg.Get(partIndex);
  204. openList = GetOpenList(partIndex);
  205. //判断段位
  206. if (openitem.OpenPrecondition == null || openitem.OpenPrecondition.Count == 0)
  207. {
  208. isRank = true;
  209. }
  210. else
  211. {
  212. if (CollectPartDataDic[openList[0]][0] >= openList[1])
  213. {
  214. if (CollectPartDataDic[openList[0]][1] >= openList[2])
  215. {
  216. isRank = true;
  217. }
  218. }
  219. }
  220. //判断等级
  221. if (RoleDataManager.lvl >= openitem.NeedRoleLv)
  222. {
  223. isLevel = true;
  224. }
  225. //判断关卡
  226. if (openitem.NeedStoryLevelId == 0 || InstanceZonesDataManager.CheckLevelPass(openitem.NeedStoryLevelId))
  227. {
  228. isPassStory = true;
  229. }
  230. else
  231. {
  232. isPassStory = false;
  233. }
  234. return isRank && isLevel && isPassStory;
  235. }
  236. public List<int> GetOpenList(int partIndex)
  237. {
  238. List<int> openList = new List<int>();
  239. string pattern = @"\d+";
  240. CollegeRankOpenCfg openitem = CommonDataManager.Tables.TblCollegeRankOpenCfg.Get(partIndex);
  241. for (int i = 0; i < openitem.OpenPrecondition.Count; i++)
  242. {
  243. MatchCollection matches = Regex.Matches(openitem.OpenPrecondition[i], pattern);
  244. foreach (Match match in matches)
  245. {
  246. openList.Add(int.Parse(match.Value));
  247. }
  248. }
  249. return openList;
  250. }
  251. }
  252. }