How to set up this damage formula?

I'm not very good with damage formulas, and this one goes beyond my knowledge with them. What I want to achieve is:

If target is affected by State A -> inflict State B. If that foe is already affected by both State A and B -> deal 50% more damage instead.
Untested:
JavaScript:
const A = 5, B = 6;  // state IDs
let r = a.atk * 4 - b.def * 2;  // damage formula
if (b.isStateAffected(A)) {
  if (b.isStateAffected(B)) r *= 1.5;  // has both states => 150% damage
  else b.addState(B);  // has A, not B => add B
}
r  // output value
Compacted to a single line for the damage formula:
Spoiler: Damage formula
JavaScript:
const A = 5, B = 6; let r = a.atk * 4 - b.def * 2; if (b.isStateAffected(A)) { if (b.isStateAffected(B)) r *= 1.5; else b.addState(B); }; r
Edit the values assigned to A, B, and r to alter the result. These are temporary variables for convenience; they do not exist outside of the damage formula. 🙂
Untested:
JavaScript:
const A = 5, B = 6;  // state IDs
let r = a.atk * 4 - b.def * 2;  // damage formula
if (b.isStateAffected(A)) {
  if (b.isStateAffected(B)) r *= 1.5;  // has both states => 150% damage
  else b.addState(B);  // has A, not B => add B
}
r  // output value
Compacted to a single line for the damage formula:
Spoiler: Damage formula
JavaScript:
const A = 5, B = 6; let r = a.atk * 4 - b.def * 2; if (b.isStateAffected(A)) { if (b.isStateAffected(B)) r *= 1.5; else b.addState(B); }; r
Edit the values assigned to A, B, and r to alter the result. These are temporary variables for convenience; they do not exist outside of the damage formula. 🙂
Thanks. Works like a charm. 😀

Original thread: https://forums.rpgmakerweb.com/threads/how-to-set-up-this-damage-formula.128830/