public static void Update(this CommonAttackComponent self) { if (!self.CanAttack) { if (TimeHelper.Now() - self.LastAttackTime > self.AttackInterval) { self.CanAttack = true; } } if (self.CanAttack && self.Entity.GetComponent <StackFsmComponent>().GetCurrentFsmState().StateTypes == StateTypes.CommonAttack) { //目标不为空,且处于攻击状态,且上次攻击已完成或取消 if (self.CachedUnitForAttack != null && !self.CachedUnitForAttack.IsDisposed && (self.CancellationTokenSource == null || self.CancellationTokenSource.IsCancellationRequested)) { float distance = Vector3.Distance((self.Entity as Unit).Position, self.CachedUnitForAttack.Position); //目标距离大于当前攻击距离会先进行寻路,这里的1.75为175码 if (distance > 1.75) { self.Entity.GetComponent <UnitPathComponent>().MoveTo_InternalWithOutStateChange(self.CachedUnitForAttack.Position) .Coroutine(); } else { self.Entity.GetComponent <UnitPathComponent>().CancelMove(); self.StartCommonAttack().Coroutine(); } } } }
public static void Update(this CommonAttackComponent self) { if (self.Entity.GetComponent <StackFsmComponent>().GetCurrentFsmState().StateTypes == StateTypes.CommonAttack) { if (self.CachedUnitForAttack != null && !self.CachedUnitForAttack.IsDisposed) { Vector3 selfUnitPos = (self.Entity as Unit).Position; double distance = Vector3.Distance(selfUnitPos, self.CachedUnitForAttack.Position); float attackRange = self.Entity.GetComponent <HeroDataComponent>().NumericComponent[NumericType.AttackRange] / 100; //目标距离大于当前攻击距离会先进行寻路,这里的1.75为175码 if (distance >= attackRange) { if (!CDComponent.Instance.GetCDResult(self.Entity.Id, "MoveToAttack")) { return; } CDComponent.Instance.TriggerCD(self.Entity.Id, "MoveToAttack"); self.IsMoveToTarget = true; //移动完进入攻击状态 CommonAttackState commonAttackState = ReferencePool.Acquire <CommonAttackState>(); commonAttackState.SetData(StateTypes.CommonAttack, "CommonAttack", 1); self.Entity.GetComponent <UnitPathComponent>() .NavigateTodoSomething(self.CachedUnitForAttack.Position, attackRange, commonAttackState); } else { //目标不为空,且处于攻击状态,且上次攻击已完成或取消 if ((self.CancellationTokenSource == null || self.CancellationTokenSource.IsCancellationRequested)) { if (distance <= 1.75 && CDComponent.Instance.GetCDResult(self.Entity.Id, "CommonAttack")) { self.StartCommonAttack().Coroutine(); } } } } } }