BuffBasic.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. using System;
  2. using System.Collections.Generic;
  3. using CombatLibrary.CombatLibrary.CombatCore.CustomizeTimeLogic.FxLogic;
  4. using Excel2Json;
  5. using Fort23.Core;
  6. using Fort23.UTool;
  7. using UnityEngine;
  8. using UTool.CustomizeTimeLogic.FxLogic.TimeLineEventinterface;
  9. namespace GameLogic.Combat.Buff
  10. {
  11. public class BuffBasic : CObject
  12. {
  13. public CombatHeroEntity Source
  14. {
  15. get { return source; }
  16. }
  17. public CombatHeroEntity CombatHeroEntity
  18. {
  19. get { return combatHeroEntity; }
  20. }
  21. protected CombatHeroEntity combatHeroEntity;
  22. // public BuffInfo buffInf;
  23. protected CombatHeroEntity source;
  24. protected TriggerData _triggerData;
  25. public float _currTime;
  26. protected float _jianGe;
  27. public System.Action buffFinish;
  28. private List<BuffStackInfo> _buffStackInfos = new List<BuffStackInfo>();
  29. public BuffConfig BuffConfig;
  30. public float buffTime;
  31. public int count;
  32. public int buffCount
  33. {
  34. get { return _count; }
  35. }
  36. protected int _count;
  37. private float _time;
  38. private BuffInfo myBuffInfo;
  39. public void Init(CombatHeroEntity combatHeroEntity, CombatHeroEntity source, BuffInfo buffInfo)
  40. {
  41. myBuffInfo = null;
  42. _triggerData.Source = this;
  43. this.combatHeroEntity = combatHeroEntity;
  44. this.BuffConfig = buffInfo.BuffConfig;
  45. this.buffTime = buffInfo.buffTime;
  46. this.count = buffInfo.count;
  47. this.source = source;
  48. ProInit();
  49. AddBuffCount(source, buffInfo);
  50. }
  51. public int AddBuffCount(CombatHeroEntity source, BuffInfo buffInfo)
  52. {
  53. int ac = 0;
  54. if (buffInfo.BuffConfig.timeType == 1)
  55. {
  56. myBuffInfo = buffInfo;
  57. _currTime = 0;
  58. int c = buffCount + buffInfo.count;
  59. if (c > buffInfo.BuffConfig.overlayCount)
  60. {
  61. c = buffInfo.BuffConfig.overlayCount - buffCount;
  62. }
  63. else
  64. {
  65. c = buffInfo.count;
  66. }
  67. if (c <= 0)
  68. {
  69. return 0;
  70. }
  71. ac = c;
  72. _count += c;
  73. }
  74. else
  75. {
  76. int c = buffCount + buffInfo.count;
  77. if (c > buffInfo.BuffConfig.overlayCount)
  78. {
  79. c = buffInfo.BuffConfig.overlayCount - buffCount;
  80. }
  81. else
  82. {
  83. c = buffInfo.count;
  84. }
  85. if (c <= 0)
  86. {
  87. return 0;
  88. }
  89. ac = c;
  90. buffInfo.count = c;
  91. _count += c;
  92. BuffStackInfo buffStackInfo = CObjectPool.Instance.Fetch<BuffStackInfo>();
  93. buffStackInfo.BuffBasic = this;
  94. buffStackInfo.BuffInfo = buffInfo;
  95. buffStackInfo.count = c;
  96. _buffStackInfos.Add(buffStackInfo);
  97. }
  98. UpdateEffect();
  99. return ac;
  100. }
  101. protected virtual void ProInit()
  102. {
  103. }
  104. public override void ActiveObj()
  105. {
  106. }
  107. public void UpdateEffect()
  108. {
  109. ProUpdateEffect();
  110. }
  111. protected virtual void ProUpdateEffect()
  112. {
  113. }
  114. public void ReduceCount(int count)
  115. {
  116. if (BuffConfig.timeType == 1)
  117. {
  118. _count -= count;
  119. if (_count <= 0)
  120. {
  121. combatHeroEntity.BuffControl.RemoveBuff(this);
  122. return;
  123. }
  124. }
  125. else
  126. {
  127. while (count > 0)
  128. {
  129. if (_buffStackInfos.Count <= 0)
  130. {
  131. combatHeroEntity.BuffControl.RemoveBuff(this);
  132. return;
  133. }
  134. BuffStackInfo buffStackInfo = _buffStackInfos[0];
  135. if (buffStackInfo.count >= count)
  136. {
  137. buffStackInfo.count -= count;
  138. _count -= count;
  139. count = 0;
  140. if (buffStackInfo.count == 0)
  141. {
  142. RemoveBuffStackInfo(buffStackInfo);
  143. }
  144. }
  145. else
  146. {
  147. int c = buffStackInfo.count;
  148. count -= c;
  149. _count -= c;
  150. buffStackInfo.count = 0;
  151. RemoveBuffStackInfo(buffStackInfo);
  152. }
  153. }
  154. }
  155. UpdateEffect();
  156. }
  157. public TimeLineEventLogicGroupBasic ActivationTimeLineData(string groupName,
  158. BetterList<ILifetCycleHitPoint> currTarget = null,
  159. Vector3[] customizePos = null, System.Action finishCallBack = null, float startTime = default,
  160. object extraData = null, int indexCount = 0)
  161. {
  162. TimeLineEventLogicGroupBasic timeLineEventLogicGroup =
  163. source.combatHeroTimeLineControl
  164. .GetTimeLineEventLogicGroup<TimeLineEventLogicGroupBasic>(groupName, null);
  165. try
  166. {
  167. if (timeLineEventLogicGroup != null)
  168. {
  169. timeLineEventLogicGroup.extraData = extraData;
  170. timeLineEventLogicGroup.SetCombatInfo(combatHeroEntity, null, currTarget, _triggerData,
  171. customizePos, indexCount);
  172. timeLineEventLogicGroup.TimeLineUpdateEnd = finishCallBack;
  173. timeLineEventLogicGroup.timeLineTime = startTime;
  174. combatHeroEntity.combatHeroTimeLineControl.AddEventLogicGroup(timeLineEventLogicGroup);
  175. // currUseAllTimeLineLogic.Add(timeLineEventLogicGroup);
  176. }
  177. }
  178. catch (Exception e)
  179. {
  180. LogTool.Error(e);
  181. }
  182. return timeLineEventLogicGroup;
  183. }
  184. public override void DormancyObj()
  185. {
  186. buffFinish?.Invoke();
  187. buffFinish = null;
  188. _currTime = 0;
  189. ProDormancyObj();
  190. CObjectPool.Instance.Recycle(myBuffInfo);
  191. myBuffInfo = null;
  192. combatHeroEntity = null;
  193. }
  194. protected virtual void ProDormancyObj()
  195. {
  196. }
  197. public void Update(float t)
  198. {
  199. if (BuffConfig.timeType == 1)
  200. {
  201. _currTime += t;
  202. if (buffTime > 0 && _currTime > buffTime)
  203. {
  204. DelectBuff();
  205. return;
  206. }
  207. }
  208. else
  209. {
  210. for (int i = 0; i < _buffStackInfos.Count; i++)
  211. {
  212. BuffStackInfo buffStackInfo = _buffStackInfos[i];
  213. buffStackInfo.Update(t);
  214. }
  215. }
  216. if (combatHeroEntity == null)
  217. {
  218. return;
  219. }
  220. if (_jianGe > 0)
  221. {
  222. _time += t;
  223. if (_time >= _jianGe)
  224. {
  225. _time -= _jianGe;
  226. UpdateJumping();
  227. }
  228. }
  229. ProUpdate(t);
  230. }
  231. public void DelectBuff()
  232. {
  233. combatHeroEntity.BuffControl.RemoveBuff(this);
  234. }
  235. public void RemoveBuffStackInfo(BuffStackInfo buffStackInfo)
  236. {
  237. _buffStackInfos.Remove(buffStackInfo);
  238. _count -= buffStackInfo.count;
  239. CObjectPool.Instance.Recycle(buffStackInfo);
  240. if (_buffStackInfos.Count <= 0)
  241. {
  242. combatHeroEntity.BuffControl.RemoveBuff(this);
  243. return;
  244. }
  245. UpdateEffect();
  246. }
  247. protected virtual void UpdateJumping()
  248. {
  249. }
  250. protected virtual void ProUpdate(float t)
  251. {
  252. }
  253. }
  254. }