/// <summary>
    /// Called from MoveAttack by enemies. Attempts to have the enemy attack
    /// </summary>
    /// <returns>True we are attacking something, false otherwise</returns>
    public bool AttemptAttack()
    {
        // If the enemy does not exist, do not try to attack something
        if (_currentEnemy == null)
        {
            Debug.Log("No enemy is current");
            return(false);
        }
        // Try to cast the curAttackNodePos to a node, if there is no node there, don't attack
        Node nodeToAttack = _mAContRef.GetNodeAtPosition(_curAttackNodePos);

        if (nodeToAttack == null)
        {
            _currentEnemy.HasAttacked = true;
            StartNextEnemy();
            return(false);
        }
        // Otherwise attack it
        _currentEnemy.StartAttack(_curAttackNodePos);
        return(true);
    }
    /// <summary>
    /// Used to test what kind of tile the current testNode in CalculateAllTiles.
    /// This is the Move specific variety. That means, nodes will be appended to currentNodes only when
    /// the character can legally travel to that location (when the node is occupied by no one or somone
    /// on the same team).
    /// We only test for the movement interaction (tests for the others will come later)
    /// </summary>
    /// <param name="testPos">Position of the node being tested</param>
    /// <param name="testedNodes">Reference to the List of Nodes that have been tested before</param>
    /// <param name="currentNodes">Reference to the List of Nodes that still need to be tested</param>
    /// <returns>Returns true if the tested node was a valid move tile</returns>
    private bool MoveTestNode(Vector2Int testPos, List <Node> testedNodes, List <Node> currentNodes)
    {
        Node testNode = _mAContRef.GetNodeAtPosition(testPos);
        // Assume this node cannot be added
        bool wasNodeAdded = false;

        // If there is a node there are we have not tested it before
        if (testNode != null)
        {
            // If the node is not occupied, I can move there
            if (testNode.Occupying == CharacterType.None)
            {
                // Only add it if we have not already done so
                if (!testedNodes.Contains(testNode))
                {
                    _moveTiles.Add(testNode);
                    currentNodes.Add(testNode);
                }
                // This node is being added to move tiles
                wasNodeAdded = true;
            }
            // If it is occupied by someone on my team, I can't move there, but I can move past there
            else if (testNode.Occupying == _whatAmI)
            {
                // Only add it if we have not already done so
                if (!testedNodes.Contains(testNode))
                {
                    currentNodes.Add(testNode);
                }
            }
            // Add the node to the tested nodes
            testedNodes.Add(testNode);
        }

        // Return if the tile is a move tile or not
        return(wasNodeAdded);
    }
예제 #3
0
    /// <summary>
    /// Gets the node at the current selection location
    /// </summary>
    /// <returns>Returns the node at the current selection location</returns>
    private Node GetSelectedNode()
    {
        Vector2Int pos = _inpContRef.SelectToGridPoint();

        return(_mAContRef.GetNodeAtPosition(pos));
    }