DotDebuff.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using UnityEngine;
  2. using XGame.Database;
  3. using XGame.Framework.Time;
  4. namespace FL.Battle.Buffs
  5. {
  6. public class DotDebuff : Buff
  7. {
  8. /// <summary>
  9. /// buff事件触发定时器
  10. /// dot类型使用
  11. /// </summary>
  12. private ITimer _tickTimer;
  13. protected override void OnInited()
  14. {
  15. _tickTimer = Context.Time.AddLooperTimer(Table.BuffTypeNum[1], OnBuffTick);
  16. }
  17. protected override void OnDispose()
  18. {
  19. _tickTimer?.Cancel();
  20. _tickTimer = null;
  21. }
  22. private void OnBuffTick(int times)
  23. {
  24. // 已经死亡
  25. if (Context.Entity.IsDead)
  26. return;
  27. var damage = Mathf.RoundToInt(Layers * Table.BuffTypeNum[0].ToRealFloat() * Context.Entity.Attr.HpLimit);
  28. Context.Calculation.Damage(-damage, ElementType);
  29. //Log.Debug($"OnBuffTick EntityId:{Context.Entity.EntityId} BuffId:{buff.TableId} Overlay:{buff.Overlays} Damage:{damage}");
  30. }
  31. public bool TryTickLayer5()
  32. {
  33. // 毒的5层直接引爆伤害
  34. if (ElementType != EElementType.Poison || Layers < LayerLimit)
  35. return false;
  36. //伤害:dot总跳数*层数*单层伤害值
  37. var count = Duration / Table.BuffTypeNum[1];
  38. var damage = Mathf.RoundToInt(count * Layers * Table.BuffTypeNum[0].ToRealFloat() * Context.Entity.Attr.HpLimit);
  39. Context.Calculation.Damage(-damage, ElementType);
  40. Listener?.OnCompleted(TableId);
  41. return true;
  42. }
  43. }
  44. }