/// <summary>
    /// Makes the skill go on cooldown.
    /// </summary>
    protected void GoOnCooldown()
    {
        if (_cooldown != 0)
        {
            // Sets cooldown timer to cooldown. When cooldown timer reaches 0, we can use the skill again
            _cooldownTimer = _cooldown;

            // If the current character is an ally, we also want them to reset their skill to basic attack
            if (_maRef.WhatAmI == CharacterType.Ally)
            {
                // Get the ally skill controller
                AllySkillController allyskillContRef = _maRef.GetComponent <AllySkillController>();
                if (allyskillContRef == null)
                {
                    Debug.Log("No AllySkillController was attached to " + _maRef.name);
                    return;
                }

                // De activate the special skill (if it was one)
                allyskillContRef.DeactivateSkill();
            }

            OnCooldownStart?.Invoke();
        }
    }
Example #2
0
    /// <summary>
    /// When the last character in the room leaves, un trigger the room
    /// </summary>
    /// <param name="collision"></param>
    private void OnTriggerExit2D(Collider2D collision)
    {
        // If we collide with something that has a MoveAttack script attached, remove it from characters currently in the room
        MoveAttack mARef = collision.GetComponent <MoveAttack>();

        if (mARef == null)
        {
            return;
        }
        // If it was an ally
        if (mARef.WhatAmI == CharacterType.Ally)
        {
            _alliesInRoom.Remove(mARef);
            // If it was the last ally and that ally dead
            if (_alliesInRoom.Count == 0 && mARef.GetComponent <Health>().CurHP == 0)
            {
                CalmRoom(mARef);
            }
        }
        // If it was an enemy and the room is active
        else if (mARef.WhatAmI == CharacterType.Enemy && mARef.gameObject.activeInHierarchy)
        {
            _enemiesInRoom.Remove(mARef);
            // If it was the last enemy
            if (_enemiesInRoom.Count == 0)
            {
                _clear = true;
            }
        }
    }
    /// <summary>
    /// Starts the skills animation and gets a reference to the enemy that will be hit.
    /// </summary>
    /// <param name="attackNodePos">The position of the enemy being hit with smite</param>
    public override void StartSkill(Vector2Int attackNodePos)
    {
        // Initialize the list of targets
        _enemiesHP = new List <Health>();

        // Get the node to attack
        Node nodeToAttack = _mAContRef.GetNodeAtPosition(attackNodePos);

        // Make sure there is a node there
        if (nodeToAttack != null)
        {
            // Try to get the move attack script of the character to attack at that node
            MoveAttack charToAttack = _mAContRef.GetCharacterMAByNode(nodeToAttack);
            if (charToAttack != null)
            {
                // Try to get the health script off the character to attack
                Health charToAtkHPScript = charToAttack.GetComponent <Health>();
                if (charToAtkHPScript != null)
                {
                    _enemiesHP.Add(charToAttack.GetComponent <Health>());
                }
                else
                {
                    Debug.Log(charToAttack.name + " has no Health script for smite to attack");
                }

                // Start the skill's animation
                StartSkillAnimation(attackNodePos);

                //sound effect
                _audManRef.PlaySound("Smite");
            }
            else
            {
                Debug.Log("Enemy to attack does not have a MoveAttack script attached to it");
            }
        }
        else
        {
            Debug.Log("No node at " + attackNodePos + " for smite to be cast towards");
            EndSkill();
        }
    }
Example #4
0
    /// <summary>
    /// Swaps the skill of the current selected player
    /// Called by pressing a side skill button
    /// </summary>
    public void SwapCharacterSkill(int index)
    {
        // Get the current selected allies skill controller
        MoveAttack charMA = _mAGUIContRef.RecentCharSelectedMA;
        // Get the current character's available skills
        List <Skill> availSkills = charMA.GetComponent <CharacterSkills>().GetAvailableSkills();

        // If the skill is on cooldown, don't swap to it
        if (availSkills[index].GetCooldownTimer() > 0)
        {
        }
        // If the character does not already have that skill active, swap their skills
        else if (charMA.SkillRef != availSkills[index])
        {
            // Get a refrence to the currently selected ally's skill controller
            AllySkillController curAllySkillCont = charMA.GetComponent <AllySkillController>();
            // Swap the equipped skill
            curAllySkillCont.SwapSkill();
            // Reselect the character
            _mAGUIContRef.RefreshSelectedVisualTiles();
        }
    }
Example #5
0
    /// <summary>
    /// Swaps the skill of the current selected player
    /// Called by the skill swap button.
    /// </summary>
    public void SwapSelectedPlayerSkill()
    {
        // Get the current selected allies skill controller
        MoveAttack charMA = _mAGUIRef.RecentCharSelectedMA;

        if (charMA != null)
        {
            // Get a refrence to the currently selected ally's skill controller
            AllySkillController curAllySkillCont = charMA.GetComponent <AllySkillController>();
            // Swap the equipped skill
            curAllySkillCont.SwapSkill();
        }
    }
Example #6
0
    /// <summary>
    /// Updates the skill skill buttons to reflect the selected character's skills
    /// </summary>
    private void UpdateSkillButtons(MoveAttack selChara)
    {
        // Get the current character's available skills
        List <Skill> availSkills = new List <Skill>();

        if (selChara != null)
        {
            availSkills = selChara.GetComponent <CharacterSkills>().GetAvailableSkills();
        }
        // Determine how many skills they have
        int amountSkills = availSkills.Count;

        if (amountSkills > _sideSkillObjs.Count)
        {
            Debug.LogError("The character has too many skills. Or there are too few side skill objects");
            amountSkills = _sideSkillObjs.Count;
        }

        // Turn on only as many side skills as needed
        for (int i = 0; i < amountSkills; ++i)
        {
            _sideSkillObjs[i].SetActive(true);
            _sideSkillIcons[i].sprite = SkillHolder.GetSkillImage(availSkills[i].GetSkillNum());
            if (availSkills[i].GetCooldownTimer() > 0)
            {
                _skillCoolTexts[i].text = availSkills[i].GetCooldownTimer().ToString();
            }
            else
            {
                _skillCoolTexts[i].text = "";
            }
            // If the skill is the active one, make it have the active color
            if (availSkills[i] == selChara.SkillRef)
            {
                _sideSkillIcons[i].color = _activeCol;
            }
            else
            {
                _sideSkillIcons[i].color = _inactiveCol;
            }
        }
        // Turn off the uneeded ones
        for (int i = amountSkills; i < _sideSkillObjs.Count; ++i)
        {
            _sideSkillObjs[i].SetActive(false);
        }
    }
Example #7
0
    // Gets character selected using the event and changes allyIndex to match the character selected character
    private void CharacterToHeal(MoveAttack charMA)
    {
        if (charMA.WhatAmI == CharacterType.Ally && _isHolding == true)
        {
            // reduces the charges
            PersistantController.SetPotCharges(PersistantController.GetPotCharges() - 1);

            _allyToHeal = charMA.GetComponent <AllyHealth>();
            if (_allyToHeal == null)
            {
                Debug.LogError("No AllyHealth attached to " + _allyToHeal.name);
            }

            HealCharacter();
            _isHolding = false;
        }
    }
Example #8
0
    /// <summary>
    /// Changes the skill detailed menu about the skill
    /// </summary>
    /// <param name="skillIndex">Index of the button pressed</param>
    public void ChangeSkillDetails(int skillIndex)
    {
        // Get the current character's available skills
        MoveAttack   charMA      = _mAGUIContRef.RecentCharSelectedMA;
        List <Skill> availSkills = charMA.GetComponent <CharacterSkills>().GetAvailableSkills();
        // Get the skill coresponding to the clicked button
        Skill skillToCareAbout = availSkills[skillIndex];

        // Set the display information to go with the skill
        _skillIcon.sprite      = SkillHolder.GetSkillImage(skillToCareAbout.GetSkillNum());
        _skillNameText.text    = " " + SkillHolder.GetSkillName(skillToCareAbout.GetSkillNum());
        _skillDescription.text = SkillHolder.GetSkillDescription(skillToCareAbout.GetSkillNum());
        _damageText.text       = skillToCareAbout.GetDamage().ToString();
        _rangeText.text        = skillToCareAbout.GetRange().ToString();
        _cooldownText.text     = skillToCareAbout.GetCoolDown().ToString();

        _lastSkill = skillToCareAbout;
    }
    /// <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: ");
        if (MARef.AttackTiles != null)
        {
            foreach (Node atkNode in MARef.AttackTiles)
            {
                //Debug.Log(atkNode.Position);
                MoveAttack potAlly = MAContRef.GetCharacterMAByNode(atkNode);
                // If we found a damaged enemy at that tile (that is not this enemy)
                if (potAlly != null && potAlly.WhatAmI == CharacterType.Enemy && potAlly != MARef)
                {
                    Health enHealth = potAlly.GetComponent <Health>();
                    if (enHealth.CurHP < enHealth.MaxHP)
                    {
                        //Debug.Log("Attacking ^ That tile");
                        nodeToAttack = atkNode.Position;
                        break;
                    }
                }
            }
        }
        else
        {
            Debug.LogError("AttackTiles are null");
        }
        // 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);
        }
    }
Example #10
0
    /// <summary>
    /// Starts the skills animation and gets a reference to the enemy that will be hit.
    /// </summary>
    /// <param name="attackNodesPos">The position of the node that will be attacked</param>
    override public void StartSkill(Vector2Int attackNodePos)
    {
        // Initialize the list of targets
        _enemiesHP = new List <Health>();

        // Get the damage
        _damage = _statsRef.GetStrength();

        // We have to set the enemy to attack, we just need to validate a bit first
        Node nodeToAttack = _mAContRef.GetNodeAtPosition(attackNodePos);

        if (nodeToAttack != null)
        {
            MoveAttack charToAttack = _mAContRef.GetCharacterMAByNode(nodeToAttack);
            if (charToAttack != null)
            {
                // Add the one enemy we will be hitting
                _enemiesHP.Add(charToAttack.GetComponent <Health>());
                if (_enemiesHP[0] == null)
                {
                    Debug.Log("Enemy to attack does not have a Health script attached to it");
                }

                // Start the skill's animation
                StartSkillAnimation(attackNodePos);
                //sound effect
                _audManRef.PlaySound("Slash");
            }
            else
            {
                Debug.Log("Enemy to attack does not have a MoveAttack script attached to it");
            }
        }
        // This occurs when an enemy isn't close enough to an ally to attack. Call end attack and don't start playing an animation
        else
        {
            //Debug.Log("Node to attack does not exist");
            EndSkill();
            return;
        }
    }
Example #11
0
    /// <summary>
    /// Starts the skills animation and gets a reference to the ally that will be healed
    /// </summary>
    /// <param name="healNodesPos">The position of the node that will be healed</param>
    public override void StartSkill(Vector2Int healNodePos)
    {
        try
        {
            // Get the node at the position
            Node nodeToHeal = _mAContRef.GetNodeAtPosition(healNodePos);
            if (nodeToHeal != null)
            {
                // Get the character at that node
                MoveAttack charToAttack = _mAContRef.GetCharacterMAByNode(nodeToHeal);
                if (charToAttack != null)
                {
                    // Actually set the reference to the enemy HP
                    _enemiesHP = new List <Health>();
                    _enemiesHP.Add(charToAttack.GetComponent <Health>());
                    if (_enemiesHP[0] == null)
                    {
                        Debug.Log("Ally to heal does not have a Health script attached to it");
                    }

                    // Start the skill's animation
                    StartSkillAnimation(healNodePos);
                    //sound effect
                    _audManRef.PlaySound("Heal");
                }
                else
                {
                    Debug.Log("Enemy to attack does not have a MoveAttack script attached to it");
                }
            }
            else
            {
                EndSkill();
            }
        }
        catch
        {
            Debug.LogError("Error in StartSkill Heal on " + this.name);
        }
    }
Example #12
0
    /// <summary>
    /// Starts the animation for 360. Also gets refences to the enemies that got hit by skill, so that they can be damaged in endSkill.
    /// </summary>
    /// <param name="attackNodePos">The point the player used to start the skill. Dictates direction of animations.</param>
    override public void StartSkill(Vector2Int attackNodePos)
    {
        // Gets the primary node to attack
        Node nodeToAttack = _mAContRef.GetNodeAtPosition(attackNodePos);

        // If we have a node to attack
        if (nodeToAttack != null)
        {
            // Sound
            _audManRef.PlaySound("360");

            // Gets a initial reference point at the position of this charcter
            Vector2Int center = new Vector2Int(Mathf.RoundToInt(this.transform.position.x), Mathf.RoundToInt(this.transform.position.y));

            // List of the 8 tiles around character
            List <Node> areaOfAttack = new List <Node>();

            // 4 Adjacent tiles
            areaOfAttack.Add(_mAContRef.GetNodeAtPosition(center + Vector2Int.up));
            areaOfAttack.Add(_mAContRef.GetNodeAtPosition(center + Vector2Int.right));
            areaOfAttack.Add(_mAContRef.GetNodeAtPosition(center + Vector2Int.down));
            areaOfAttack.Add(_mAContRef.GetNodeAtPosition(center + Vector2Int.left));

            // These are the diagnol tiles
            areaOfAttack.Add(_mAContRef.GetNodeAtPosition(center + Vector2Int.up + Vector2Int.left));
            areaOfAttack.Add(_mAContRef.GetNodeAtPosition(center + Vector2Int.up + Vector2Int.right));
            areaOfAttack.Add(_mAContRef.GetNodeAtPosition(center + Vector2Int.down + Vector2Int.left));
            areaOfAttack.Add(_mAContRef.GetNodeAtPosition(center + Vector2Int.down + Vector2Int.right));

            // Initialize the list of enemies
            _enemiesHP = new List <Health>();

            // Iterates through the area of attack to test for enemies
            foreach (Node attack in areaOfAttack)
            {
                MoveAttack charToAttack = _mAContRef.GetCharacterMAByNode(attack);
                // Checks if character exist on node
                if (charToAttack != null)
                {
                    //checks if charcter is an enemy
                    if (charToAttack.WhatAmI == CharacterType.Enemy)
                    {
                        // Get the health script from that enemy
                        Health charToAtkHPScript = charToAttack.GetComponent <Health>();

                        // Make sure they have a health script
                        if (charToAtkHPScript == null)
                        {
                            Debug.Log("Enemy to attack does not have a Health script attached to it");
                        }
                        else
                        {
                            _enemiesHP.Add(charToAttack.GetComponent <Health>());
                        }
                    }
                }
            }

            // If we have at least 1 enemy to attack
            if (_enemiesHP.Count > 0)
            {
                // Start the animation of the character
                StartSkillAnimation(attackNodePos);
            }
            else
            {
                Debug.Log("There were no enemies for ThreeSixtySwing to hit");
            }
        }
        else
        {
            //Debug.Log("Node to attack does not exist");
            EndSkill();
            return;
        }
    }