feat(economy): offer a free offline payment option
Expose free payment in the in-game dialog, local store, and marketplace. Grant the selected item without debiting GJN and reject unknown payment methods. Apply the configured per-purchase limit consistently. Type checking, binary and GUI patch checks, and local purchase checks passed. In-game acceptance is pending.
This commit is contained in:
1 parent
e1468df52b
commit
4d8229ae92
9 files changed
+161
-56
No files matched your search
@@ -247,15 +247,36 @@ export function buyMarketplaceCoupon(
|
||||
catalogue: InventoryCatalogue,
|
||||
itemdefId: number,
|
||||
quantity: number,
|
||||
maxPerPurchase: number,
|
||||
): MarketBuyOutcome {
|
||||
const listing = catalogue.marketplaceListing(itemdefId);
|
||||
if (!listing || !Number.isSafeInteger(quantity) || quantity < 1 || quantity > 20) {
|
||||
return { ok: false, reason: 'NOT_FOUND' };
|
||||
}
|
||||
const listing = validCouponPurchase(catalogue, itemdefId, quantity, maxPerPurchase);
|
||||
if (!listing) return { ok: false, reason: 'NOT_FOUND' };
|
||||
const totalCost = listing.gjnCostCents * quantity;
|
||||
if (balanceOf(profile).gjnCents < totalCost) return { ok: false, reason: 'NOT_ENOUGH_GJN' };
|
||||
|
||||
payGjnCents(profile, totalCost);
|
||||
const item = grantExternalItem(profile, itemdefId, quantity);
|
||||
return { ok: true, item };
|
||||
return { ok: true, item: grantExternalItem(profile, itemdefId, quantity) };
|
||||
}
|
||||
|
||||
/** Direct free marketplace coupon claim ("老福爷付过了") without deducting GJN. */
|
||||
export function buyFreeMarketplaceCoupon(
|
||||
profile: BlkBlock,
|
||||
catalogue: InventoryCatalogue,
|
||||
itemdefId: number,
|
||||
quantity: number,
|
||||
maxPerPurchase: number,
|
||||
): MarketBuyOutcome {
|
||||
const listing = validCouponPurchase(catalogue, itemdefId, quantity, maxPerPurchase);
|
||||
if (!listing) return { ok: false, reason: 'NOT_FOUND' };
|
||||
return { ok: true, item: grantExternalItem(profile, itemdefId, quantity) };
|
||||
}
|
||||
|
||||
function validCouponPurchase(
|
||||
catalogue: InventoryCatalogue,
|
||||
itemdefId: number,
|
||||
quantity: number,
|
||||
maxPerPurchase: number,
|
||||
) {
|
||||
if (!Number.isSafeInteger(quantity) || quantity < 1 || quantity > maxPerPurchase) return undefined;
|
||||
return catalogue.marketplaceListing(itemdefId);
|
||||
}
|
||||
Reference in new issue
Block a user