// Function to take damage
    public DamageDetails TakeDamage(SkillCalc skill, TerasCalcs attacker)
    {
        // check for critical hit
        float critical = 1f;

        if (Random.value * 100f <= 6.25)
        {
            critical = 2f;
        }

        // check element effectiveness
        float element = ElementEffectiveness.GetEffectiveness(skill.baseSkill.SkillElement, attacker._baseTeras.FirstElement) * ElementEffectiveness.GetEffectiveness(skill.baseSkill.SkillElement, attacker._baseTeras.SecondElement);

        // set details of damage
        var DMG_Details = new DamageDetails()
        {
            Critical             = critical,
            ElementEffectiveness = element,
            Fainted = false
        };

        // calculate damage
        float modifiers = 1 * element * critical;
        float a         = (2 * attacker.level + 10) / 250f;
        float d         = a * skill.baseSkill.Damage * ((float)attacker._baseTeras.Attack / _baseTeras.Defense);
        int   damage    = Mathf.FloorToInt(d * modifiers);

        // substract health
        this.Health -= damage;

        UpdateHP(damage);

        return(DMG_Details);
    }
Example #2
0
    /// <summary>
    /// finds the element that is element[col], and returns it. It also outputs the multiplyer for using element[row] on element[col]
    /// </summary>
    /// <param name="row"></param>
    /// <param name="col"></param>
    /// <param name="multiplyer"></param>
    /// <returns></returns>
    public ElementEffectiveness FindElementEffectiveness(int row, int col, out float multiplyer)
    {
        //set up default returns
        multiplyer = 1;
        ElementEffectiveness e = new ElementEffectiveness(Elements[col], 1);

        //find the element
        bool foundElement = false;

        for (int i = Elements[row].EffectivenessOnElement.Count - 1; i >= 0 && !foundElement; i--)
        {
            //remove any effectiveness that have had the element deleted or removed
            while (Elements[row].EffectivenessOnElement[i].element == null && i < Elements[row].EffectivenessOnElement.Count && i >= 0)
            {
                if (Elements[row].EffectivenessOnElement[i].element == null)
                {
                    Elements[row].EffectivenessOnElement.RemoveAt(i);
                    i--;
                }
            }
            //compares the name of the element we're looking for with the next element in the row's effectiveness
            //if the element we're looking for is this one.
            if (i < Elements[row].EffectivenessOnElement.Count && i >= 0 && Elements[col].elementName == Elements[row].EffectivenessOnElement[i].element.elementName)
            {
                //inform that its found
                foundElement = true;

                //collect the values
                e          = Elements[row].EffectivenessOnElement[i];
                multiplyer = e.Multiplyer;
            }
        }
        //if the element's relation doesn't exist; Create the default relation of 0
        if (!foundElement)
        {
            //creates an effectiveness
            Elements[row].EffectivenessOnElement.Add(e);

            //this lets the element save during the next asset save
            EditorUtility.SetDirty(Elements[row]);
        }
        return(e);
    }