gammatools/web/assets/js/mentalattack.js

49 lines
1.9 KiB
JavaScript
Raw Normal View History

2024-06-28 22:00:49 +00:00
window.onload = function () {
document.getElementById('mentalAttackForm').addEventListener('submit', function (event) {
event.preventDefault(); // Prevent the form from submitting the normal way
const ams = parseInt(document.getElementById('ams').value, 10);
const dms = parseInt(document.getElementById('dms').value, 10);
const modifier = parseInt(document.getElementById('modifier').value, 0);
const queryParams = new URLSearchParams({
ams: ams,
dms: dms,
modifier: modifier
});
2024-06-28 22:00:49 +00:00
fetch(`${window.BASE_URL}/gameplay/attack/mental?${queryParams}`)
2024-06-28 22:00:49 +00:00
.then(response => response.json())
.then(data => {
const resultsDiv = document.getElementById('results');
let html = '';
if (data['needed']) {
html += `<p><b>Needed: </b>${data['needed']} &emsp;&emsp;&emsp;&emsp;&emsp;`;
}
if (data['original-roll']) {
html += `<b>Original Roll: </b>${data['original-roll']}</p>`;
}
if (data['modifier']) {
html += `<p><b>Modifier: </b>${data['modifier']} &emsp;&emsp;&emsp;&emsp;&emsp;`;
}
if (data['adjusted-roll']) {
html += `<b>Adjusted Roll: </b> ${data['adjusted-roll']}</p>`;
}
html += `<br/>`;
if (data['outcome']) {
let outcomeText = data['outcome'];
html += `<p><h2>${outcomeText}</h2></p>`;
// adding img tag
2024-07-16 23:50:14 +00:00
let outcomeImage = `${window.IMG}/` + outcomeText.replace(' ', '%20') + '.png';
2024-06-28 22:26:42 +00:00
html += `<img src="${outcomeImage}" width="350px" height="350px"/>`
2024-06-28 22:00:49 +00:00
resultsDiv.innerHTML = html;
}
})
});
}