Detonation Damage Formula

Hey guys, I am having a bit of a problem coming up with a working damage formula for a detonation spell and would like some help. Here's what I am trying to do:

IF (enemy has state "burn") THEN (deal magic damage x 2) AND (remove state "burn") ELSE (deal magic damage x1)

I'm having trouble with the AND part specifically, fitting multiple THEN effects into my formula before the else.

The formula looks like this but I am unsure of which symbol to use for AND:

b.isStateAffected(13) ? (100 + a.mat * 4 - b.mdf * 2) b.removeState(13): (100 + a.mat * 2 - b.mdf * 2)

Any assistance is appreciated!
You don't have to remove the "burn" state through the damage formula. You can do it via the "Effects" panel below it.
Spoiler
Capture.PNG


But for learning purposes you can do this:
Code:
b.isStateAffected(13) ? function() { b.removeState(13); return 100 + a.mat * 4 - b.mdf * 2; }() : 100 + a.mat * 2 - b.mdf * 2

Here's what I did:
First of all, the following pattern is called the "conditional operator":
Code:
condition ? expression1 : expression2

In order to perform multiple actions inside an expression, you need to make it a function, like this:
Code:
condition ? function() { action1; action2; ... }() : expression2
Each action must be separated by a semicolon ( ; )

"function" is a keyword for defining functions. It is followed by round brackets () that may contain arguments within. It is also followed by curly brackets {} inside which you put the code you want to run. The round brackets after the curly ones are a bit special; they're here to indicate that we want the function to run. Without those final round brackets, we only defined the function, but we're not running it yet.

Since your formula is now inside a function, it must be returned from that function. That's where the "return" keyword comes in. It's basically saying "this is the result of my function".

The problem with "return", is that it marks the end of a function, so any code that comes after it won't be executed, which is why we have to remove the burn state before we return the damage formula.
Thanks Nolonar, I appreciate you taking time to explain function for me!

So to get a little bit more complex, say I wanted to make 'detonate' consume all the debuffs on the enemy, and do a set amount of damage for each debuff consumed. Is it possible to do this within a single damage formula string?

EDIT: In case anybody was wondering, I used Yanfly Action Sequence Packs 1 and 2 to do the following:

<Target Action>

if target.isStateAffected(13)

animation 13: target

wait for animation

action effect: target

REMOVE STATE 13: target

end

if target.isStateAffected(14)

animation 13: target

wait for animation

action effect: target

REMOVE STATE 14: target

end

if target.isStateAffected(15)

animation 13: target

wait for animation

action effect: target

REMOVE STATE 15: target

end

if target.isStateAffected(16)

animation 13: target

wait for animation

action effect: target

REMOVE STATE 16: target

end

</Target Action>

Original thread: https://forums.rpgmakerweb.com/threads/detonation-damage-formula.93797/