Skip to content

Instantly share code, notes, and snippets.

@serialhex
Created January 3, 2020 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serialhex/10244d66b22237fb4be2c0b971706ba6 to your computer and use it in GitHub Desktop.
Save serialhex/10244d66b22237fb4be2c0b971706ba6 to your computer and use it in GitHub Desktop.
A Damage per Round calculator for use in comparing the relative strengths of different Pathfinder 2e characters.
<!DOCTYPE html>
<html lang="en-US">
<!--
Copyright 2020 serialhex <serialhex@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>DPR-ism</title>
<script>
var rows = 0;
var all_rows = [];
function calc_all_rows() {
all_rows.forEach(fn => {
fn();
});
}
function calculate_damage(min_roll, dmg, atks, matkp, res) {
if (atks == 0) {
return res;
}
console.log("min roll: " + min_roll + " matkp: " + matkp);
if (min_roll > 30) {
// can't hit even on a natural 20
console.log("complete fail");
res.tohit.push("nil");
res.dpr += 0;
} else if (min_roll > 20) {
console.log("only hit on a nat 20");
// only hit on a natural 20
res.tohit.push(20);
res.dpr += dmg * 0.05;
} else if (min_roll <= 20 && min_roll > 10) {
// a single crit
console.log("single crit");
res.tohit.push(Math.max(2, min_roll));
var hits = 20 - Math.max(2, min_roll);
res.dpr += dmg * 0.05 * (hits + 1);
} else if (min_roll <= 10 && min_roll >= -9) {
// multiple crits
console.log("multi crits");
res.tohit.push(Math.max(2, min_roll));
var hits = 20 - Math.max(2, min_roll);
var crits = hits - 10;
console.log("# hits: " + hits + " # crits: " + crits);
res.dpr += dmg * 0.05 * (hits + crits);
} else {
// all crits & 1 hit
console.log("all crits");
var hits = 1;
var crits = 19;
res.tohit.push(1)
res.dpr += dmg * 0.05; // the hit
res.dpr += dmg * 0.05 * 19 * 2; // the crits
}
return calculate_damage(min_roll + matkp, dmg, atks - 1, matkp, res);
}
</script>
</head>
<body>
This is a nifty tool to figure out about how much damage a character can output per round against a target AC. This doesn't (yet) take into account things like resistances or weakness.
<br>
<br>
<br>
Target AC: <input type="number" id="ac" value="18" onchange="calc_all_rows()"/>
<table id="dprism">
<thead>
<tr>
<th>Attack Bonus</th>
<th>Damage</th>
<th>Number of Attacks per Round</th>
<th>Multiple Attack Penalty</th>
<th>To-hit</th>
<th>DPR</th>
</tr>
</thead>
<tbody></tbody>
</table>
<script>
function addrow() {
var tableRef = document.getElementById('dprism').getElementsByTagName('tbody')[0];
// Insert a row in the table at the last row
var newRow = tableRef.insertRow();
rows++;
// Attack Bonus
var atk = document.createElement('input');
atk.type = "number";
atk.id = "atk" + rows;
atk.value = 10;
atk.style = "width:100px";
// Number and size of dice
var ndice = document.createElement('input');
ndice.type = "number";
ndice.id = "ndice" + rows;
ndice.value = 1;
ndice.style = "width:50px";
var sdice = document.createElement('input');
sdice.type = "number";
sdice.id = "sdice" + rows;
sdice.value = 8;
sdice.style = "width:50px";
// Number of attacks
var natk = document.createElement('input');
natk.type = "number";
natk.id = "natk" + rows;
natk.value = 2;
// Multiple attack penalty
var matkp = document.createElement('input');
matkp.type = "number";
matkp.id = "matkp" + rows;
matkp.value = -5;
var tohit = document.createTextNode("");
var dpr = document.createTextNode("");
function calculate() {
var s = sdice.value * 1.0;
var n = ndice.value * 1.0;
var damage = n * (1 + s) * 0.5;
var target = document.getElementById('ac').value;
// natural 1 is always a fail... maybe
var min_roll = target - atk.value;
console.log("------------------------");
var res = calculate_damage(
min_roll, damage, natk.value, -1.0 * matkp.value, {tohit: [], dpr: 0});
tohit.textContent = res.tohit;
dpr.textContent = res.dpr;
}
atk.addEventListener("input", function () {calculate()});
ndice.addEventListener("input", function () {
if (this.value < 1) {
this.value = 1;
alert("Can't have fewer than one die!");
return;
}
calculate()
});
sdice.addEventListener("input", function () {
if (this.value < 1) {
this.value = 1;
alert("Dice can't have fewer than one side!");
return;
}
calculate()
});
natk.addEventListener("input", function () {
if (this.value < 0) {
this.value = 1;
alert("Number of attacks should always be greater than 0!");
return;
}
calculate()
});
matkp.addEventListener("input", function () {
if (this.value < 0) {
this.value = -1;
alert("Multiple Attack Penalty should always be less than 0!");
return;
}
calculate()
});
all_rows.push(calculate);
// Insert a cell in the row
newRow.insertCell().appendChild(atk);
var dam = newRow.insertCell();
dam.appendChild(ndice);
dam.appendChild(document.createTextNode("d"));
dam.appendChild(sdice);
newRow.insertCell().appendChild(natk);
newRow.insertCell().appendChild(matkp);
newRow.insertCell().appendChild(tohit);
newRow.insertCell().appendChild(dpr);
}
// seed with the first row
addrow();
</script>
<input type=button onclick="addrow()" value="Add a row"/>
<br>
<input type=button onclick="calc_all_rows()" value="Recalculate all"/>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment