Skip to content

Commit

Permalink
馃憯 Adjust XP tracker to show current total / next level
Browse files Browse the repository at this point in the history
Instead of adjusting the value relative to the current level (which
would look nice on the bar), this instead shows the current total
experience as the value, and the next level as the max. This is closer
to what D&D Beyond shows, although it has a nicer bar that shows the
progress to the next level. We don't really have a way to do that solely
with a tracker at the moment, though.
  • Loading branch information
voidrender committed Nov 27, 2023
1 parent 6330e1d commit a8554f6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 128 deletions.
11 changes: 2 additions & 9 deletions src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ import {
DdbSpell,
DdbSpellActivationType,
} from './ddb';
import {
getBaseExperienceForLevel,
getExperienceRequiredForNextLevel,
getLevelFromExp,
} from './fifth-edition';
import { getExperienceRequiredForNextLevel } from './fifth-edition';

// Shared between both platforms
const STR = 1;
Expand Down Expand Up @@ -1046,18 +1042,15 @@ const convertSpellHigherLevels = (ddbSpell: DdbSpell): AlchemySpellAtHigherLevel

const convertTrackers = (ddbCharacter: DdbCharacter): AlchemyTracker[] => {
const totalExp = ddbCharacter.currentXp;
const level = getLevelFromExp(totalExp);
const baseExp = getBaseExperienceForLevel(level);
const nextLevelExp = getExperienceRequiredForNextLevel(totalExp);
const expIntoLevel = totalExp - baseExp;

return [
{
name: 'XP',
category: 'experience',
color: 'Yellow',
max: nextLevelExp,
value: expIntoLevel,
value: totalExp,
type: 'Bar',
sortOrder: 0,
},
Expand Down
99 changes: 0 additions & 99 deletions src/fifth-edition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,105 +46,6 @@ export const getExperienceRequiredForNextLevel = (
} else if (currentExp < 355000) {
return 355000;
} else {
return NaN;
}
};

/**
* Returns the minimum experience required for a level given a 5e character's
* current level.
* @param currentLevel The character's current level.
* @returns The minimum amount of experience required for the level.
*/
export const getBaseExperienceForLevel = (level: number): number => {
if (level <= 1) {
return 0;
} else if (level === 2) {
return 300;
} else if (level === 3) {
return 900;
} else if (level === 4) {
return 2700;
} else if (level === 5) {
return 6500;
} else if (level === 6) {
return 14000;
} else if (level === 7) {
return 23000;
} else if (level === 8) {
return 34000;
} else if (level === 9) {
return 48000;
} else if (level === 10) {
return 64000;
} else if (level === 11) {
return 85000;
} else if (level === 12) {
return 100000;
} else if (level === 13) {
return 120000;
} else if (level === 14) {
return 140000;
} else if (level === 15) {
return 165000;
} else if (level === 16) {
return 195000;
} else if (level === 17) {
return 225000;
} else if (level === 18) {
return 265000;
} else if (level === 19) {
return 305000;
} else {
return 355000;
}
};

/**
* Returns the level corresponding to a given amount of experience.
* @param exp The character's current total experience.
* @returns The character's level.
*/
export const getLevelFromExp = (exp: number): number => {
if (exp < 300) {
return 1;
} else if (exp < 900) {
return 2;
} else if (exp < 2700) {
return 3;
} else if (exp < 6500) {
return 4;
} else if (exp < 14000) {
return 5;
} else if (exp < 23000) {
return 6;
} else if (exp < 34000) {
return 7;
} else if (exp < 48000) {
return 8;
} else if (exp < 64000) {
return 9;
} else if (exp < 85000) {
return 10;
} else if (exp < 100000) {
return 11;
} else if (exp < 120000) {
return 12;
} else if (exp < 140000) {
return 13;
} else if (exp < 165000) {
return 14;
} else if (exp < 195000) {
return 15;
} else if (exp < 225000) {
return 16;
} else if (exp < 265000) {
return 17;
} else if (exp < 305000) {
return 18;
} else if (exp < 355000) {
return 19;
} else {
return 20;
}
};
39 changes: 19 additions & 20 deletions test/convert.exp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,25 @@ describe('Convert DDB currentXp to Alchemy tracker', () => {
test.each`
currentXp | expectedValue | expectedMax
${0} | ${0} | ${300}
${300} | ${0} | ${900}
${600} | ${300} | ${900}
${900} | ${0} | ${2700}
${1500} | ${600} | ${2700}
${2700} | ${0} | ${6500}
${6500} | ${0} | ${14000}
${14000} | ${0} | ${23000}
${23000} | ${0} | ${34000}
${34000} | ${0} | ${48000}
${48000} | ${0} | ${64000}
${64000} | ${0} | ${85000}
${85000} | ${0} | ${100000}
${100000} | ${0} | ${120000}
${120000} | ${0} | ${140000}
${140000} | ${0} | ${165000}
${165000} | ${0} | ${195000}
${195000} | ${0} | ${225000}
${225000} | ${0} | ${265000}
${265000} | ${0} | ${305000}
${305000} | ${0} | ${355000}
${300} | ${300} | ${900}
${900} | ${900} | ${2700}
${2700} | ${2700} | ${6500}
${6500} | ${6500} | ${14000}
${14000} | ${14000} | ${23000}
${23000} | ${23000} | ${34000}
${34000} | ${34000} | ${48000}
${48000} | ${48000} | ${64000}
${64000} | ${64000} | ${85000}
${85000} | ${85000} | ${100000}
${100000} | ${100000} | ${120000}
${120000} | ${120000} | ${140000}
${140000} | ${140000} | ${165000}
${165000} | ${165000} | ${195000}
${195000} | ${195000} | ${225000}
${225000} | ${225000} | ${265000}
${265000} | ${265000} | ${305000}
${305000} | ${305000} | ${355000}
${355000} | ${355000} | ${0}
`(
'returns tracker.value=$expectedValue and tracker.max=$expectedMax when currentXp=$currentXp',
({ currentXp, expectedValue, expectedMax }) => {
Expand Down

0 comments on commit a8554f6

Please sign in to comment.