fix: track FreeFavorsUsed

This commit is contained in:
Sainan 2025-01-17 06:40:35 +01:00
parent 8c5225886e
commit cb9b5222f4

View File

@ -79,23 +79,33 @@ export const handlePurchase = async (
switch (purchaseRequest.PurchaseParams.Source) { switch (purchaseRequest.PurchaseParams.Source) {
case 2: case 2:
if (!purchaseRequest.PurchaseParams.UseFreeFavor!) { {
const syndicateTag = purchaseRequest.PurchaseParams.SyndicateTag!; const syndicateTag = purchaseRequest.PurchaseParams.SyndicateTag!;
const syndicate = ExportSyndicates[syndicateTag]; if (purchaseRequest.PurchaseParams.UseFreeFavor!) {
if (syndicate) { const inventory = await getInventory(accountId);
const favour = syndicate.favours.find(x => x.storeItem == purchaseRequest.PurchaseParams.StoreItem); const affiliation = inventory.Affiliations.find(x => x.Tag == syndicateTag)!;
if (favour) { affiliation.FreeFavorsUsed ??= [];
const inventory = await getInventory(accountId); affiliation.FreeFavorsUsed.push(affiliation.FreeFavorsEarned![affiliation.FreeFavorsUsed.length]);
const affiliation = inventory.Affiliations.find(x => x.Tag == syndicateTag); await inventory.save();
if (affiliation) { } else {
purchaseResponse.Standing = [ const syndicate = ExportSyndicates[syndicateTag];
{ if (syndicate) {
Tag: syndicateTag, const favour = syndicate.favours.find(
Standing: favour.standingCost x => x.storeItem == purchaseRequest.PurchaseParams.StoreItem
} );
]; if (favour) {
affiliation.Standing -= favour.standingCost; const inventory = await getInventory(accountId);
await inventory.save(); const affiliation = inventory.Affiliations.find(x => x.Tag == syndicateTag);
if (affiliation) {
purchaseResponse.Standing = [
{
Tag: syndicateTag,
Standing: favour.standingCost
}
];
affiliation.Standing -= favour.standingCost;
await inventory.save();
}
} }
} }
} }