So, I'm trying to make a sort of... "tabletop style" system for combat. Basically, I've managed to use a couple plugins to create Strength, Dexterity, Constitution, etc. for all of the characters and monsters. So, now I'm trying to figure out how to make the game "roll a d20" and determine a hit, miss, or crit. I've technically done this entirely in the "Damage Formula" system... but it's still also using the normal formula to determine a hit and a crit. Unfortunately, I don't understand the other sections well enough to understand how to edit them. Here's the damage formula system I made, if it helps.
JavaScript:
// Define Constants
const user = this.subject();
const target = arguments[0];
const item = this.item();
const a = this.subject();
const b = target;
const sign = [3, 4].includes(item.damage.type) ? -1 : 1;
const note = this.item().note;
// Check for Hit
let armor = 1;
if (note.match(/<REFLEX>/i)){
armor = b.dex;
} else if (note.match(/<FORTITUDE>/i)){
armor = b.con;
} else if (note.match(/<WILL>/i)){
armor = b.int;
} else {
armor = b.def;
}
armor = this.applyArmorModifiers(b, armor);
console.log("armor = " + armor);
let attack = a.atk;
let diceRoll = Math.floor(Math.random() * 20);
console.log("Dice Roll: " + diceRoll);
let toHit = 0;
toHit = diceRoll + attack;
console.log("To Hit = " + toHit);
// Create Damage Value
let value = 0;
let damageRoll = Math.floor(Math.random() * (item.damage.formula - 1) + 1)
if (diceRoll == 1) {
value = 0;
} else if (diceRoll == 20) {
value = damageRoll * 3
}
if (toHit >= armor){
value = damageRoll
} else {
value = 0;
}
console.log("Damage: " + value);
// Return Value
return isNaN(value) ? 0 : value;