CombatCalculateTool.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. using System;
  2. using System.Collections.Generic;
  3. using CombatLibrary.CombatLibrary.CombatCore.CustomizeTimeLogic.FxLogic;
  4. using Common.Utility.CombatEvent;
  5. using Excel2Json;
  6. using Fort23.Core;
  7. using GameLogic.Combat.Hero;
  8. using GameLogic.Player;
  9. using Utility;
  10. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
  11. namespace GameLogic.Combat.CombatTool
  12. {
  13. public class CombatCalculateTool : Singleton<CombatCalculateTool>
  14. {
  15. public Random Random = new Random();
  16. static readonly WuXingType[] Symbiosis = new WuXingType[5]
  17. {
  18. WuXingType.Water, // 金生水
  19. WuXingType.Fire, // 木生火
  20. WuXingType.Gold, // 水生金
  21. WuXingType.Earth, // 火生土
  22. WuXingType.Wood // 土生木
  23. };
  24. // 相克关系表(用位表示)
  25. static readonly WuXingType[] Restrain = new WuXingType[5]
  26. {
  27. WuXingType.Wood, // 金克木
  28. WuXingType.Earth, // 木克土
  29. WuXingType.Fire, // 水克火
  30. WuXingType.Gold, // 火克金
  31. WuXingType.Water // 土克水
  32. };
  33. public CombatCalculateTool()
  34. {
  35. Random = new Random(System.DateTime.Now.Millisecond);
  36. }
  37. public int GetOdd()
  38. {
  39. return Random.Next(0, 100);
  40. }
  41. public int GetOdd(int min, int max)
  42. {
  43. return Random.Next(min, max);
  44. }
  45. public long GetVlaueRatioForLong(long value, float ration)
  46. {
  47. long v = (value * (long)(ration * 100)) / 10000;
  48. return v;
  49. }
  50. public float GetVlaueRatioForFloat(float value, float ration)
  51. {
  52. float v = (value * ration) / 100f;
  53. return v;
  54. }
  55. public int GetVlaueRatioForInt(int value, float ration)
  56. {
  57. int v = (value * (int)(ration * 100)) / 10000;
  58. return v;
  59. }
  60. public HarmReturnInfo Harm(CombatHeroEntity source, CombatHeroEntity target, long att, AttType attType,
  61. TriggerData triggerData, WuXingType WuXingType, HarmType harmType = HarmType.Null)
  62. {
  63. return Harm(source, target.GetMainHotPoin<CombatHeroHitPoint>(), att,
  64. attType, triggerData, WuXingType, harmType);
  65. }
  66. /// <summary>
  67. /// 造成伤害
  68. /// </summary>n
  69. /// <param name="source">攻击方</param>
  70. /// <param name="target">被攻击方</param>
  71. /// <param name="att">伤害值</param>
  72. public HarmReturnInfo Harm(CombatHeroEntity source, CombatHeroHitPoint target, long att,
  73. AttType attType, TriggerData triggerData, WuXingType WuXingType,
  74. HarmType harmType = HarmType.Default)
  75. {
  76. HarmReturnInfo harmReturnInfo = CObjectPool.Instance.Fetch<HarmReturnInfo>();
  77. harmReturnInfo.source = source;
  78. harmReturnInfo.target = target;
  79. harmReturnInfo.att = att;
  80. harmReturnInfo.attType = attType;
  81. harmReturnInfo.WuXingType = WuXingType;
  82. harmReturnInfo.harmType = harmType;
  83. harmReturnInfo.triggerData = triggerData;
  84. if (target.combatHeroEntity.isDie)
  85. {
  86. return harmReturnInfo;
  87. }
  88. if (CombatController.currActiveCombat.IsGameOver)
  89. {
  90. return harmReturnInfo;
  91. }
  92. StartInjuredEventData startInjuredEventData = StartInjuredEventData.Create();
  93. startInjuredEventData.HarmReturnInfo = harmReturnInfo;
  94. CombatEventManager.Instance.Dispatch(CombatEventType.StartInjured, startInjuredEventData);
  95. target.combatHeroEntity.This<CombatHeroEntity>().HeroHurt(harmReturnInfo);
  96. return harmReturnInfo;
  97. }
  98. public HarmReturnInfo TrueHarm(CombatHeroEntity source, CombatHeroHitPoint target, long att,
  99. AttType attType, TriggerData triggerData,
  100. HarmType harmType = HarmType.Default)
  101. {
  102. HarmReturnInfo harmReturnInfo = CObjectPool.Instance.Fetch<HarmReturnInfo>();
  103. harmReturnInfo.source = source;
  104. harmReturnInfo.target = target;
  105. harmReturnInfo.att = att;
  106. harmReturnInfo.attType = attType;
  107. harmReturnInfo.harmType = harmType;
  108. harmReturnInfo.triggerData = triggerData;
  109. if (target.combatHeroEntity.isDie)
  110. {
  111. return harmReturnInfo;
  112. }
  113. target.combatHeroEntity.This<CombatHeroEntity>().HeroHurt(harmReturnInfo);
  114. return harmReturnInfo;
  115. }
  116. public HarmReturnInfo Recover(CombatHeroEntity source, CombatHeroHitPoint target, long att,
  117. AttType attType, HarmType harmType, TriggerData triggerData)
  118. {
  119. HarmReturnInfo harmReturnInfo = new HarmReturnInfo();
  120. harmReturnInfo.source = source;
  121. harmReturnInfo.target = target;
  122. harmReturnInfo.att = att;
  123. harmReturnInfo.attType = attType;
  124. harmReturnInfo.harmType = harmType;
  125. harmReturnInfo.triggerData = triggerData;
  126. if (target.combatHeroEntity.isDie)
  127. {
  128. return harmReturnInfo;
  129. }
  130. target.combatHeroEntity.This<CombatHeroEntity>().Recover(harmReturnInfo);
  131. return harmReturnInfo;
  132. }
  133. public ILifetCycleHitPoint[] GetMinHpHero(ILifetCycleHitPoint[] allLifetCycleHitPoints, int count)
  134. {
  135. if (allLifetCycleHitPoints == null)
  136. {
  137. return null;
  138. }
  139. BetterList<ILifetCycleHitPoint> findHero = new BetterList<ILifetCycleHitPoint>();
  140. findHero.AddRange(allLifetCycleHitPoints);
  141. int currCount = Math.Min(allLifetCycleHitPoints.Length, count);
  142. ILifetCycleHitPoint[] minHpHero = new ILifetCycleHitPoint[currCount];
  143. for (int k = 0; k < currCount; k++)
  144. {
  145. CombatHeroEntity lifetCycleHitPoint = null;
  146. int index = 0;
  147. if (findHero.Count <= 0)
  148. {
  149. return minHpHero;
  150. }
  151. lifetCycleHitPoint = findHero[0].IfLifeCycle.This<CombatHeroEntity>();
  152. for (int j = 0; j < findHero.Count; j++)
  153. {
  154. CombatHeroEntity lifetCycleHitPoint2 =
  155. findHero[j].IfLifeCycle.This<CombatHeroEntity>();
  156. if (lifetCycleHitPoint2.HpBl < lifetCycleHitPoint.HpBl)
  157. {
  158. lifetCycleHitPoint = lifetCycleHitPoint2;
  159. index = j;
  160. }
  161. }
  162. ILifetCycleHitPoint currFindHitPoint = lifetCycleHitPoint.GetMainHotPoin<ILifetCycleHitPoint>(true);
  163. minHpHero[k] = currFindHitPoint;
  164. findHero.RemoveAt(index);
  165. }
  166. return minHpHero;
  167. }
  168. private int GeWuXingTypeIndex(WuXingType e)
  169. {
  170. switch (e)
  171. {
  172. case WuXingType.Gold: return 0;
  173. case WuXingType.Wood: return 1;
  174. case WuXingType.Water: return 2;
  175. case WuXingType.Fire: return 3;
  176. case WuXingType.Earth: return 4;
  177. default: return -1; // 无效元素
  178. }
  179. }
  180. /// <summary>
  181. /// 是否相生
  182. /// </summary>
  183. /// <returns></returns>
  184. public bool IsSymbiosis(WuXingType a, WuXingType b)
  185. {
  186. int index = GeWuXingTypeIndex(a);
  187. if (index < 0)
  188. {
  189. return false;
  190. }
  191. return (b & Symbiosis[index]) != 0;
  192. }
  193. /// <summary>
  194. /// 是否相生
  195. /// </summary>
  196. /// <returns></returns>
  197. public bool IsRestrain(WuXingType a, WuXingType b)
  198. {
  199. int index = GeWuXingTypeIndex(a);
  200. if (index < 0)
  201. {
  202. return false;
  203. }
  204. return (b & Restrain[index]) != 0;
  205. }
  206. }
  207. }