示例#1
0
 /// <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);
 }
示例#2
0
        /// <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();
        }
示例#3
0
 /// <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);
 }
示例#4
0
 /// <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);
 }
示例#5
0
        //======================================================================

        /// <summary>Set a new attacking target.</summary>
        /// <param name="target">The new target.</param>
        public void Attack(Attackable target)
        {
            enabled = true;
            Target  = target;
        }