chore: improve IInventoryChanges (#654)

This commit is contained in:
Sainan 2024-12-29 21:40:54 +01:00 committed by GitHub
parent 00bcf5c3c5
commit 9e21105474
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 3 deletions

View File

@ -81,7 +81,7 @@ export const combineInventoryChanges = (InventoryChanges: IInventoryChanges, del
for (const item of right) {
left.push(item);
}
} else {
} else if (typeof delta[key] == "object") {
console.assert(key.substring(-3) == "Bin");
const left = InventoryChanges[key] as IBinChanges;
const right: IBinChanges = delta[key];
@ -92,6 +92,8 @@ export const combineInventoryChanges = (InventoryChanges: IInventoryChanges, del
left.Extra ??= 0;
left.Extra += right.Extra;
}
} else {
logger.warn(`inventory change not merged: ${key}`);
}
}
};
@ -476,7 +478,11 @@ export const updateSlots = async (accountId: string, slotName: SlotNames, slotAm
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) {
return {};
}

View File

@ -17,7 +17,13 @@ export interface IPurchaseParams {
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 {
InventoryChanges: IInventoryChanges;