/// <summary>
    /// Sets the attack range of MoveAttack
    /// Called when the skill is equipped
    /// </summary>
    public void EquipSkill()
    {
        // Set the range
        _maRef.AttackRange = _range;

        // Set if the skill is friendly or deadly
        _maRef.TargetFriendly = _healing;

        // Update the attack tiles
        if (_maRef.AttackTiles != null)
        {
            _maRef.CalculateAllTiles();
        }
    }
Beispiel #2
0
    /// <summary>
    /// Allows the user to select again and recalculates all the visual tiles, since they have now changed
    /// Called by the TurnSystem.OnBeginPlayerTurn event
    /// Called when an ally stops moving (and they wont be taking action) or their action ends
    /// </summary>
    private void AllowSelect()
    {
        // Call the event for when the player is allowed to select
        if (OnPlayerAllowedSelect != null)
        {
            OnPlayerAllowedSelect();
        }

        // Allow them to hit buttons
        ToggleSelect(true);
        // If the user still has someone selected, show their new active visuals
        if (_charSelected != null)
        {
            _mAContRef.TurnOffVisuals(_charSelected);
            _charSelected.CalculateAllTiles();
            _mAContRef.SetActiveVisuals(_charSelected);
        }
    }
Beispiel #3
0
    /// <summary>
    /// Takes the turn of the enemy
    /// </summary>
    public void TakeTurn()
    {
        // Reset my turn
        _mARef.ResetMyTurn();

        // Get the node this enemy is standing on
        _standingNode = _mAContRef.GetNodeByWorldPosition(this.transform.position);
        // We are going to use the enemy's move tiles, so we need to recalculate those,
        // since other characters have probably moved on their turn
        _mARef.CalculateAllTiles();
        // Find the tile the enemy should move to
        Node nodeToMoveTo = FindTileToMoveTo();

        // Make sure we have a place to move
        if (nodeToMoveTo != null)
        {
            // After the enemy finishes moving, it will call the CharacterFinishedMovingEvent.
            // So we add the BeginAttemptAction function to be called when that event is called.
            // It will remove itself from the event once it is called.
            // The idea is that only one function will be attached to that event at a time (will belong to current character)
            MoveAttack.OnCharacterFinishedMoving += BeginAttemptAction;
            // Start moving the enemy
            MoveToTile(nodeToMoveTo);

            /// We want the enemy's turn to look like Move, Action, End.
            /// But we only call MoveToTile above.
            /// This is because we need the enemy to finish moving before it does its action.
            /// Action is called when the character finishes moving.
            /// Similarly, End is called when the character finishes its action.
        }
        // If we have no where to move, just finish this enemy's turn
        else
        {
            // Call the finish enemy turn event
            if (OnSingleEnemyFinish != null)
            {
                OnSingleEnemyFinish();
            }
        }
    }
Beispiel #4
0
    /// <summary>
    /// Tries to select a character at the grid location the user just clicked on. If successful, show that characters move/attack ranges
    /// </summary>
    /// <param name="selNode">The node that was just selected</param>
    private void AttemptSelect(Node selNode)
    {
        // Try to get the MoveAttack script off the character
        _charSelected = _mAContRef.GetCharacterMAByNode(selNode);
        // Make sure the MoveAttack script is valid and that the character is active in the hierarchy
        if (_charSelected != null && _charSelected.gameObject.activeInHierarchy)
        {
            // Set the recent selected character
            _recentCharSel = _charSelected;
            // If it hasn't moved this turn yet or hasn't attacked this turn
            if (!(_charSelected.HasMoved && _charSelected.HasAttacked))
            {
                //Debug.Log("Select character");
                // Calculate its valid tiles
                _charSelected.CalculateAllTiles();
                // Set the visuals of it to be on
                _mAContRef.SetActiveVisuals(_charSelected);
            }

            // Call the character selected event
            OnCharacterSelect?.Invoke(_charSelected);
        }
    }
    /// <summary>
    /// Moves the current enemy and makes them attack
    /// </summary>
    private void TakeSingleTurn()
    {
        // Try to get the current enemy we should move
        _currentEnemy = _enemiesMA[_enemyIndex];
        // If the enemy does not exist, do not try to move it
        if (_currentEnemy == null)
        {
            Debug.Log("We done bois, I'm don't exist");
            return;
        }
        //Debug.Log("Moving " + currentEnemy.name);

        Node startNode = _mAContRef.GetNodeByWorldPosition(_currentEnemy.transform.position);

        // Reset this enemies movement
        _currentEnemy.CalculateAllTiles();

        // Get the node this character should try to attack and the node this character should move to
        _curAttackNodePos = FindDesiredAttackNodePos();
        //Debug.Log("Found node to attack at " + curAttackNodePos);
        Node desiredNode = FindDesiredMovementNode();

        // If the node returns null, it means we cannot do anything with this enemy
        if (desiredNode == null)
        {
            // Debug.Log(currentEnemy.name + " Attack Node: " + curAttackNodePos);
            Debug.Log("Desired node is null");
            AttemptAttack();
            EndSingleTurn();
            return;
        }
        // See if they are trying to move where a character already is
        else if (desiredNode.Occupying != CharacterType.None)
        {
            Debug.Log("Desired Node is at " + desiredNode.Position);
            Debug.Log("Trying to move to where a character already is");
            if (desiredNode != startNode)
            {
                Debug.Log("Wrong move pal");
                Debug.Log(_currentEnemy.name + " Start Node: " + startNode.Position + ". End Node: " + desiredNode.Position);
                Debug.Log(_currentEnemy.name + " Attack Node: " + _curAttackNodePos);
            }
            // Come back
            bool didAttack = AttemptAttack();
            EndSingleTurn();
            if (!didAttack)
            {
                StartNextEnemy();
            }
            return;
        }
        Debug.Log("Desired Node is at " + desiredNode.Position);
        // Debug.Log(currentEnemy.name + " Start Node: " + startNode.position + ". End Node: " + desiredNode.position);
        // Debug.Log(currentEnemy.name + " Attack Node: " + curAttackNodePos);

        // Calculate the pathing

        // If they successfully pathed
        if (_mAContRef.Pathing(startNode, desiredNode, _currentEnemy.WhatAmI))
        {
            // Start moving the character
            _currentEnemy.StartMove();
        }
        // If they didn't just attempt an attack
        else
        {
            _mAContRef.ResetPathing();
            AttemptAttack();
        }

        // Attacking will be called after the enemy has moved

        // End the single turn
        EndSingleTurn();
    }