CombatCalculateTool.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. using System;
  2. using System.Collections.Generic;
  3. using CombatLibrary.CombatLibrary.CombatCore.CustomizeTimeLogic.FxLogic;
  4. using Excel2Json;
  5. using Fort23.Core;
  6. using GameLogic.Combat.Hero;
  7. using GameLogic.Player;
  8. using Utility;
  9. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
  10. namespace GameLogic.Combat.CombatTool
  11. {
  12. public class CombatCalculateTool : Singleton<CombatCalculateTool>
  13. {
  14. public Random Random = new Random();
  15. public CombatCalculateTool()
  16. {
  17. Random = new Random(System.DateTime.Now.Millisecond);
  18. }
  19. public int GetOdd()
  20. {
  21. return Random.Next(0, 100);
  22. }
  23. public int GetOdd(int min, int max)
  24. {
  25. return Random.Next(min, max);
  26. }
  27. public long GetVlaueRatioForLong(long value, float ration)
  28. {
  29. long v = (value * (long)(ration * 100)) / 10000;
  30. return v;
  31. }
  32. public int GetVlaueRatioForInt(int value, float ration)
  33. {
  34. int v = (value * (int)(ration * 100)) / 10000;
  35. return v;
  36. }
  37. public HarmReturnInfo Harm(CombatHeroEntity source, CombatHeroEntity target, long att, AttType attType,
  38. TriggerData triggerData,WuXingType WuXingType, HarmType harmType = HarmType.Null)
  39. {
  40. return Harm(source, target.GetMainHotPoin<CombatHeroHitPoint>(), att,
  41. attType, triggerData,WuXingType, harmType);
  42. }
  43. /// <summary>
  44. /// 造成伤害
  45. /// </summary>n
  46. /// <param name="source">攻击方</param>
  47. /// <param name="target">被攻击方</param>
  48. /// <param name="att">伤害值</param>
  49. public HarmReturnInfo Harm(CombatHeroEntity source, CombatHeroHitPoint target, long att,
  50. AttType attType, TriggerData triggerData,WuXingType WuXingType,
  51. HarmType harmType = HarmType.Default)
  52. {
  53. HarmReturnInfo harmReturnInfo = CObjectPool.Instance.Fetch<HarmReturnInfo>();
  54. harmReturnInfo.source = source;
  55. harmReturnInfo.target = target;
  56. harmReturnInfo.att = att;
  57. harmReturnInfo.attType = attType;
  58. harmReturnInfo.WuXingType= WuXingType;
  59. harmReturnInfo.harmType = harmType;
  60. harmReturnInfo.triggerData = triggerData;
  61. if (target.combatHeroEntity.isDie)
  62. {
  63. return harmReturnInfo;
  64. }
  65. if (CombatController.currActiveCombat.IsGameOver)
  66. {
  67. return harmReturnInfo;
  68. }
  69. if (target.combatHeroEntity.CombatAIBasic.stateControl.CurrStateName.Equals(CombatHeroStateType.rolling))
  70. {
  71. harmReturnInfo.isMiss = true;
  72. return harmReturnInfo;
  73. }
  74. harmReturnInfo.att = att;
  75. target.combatHeroEntity.This<CombatHeroEntity>().HeroHurt(harmReturnInfo);
  76. return harmReturnInfo;
  77. }
  78. public HarmReturnInfo TrueHarm(CombatHeroEntity source, CombatHeroHitPoint target, long att,
  79. AttType attType, TriggerData triggerData,
  80. HarmType harmType = HarmType.Default)
  81. {
  82. HarmReturnInfo harmReturnInfo = CObjectPool.Instance.Fetch<HarmReturnInfo>();
  83. harmReturnInfo.source = source;
  84. harmReturnInfo.target = target;
  85. harmReturnInfo.att = att;
  86. harmReturnInfo.attType = attType;
  87. harmReturnInfo.harmType = harmType;
  88. harmReturnInfo.triggerData = triggerData;
  89. if (target.combatHeroEntity.isDie)
  90. {
  91. return harmReturnInfo;
  92. }
  93. target.combatHeroEntity.This<CombatHeroEntity>().HeroHurt(harmReturnInfo);
  94. return harmReturnInfo;
  95. }
  96. public HarmReturnInfo Recover(CombatHeroEntity source, CombatHeroHitPoint target, long att,
  97. AttType attType, HarmType harmType, TriggerData triggerData)
  98. {
  99. HarmReturnInfo harmReturnInfo = new HarmReturnInfo();
  100. harmReturnInfo.source = source;
  101. harmReturnInfo.target = target;
  102. harmReturnInfo.att = att;
  103. harmReturnInfo.attType = attType;
  104. harmReturnInfo.harmType = harmType;
  105. harmReturnInfo.triggerData = triggerData;
  106. if (target.combatHeroEntity.isDie)
  107. {
  108. return harmReturnInfo;
  109. }
  110. target.combatHeroEntity.This<CombatHeroEntity>().Recover(harmReturnInfo);
  111. return harmReturnInfo;
  112. }
  113. public ILifetCycleHitPoint[] GetMinHpHero(ILifetCycleHitPoint[] allLifetCycleHitPoints, int count)
  114. {
  115. if (allLifetCycleHitPoints == null)
  116. {
  117. return null;
  118. }
  119. BetterList<ILifetCycleHitPoint> findHero = new BetterList<ILifetCycleHitPoint>();
  120. findHero.AddRange(allLifetCycleHitPoints);
  121. int currCount = Math.Min(allLifetCycleHitPoints.Length, count);
  122. ILifetCycleHitPoint[] minHpHero = new ILifetCycleHitPoint[currCount];
  123. for (int k = 0; k < currCount; k++)
  124. {
  125. CombatHeroEntity lifetCycleHitPoint = null;
  126. int index = 0;
  127. if (findHero.Count <= 0)
  128. {
  129. return minHpHero;
  130. }
  131. lifetCycleHitPoint = findHero[0].IfLifeCycle.This<CombatHeroEntity>();
  132. for (int j = 0; j < findHero.Count; j++)
  133. {
  134. CombatHeroEntity lifetCycleHitPoint2 =
  135. findHero[j].IfLifeCycle.This<CombatHeroEntity>();
  136. if (lifetCycleHitPoint2.HpBl < lifetCycleHitPoint.HpBl)
  137. {
  138. lifetCycleHitPoint = lifetCycleHitPoint2;
  139. index = j;
  140. }
  141. }
  142. ILifetCycleHitPoint currFindHitPoint = lifetCycleHitPoint.GetMainHotPoin<ILifetCycleHitPoint>(true);
  143. minHpHero[k] = currFindHitPoint;
  144. findHero.RemoveAt(index);
  145. }
  146. return minHpHero;
  147. }
  148. }
  149. }