VXAce Help with this damage formula

Happy halloween to everyone! I had a custom formula for my game. I wanted to take inspiration from the ttrpg game manual that I brought through Amazon called Fabula Ultima.
In the section of the status page it says:
"A character (whether PC or NPC) can suffer from various status ailments during the game, which are often the direct consequence of attacks or spells.
The ailments are:
-Poisoned: Temporarily reduces Might and Willpower dice by one size.
-Confused: Temporarily reduces your Insight die by one size.
-Weak: Temporarily reduces your Might die by one size.
-Enraged: Temporarily reduces your Dexterity and Insight die by one size.
-Slow: Temporarily reduces your Dexterity die by one size.
-Shaken: Temporarily reduces your Willpower die by one size.

Different statuses that affect the same ability are cumulative: for example, being confused and furious reduces the Insight die by two sizes.

However, a characteristic can never be reduced below d6."
So I had first a script from this jappan site: https://tm.yumineko.com/viewtopic.php?t=5855
it's a module that simulate the dice system.
I tried with this one:
I tried with this:
`` def dex(a,b,power)
case power
when power === 12
if b.state?(2) || b.state?(4)
power = 12 - 2
elsif
b.state?(2) && b.state?(4)
power = 12 - 4
else
power = 12
end
when power === 10
if b.state?(2) || b.state?(4)
power = 10 - 2
elsif
b.state?(2) && b.state?(4)
power = 10 - 4
else
power = 10
end
when power === 8
if b.state?(2) || b.state?(4)
power = 8 - 2
else
power = 8
end
when power === 6
power = 6
end
end``

But the damage is resulted 0 or they don't take damage.
Where did I get wrong?
Can you help me out?
Please edit your post and place the code into code-tags, that will keep the correct indentions and make it readable - at the moment that is difficult to do.

and what are the '' at the beginning and the end? They can't be part of the code because that would turn this code into a string...

EDIT:
just to add an explanation:
If the damage formula contains a code error (including a syntax typo), the damage result defaults to zero instead of creating the usual error messages.
Please edit your post and place the code into code-tags, that will keep the correct indentions and make it readable - at the moment that is difficult to do.

and what are the '' at the beginning and the end? They can't be part of the code because that would turn this code into a string...

EDIT:
just to add an explanation:
If the damage formula contains a code error (including a syntax typo), the damage result defaults to zero instead of creating the usual error messages.
For now let's put aside this sub formula here: dice(1,y)
and let's concetrate for the "y".

I have a character with a dexterity of d12 as a characteristic
But when he's under the "Enraged" status, his Dexterity value drop to d10.
And when is added the status "Slow" in this character, the dice value is dropped to d8.

But let's think of what will happen when this character had a Willpower of d8.
One of the status ailment can actually reduce the d8 to d6, but two of them can't cause the dice is on d6 and can't go any further.

Please edit your post and place the code into code-tags, that will keep the correct indentions and make it readable - at the moment that is difficult to do.

and what are the '' at the beginning and the end? They can't be part of the code because that would turn this code into a string...

EDIT:
just to add an explanation:
If the damage formula contains a code error (including a syntax typo), the damage result defaults to zero instead of creating the usual error messages.
I added the tags too

Original thread: https://forums.rpgmakerweb.com/threads/help-with-this-damage-formula.180798/