Example #1
0
    /// <summary>
    /// Tells the unit to follow the specified path, then attack the unit at the end of the path.
    /// </summary>
    /// <param name="path">The path to be followed by this unit</param>
    /// <param name="unit">The unit to be attacked at the end of the path</param>
    public void TravelPathAndAttack(List <BattleHex> path, BattleUnit unit)
    {
        HexDirection finalFacingDirection = TravelPath(path);
        BattleHex    unitTile;

        //this._actions.la
        if (path.Count > 1)
        {
            unitTile = path[path.Count - 1];
        }
        else
        {
            unitTile = _currentHex;
        }

        HexDirection requiredDirection = HexHelpers.GetTargetDirection(unitTile, unit.CurrentHexTile);

        if (requiredDirection != finalFacingDirection)
        {
            this._actions.Enqueue(new UnitRotation(this, HexHelpers.GetTargetDegrees(HexHelpers.ReverseDirection(finalFacingDirection)), HexHelpers.GetTargetDegrees(requiredDirection)));
        }

        this._actions.Enqueue(new UnitAttack(this, unit));

        if (this._currentAction == null)
        {
            this._currentAction = this._actions.Dequeue();
        }
    }
Example #2
0
        /// <summary>
        /// Performs the standard unit rotation.
        /// </summary>
        internal override void Perform()
        {
            Vector3 currentRotation = base.unit.transform.rotation.eulerAngles;

            currentRotation.y = Mathf.LerpAngle(this._startRotation, this._endRotation, this._lerpValue);

            base.unit.transform.rotation = Quaternion.Euler(currentRotation);

            if (this._lerpValue >= 1f)
            {
                base.unit.FacingDirection = HexHelpers.ReverseDirection(HexHelpers.GetRotationDirection(this._endRotation));
                base.FinishAction();
            }
            else
            {
                this._lerpValue += (Time.deltaTime * base.unit._standingRotationSpeed);
            }
        }
Example #3
0
    /// <summary>
    /// Tells the unit to follow the specified path.
    /// </summary>
    /// <param name="path">The path to be followed by this unit</param>
    public HexDirection TravelPath(List <BattleHex> path)
    {
        if (path.Count == 1)
        {
            return(_facingDirection);
        }

        float currentRotation = Mathf.Round(base.transform.eulerAngles.y);

        Vector3 startPosition = Vector3.zero;
        Vector3 endPosition   = this.CurrentHexTile.WorldPosition;

        HexDirection facingDirection = _facingDirection;

        for (var i = 0; i < path.Count - 1; i++)
        {
            BattleHex current = path[i];
            BattleHex next    = path[i + 1];

            HexDirection requiredDirection = HexHelpers.GetTargetDirection(current, next);

            float requiredRotation = HexHelpers.GetTargetDegrees(requiredDirection);

            if (i == 0 && currentRotation != requiredRotation)
            {
                _actions.Enqueue(new UnitRotation(this, currentRotation, requiredRotation));
                currentRotation = requiredRotation;
                facingDirection = requiredDirection;
            }

            float distance      = current.TileLength;
            float speedModifier = 1f;

            if (i == 0)
            {
                distance     /= 2f;
                speedModifier = 2f;
            }

            startPosition = endPosition;

            endPosition = next.GetEdge(requiredDirection);

            HexDirection requiredFacingDirection = HexHelpers.ReverseDirection(requiredDirection);

            _actions.Enqueue(new UnitMovement(this, startPosition, endPosition, current, facingDirection, requiredFacingDirection, currentRotation, requiredRotation, speedModifier));

            facingDirection = requiredFacingDirection;
            currentRotation = requiredRotation;
        }

        BattleHex endTile = path[path.Count - 1];

        _actions.Enqueue(new UnitMovement(this, endPosition, endTile.transform.position, endTile, facingDirection, facingDirection, 0f, 0f, 2f));

        this._currentAction = this._actions.Dequeue();

        _battleGrid.UnhighlightNodes();

        return(facingDirection);
    }