MV Per-Action Turn Order System

Hi,

I was testing my game, and discovered something about the design of MV's engine : The turn order is battler based.
This is bad. Because of two mechanics : Speed and Action Times +

Skill priority is a mechanic that I use in my game : Wind attacks have high priority, Basic attacks have higher priority, and Guard have the highest priority.
But right now, a battler with Action Times+ doesn't benefit from guard priority, as the makeSpeed() function takes the lowest speed. I tried to invert and pick the highest speed instead, but then the battlers hacks the system by guarding first then inputting two extra slow actions before everyone.

What I want is that if A does [Guard, Attack, Attack], B does [Attack,Wind,Fire] and C does [Fire,Attack,Attack], and that in terms of AGI we have C>B>A, then the turn order should be ACCBAABCB

But right now it's AAABBBCCC and this is very bad, strategically speaking and gamedesign wise.

Do you happen to know a solution to setup a proper per-action order system ? Maybe a plugin already exists ? Couldn't find it.


================== MORE INFORMATION ====================
I tried coding it myself :
The idea was to allow duplicates in the BattleManager._actionBattlers array, so it should work with Yanfly's Turn Order Display (like showing the battlers multiple times on the track if they have more than one action)
JavaScript:
BattleManager.makeActionOrders = function() {
    var battlers = [];
    var order = [];
    this._sortedActions = [];
    if (!this._surprise) {
        battlers = battlers.concat($gameParty.members());
    }
    if (!this._preemptive) {
        battlers = battlers.concat($gameTroop.members());
    }
    battlers.forEach(function(battler) {
        battler.makeSpeed(); //makeSpeed is edited to just push the battler's actions into this._sortedActions
    });
    this._sortedActions.sort(function(a, b) {
        return b.speed() - a.speed(); // I sort the actions by speed
    });
    this._sortedActions.forEach(function(action) {
       order.push(action.subject()); // I create the turn order, allowing duplicates, based on the sorted actions
    });
    this._actionBattlers = order;
};

I also barely edited BattleManager.processTurn so it changes subject at the end of each action
And finally, I edited Yanfly's BattleManager.getNextSubject to get rid of the performedBattlers stuff preventing duplicates in the battlers order.


You guess that if I'm posting, it's because it doesn't work. For some reason, my method messes with Window_BattleLog.performActionStart, called all the way down from Yanfly's updateActionList
1721663757472.png


PS : No ATB, I don't want a tick-based battle system
No, I have never seen a system that breaks up multiple skills entered via Action Times+.
maybe try showing all the edits youve made? there might be a minor detail somewhere being overlooked.
i havent poked around the turn order segments in a while but if im not mistaken...

I also barely edited BattleManager.processTurn so it changes subject at the end of each action
this already happens between the base engine and yanfly's battle core, no?

I edited Yanfly's BattleManager.getNextSubject to get rid of the performedBattlers stuff preventing duplicates in the battlers order.
makes perfect sense, but...
so it should work with Yanfly's Turn Order Display (like showing the battlers multiple times on the track if they have more than one action)
iirc the turn order plugin was also written so that a battler is shown once in the turn order. which means theres edits there youve also made and didnt mention? When i had initially looked into it for my own project months back, i did see that it does touch on a few BattleManager values, but i certainty wouldnt remember how or why by now 😛

For some reason, my method messes with Window_BattleLog.performActionStart, called all the way down from Yanfly's updateActionList
odd. you might have to use breakpoints to pinpoint that error. I didnt think anything other than the BEC winds up there when its installed, and between the description of the changes and that, everything sounds like it should be in order.

I cant look into any of it now, but id provide extra details like the full list of edits, plugin manager screenshots, etc
maybe try showing all the edits youve made? there might be a minor detail somewhere being overlooked.
i havent poked around the turn order segments in a while but if im not mistaken...


this already happens between the base engine and yanfly's battle core, no?


makes perfect sense, but...

iirc the turn order plugin was also written so that a battler is shown once in the turn order. which means theres edits there youve also made and didnt mention? When i had initially looked into it for my own project months back, i did see that it does touch on a few BattleManager values, but i certainty wouldnt remember how or why by now 😛


odd. you might have to use breakpoints to pinpoint that error. I didnt think anything other than the BEC winds up there when its installed, and between the description of the changes and that, everything sounds like it should be in order.

I cant look into any of it now, but id provide extra details like the full list of edits, plugin manager screenshots, etc
Thanks for your reply.


I am working on a fresh project, with only BEC active. Once I manage to have a working per-action turn order system, only then I will edit the Turn Order Display plugin (or disable it if it is not possible/too much work. It's non-essential)

Here's is every edit I made :

rpg_managers.js :
JavaScript:
BattleManager.makeActionOrders = function() {
    var battlers = [];
    var order = [];
    this._sortedActions = [];
    if (!this._surprise) {
        battlers = battlers.concat($gameParty.members());
    }
    if (!this._preemptive) {
        battlers = battlers.concat($gameTroop.members());
    }
    battlers.forEach(function(battler) {
        battler.makeSpeed(); //makeSpeed is edited to just push the battler's actions into this._sortedActions
    });
    this._sortedActions.sort(function(a, b) {
        return b.speed() - a.speed(); // I sort the actions by speed
    });
    this._sortedActions.forEach(function(action) {
       order.push(action.subject()); // I create the turn order, allowing duplicates, based on the sorted actions
    });
    this._actionBattlers = order;
};

JavaScript:
BattleManager.processTurn = function() {
    var subject = this._subject;
    var action = subject.currentAction();
    if (action) {
        action.prepare();
        if (action.isValid()) {
            this.startAction();
        }
        subject.removeCurrentAction();
        if (this._actionBattlers.indexOf(subject) < 0) { //Battler not in array = it was their last action
            subject.onAllActionsEnd();
            this.refreshStatus();
            this._logWindow.displayAutoAffectedStatus(subject);
            this._logWindow.displayCurrentState(subject);
            this._logWindow.displayRegeneration(subject);
        }
    }
    this._subject = this.getNextSubject();
};


YEP_BattleEngineCore.js :

JavaScript:
BattleManager.getNextSubject = function() {
    if ($gameTroop.turnCount() <= 0) return;
    this.makeActionOrders();
        var battler = this._actionBattlers.shift();
        if (!battler) return null;
        if (battler.isBattleMember() && battler.isAlive()) {
            return battler;
        }
        return null; //Added this for protection
}; //Like I said, I scraped the whole performedBattlers thing.

As for breakpoints, I don't know where to put them. The only info I have is that once the _actionBattlers is empty some Yanfly script's still running, idk which one or how, so updateActionList continues to do stuff with empty data...
I don't know if you will be interested, but some times ago I tried to fix the same issue on MZ.


You will probably have compatibility issues with other battle plugins, but maybe you can get some inspiration from this.
I don't know if you will be interested, but some times ago I tried to fix the same issue on MZ.


You will probably have compatibility issues with other battle plugins, but maybe you can get some inspiration from this.
MARVELOUS

I have no knowledge of MZ engine but maybe porting it to MV won't be that hard

Help from MV coders would be much appreciated !

EDIT : I looked into the code, and while the idea of re-sort thea action by speed, the turn order is still per-battler 🙁


It should not be hard, I only edited 3 functions and it looked like it's the only thing I needed, but I disabled BEC and the error codes now looks like this :

There seem to be a problem with how targets are updated, but idk where to look


EDIT : I managed to code a working turn order based on actions. But for some reason, when I use "Force Action" in a troop event, the _list array in the interpreter is not cleared, making $gameTroop.isEventRunning() permanently true, and preventing stuff like victory process :/


Here's my code as a plugin :
Bump, after a week of debugging, I think I found what's the issue : The turnEnd phase doesn't proc correctly... ?

I mean, even "Turn End" troop events proc only once. And the _list array in the interpreter is event not cleared afterwards.

That's where I'm left with. I don't know what might be the issue here. Other than that the turn order works as intended.

Original thread: https://forums.rpgmakerweb.com/threads/per-action-turn-order-system.170520/