YEP auto passive state about removing and reseting a passive state?

Im trying to make enemies have a built in resistance to certain states but can be broken,
for example:
Enemy A has resistance to psn at rank II,
I made 2 states called resist psn I and resist psn II. Both do nothing except resist psn 100%.
What happens if you cast psn on enemy A, that enemy is not psn but resist psn II is replaced with resist psn I. Repeat for resist psn I to then be removed.
Finally if you cast psn now the enemy will be psn.

What I can't figure out is next:
After psn wears off/removed I want the enemy to restart the stack and regain resist psn II again.
I think to make this possible, you'll need to have a passive state that remains the entire time, as well as include code in the psn state to check for that passive. What exactly is your code so far? Because excluding the psn state, you'll need three other states to made this work, I think.
I think to make this possible, you'll need to have a passive state that remains the entire time, as well as include code in the psn state to check for that passive. What exactly is your code so far? Because excluding the psn state, you'll need three other states to made this work, I think.

I just figured out or I think I did it works for now lol but its incredibly complicated and wondering if theres a more elegant solution because it makes coding my skills a ton more work.

So psn skill does this:
if (b.isStateAffected(Resistpsn1)) {
dmg
b.removeState(Resistpsn1)
b.addState(removepsn)
else
dmg
b.addState(psn)
b.removeState(removepsn)

Enemy has passive:
<Passive State: Resistpsn1>

Resistpsn1 state has:
Traits: State resist: Psn
<Custom Passive Condition>
if (!user.isStateAffected(psn) &&
!user.isStateAffected(removepsn)) {
condition = true;
} else {
condition = false;
}
</Custom Passive Condition>

So my psn both adds psn and removes the state holder that allows psn to be removed. My Resistpsn1 state has condition if neither psn or removepsn is applied then the conditions are met and state is applied, if it has either of those states then it is not applied.
Removepsn state does nothing but is used to be check, as you suggested. I welcome anyone who can make this cleaner lol if not I have my solution.
You could potentially use variables and have attacks have a random chance to raise said variable so that the target can resist states but I don't think you'll find a solution shorter or cleaner than what you have for the most part.

Original thread: https://forums.rpgmakerweb.com/threads/yep-auto-passive-state-about-removing-and-reseting-a-passive-state.97203/