fix ability check function bug

This commit is contained in:
Greg Gauthier 2024-06-30 12:01:34 +01:00
parent ae251bf830
commit 8621353105
3 changed files with 76 additions and 4 deletions

View File

@ -5,6 +5,6 @@ def roll_ability_check(score, multiplier):
threshold = score * multiplier
rolled = roll_dices(1, 100, False).get('result')
if rolled < threshold:
return {'threshold': threshold, 'rolled': rolled, 'success': True}, 200
return {'threshold': threshold, 'rolled': rolled, 'success': True}
else:
return {'threshold': threshold, 'rolled': rolled, 'success': False}, 200
return {'threshold': threshold, 'rolled': rolled, 'success': False}

65
web/ability_check.html Normal file
View File

@ -0,0 +1,65 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="styles.css">
<title>Ability Checks</title>
</head>
<body>
<h2>Will You Succeed?</h2>
<div class="content-container">
<form id="abilityCheckForm">
<div class="form-row">
<div class="form-field" style="margin-right: 15px">
<label for="score" style="margin-right: 2px">Ability Score</label>
<input type="number" name="score" id="score" min="3" max="24" value="10">
</div>
<div class="form-field" style="margin-left: 15px">
<label for="multiplier">Multiplier</label>
<input type="number" name="multiplier" id="multiplier" min="-100" max="100" value="5">
</div>
<div class="form-field" style="margin: 5px">
<button type="submit" style="margin: 3px">Roll</button>
</div>
</div>
</form>
</div>
<hr/>
<div id="results"></div>
<script>
document.getElementById("abilityCheckForm").addEventListener("submit", function (event) {
event.preventDefault();
let ability_score = document.getElementById('score').value;
let multiplier = document.getElementById('multiplier').value;
fetch("https://gammaworld.gmgauthier.com/roll/check", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
"ability_score": ability_score,
"multiplier": multiplier
}),
})
.then(response => response.json())
.then(data => {
let result = document.getElementById("results");
result.innerHTML = "Threshold: " + data[0].threshold + "<br>"
+ "Rolled: " + data[0].rolled + "<br>"
+ (data[0].success ? "You Succeeded!" : "You Failed!");
})
.catch((error) => {
console.error('Error:', error);
});
});
</script>
</body>
</html>

View File

@ -15,11 +15,14 @@
<button id="coinflip">Flip Coin</button>
<button id="chance">Roll Chance</button>
</div>
<div id="button-panel" style="text-align: center; margin: 3px">
<div id="gameplay-panel" style="text-align: center; margin: 3px">
<button id="encounter">Encounters</button>
<button id="abcheck">Ability Check</button>
<button id="physicalattack">Physical Attack!</button>
<button id="mentalattack">Mental Attack!</button>
</div>
<div id="gameref-panel" style="text-align: center; margin: 3px">
<button id="chargen">Characters</button>
<button id="tables">Show Tables</button>
</div>
@ -31,6 +34,10 @@
document.addEventListener('DOMContentLoaded', function () {
loadContent("intro.html");
document.getElementById("tables").addEventListener("click", function () {
loadContent("ability_check.html?t=" + new Date().getTime());
});
document.getElementById("tables").addEventListener("click", function () {
loadContent("display_tables.html?t=" + new Date().getTime());
});