I'm trying to make a plugin that speeds up the pace at which the action bars fill up in MZ's TPB ("ATB") battle systems. Since this is meant to just be a convenience that cuts out unnecessary waiting, it's important that the turn order stays exactly the same.
I took the following method from the core scripts:
...and I aliased it as such:
For now, this is the only method in the plugin.
In order to test the plugin, I assigned each Actor a considerably different AGI, and tested a battle against a troop (using the same Troop each time). In order to prevent the randomization of the starting TPB gauge fill value, and start it at 0 instead for all battlers, I added a troop event that paralyzes all Actors and all Enemies for 1 turn, on "turn 0" (the start of battle).
First, I tested without the plugin (in TPB Wait Mode). The faster battlers lost their Paralyze states first and then their TPBs started to fill. As expected, Actor 2 (the highest-AGI battler) went first, then Actor 1, then 3, then 4. Then 2 again, and so on; Actor 2 eventually lapped 4, and the TPB behaved as I would expect.
Then, I tested with the plugin, and with the Speed Multiplier parameter (wave_lapse.normal_mult) set to 10. It looked like this time Actor 1 lost his Paralyze status first (though it was very close), and even more strangely, Actor 1 received the first turn! Then Actor 2, then 3, then 4. Repeated tests with 10x speed showed the same exact thing happening.
Thinking that maybe I did something wrong with my code, I tried a third test with the plugin but with the Speed Multiplier parameter set to 1. Behavior was exactly the same as what happened when the plugin was not installed, so I don't think I made any kind of coding/logic error.
Throwing some debug messages to the console (pasting the code I used to do this below, but it's only relevant if you want to try it yourself), it looks like actors' TPBs are moving up the correct amount with each tick - for example, with the Parameter set to 1, Actor 2's TPB charge increases by 0.01666 each frame, whereas when it's set to 10, Actor 2's TPB charge increases by 0.16666 each frame (exactly 10x the amount). Actors seem to correctly gain a turn whenever their TPB increases to 1.000 or above, although there is likely a 1 frame delay (probably because of the way battle flow is handled in the core scripts).
I played around with a bunch of different numbers for the Parameter: When using 1 through 9, Actor 2 (correctly) received the first turn, and all numbers 10 and above (including a really high multiplier like 38) caused Actor 1 to go first instead.
I have been looking through the code for hours now and I can't figure out why this is happening!!
Can anyone help me figure out what is causing Actor #1 to get their turn faster than Actor #2 whenever the multiplier is high enough? Is there something in the base code that would cause only the first Actor to lose a state during a tick in the TPB when two Actors are due to lose a state during that tick? Is there something else in the code base that could cause this slightly different turn order when the TPB meters are set to fill at many times their normal rates?
Thanks so much for any help or thoughts you can offer. This one's really been vexing me!
I took the following method from the core scripts:
JavaScript:
Game_Battler.prototype.tpbAcceleration = function() {
const speed = this.tpbRelativeSpeed();
const referenceTime = $gameParty.tpbReferenceTime();
return speed / referenceTime;
};
...and I aliased it as such:
JavaScript:
Game_Battler.prototype.tpbAcceleration_lapse = Game_Battler.prototype.tpbAcceleration;
Game_Battler.prototype.tpbAcceleration = function() {
// Run the old version of this method to get what the TPB Gain would be without any further modifications
var orig_accel = this.tpbAcceleration_lapse.call(this);
// Multiply the TPB Gain by the Normal Multiplier specified in this plugin's parameters
var final_accel = orig_accel * wave_lapse.normal_mult;
// Now that all calculations have been done, return the amount of TPB Gain calculated
return final_accel;
};
For now, this is the only method in the plugin.
In order to test the plugin, I assigned each Actor a considerably different AGI, and tested a battle against a troop (using the same Troop each time). In order to prevent the randomization of the starting TPB gauge fill value, and start it at 0 instead for all battlers, I added a troop event that paralyzes all Actors and all Enemies for 1 turn, on "turn 0" (the start of battle).
First, I tested without the plugin (in TPB Wait Mode). The faster battlers lost their Paralyze states first and then their TPBs started to fill. As expected, Actor 2 (the highest-AGI battler) went first, then Actor 1, then 3, then 4. Then 2 again, and so on; Actor 2 eventually lapped 4, and the TPB behaved as I would expect.
Then, I tested with the plugin, and with the Speed Multiplier parameter (wave_lapse.normal_mult) set to 10. It looked like this time Actor 1 lost his Paralyze status first (though it was very close), and even more strangely, Actor 1 received the first turn! Then Actor 2, then 3, then 4. Repeated tests with 10x speed showed the same exact thing happening.
Thinking that maybe I did something wrong with my code, I tried a third test with the plugin but with the Speed Multiplier parameter set to 1. Behavior was exactly the same as what happened when the plugin was not installed, so I don't think I made any kind of coding/logic error.
Throwing some debug messages to the console (pasting the code I used to do this below, but it's only relevant if you want to try it yourself), it looks like actors' TPBs are moving up the correct amount with each tick - for example, with the Parameter set to 1, Actor 2's TPB charge increases by 0.01666 each frame, whereas when it's set to 10, Actor 2's TPB charge increases by 0.16666 each frame (exactly 10x the amount). Actors seem to correctly gain a turn whenever their TPB increases to 1.000 or above, although there is likely a 1 frame delay (probably because of the way battle flow is handled in the core scripts).
JavaScript:
Game_Battler.prototype.updateTpbChargeTime = function() {
if (this._tpbState === "charging") {
this._tpbChargeTime += this.tpbAcceleration();
console.log(this.name() + "'s Charge is " + String(this._tpbChargeTime));
if (this._tpbChargeTime >= 1) {
this._tpbChargeTime = 1;
this.onTpbCharged();
}
}
};
I played around with a bunch of different numbers for the Parameter: When using 1 through 9, Actor 2 (correctly) received the first turn, and all numbers 10 and above (including a really high multiplier like 38) caused Actor 1 to go first instead.
I have been looking through the code for hours now and I can't figure out why this is happening!!
Can anyone help me figure out what is causing Actor #1 to get their turn faster than Actor #2 whenever the multiplier is high enough? Is there something in the base code that would cause only the first Actor to lose a state during a tick in the TPB when two Actors are due to lose a state during that tick? Is there something else in the code base that could cause this slightly different turn order when the TPB meters are set to fill at many times their normal rates?
Thanks so much for any help or thoughts you can offer. This one's really been vexing me!