feat(inventory): add external inventory, marketplace, and supply chests
Define external inventory items and support GJN purchases, recycling, and supply chest drops.
This commit is contained in:
1 parent
129d796095
commit
415f78e761
27 files changed
+2538
-15
No files matched your search
@@ -19,13 +19,14 @@ import type { ItemDefinition } from './game-data/datasets/item-catalogue.ts';
|
||||
import { grantItem } from './items/item-grants.ts';
|
||||
import { balanceOf, setGjn, setGoldenEagles, setSilverLions } from './profile/profile-currency.ts';
|
||||
import { remainingPremiumDays } from './profile/profile-entitlements.ts';
|
||||
import { externalInventoryItems, grantExternalItem } from './profile/profile-external-inventory.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>] [--gjn <n>] [--free-rp <n>] [--give-item <item>[:<pieces>]]...';
|
||||
+ '[--silver <n>] [--gold <n>] [--gjn <n>] [--free-rp <n>] [--give-item <item>[:<pieces>]]... [--give-coupon <itemdefId>[:<qty>]]...';
|
||||
|
||||
function main(): number {
|
||||
const { values } = parseArgs({
|
||||
@@ -38,6 +39,7 @@ function main(): number {
|
||||
gjn: { type: 'string' },
|
||||
'free-rp': { type: 'string' },
|
||||
'give-item': { type: 'string', multiple: true },
|
||||
'give-coupon': { type: 'string', multiple: true },
|
||||
},
|
||||
});
|
||||
if (!values.game || !values.data || !values.player) {
|
||||
@@ -72,7 +74,18 @@ function main(): number {
|
||||
}
|
||||
gifts.push({ item, pieces });
|
||||
}
|
||||
const changes = silver !== undefined || gold !== undefined || gjn !== undefined || freeRp !== undefined || gifts.length > 0;
|
||||
const coupons: { itemdefId: number; quantity: number }[] = [];
|
||||
for (const request of values['give-coupon'] ?? []) {
|
||||
const [idText = '', qtyText = '1'] = request.split(':');
|
||||
const itemdefId = optionalAmount(idText);
|
||||
const quantity = optionalAmount(qtyText);
|
||||
if (!itemdefId || !quantity || !research.inventory.hasItemDef(itemdefId)) {
|
||||
console.error(`--give-coupon: unknown itemdef id "${idText}", or quantity not a whole number of 1 or more`);
|
||||
return 2;
|
||||
}
|
||||
coupons.push({ itemdefId, quantity });
|
||||
}
|
||||
const changes = silver !== undefined || gold !== undefined || gjn !== undefined || freeRp !== undefined || gifts.length > 0 || coupons.length > 0;
|
||||
const now = serverTimeNow();
|
||||
const profile = !changes
|
||||
? profiles.profileOf(account.userId)
|
||||
@@ -82,6 +95,7 @@ function main(): number {
|
||||
if (gjn !== undefined) setGjn(saved, gjn);
|
||||
if (freeRp !== undefined) setFreeResearchPoints(saved, freeRp);
|
||||
for (const gift of gifts) grantItem(saved, gift.item, gift.pieces, now);
|
||||
for (const coupon of coupons) grantExternalItem(saved, coupon.itemdefId, coupon.quantity);
|
||||
});
|
||||
const balance = balanceOf(profile);
|
||||
const premiumDays = remainingPremiumDays(profile, now);
|
||||
@@ -89,6 +103,8 @@ function main(): number {
|
||||
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(', ')}`);
|
||||
const extItems = externalInventoryItems(profile);
|
||||
if (extItems.length) console.log(`extInventory: ${extItems.map((item) => `#${item.itemDefId} x${item.quantity}`).join(', ')}`);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user