[RMMV] State passing from one enemy to another, every turn (using Yanfly perhaps?)

Hello! Need some help conceptualizing this one out.

In essence, I have a skill that applies a debuff state. What I want to add is: for 5 turns, this state will remove itself from current enemy and jump to another enemy.

Here's what I'm thinking of:

1- Skill applies state (duration 1 turn)

2- State to have Custom Apply

Code:
<Custom Apply Effect>

    // Duration of plague
    target._plagueTurns = 5;

</Custom Apply Effect>

3- Every turn, the state removes itself, so in my state, I would also have:

Code:
<Custom Remove Effect>

    // Check if the party is in battle.
    if ($gameParty.inBattle()) {

        // Remove 1 turn from plague duration
        target._plagueTurns -= 1;

        // Plague only jumps if >0 turns left
        if target._plagueTurns > 0 {

            // Get list of all foes
            var members = user.opponentsUnit().aliveMembers();

            // Remove current bearer of plague
            members.splice(members.indexOf(user), 1);

            // Select one member to transfer the plague to
            var member = members[Math.floor(Math.random() * members.length)];

            // Transfer plague state and remaining turns
            member.addState(10);
            member._plagueTurns = user._plagueTurns;

        }

    } else {

        // Not in battle, kill the plague
        user._plagueTurns = 0;

    }

}

</Custom Remove Effect>

Wondering if anyone would approach this one differently?
Edit: I don't think this would work quite the way you're envisioning, because the Custom Remove Effect for each turn after the first will treat the enemy that *currently* has it as target, rather than the original one the state started on.
Edit: I don't think this would work quite the way you're envisioning, because the Custom Remove Effect for each turn after the first will treat the enemy that *currently* has it as target, rather than the original one the state started on.

hmm.. okay, I see what you mean. Have you worked on something similar or have any suggestion?
I think you could take a look at the Yanfly Roaming Mend state from tips and tricks to see how to handle a state that moves to new targets.

Basically, the state is given charges. Each turn a charge is consumed, if another charge exists, then the state is removed from the current affected unit and moved onto a random ally unit, else if no charges exist then it is just removed.

This is handled through the <Custom Apply Effect> and <Custom Remove Effect> and <Custom Deselect Effect>

I think if you read through the note tag for this state and come to understand how it works, with some slight changes, you can make it into what you want.
Yeah, I think I have this. The trick is removing the 1 turn expiry and handling the jump manually. It just means you'll have to remove the state from the old target. Give me 5 and I should have something that works.

Edit: Try this.

Code:
<Custom Apply Effect>
    // Duration of plague
    target._plagueTurns = 5;
</Custom Apply Effect>

<Custom Turn End Effect>
  target._plagueTurns -= 1;
  if (target._plagueTurns > 0) {
    var members = target.friendsUnit().aliveMembers();
    members.splice(members.indexOf(target), 1);
    var member = members[Math.randomInt(members.length)];
    member.addState(24);
    target.removeState(24);
    member._plagueTurns = target._plagueTurns;
    delete target._plagueTurns;
  } else {
    target.removeState(24);
    delete target._plagueTurns;
</Custom Turn End Effect>

Original thread: https://forums.rpgmakerweb.com/threads/rmmv-state-passing-from-one-enemy-to-another-every-turn-using-yanfly-perhaps.123430/