FxParabolaBulletLogic.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. [Header("释放碰撞到地面时结束")] public bool isTriggerGroundEnd;
  17. [Header("碰撞到地面时的特效")] public string GroundHitFxName;
  18. private Vector3 endPos;
  19. private Vector3 dir;
  20. public float maxDis = 20;
  21. protected float maxDisSpr;
  22. // private BesselPath _besselPath;
  23. private float _addTime;
  24. protected Vector3 startDir;
  25. private float dirLerpTime;
  26. protected override void ProInit()
  27. {
  28. maxDisSpr = maxDis * maxDis;
  29. UnRegister = gameObject.OnTriggerEnterEvent(this, OnTriggerEnterEvent);
  30. if (isUseCustomTargetEndPos)
  31. {
  32. endPos = TimeLineEventParticleLogicBasic.customizePos[
  33. customTargetEndPosIndex];
  34. }
  35. else
  36. {
  37. endPos = AttTarget.GetSpecialDotInfo("hitpos").GetWorlPos();
  38. // endPos = new Vector3(endPos.x, CurrPos.y, endPos.z);
  39. }
  40. Vector3 off = _currPos - CombatHeroEntity.GameObject.transform.position;
  41. startDir = CombatHeroEntity.GameObject.transform.TransformPoint(off +
  42. new Vector3(
  43. Mathf.Sign(Random.Range(-1, 1)),
  44. Random.Range(0.1f, 1f),
  45. Random.Range(0.1f, 5f)));
  46. startDir = (startDir - _currPos).normalized;
  47. dirLerpTime = 0;
  48. dir = (endPos - CurrPos).normalized;
  49. gameObject.transform.rotation = Quaternion.LookRotation(dir);
  50. }
  51. void TriggerGround()
  52. {
  53. ITimeLineTriggerEvent timeLineTriggerEvent =
  54. TimeLineEventParticleLogicBasic.ITimeLineTriggerEntity as ITimeLineTriggerEvent;
  55. FinishHit(new Vector3(_currPos.x, 0.5f, _currPos.z), GroundHitFxName);
  56. AudioManager.Instance.PlayAudio(hitAudioName, false);
  57. if (timeLineTriggerEvent != null)
  58. {
  59. timeLineTriggerEvent.TimeLineTriggerGround(
  60. TimeLineEventParticleLogicBasic.TimeLineEventLogicGroup.groupName,
  61. this, triggerData);
  62. }
  63. AudioManager.Instance.PlayAudio(hitAudioName, false);
  64. Dispose();
  65. }
  66. protected void GetTargetPos()
  67. {
  68. if (isUseCustomTargetEndPos)
  69. {
  70. endPos = TimeLineEventParticleLogicBasic.customizePos[
  71. customTargetEndPosIndex];
  72. }
  73. else
  74. {
  75. endPos = AttTarget.GetSpecialDotInfo("hitpos").GetWorlPos();
  76. // endPos = new Vector3(endPos.x, CurrPos.y, endPos.z);
  77. }
  78. }
  79. protected void OnTriggerEnterEvent(Collider collision, ITriggerEntity triggerEntity)
  80. {
  81. if (isTriggerGroundEnd)
  82. {
  83. if (collision.gameObject.CompareTag("dimian"))
  84. {
  85. TriggerGround();
  86. return;
  87. }
  88. }
  89. FxAILogicBasic fxAILogicBasic = triggerEntity as FxAILogicBasic;
  90. if (fxAILogicBasic != null) //击中其他的功法
  91. {
  92. SkillFeaturesData skillFeaturesData = fxAILogicBasic.SkillFeaturesData;
  93. if (skillFeaturesData.isEnemy == SkillFeaturesData.isEnemy)
  94. {
  95. return;
  96. }
  97. int myRestrained = SkillFeaturesData.GetRestrained(skillFeaturesData.SkillFeaturesType);
  98. int targetRestrained = skillFeaturesData.GetRestrained(SkillFeaturesData.SkillFeaturesType);
  99. int c = myRestrained - targetRestrained;
  100. int myHp = SkillFeaturesData.hp;
  101. int targetHp = skillFeaturesData.hp;
  102. if (c < 0) //我被压制
  103. {
  104. myHp -= CombatCalculateTool.Instance.GetVlaueRatioForInt(myHp, 10 * (Mathf.Abs(c)));
  105. }
  106. else if (c > 0)
  107. {
  108. targetHp -= CombatCalculateTool.Instance.GetVlaueRatioForInt(targetHp, 10 * (Mathf.Abs(c)));
  109. }
  110. if (myHp > targetHp)
  111. {
  112. myHp -= targetHp;
  113. SkillFeaturesData.hp = myHp;
  114. fxAILogicBasic.PlayHit();
  115. fxAILogicBasic.Dispose();
  116. }
  117. else if (myHp < targetHp)
  118. {
  119. targetHp -= myHp;
  120. skillFeaturesData.hp = targetHp;
  121. Dispose();
  122. PlayHit();
  123. }
  124. else if (myHp == targetHp)
  125. {
  126. myHp = 0;
  127. fxAILogicBasic.PlayHit();
  128. fxAILogicBasic.Dispose();
  129. Dispose();
  130. PlayHit();
  131. }
  132. return;
  133. }
  134. else
  135. {
  136. HeroEntityMono heroEntityMono = collision.gameObject.GetComponent<HeroEntityMono>();
  137. TriggerHero(collision, heroEntityMono);
  138. }
  139. }
  140. protected void TriggerHero(Collider collision, HeroEntityMono heroEntityMono)
  141. {
  142. if (heroEntityMono == null)
  143. {
  144. return;
  145. }
  146. CombatHeroEntity target = heroEntityMono.combatHeroEntity;
  147. if (target.IsEnemy == CombatHeroEntity.IsEnemy||target is CombatMagicWeaponEntity)
  148. {
  149. return;
  150. }
  151. if (TimeLineEventParticleLogicBasic.TimeLineEventLogicGroup.groupName == null)
  152. {
  153. Dispose();
  154. return;
  155. }
  156. ITimeLineTriggerEvent timeLineTriggerEvent =
  157. TimeLineEventParticleLogicBasic.ITimeLineTriggerEntity as ITimeLineTriggerEvent;
  158. if (timeLineTriggerEvent != null)
  159. {
  160. timeLineTriggerEvent.TimeLineTrigger(TimeLineEventParticleLogicBasic.TimeLineEventLogicGroup.groupName,
  161. target.GetMainHotPoin<ILifetCycleHitPoint>(), this, triggerData);
  162. if (!string.IsNullOrEmpty(hitFxName))
  163. {
  164. FinishHit(collision.ClosestPoint(gameObject.transform.position), hitFxName);
  165. }
  166. AudioManager.Instance.PlayAudio(hitAudioName, false);
  167. if (!isPenetrate)
  168. {
  169. Dispose();
  170. }
  171. }
  172. }
  173. private void FinishHit(Vector3 pos, string hitFxName)
  174. {
  175. if (!string.IsNullOrEmpty(hitFxName))
  176. {
  177. CombatController.currActiveCombat.GameTimeLineParticleFactory.CreateParticle(hitFxName,
  178. pos, null, false, null, null);
  179. }
  180. }
  181. protected override void ProCombatUpdate(float time)
  182. {
  183. currTime += _addTime * time;
  184. dirLerpTime += time * 4F;
  185. if (dirLerpTime > 1)
  186. {
  187. dirLerpTime = 1;
  188. }
  189. GetTargetPos();
  190. Vector3 dir = (endPos - _currPos).normalized;
  191. dir = Vector3.Lerp(startDir, dir, dirLerpTime).normalized;
  192. // startDir= dir;
  193. Vector3 lasetPos = _currPos;
  194. _currPos += dir * speed * time;
  195. gameObject.transform.position = _currPos;
  196. gameObject.transform.rotation = Quaternion.LookRotation(dir);
  197. // if (Vector3.Distance(endPos, _currPos) < 0.5f)
  198. // {
  199. // Dispose();
  200. // }
  201. }
  202. protected override void ProDispose()
  203. {
  204. if (UnRegister != null)
  205. {
  206. UnRegister.UnRegister();
  207. }
  208. UnRegister = null;
  209. }
  210. }
  211. }