Damage formula, with two variables that stack.

Greetings and salutations, sages and scholars of RPG Maker forums!
I come to you with another damage formula related woe.

The idea behind this one is that damage is increased if an enemy has a state applied, but also if the character attacking has another state applied to them.
The main problem I have is that I want these two states to be independent, both increasing damage on their own, but stacking.
So, if enemy has state X on them he will take 200% damage. If the character has a state Y whilst he attacks the enemy he will deal 200% damage, but if the character has the Y state whilst enemy is afflicted with X, the enemy will take 300% damage.

Here is my pathetic attempt at creating a formula that would reflect it.
const m = b._states.filter(s=>[4].includes(s)).length; m ? m*(a.atk * 6) && if (a.isStateAffected(26)) { a.atk * 6 } else { a.atk * 3 }
I will greatly appreciate help with this, as I always do. I thank all responders in advance.
I'd try something like this:

a.atk * 3 * [4, 5].reduce(function(t, c) { return t + (b.isStateAffected(c) ? 1 : 0); }, 1)
I.e.
  • Damage equals subject's ATK, times 3, times another multiplier:
    • Multiplier starts at 1, and
    • Gets +1 for each state from the list [4, 5] by which the target is currently affected.
Here's some technical info on the reduce method I've used, in case you're interested:
I'd try something like this:

a.atk * 3 * [4, 5].reduce(function(t, c) { return t + (b.isStateAffected(c) ? 1 : 0); }, 1)
I.e.
  • Damage equals subject's ATK, times 3, times another multiplier:
    • Multiplier starts at 1, and
    • Gets +1 for each state from the list [4, 5] by which the target is currently affected.
Here's some technical info on the reduce method I've used, in case you're interested:
Quick question; does "t" and "c" stand for something specific? Is it a stand-in for some formula or a needed part of the equation?
Can't you just do something like
Code:
a.atk + (a.isStateAffected(14) ? a.atk : 0) + (b.isStateAffected(15) ? a.atk : 0)
?

So, if no one has any states it will do a.atk damage, if a has state 14 it will add another a.atk damage, and if b has state 15 it will add another lot of a.atk damage.
Can't you just do something like
Code:
a.atk + (a.isStateAffected(14) ? a.atk : 0) + (b.isStateAffected(15) ? a.atk : 0)
?

So, if no one has any states it will do a.atk damage, if a has state 14 it will add another a.atk damage, and if b has state 15 it will add another lot of a.atk damage.
It does work! Many thanks.
You could also take advantage of the way boolean is handled with numbers (boolean arithmetic):
JavaScript:
a.atk * (1 + a.isStateAffected(14) + b.isStateAffected(15))
I would use reduce() as @caethyril suggests for when you have a need for multiple states between the user (a) and the target (b):
JavaScript:
a.atk * [4, 5, 11, 26, 37, 49].reduce((t, c) => t + a.isStateAffected(c) + b.isStateAffected(c), 1);
Modify as needed but it will account for any of those states between the user and target to increase the multiplication of the attack power.

Spoiler
For readability, I would build a function and save it as a plugin instead and then call it in the formula:
JavaScript:
function dmgForm(a, b, arr) {
    return a.atk * arr.reduce((t, c) => t + a.isStateAffected(c) + b.isStateAffected(c), 1);
}
Then in the damage formula, do this:
JavaScript:
dmgForm(a, b, [4, 5, 11, 26, 37, 49]);
Quick question; does "t" and "c" stand for something specific?
They're what I've named the arguments of the callback function used in reduce. I was thinking t for "total multiplier" and c for "current state ID".

Can't you just do something like
Yep! Just different syntax. I'm just pathologically averse to repeating myself. 😊

You could also take advantage of the way boolean is handled with numbers
Ew. Uh, I mean...what an elegant use of type-coercion!
Ew. Uh, I mean...what an elegant use of type-coercion!
Haha! I'm "js" kidding...

Also... I have failed the masters...
@caethyril That reminds me of Zombie's thread the other day when I was checking to see that, in fact,
Code:
let array = [15];
array == 15;
and it made me wince so hard I strained an eyelid 😛
let array = [15]; array == 15;
between null being an object, NaN being a number, and 9999999999999999999===9999999999999999236 being true ive come to accept that if it sounds like a warcrime, js probably says its ok 🤣

Original thread: https://forums.rpgmakerweb.com/threads/damage-formula-with-two-variables-that-stack.174090/