feat(store): add GJN balances, a local store, and redemption codes

Support currency and entitlement purchases, including packs, from the
local store and the in-game payment flow. Expose the supported
redemption codes.
This commit is contained in:
N0VAN0M4LY committed 2026-11-25 06:33:41 +08:00
1 parent ddb381d7f9
commit 129d796095
26 files changed
+1352 -29

No files matched your search

+14 -8
View File
@@ -3,7 +3,7 @@
* section A; the launcher will call the same profile functions).
*
* node packages/local-service/src/save-cli.ts --game <game folder> --data <data folder>
* --player <login or user id> [--silver <n>] [--gold <n>] [--free-rp <n>]
* --player <login or user id> [--silver <n>] [--gold <n>] [--gjn <n>] [--free-rp <n>]
* [--give-item <item>[:<pieces>]]...
*
* --free-rp sets the free research points. --give-item gives classic
@@ -17,14 +17,15 @@ import { DatasetCache } from './game-data/datasets/dataset-cache.ts';
import { GameFiles } from './game-data/game-files.ts';
import type { ItemDefinition } from './game-data/datasets/item-catalogue.ts';
import { grantItem } from './items/item-grants.ts';
import { balanceOf, setGoldenEagles, setSilverLions } from './profile/profile-currency.ts';
import { balanceOf, setGjn, setGoldenEagles, setSilverLions } from './profile/profile-currency.ts';
import { remainingPremiumDays } from './profile/profile-entitlements.ts';
import { ownedItems } from './profile/profile-items.ts';
import { freeResearchPoints, setFreeResearchPoints } from './profile/profile-research-points.ts';
import { serverTimeNow } from './profile/server-time.ts';
import { setUpProfiles } from './profiles-setup.ts';
const USAGE = 'usage: save-cli.ts --game <game folder> --data <data folder> --player <login or user id> '
+ '[--silver <n>] [--gold <n>] [--free-rp <n>] [--give-item <item>[:<pieces>]]...';
+ '[--silver <n>] [--gold <n>] [--gjn <n>] [--free-rp <n>] [--give-item <item>[:<pieces>]]...';
function main(): number {
const { values } = parseArgs({
@@ -34,6 +35,7 @@ function main(): number {
player: { type: 'string' },
silver: { type: 'string' },
gold: { type: 'string' },
gjn: { type: 'string' },
'free-rp': { type: 'string' },
'give-item': { type: 'string', multiple: true },
},
@@ -44,9 +46,10 @@ function main(): number {
}
const silver = optionalAmount(values.silver);
const gold = optionalAmount(values.gold);
const gjn = optionalAmount(values.gjn);
const freeRp = optionalAmount(values['free-rp']);
if (silver === null || gold === null || freeRp === null) {
console.error('--silver, --gold and --free-rp take a whole number of 0 or more');
if (silver === null || gold === null || gjn === null || freeRp === null) {
console.error('--silver, --gold, --gjn and --free-rp take a whole number of 0 or more');
return 2;
}
const accounts = new AccountStore(values.data);
@@ -69,18 +72,21 @@ function main(): number {
}
gifts.push({ item, pieces });
}
const changes = silver !== undefined || gold !== undefined || freeRp !== undefined || gifts.length > 0;
const changes = silver !== undefined || gold !== undefined || gjn !== undefined || freeRp !== undefined || gifts.length > 0;
const now = serverTimeNow();
const profile = !changes
? profiles.profileOf(account.userId)
: profiles.update(account.userId, (saved) => {
if (silver !== undefined) setSilverLions(saved, silver);
if (gold !== undefined) setGoldenEagles(saved, gold);
if (gjn !== undefined) setGjn(saved, gjn);
if (freeRp !== undefined) setFreeResearchPoints(saved, freeRp);
const now = serverTimeNow();
for (const gift of gifts) grantItem(saved, gift.item, gift.pieces, now);
});
const balance = balanceOf(profile);
console.log(`${account.login} (${account.userId}): ${balance.silverLions} silver lions, ${balance.goldenEagles} golden eagles, ${freeResearchPoints(profile)} free research points`);
const premiumDays = remainingPremiumDays(profile, now);
const premiumNote = premiumDays > 0 ? `, premium: ${premiumDays}d` : '';
console.log(`${account.login} (${account.userId}): ${balance.silverLions} silver lions, ${balance.goldenEagles} golden eagles, ${balance.gjn} GJN, ${freeResearchPoints(profile)} free research points${premiumNote}`);
const items = ownedItems(profile);
if (items.length) console.log(`items: ${items.map((item) => `${item.id} x${item.count}`).join(', ')}`);
return 0;