From 83da8c33f2c2210c068524f39d333aa712c08316 Mon Sep 17 00:00:00 2001 From: martbost Date: Wed, 30 Sep 2026 15:35:32 -0500 Subject: [PATCH] Facts you learn as you play (SkyCash): tips priced from the live IAP catalog on the lobby, run-over and chapter-cleared cards; Level up on InstantAdPay button in the lobby Co-Authored-By: Claude Fable 5.1 --- lib/tips.js | 37 +++++++++++++++++++++++++++++++++++++ public/play.html | 5 +++++ public/play.js | 11 ++++++----- server.js | 3 ++- 4 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 lib/tips.js diff --git a/lib/tips.js b/lib/tips.js new file mode 100644 index 0000000..b79f334 --- /dev/null +++ b/lib/tips.js @@ -0,0 +1,37 @@ +// "Facts so you learn as you play" (SkyCash, 2026-09-30). Every number comes from InstantAdPay's live +// catalog (price in cents, credits, and the POL the contract quotes right now), never typed in, so the +// tips stay true as POL moves. Cached ten minutes; with no catalog only the price-free tips show. +'use strict'; +const IAP = () => String(process.env.IAP_URL || 'https://instantadpay.com').replace(/\/+$/, ''); +const RATES = { visitCost: 3, featuredPerDay: 40 }; // IAP ads.js rates (visitCostPerVisit, featuredPerDay) +let cache = { at: 0, products: [] }; +const fmt = n => Number(n).toLocaleString('en-US', { maximumFractionDigits: n < 10 ? 2 : 0 }); + +async function catalog() { + if (Date.now() - cache.at < 10 * 60000) return cache.products; + try { + const r = await fetch(IAP() + '/api/catalog', { signal: AbortSignal.timeout(6000) }); const j = await r.json(); + const products = (j.products || []).filter(p => p.active && p.exists).map(p => ({ usd: p.priceCents / 100, credits: Number(p.creditAmount), pol: Number(BigInt(p.costWei) / 10n ** 12n) / 1e6 })).filter(p => p.pol > 0); + if (products.length) cache = { at: Date.now(), products }; + } catch (e) { if (!cache.products.length) cache.at = Date.now() - 9 * 60000; } // retry in a minute + return cache.products; +} + +async function list(settings) { + const ps = await catalog(); const by = usd => ps.find(p => p.usd === usd); + const p5 = by(5), p20 = by(20), p100 = by(100); const th = Number(settings.thresholdPol), drip = Number(settings.dripPol); + const tips = [ + 'Every refuel is a verified visit an advertiser paid for on InstantAdPay. A share of it funds everyone’s chapter drips.', + 'Shield Core and Slow Field cost POL from your game balance, and that POL goes straight back into the pool.', + 'Your game balance pays out at ' + fmt(th) + ' POL, to the wallet on your InstantAdPay account. Link one under Wallet if you have not.', + 'Only the first clear of a chapter pays a drip (' + fmt(drip) + ' POL). Replays are for practice and for drips to spend in the hangar.', + 'Your first $20 buyer on InstantAdPay pays you 50 percent. Your second opens level 2: 20 percent of everything their people buy.', + 'InstantAdPay packages are bought with POL and pay your sponsor on the spot, on chain. Nothing to withdraw, nothing to wait for.', + ]; + if (p20) tips.push('A $20 InstantAdPay package is about ' + fmt(p20.pol) + ' POL today. Half of it goes to the sponsor, on chain, the moment it is bought.'); + if (p5) tips.push('$5 on InstantAdPay is ' + fmt(p5.credits) + ' credits, about ' + fmt(p5.pol) + ' POL today. That runs ' + Math.floor(p5.credits / RATES.visitCost) + ' verified visits to your own page.'); + if (p5) tips.push('A Featured ad on InstantAdPay is ' + RATES.featuredPerDay + ' credits a day. A $5 pack keeps you featured for ' + Math.floor(p5.credits / RATES.featuredPerDay) + ' days.'); + if (p100 && p100.credits > p100.usd * 100) tips.push('The $100 InstantAdPay pack is ' + fmt(p100.credits) + ' credits for about ' + fmt(p100.pol) + ' POL today: ' + fmt(p100.credits - p100.usd * 100) + ' bonus credits on top of the ' + fmt(p100.usd * 100) + ' you paid for.'); + return tips; +} +module.exports = { list, catalog }; diff --git a/public/play.html b/public/play.html index d20be75..d95f033 100644 --- a/public/play.html +++ b/public/play.html @@ -76,6 +76,7 @@ canvas#game{position:absolute;inset:0;width:100%;height:100%;display:block;touch .buy.no{opacity:.4;pointer-events:none} .led{display:flex;justify-content:space-between;gap:8px;font-size:12px;color:var(--ink2);padding:7px 2px;border-top:1px solid var(--line)}.led:first-child{border-top:0}.led .m{font:700 12px var(--mono);color:var(--gold);white-space:nowrap}.led .m.ok{color:var(--ok)}.led .m.neg{color:var(--sig)}.led a{color:var(--cyan2)} .prog{height:8px;background:rgba(255,255,255,.08);border-radius:4px;overflow:hidden;margin-top:8px}.prog i{display:block;height:100%;background:linear-gradient(90deg,var(--cyan),var(--gold));box-shadow:0 0 10px rgba(255,194,75,.5)} +.tip{margin:12px 0 0;padding:10px 12px;border-radius:10px;background:rgba(34,211,238,.07);border:1px solid rgba(34,211,238,.25);font-size:12px;line-height:1.45;color:var(--ink2);text-align:left}.tip b{display:block;font:700 9px var(--body);letter-spacing:.16em;text-transform:uppercase;color:var(--cyan);margin-bottom:3px} .toast{position:absolute;left:50%;bottom:calc(70px + env(safe-area-inset-bottom,0px));transform:translateX(-50%);z-index:20;background:var(--panel2);border:1px solid var(--line);color:var(--ink);font-size:12px;padding:8px 12px;border-radius:10px;opacity:0;transition:opacity .2s;pointer-events:none;max-width:92%;text-align:center} .toast.on{opacity:1} .tapdesk{position:absolute;bottom:calc(14px + env(safe-area-inset-bottom,0px));left:14px;z-index:5;font:600 10px var(--body);letter-spacing:.14em;text-transform:uppercase;color:var(--muted);pointer-events:none} @@ -105,8 +106,10 @@ canvas#game{position:absolute;inset:0;width:100%;height:100%;display:block;touch
Balance0.000
+
+ Level up on InstantAdPay
connecting…
@@ -117,12 +120,14 @@ canvas#game{position:absolute;inset:0;width:100%;height:100%;display:block;touch diff --git a/public/play.js b/public/play.js index 6dcda4e..aaffde8 100644 --- a/public/play.js +++ b/public/play.js @@ -6,7 +6,8 @@ var $ = function (id) { return document.getElementById(id); }; var canvas = $('game'), ctx = canvas.getContext('2d'); var W = 390, H = 760, DPR = 1, floorY = H - DRSpawn.FLOOR; var player = { x: 100, y: 300, vy: 0, r: 13, tilt: 0 }; -var ME = null, P = null, BAL = null, POOL = null, IAP = 'https://instantadpay.com'; +var ME = null, P = null, BAL = null, POOL = null, IAP = 'https://instantadpay.com', TIPS = [], tipAt = Math.floor(Math.random() * 97); +function tip(id) { var el = $(id); if (!TIPS.length) { el.hidden = true; return; } var t = TIPS[tipAt++ % TIPS.length]; el.innerHTML = 'Did you know' + esc(t); el.hidden = false; } // rotates through the facts var R = null; // the live run var muted = false; try { muted = localStorage.getItem('dr.muted') === '1'; } catch (e) {} @@ -43,12 +44,12 @@ var hudCache = {}; function setHud() { if (!R) return; var v = { d: R.drips, c: function f3(n) { return Number(n || 0).toFixed(3); } /* ---------- lobby / me ---------- */ -function loadMe() { return api('/api/me').then(function (r) { if (r._status !== 200) throw r; ME = r.me; P = r.player; BAL = r.balance; POOL = r.pool; IAP = r.iap || IAP; return r; }); } +function loadMe() { return api('/api/me').then(function (r) { if (r._status !== 200) throw r; ME = r.me; P = r.player; BAL = r.balance; POOL = r.pool; IAP = r.iap || IAP; TIPS = r.tips || []; return r; }); } function lobby() { R = null; $('hud').classList.remove('on'); $('tapdesk').hidden = true; $('lChap').textContent = P.chapter; $('lDrips').textContent = P.bank.toLocaleString(); $('lPol').textContent = f3(BAL.unpaid); $('lPool').innerHTML = 'POL pool ' + f3(POOL.available) + ' · today’s cap left ' + f3(POOL.capLeft) + ' · a chapter drip is ' + f3(POOL.dripPol) + ''; - $('lIap').href = IAP + '/my'; + $('lIap').href = IAP + '/my'; $('bLevel').href = IAP + '/my#buy'; tip('lTip'); $('lMember').innerHTML = 'InstantAdPay · ' + (ME.username ? '@' + ME.username : '#' + ME.memberId) + ' · ' + (ME.wallet ? ME.wallet.slice(0, 6) + '…' + ME.wallet.slice(-4) : 'no wallet on file'); show('ovLobby'); } @@ -110,7 +111,7 @@ function update(dt) { function crash(x, y) { sfx.crash(); burst(x, y, 36, '255,59,122', 260); burst(x, y, 14, '255,255,255', 160); R.shake = .5; over('Courier hit', 'A bot got you.'); } function over(title, why) { R.paused = true; flush(false); - setTimeout(function () { if (!R) return; $('oEyebrow').textContent = title; $('oTitle').textContent = 'Run over at ' + R.drips; $('oText').textContent = why + ' Refuel with a sponsor visit and keep this run, drips and chapter progress intact.'; $('bRefuel').hidden = false; $('oChip').hidden = false; show('ovOver'); }, 450); + setTimeout(function () { if (!R) return; $('oEyebrow').textContent = title; $('oTitle').textContent = 'Run over at ' + R.drips; $('oText').textContent = why + ' Refuel with a sponsor visit and keep this run, drips and chapter progress intact.'; $('bRefuel').hidden = false; $('oChip').hidden = false; tip('oTip'); show('ovOver'); }, 450); } function cleared() { R.paused = true; pill('Verifying…'); @@ -124,7 +125,7 @@ function cleared() { var why = { paid: 'First clear, verified. Added to your game balance.', replay: c.first ? 'Verified.' : 'You cleared this one before. Only the first clear pays.', pool: 'The POL pool is empty right now. Refuel visits fill it, so this clear counts but pays nothing.', cap: 'Today’s pool cap is spent. Chapter counts, no POL today.', flagged: 'This run was flagged by the server check, so it pays nothing.' }; $('cText').textContent = why[c.reason] || ''; $('cChip').className = 'chip ' + (c.pol ? 'ok' : 'sig'); $('cChip').textContent = (c.pol ? 'verified' : c.reason) + ' · ' + tm + ' play time'; R.chapter = c.next; R.goal = c.nextGoal; R.chapDrips = 0; if (r.pool != null) POOL.available = r.pool; - setTimeout(function () { show('ovClear'); }, 500); + tip('cTip'); setTimeout(function () { show('ovClear'); }, 500); }); } $('bNext').addEventListener('click', function () { if (!R) return; R.paused = false; R.inv = 1.5; hideAll(); }); diff --git a/server.js b/server.js index 6040272..1beb83c 100644 --- a/server.js +++ b/server.js @@ -23,6 +23,7 @@ const ledger = require('./lib/ledger'); const faucet = require('./lib/faucet'); const spawn = require('./lib/spawn'); const badge = require('./lib/badge'); +const tips = require('./lib/tips'); // facts you learn as you play, priced from the live IAP catalog const PORT = Number(process.env.PORT || 3000); const DATA_DIR = process.env.DATA_DIR || path.join(__dirname, 'data'); @@ -234,7 +235,7 @@ const server = http.createServer(async (req, res) => { if (!me) return json(res, 401, { error: 'Sign in through InstantAdPay first.', iap: IAP + '/api/my/driprunner' }); if (p === '/api/me' && req.method === 'GET') { const pl = ledger.pool(); - return json(res, 200, { me: { memberId: me.memberId, username: me.username, wallet: me.wallet }, player: game.view(me), balance: ledger.balance(me.memberId), pool: { available: pl.available, capLeft: pl.capLeft, dripPol: Number(ledger.settings().dripPol) }, iap: IAP, site: SITE }); + return json(res, 200, { me: { memberId: me.memberId, username: me.username, wallet: me.wallet }, player: game.view(me), balance: ledger.balance(me.memberId), pool: { available: pl.available, capLeft: pl.capLeft, dripPol: Number(ledger.settings().dripPol) }, iap: IAP, site: SITE, tips: await tips.list(ledger.settings()) }); } if (p === '/api/balance' && req.method === 'GET') return json(res, 200, ledger.balance(me.memberId)); if (p === '/api/run/start' && req.method === 'POST') { const { body } = await readBody(req); const r = game.start(me, body.W, body.H); return json(res, 200, { runId: r.id, seed: r.seed, W: r.W, H: r.H, speed: r.speed, chapter: r.chapter, goal: r.goal, armed: r.armed, ship: r.ship }); }