/// <summary> /// Check if current target is the same as the given one. /// </summary> /// <returns>Whethet it is the same target.</returns> /// <param name="target">Target to check against.</param> public bool SameTarget(Attackable target) { return(_agg.Target && _agg.Target == target); }
/// <summary>Start an auto attack.</summary> private void AutoAttack(Attackable target) { // Start attacking Debug.Log(sel.name + " Auto attacking " + target.sel.name); _agg.Attack(target); // Set AutoReturn destination if movable. if (_mov) { if (_mov.Dest != null && _mov.Dest.Type == DestType.PlayerSet) { _returnPos = _mov.Dest.Position; } else { if (_returnPos == Vector3.zero) { _returnPos = _trans.position; } } } // Start AutoAttack chasing stream. Chase enemy while it is within // autoChaseRange. Transform tgtTrans = target.transform; Destination dest = null; Observable.EveryUpdate() .TakeUntilDestroy(gameObject) .TakeWhile(_ => this.SameTarget(target) && target.Alive && this.AutoAttackReachable(target) ) .Do(_ => { if (!_agg.WithinWeaponRange(target)) { // Chase enemy dest = this.AddAutoAttackDest(tgtTrans.position); } else if (_mov) { // Clear destination _mov.Remove(DestType.AutoAtt); _mov.Remove(DestType.AutoAttRetrun); } }) .DoOnCompleted(() => { // Clear target _agg.Release(target); if (_mov) { // Cleat autoAttack destination _mov.Remove(dest); if (_mov.Dest == null && _returnPos != Vector3.zero && _returnPos != _trans.position) { // Add AutoReturn destination this.AddReturnDest(); } } }) .Subscribe(); }
/// <summary> /// Check whether a given target is within its weapon range. /// </summary> /// <param name="att">The attackable target.</param> public bool WithinWeaponRange(Attackable target) { return(Vector3.Distance( sel.trans.position, target.sel.trans.position ) < weapon.distance); }
/// <summary> /// View effects when attacking the specified target. /// </summary> /// <param name="target">Target attackable.</param> public override void Attack(Attackable target) { transform.LookAt(target.transform.position); }
//====================================================================== /// <summary>Set a new attacking target.</summary> /// <param name="target">The new target.</param> public void Attack(Attackable target) { enabled = true; Target = target; }