XmdsInstanceSummonUnit.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using CommonAI.Zone;
  2. using CommonAI.Zone.Helper;
  3. using CommonAI.Zone.Instance;
  4. using CommonLang;
  5. namespace XmdsCommonServer.Plugin.Units
  6. {
  7. /// <summary>
  8. /// 召唤单位,目前召唤单位AI与宠物相同,先继承自宠物.
  9. /// </summary>
  10. public class XmdsInstanceSummonUnit : XmdsInstancePet //InstanceGuard, ViewTrigger.ViewTriggerListener, ISummonedUnit
  11. {
  12. public override bool IntersectObj { get { return false; } }
  13. public XmdsInstanceSummonUnit(InstanceZone zone, UnitInfo info, string name, int force, int level)
  14. : base(zone, info, name, force, level)
  15. {
  16. }
  17. public InstanceUnit BindUnit { get; set; }
  18. protected override void onAdded(bool pointLv)
  19. {
  20. base.onAdded(pointLv);
  21. if(this.Info.SumType == CommonAI.Data.SummonType.attack)
  22. {
  23. base.SetFollowMode(XmdsCommon.Plugin.XmdsPetConifg.XmdsPetFollowMode.ActiveAtk);
  24. }
  25. }
  26. public override bool IsMonster { get { return true; } }
  27. override protected void onUpdate(bool slowRefresh)
  28. {
  29. base.onUpdate(slowRefresh);
  30. if (BindUnit != null)
  31. {
  32. if (X != BindUnit.X || Y != BindUnit.Y)
  33. {
  34. setPos(BindUnit.X, BindUnit.Y, false);
  35. }
  36. }
  37. if ((PassTimeMS >= Info.LifeTimeMS) || (SummonerUnit != null && !SummonerUnit.IsActive))
  38. {
  39. kill(null, false);
  40. }
  41. }
  42. public override void InitSkills(LaunchSkill baseSkill, params LaunchSkill[] skills)
  43. {
  44. if (this.Virtual == null ||
  45. (this.Virtual as XmdsVirtual).IsFinishSkillInit() == false)
  46. {
  47. return;
  48. }
  49. base.InitSkills(baseSkill, skills);
  50. }
  51. // 各种填坑,宠物机制被改的贼特殊,贼恶心
  52. protected override bool IsCanAttack(InstanceUnit unit) { return true; }
  53. public override bool IsPet { get { return false; } }
  54. public override bool IsPlayerUnit { get { return false; } }
  55. protected override bool IsPetCanAttack() { return true; }
  56. protected override void followMasterChangeSpeed(float speedChag) { }
  57. protected override bool CheckFollowMaster()
  58. {
  59. if(this.Info.SumType == CommonAI.Data.SummonType.MoveToMaster || this.Info.SumType == CommonAI.Data.SummonType.AwaitMaster)
  60. {
  61. return false;
  62. }
  63. return true;
  64. }
  65. public override bool checkOutOffBattle()
  66. {
  67. if (CurrentState is StateIdle)
  68. {
  69. return true;
  70. }
  71. return false;
  72. }
  73. protected override void Disposing()
  74. {
  75. BindUnit = null;
  76. base.Disposing();
  77. }
  78. protected override bool TryAtkSelfEnemy()
  79. {
  80. bool ret = false;
  81. using (var list = ListObjectPool<InstanceUnit>.AllocAutoRelease())
  82. {
  83. //找到离自己最近的单位攻击.
  84. Parent.getObjectsRoundRange<InstanceUnit>(Collider.Object_BlockBody_TouchRound, X, Y, Info.GuardRange, list, AoiStatus);
  85. DoAndRemoveCollection.UpdateAndRemove<InstanceUnit>(list, (InstanceUnit u) =>
  86. {
  87. return !u.IsActive;
  88. });
  89. if (list != null && list.Count > 0)
  90. {
  91. list.Sort((a, b) =>
  92. {
  93. //选距离最近的单位.
  94. float da = CMath.getDistanceSquare(a.X, a.Y, this.X, this.Y);
  95. float db = CMath.getDistanceSquare(b.X, b.Y, this.X, this.Y);
  96. return (int)(da - db);
  97. });
  98. foreach (SkillState skill in SkillStatus)
  99. {
  100. if (skill.LaunchSkill.AutoLaunch && skill.TryLaunch())
  101. {
  102. foreach (InstanceUnit u in list)
  103. {
  104. if (this.IsCanAttack(u) && Parent.IsAttackable(this, u, skill.Data.ExpectTarget, AttackReason.Attack, skill.Data))
  105. {
  106. //是否在守卫范围内.
  107. if (CheckInAtkRange(u, this.Info.GuardRange + skill.Data.AttackRange))
  108. {
  109. //检测是否有可释放技能//
  110. if (tryAutoLaunch(skill, u))
  111. {
  112. return true;
  113. }
  114. }
  115. }
  116. }
  117. }
  118. }
  119. }
  120. }
  121. return ret;
  122. }
  123. }
  124. }