Member welcome offer + member perk: after a chapter clear, a signed-in non-member (IAP memberId 0) sees a dismissible "Become an InstantAdPay member" card once per Central day (bonus from IAP /api/starter/public, cached 10 min, skipped when off); a member's first hand-off grants one free hangar upgrade (token on the player, next purchase costs nothing, no POL moved), with a one-time lobby message

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
martbost
2026-10-05 06:24:20 -05:00
parent 4fa68b2745
commit 09692de8c6
8 changed files with 218 additions and 13 deletions
+6 -1
View File
@@ -27,7 +27,7 @@ function updPlayer(memberId, fn) {
function view(me) {
const p = player(me.memberId) || updPlayer(me.memberId, () => {});
const s = ledger.settings();
return { bank: p.bank, chapter: p.chapter, cleared: p.cleared, items: p.items, best: p.runs ? p.best : 0, runs: p.runs,
return { bank: p.bank, chapter: p.chapter, cleared: p.cleared, items: p.items, best: p.runs ? p.best : 0, runs: p.runs, freeUpgrades: Number(p.freeUpgrades) || 0,
goal: spawn.goalFor(p.chapter), prices: { pol: s.itemPol, drips: s.itemDrips }, dripPol: Number(s.dripPol) };
}
@@ -112,18 +112,23 @@ function end(me, runId) {
function refuelled(me, runId) { return updRun(runId, x => { x.refuels++; }); }
// hangar
// a free upgrade token (the member perk, lib/starter.js) pays for the next purchase whatever it is: no drips, no POL moved
function useFree(me, item) { updPlayer(me.memberId, x => { x.freeUpgrades = Math.max(0, (Number(x.freeUpgrades) || 0) - 1); x.items[item] = true; }); return { ok: true, free: true, paid: 'free upgrade' }; }
function buy(me, item) {
const s = ledger.settings(); const p = player(me.memberId) || updPlayer(me.memberId, () => {});
const free = Number(p.freeUpgrades) > 0;
if (s.itemDrips[item] != null) {
const cost = Number(s.itemDrips[item]);
if (item === 'ship' && p.items.ship) return { error: 'You already own the Courier Mk II.' };
if (p.items[item] && item !== 'ship') return { error: 'That one is already armed for your next run.' };
if (free) return useFree(me, item);
if (p.bank < cost) return { error: 'Not enough drips. You have ' + p.bank + ', it costs ' + cost + '.' };
updPlayer(me.memberId, x => { x.bank -= cost; x.items[item] = true; });
return { ok: true, paid: cost + ' drips' };
}
if (s.itemPol[item] != null) {
if (p.items[item]) return { error: 'That one is already armed for your next run.' };
if (free) return useFree(me, item);
const r = ledger.spend(me, item, Number(s.itemPol[item])); if (r.error) return r;
updPlayer(me.memberId, x => { x.items[item] = true; });
return { ok: true, paid: r.pol + ' POL' };
+60
View File
@@ -0,0 +1,60 @@
// Member welcome offer (Marty, 2026-10-05): turn players into InstantAdPay members through the $5 package.
//
// After a chapter clear, a signed-in player with no InstantAdPay member id yet (the hand-off carried memberId 0, so they
// play on the negative email id) gets one card a Central day: "Become an InstantAdPay member". Never a guest, never
// during a run. InstantAdPay owns the purchase and its bonus credits; the bonus number comes from its public endpoint
// (cached ten minutes) and the offer stays off while InstantAdPay says it is off. If the endpoint cannot be read the
// card still shows, without a number.
//
// The perk here: the first time a member (memberId > 0) comes through the hand-off, one free hangar upgrade. It is a
// token on the player (freeUpgrades) that makes the next hangar purchase cost nothing, drips or POL. A free POL item
// moves no POL: nothing leaves the pool and nothing is paid out, so Marty's "no POL the game did not earn" rule holds.
//
// Player record fields: starterShown (the Central day the card last showed), perkAt (ms, granted once, never again),
// freeUpgrades (tokens left), perkNotice (the one-time lobby message is still to be shown).
'use strict';
const game = require('./game');
const ledger = require('./ledger');
const IAP = () => String(process.env.IAP_URL || 'https://instantadpay.com').replace(/\/+$/, '');
const PERK = 'a free hangar upgrade';
const NOTICE = 'Member perk: a free hangar upgrade. Thanks for joining InstantAdPay!';
let cache = { at: 0, v: null };
// InstantAdPay's public offer numbers: { on, bonus } or null when unreadable (a failure is remembered for a minute)
async function publicOffer() {
if (Date.now() - cache.at < 10 * 60000) return cache.v;
try {
const r = await fetch(IAP() + '/api/starter/public', { signal: AbortSignal.timeout(5000) }); if (!r.ok) throw new Error('http ' + r.status);
const j = await r.json(); const b = Number(j.bonus);
cache = { at: Date.now(), v: { on: j.on !== false, bonus: isFinite(b) && b > 0 ? Math.round(b) : null } };
} catch (e) { cache = { at: Date.now() - 9 * 60000, v: null }; }
return cache.v;
}
// the card for this clear, or null. Counts as shown the moment it is handed out.
async function offerFor(me) {
if (!me || me.guest || Number(me.memberId) > 0) return null;
const p = game.player(me.memberId); const today = ledger.ctDay();
if (!p || p.starterShown === today) return null;
const pub = await publicOffer();
if (pub && pub.on === false) return null;
let fresh = false; game.updPlayer(me.memberId, x => { if (x.starterShown !== today) { x.starterShown = today; fresh = true; } });
if (!fresh) return null;
return { bonus: pub ? pub.bonus : null, perk: PERK, url: IAP() + '/my?from=driprunner#buy' };
}
// the hand-off: a member's first visit as a member gets the free upgrade, once per account
function grantPerk(memberId) {
if (!(Number(memberId) > 0)) return false; let granted = false;
game.updPlayer(memberId, x => { if (!x.perkAt) { x.perkAt = Date.now(); x.freeUpgrades = (Number(x.freeUpgrades) || 0) + 1; x.perkNotice = true; granted = true; } });
return granted;
}
// the one-time lobby message: handed out once, then cleared
function takeNotice(memberId) {
const p = game.player(memberId); if (!p || !p.perkNotice) return null;
game.updPlayer(memberId, x => { delete x.perkNotice; });
return NOTICE;
}
module.exports = { publicOffer, offerFor, grantPerk, takeNotice, PERK };