JSFiddle - React, Tailwind, and code Playground
HTML
<input id="ct" placeholder="current total" value="1800" />
<br />
<input id="ot" placeholder="original total" value="2000" />
<br />
<input id="xp" placeholder="event exp" value="150" />
<br />
<input id="plan" placeholder="character plan" value="A" />
<br />
<button id="calculate">Calculate</button>
<br />
<span id='blah'></span>
JavaScript
var tests = {
0: {
currentTotal: 850,
originalTotal: 1000,
experience: 150
},
1: {
currentTotal: 1000,
originalTotal: 3000,
experience: 300
},
2: {
currentTotal: 1500,
originalTotal: 2000,
experience: 300
},
3: {
currentTotal: 1300,
originalTotal: 2000,
experience: 100
},
4: {
currentTotal: 1900,
originalTotal: 2000,
experience: 150
}
};
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: {
val: 0.5,
until: (original_total + 500 < 2000 ? original_total + 500 : 2000)
}
}
},
plan = document.getElementById("plan").value,
until = plans[plan].until,
bonus = plans[plan].mod,
new_total = current_total;
if ((typeof plans[plan].bonus === 'undefined')) {
var secondary_bonus = 1;
var secondary_bonus_limit = 0;
} else {
//We have a secondary bonus
secondary_bonus_limit = plans[plan].bonus.until;
secondary_bonus = plans[plan].bonus.val;
}
if (current_total + (event_xp * bonus) < until) {
//Current xp and the bonus don't add up to greater than the limit, just add it
new_total = current_total + (event_xp * bonus);
} else {
if ((current_total + event_xp) > until) {
//Current xp + xp add up to over the limit on it's own, just add the experience
new_total = current_total + event_xp;
} else {
//Current XP + XP does not equal limit, so...