I'd like to be able to pass a game variable into the States and Skills Core notetags instead of a number value. (EG: <Potion Cost: \V[x]> instead of <Potion Cost: x>). I had a look into the JS: Cost Calculation for the Skill Cost Types parameter and I can see that it's grabbing the value there, but I don't know enough JavaScript to be able to add an option there for it to read a game variable and pass it as a number value, or if I do manage to add it, if this value will update as the game variable is changed via events.
If anyone could suggest any JS changes I could make to the Cost Calculation, or to another area of the plugin parameters that I've overlooked, that would be very helpful. Thank you.
JS: Cost Calcuations in VisuStella: Skills and States Core (Created by the VisuStella team)
If anyone could suggest any JS changes I could make to the Cost Calculation, or to another area of the plugin parameters that I've overlooked, that would be very helpful. Thank you.
JS: Cost Calcuations in VisuStella: Skills and States Core (Created by the VisuStella team)
JavaScript:
// Declare Variables
const user = this;
const skill = arguments[0];
let cost = 0;
// Calculations
const note = skill.note;
if (note.match(/<POTION COST:[ ](\d+)>/i)) {
cost += Number(RegExp.$1);
}
if (note.match(/<JS POTION COST>\s*([\s\S]*)\s*<\/JS POTION COST>/i)) {
const code = String(RegExp.$1);
eval(code);
}
// Apply Trait Cost Alterations
if (cost > 0) {
const rateNote = /<POTION COST:[ ](\d+\.?\d*)([%%])>/i;
const rates = user.traitObjects().map((obj) => (obj && obj.note.match(rateNote) ? Number(RegExp.$1) / 100 : 1));
const flatNote = /<POTION COST:[ ]([\+\-]\d+)>/i;
const flats = user.traitObjects().map((obj) => (obj && obj.note.match(flatNote) ? Number(RegExp.$1) : 0));
cost = rates.reduce((r, rate) => r * rate, cost);
cost = flats.reduce((r, flat) => r + flat, cost);
cost = Math.max(1, cost);
}
// Set Cost Limits
if (note.match(/<POTION COST MAX:[ ](\d+)>/i)) {
cost = Math.min(cost, Number(RegExp.$1));
}
if (note.match(/<POTION COST MIN:[ ](\d+)>/i)) {
cost = Math.max(cost, Number(RegExp.$1));
}
// Return cost value
return Math.round(Math.max(0, cost));