Skill that does damage based on # of ailments

Howdy all, me again, with another silly question.

I was thinking about giving one of my characters a skill that did more damage based on the amount of status ailments on the enemy. And thinking for simplicity's sake, I'd probably keep it to the basic ailments (Poison, Blind, Confusion, ect).
You can add this as a new plugin or add the functions to Game_BattlerBase.

JavaScript:
/*:
 * @plugindesc Adds a function to count the number of states on a battler within a given range of IDs.
 */
(function() {
    Game_BattlerBase.prototype.countStatesRange = function(x, y) {
        var count = 0;
        for (var i = x; i <= y; i++) {
            if (this.isStateAffected(i)) count++;
        }
        return count;
    };
    
    // a = user, b = target, x = min state ID, y = max state ID
    Game_BattlerBase.prototype.stateAmplifier = function(a, b, x, y) {
        var count = b.countStatesRange(x, y);
        var baseDamage = 1; // Replace with your skill's damage formula
        var finalDamage = baseDamage * (1 + count);
        return finalDamage;
    };
    
    // Example to put in skill's damage formula field: b.stateAmplifier(a, b, 4, 21)
    // Amplifies damage for every state the target has starting with State ID 4 through State ID 21
})();
I was thinking about giving one of my characters a skill that did more damage based on the amount of status ailments on the enemy. And thinking for simplicity's sake, I'd probably keep it to the basic ailments (Poison, Blind, Confusion, ect).
if you dont mind tagging your states, you can put a <Negative> notetag in any states that should count and then use
Code:
b.states().filter(s => s.meta.Negative).length
in the formula to grab the number of negative states they have and do math with it accordingly. then you can make as many or as little states apply as you want, youll just need to tag the states
You can add this as a new plugin or add the functions to Game_BattlerBase.

JavaScript:
/*:
 * @plugindesc Adds a function to count the number of states on a battler within a given range of IDs.
 */
(function() {
    Game_BattlerBase.prototype.countStatesRange = function(x, y) {
        var count = 0;
        for (var i = x; i <= y; i++) {
            if (this.isStateAffected(i)) count++;
        }
        return count;
    };
   
    // a = user, b = target, x = min state ID, y = max state ID
    Game_BattlerBase.prototype.stateAmplifier = function(a, b, x, y) {
        var count = b.countStatesRange(x, y);
        var baseDamage = 1; // Replace with your skill's damage formula
        var finalDamage = baseDamage * (1 + count);
        return finalDamage;
    };
   
    // Example to put in skill's damage formula field: b.stateAmplifier(a, b, 4, 21)
    // Amplifies damage for every state the target has starting with State ID 4 through State ID 21
})();
I'll definitely try this! I'm not good at Javascript, so I hope I don't break it when I change stuff, haha.

if you dont mind tagging your states, you can put a <Negative> notetag in any states that should count and then use
Code:
b.states().filter(s => s.meta.Negative).length
in the formula to grab the number of negative states they have and do math with it accordingly. then you can make as many or as little states apply as you want, youll just need to tag the states
Also, with this code, would I add the regular damage formula to the front of it? Or would I just put that into it raw?
Also, with this code, would I add the regular damage formula to the front of it? Or would I just put that into it raw?
its up to you and how you want it to be included. its just a value like anything else youd put into a formula (a.atk, 500, b.mdf, etc.). all it does is grab the number of the target's negative states.
so if you wanted the skill to to an extra 1 damage per state you can just add it to your regular formula directly. if you wanted it to provide some multiplicative bonus then you multiply it by something and include it into the formula.
Note that if you own (or see a sufficient number of useful plugins to merit purchasing) the Yanfly suite, this is exactly what the State Categories plugin is made for. You'd use b.getStateCategoryAffectedCount("negative") in your damage formula as a multiplier.

Alternately, you can put something like
Code:
let multiplier = 1; [5, 7, 12, 21].forEach(state =>{if (b.isStateAffected(state)) multiplier++}); the rest of your damage formula * multiplier

It makes your damage formula a bit more lengthy, but it has the advantage over @Coolie's suggestion in that all of your negative states don't need to be in subsequent IDs - you list whatever specific IDs you want to check between the brackets.

Of course, you can combine both methods and outsource the code above to a function like Coolie did. But from your original description you're only using this in one skill, so it doesn't seem to make sense to add global stuff to your game for it.

Original thread: https://forums.rpgmakerweb.com/threads/skill-that-does-damage-based-on-of-ailments.181210/