PartnersService.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. using System.Collections.Generic;
  2. using System.Security.Cryptography;
  3. using FL.Network;
  4. using XGame;
  5. using XGame.Database;
  6. using XGame.Framework.Data;
  7. using XGame.Framework.Network;
  8. namespace FL.Data
  9. {
  10. public class PartnersService : DataSingleton<PartnersService>
  11. {
  12. #region 新接口
  13. /// <summary>
  14. /// 圣兵一键上阵
  15. /// </summary>
  16. public void RequestPartnerOneKeyUp()
  17. {
  18. NetModule.Request(new ShengbingWearAllRequest());
  19. }
  20. public void RequestPartnerOneKeyLvUp()
  21. {
  22. NetModule.Request(new ShengbingStrongAllRequest());
  23. }
  24. public void RequestUpdatePlanSb(int planId, int slotId, int sbId)
  25. {
  26. if (planId != PartnersData.Instance.UsePlanId)
  27. {
  28. var info = PartnersData.Instance.GetPartnerAttrByTableId(sbId);
  29. RequestUpdatePlan(planId, slotId, sbId, info?.EpigraphId ?? 0);
  30. }
  31. else
  32. {
  33. if (sbId > 0)
  34. {
  35. RequestPartnerUp(slotId, sbId);
  36. }
  37. else
  38. {
  39. RequestPartnerDown(slotId);
  40. }
  41. }
  42. }
  43. public void RequestUpdatePlanMw(int planId, int slotId, int sbId, int mwId)
  44. {
  45. if (planId != PartnersData.Instance.UsePlanId)
  46. {
  47. RequestUpdatePlan(planId, slotId, sbId, mwId);
  48. }
  49. else
  50. {
  51. var sbInfo = PartnersData.Instance.GetPartnerAttrByTableId(sbId);
  52. EpigraphService.Instance.RequestEpiInset(sbId, mwId);
  53. }
  54. }
  55. private void RequestUpdatePlan(int planId, int slotId, int sbId, int mwId)
  56. {
  57. var param = new ShengbingUpdateSuitRequest()
  58. {
  59. suit = planId,
  60. caoId = slotId,
  61. sbId = sbId,
  62. mwId = mwId,
  63. };
  64. NetModule.Request(param);
  65. }
  66. /// <summary>
  67. /// 请求替换圣兵方案
  68. /// </summary>
  69. /// <param name="planId"></param>
  70. public void RequestChangePlan(int planId)
  71. {
  72. //EventSingle.Instance.Notify(EventDefine.ShowTips, $"替换方案{planId}");
  73. var param = new ShengbingChangeSuitRequest() { suit = planId };
  74. NetModule.Request(param);
  75. }
  76. /// <summary>
  77. /// 修改圣兵方案名称
  78. /// </summary>
  79. /// <param name="planId"></param>
  80. /// <param name="name"></param>
  81. public void RequestRenamePlan(int planId, string name)
  82. {
  83. var param = new ShengbingSetNameRequest() { suit = planId, name = name };
  84. NetModule.Request(param);
  85. }
  86. /// <summary>
  87. /// 圣兵上阵
  88. /// </summary>
  89. /// <param name="posId">槽位id 0开始</param>
  90. /// <param name="id">圣兵id</param>
  91. public void RequestPartnerUp(int posId, int id)
  92. {
  93. var sbAttr = PartnersData.Instance.GetPartnerAttrByTableId(id);
  94. if (sbAttr == null)
  95. return;
  96. var param = new ShengbingWearRequest() { caoId = posId, sbId = id };
  97. (param as IMessage).Context = sbAttr.UID;
  98. NetModule.Request(param);
  99. }
  100. /// <summary>
  101. /// 下阵圣兵
  102. /// </summary>
  103. /// <param name="sbId"></param>
  104. public void RequestPartnerDown(int sbId)
  105. {
  106. var sbAttr = PartnersData.Instance.GetPartnerAttrByTableId(sbId);
  107. var pos = PartnersData.Instance.GetPartnerUpPosById(sbId);
  108. var param = new ShengbingUnfixRequest() { caoId = pos };
  109. (param as IMessage).Context = sbAttr.UID;
  110. NetModule.Request(param);
  111. }
  112. public void RequestStarUp(int sbId)
  113. {
  114. var param = new ShengbingUpStarRequest() { sbId = sbId };
  115. NetModule.Request(param);
  116. }
  117. public void RequestLvUp(int sbId)
  118. {
  119. var param = new ShengbingUpLevelRequest() { sbId = sbId };
  120. NetModule.Request(param);
  121. }
  122. private void OpenUpPartnerMode(int id)
  123. {
  124. PartnersData.Instance.UpModeSelect = id;
  125. EventSingle.Instance.Notify(EventDefine.PartnerOpenUpMode, id);
  126. }
  127. public void OpenPartnerMode(int id)
  128. {
  129. var plan = PartnersData.Instance.CurUsePlan;
  130. var selectCaoId = -1;
  131. for (int caoId = 0; caoId < PartnersData.GoneUpLimit; caoId++)
  132. {
  133. var slot = plan.GetSlot(caoId);
  134. if (slot == null || slot.SbId == 0)
  135. {
  136. selectCaoId = caoId;
  137. break;
  138. }
  139. }
  140. if (selectCaoId >= 0)
  141. {
  142. RequestPartnerUp(selectCaoId, id);
  143. }
  144. else
  145. {
  146. OpenUpPartnerMode(id);
  147. }
  148. }
  149. public void FinishUpPartnerMode()
  150. {
  151. PartnersData.Instance.UpModeSelect = 0;
  152. EventSingle.Instance.Notify(EventDefine.PartnerFinishUpMode);
  153. }
  154. /// <summary>
  155. /// 更新当前已上阵随从位置
  156. /// </summary>
  157. public void UpdateCurUpPartnerMap()
  158. {
  159. var plan = PartnersData.Instance.CurUsePlan;
  160. PartnersData.Instance.UpPartnerMap.Clear();
  161. PartnersData.Instance.UpPartnerUIDMap.Clear();
  162. if (plan == null)
  163. return;
  164. foreach (var partnerSlot in plan.Slots)
  165. {
  166. if (partnerSlot.SbId > 0)
  167. {
  168. var partnerAttr = PartnersData.Instance.GetPartnerAttrByTableId(
  169. partnerSlot.SbId
  170. );
  171. if (partnerAttr == null)
  172. {
  173. Log.Debug("槽位圣兵id不存在");
  174. return;
  175. }
  176. PartnersData.Instance.UpPartnerMap.Add(partnerSlot.SbId, partnerSlot.CaoId);
  177. PartnersData.Instance.UpPartnerUIDMap.Add(partnerAttr.UID, partnerSlot.CaoId);
  178. }
  179. }
  180. }
  181. /// <summary>
  182. /// 更新拥有圣兵信息
  183. /// </summary>
  184. /// <param name="list"></param>
  185. public void UpdatePartnerMap(List<ActShengBingList> list)
  186. {
  187. foreach (var shengBing in list)
  188. {
  189. if (
  190. PartnersData.Instance.TryGetPartnerAttrByTableId(
  191. shengBing.sbId,
  192. out var partnerInfo
  193. )
  194. )
  195. {
  196. var table = PartnerTableRepo.Get(shengBing.sbId);
  197. var skillId = PartnersData.Instance.GetSkillId(shengBing.star, table?.Skill);
  198. partnerInfo.Level = shengBing.level;
  199. partnerInfo.RisingStarLv = shengBing.star;
  200. partnerInfo.EpigraphId = shengBing.mingwen;
  201. partnerInfo.Status = shengBing.status;
  202. partnerInfo.SkillId = skillId;
  203. }
  204. else
  205. {
  206. var attr = PartnersData.Instance.CreatePartnerAttr(
  207. shengBing.sbId,
  208. shengBing.level,
  209. shengBing.star,
  210. shengBing.mingwen,
  211. shengBing.status
  212. );
  213. PartnersData.Instance.AddPartnerAttr(attr);
  214. }
  215. }
  216. }
  217. /// <summary>
  218. /// 更新方案
  219. /// </summary>
  220. /// <param name="suitList"></param>
  221. public void UpdatePlanMap(List<ActShengBingSuit> suitList)
  222. {
  223. foreach (var suit in suitList)
  224. {
  225. var plan = PartnersData.Instance.GetPlanById(suit.id);
  226. if (plan != null)
  227. {
  228. var caoList = new List<PartnerPlanSlot>();
  229. foreach (var cao in suit.cao)
  230. {
  231. var slot = new PartnerPlanSlot();
  232. slot.Init(cao.caoId, cao.mwId, cao.sbId);
  233. caoList.Add(slot);
  234. }
  235. plan.SetData(suit.id, suit.name, caoList);
  236. }
  237. else
  238. {
  239. var caoList = new List<PartnerPlanSlot>();
  240. foreach (var cao in suit.cao)
  241. {
  242. var slot = new PartnerPlanSlot();
  243. slot.Init(cao.caoId, cao.mwId, cao.sbId);
  244. caoList.Add(slot);
  245. }
  246. var partnerPlan = new PartnerPlan();
  247. partnerPlan.SetData(suit.id, suit.name, caoList);
  248. PartnersData.Instance.AddPlanMap(partnerPlan);
  249. }
  250. }
  251. }
  252. /// <summary>
  253. /// 初始化方案信息
  254. /// </summary>
  255. /// <param name="suitList"></param>
  256. public void InitPlanMap(List<ActShengBingSuit> suitList)
  257. {
  258. PartnersData.Instance.ClearPlanMap();
  259. foreach (var suit in suitList)
  260. {
  261. var caoList = new List<PartnerPlanSlot>();
  262. foreach (var cao in suit.cao)
  263. {
  264. var slot = new PartnerPlanSlot();
  265. slot.Init(cao.caoId, cao.mwId, cao.sbId);
  266. caoList.Add(slot);
  267. }
  268. var plan = new PartnerPlan();
  269. plan.SetData(suit.id, suit.name, caoList);
  270. PartnersData.Instance.AddPlanMap(plan);
  271. }
  272. }
  273. public void InitPartnerMap(List<ActShengBingList> list)
  274. {
  275. PartnersData.Instance.ClearPartnerMap();
  276. foreach (var shengBing in list)
  277. {
  278. var attr = PartnersData.Instance.CreatePartnerAttr(
  279. shengBing.sbId,
  280. shengBing.level,
  281. shengBing.star,
  282. shengBing.mingwen,
  283. shengBing.status
  284. );
  285. PartnersData.Instance.AddPartnerAttr(attr);
  286. }
  287. }
  288. /// <summary>
  289. /// 获取星星的色阶
  290. /// </summary>
  291. /// <param name="starLv"></param>
  292. /// <returns></returns>
  293. public int GetStarStep(int starLevel)
  294. {
  295. int step = PartnersData.MaxStarStep - 1;
  296. for (int i = step; starLevel >= 0; i--)
  297. {
  298. if (starLevel > i * PartnersData.MaxStarNum)
  299. {
  300. return i + 1;
  301. }
  302. }
  303. return 1;
  304. }
  305. #endregion
  306. }
  307. }