Esempio n. 1
0
    public void Attack(BaseItemScript target)
    {
        this._baseItem.Walker.OnBetweenWalk = null;

        if (target != null)
        {
            this._currentTarget = target;

            Vector3[] outerCells = target.GetOuterCells();
            if (outerCells.Length > 0)
            {
                //finding nearest outer cell
                Vector3 nearestCell     = Vector3.one * 999999;
                float   smallerDistance = 999999;
                for (int index = 0; index < outerCells.Length; index++)
                {
                    float distance = Vector3.Distance(this._baseItem.GetPosition(), outerCells[index]);
                    if (distance < smallerDistance)
                    {
                        smallerDistance = distance;
                        nearestCell     = outerCells[index];
                    }
                }

                this._currentTargetPoint = nearestCell;

                this._baseItem.Walker.WalkToPosition(_currentTargetPoint);
                this._baseItem.Walker.OnFinishWalk += this.AttackLoop;

                //check any walls on root
                BaseItemScript nearestWallOnPath = this._baseItem.Walker.GetNearestWallOnPath();
                if (nearestWallOnPath != null)
                {
                    this._currentTarget = nearestWallOnPath;
                    //					Debug.Log (nearestWallOnPath);
                }
            }

            if (this._baseItem.itemData.configuration.attackRange > 0)
            {
                this._baseItem.Walker.OnBetweenWalk += this.CheckTargetBeyondRange;
                //check on start walk because the unit will already in range of target maybe
                this.CheckTargetBeyondRange();
            }
        }
    }