@ -4,13 +4,13 @@
{% block title %}Spoil Shares Calculator{% endblock %}
{% block title %}Spoil Shares Calculator{% endblock %}
{% block content %}
{% block content %}
< div class = "uk-flex uk-flex-center uk-margin-bottom uk-margin-top" >
< div class = "uk-flex uk-flex-center uk-margin-bottom uk-margin-top" >
< h1 class = "uk-text-center" > < strong > Adventurer Conqueror King < / strong > Spoil Shares Calculator< / h1 >
< h1 class = "uk-text-center" > < strong > Legends of Palisma < / strong > Spoil Shares Calculator< / h1 >
< / div >
< / div >
< div class = "uk-grid-divider" uk-grid >
< div class = "uk-grid-divider" uk-grid >
< div class = "uk-width-1-3" >
< div class = "uk-width-1-3" >
< h3 > Session Info< / h3 >
< h3 > Session Info< / h3 >
< form class = "uk-form-horizontal uk-margin-large" >
< form class = "uk-form-horizontal uk-margin-large" autocomplete = off >
< div class = "uk-margin" >
< div class = "uk-margin" >
< label class = "uk-form-label" for = "player_count" > Number of players< / label >
< label class = "uk-form-label" for = "player_count" > Number of players< / label >
< div class = "uk-form-controls" >
< div class = "uk-form-controls" >
@ -76,8 +76,14 @@
< h4 > Player GP Share< / h4 >
< h4 > Player GP Share< / h4 >
< span id = "pc_gp_share" > < / span >
< span id = "pc_gp_share" > < / span >
< div id = "share_button_container" class = "uk-margin-large-top uk-hidden" >
< button type = "button" class = "uk-button uk-button-secondary uk-button-small" id = "export_button" title = "Will copy a chat message to be pasted into Roll20." > Share< / button >
< button type = "button" class = "uk-button uk-button-default uk-button-small" id = "clear_button" > Reset< / button >
< / div >
< / div >
< / div >
< / div >
< / div >
< textarea id = "export-data" class = "uk-textarea uk-hidden" > < / textarea >
{% endblock %}
{% endblock %}
{% block head %}
{% block head %}
@ -87,17 +93,29 @@
{% block scripts %}
{% block scripts %}
< script type = "text/javascript" >
< script type = "text/javascript" >
var lastCalculatedShares = null;
window.addEventListener('DOMContentLoaded', () => {
window.addEventListener('DOMContentLoaded', () => {
var calc = document.querySelector('button#share_calc_button');
var calc = document.querySelector('button#share_calc_button');
calc.addEventListener("click", calculateShares);
calc.addEventListener("click", calculateShares);
var share = document.querySelector('button#export_button');
share.addEventListener("click", clipboardShare);
var clear = document.querySelector('button#clear_button');
clear.addEventListener("click", resetPage);
});
});
function calculateShares() {
function calculateShares() {
document.querySelector('div#share_button_container').classList.remove('uk-hidden');
var player_shares = document.querySelector('table#player_shares > tbody');
var player_shares = document.querySelector('table#player_shares > tbody');
var hench_shares = document.querySelector('table#hench_shares > tbody');
var hench_shares = document.querySelector('table#hench_shares > tbody');
var pc_gp_share = document.querySelector('span#pc_gp_share');
player_shares.innerHTML = '';
player_shares.innerHTML = '';
hench_shares.innerHTML = '';
hench_shares.innerHTML = '';
pc_gp_share.innerText = '';
var player_count = parseInt(document.querySelector('select#player_count').value);
var player_count = parseInt(document.querySelector('select#player_count').value);
var hench_count = parseInt(document.querySelector('input#hench_count').value);
var hench_count = parseInt(document.querySelector('input#hench_count').value);
@ -105,10 +123,11 @@
var gp = parseInt(document.querySelector('input#gp_recovered').value);
var gp = parseInt(document.querySelector('input#gp_recovered').value);
var xp = parseInt(document.querySelector('input#xp_earned').value);
var xp = parseInt(document.querySelector('input#xp_earned').value);
lastCalculatedShares = {pc: player_count, hc: hench_count, gp: gp, xp: xp};
let total_xp = gp + xp;
let total_xp = gp + xp;
let pc_base_xp_share = total_xp / (player_count + hench_count / 2.0);
let pc_base_xp_share = total_xp / (player_count + hench_count / 2.0);
let response = '';
for(let i = 0; i < 5 ; i + + ) {
for(let i = 0; i < 5 ; i + + ) {
// Build player rows
// Build player rows
const row = document.createElement("tr");
const row = document.createElement("tr");
@ -141,5 +160,71 @@
let gpshare = Math.floor(gp / (player_count + hench_count / 6.0))
let gpshare = Math.floor(gp / (player_count + hench_count / 6.0))
pc_gp_share.appendChild(document.createTextNode(`${gpshare} gold per player.`));
pc_gp_share.appendChild(document.createTextNode(`${gpshare} gold per player.`));
}
}
function clipboardShare() {
if(!lastCalculatedShares) {
return;
}
var btn = document.querySelector('button#export_button');
btn.classList.remove('uk-animation-shake');
var lcs = lastCalculatedShares;
var [player_count, hench_count, gp, xp] = [lcs.pc, lcs.hc, lcs.gp, lcs.xp];
let total_xp = gp + xp;
let pc_base_xp_share = total_xp / (player_count + hench_count / 2.0);
var [ps, hs] = [{}, {}];
for(let i = 0; i < 5 ; i + + ) {
// Build player rows
ps[`@ ${5 * i}%`] = `${Math.floor(pc_base_xp_share * (1 + 0.05 * i))} xp`;
// Build hench rows
hs[`@ ${5 * i}%`] = `${Math.floor(pc_base_xp_share * (1 + 0.05 * i) / 2.0)} xp`;
}
let gpshare = Math.floor(gp / (player_count + hench_count / 6.0))
{% raw %}
let response = '& {template:acks}{{name=Spoil Shares}}';
response += `{{**Player Gold Share** = [[${gpshare}]]}}`;
response += '{{**Player XP Share**=\n'
for(const [k, v] of Object.entries(ps)) {
response += `${k} bonus: *${v}*\n`;
}
response += '}}';
response += '{{**Henchmen XP Share**=\n'
for(const [k, v] of Object.entries(hs)) {
response += `${k} bonus: *${v}*\n`;
}
response += `}}{{desc=${player_count} players, ${hench_count} henchmen sharing ${gp} gold XP and ${xp} monster XP.}}`;
{% endraw %}
let export_data = document.querySelector('#export-data');
export_data.value = response;
export_data.classList.remove('uk-hidden');
export_data.select();
document.execCommand("copy");
export_data.classList.add('uk-hidden');
btn.classList.add('uk-animation-shake');
}
function resetPage() {
document.querySelector('div#share_button_container').classList.add('uk-hidden');
document.querySelector('table#player_shares > tbody').innerHTML = '';
document.querySelector('table#hench_shares > tbody').innerHTML = '';
document.querySelector('span#pc_gp_share').innerText = '';
document.querySelector('select#player_count').value = 1;
document.querySelector('input#hench_count').value = 0;
document.querySelector('input#gp_recovered').value = 0;
document.querySelector('input#xp_earned').value = 0;
}
< / script >
< / script >
{% endblock %}
{% endblock %}