feat(net)!: client on server-run fights, websocket lobby, server economy (P1-5, P1-6, P1-7, P2-3, P2-4)
- net.js: REST + one WebSocket with reconnect; single-flight refresh shared across tabs; ?slot=N - lobby.js / netfight.js: server owns presence, challenges and the fight; client shows snapshots - game.js: every workshop change goes through RC.Eco via act() (server-checked online); results, rewards and achievements come from the server (match.end) - ranking/live/cloudsave on the new REST endpoints; online tournament removed until P2-6 BREAKING CHANGE: needs the new server (protocol v1); old online saves are not migrated.
This commit is contained in:
20
game/shop.js
20
game/shop.js
@@ -15,7 +15,6 @@
|
||||
// ready-made [body, accent] combinations
|
||||
RC.SCHEMES = [[0xff7a1a, 0x15171b], [0x15171b, 0xff7a1a], [0x2a6fd8, 0xe6e6e6], [0xd8452b, 0xf2c230],
|
||||
[0x5fae3b, 0x15171b], [0x6a3fb0, 0xf2c230], [0xe6e6e6, 0xd8452b], [0x3a3d44, 0x2e9c8f]];
|
||||
const SELL = 0.5;
|
||||
const HOTKEY = { weapon: 'hk_weapon', tower: 'hk_tower', gadget: 'hk_gadget' };
|
||||
const GLYPH = { chassis: '🧱', motor: '⚙️', wheels: '🛞', battery: '🔋', armour: '🛡️', weapon: '🪓', tower: '🔥', gadget: '🧰' };
|
||||
const ICO = { hp: ['ico_hp', '❤️'], armour: ['ico_armour', '🛡️'], speed: ['ico_speed', '⏱️'], weight: ['ico_weight', '⚖️'],
|
||||
@@ -98,7 +97,7 @@
|
||||
if (eq) act = `<button disabled>${t('equipped')}</button>`;
|
||||
else if (own) act = `<button class="primary" data-act="eq">${t('equip')}</button>`;
|
||||
else act = `<button class="primary" data-act="buy" ${save.money < p.cost ? 'disabled' : ''}>${t('buy', { n: Kit.fmt(p.cost) })}</button>`;
|
||||
if (p && own && !eq) act += `<button data-act="sell">${t('sell', { n: Kit.fmt(Math.round(p.cost * SELL)) })}</button>`;
|
||||
if (p && own && !eq) act += `<button data-act="sell">${t('sell', { n: Kit.fmt(RC.Eco.sellValue(sel)) })}</button>`;
|
||||
if (p && !own && save.money < p.cost) act += `<span class="muted">${t('need_money', { n: Kit.fmt(p.cost - save.money) })}</span>`;
|
||||
$('detail').innerHTML = `${RC.pic(p ? 'part_' + sel : null, p ? GLYPH[slot] : '✖')}
|
||||
<div><div class="nm">${p ? p.name : t('none')}</div><div class="ds">${p ? t('pd_' + sel) : t('none_' + slot)}</div>
|
||||
@@ -183,21 +182,18 @@
|
||||
}).join('');
|
||||
$('fitted').querySelectorAll('.frow').forEach(el => { el.onclick = e => {
|
||||
if (el.dataset.edit) { slot = 'weapon'; opt.sfx.click(); render(); return; }
|
||||
if (e.target.dataset.rm) { const s = e.target.dataset.rm; opt.getSave().build[s] = null; opt.sfx.click(); opt.onSave(); opt.onBuild(); render(); return; }
|
||||
if (e.target.dataset.rm) { const s = e.target.dataset.rm; if (!opt.act({ type: 'equip', slot: s, part: null }).ok) { opt.sfx.deny(); return; } opt.sfx.click(); opt.onSave(); opt.onBuild(); render(); return; }
|
||||
slot = el.dataset.goto; sel = opt.getSave().build[slot] || null; topTab = 'build'; opt.sfx.click(); render();
|
||||
}; });
|
||||
}
|
||||
|
||||
// every economy change goes through opt.act (RC.Eco rules; online the server checks the same action)
|
||||
function act2(what) {
|
||||
const save = opt.getSave(), p = sel ? RC.PARTS[sel] : null;
|
||||
if (what === 'buy' && p && save.money >= p.cost && !save.owned.includes(sel)) {
|
||||
save.money -= p.cost; save.owned.push(sel); save.build[slot] = sel; opt.sfx.buy();
|
||||
say(t('tip_bought', { name: p.name }));
|
||||
} else if (what === 'eq') {
|
||||
save.build[slot] = sel; opt.sfx.click();
|
||||
} else if (what === 'sell' && p && save.build[slot] !== sel) {
|
||||
save.owned = save.owned.filter(x => x !== sel); save.money += Math.round(p.cost * SELL); opt.sfx.buy();
|
||||
} else { opt.sfx.deny(); return; }
|
||||
const p = sel ? RC.PARTS[sel] : null;
|
||||
const a = what === 'buy' ? { type: 'buy', part: sel } : what === 'eq' ? { type: 'equip', slot, part: sel || null } : what === 'sell' ? { type: 'sell', part: sel } : null;
|
||||
if (!a || !opt.act(a).ok) { opt.sfx.deny(); return; }
|
||||
if (what === 'eq') opt.sfx.click(); else opt.sfx.buy();
|
||||
if (what === 'buy' && p) say(t('tip_bought', { name: p.name }));
|
||||
opt.onSave(); opt.onBuild(); render();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user