Example #1
0
    //Apply status effects.
    public void ApplyStatusEffects(Unit t, AttackData data, float variableValue)
    {
        //For each status effect.
        for (int se = 0; se < statusEffects.Length; se++)
        {
            //Apply elemental advantage.
            float hit = hitRoll;
            if (MathP.IsElementAdavantage(data.actor.uElement, t.uElement) == 1)
            {
                hit /= ELEMPLUS;
            }
            else if (MathP.IsElementAdavantage(data.actor.uElement, t.uElement) == -1)
            {
                hit /= ELEMMINUS;
            }

            //Roll.
            float rand = Random.Range(0, 100);
            if ((rand < statusChances[se] && (hit < ((float)data.actor.GetDEX() / (float)t.GetAGI()) * 100) || !statusEffects[se].isNegative))
            {
                StatusEffect r = StatusEffect.Instantiate(statusEffects[se]);
                if (t == data.actor)
                {
                    r.duration = statusDurations[se] + 1;
                }
                else
                {
                    r.duration = statusDurations[se];
                }
                r.applier       = data.actor;
                r.variableValue = variableValue;
                t.AddStatusEffect(r);
            }
            else if (rand < statusChances[se] && statusEffects[se].isNegative && hit > ((float)data.actor.GetDEX() / (float)t.GetAGI()) * 100)
            {
                t.textQueue.Add("Resist");
                t.textColor.Add(Color.white);
            }
        }
    }
Example #2
0
    //Make a single attack.
    public long AttackTarget(Unit actor, Unit target, AttackData data, bool isCrit, float dmgMod)
    {
        //If we crit, apply that.
        float critmod = 1f;

        if (isCrit)
        {
            critmod = actor.GetCritDMG();
        }

        //Apply elemental advantage.
        float hit = hitRoll;

        if (MathP.IsElementAdavantage(actor.uElement, target.uElement) == 1)
        {
            hit /= ELEMPLUS;
        }
        else if (MathP.IsElementAdavantage(actor.uElement, target.uElement) == -1)
        {
            hit /= ELEMMINUS;
        }

        //Check if we miss.
        if (hit < ((float)actor.GetDEX() / (float)target.GetAGI()) * 100)
        {
            //Roll for damage.
            float rowMod = 1;
            if (data.actorParty.GetAllUnits().Contains(target))
            {
                rowMod = data.actorParty.GetRowDamageMod(target);
            }
            else if (data.defendingParty.GetAllUnits().Contains(target))
            {
                rowMod = data.defendingParty.GetRowDamageMod(target);
            }
            long d = MathP.GetDamage((decimal)(GetSkillDamage(actor) * dmgMod), target.GetStat(defenseStat));
            d = (long)(Mathf.CeilToInt(d * rowMod));

            //Apply elemental advantage.
            if (MathP.IsElementAdavantage(actor.uElement, target.uElement) == 1)
            {
                d = (long)(d * ELEMPLUS);
            }
            else if (MathP.IsElementAdavantage(actor.uElement, target.uElement) == -1)
            {
                d = (long)(d * ELEMMINUS);
            }

            //Deal the damage.
            if (target.myStatusEffects.Find(n => n.isCover) == null)
            {
                target.TakeHit(d, false, critmod, MathP.IsElementAdavantage(actor.uElement, target.uElement));
            }
            else
            {
                //Get how much damage is diverted.
                for (int i = 0; i < target.myStatusEffects.Count; i++)
                {
                    long diverted = 0;
                    if (target.myStatusEffects[i].isCover && target.myStatusEffects[i].applier != null)
                    {
                        diverted += (long)((target.myStatusEffects[i].variableValue / 100) * (float)d);
                        Debug.Log("Yes");
                        //If the diverter is still alive and stuff.
                        if (target.myStatusEffects[i].applier.IsAlive())
                        {
                            target.myStatusEffects[i].applier.TakeHit(diverted, false, 1f);
                            d -= diverted;
                        }
                    }
                }

                //Finally, deal remaining damage to the target.
                target.TakeHit(d, false, critmod, MathP.IsElementAdavantage(actor.uElement, target.uElement));
            }

            //Take any thorns damage.
            if (target.GetThorns(Mathf.CeilToInt((long)(d * critmod))) > 0)
            {
                actor.TakeHit(target.GetThorns(Mathf.CeilToInt((long)(d * critmod))), false, 1f);
            }
            return(d);
        }
        else
        {
            target.TakeMiss();
            return(-1);
        }
    }