PartnersService.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. using System.Collections.Generic;
  2. using FL.Network;
  3. using UnityEngine;
  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 RequestPartnerOneKeyStarUp()
  21. {
  22. NetModule.Request(new ShengbingStrongAllRequest());
  23. }
  24. /// <summary>
  25. /// 圣兵上阵
  26. /// </summary>
  27. /// <param name="posId">槽位id 0开始</param>
  28. /// <param name="id">圣兵id</param>
  29. public void RequestPartnerUpNew(int posId, int id)
  30. {
  31. var sbAttr = PartnersData.Instance.GetPartnerAttrByTableId(id);
  32. if (sbAttr == null)
  33. return;
  34. var param = new ShengbingNewWearRequest() { caoId = posId, sbId = id };
  35. (param as IMessage).Context = sbAttr.UID;
  36. NetModule.Request(param);
  37. }
  38. /// <summary>
  39. /// 下阵圣兵
  40. /// </summary>
  41. /// <param name="sbId"></param>
  42. public void RequestPartnerDownNew(int sbId)
  43. {
  44. var sbAttr = PartnersData.Instance.GetPartnerAttrByTableId(sbId);
  45. var pos = PartnersData.Instance.UpSbPosMap.GetValueOrDefault(sbId, -1);
  46. var param = new ShengbingNewUnfixRequest() { caoId = pos };
  47. (param as IMessage).Context = sbAttr.UID;
  48. NetModule.Request(param);
  49. }
  50. public void RequestStarUp(int sbId)
  51. {
  52. var param = new ShengbingUpStarRequest() { sbId = sbId };
  53. NetModule.Request(param);
  54. }
  55. public void RequestLvUp(int sbId)
  56. {
  57. var param = new ShengbingUpLevelRequest() { sbId = sbId };
  58. NetModule.Request(param);
  59. }
  60. public void RequestJibanRwdGet(int rwdId)
  61. {
  62. var param = new ShengbingUnlockJibanRequest() { jiban = rwdId };
  63. NetModule.Request(param);
  64. }
  65. public void RequestJibanRwdGetAll(int collectId)
  66. {
  67. var param = new ShengbingUnlockJibanAllRequest() { collectId = collectId };
  68. NetModule.Request(param);
  69. }
  70. public void OpenUpPartnerMode(int id)
  71. {
  72. PartnersData.Instance.UpModeSelect = id;
  73. EventSingle.Instance.Notify(EventDefine.PartnerOpenUpMode, id);
  74. }
  75. public void FinishUpPartnerMode()
  76. {
  77. PartnersData.Instance.UpModeSelect = 0;
  78. EventSingle.Instance.Notify(EventDefine.PartnerFinishUpMode);
  79. }
  80. /// <summary>
  81. /// 更新拥有圣兵信息
  82. /// </summary>
  83. /// <param name="list"></param>
  84. public void UpdatePartnerMap(List<ActShengBingList> list)
  85. {
  86. foreach (var shengBing in list)
  87. {
  88. if (
  89. PartnersData.Instance.TryGetPartnerAttrByTableId(
  90. shengBing.sbId,
  91. out var partnerInfo
  92. )
  93. )
  94. {
  95. var table = PartnerTableRepo.Get(shengBing.sbId);
  96. var skillId = PartnersData.Instance.GetSkillId(shengBing.star, table?.Skill);
  97. partnerInfo.Level = shengBing.level;
  98. partnerInfo.RisingStarLv = shengBing.star;
  99. partnerInfo.EpigraphId = shengBing.mingwen;
  100. partnerInfo.Status = shengBing.status;
  101. partnerInfo.SkillId = skillId;
  102. }
  103. else
  104. {
  105. var attr = PartnersData.Instance.CreatePartnerAttr(
  106. shengBing.sbId,
  107. shengBing.level,
  108. shengBing.star,
  109. shengBing.mingwen,
  110. shengBing.status
  111. );
  112. PartnersData.Instance.AddPartnerAttr(attr);
  113. }
  114. }
  115. }
  116. public void InitPartnerMap(List<ActShengBingList> list)
  117. {
  118. PartnersData.Instance.ClearPartnerMap();
  119. foreach (var shengBing in list)
  120. {
  121. var attr = PartnersData.Instance.CreatePartnerAttr(
  122. shengBing.sbId,
  123. shengBing.level,
  124. shengBing.star,
  125. shengBing.mingwen,
  126. shengBing.status
  127. );
  128. PartnersData.Instance.AddPartnerAttr(attr);
  129. }
  130. }
  131. /// <summary>
  132. /// 获取星星的色阶
  133. /// </summary>
  134. /// <param name="starLv"></param>
  135. /// <returns></returns>
  136. public int GetStarStep(int starLevel)
  137. {
  138. return Mathf.FloorToInt((starLevel - 1) / PartnersData.MaxStarNum) + 1;
  139. }
  140. /// <summary>
  141. /// 获取升星当前级别星星等级
  142. /// </summary>
  143. /// <param name="starLv"></param>
  144. /// <returns></returns>
  145. public int GetStarLv(int starLv)
  146. {
  147. int starNum = starLv == 0 ? 0 : starLv % PartnersData.MaxStarNum;
  148. if (starLv > 0 && starNum == 0)
  149. starNum = PartnersData.MaxStarNum;
  150. return starNum;
  151. }
  152. #endregion
  153. }
  154. }