Altering "Element Rate" to reduce defence instead of increasing damage?

Currently in my game I've changed (via formulas) the way defense (and mdef too) works - each point in DEF is 0.1% of damage reduction (ie. 200 DEF = incoming damage is reduced by 20%). Now I wanted to add a bit more depth into battle and add three damage types - slashing (swords), thrusting (spears) and striking (maces). And it's fairly simple, I've created separate elements, applied them to corresponding weapons, and altered Element Rates for enemies. But I want to change how they work. As an example:

Enemy has following stats:
Defense: 200 (=> 20% damage reduction)
---
Element Rate: Strike 170%
Element Rate: Slash 100%
Element Rate: Thrust 100%
Now, having 170% at Strike Element Rate should increase the attack with Strike weapon by 70%. Let's assume I'm fighting with player that has a total of 130 Attack:
Player attacks with Slash weapon with 130 Attack. Deals 84 damage (130 - 20% reduction).
Changing to Strike damage, the same actor now deals 144 damage.

I don't know the correct maths for increase, but it seems that attack is first reduced by Defense (to 84) and then multiplied by Element Rate (170% = ~143).

Is there any way to change how that works, and apply the Element Rate to DEF (or MDEF in case of magical attacks)? Basically:
Player attacks with Strike weapon, with same 130 Attack. Now he should deal 122 damage (130 - (30% of 20% reduction = 6%)).

TLDR: Can i change Weapon Rate from increasing Attack to decreasing Defense?
Use states maybe?

Give the enemy a pasaive state with no icon so that the player doesn't know that it's there. It does nothing ezcept indicate that the enemy has this increased attack.

In your damage formula for the actor, check for this state. If present then add a def debuff for the correct percentage and deal damage. If not present just deal damage.
Hm, according to Game_Battler's make_damage_value method...

Code:
def make_damage_value(user, item)
  value = item.damage.eval(user, self, $game_variables)
  value *= item_element_rate(user, item)
  value *= pdr if item.physical?
  value *= mdr if item.magical?
  value *= rec if item.damage.recover?
  value = apply_critical(value) if @result.critical
  value = apply_variance(value, item.damage.variance)
  value = apply_guard(value)
  @result.make_damage(value.to_i, item)
end

Pretty much, your formula that includes defense goes under item.damage.eval, then the next line is element, so you're right that damage is calculated in that order. The elemental rate is calculated as:

Code:
def item_element_rate(user, item)
  if item.damage.element_id < 0
    user.atk_elements.empty? ? 1.0 : elements_max_rate(user.atk_elements)
  else
    element_rate(item.damage.element_id)
  end
end

In other words, multiply by the item (skill)'s element, multiply by the user's elements (from the enemy or actor, class and equipment via feature_objects), or return a multiplier of 1.0 (100%). The user in both cases refer to the user of the skill.

---

Okay, it depends on how you wrote your formula and how you want to apply the elemental rate. If you define elements only by weapons and not by skills, you should be able to use user.atk_elements.empty? ? 1.0 : elements_max_rate(user.atk_elements) in your formula, user being a or whatever you use to identify the caster. Also, you need to make a new snippet of def make_damage_value(user, item) and get rid of the item_element_rate line.

So I guess you'll have

formula = attack - (def% * ele%)

value = damage
value *= pdr etc etc.

---

Alternatively, you can redesign your damage formula just for the attack and redesign make_damage_value so you can calculate reduction. For example:

formula = attack

value = damage
value *= make_damage_reduction(user, item)
value *= pdr etc etc

def make_damage_reduction(user, item)
c = self.def / 1000 # 200 equals 20%
c *= 2.0 - item_element_rate(user, item) # 170% Slash = 30%, then 30 of 20% is 6%
return 1.0 - c # 100% minus 6% equals 94%, 100 -20 is 80%
end

Original thread: https://forums.rpgmakerweb.com/threads/altering-element-rate-to-reduce-defence-instead-of-increasing-damage.76680/