PartnersService.cs 10.0 KB

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