Update: So searching for the root cause hasn't turned up anything as of yet but I'm tired so focus is kind of wavering here. Haven't solved it yet. Power isnt stable here at the moment due to the storm. We'll have to look elsewhere than applyCN. Here's the logic I used
JavaScript:
//==============================
// * apply CN
//==============================
Game_Action.prototype.applyCN = function(target, coopUsers) {
if (Imported.MOG_BossHP) {
if (target.isEnemy() && target._bosshp_meter) {
$gameTemp._battler_bhp_temp[1] = target.hp;
$gameTemp._battler_bhp_temp[3] = 0;
}
}
if (Imported.MOG_Chrono_EnemyHP) {
$gameTemp._chronoEnemyHP[4] = target.hp;
}
var oldhp = target.hp;
var oldmp = target.mp;
var result = target.result();
this.subject().clearResult();
result.clear();
result.used = this.testApply(target);
result.missed = (result.used && Math.random() >= this.itemHit(target));
result.evaded = (!result.missed && Math.random() < this.itemEva(target));
result.physical = this.isPhysical();
result.drain = this.isDrain();
if (result.isHitCR()) {
if (this.item().damage.type > 0) {
result.critical = (Math.random() < this.itemCri(target));
if (coopUsers.length > 0) {
var value = 0;
for (var i = 0; i < coopUsers.length; i++) {
var subject = coopUsers[i].battler();
value += this.makeDamageValueCN(target, result.critical, subject);
}
var realValue = Math.floor(value / coopUsers.length)
value = realValue;
} else {
var value = this.makeDamageValue(target, result.critical);
}
// Checking if new HP after value is returned is less than or equal to 0
if (target.hp <= 0) {
// Call custom function to get alive enemies. Not sure who the author is. Flintx's brother maybe?
var aliveEnemies = Game_Chrono.prototype.getAliveEnemies();
// peeking at the array length for expected value
console.log("Number of alive enemies: " + aliveEnemies.length);
// Checking if the last enemy is going to die.
if (aliveEnemies.length < 1) {
const bat1 = $gameMap.players()[0].battler();
bat1.action = null;
bat1.clearRasCast();
const bat2 = $gameMap.players()[1].battler();
bat2.action = null;
bat2.clearRasCast();
const bat3 = $gameMap.players()[2].battler();
bat3.action = null;
bat3.clearRasCast();
const bat4 = $gameMap.players()[3].battler();
bat4.action = null;
bat4.clearRasCast();
console.log("Purging actions from battlers");
}
}
this.executeDamageCN(target, value);
}
this.item().effects.forEach(function(effect) {
this.applyItemEffect(target, effect);
}, this);
this.applyItemUserEffect(target);
this.afterApplyCN(target, result, oldhp, oldmp);
}
// Get new HP value after damage calculation
var newHP = target.hp;
console.log("New HP value: " + newHP);
};commented lines are those I added in. The logic is sound but it doesn't rectify the problem. It also turns out the function I saw for obtaining an array populated to know how many enemies are left alive is custom in the version I obtained in flintx's thread. It returns correctly so it does do as advertised, here is the function
JavaScript:
Game_Chrono.prototype.getAliveEnemies = function() {
const enemies = [];
for (var i = 0; i < $gameMap.enemiesF().length; i++) {
var battler = $gameMap.enemiesF()[i].battler();
if (!battler.isDead()) {
enemies.push(battler);
};
};
return enemies;
};it appears underneath isAllEnemiesDead function and before Game_Chrono.prototype.update.
was hoping someone else could test this as I don't have a base version of chrono engine at the moment readily accessible, just my modified one which has also been extended in other areas significantly past what flintx and restart had done. If this doesn't work on base we have 2 options, take a step back in the chain and try and force the same approach there or search out the root cause. I'm gonna hit the sack for the night and I'll mess with it some more tomorrow and see what if I can find a thread to pull or something lol. @bass2yang since you said it worked when moving to the target my next step will probably be falling back in the logic chain and seeing if there's a way to approach predicting the enemy's demise there. anyhoo night to yall!
edit: I used the straight forward attack you did bass in this before attempting to iterate through each battler to force the reset for testing purposes. When its all said and done I'd rather iterate through an array though.