CombatMagicWeaponEntity.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using Animancer;
  2. using Common.Utility.CombatEvent;
  3. using Excel2Json;
  4. using Fort23.Core;
  5. using Fort23.UTool;
  6. using GameLogic.Combat.Buff;
  7. using GameLogic.Combat.CombatTool;
  8. using GameLogic.Combat.Hero.State;
  9. using GameLogic.Combat.Skill;
  10. using UnityEngine;
  11. using UnityEngine.AI;
  12. namespace GameLogic.Combat.Hero
  13. {
  14. /// <summary>
  15. /// 法宝对象
  16. /// </summary>
  17. public class CombatMagicWeaponEntity : CombatHeroEntity
  18. {
  19. /// <summary>
  20. /// 碰撞的target
  21. /// </summary>
  22. public CombatMagicWeaponEntity CollidingTarget;
  23. public int MagicWeaponCollisionId = -1;
  24. protected MagicWeaponConfig _magicWeaponConfig;
  25. public float cd = 2;
  26. public float HpBl
  27. {
  28. get { return _HpBl; }
  29. }
  30. private float _HpBl = 100;
  31. public int useIndex;
  32. /// <summary>
  33. /// 是否进入战斗状态
  34. /// </summary>
  35. public bool isCombatState;
  36. private MagicWeaponControl _magicWeaponControl;
  37. public MagicWeaponControl MagicWeaponControl
  38. {
  39. get { return _magicWeaponControl; }
  40. }
  41. private BetterList<SkillBasic> allSkill = new BetterList<SkillBasic>();
  42. public float MaxCd
  43. {
  44. get { return magicWeaponConfig.cd; }
  45. }
  46. private MagicWeaponConfig magicWeaponConfig;
  47. public void ReduceHp(float value)
  48. {
  49. _HpBl -= value;
  50. if (_HpBl <= 0)
  51. {
  52. HeroDieEventData heroDieEventData = HeroDieEventData.Create();
  53. heroDieEventData.combatHeroEntity = this;
  54. CombatEventManager.Instance.Dispatch(CombatEventType.MagicWeaponDie,
  55. heroDieEventData);
  56. CombatAIBasic.ChangeState(CombatHeroStateType.dile);
  57. }
  58. }
  59. public async CTask<CombatMagicWeaponEntity> Init(MagicWeaponControl magicWeaponControl,
  60. MagicWeaponConfig magicWeaponConfig,
  61. System.Action<CombatMagicWeaponEntity> callBack = null)
  62. {
  63. this.magicWeaponConfig = magicWeaponConfig;
  64. this._magicWeaponControl = magicWeaponControl;
  65. string modelName = magicWeaponConfig.model;
  66. cd = magicWeaponConfig.cd;
  67. // GameTimeLineParticleFactory
  68. CombatHeroGameObjectPool poolInterface =
  69. await GObjectPool.Instance.FetchAsync<CombatHeroGameObjectPool>(modelName + ".prefab", null);
  70. #if !COMBAT_SERVER
  71. if (poolInterface == null || poolInterface.own == null)
  72. {
  73. return null;
  74. }
  75. poolInterface.own.transform.position = Vector3.one;
  76. poolInterface.own.SetActive(false);
  77. combatHeroTimeLineControl = new CombatHeroTimeLineControl();
  78. combatHeroTimeLineControl.Init(this);
  79. AssetHandle assetHandle =
  80. await AssetBundleLoadManager.Instance.LoadAssetAsyncTask<TextAsset>(
  81. modelName + "_TD.txt");
  82. if (assetHandle != null)
  83. {
  84. TextAsset textAsset = assetHandle.AssetObject<TextAsset>();
  85. TimeLienData timeLienData = JsonManager.FromJson<TimeLienData>(textAsset.text);
  86. timeLienData.DeserializeData();
  87. assetHandle.Release();
  88. combatHeroTimeLineControl.AddTimeLienData(timeLienData);
  89. }
  90. combatHeroGameObject = new CombatHeroGameObject();
  91. combatHeroGameObject.Init(this, poolInterface);
  92. CombatHeroSkillControl = new CombatHeroSkillControlBasic();
  93. CombatHeroSkillControl.Init(this);
  94. if (magicWeaponConfig.skillID != null)
  95. {
  96. for (int i = 0; i < magicWeaponConfig.skillID.Length; i++)
  97. {
  98. int id = magicWeaponConfig.skillID[i] * 10 + 1;
  99. SkillConfig skillConfig = ConfigComponent.Instance.Get<SkillConfig>(id);
  100. CombatHeroSkillControl.AddSkill(skillConfig);
  101. }
  102. }
  103. if (CombatAIBasic == null)
  104. {
  105. CombatAIBasic = new MagicWeaponAi();
  106. }
  107. HeroEntityMono heroEntityMono = poolInterface.own.GetComponent<HeroEntityMono>();
  108. if (heroEntityMono == null)
  109. {
  110. heroEntityMono = poolInterface.own.AddComponent<HeroEntityMono>();
  111. }
  112. heroEntityMono.combatHeroEntity = this;
  113. CombatAIBasic.Init(this);
  114. // AnimancerComponent animancerComponent = poolInterface.own.GetComponentInChildren<AnimancerComponent>();
  115. combatHeroAnimtion = new CombatHeroAnimtion();
  116. poolInterface.own.SetActive(true);
  117. combatHeroAnimtion.Init(this);
  118. CombatAIBasic.ChangeState(CombatHeroStateType.XiuMian);
  119. #endif
  120. callBack?.Invoke(this);
  121. return this;
  122. }
  123. public override float GetAttSpeed()
  124. {
  125. return 1;
  126. }
  127. public void UseMagicWeapon()
  128. {
  129. if (cd > 0 || _magicWeaponControl.combatHeroEntity.CombatAIBasic.currFocusTarget == null)
  130. {
  131. return;
  132. }
  133. _HpBl = 100;
  134. cd = magicWeaponConfig.cd;
  135. CollidingTarget = null;
  136. _magicWeaponControl.UseMagicWeapon(this);
  137. }
  138. public override void Update(float t)
  139. {
  140. combatHeroTimeLineControl.Update(t);
  141. CombatAIBasic?.Update(t);
  142. CombatHeroSkillControl?.Update(t);
  143. if (CombatAIBasic.CurrState.GetType() == typeof(MagicWeapomDormancyState))
  144. {
  145. cd -= t;
  146. if (_magicWeaponControl.isAutoUse)
  147. {
  148. UseMagicWeapon();
  149. }
  150. }
  151. }
  152. }
  153. }