MV Reverse Logic for Damage/Recovery Sounds during Damage Popup, But Only for MP/TP

So, I'm using TP and MP as anti-resources--gauges that inflict debuffs when they get high, and build up when using skills, as opposed to counters that define how much you get to use skills.

The issue is that when you "heal" one (increasing it, which is a bad thing mechanically), when it draws the damage popup (well, heal popup, but I think they're the same thing internally), it plays the database's defined "Recovery" sound. I need it to... not do that. Play the damage sound, ideally.

In other words:

Default Functionality
During damage popup:
-When taking HP Damage, plays "Actor Damage" sound.
-When taking MP or TP Damage, plays no sound for some reason
-When taking Healing, plays "Recovery" sound, regardless of gauge.

Desired Result
During damage popup:
-When taking HP Damage, play "Actor Damage" sound.
-When taking MP or TP Healing, play "Actor Damage" sound (or no sound at all, if need be).
-When taking HP Healing, play "Recovery" sound.
-When taking MP or TP Damage, play "Recovery" sound.

Bonus point for being able to set separate damage sounds for each resource? But mostly I just need to reverse the logic for TP and MP. I know next to nothing about javascript or RMMV's code, sadly, so if someone goes through the trouble to hammer this out, I'd be very thankful.
It's just a matter of reversing some math operators in the default functions. Paste the below into a text editor, save as a *.js file, include as a plugin.
Code:
Window_BattleLog.prototype.displayMpDamage = function(target) {
    if (target.isAlive() && target.result().mpDamage !== 0) {
        if (target.result().mpDamage > 0) {
            this.push('performRecovery', target);
        }
        this.push('addText', this.makeMpDamageText(target));
    }
};

Window_BattleLog.prototype.displayTpDamage = function(target) {
    if (target.isAlive() && target.result().tpDamage !== 0) {
        if (target.result().tpDamage > 0) {
            this.push('performRecovery', target);
        }
        this.push('addText', this.makeTpDamageText(target));
    }
};

Window_BattleLog.prototype.makeMpDamageText = function(target) {
    var result = target.result();
    var damage = result.mpDamage;
    var isActor = target.isActor();
    var fmt;
    if (damage > 0 && result.drain) {
        fmt = isActor ? TextManager.actorDrain : TextManager.enemyDrain;
        return fmt.format(target.name(), TextManager.mp, damage);
    } else if (damage < 0) {
        fmt = isActor ? TextManager.actorLoss : TextManager.enemyLoss;
        return fmt.format(target.name(), TextManager.mp, -damage);
    } else if (damage > 0) {
        fmt = isActor ? TextManager.actorRecovery : TextManager.enemyRecovery;
        return fmt.format(target.name(), TextManager.mp, damage);
    } else {
        return '';
    }
};

Window_BattleLog.prototype.makeTpDamageText = function(target) {
    var result = target.result();
    var damage = result.tpDamage;
    var isActor = target.isActor();
    var fmt;
    if (damage < 0) {
        fmt = isActor ? TextManager.actorLoss : TextManager.enemyLoss;
        return fmt.format(target.name(), TextManager.tp, -damage);
    } else if (damage > 0) {
        fmt = isActor ? TextManager.actorGain : TextManager.enemyGain;
        return fmt.format(target.name(), TextManager.tp, damage);
    } else {
        return '';
    }
};
Dang, you were ready.

So, this does cause damage to play the healing sound. However, healing still plays the healing sound, meaning it only half-worked.

...on my main project. On a clean project, it plays the healing sound on damage, and no sound on healing. So... now I get to figure out which plugin is causing a conflict.

I didn't even think that was a possibility, because none of my plugins seem to interact with sounds? I have VE Core (the command menu customization plugin is its only plugin I have, lmao), Yanfly Core and Battle Engine Core, and... a lot of others, but those are the only ones I can imagine causing a conflict.

Uh, I'll attach the plugins I'm using in case something stands out, while I test.

EDIT: Yanfly Battle Engine Core seems to be the culprit, as it also messes with the functions your plugin edits. Commenting out the relevant lines doesn't seem to change anything, though...


EDIT 2: OKAY, GOT IT. So, the culprit was this:


JavaScript:
Game_Battler.prototype.performResultEffects = function() {
    var result = this.result();
    if (result.missed && result.physical) this.performMiss();
    if (result.evaded) {
      if (result.physical) {
        this.performEvasion();
      } else {
        this.performMagicEvasion();
      }
    }
    if (result.hpAffected) {
      if (result.hpDamage > 0 && !result.drain) {
        this.performDamage();
      }
      if (result.hpDamage < 0) {
        this.performRecovery();
      }
    }
    if (this.isAlive() && result.mpDamage !== 0 && result.mpDamage < 0) {
      this.performRecovery();
    }
    if (this.isAlive() && result.tpDamage !== 0 && result.tpDamage < 0) {
      this.performRecovery();
    }
};

At the end there, it checks if it's doing 'negative damage' and if so, performs recovery. Independently of the damage popup code. For some reason.

I commented that part out, and your plugin now works perfectly. Thank you for your help, friend. If I need to attach a damage sound, I can probably use action sequences to play one during action effect.
I commented that part out, and your plugin now works perfectly.
Well, the code is there for a reason - I'm not looking at it at the moment, but it's probably to make popups appear that don't appear in the default code or something like that.

I'd suggest rather than commenting them out, just turn the math operators around to make the logic correct for you.
this is wholly fair--if problems arise I'll do just that

oh yeah--this problem is solved; I believe threads like that are meant to be closed, though I'm not sure how to tag it that way
You Report the first post and say it's solved.

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/reverse-logic-for-damage-recovery-sounds-during-damage-popup-but-only-for-mp-tp.159680/