FxParabolaBulletLogic.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. using System.Collections.Generic;
  2. using Core.Audio;
  3. using Core.Triiger;
  4. using GameLogic.Combat.CombatTool;
  5. using GameLogic.Combat.Hero;
  6. using GameLogic.Combat.Skill;
  7. using UnityEngine;
  8. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
  9. namespace Common.Combat.FxAILogic
  10. {
  11. [AddComponentMenu("特效脚本/弹道/功法通用弹道")]
  12. public class FxParabolaBulletLogic : FxAILogicBasic
  13. {
  14. public float speed;
  15. private IUnRegister UnRegister = null;
  16. public enum CurveType
  17. {
  18. DynamicCurve,
  19. Beeline,
  20. CustomizeCurve,
  21. }
  22. [Header("曲线类型")] public CurveType parabolaCurveType;
  23. [Header("释放碰撞到地面时结束")] public bool isTriggerGroundEnd;
  24. [Header("碰撞到地面时的特效")] public string GroundHitFxName;
  25. private Vector3 endPos;
  26. private Vector3 dir;
  27. public float maxDis = 20;
  28. protected float maxDisSpr;
  29. // private BesselPath _besselPath;
  30. private float _addTime;
  31. protected Vector3 startDir;
  32. private float dirLerpTime;
  33. protected override void ProInit()
  34. {
  35. maxDisSpr = maxDis * maxDis;
  36. UnRegister = gameObject.OnTriggerEnterEvent(this, OnTriggerEnterEvent);
  37. if (isUseCustomTargetEndPos)
  38. {
  39. endPos = TimeLineEventParticleLogicBasic.customizePos[
  40. customTargetEndPosIndex];
  41. }
  42. else
  43. {
  44. endPos = AttTarget.GetSpecialDotInfo("hitpos").GetWorlPos();
  45. // endPos = new Vector3(endPos.x, CurrPos.y, endPos.z);
  46. }
  47. if (parabolaCurveType == CurveType.DynamicCurve)
  48. {
  49. Vector3 off = _currPos - CombatHeroEntity.GameObject.transform.position;
  50. startDir = CombatHeroEntity.GameObject.transform.TransformPoint(off +
  51. new Vector3(
  52. Mathf.Sign(Random.Range(-1, 1)),
  53. Random.Range(0.1f, 1f),
  54. Random.Range(0.1f, 5f)));
  55. startDir = (startDir - _currPos).normalized;
  56. dirLerpTime = 0;
  57. dir = (endPos - CurrPos).normalized;
  58. }
  59. else
  60. {
  61. dir = (endPos - _currPos).normalized;
  62. }
  63. gameObject.transform.rotation = Quaternion.LookRotation(dir);
  64. }
  65. void TriggerGround()
  66. {
  67. ITimeLineTriggerEvent timeLineTriggerEvent =
  68. TimeLineEventParticleLogicBasic.ITimeLineTriggerEntity as ITimeLineTriggerEvent;
  69. FinishHit(new Vector3(_currPos.x, 0.5f, _currPos.z), GroundHitFxName);
  70. AudioManager.Instance.PlayAudio(hitAudioName, false);
  71. if (timeLineTriggerEvent != null)
  72. {
  73. timeLineTriggerEvent.TimeLineTriggerGround(
  74. TimeLineEventParticleLogicBasic.TimeLineEventLogicGroup.groupName,
  75. this, triggerData);
  76. }
  77. AudioManager.Instance.PlayAudio(hitAudioName, false);
  78. Dispose();
  79. }
  80. protected void GetTargetPos()
  81. {
  82. if (isUseCustomTargetEndPos)
  83. {
  84. endPos = TimeLineEventParticleLogicBasic.customizePos[
  85. customTargetEndPosIndex];
  86. }
  87. else
  88. {
  89. endPos = AttTarget.GetSpecialDotInfo("hitpos").GetWorlPos();
  90. // endPos = new Vector3(endPos.x, CurrPos.y, endPos.z);
  91. }
  92. }
  93. protected void OnTriggerEnterEvent(Collider collision, ITriggerEntity triggerEntity)
  94. {
  95. if (isTriggerGroundEnd)
  96. {
  97. if (collision.gameObject.CompareTag("dimian"))
  98. {
  99. TriggerGround();
  100. return;
  101. }
  102. }
  103. FxAILogicBasic fxAILogicBasic = triggerEntity as FxAILogicBasic;
  104. if (fxAILogicBasic != null) //击中其他的功法
  105. {
  106. SkillFeaturesData skillFeaturesData = fxAILogicBasic.SkillFeaturesData;
  107. if (skillFeaturesData.isEnemy == SkillFeaturesData.isEnemy)
  108. {
  109. return;
  110. }
  111. int myRestrained = SkillFeaturesData.GetRestrained(skillFeaturesData.SkillFeaturesType);
  112. int targetRestrained = skillFeaturesData.GetRestrained(SkillFeaturesData.SkillFeaturesType);
  113. int c = myRestrained - targetRestrained;
  114. int myHp = SkillFeaturesData.hp;
  115. int targetHp = skillFeaturesData.hp;
  116. if (c < 0) //我被压制
  117. {
  118. myHp -= CombatCalculateTool.Instance.GetVlaueRatioForInt(myHp, 10 * (Mathf.Abs(c)));
  119. }
  120. else if (c > 0)
  121. {
  122. targetHp -= CombatCalculateTool.Instance.GetVlaueRatioForInt(targetHp, 10 * (Mathf.Abs(c)));
  123. }
  124. if (myHp > targetHp)
  125. {
  126. myHp -= targetHp;
  127. SkillFeaturesData.hp = myHp;
  128. fxAILogicBasic.PlayHit();
  129. fxAILogicBasic.Dispose();
  130. }
  131. else if (myHp < targetHp)
  132. {
  133. targetHp -= myHp;
  134. skillFeaturesData.hp = targetHp;
  135. Dispose();
  136. PlayHit();
  137. }
  138. else if (myHp == targetHp)
  139. {
  140. myHp = 0;
  141. fxAILogicBasic.PlayHit();
  142. fxAILogicBasic.Dispose();
  143. Dispose();
  144. PlayHit();
  145. }
  146. return;
  147. }
  148. else
  149. {
  150. HeroEntityMono heroEntityMono = collision.gameObject.GetComponent<HeroEntityMono>();
  151. TriggerHero(collision, heroEntityMono);
  152. }
  153. }
  154. protected void TriggerHero(Collider collision, HeroEntityMono heroEntityMono)
  155. {
  156. if (heroEntityMono == null)
  157. {
  158. return;
  159. }
  160. CombatHeroEntity target = heroEntityMono.combatHeroEntity;
  161. if (target.IsEnemy == CombatHeroEntity.IsEnemy || target is CombatMagicWeaponEntity)
  162. {
  163. return;
  164. }
  165. if (TimeLineEventParticleLogicBasic.TimeLineEventLogicGroup.groupName == null)
  166. {
  167. Dispose();
  168. return;
  169. }
  170. ITimeLineTriggerEvent timeLineTriggerEvent =
  171. TimeLineEventParticleLogicBasic.ITimeLineTriggerEntity as ITimeLineTriggerEvent;
  172. if (timeLineTriggerEvent != null)
  173. {
  174. timeLineTriggerEvent.TimeLineTrigger(TimeLineEventParticleLogicBasic.TimeLineEventLogicGroup.groupName,
  175. target.GetMainHotPoin<ILifetCycleHitPoint>(), this, triggerData);
  176. if (!string.IsNullOrEmpty(hitFxName))
  177. {
  178. FinishHit(collision.ClosestPoint(gameObject.transform.position), hitFxName);
  179. }
  180. AudioManager.Instance.PlayAudio(hitAudioName, false);
  181. if (!isPenetrate)
  182. {
  183. Dispose();
  184. }
  185. }
  186. }
  187. private void FinishHit(Vector3 pos, string hitFxName)
  188. {
  189. if (!string.IsNullOrEmpty(hitFxName))
  190. {
  191. CombatController.currActiveCombat.GameTimeLineParticleFactory.CreateParticle(hitFxName,
  192. pos, null, false, null, null);
  193. }
  194. }
  195. protected override void ProCombatUpdate(float time)
  196. {
  197. switch (parabolaCurveType)
  198. {
  199. case CurveType.Beeline:
  200. Beeline(time);
  201. break;
  202. case CurveType.DynamicCurve:
  203. DynamicCurve(time);
  204. break;
  205. case CurveType.CustomizeCurve:
  206. CustomizeCurve(time);
  207. break;
  208. }
  209. // if (Vector3.Distance(endPos, _currPos) < 0.5f)
  210. // {
  211. // Dispose();
  212. // }
  213. }
  214. private void Beeline(float time)
  215. {
  216. GetTargetPos();
  217. Vector3 dir = (endPos - _currPos).normalized;
  218. // dir = Vector3.Lerp(startDir, dir, dirLerpTime).normalized;
  219. // startDir= dir;
  220. Vector3 lasetPos = _currPos;
  221. _currPos += dir * speed * time;
  222. gameObject.transform.position = _currPos;
  223. gameObject.transform.rotation = Quaternion.LookRotation(dir);
  224. }
  225. private void CustomizeCurve(float time)
  226. {
  227. }
  228. private void DynamicCurve(float time)
  229. {
  230. currTime += _addTime * time;
  231. dirLerpTime += time * 4F;
  232. if (dirLerpTime > 1)
  233. {
  234. dirLerpTime = 1;
  235. }
  236. GetTargetPos();
  237. Vector3 dir = (endPos - _currPos).normalized;
  238. dir = Vector3.Lerp(startDir, dir, dirLerpTime).normalized;
  239. // startDir= dir;
  240. Vector3 lasetPos = _currPos;
  241. _currPos += dir * speed * time;
  242. gameObject.transform.position = _currPos;
  243. gameObject.transform.rotation = Quaternion.LookRotation(dir);
  244. }
  245. protected override void ProDispose()
  246. {
  247. if (UnRegister != null)
  248. {
  249. UnRegister.UnRegister();
  250. }
  251. UnRegister = null;
  252. }
  253. }
  254. }