Exemplo n.º 1
0
    public void OnDamage(Shooter p_damager, DamageType p_type, int p_damage, bool p_bypassDefense, bool p_bypassImmunityWindow)
    {
        int finalDamage = p_damage;
        int effective   = p_type.IsEffectiveAgainst(m_type);

        if (!p_bypassDefense)
        {
            finalDamage -= m_defense;
        }
        if (effective == 1)
        {
            finalDamage = Mathf.CeilToInt(finalDamage * 1.5f);
        }
        else if (effective == -1)
        {
            finalDamage /= 2;
        }

        if (m_feedbackTemplate && (!m_health.IsImmune() || p_bypassImmunityWindow))
        {
            FeedbackGenerator.GenerateFeedback(transform, m_feedbackTemplate, p_type, finalDamage <= 0 ? 0 : -finalDamage,
                                               Constants.YELLOW, p_bypassDefense ? Constants.PURPLE : Constants.TRANSPARENT,
                                               m_feedbackPositionRandomness.x, m_feedbackPositionRandomness.y);
        }

        if (finalDamage > 0)
        {
            m_health.Damage(finalDamage, p_bypassImmunityWindow);
        }
    }
Exemplo n.º 2
0
    public void OnDamage(Shooter p_damager, DamageType p_type, int p_damage, bool p_bypassDefense, bool p_bypassImmunityWindow)
    {
        if (m_health)
        {
            int finalDamage = p_damage;
            int effective   = p_type.IsEffectiveAgainst(m_type);

            if (!p_bypassDefense)
            {
                finalDamage -= m_stats.GetStatEffect(Stats.DEF);
            }
            if (effective == 1)
            {
                finalDamage = Mathf.CeilToInt(finalDamage * 1.5f);
            }
            else if (effective == -1)
            {
                finalDamage /= 2;
            }

            int resistance = Mathf.FloorToInt(m_modifiers.GetModifier(p_type.m_name + " Resistance"));
            finalDamage -= resistance;

            if (m_feedbackTemplate && (!m_health.IsImmune() || p_bypassImmunityWindow))
            {
                FeedbackGenerator.GenerateFeedback(transform, m_feedbackTemplate, p_type, finalDamage <= 0 ? 0 : -finalDamage,
                                                   m_feedbackColor, p_bypassDefense ? Constants.PURPLE : Constants.TRANSPARENT,
                                                   m_feedbackPositionRandomness.x, m_feedbackPositionRandomness.y);
            }

            if (finalDamage > 0)
            {
                m_health.Damage(finalDamage, p_bypassImmunityWindow);
            }
        }

        // make sure the AI starts targeting its last damager (if it's an entity)
        if (m_ai && p_damager && p_damager.m_entity)
        {
            m_ai.m_target = p_damager.m_entity;
        }
    }