chore: improve IInventoryChanges #654

Merged
Sainan merged 2 commits from improve-IInventoryChanges into main 2024-12-29 12:40:54 -08:00
2 changed files with 15 additions and 3 deletions

View File

@ -82,7 +82,7 @@ export const combineInventoryChanges = (InventoryChanges: IInventoryChanges, del
for (const item of right) { for (const item of right) {
left.push(item); left.push(item);
} }
} else { } else if (typeof delta[key] == "object") {
console.assert(key.substring(-3) == "Bin"); console.assert(key.substring(-3) == "Bin");
const left = InventoryChanges[key] as IBinChanges; const left = InventoryChanges[key] as IBinChanges;
const right: IBinChanges = delta[key]; const right: IBinChanges = delta[key];
@ -93,6 +93,8 @@ export const combineInventoryChanges = (InventoryChanges: IInventoryChanges, del
left.Extra ??= 0; left.Extra ??= 0;
left.Extra += right.Extra; left.Extra += right.Extra;
} }
} else {
logger.warn(`inventory change not merged: ${key}`);
} }
} }
}; };
@ -477,7 +479,11 @@ export const updateSlots = async (accountId: string, slotName: SlotNames, slotAm
await inventory.save(); await inventory.save();
}; };
export const updateCurrency = async (price: number, usePremium: boolean, accountId: string) => { export const updateCurrency = async (
price: number,
usePremium: boolean,
accountId: string
): Promise<IInventoryChanges> => {
if (usePremium ? config.infinitePlatinum : config.infiniteCredits) { if (usePremium ? config.infinitePlatinum : config.infiniteCredits) {
return {}; return {};
} }

View File

@ -17,7 +17,13 @@ export interface IPurchaseParams {
UseFreeFavor?: boolean; // for Source 2 UseFreeFavor?: boolean; // for Source 2
} }
export type IInventoryChanges = Record<string, IBinChanges | object[]>; export type IInventoryChanges = {
[_ in SlotNames]?: IBinChanges;
} & {
RegularCredits?: number;
PremiumCredits?: number;
PremiumCreditsFree?: number;
} & Record<string, IBinChanges | number | object[]>;
export interface IPurchaseResponse { export interface IPurchaseResponse {
InventoryChanges: IInventoryChanges; InventoryChanges: IInventoryChanges;