JSFiddle - React, Tailwind, and code Playground
HTML
<input id="ct" placeholder="current total" />
<br />
<input id="ot" placeholder="original total" />
<br />
<input id="xp" placeholder="event exp" />
<br />
<button id="calculate">Calculate</button>
<br />
<span id='blah'></span>
JavaScript
function test_xp(ct, ot, xp) {
var current_total = ct,
original_total = ot,
event_xp = xp,
plans = {
C: {
mod: 1,
until: 0
},
B: {
mod: 1.5,
until: original_total
},
A: {
mod: 2,
until: original_total,
bonus: [{
bonus_val: 0.5,
bonus_until: (original_total < 2000 ? original_total + 500 : 2000)
}]
}
},
plan = "A",
until = plans[plan].until,
bonus = plans[plan].mod,
bonus_i = 0;
while (current_total <= until && bonus_i < plans[plan].bonus.length) {
until = plans[plan].bonus[bonus_i].bonus_until;
if (current_total <= until) {
bonus += plans[plan].bonus[bonus_i].bonus_val;
}
bonus_i++;
}
var remainder = 0;
if ((current_total + (event_xp * bonus)) > until) {
//remainder = event_xp - ((cap - current_total) / bonus);
remainder = ((until - current_total) % bonus);
current_total += ((event_xp - remainder) * bonus);
current_total += remainder;
var new_event_exp = current_total + " and I hit my limit, remainder was " + remainder + " until: " + until + " current total: " + current_total + " bonus: " + bonus;
} else {
current_total = current_total + event_xp * bonus;
var new_event_exp = current_total + " and I did not hit my limit";
}
document.getElementById('blah').innerHTML = new_event_exp;
}
$(function () {
$("#calculate").click(function () {
var ct = parseInt($("#ct").val(), 10),
ot = parseInt($("#ot").val(), 10),
xp = parseInt($("#xp").val(), 10)
test_xp(ct,ot,xp);
});
});