PartnersService.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using XGame;
  5. using XGame.Database;
  6. using XGame.Framework.Data;
  7. using Random = UnityEngine.Random;
  8. namespace FL.Data
  9. {
  10. public class PartnersService : DataSingleton<PartnersService>
  11. {
  12. /// <summary>
  13. /// 模拟初始化数据
  14. /// </summary>
  15. public void Mock()
  16. {
  17. var tableIds = new List<int> { 20511, 20521, 20541, 20531, 20561, 20551 };
  18. var goneUpMap = PartnersData.Instance.GoneUpMap;
  19. var partnersMap = PartnersData.Instance.PartnersMap;
  20. var allTables = PartnerTableRepo.GetAll();
  21. foreach (var table in allTables)
  22. {
  23. int starLv = Random.Range(0, 6);//随机数的取值范围包括min,但不包括max
  24. int skillId = GetSkillId(starLv, table.Skill);
  25. var entityAttr = new PartnerAttributes()
  26. {
  27. TableId = table.Id,
  28. UID = UIDDefine.New(),
  29. Name = table.Name,
  30. Level = Random.Range(1, 10),
  31. RisingStarLv = starLv,
  32. SkillId = skillId,
  33. Radius = table.Size * 0.5f,
  34. };
  35. entityAttr.Attr.Hp = 500;
  36. entityAttr.Attr.HpLimit = 500;
  37. entityAttr.Attr.MoveSpeed = PlayerData.Instance.Attr.MoveSpeed;
  38. entityAttr.Attr.Attack = Random.Range(5, 10);
  39. var idx = tableIds.IndexOf(table.Id);
  40. if (idx >= 0)
  41. {
  42. goneUpMap.Add(entityAttr.UID, idx);
  43. }
  44. partnersMap.Add(entityAttr.UID, entityAttr);
  45. }
  46. // 模拟圣兵方案数据
  47. PartnersData.Instance.usePlanIndex = 0;
  48. var lineupPlanNameList = PartnersData.Instance.LineupPlanNameList;
  49. var lineupPlanList = PartnersData.Instance.LineupPlanList;
  50. for (int i = 0; i < 5; i++)
  51. {
  52. lineupPlanNameList.Add($"方案{i + 1}");
  53. int numberOfItems = i == 0 ? 5 : UnityEngine.Random.Range(0, 7); // 你想获取的随机项数
  54. var dataList = new List<long>();
  55. for (int j = 0; j < 6; j++)
  56. {
  57. long partnerUid = 0;
  58. if (j <= numberOfItems)
  59. {
  60. foreach (var item in goneUpMap)
  61. {
  62. if (item.Value == j)
  63. {
  64. partnerUid = item.Key;
  65. }
  66. }
  67. }
  68. dataList.Add(partnerUid);
  69. }
  70. lineupPlanList.Add(dataList);
  71. }
  72. }
  73. /// <summary>
  74. /// 获取
  75. /// </summary>
  76. /// <param name="starLv"></param>
  77. /// <param name="skillIdList"></param>
  78. private int GetSkillId(int starLv, int[] skillIdList)
  79. {
  80. if (skillIdList?.Length > 1)
  81. {
  82. int count = skillIdList.Length - 1;
  83. for (int i = count; i >= 0; i -= 2)
  84. {
  85. //XGame.Log.Info($"索引:{i}的技能id:{skillIdList[i]},需要的星级:{skillIdList[i-1]}");
  86. if (starLv >= skillIdList[i - 1])
  87. {
  88. return skillIdList[i];
  89. }
  90. }
  91. }
  92. return skillIdList[0];
  93. }
  94. public void RequestPartnerUp(long partnerUID)
  95. {
  96. if (PartnersData.Instance.IsReachedLimit)
  97. {
  98. EventSingle.Instance.Notify(EventDefine.ShowTips, "随从已经达到出战数量上限.");
  99. return;
  100. }
  101. var goneUpMap = PartnersData.Instance.GoneUpMap;
  102. for (var i = 0; i < PartnersData.GoneUpLimit; i++)
  103. {
  104. if (goneUpMap.Values.Contains(i))
  105. {
  106. continue;
  107. }
  108. goneUpMap.Add(partnerUID, i);
  109. EventSingle.Instance.Notify(EventDefine.PartnerUp, partnerUID);
  110. break;
  111. }
  112. }
  113. public void RequestPartnerDown(long partnerUID)
  114. {
  115. if (!PartnersData.Instance.GoneUpMap.ContainsKey(partnerUID))
  116. {
  117. return;
  118. }
  119. PartnersData.Instance.GoneUpMap.Remove(partnerUID);
  120. EventSingle.Instance.Notify(EventDefine.PartnerDown, partnerUID);
  121. var useLineupPlanList = PartnersData.Instance.LineupPlanList[PartnersData.Instance.usePlanIndex];
  122. if (useLineupPlanList?.Count > 0)
  123. {
  124. }
  125. if (PartnersData.Instance.IsWaitForDownState)
  126. EventSingle.Instance.Notify(EventDefine.WaitForDownPartner, false);
  127. }
  128. //public void ExchangePartners()
  129. //{
  130. // var all = PartnerTableRepo.GetAll();
  131. // var activePartnerIds = PartnersData.Instance.ActiveUIDs;
  132. // var addPartners = new List<int>();
  133. // foreach (var table in all)
  134. // {
  135. // if (activePartnerIds.Contains(table.Id))
  136. // {
  137. // continue;
  138. // }
  139. // addPartners.Add(table.Id);
  140. // }
  141. // EventSingle.Instance.Notify(EventDefine.GameMainMapExchangePartner, addPartners);
  142. //}
  143. /// <summary>
  144. /// 请求替换圣兵方案
  145. /// </summary>
  146. /// <param name="lineupPlanIndex"></param>
  147. public void RequestToChangeLineupPlan(int lineupPlanIndex)
  148. {
  149. EventSingle.Instance.Notify(EventDefine.ShowTips, $"替换方案{lineupPlanIndex}");
  150. }
  151. /// <summary>
  152. /// 修改圣兵方案名称
  153. /// </summary>
  154. /// <param name="lineupPlanNameIndex"></param>
  155. /// <param name="changeName"></param>
  156. public void RequestToAlterLineupPlanName(int lineupPlanNameIndex, string changeName)
  157. {
  158. }
  159. }
  160. }