XmdsBuff_Event_OnHitDamage.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using CommonAI.Data;
  2. using CommonAI.Zone;
  3. using CommonAI.Zone.Formula;
  4. using CommonAI.Zone.Instance;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using XmdsCommon.Plugin;
  10. using XmdsCommonServer.Plugin;
  11. using XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills;
  12. namespace XmdsCommonSkill.Plugin.Buffs
  13. {
  14. /// <summary>
  15. /// 单位收到伤害回调.
  16. /// </summary>
  17. public class XmdsBuff_Event_OnHitDamage : XmdsBuffBase
  18. {
  19. private int mHandleUUID = 0;
  20. //绑定的技能信息
  21. public GameSkill bindSkill = null;
  22. public XmdsCommonServer.Plugin.XmdsSkillTemplate.Skills.IOnHit OnHitDamageEvent;
  23. public override int GetAbilityID()
  24. {
  25. return (int)XmdsBuffProperties.XmdsBuffAbility.Event_OnHitDamageEvent;
  26. }
  27. public override void CopyTo(UnitBuff other)
  28. {
  29. var ret = other as XmdsBuff_Event_OnHitDamage;
  30. ret.bindSkill = this.bindSkill;
  31. ret.OnHitDamageEvent = this.OnHitDamageEvent;
  32. base.CopyTo(other);
  33. }
  34. protected override void OnBindTemplate(ref BuffTemplate buffTemplate)
  35. {
  36. //关联性BUFF必须在施放者死亡后清除.
  37. buffTemplate.IsRemoveOnSenderRemoved = true;
  38. base.OnBindTemplate(ref buffTemplate);
  39. }
  40. protected override void OnBuffBegin(XmdsCommonServer.Plugin.XmdsVirtual hitter, XmdsCommonServer.Plugin.XmdsVirtual attacker, InstanceUnit.BuffState state)
  41. {
  42. //注册监听.
  43. mHandleUUID = hitter.RegistOnHitDamage(OnHandleHitDmage, null);
  44. XmdsVirtual.FormatLog("BuffBegin : 单位【{0}】增加OnHandleHitDmage事件监听.", hitter.mProp.ServerData.BaseInfo.name);
  45. }
  46. protected override void OnBuffEnd(XmdsCommonServer.Plugin.XmdsVirtual hitter, InstanceUnit.BuffState state, bool replace)
  47. {
  48. //取消监听.
  49. hitter.UnRegistOnHitDamage(mHandleUUID);
  50. XmdsVirtual.FormatLog("BuffBegin : 单位【{0}】去除OnHandleHitDmage事件监听.", hitter.mProp.ServerData.BaseInfo.name);
  51. }
  52. private float OnHandleHitDmage(float damage, XmdsVirtual hitted, XmdsVirtual attacker, AttackSource source,
  53. ref XmdsVirtual.AtkResult result, DamageType damageType, GameSkill skill, ref bool isEndDispatch)
  54. {
  55. if (OnHitDamageEvent != null)
  56. {
  57. OnHitDamageEvent.Invoke(damage, hitted, attacker, source, ref result,
  58. damageType, bindSkill, ref isEndDispatch);
  59. }
  60. return damage;
  61. }
  62. protected override void OnDispose()
  63. {
  64. //OnHitDamageEvent = null;
  65. base.OnDispose();
  66. }
  67. }
  68. }