Other_100003.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using CommonAI.Zone.Helper;
  2. using CommonAI.Zone.Instance;
  3. using XmdsCommonServer.Plugin;
  4. using XmdsCommonServer.XLS.Data;
  5. using XmdsCommonSkill.Plugin.Buffs;
  6. using System;
  7. using static CommonAI.Zone.Instance.InstanceUnit;
  8. using XmdsCommon.Plugin;
  9. using CommonAI.Zone;
  10. using XmdsCommonServer.Plugin.Units;
  11. using CommonAI.Zone.Formula;
  12. using XmdsCommonSkill.Plugin.Skills;
  13. using XmdsCommonServer.Plugin.XmdsSkillTemplate.DamageCalculator;
  14. using XmdsCommonSkill.Plugin.Skills.Magic;
  15. using CommonLang;
  16. using CommonAI.Data;
  17. namespace XmdsCommonSkill.Plugin.PassiveSkills.Magic
  18. {
  19. /// <summary>
  20. /// 防御塔被动
  21. /// 1. 受伤机制, 2. 攻击机制
  22. /// </summary>
  23. public class Other_100003 : XmdsPassiveSkillBase
  24. {
  25. /// 技能ID.
  26. public static readonly int ID = 100003;
  27. public static readonly float SoliderAtkRange = 6.0f;
  28. private XmdsVirtual mOwner = null;
  29. private int mUUID_1 = 0;
  30. private int mUUID_2 = 0;
  31. public override int SkillID { get { return ID; } }
  32. protected override void OnInit(GameSkill skillInfo, XmdsVirtual owner)
  33. {
  34. this.mOwner = owner;
  35. mUUID_1 = owner.RegistOnHitDamage(OnHandleHitDmage, skillInfo, true);
  36. mUUID_2 = owner.RegistOnHitOther(OnHandleOnHitOther, skillInfo, true);
  37. }
  38. //受到攻击
  39. private float OnHandleHitDmage(float damage, XmdsVirtual hitted, XmdsVirtual attacker, AttackSource source,
  40. ref XmdsVirtual.AtkResult result, DamageType damageType, GameSkill skill, ref bool isEndDispatch)
  41. {
  42. //队伍范围内找友军
  43. int soldiersCount = 0;
  44. using (var list = ListObjectPool<InstanceUnit>.AllocAutoRelease())
  45. {
  46. mOwner.mUnit.Parent.getObjectsRoundRange<InstanceUnit>(
  47. (obj, dx, dy, dr) =>
  48. {
  49. var u = obj as InstanceUnit;
  50. if (u.Virtual is XmdsVirtual_Monster && CMath.includeRoundPoint(dx, dy, dr, u.X, u.Y))
  51. {
  52. //己方单位.
  53. if (mOwner.mUnit.Force != u.Force)
  54. {
  55. soldiersCount++;
  56. }
  57. }
  58. return true;
  59. },
  60. mOwner.mUnit.X,
  61. mOwner.mUnit.Y,
  62. SoliderAtkRange,
  63. list, mOwner.mUnit.AoiStatus);
  64. }
  65. //有小兵,伤害不衰减,最大1/10防御塔最大血量
  66. if (soldiersCount > 0)
  67. {
  68. return Math.Min(damage, mOwner.mUnit.MaxHP / 10);
  69. }
  70. //没有小兵,伤害衰减10倍,最大1/10防御塔最大血量
  71. return Math.Min(damage / 100, mOwner.mUnit.MaxHP / 10);
  72. }
  73. //单位攻击
  74. private float OnHandleOnHitOther(float damage, XmdsVirtual hitter, XmdsVirtual attacker, AttackSource source,
  75. ref XmdsVirtual.AtkResult result, DamageType damageType, GameSkill skill, ref bool isEndDispatch)
  76. {
  77. if (hitter is XmdsVirtual_Player)
  78. {
  79. damage = Math.Max(damage, hitter.mUnit.MaxHP/10);
  80. }
  81. return damage;
  82. }
  83. protected override void OnDispose(XmdsVirtual owner)
  84. {
  85. owner.UnRegistOnHitDamage(mUUID_1);
  86. owner.UnRegistOnHitOther(mUUID_2);
  87. }
  88. }
  89. }