Thank for pointing to Game_Action, but probably I have to manage damage formulas instead of aliasing Game_Action methods (not sure about it).
An action is performed when a battler uses a skill or item. Evaluating the damage formula (if there is one) is part of that...
😅
The formula must have something to do with
makeDamageValue, right? So let's have a look at that method in the code (rpg_objects.js); here's the first three lines:
JavaScript:
Game_Action.prototype.makeDamageValue = function(target, critical) {
var item = this.item();
var baseValue = this.evalDamageFormula(target);
OK, that sounds promising! Let's have a look at the
evalDamageFormula method:
Spoiler: evalDamageFormula
JavaScript:
Game_Action.prototype.evalDamageFormula = function(target) {
try {
var item = this.item();
var a = this.subject();
var b = target;
var v = $gameVariables._data;
var sign = ([3, 4].contains(item.damage.type) ? -1 : 1);
var value = Math.max(eval(item.damage.formula), 0) * sign;
if (isNaN(value)) value = 0;
return value;
} catch (e) {
return 0;
}
};
Here we see that the damage formula (a string, i.e. text) is evaluated using
eval, i.e. "string to code". Several local variables are defined immediately beforehand, so that certain things can be written more concisely in the formula, e.g.
b = target.
I'm currently experimenting this formula:
Code:
a.atk * 4 * a.rrf - b.def * 2
where rrf is a multiplier custom value inside an actor (defined with Object.defineProperties, and based on the xcp1 parameter showed in the code snipped on my previous reply) . But I have this two doubts on this approach:
1) is the 'rrf' parameter actually visible / usable inside damage formula?
2) how to make the formula actually valid since (at least currently) the rrf parameter actually exists only for actors and not for enemies? Are there other battlers other than actors and enemies?
- The objects
a and b will still have all their properties. If the rrf property is defined on the skill user, a, then yes: a.rrf will be defined. 🙂
- Like you say, generally speaking this might be a
Game_Enemy (or possibly something else if you're using plugins that add other battler types). If you've only defined the rrf property on Game_Actor, then you'll get unexpected behaviour if a is actually an enemy. That's one reason that the existing parameters are defined on Game_BattlerBase instead, since both actors and enemies inherit from it via Game_Battler. For reference, you can find the Game_BattlerBase stuff at around line 2125 in rpg_objects.js~
PS: itemEva default function, as I see, simply returns an evasion value, It could be a good function to alter if/when I need to apply a custom evasion modifier but probably doesn't change how the system will use evasion value... however very nice suggestion, thank!
Oh, good point! For applying the hit/evasion values, check
Game_Action.prototype.apply. If you want to edit something in the middle of a method, generally that requires a complete override, i.e. copy + paste the method into your plugin then change whatever you want changed.
Note: if you just want the result, Yanfly has a
Hit Accuracy plugin that lets you adjust the hit/eva stuff. Looks like it's a paid plugin now, but at least it's cheap.
😛