CombatCalculateTool.cs 8.9 KB

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