Beispiel #1
0
    /// <summary>
    /// 非玩家受到傷害
    /// </summary>
    /// <param name="attacker">攻擊方</param>
    /// <param name="defender">防禦方</param>
    public void TakeDamage(Player player, Enemy enemy)
    {
        StatGeneral attacker = player.stat;
        StatGeneral defender = enemy.stat;

        float  dmg;
        string damage;

        Elements a = player.stat.eKeep;
        Elements d = enemy.State;

        short isStrongOrWeak = GameState.StrongOrWeakDetector(a, d);

        float atk = GameState.ValueWithElements(a, attacker, true);
        float def = GameState.ValueWithElements(a, defender, !Guarding);

        if (isStrongOrWeak > 0)
        {
            dmg = (atk + attacker.INT * 0.2f - def) + attacker.INT * 0.5f;
        }
        else if (isStrongOrWeak < 0)
        {
            dmg = (atk + attacker.INT * 0.2f - def) - defender.INT * 0.5f;
        }
        else
        {
            dmg = (a == 0) ? (atk - def) : (atk + attacker.INT * 0.2f - def);
        }

        dmg = Mathf.Clamp(dmg, 0, dmg);
        bool isCrit = attacker.LUK + Random.Range(attacker.LUK * -1f, attacker.LUK * 0.2f) > attacker.LUK;

        dmg = (isCrit && dmg > attacker.STR) ? (dmg * 2f) : dmg;
        dmg = (Random.Range(0, defender.AGI) > Random.Range(0, attacker.AGI)) ? -1 : dmg;

        damage = (dmg < 0) ? "miss" : ((int)dmg).ToString();

        if (damage == "miss")
        {
            isCrit = false;
        }
        else
        {
            enemy.TakeHit();
        }

        if (dmg > attacker.STR)
        {
            isCrit = false;
        }

        StartCoroutine(defender.DamageDisplayer(damage, transform, a, isCrit));
    }
Beispiel #2
0
        public static float ValueWithElements(Elements e, StatGeneral stat, bool isAttack)
        {
            float value = stat.STR;

            if (e == Elements.Brave || e == Elements.Agile || e == Elements.Guard)
            {
                value = 0.1f * (value * stat.STR);
                switch ((int)e)
                {
                case 1:
                    value *= (isAttack) ? 2f : 0.8f;
                    break;

                case 2:
                    value *= (isAttack) ? 1.5f : 1.5f;
                    break;

                case 3:
                    value *= (isAttack) ? 0.8f : 2f;
                    break;
                }
            }
            else if (e == Elements.Origin)
            {
                value = 0.1f * (value * stat.INT);
            }
            else if (e == Elements.Earth)
            {
                value = 0.1f * (value * stat.AGI);
            }
            else if (e == Elements.Chaos)
            {
                value = 0.1f * (value * stat.LUK);
            }
            else if (e == Elements.Iridescent || e == Elements.Dark)
            {
                value = 0.5f * (stat.STR * stat.INT);
                if (e == Elements.Iridescent)
                {
                    value *= (isAttack) ? 1f : 2f;
                }
                else
                {
                    value *= (isAttack) ? 2f : 1f;
                }
            }

            value *= (isAttack) ? 1.5f : 1f;

            return(Random.Range(value * 0.9f, value * 1.1f));
        }