XmdsInstanceNPC.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using CommonAI.RTS;
  2. using CommonAI.Zone;
  3. using CommonAI.Zone.Formula;
  4. using CommonAI.Zone.Helper;
  5. using CommonAI.Zone.Instance;
  6. using CommonLang;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. namespace XmdsCommonServer.Plugin.Units
  12. {
  13. public class XmdsInstanceNPC : InstanceGuard
  14. {
  15. private bool mIsBattleable;
  16. public override bool IsNature { get { return !this.mIsBattleable; } }
  17. public override bool IsActive { get { return this.mIsBattleable; } }
  18. public override bool IsAttackable { get { return this.mIsBattleable; } }
  19. private float mGuardRangeLimit;
  20. private float mGuardRange;
  21. public XmdsInstanceNPC(InstanceZone zone, UnitInfo info, string name, int force, int level)
  22. : base(zone, info, name, force, level)
  23. {
  24. //该类型,单位无法被攻击.
  25. this.mIsBattleable = info.UType != UnitInfo.UnitType.TYPE_NEUTRALITY && info.UType != UnitInfo.UnitType.TYPE_NPC;
  26. //阵营为0无法被攻击.
  27. if (force == 0)
  28. {
  29. this.mIsBattleable = false;
  30. }
  31. mGuardRangeLimit = info.GuardRangeLimit;
  32. mGuardRange = info.GuardRange;
  33. }
  34. protected override void updateBackToOrgin()
  35. {
  36. if (mBackToPosition != null)
  37. {
  38. if (mBackToPosition.IsDone)
  39. {
  40. mBackToPosition = null;
  41. }
  42. }
  43. if (mOrginPosition != null && mGuardRangeLimit > mGuardRange)
  44. {
  45. //if (mCheckInGuardLimit.Update(Parent.UpdateIntervalMS))
  46. if (mNextCheckGuardLimit != null && mNextCheckGuardLimit.IsTrigger())
  47. {
  48. if (!CMath.includeRoundPoint(X, Y, mGuardRangeLimit, mOrginPosition.X, mOrginPosition.Y))
  49. {
  50. backToOrgin();
  51. }
  52. else if (mTracingTarget != null)
  53. {
  54. if (!mTracingTarget.IsActive || !CMath.intersectRound(
  55. X, Y, mGuardRangeLimit,
  56. mTracingTarget.TargetUnit.X,
  57. mTracingTarget.TargetUnit.Y,
  58. mTracingTarget.TargetUnit.BodyHitSize))
  59. {
  60. backToOrgin();
  61. return;
  62. }
  63. }
  64. }
  65. }
  66. }
  67. public void SetGuardRange(float r)
  68. {
  69. if (mViewTrigger is ViewTriggerRoundBody)
  70. {
  71. mGuardRange = r;
  72. (mViewTrigger as ViewTriggerRoundBody).SetLookRange(r);
  73. }
  74. }
  75. protected override void onNewStateBeginChange(State old_state, ref State new_state)
  76. {
  77. if (new_state is StateBackToPosition)
  78. {
  79. //回血.
  80. this.AddHP(this.MaxHP, null);
  81. this.AddMP(this.MaxMP, null);
  82. this.Virtual.StartRecoverMP(true);
  83. //去BUFF.
  84. this.clearBuffs();
  85. }
  86. base.onNewStateBeginChange(old_state, ref new_state);
  87. }
  88. public override void InitSkills(LaunchSkill baseSkill, params LaunchSkill[] skills)
  89. {
  90. if (this.Virtual == null ||
  91. (this.Virtual as XmdsVirtual).IsFinishSkillInit() == false)
  92. {
  93. return;
  94. }
  95. base.InitSkills(baseSkill, skills);
  96. }
  97. public override bool tryLaunchRandomSkillAndCancelCurrentSkill(InstanceUnit target, bool autoFocusNearTarget = false)
  98. {
  99. //自动战斗不允许中断当前技能施放.
  100. return false;
  101. }
  102. }
  103. }