Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert XP constant changes #885

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/backend-e2e/src/prisma.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe('Prisma Client Extensions', () => {
expect(profile.userID).toBe(userID);
expect(userStats).toMatchObject({
userID: userID,
level: 0,
level: 1,
cosXP: 0n,
mapsCompleted: 0,
runsSubmitted: 0,
Expand Down
2 changes: 1 addition & 1 deletion libs/db/src/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ model UserAuth {
model UserStats {
totalJumps BigInt @default(0) @db.BigInt
totalStrafes BigInt @default(0) @db.BigInt
level Int @default(0) @db.SmallInt
level Int @default(1) @db.SmallInt
cosXP BigInt @default(0) @db.BigInt
mapsCompleted Int @default(0)
runsSubmitted Int @default(0)
Expand Down
2 changes: 1 addition & 1 deletion libs/xp-systems/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const RANK_XP_PARAMS: RankXpParams = {
export const COS_XP_PARAMS: CosXpParams = {
levels: {
maxLevels: 500,
startingValue: 0,
startingValue: 20000,
linearScaleBaseIncrease: 1000,
linearScaleInterval: 10,
linearScaleIntervalMultiplier: 1,
Expand Down
71 changes: 52 additions & 19 deletions libs/xp-systems/src/xp-system.class.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,60 @@ describe('XpSystemsService', () => {
expect(service).toBeDefined();
});

describe('getCosmeticXpInLevel', () => {
it('should handle 0', () => {
const xp = service.getCosmeticXpInLevel(0);
expect(xp).toEqual(0);
});
it('should calculate correct level assignments for original constants', () => {
// These constants may get changed in the future, we also care about the maths,
// so mock here and check values correspond to below sheet
// https://docs.google.com/spreadsheets/d/1JiHJYsxlGPXAZqCPh7-paJI6U_TH-Ro0H0OWDFCiA74

it('should handle greater than 0', () => {
const xp = service.getCosmeticXpInLevel(1);
expect(xp).toBeGreaterThan(0);
// Note, this is NOT quite what the linked spreadsheet produces.
// At level 101, the sheet expects xpInLevel from 101 to be
// 152000 - it must factor in `startingValue` for some reason. In code,
// `startingValue` isn't used at all for levels greater than
// `staticScaleStart`. Not really an issue, but worth being aware of.
jest.replaceProperty(service, 'cosXpParams', {
levels: {
maxLevels: 500,
startingValue: 20000,
linearScaleBaseIncrease: 1000,
linearScaleInterval: 10,
linearScaleIntervalMultiplier: 1,
staticScaleStart: 101,
staticScaleBaseMultiplier: 1.5,
staticScaleInterval: 25,
staticScaleIntervalMultiplier: 0.5
},
completions: {
unique: { tierScale: { linear: 2500, staged: 2500 } },
repeat: {
tierScale: { linear: 20, staged: 40, stages: 5, bonus: 40 }
}
}
});
});

describe('getCosmeticXpForLevel', () => {
it('should handle 0', () => {
const xp = service.getCosmeticXpForLevel(0);
expect(xp).toEqual(0);
});

it('should handle greater than 0', () => {
const xp = service.getCosmeticXpForLevel(1);
expect(xp).toBeGreaterThan(0);
});
// prettier-ignore
for (const { level, xpInLevel, total } of [
{ level: 1, xpInLevel: 21000, total: 21000 },
{ level: 2, xpInLevel: 22000, total: 43000 },
{ level: 3, xpInLevel: 23000, total: 66000 },
{ level: 4, xpInLevel: 24000, total: 90000 },
{ level: 5, xpInLevel: 25000, total: 115000 },
{ level: 6, xpInLevel: 26000, total: 141000 },
{ level: 7, xpInLevel: 27000, total: 168000 },
{ level: 8, xpInLevel: 28000, total: 196000 },
{ level: 9, xpInLevel: 29000, total: 225000 },
{ level: 10, xpInLevel: 30000, total: 255000 },
{ level: 11, xpInLevel: 42000, total: 297000 },
{ level: 97, xpInLevel: 990000, total: 34995000 },
{ level: 98, xpInLevel: 1000000, total: 35995000 },
{ level: 99, xpInLevel: 1010000, total: 37005000 },
{ level: 100, xpInLevel: 1020000, total: 38025000 },
{ level: 101, xpInLevel: 1500000, total: 39525000 },
{ level: 102, xpInLevel: 1500000, total: 41025000 },
{ level: 103, xpInLevel: 1500000, total: 42525000 },
{ level: 104, xpInLevel: 1500000, total: 44025000 }
]) {
expect(service.getCosmeticXpInLevel(level)).toBe(xpInLevel);
expect(service.getCosmeticXpForLevel(level)).toBe(total);
}
});
});
6 changes: 3 additions & 3 deletions libs/xp-systems/src/xp-systems.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class XpSystems {
this.xpInLevels = [0];
this.xpForLevels = [0, 0];

for (let i = 0; i < this.cosXpParams.levels.maxLevels; i++) {
for (let i = 1; i < this.cosXpParams.levels.maxLevels; i++) {
this.xpInLevels[i] = this.getCosmeticXpInLevel(i);

if (i > 0)
Expand All @@ -38,7 +38,7 @@ export class XpSystems {
getCosmeticXpInLevel(level: number): number {
const levels = this.cosXpParams.levels;

if (!levels || level < 0 || level > levels.maxLevels) return -1;
if (!levels || level < 1 || level > levels.maxLevels) return -1;

if (level < levels.staticScaleStart) {
return (
Expand Down Expand Up @@ -70,7 +70,7 @@ export class XpSystems {
getCosmeticXpForLevel(level: number): number {
if (
!this.cosXpParams ||
level < 0 ||
level < 1 ||
level > this.cosXpParams.levels.maxLevels
)
return -1;
Expand Down