XmdsBuff_LimitingDamage.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. 
  2. using CommonAI.Data;
  3. using CommonAI.Zone.Formula;
  4. using CommonAI.Zone.Instance;
  5. using System;
  6. using XmdsCommon.Plugin;
  7. using XmdsCommonServer.Plugin;
  8. using XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills;
  9. namespace XmdsCommonSkill.Plugin.Buffs
  10. {
  11. /// <summary>
  12. /// 护盾BUFF.限制单位每次最多受到的伤害.
  13. /// </summary>
  14. public class XmdsBuff_Shield_LimitingDamage : XmdsBuffBase
  15. {
  16. /// <summary>
  17. /// 吸收伤害总量.
  18. /// </summary>
  19. public int AbsorbDamageSum = 0;
  20. /// <summary>
  21. /// 是否吸收过量伤害.
  22. /// </summary>
  23. public bool AbsorbOverFlowDamage = true;
  24. private int mLimitingDamage = 1;
  25. /// <summary>
  26. /// 单次攻击最多可受的伤害.
  27. /// </summary>
  28. public int LimitingDamage
  29. {
  30. get { return mLimitingDamage; }
  31. set { mLimitingDamage = Math.Max(1, value); }
  32. }
  33. private int mHandleUUID = 0;
  34. public override int GetAbilityID()
  35. {
  36. return (int)XmdsCommon.Plugin.XmdsBuffProperties.XmdsBuffAbility.SHIELD_LimitingDamage;
  37. }
  38. public override void CopyTo(UnitBuff other)
  39. {
  40. var ret = other as XmdsBuff_Shield_LimitingDamage;
  41. ret.AbsorbDamageSum = this.AbsorbDamageSum;
  42. ret.AbsorbOverFlowDamage = this.AbsorbOverFlowDamage;
  43. ret.LimitingDamage = this.LimitingDamage;
  44. base.CopyTo(other);
  45. }
  46. protected override void OnBuffBegin(XmdsCommonServer.Plugin.XmdsVirtual hitter, XmdsCommonServer.Plugin.XmdsVirtual attacker, InstanceUnit.BuffState state)
  47. {
  48. //注册监听.
  49. mHandleUUID = hitter.RegistOnHitDamage(OnHandleHitDmage, null);
  50. XmdsVirtual.FormatLog("BuffBegin : 单位【{0}】增加限制伤害护盾.", hitter.mProp.ServerData.BaseInfo.name);
  51. }
  52. protected override void OnBuffEnd(XmdsCommonServer.Plugin.XmdsVirtual hitter, InstanceUnit.BuffState state, bool replace)
  53. {
  54. //取消监听.
  55. hitter.UnRegistOnHitDamage(mHandleUUID);
  56. XmdsVirtual.FormatLog("BuffBegin : 单位【{0}】失去限制伤害护盾.", hitter.mProp.ServerData.BaseInfo.name);
  57. }
  58. //单位被攻击时.伤害吸收计算.
  59. private float OnHandleHitDmage(float damage, XmdsVirtual hitted, XmdsVirtual attacker, AttackSource source,
  60. ref XmdsVirtual.AtkResult result, DamageType damageType, GameSkill skill, ref bool isEndDispatch)
  61. {
  62. int ret = (int)damage;
  63. //damage > 0是伤害,damage < 0是加血机制.
  64. if (damage > 0 && AbsorbDamageSum > 0)
  65. {
  66. //if (ret > LimitingDamage)
  67. //{
  68. ret = LimitingDamage;
  69. //}
  70. hitted.SendBattleHintNumberB2C(ret, XmdsVirtual.UnitHitEventState.Normal);
  71. AbsorbDamageSum -= ret;
  72. AbsorbDamageSum = Math.Max(0, AbsorbDamageSum);
  73. if (AbsorbDamageSum <= 0)
  74. {
  75. //破盾.
  76. hitted.mUnit.removeBuff(BindBuffID);
  77. }
  78. }
  79. return 0;
  80. }
  81. }
  82. }