コード例 #1
0
    /// <summary>
    /// Attempts to do whatever action this enemy does.
    /// Called after the character finishes moving.
    /// If the enemy is within range of an ally, it will push them.
    /// </summary>
    protected override void AttemptAction()
    {
        Node currentNode = MAContRef.GetNodeByWorldPosition(this.transform.position);
        // Get the nodes it can push
        List <Node> adjNodes = MAContRef.GetNodesDistFromNode(currentNode, 1);
        // Try to find an ally to push at any of these nodes
        Node nodeToAttack = null;

        foreach (Node curNode in adjNodes)
        {
            // If we found a node containing an ally
            if (curNode.Occupying == CharacterType.Ally)
            {
                nodeToAttack = curNode;
                break;
            }
        }

        // If we found an ally to push, push it
        if (nodeToAttack != null)
        {
            MARef.StartAttack(nodeToAttack.Position);
        }
        // Otherwise, just end the attack
        else
        {
            MARef.EndAttack();
        }
    }
コード例 #2
0
    /// <summary>
    /// Attempts to do whatever action this enemy does.
    /// Called after the character finishes moving.
    /// Uses the character's skill on an enemy in range.
    /// </summary>
    override protected void AttemptAction()
    {
        // Recalculate the enemy's move and attack tiles.
        // We really only want their attack tiles, but those are based on the move tiles
        // Which are currently out of place since they are what the
        MARef.CalculateAllTiles();
        Vector2Int nodeToAttack = new Vector2Int(int.MaxValue, int.MaxValue);

        // Try to find an ally in range
        //Debug.Log("These are " + this.name + " at " + this.transform.position + " potential attack tiles: ");
        foreach (Node atkNode in MARef.AttackTiles)
        {
            //Debug.Log(atkNode.Position);
            MoveAttack potAlly = MAContRef.GetCharacterMAByNode(atkNode);
            // If we found an ally at that tile
            if (potAlly != null && potAlly.WhatAmI == CharacterType.Ally)
            {
                //Debug.Log("Attacking ^ That tile");
                nodeToAttack = atkNode.Position;
                break;
            }
        }
        // If there is no node to attack, just end the attack
        if (nodeToAttack.x == int.MaxValue && nodeToAttack.y == int.MaxValue)
        {
            MARef.EndAttack();
        }
        // If there is a node being attacked, start the attack
        else
        {
            MARef.StartAttack(nodeToAttack);
        }
    }