I'm working on a Plugin that allows for, essentially, counterattacks to happen before the original attack, but the original attack to still come through.
As an example, if Bat A attacks Harold, then Harold immediately counterattacks (without automatic evasion). If Bat A is still alive, then Bat A's original attack continues.
I've got pretty well everything figured out except how to get the actions to wait for each other to complete.
A super simplified version of what I'm attempting at the moment is the following:
The problem is, the animation, damage popup, processing, etc., all happen simultaneously. It looks like what I want to do is tell the BattleManager._logWindow to wait somehow, but trying to push "waitForMovement", "waitForEffect", or "waitForNewLine" does no good. In fact, I've tried about a billion combinations of wait - waitForUpdate, changing the waitCount property, calling wait, pushing every possible wait function defined - I just can't get it to work.
I've tried making a Window_BattleLog.prototype method that calls BattleManager._invokeAction, and trying to do something with setWaitMode that would then make the invokeAction call a method in the stack that updateWait can eventually call via callNextMethod, but that hasn't worked out, either.
The only thing I've been able to get to work is to do something like:
Does exactly what I want it to do, except it assumes that every counterattack will take 1.2 seconds, so if I ever want to modify how a Battler counterattacks, it won't work. It's basically a non-solution.
EDIT: Well... I guess nevermind. I went back and tried this again:
And it worked just fine. No idea why I couldn't get the same thing to work earlier. Yay coding late at night.
As an example, if Bat A attacks Harold, then Harold immediately counterattacks (without automatic evasion). If Bat A is still alive, then Bat A's original attack continues.
I've got pretty well everything figured out except how to get the actions to wait for each other to complete.
A super simplified version of what I'm attempting at the moment is the following:
Code:
BattleManager._invokeAction = BattleManager.invokeAction;
BattleManager.invokeAction = function(subject, target) {
BattleManager.invokeCounterAttack(subject, target);
if (subject.hp <= 0) { return; }
BattleManager._invokeAction.call(this, subject, target);
}
The problem is, the animation, damage popup, processing, etc., all happen simultaneously. It looks like what I want to do is tell the BattleManager._logWindow to wait somehow, but trying to push "waitForMovement", "waitForEffect", or "waitForNewLine" does no good. In fact, I've tried about a billion combinations of wait - waitForUpdate, changing the waitCount property, calling wait, pushing every possible wait function defined - I just can't get it to work.
I've tried making a Window_BattleLog.prototype method that calls BattleManager._invokeAction, and trying to do something with setWaitMode that would then make the invokeAction call a method in the stack that updateWait can eventually call via callNextMethod, but that hasn't worked out, either.
Code:
BattleManager._invokeAction = BattleManager.invokeAction;
BattleManager.invokeAction = function(subject, target) {
BattleManager.invokeCounterAttack(subject, target);
if (subject.hp <= 0) { return; }
// Here I've tried logWindow.wait(), logWindow.push('waitForNewLine'), etc.
BattleManager._logWindow.push('invokeAction', subject, target);
}
Window_BattleLog.prototype.invokeAction = function(subject, target) {
BattleManager._invokeAction.call(BattleManager, subject, target);
};
The only thing I've been able to get to work is to do something like:
Code:
BattleManager._invokeAction = BattleManager.invokeAction;
BattleManager.invokeAction = function(subject, target) {
BattleManager.invokeCounterAttack(subject, target);
if (subject.hp <= 0) { return; }
setTimeout(() => BattleManager._invokeAction.call(this, subject, target), 1200);
Does exactly what I want it to do, except it assumes that every counterattack will take 1.2 seconds, so if I ever want to modify how a Battler counterattacks, it won't work. It's basically a non-solution.
EDIT: Well... I guess nevermind. I went back and tried this again:
Code:
BattleManager._invokeAction = BattleManager.invokeAction;
BattleManager.invokeAction = function(subject, target) {
BattleManager.invokeCounterAttack(subject, target);
if (subject.hp <= 0) { return; }
BattleManager._logWindow.push('invokeAction', subject, target);
}
Window_BattleLog.prototype.invokeAction = function(subject, target) {
BattleManager._invokeAction.call(BattleManager, subject, target);
};
And it worked just fine. No idea why I couldn't get the same thing to work earlier. Yay coding late at night.