Example #1
0
    public IEnumerator DealDamage(BattleCharacter character, AttackType type)
    {
        BattleHUD.Instance.UpdateMenu(BattleHUD.SelectionMenu.None);

        if (type == AttackType.Magical && characterList[TurnIndex] is BattleParty)
        {
            (characterList[TurnIndex] as BattleParty).Mana -= 5;
            BattleHUD.Instance.UpdateCard(characterList[TurnIndex]);
        }

        //Animation
        string animName = null;

        animName = (type == AttackType.Physical) ? "Attack" : "MagicAttack";
        characterList[TurnIndex].GetComponent <Animator>().SetTrigger(animName);
        AnimatorClipInfo[] currentClipInfo = characterList[TurnIndex].GetComponent <Animator>().GetCurrentAnimatorClipInfo(0);
        yield return(new WaitForSeconds(currentClipInfo[0].clip.length));


        int damage = 0;

        if (guardingDictionary[character] == false)
        {
            if (characterList[TurnIndex] is BattleParty)
            {
                damage = CalculatePlayerDamage(type);
            }
            else
            {
                damage = CalculateEnemyDamage(type, character);
            }
        }
        else
        {
            character.GetComponent <Animator>().SetBool("IsGuarding", false);
            BattleHUD.Instance.UpdateCharacterStats(character, CharacterCard.CharacterStats.None);
            if (characterList[TurnIndex] is BattleParty)
            {
                damage = CalculatePlayerDamage(type) / 2;
            }
            else
            {
                damage = characterList[TurnIndex].charInfo.baseStrength / 2;
            }
            guardingDictionary[character] = false;
        }

        character.SendMessage("TakeDamage", damage);

        TurnIndex++;
    }