Referral layer: guest play from share links (/r/<username>), guest clears paid on sign-in, sharer's link via their IAP join page, 10% referrer slice of each referral refuel's pool income (IAP sponsor), share buttons + stats in the lobby and on chapter clears, wallet-less progress follows the member once a wallet is linked; 11 new checks
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+14
-1
@@ -24,6 +24,7 @@ const DEFAULTS = {
|
||||
lowBalancePol: 1,
|
||||
itemPol: { shield: 0.05, slow: 0.03 }, // hangar items paid from the POL balance (the sink)
|
||||
itemDrips: { magnet: 250, ship: 600 }, // hangar items paid in drips (never money)
|
||||
refSharePct: 10, // the referrer's slice of each refuel's pool income (their referrals' refuels), paid into the referrer's game balance
|
||||
testers: [], // emails or member ids allowed through the hand-off while signups = 'testers'
|
||||
trial: true, // posts say 'coming soon, in testing' and 'would have earned' until Marty flips it
|
||||
signups: 'testers' // 'testers' | 'key' (tester list or the curtain pass) | 'open' | 'closed'
|
||||
@@ -58,6 +59,17 @@ async function refuel(me, info) {
|
||||
const row = { id: id(), nonce: info.nonce || null, memberId: Number(me.memberId), username: me.username || null, campaignId: info.campaignId || null, credits, usd: r4(usd), share: r4(share), usdPerPol: r4(rate), pol, via: info.via || 'callback', day: ctDay(), ts: Date.now() };
|
||||
store.update('refuels', [], all => { all.push(row); return all; });
|
||||
poolAdd('in', pol);
|
||||
// the referral slice: a cut of THIS refuel's pool income, so it can never cost more than the refuel brought in
|
||||
const ref = info.referrer; const pct = Number(s.refSharePct) || 0;
|
||||
if (ref && ref.memberId > 0 && ref.memberId !== Number(me.memberId) && pct > 0) {
|
||||
const slice = r4(pol * pct / 100);
|
||||
if (slice > 0) {
|
||||
poolAdd('out', slice);
|
||||
updAccount(ref.memberId, a => { a.unpaid += slice; a.earnedTotal = r4((a.earnedTotal || 0) + slice); a.refTotal = r4((a.refTotal || 0) + slice); a.wallet = a.wallet || ref.wallet || null; a.username = a.username || ref.username || null; });
|
||||
store.update('refslices', [], all => { all.push({ id: id(), refuelId: row.id, memberId: ref.memberId, fromMemberId: Number(me.memberId), fromUsername: me.username || null, pol: slice, day: ctDay(), ts: Date.now() }); return all; });
|
||||
row.slice = { to: ref.memberId, pol: slice };
|
||||
}
|
||||
}
|
||||
return row;
|
||||
}
|
||||
function refuelsToday() { const d = ctDay(); return store.read('refuels', []).filter(r => r.day === d); }
|
||||
@@ -125,9 +137,10 @@ function balance(memberId) {
|
||||
const hist = []
|
||||
.concat(store.read('drips', []).filter(d => d.memberId === Number(memberId)).map(d => ({ t: d.ts, kind: 'drip', label: 'Chapter ' + d.chapter + ' · first clear', pol: d.pol })))
|
||||
.concat(store.read('spends', []).filter(d => d.memberId === Number(memberId)).map(d => ({ t: d.ts, kind: 'spend', label: 'Hangar · ' + d.item, pol: -d.pol })))
|
||||
.concat(store.read('refslices', []).filter(d => d.memberId === Number(memberId)).map(d => ({ t: d.ts, kind: 'ref', label: 'Referral · ' + (d.fromUsername ? '@' + d.fromUsername : 'a player') + ' refuelled', pol: d.pol })))
|
||||
.concat(store.read('payouts', []).filter(d => d.memberId === Number(memberId)).map(d => ({ t: d.ts, kind: 'payout', label: d.status === 'paid' ? 'Paid to your wallet' : d.status === 'failed' ? 'Payout failed: ' + (d.error || '') : 'Payout on its way', pol: d.pol, status: d.status, tx: d.tx || null })))
|
||||
.sort((x, y) => y.t - x.t).slice(0, 40);
|
||||
return { unpaid: r4(a.unpaid), paidTotal: r4(a.paidTotal || 0), spentTotal: r4(a.spentTotal || 0), earnedTotal: r4(a.earnedTotal || 0), threshold: Number(s.thresholdPol), history: hist, wallet: a.wallet || null };
|
||||
return { unpaid: r4(a.unpaid), paidTotal: r4(a.paidTotal || 0), spentTotal: r4(a.spentTotal || 0), earnedTotal: r4(a.earnedTotal || 0), refTotal: r4(a.refTotal || 0), refSharePct: Number(s.refSharePct) || 0, threshold: Number(s.thresholdPol), history: hist, wallet: a.wallet || null };
|
||||
}
|
||||
|
||||
module.exports = { DEFAULTS, settings, setSettings, ctDay, pool, refuel, refuelsToday, account, chapterDrip, spend, sweep, payable, mark, balance, usdPerPol, r4 };
|
||||
|
||||
Reference in New Issue
Block a user