feat(store): show native receipts for purchases
Persist the actual grant in the purchase log and open one native receipt per unread entry. Keep pending receipts during log trimming and resume them when the price table becomes available. Verified TypeScript types, GUI patch application, and Quirrel syntax.
This commit is contained in:
1 parent
98812fa9c2
commit
4b1e226c34
13 files changed
+376
-6
No files matched your search
@@ -9,6 +9,7 @@ import type { BlkBlock } from '@wto/blk';
|
||||
import { addGoldenEagles, addSilverLions, balanceOf, canAfford, pay, payGjnCents } from '../profile/profile-currency.ts';
|
||||
import { extendPremiumAccount, hasEntitlement, recordEntitlementPurchase } from '../profile/profile-entitlements.ts';
|
||||
import { addOwnedVehicle, ownsVehicle } from '../profile/profile-hangar.ts';
|
||||
import { appendEntitlementPurchase } from '../profile/profile-trophies-log.ts';
|
||||
import { ACCEPTED, refused, type RuleOutcome } from '../research/rule-outcome.ts';
|
||||
import type { StoreCatalogue, StoreProduct } from './store-catalogue.ts';
|
||||
|
||||
@@ -65,16 +66,30 @@ export function buyFreeStoreProduct(profile: BlkBlock, product: StoreProduct, no
|
||||
}
|
||||
|
||||
function grantProductRewards(profile: BlkBlock, product: StoreProduct, nowFiletime: bigint): void {
|
||||
const before = balanceOf(profile);
|
||||
const newVehicles: string[] = [];
|
||||
if (product.id !== 'PremiumAccount') recordEntitlementPurchase(profile, product.id);
|
||||
if (product.goldIncome) addGoldenEagles(profile, product.goldIncome);
|
||||
if (product.silverIncome) addSilverLions(profile, product.silverIncome);
|
||||
if (product.premiumDays) extendPremiumAccount(profile, product.premiumDays, nowFiletime);
|
||||
if (product.vehicles) {
|
||||
for (const vehicle of product.vehicles) {
|
||||
if (!ownsVehicle(profile, vehicle.name)) addOwnedVehicle(profile, vehicle.name);
|
||||
if (!ownsVehicle(profile, vehicle.name)) {
|
||||
addOwnedVehicle(profile, vehicle.name);
|
||||
newVehicles.push(vehicle.name);
|
||||
}
|
||||
for (const part of vehicle.parts) {
|
||||
if (!ownsVehicle(profile, part)) addOwnedVehicle(profile, part);
|
||||
}
|
||||
}
|
||||
}
|
||||
const after = balanceOf(profile);
|
||||
appendEntitlementPurchase(profile, {
|
||||
productId: product.id,
|
||||
goldenEagleCost: product.goldCost,
|
||||
goldenEagles: after.goldenEagles - before.goldenEagles,
|
||||
silverLions: after.silverLions - before.silverLions,
|
||||
premiumDays: product.premiumDays ?? 0,
|
||||
vehicles: newVehicles,
|
||||
}, nowFiletime);
|
||||
}
|
||||
Reference in new issue
Block a user