ElementAddDebuff.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using XGame.Database;
  2. using XGame.Framework;
  3. namespace FL.Battle.Buffs
  4. {
  5. /// <summary>
  6. /// 元素易伤debuff
  7. /// </summary>
  8. public class ElementAddDebuff : Buff
  9. {
  10. private int _autoTickLayer = 3;
  11. private int _elementTickLayer = 5;
  12. //private EElementType _elementType;
  13. protected override void OnInited()
  14. {
  15. //_elementType = (EElementType)(Table.BuffType / 10 % 10); // BuffType的十位数为元素类型
  16. Assert.IsTrue((Table.BuffType / 10 % 10) == (int)ElementType, $"元素易伤配置错误. BuffType:{Table.BuffType} ElementType:{ElementType}");
  17. _autoTickLayer = Table.BuffTypeNum[2];
  18. _elementTickLayer = Table.BuffTypeNum[4];
  19. }
  20. protected override void OnDispose()
  21. {
  22. }
  23. public bool IsReachLayer3()
  24. {
  25. return Layers >= _autoTickLayer;
  26. }
  27. /// <summary>
  28. /// 是否达到3层元素易伤条件
  29. /// AddBuff时判定
  30. /// </summary>
  31. /// <param name="attacker"></param>
  32. /// <returns></returns>
  33. public bool TryTickLayer3(ICombatCalculation attacker)
  34. {
  35. if (Layers < _autoTickLayer) return false;
  36. if (Layers == _autoTickLayer)
  37. {
  38. var buffOrSkillId = Table.BuffTypeNum[3];
  39. if (Table.BuffType == (int)EBuffType.ElementAddPoison)
  40. {
  41. var calculation = Context.Calculation.GetSkillTrigger(buffOrSkillId, attacker);
  42. calculation?.TickSkill(buffOrSkillId, Context.Entity.EntityId);
  43. }
  44. else
  45. {
  46. var calculation = Context.Calculation.GetBuffTrigger(buffOrSkillId, attacker);
  47. calculation?.TickBuff(buffOrSkillId);
  48. }
  49. }
  50. return true;
  51. }
  52. /// <summary>
  53. /// 是否达到5层元素易伤条件
  54. /// 攻击生效时判定
  55. /// </summary>
  56. /// <param name="elementType"></param>
  57. /// <returns></returns>
  58. public bool IsReachLayer5(EElementType elementType)
  59. {
  60. return elementType == ElementType && _elementTickLayer == Layers;
  61. }
  62. public bool TryTickBuff(int damage, EElementType elementType, ICombatCalculation attacker)
  63. {
  64. if (elementType == EElementType.None)
  65. return false;
  66. var isReach = IsReachLayer5(elementType);
  67. var isSkill = false;
  68. var buffOrSkillId = isReach ? Table.BuffTypeNum[5] : Table.BuffTypeNum[0];
  69. var probability = isReach ? TableUtils.Multiple : Table.BuffTypeNum[1];
  70. var addLayer = 1;
  71. switch (BuffType)
  72. {
  73. case EBuffType.ElementAddFire:
  74. case EBuffType.ElementAddWind:
  75. {
  76. isSkill = isReach;
  77. }
  78. break;
  79. case EBuffType.ElementAddThunder:
  80. {
  81. isSkill = true;
  82. }
  83. break;
  84. case EBuffType.ElementAddIce:
  85. {
  86. if (!isReach)
  87. return false;
  88. // TODO 给主角加冰盾buff,
  89. //probability = 0;
  90. }
  91. break;
  92. case EBuffType.ElementAddPoison:
  93. {
  94. addLayer = isReach ? Table.BuffTypeNum[5] : Layers;
  95. buffOrSkillId = Table.BuffTypeNum[0];
  96. }
  97. break;
  98. }
  99. if (isSkill)
  100. {
  101. var calculation = Context.Calculation.GetSkillTrigger(buffOrSkillId, attacker);
  102. calculation?.TickSkill(buffOrSkillId, Context.Entity.EntityId, probability);
  103. }
  104. else
  105. {
  106. var calculation = Context.Calculation.GetBuffTrigger(buffOrSkillId, attacker);
  107. calculation?.TickBuff(buffOrSkillId, probability, addLayer, damage);
  108. }
  109. if (isReach)
  110. {
  111. Listener?.OnCompleted(TableId);
  112. }
  113. return true;
  114. }
  115. }
  116. }