InstanceTriggerUnit.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using CommonAI.RTS; using CommonLang.Vector;
  2. using CommonAI.Zone.Helper;
  3. using CommonLang;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. namespace CommonAI.Zone.Instance
  9. {
  10. //--------------------------------------------------------------------------------------------------------
  11. /// <summary>
  12. /// 场景内机关
  13. /// </summary>
  14. public class InstanceTriggerUnit : InstanceUnit
  15. {
  16. private Vector2 target = new Vector2();
  17. public InstanceTriggerUnit(InstanceZone zone, UnitInfo info, string name, int force, int level)
  18. : base(zone, info, name, force, level)
  19. {
  20. }
  21. public override bool IsActive { get { return false; } }
  22. public override bool IsAttackable { get { return false; } }
  23. public override bool IntersectMap { get { return false; } }
  24. public override bool IntersectObj { get { return false; } }
  25. public override bool Moveable { get { return false; } }
  26. override protected void onUpdate(bool slowRefresh)
  27. {
  28. base.onUpdate(slowRefresh);
  29. this.target.SetX(X);
  30. this.target.SetY(Y);
  31. if (!IsPaused && !IsNoneSkill)
  32. {
  33. if (CurrentState is StateIdle)
  34. {
  35. if (!doSomething2())
  36. {
  37. launchRandomSkillForAll(new InstanceUnit.LaunchSkillParam(0, target));
  38. }
  39. }
  40. }
  41. }
  42. private bool doSomething2()
  43. {
  44. if (Info.GuardRange > 0)
  45. {
  46. using (var list = ListObjectPool<InstanceUnit>.AllocAutoRelease())
  47. {
  48. //随机找个目标施法//
  49. Parent.getObjectsRoundRange<InstanceUnit>(Collider.Object_Pos_IncludeInRound, X, Y, Info.GuardRange, list , this.AoiStatus);
  50. DoAndRemoveCollection.UpdateAndRemove<InstanceUnit>(list, (InstanceUnit u) =>
  51. {
  52. return !u.IsActive;
  53. });
  54. CUtils.RandomList(Parent.RandomN, list);
  55. foreach (SkillState skill in SkillStatus)
  56. {
  57. if (skill.TryLaunch())
  58. {
  59. foreach (InstanceUnit u in list)
  60. {
  61. if (Parent.IsAttackable(this, u, skill.Data.ExpectTarget, AttackReason.Look, Info))
  62. {
  63. //检测是否有可释放技能//
  64. if (tryAutoLaunch(skill, u))
  65. {
  66. return true;
  67. }
  68. }
  69. }
  70. }
  71. }
  72. }
  73. }
  74. return false;
  75. }
  76. private bool tryAutoLaunch(SkillState st, InstanceUnit target)
  77. {
  78. if (st != null)
  79. {
  80. if (launchSkill(st.ID, new LaunchSkillParam(target.ID, new Vector2(target.X, target.Y), false)) != null)
  81. {
  82. return true;
  83. }
  84. }
  85. return false;
  86. }
  87. }
  88. }