view update
This commit is contained in:
449
game/game.js
449
game/game.js
@@ -19,6 +19,21 @@
|
||||
|
||||
// Credits (standard for every game): shown on the title screen, links open in the normal browser
|
||||
const DISCORD = 'https://discord.gg/Ej4JPmCZva';
|
||||
// live settings from the backend (/live): news, events, unlocks, kill switch.
|
||||
// Always usable - without a backend or network this is simply "nothing special running".
|
||||
let LIVE = RC.Live.parse(null, Date.now(), BUILD_ID());
|
||||
const liveText = o => (o && (o[L.lang] || o.en || o.de)) || '';
|
||||
const evMul = () => (LIVE.event ? LIVE.event.prizeMul : 1);
|
||||
// extra earnings from a running event, shown as its own result line
|
||||
function applyEvent(money, lines) {
|
||||
const m = evMul();
|
||||
if (m === 1 || money <= 0) return money;
|
||||
const bonus = Math.round(money * m) - money;
|
||||
if (bonus) lines.push([t('event_bonus'), bonus]);
|
||||
return money + bonus;
|
||||
}
|
||||
function BUILD_ID() { return (typeof window !== 'undefined' && window.RC_BUILD) || ''; }
|
||||
|
||||
const SITE = 'https://michael-media.de';
|
||||
// build stamp comes from build-web.mjs; identifies the exact release in a leaked copy
|
||||
const BUILD = (typeof window !== 'undefined' && window.RC_BUILD) || '';
|
||||
@@ -33,22 +48,26 @@
|
||||
|
||||
// ---------------------------------------------------------------- services
|
||||
const L = Kit.i18n(window.LANG, { prefix: ID });
|
||||
// first start (no saved choice yet): default to English, not the browser language
|
||||
if (Kit.store(ID).get('lang', null) === null) L.set('en');
|
||||
const t = L.t;
|
||||
const store = Kit.store(ID);
|
||||
// steer: 'simple' (keys = screen direction) | 'tank' · diff: 'easy' | 'normal' | 'hard' · autofire: weapon fires by itself in reach
|
||||
const settings = Object.assign({ gfx: 'medium', intro: true, steer: 'tank', diff: 'easy', autofire: true, cam: 'fpv', arena: 'random' }, store.get('settings', {}));
|
||||
const settings = Object.assign({ gfx: 'medium', intro: true, steer: 'tank', autofire: true, cam: 'fpv', arena: 'random', quiet: false }, store.get('settings', {}));
|
||||
// v2: Michael found "simple" steering worse -> tank is the default again, old saved choice reset once
|
||||
// v3: fights start in first person (cockpit) -> old saved camera reset once
|
||||
if (!settings.v || settings.v < 2) settings.steer = 'tank';
|
||||
if (!settings.v || settings.v < 3) { settings.cam = 'fpv'; settings.v = 3; store.set('settings', settings); }
|
||||
// difficulty: player hit points x, AI skill +
|
||||
const DIFF = { easy: { hp: 1.4, skill: -0.2 }, normal: { hp: 1.15, skill: -0.05 }, hard: { hp: 0.95, skill: 0.12 } };
|
||||
// fixed balance baseline (used to be the "easy" setting, which was the default anyway).
|
||||
// The weight class is meant to be the dial from here on, not a difficulty menu.
|
||||
const BASE = { hp: 1.4, skill: -0.2 };
|
||||
const saveSettings = () => store.set('settings', settings);
|
||||
const accounts = RC.Accounts(ID);
|
||||
const newSave = () => ({
|
||||
money: 800, fame: 0, best: 0, season: 1, beaten: 0, wins: 0, losses: 0, games: 0,
|
||||
owned: Object.values(RC.STARTER).filter(Boolean), build: Object.assign({}, RC.STARTER),
|
||||
paint: { body: 0xff7a1a, accent: 0x15171b }, robotName: 'Clank', flag: 'XX', tutorialSeen: false,
|
||||
paint: { body: 0xff7a1a, accent: 0x15171b }, robotName: 'Clank', flag: 'XX', tutorialSeen: false, ach: {}, tour: null, cls: 'medium', leagues: null,
|
||||
robots: [], active: 0, // hangar: saved robot builds; the active one mirrors build/paint/robotName
|
||||
});
|
||||
const MAX_ROBOTS = 6;
|
||||
@@ -60,12 +79,17 @@
|
||||
r.name = save.robotName; r.build = save.build; r.paint = save.paint;
|
||||
}
|
||||
let slot = null, save = null; // per account, set by enterAccount()
|
||||
const persist = () => { if (slot && save) { syncActive(); slot.save(save); } };
|
||||
// the active class's league progress lives in save.beaten/season while you play,
|
||||
// and is written back to its own slot on every save (same idea as the active robot)
|
||||
const syncClass = () => { if (save && save.leagues && save.cls) save.leagues[save.cls] = { beaten: save.beaten | 0, season: save.season || 1 }; };
|
||||
const persist = () => { if (slot && save) { syncActive(); syncClass(); slot.save(save); } };
|
||||
const audio = Kit.createAudio({
|
||||
prefix: ID,
|
||||
files: ['sfx_click', 'sfx_buy', 'sfx_hit', 'sfx_saw', 'sfx_boom', 'sfx_win', 'sfx_lose', 'music_title', 'music_garage', 'music_fight'],
|
||||
throttle: { sfx_hit: 80, sfx_saw: 120, sfx_boom: 100 },
|
||||
});
|
||||
// first start (nothing saved yet): start very quiet; gain is squared, so these are low
|
||||
if (Kit.store(ID).get('music', null) === null) audio.setVolume(0.1, 0.35);
|
||||
const scores = Kit.scores({ url: DB_URL });
|
||||
const DEV = new URLSearchParams(location.search);
|
||||
if (DEV.has('touch')) document.body.classList.add('forcetouch'); // dev: &touch shows the touch pad on desktop
|
||||
@@ -98,6 +122,12 @@
|
||||
deny() { audio.tone(160, 0.15, 'square', 0.12, -40); },
|
||||
beep(hi) { audio.tone(hi ? 1046 : 523, hi ? 0.4 : 0.15, 'square', 0.14); },
|
||||
clunk() { audio.noise(0.25, 0.5, 260); audio.tone(70, 0.3, 'sine', 0.4, -20); },
|
||||
gate() { // metal garage door rolling open
|
||||
audio.noise(1.0, 0.4, 1500); audio.noise(0.9, 0.3, 500, 0.05); // metal roll rumble
|
||||
audio.tone(110, 0.9, 'sawtooth', 0.1, 70); // servo whir rising
|
||||
for (let k = 0; k < 6; k++) audio.tone(170 + k * 28, 0.05, 'square', 0.07, 0, k * 0.11); // chain clanks
|
||||
audio.noise(0.25, 0.55, 300, 0.9); audio.tone(58, 0.4, 'sine', 0.5, -22, 0.9); // heavy end clunk
|
||||
},
|
||||
win() { audio.sfx('sfx_win'); audio.arp([523, 659, 784, 1046, 1318], 0.09, 'square', 0.1); },
|
||||
lose() { audio.sfx('sfx_lose'); audio.arp([392, 330, 262, 196], 0.14, 'sawtooth', 0.1); },
|
||||
event(e) {
|
||||
@@ -126,10 +156,11 @@
|
||||
},
|
||||
loops(s) { // continuous weapons as short repeated bursts
|
||||
for (const r of s.robots) {
|
||||
if (r.sawOn && every('saw' + r.i, 110)) { audio.sfx('sfx_saw'); audio.tone(900 + Math.random() * 60, 0.1, 'sawtooth', 0.03); }
|
||||
if (r.flameOn && every('fl' + r.i, 120)) audio.noise(0.14, 0.12, 900);
|
||||
if (r.gunOn && every('gun' + r.i, 70)) audio.noise(0.04, 0.16, 3500);
|
||||
if (r.spin > 0.2 && every('spin' + r.i, 100)) audio.tone(120 + r.spin * 260, 0.1, 'sawtooth', 0.03 * r.spin);
|
||||
const q = settings.quiet ? 0.3 : 1, slow = settings.quiet ? 1.7 : 1; // quiet mode: softer + less often
|
||||
if (r.sawOn && every('saw' + r.i, 200 * slow)) { if (!settings.quiet) audio.sfx('sfx_saw', 0.35); audio.tone(360 + Math.random() * 40, 0.12, 'triangle', 0.02 * q); }
|
||||
if (r.flameOn && every('fl' + r.i, 120 * slow)) audio.noise(0.14, 0.12 * q, 900);
|
||||
if (r.gunOn && every('gun' + r.i, 70 * slow)) audio.noise(0.04, 0.16 * q, 3500);
|
||||
if (r.spin > 0.2 && every('spin' + r.i, 100 * slow)) audio.tone(120 + r.spin * 260, 0.1, 'sawtooth', 0.03 * r.spin * q);
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -155,6 +186,7 @@
|
||||
onPaint: () => view.setPaint(paintObj()),
|
||||
onPreview: b => { if (mode === 'garage') view.showGarage(b, paintObj()); }, // show the selected part on the robot
|
||||
onHangarView: el => renderHangar(el), // Hangar tab content
|
||||
locked: id => LIVE.locked('parts', id), // event/unlock: part not released yet
|
||||
sfx: SFX,
|
||||
});
|
||||
|
||||
@@ -202,12 +234,42 @@
|
||||
const fbAcc = () => (fbUser() && !fbUser().guest ? fbUser() : null); // real (e-mail) account
|
||||
const playerName = () => (fbUser() ? fbUser().name : accounts.current && !accounts.current.guest ? accounts.current.name : save ? save.robotName : '');
|
||||
// save slot: Firebase account -> robotclash.save.fb_<uid>, else local profile / guest
|
||||
const saveKey = () => (fbAcc() ? ID + '.save.fb_' + fbAcc().uid : accounts.saveKey());
|
||||
// Two completely separate games: the campaign (league, seasons) and online play (PvP).
|
||||
// Money, parts and robots never cross over - they simply live in different saves.
|
||||
// Opening the page always starts in online mode; the campaign keeps the old save key,
|
||||
// so an existing game carries on as the campaign.
|
||||
let gameMode = 'online';
|
||||
const saveKey = () => (fbAcc() ? ID + '.save.fb_' + fbAcc().uid : accounts.saveKey())
|
||||
+ (gameMode === 'online' ? '.online' : '');
|
||||
function setMode(m) {
|
||||
const onlineOk = net && net.enabled && !LIVE.onlineOff;
|
||||
gameMode = onlineOk ? m : 'campaign'; // no Firebase or switched off: campaign only
|
||||
document.body.dataset.gmode = gameMode;
|
||||
}
|
||||
function switchMode(m) {
|
||||
if (m === gameMode) return;
|
||||
persist(); // keep the mode we are leaving
|
||||
setMode(m);
|
||||
loadSave(); hud(); shop.reset();
|
||||
openGarage();
|
||||
// banner() only works during a fight (it writes to F) - the mechanic says it instead
|
||||
$('mechTip').textContent = t(gameMode === 'online' ? 'mode_online' : 'mode_campaign') + ': ' + t('mode_switched');
|
||||
}
|
||||
|
||||
function hud() {
|
||||
$('hMoney').textContent = save ? Kit.fmt(save.money) : '–';
|
||||
$('hFame').textContent = save ? Kit.fmt(save.fame) : '–';
|
||||
$('hLeague').textContent = save ? t('league_chip', { s: save.season, n: save.beaten, m: RC.LEAGUE.length }) : '–';
|
||||
$('hRank').textContent = save ? t('rank_' + RC.Progress.rankOf(save.fame).key) : '';
|
||||
const ht = $('hTour');
|
||||
if (ht) {
|
||||
const running = save && save.tour && !save.tour.done;
|
||||
const on = running || (typeof tourOpen === 'function' && tourOpen());
|
||||
ht.classList.toggle('hide', !on);
|
||||
if (on) ht.textContent = '🏆 ' + (running ? t('tour_continue') : t('tournament'));
|
||||
}
|
||||
const camp = gameMode === 'campaign';
|
||||
$('hModeLbl').textContent = camp ? t('hud_league') : t('mode_online');
|
||||
$('hLeague').textContent = !save ? '–' : camp ? t('league_chip', { s: save.season, n: save.beaten, m: RC.LEAGUE.length }) : t('mode_pvp');
|
||||
$('hUser').textContent = fbUser() ? '👤 ' + fbUser().name : accounts.current ? (accounts.current.guest ? '👤 ' + t('guest') : '👤 ' + accounts.current.name) : save ? '👤 ' + t('guest') : '👤 –';
|
||||
$('bMute').textContent = audio.muted ? '🔇' : '🔊';
|
||||
$('bMute').title = (audio.muted ? t('sound_off') : t('sound_on')) + ' (M)';
|
||||
@@ -218,6 +280,7 @@
|
||||
mode = m;
|
||||
document.body.dataset.mode = m; // CSS shows/places the HUD per screen
|
||||
document.body.classList.toggle('fighting', m === 'fight' || m === 'pause');
|
||||
if (m !== 'fight' && m !== 'pause') { const dv = $('dmgvig'); if (dv) dv.style.opacity = 0; } // clear the red damage glow when the fight is over
|
||||
show('shop', m === 'garage');
|
||||
show('fightHud', m === 'fight' || m === 'pause' || m === 'result');
|
||||
backdrop(m === 'garage' ? 'bg_workshop.jpg' : null);
|
||||
@@ -235,7 +298,8 @@
|
||||
overlay.innerHTML = `<div class="title"><div class="tpanel">${logo}
|
||||
<div class="hazbar"></div><p class="tag">${t('click_start')}</p>
|
||||
<p class="credits">${CREDITS}</p></div></div>`;
|
||||
overlay.classList.remove('hide'); overlay.classList.add('clear'); overlay.style.backgroundImage = '';
|
||||
overlay.classList.remove('hide'); overlay.classList.remove('clear');
|
||||
overlay.style.backgroundImage = `url("${img('bg_start.jpg')}")`; // start screen backdrop (ComfyGen)
|
||||
const go = e => {
|
||||
if (e) { e.stopPropagation(); if (e.preventDefault) e.preventDefault(); } // must not also skip the intro
|
||||
removeEventListener('pointerdown', go, true); removeEventListener('keydown', go, true);
|
||||
@@ -284,10 +348,11 @@
|
||||
overlay.innerHTML = `<div class="title"><div class="tpanel">
|
||||
${logo}
|
||||
<div class="tag">${t('menu_text')}</div>
|
||||
${liveBanner()}
|
||||
<div class="hazbar"></div>
|
||||
<div class="tmenu">${btns}</div>
|
||||
<div class="trow2"><button id="bSet">⚙ ${t('settings')}</button><button id="bHelp">${t('how_to')}</button>
|
||||
<button id="bLang" title="English / Deutsch">🌐 ${t('lang_self')}</button>${scores.enabled ? `<button id="bRank">🏆 ${t('ranking')}</button>` : ''}</div>
|
||||
<button id="bLang" title="English / Deutsch">🌐 ${t('lang_self')}</button>${save ? `<button id="bAch">🏅 ${t('achievements')}</button>` : ''}${scores.enabled ? `<button id="bRank">🏆 ${t('ranking')}</button>` : ''}</div>
|
||||
<p class="credits">${CREDITS}</p></div></div>`;
|
||||
overlay.classList.remove('hide'); overlay.classList.add('clear'); overlay.style.backgroundImage = '';
|
||||
const on = (id, f) => { const el = $(id); if (el) el.onclick = () => { SFX.click(); f(); }; };
|
||||
@@ -300,14 +365,17 @@
|
||||
on('bSet', () => showSettings(showTitle));
|
||||
on('bHelp', () => showHelp(showTitle));
|
||||
on('bLang', () => L.next());
|
||||
on('bAch', () => showAchievements(showTitle));
|
||||
on('bRank', () => showRanking(showTitle));
|
||||
hud();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- online lobby
|
||||
let onlineReady = false, lobbyRows = [], pendingOut = null, lobbyRoom = null; // lobbyRoom = country code or null (room picker)
|
||||
let ntour = null, inNetTour = false; // live multiplayer tournament
|
||||
async function startOnline() {
|
||||
if (!net.enabled) return;
|
||||
if (gameMode !== 'online') { setMode('online'); if (save) { loadSave(); hud(); } } // online uses its own save
|
||||
if (!net.auth.current) {
|
||||
if (save && !fbAcc()) return joinAnon(); // playing as guest -> straight in, anonymously
|
||||
showOnlineLogin(false, null, 'online'); return;
|
||||
@@ -383,7 +451,7 @@
|
||||
<label class="flagpick">${t('your_flag')} <select id="lFlag">${flagOpts}</select></label></div>
|
||||
<div class="plist">${showMe ? prow(null, true) : ''}${list || (showMe ? '' : `<div class="muted" style="padding:16px;text-align:center">${t('lobby_empty')}</div>`)}</div>
|
||||
${pendingOut ? `<p class="muted" style="margin:6px 0 0">${t('waiting_accept')} <button class="link" id="lCancel">${t('cancel')}</button></p>` : ''}
|
||||
<div class="row" style="margin-top:8px"><button id="lBack">${t('back')}</button><button class="primary" id="lQuick">${t('quick_match')}</button></div>
|
||||
<div class="row" style="margin-top:8px"><button id="lBack">${t('back')}</button><button id="lTour">🏆 ${t('ltour_title')}</button><button class="primary" id="lQuick">${t('quick_match')}</button></div>
|
||||
</div></div>`;
|
||||
overlay.classList.remove('hide'); overlay.classList.remove('clear');
|
||||
overlay.style.backgroundImage = `linear-gradient(rgba(5,6,10,.6), rgba(5,6,10,.8)), url("${img('bg_title.jpg')}")`;
|
||||
@@ -393,6 +461,80 @@
|
||||
if ($('lCancel')) $('lCancel').onclick = () => { SFX.click(); lobby.cancel(); pendingOut = null; renderLobby(); };
|
||||
$('lQuick').onclick = () => { const idle = here.find(r => r.state === 'idle') || all.find(r => r.state === 'idle'); if (idle) { SFX.click(); pendingOut = idle.uid; lobby.challenge(idle.uid); renderLobby(); } else SFX.deny(); };
|
||||
$('lBack').onclick = () => { SFX.click(); if (save) openGarage(); else showTitle(); };
|
||||
$('lTour').onclick = () => { SFX.click(); openNetTourney(); };
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- live multiplayer tournament
|
||||
function openNetTourney() {
|
||||
if (!(net && net.enabled && net.auth.current)) { showOnlineLogin(false, null, 'online'); return; }
|
||||
const u = net.auth.current;
|
||||
if (!ntour) ntour = RC.NetTourney(net, { uid: u.uid, name: u.name || playerName(), flag: save.flag || 'XX' }, {
|
||||
onView: v => { if (inNetTour) renderNetTourney(v); },
|
||||
startMatch: info => startNetTourMatch(info),
|
||||
});
|
||||
inNetTour = true;
|
||||
ntour.join(save.build, paintObj());
|
||||
renderNetTourney(ntour.view());
|
||||
}
|
||||
function leaveNetTourney() {
|
||||
inNetTour = false;
|
||||
if (ntour) { ntour.leave(); }
|
||||
}
|
||||
function renderNetTourney(v) {
|
||||
if (!inNetTour) return;
|
||||
const pls = v.players.map(p => `<div class="prow ${p.me ? 'me' : ''}"><span class="pf">${flagHtml(p.flag)}</span>`
|
||||
+ `<span class="pn">${esc(p.name)}${p.me ? ` <span class="muted">(${t('you')})</span>` : ''}</span>`
|
||||
+ `<span class="${p.ready ? 'plus' : 'muted'}">${p.ready ? '✔ ' + t('ltour_ready') : t('ltour_waiting')}</span></div>`).join('')
|
||||
|| `<p class="muted" style="text-align:center;padding:12px">${t('ltour_empty')}</p>`;
|
||||
let body, buttons = '';
|
||||
if (v.phase === 'running' || v.phase === 'done') {
|
||||
body = netBracketHtml(v);
|
||||
if (v.me.match) buttons = `<button class="primary" id="ntFight">▶ ${t('tour_fight')} (${esc(v.me.match.opp || 'Bye')})</button>`;
|
||||
else if (v.me.champion) body += `<p class="plus" style="text-align:center">🏆 ${t('tour_won')}</p>`;
|
||||
else if (v.me.out) body += `<p class="muted" style="text-align:center">${t('tour_out')}</p>`;
|
||||
else body += `<p class="muted" style="text-align:center">${t('ltour_wait_round')}</p>`;
|
||||
} else {
|
||||
const me = v.players.find(p => p.me);
|
||||
body = `<p class="muted">${v.phase === 'countdown' ? t('ltour_countdown', { n: v.countdown }) : t('ltour_lobby', { n: v.readyCount })}</p>`
|
||||
+ `<div class="plist" style="min-width:0;max-width:420px;margin:0 auto">${pls}</div>`;
|
||||
buttons = me ? `<button class="${me.ready ? '' : 'primary'}" id="ntReady">${me.ready ? t('ltour_unready') : t('ltour_setready')}</button>` : '';
|
||||
}
|
||||
card(`<h1>🏆 ${t('ltour_title')}</h1>${body}
|
||||
<div class="row">${buttons}<button id="ntBack">${t('back')}</button></div>`, { wide: true, bg: 'bg_title.jpg' });
|
||||
if ($('ntReady')) $('ntReady').onclick = () => { SFX.click(); const me = v.players.find(p => p.me); ntour.setReady(!(me && me.ready)); };
|
||||
if ($('ntFight')) $('ntFight').onclick = () => { SFX.click(); if (v.me.match && v.me.match.opp == null) return; /* bye */ };
|
||||
$('ntBack').onclick = () => { SFX.click(); leaveNetTourney(); showLobby(); };
|
||||
}
|
||||
function netBracketHtml(v) {
|
||||
if (!v.order) return '';
|
||||
const rounds = RC.LTourney.rounds(v.order, v.results);
|
||||
const name = u => (u ? (v.players.find(p => p.uid === u) || {}).name || u.slice(0, 5) : '—');
|
||||
let cols = '';
|
||||
for (let r = 0; r < rounds.length; r++) {
|
||||
const col = rounds[r]; if (col.length < 2 && r) continue;
|
||||
let rows = '';
|
||||
for (let i = 0; i < col.length; i += 2) {
|
||||
rows += `<div class="tpair">${[col[i], col[i + 1]].map(u => {
|
||||
const mine = u === net.auth.current.uid;
|
||||
return `<div class="tslot ${mine ? 'you' : ''}">${esc(name(u))}</div>`; }).join('')}</div>`;
|
||||
}
|
||||
cols += `<div class="tcol"><div class="tch">${t('tour_round_' + (RC.Tourney.ROUND_KEY[r] || 'final'))}</div>${rows}</div>`;
|
||||
}
|
||||
return `<div class="bracket">${cols}</div>`;
|
||||
}
|
||||
function startNetTourMatch(info) {
|
||||
const opp = { name: info.opp.name || 'Rival', build: info.opp.build, paint: info.opp.paint || { body: 0x888888, accent: 0xff7a1a }, style: 'brawler', skill: 0.6, flag: info.opp.flag };
|
||||
startFight(opp, false, false, { id: info.id, host: info.host, seed: info.seed, tourney: { round: info.round, pair: info.pairIndex, oppUid: info.oppUid } });
|
||||
}
|
||||
function endNetTourFight(res, won, me) {
|
||||
if (ntour) ntour.reportWin(F.online.tourney.round, F.online.tourney.pair, won ? net.auth.current.uid : F.online.tourney.oppUid);
|
||||
save.games++; if (won) save.wins++; else save.losses++;
|
||||
save.fame += won ? 120 : 30; persist(); hud();
|
||||
(won ? SFX.win : SFX.lose)();
|
||||
setScreen('result');
|
||||
card(`<h1>${won ? t('victory') : t('defeat')}</h1><p>${esc(F.opp.name)}</p>
|
||||
<div class="row"><button class="primary" id="ntRes">🏆 ${t('ltour_title')}</button></div>`, { bg: won ? 'bg_win.jpg' : 'bg_lose.jpg' });
|
||||
$('ntRes').onclick = () => { SFX.click(); inNetTour = true; renderNetTourney(ntour.view()); };
|
||||
}
|
||||
function showIncoming(c) {
|
||||
card(`<h2>${t('challenge_in')}</h2><p>${flagHtml(c.fromFlag)} <b>${esc(c.fromName)}</b> ${t('wants_fight')}</p>
|
||||
@@ -470,6 +612,16 @@
|
||||
// saves from older versions: missing parts, invalid ids, hangar migration
|
||||
function repairSave() {
|
||||
save.owned = (save.owned || []).filter(id => RC.PARTS[id]);
|
||||
// weight classes: an older save has one league - that progress becomes the medium class
|
||||
if (!save.leagues) {
|
||||
save.leagues = { light: { beaten: 0, season: 1 },
|
||||
medium: { beaten: save.beaten | 0, season: save.season || 1 },
|
||||
heavy: { beaten: 0, season: 1 } };
|
||||
}
|
||||
for (const c of RC.CLASSES) if (!save.leagues[c.id]) save.leagues[c.id] = { beaten: 0, season: 1 };
|
||||
if (!RC.CLASSES.some(c => c.id === save.cls)) save.cls = 'medium';
|
||||
RC.setClass(save.cls);
|
||||
save.beaten = save.leagues[save.cls].beaten; save.season = save.leagues[save.cls].season;
|
||||
// hangar migration: older saves have only build/paint/robotName -> make it robot slot 0
|
||||
if (!Array.isArray(save.robots) || !save.robots.length) {
|
||||
save.robots = [{ name: save.robotName || 'Clank', build: save.build || Object.assign({}, RC.STARTER), paint: save.paint || { body: 0xff7a1a, accent: 0x15171b } }];
|
||||
@@ -530,6 +682,7 @@
|
||||
function signOut() {
|
||||
persist();
|
||||
if (lobby && onlineReady) { lobby.leave(); onlineReady = false; lobbyRows = []; pendingOut = null; }
|
||||
if (ntour) { ntour.leave(); inNetTour = false; }
|
||||
if (net && net.enabled) net.auth.logout();
|
||||
accounts.logout(); save = null; slot = null; F = null; hud();
|
||||
}
|
||||
@@ -559,10 +712,10 @@
|
||||
${item(t('s_music'), `<input type="range" id="sMusic" min="0" max="1" step="0.05" value="${audio.musicVol}">`)}
|
||||
${item(t('s_sfx'), `<input type="range" id="sSfx" min="0" max="1" step="0.05" value="${audio.sfxVol}">`)}
|
||||
${item(t('s_gfx'), seg('sGfx', settings.gfx, [['low', t('gfx_low')], ['medium', t('gfx_medium')], ['high', t('gfx_high')]]))}
|
||||
${item(t('s_diff'), seg('sDiff', settings.diff, [['easy', t('diff_easy')], ['normal', t('diff_normal')], ['hard', t('diff_hard')]]))}
|
||||
${item(t('s_cam'), seg('sCam', settings.cam, CAMS.map(c => [c, t('cam_' + c)])))}
|
||||
${item(t('s_steer'), seg('sSteer', settings.steer, [['tank', t('steer_tank')], ['simple', t('steer_simple')]]))}
|
||||
${item(t('s_autofire'), seg('sAuto', settings.autofire ? '1' : '0', [['1', t('on')], ['0', t('off')]]))}
|
||||
${item(t('s_quiet'), seg('sQuiet', settings.quiet ? '1' : '0', [['0', t('off')], ['1', t('on')]]))}
|
||||
${item(t('s_arena'), seg('sArena', settings.arena, [['random', t('arena_random')]].concat(RC.ARENAS.map(a => [a.id, t('arena_' + a.id)]))))}
|
||||
${item(t('s_intro'), seg('sIntro', settings.intro ? '1' : '0', [['1', t('on')], ['0', t('off')]]))}
|
||||
</div>
|
||||
@@ -576,10 +729,10 @@
|
||||
segOn('sMute', v => { if ((v === '1') !== audio.muted) audio.toggleMute(); hud(); });
|
||||
segOn('sGfx', v => { settings.gfx = v; saveSettings(); if (view) view.setQuality(v); });
|
||||
segOn('sIntro', v => { settings.intro = v === '1'; saveSettings(); });
|
||||
segOn('sDiff', v => { settings.diff = v; saveSettings(); });
|
||||
segOn('sSteer', v => { settings.steer = v; saveSettings(); });
|
||||
segOn('sCam', v => { settings.cam = v; saveSettings(); if (view) view.setCam(v); });
|
||||
segOn('sAuto', v => { settings.autofire = v === '1'; saveSettings(); });
|
||||
segOn('sQuiet', v => { settings.quiet = v === '1'; saveSettings(); });
|
||||
segOn('sArena', v => { settings.arena = v; saveSettings(); });
|
||||
$('sMusic').oninput = e => audio.setVolume(+e.target.value, audio.sfxVol);
|
||||
$('sSfx').oninput = e => audio.setVolume(audio.musicVol, +e.target.value);
|
||||
@@ -614,6 +767,41 @@
|
||||
step();
|
||||
}
|
||||
|
||||
// one line for the running event and one for the admin's message
|
||||
function liveBanner() {
|
||||
const out = [];
|
||||
if (LIVE.event) {
|
||||
const n = liveText(LIVE.event.name) || t('event_running');
|
||||
const extra = LIVE.event.prizeMul !== 1 ? ` · ${t('event_prize', { n: LIVE.event.prizeMul })}` : '';
|
||||
out.push(`<div class="evbar"><b>${t('event')}</b><span>${esc(n)}${extra}</span></div>`);
|
||||
}
|
||||
const m = liveText(LIVE.motd);
|
||||
if (m) out.push(`<p class="motd">${esc(m)}</p>`);
|
||||
return out.join('');
|
||||
}
|
||||
|
||||
function showAchievements(back) {
|
||||
overlayEnter();
|
||||
const P = RC.Progress, r = P.rankOf(save.fame);
|
||||
const pct = Math.round(r.pct * 100);
|
||||
const nextLine = r.next
|
||||
? t('rank_next', { n: t('rank_' + r.next.key), f: Kit.fmt(r.next.at - save.fame) })
|
||||
: t('rank_top');
|
||||
const rows = P.ACHIEVEMENTS.map(a => {
|
||||
const done = !!(save.ach && save.ach[a.id]);
|
||||
return `<div class="achrow ${done ? 'done' : 'todo'}"><span class="am">${done ? '🏅' : '🔒'}</span>
|
||||
<span><span class="an">${t('ach_' + a.id)}</span><br><span class="ad">${t('achd_' + a.id)}</span></span>
|
||||
<span class="${done ? 'plus' : 'muted'}">${Kit.fmt(a.reward)}</span></div>`;
|
||||
}).join('');
|
||||
card(`<h2>🏅 ${t('achievements')}</h2>
|
||||
<div class="rankbar"><div class="rt"><b>${t('rank_' + r.key)}</b><span class="muted">${nextLine}</span></div>
|
||||
<div class="bar"><i style="width:${pct}%"></i></div></div>
|
||||
<p class="muted">${t('ach_done', { n: P.earned(save), m: P.total })}</p>
|
||||
<div class="achlist">${rows}</div>
|
||||
<div class="row"><button class="primary" id="bBack">${t('back')}</button></div>`, { wide: true, bg: 'bg_title.jpg' });
|
||||
$('bBack').onclick = () => { SFX.click(); back(); };
|
||||
}
|
||||
|
||||
function showHelp(back) {
|
||||
overlayEnter();
|
||||
card(`<h2>${t('how_to')}</h2><p>${t('help_text')}</p>${keysHtml()}
|
||||
@@ -631,6 +819,14 @@
|
||||
$('bNo').onclick = () => { SFX.click(); back(); };
|
||||
$('bYes').onclick = () => { Object.assign(save, newSave()); RC.layerFromData(layer, null); save.tutorialSeen = true; persist(); hud(); shop.reset(); SFX.click(); openGarage(); };
|
||||
}
|
||||
// the rank badge opens the achievements page
|
||||
$('hTour').onclick = () => { SFX.click(); openNetTourney(); };
|
||||
$('chipFame').onclick = () => {
|
||||
if (!save || mode === 'intro' || mode === 'title') return;
|
||||
if (mode === 'fight') togglePause();
|
||||
SFX.click();
|
||||
showAchievements(mode === 'pause' ? () => { mode = 'fight'; togglePause(); } : currentBack());
|
||||
};
|
||||
$('bSettings').onclick = () => {
|
||||
if (mode === 'fight') togglePause();
|
||||
if (mode === 'intro') skipIntro();
|
||||
@@ -657,17 +853,98 @@
|
||||
setScreen('garage');
|
||||
view.showGarage(save.build, paintObj());
|
||||
audio.music('music_garage');
|
||||
shop.render(); hud();
|
||||
shop.render(); hud(); updateShopBar();
|
||||
$('zIn').onclick = () => { SFX.click(); view.zoomGarage(1.18); };
|
||||
$('zOut').onclick = () => { SFX.click(); view.zoomGarage(1 / 1.18); };
|
||||
}
|
||||
$('bGMenu').onclick = () => { SFX.click(); persist(); startIntroOrTitle(); };
|
||||
$('bGOnline').onclick = () => { SFX.click(); persist(); startOnline(); };
|
||||
if (!(net && net.enabled)) $('bGOnline').style.display = 'none';
|
||||
$('bGMode').onclick = () => { SFX.click(); switchMode(gameMode === 'online' ? 'campaign' : 'online'); };
|
||||
const onlineUsable = () => !!(net && net.enabled && !LIVE.onlineOff);
|
||||
if (!onlineUsable()) $('bGMode').style.display = 'none';
|
||||
$('bTrain').onclick = () => { SFX.click(); startFight(RC.DUMMY, true); };
|
||||
$('bLeague').onclick = () => { SFX.click(); showLeague(); };
|
||||
$('bLeague').onclick = () => { SFX.click(); if (gameMode === 'online') { persist(); startOnline(); } else showLeague(); };
|
||||
function updateShopBar() {
|
||||
const on = gameMode === 'online';
|
||||
$('bGMode').style.display = onlineUsable() ? '' : 'none';
|
||||
$('bGMode').textContent = on ? '🏆 ' + t('mode_campaign') : '🌍 ' + t('mode_online');
|
||||
$('bLeague').textContent = on ? t('to_lobby') : t('to_league');
|
||||
}
|
||||
|
||||
function applyClass(id) {
|
||||
if (id === save.cls) return;
|
||||
persist(); // write the ladder we are leaving
|
||||
save.cls = id;
|
||||
RC.setClass(id);
|
||||
save.beaten = save.leagues[id].beaten; save.season = save.leagues[id].season;
|
||||
save.tour = null; // a running bracket belongs to its class
|
||||
persist(); hud(); shop.render();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- tournament
|
||||
function tourState() { return save.tour || null; }
|
||||
const tourOpen = () => !!LIVE.tournament; // admin switch
|
||||
const tourFee = () => (tourOpen() ? 0 : RC.Tourney.ENTRY_FEE);
|
||||
function startTournament() {
|
||||
if (save.money < tourFee()) { SFX.deny(); return; }
|
||||
save.money -= tourFee();
|
||||
save.tour = RC.Tourney.create({ me: { name: save.robotName, build: save.build, paint: paintObj() }, seed: (Date.now() & 0xffffff) || 1 });
|
||||
persist(); hud();
|
||||
showTournament();
|
||||
}
|
||||
function showTournament() {
|
||||
const st = tourState();
|
||||
if (!st) { showLeague(); return; }
|
||||
overlayEnter();
|
||||
const nameOf = e => (e.player ? save.robotName : e.name);
|
||||
// a slot won its match if it shows up again in the next round's line-up (same object)
|
||||
const advanced = (e, r) => st.rounds[r + 1] && st.rounds[r + 1].indexOf(e) >= 0;
|
||||
const pr = RC.Tourney.pair(st); // the player's match this round (null if done)
|
||||
const playerMatch = !st.done && pr ? pr : null;
|
||||
|
||||
// draw the bracket column by column: quarters -> semis -> final -> champion
|
||||
let cols = '';
|
||||
for (let r = 0; r < st.rounds.length; r++) {
|
||||
const col = st.rounds[r];
|
||||
if (col.length < 2) continue; // single entry = champion, shown separately
|
||||
let rows = '';
|
||||
for (let i = 0; i < col.length; i += 2) {
|
||||
const pair = [col[i], col[i + 1]].filter(Boolean);
|
||||
const isPlayerPair = !st.done && r === st.round && pair.indexOf(pr && pr[0]) >= 0;
|
||||
const slots = pair.map(e => {
|
||||
const you = e.player, win = advanced(e, r);
|
||||
return `<div class="tslot ${you ? 'you' : ''} ${win ? 'win' : ''}" title="${esc(nameOf(e))}">${esc(nameOf(e))}${you ? '' : ` <span class="ki">${t('ai_tag')}</span>`}</div>`;
|
||||
}).join('');
|
||||
rows += `<div class="tpair ${isPlayerPair ? 'now' : ''}" ${isPlayerPair ? 'data-go="1"' : ''}>${slots}${isPlayerPair ? `<div class="tgo">▶ ${t('tour_fight')}</div>` : ''}</div>`;
|
||||
}
|
||||
cols += `<div class="tcol"><div class="tch">${t('tour_round_' + (RC.Tourney.ROUND_KEY[r] || 'final'))}</div>${rows}</div>`;
|
||||
}
|
||||
// champion column
|
||||
const champ = st.done && st.won ? save.robotName : (st.rounds.length && st.rounds[st.rounds.length - 1].length === 1 ? nameOf(st.rounds[st.rounds.length - 1][0]) : '?');
|
||||
cols += `<div class="tcol"><div class="tch">🏆 ${t('tour_champion')}</div><div class="tpair"><div class="tslot ${st.won ? 'you win' : 'win'}">${st.done ? esc(champ) : '…'}</div></div></div>`;
|
||||
|
||||
let head, buttons;
|
||||
if (st.done) {
|
||||
head = st.won
|
||||
? `<p class="plus">🏆 ${t('tour_won')} · ${t('tour_won_text', { n: Kit.fmt(st.prize) })}</p>`
|
||||
: `<p>${t('tour_out')} · ${t('tour_out_text', { n: Kit.fmt(st.prize) })}</p>`;
|
||||
buttons = `<button class="primary" id="tDone">${t('to_garage')}</button>`;
|
||||
} else {
|
||||
head = `<p>${t('tour_round_' + RC.Tourney.ROUND_KEY[st.round])} · ${playerMatch ? t('tour_your_match', { name: esc(playerMatch[1].name) }) : ''}</p>`;
|
||||
buttons = `<button id="tLater">${t('back')}</button><button class="primary" id="tGo">${t('tour_fight')}</button>`;
|
||||
}
|
||||
card(`<h1>🏆 ${t('tournament')}</h1>${head}
|
||||
<div class="bracket">${cols}</div>
|
||||
<div class="row">${buttons}</div>`, { wide: true, bg: 'bg_title.jpg' });
|
||||
|
||||
const go = () => { SFX.click(); const p = RC.Tourney.pair(st); RC.Tourney.simOthers(st); persist(); startFight(p[1], false, false, null, true); };
|
||||
if ($('tGo')) $('tGo').onclick = go;
|
||||
overlay.querySelectorAll('.tpair.now').forEach(el => { el.style.cursor = 'pointer'; el.onclick = go; });
|
||||
if ($('tLater')) $('tLater').onclick = () => { SFX.click(); openGarage(); };
|
||||
if ($('tDone')) $('tDone').onclick = () => { SFX.click(); save.tour = null; persist(); openGarage(); };
|
||||
}
|
||||
|
||||
function showLeague() {
|
||||
if (gameMode !== 'campaign') { switchMode('campaign'); return; } // league is campaign-only
|
||||
setScreen('league');
|
||||
const cards = RC.LEAGUE.map((o, i) => {
|
||||
const cls = i < save.beaten ? 'done' : i === save.beaten ? 'next' : 'locked';
|
||||
@@ -675,10 +952,21 @@
|
||||
<div class="sm">${i <= save.beaten ? t('style_' + o.style) : '???'}</div>
|
||||
<div class="pz">${RC.pic('ico_credits', '🪙')}${Kit.fmt(Math.round(o.prize * seasonMul()))}</div></div>`;
|
||||
}).join('');
|
||||
card(`<h2>${t('league_title', { s: save.season })}</h2><p>${t('league_text')}</p><div class="opps">${cards}</div>
|
||||
<div class="row"><button id="bBack">${t('back')}</button><button class="primary" id="bFight">${t('fight_vs', { name: RC.LEAGUE[save.beaten].name })}</button></div>
|
||||
const tabs = RC.CLASSES.map(c => {
|
||||
const pr = save.leagues[c.id] || { beaten: 0, season: 1 };
|
||||
return `<button data-v="${c.id}" class="${c.id === save.cls ? 'on' : ''}">${t('cls_' + c.id)}
|
||||
<small>${c.max} kg · ${pr.beaten}/${RC.LEAGUES[c.id].length}</small></button>`;
|
||||
}).join('');
|
||||
card(`<h2>${t('league_title', { s: save.season })}</h2>
|
||||
<div class="seg clstabs" id="clsTabs">${tabs}</div>
|
||||
<p>${t('league_text')}</p><div class="opps">${cards}</div>
|
||||
<div class="row"><button id="bBack">${t('back')}</button>
|
||||
<button class="primary" id="bFight">${t('fight_vs', { name: RC.LEAGUE[save.beaten].name })}</button></div>
|
||||
${save.beaten ? `<p class="muted">${t('exhibition_hint')}</p>` : ''}`,
|
||||
{ wide: true, bg: 'bg_title.jpg' });
|
||||
$('clsTabs').querySelectorAll('button').forEach(b => {
|
||||
b.onclick = () => { SFX.click(); applyClass(b.dataset.v); showLeague(); };
|
||||
});
|
||||
overlay.querySelectorAll('.opp.next').forEach(el => { el.style.cursor = 'pointer'; el.onclick = () => { SFX.click(); showVs(RC.LEAGUE[save.beaten]); }; });
|
||||
// beaten opponents: repeatable exhibition fights for half the prize (steady income)
|
||||
overlay.querySelectorAll('.opp.done').forEach(el => { el.style.cursor = 'pointer'; el.title = t('exhibition_note'); el.onclick = () => { SFX.click(); showVs(RC.LEAGUE[+el.dataset.i], true); }; });
|
||||
@@ -700,9 +988,19 @@
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- fight
|
||||
function startFight(opp, training, exhibition, online) {
|
||||
// spawn intro: the steel gate is shut over the arena, then splits open with a metal sound
|
||||
function gateOpen() {
|
||||
const g = $('gate'); if (!g) return;
|
||||
g.classList.remove('open', 'hide');
|
||||
void g.offsetWidth; // reflow so the transition runs from the shut state
|
||||
SFX.gate();
|
||||
requestAnimationFrame(() => g.classList.add('open'));
|
||||
setTimeout(() => g.classList.add('hide'), 1150);
|
||||
}
|
||||
|
||||
function startFight(opp, training, exhibition, online, tour) {
|
||||
hideOverlay();
|
||||
const D = DIFF[settings.diff] || DIFF.easy;
|
||||
const D = BASE;
|
||||
const stA = RC.stats(save.build), stB = RC.stats(opp.build);
|
||||
if (!online) stA.hp = Math.round(stA.hp * D.hp); // no handicap in live PvP
|
||||
const seed = online ? online.seed : (Date.now() & 0xffff) + save.games * 31;
|
||||
@@ -710,12 +1008,13 @@
|
||||
const ids = RC.ARENAS.map(a => a.id), idx = RC.LEAGUE.indexOf(opp);
|
||||
const bySize = RC.ARENAS.slice().sort((a, b) => a.half - b.half).map(a => a.id); // small -> big for league progression
|
||||
const arenaId = DEV.get('arena') ? DEV.get('arena')
|
||||
: (LIVE.event && LIVE.event.arena && !online) ? LIVE.event.arena
|
||||
: online ? ids[seed % ids.length]
|
||||
: idx >= 0 ? bySize[Math.min(bySize.length - 1, Math.floor(idx * bySize.length / RC.LEAGUE.length))]
|
||||
: settings.arena === 'random' || !settings.arena ? ids[(Math.random() * ids.length) | 0] : settings.arena;
|
||||
const s = RC.Combat.create({ robots: [stA, stB], seed, names: [save.robotName, opp.name], arena: arenaId });
|
||||
const skill = Kit.clamp(opp.skill + (save.season - 1) * 0.12 + D.skill, 0, 1);
|
||||
F = { s, opp, training, exhibition: !!exhibition, online, brain: online ? null : RC.AI.create({ style: opp.style, skill, seed: seed + 5 }), count: 3.5, beat: 4,
|
||||
F = { s, opp, training, exhibition: !!exhibition, online, tour: !!tour, brain: online ? null : RC.AI.create({ style: opp.style, skill, seed: seed + 5 }), count: 3.5, beat: 4,
|
||||
acc: [0, 0], accT: 0, banner: null, ended: false };
|
||||
if (online) {
|
||||
F.nf = RC.NetFight({ net, id: online.id, host: online.host, oppStyle: 'brawler', oppSkill: 0.6, onPeerLost: () => banner(t('peer_lost'), '#ff4a3a', 2.5), onPeerBack: () => banner(t('peer_back'), '#6dff9e', 1.6) });
|
||||
@@ -739,6 +1038,7 @@
|
||||
fx.clear();
|
||||
setScreen('fight');
|
||||
audio.music('music_fight');
|
||||
gateOpen();
|
||||
banner('📍 ' + t('arena_' + s.arena.id), '#ff7a1a', 2.2);
|
||||
if (save.games === 0 && !F.online) setTimeout(() => { if (mode === 'fight') banner(t('tut_controls'), '#ffffff', 5); }, 2400);
|
||||
const pg = $('padGadget'); if (pg) pg.style.display = s.robots[0].st.gadget ? '' : 'none';
|
||||
@@ -798,7 +1098,8 @@
|
||||
const near = tw.type === 'flamer' || tw.type === 'zapper';
|
||||
k.fire2 = dist < tw.range * 0.95 && ahead < (near ? 0.5 : 0.3);
|
||||
}
|
||||
if (me.st.gadget && !k.fire3) k.fire3 = RC.Combat.wantGadget(s, me, en);
|
||||
// the mine layer stays manual - you decide where a mine goes, the helper does not
|
||||
if (me.st.gadget && me.st.gadget.type !== 'mines' && !k.fire3) k.fire3 = RC.Combat.wantGadget(s, me, en);
|
||||
}
|
||||
return k;
|
||||
}
|
||||
@@ -852,7 +1153,9 @@
|
||||
|
||||
function banner(text, color, time = 1.4) { F.banner = { text, color: color || '#ff7a1a', t: time, max: time }; }
|
||||
|
||||
let ntourT = 0;
|
||||
function update(dt) {
|
||||
if (ntour && inNetTour) { ntourT -= dt; if (ntourT <= 0) { ntourT = 2; ntour.tick(); } }
|
||||
fx.update(dt);
|
||||
introTick();
|
||||
if (mode !== 'fight' || !F) return;
|
||||
@@ -960,10 +1263,27 @@
|
||||
$('fState').textContent = st;
|
||||
}
|
||||
|
||||
// achievements are part of the save, so campaign and online each have their own
|
||||
function awardAch(ctx) {
|
||||
const got = RC.Progress.check(save, ctx);
|
||||
if (!got.length) return got;
|
||||
let pay = 0;
|
||||
for (const a of got) pay += a.reward;
|
||||
save.money += pay;
|
||||
persist();
|
||||
SFX.buy && SFX.buy();
|
||||
return got;
|
||||
}
|
||||
const achHtml = got => (!got || !got.length ? '' :
|
||||
`<div class="achwon"><b>🏅 ${t('ach_new')}</b>` + got.map(a =>
|
||||
`<div><span>${t('ach_' + a.id)}</span><span class="plus">+${Kit.fmt(a.reward)}</span></div>`).join('') + '</div>');
|
||||
|
||||
function endFight() {
|
||||
const s = F.s, res = s.result, opp = F.opp, idx = RC.LEAGUE.indexOf(opp);
|
||||
const won = res.winner === 0, me = s.robots[0];
|
||||
if (F.online && F.online.tourney) { endNetTourFight(res, won, me); return; }
|
||||
if (F.online) { endOnlineFight(res, won, me); return; }
|
||||
if (F.tour) { endTourFight(res, won, me); return; }
|
||||
const lines = [];
|
||||
let money = 0, fame = 0, champion = false;
|
||||
if (!F.training) {
|
||||
@@ -995,10 +1315,14 @@
|
||||
const repair = Math.round((1 - me.hp / me.maxHp) * me.st.value * 0.06 + (res.reason === 'pit' && !won ? me.st.value * 0.03 : 0));
|
||||
const paid = Math.min(repair, save.money + money);
|
||||
if (paid) lines.push([t('r_repair'), -paid]);
|
||||
money = applyEvent(money, lines);
|
||||
money -= paid;
|
||||
save.money += money; save.fame += fame;
|
||||
persist();
|
||||
}
|
||||
const gotAch = awardAch({ won, reason: res.reason, hpPct: me.hp / me.maxHp, dealt: me.dealt,
|
||||
lost: ['armour', 'wheels', 'weapon', 'tower'].filter(k => me.lost && me.lost[k]).length,
|
||||
training: F.training, exhibition: F.exhibition, champion });
|
||||
hud();
|
||||
(won ? SFX.win : SFX.lose)();
|
||||
const title = res.winner === -1 ? t('draw') : won ? t('victory') : t('defeat');
|
||||
@@ -1009,6 +1333,7 @@
|
||||
card(`<h1>${title}</h1><p>${why}</p>
|
||||
${champion ? `<h2>${t('champion_title', { s: save.season - 1 })}</h2><p>${t('champion_text')}</p>` : ''}
|
||||
<div class="res">${stats}${rows}${!F.training && fame ? `<span>${t('hud_fame')}</span><span class="plus">+${Kit.fmt(fame)}</span>` : ''}</div>
|
||||
${achHtml(gotAch)}
|
||||
${F.training ? `<p class="muted">${t('training_note')}</p>` : ''}
|
||||
<div class="row"><button class="primary" id="bGarage">${t('to_garage')}</button>${!F.training && !won ? `<button id="bRetry">${t('retry')}</button>` : ''}</div>${boardHtml()}`,
|
||||
{ bg: won ? 'bg_win.jpg' : 'bg_lose.jpg' });
|
||||
@@ -1020,6 +1345,40 @@
|
||||
} else fillBoard();
|
||||
}
|
||||
|
||||
// a tournament round: the bracket moves on, the round prize is paid, then back to the bracket
|
||||
function endTourFight(res, won, me) {
|
||||
const st = save.tour, lines = [];
|
||||
const before = st.prize;
|
||||
RC.Tourney.advance(st, won);
|
||||
const roundPay = st.prize - before;
|
||||
save.games++;
|
||||
if (won) save.wins++; else save.losses++;
|
||||
let money = 0, fame = won ? 70 * st.round : 20;
|
||||
if (roundPay) { money += roundPay; lines.push([t('tour_round_prize'), roundPay]); }
|
||||
const db = Math.round(me.dealt * 0.6);
|
||||
if (db) { money += db; lines.push([t('r_dmg_bonus'), db]); }
|
||||
if (st.won) { money += 2000; fame += 400; lines.push([t('tour_trophy'), 2000]); }
|
||||
const repair = Math.round((1 - me.hp / me.maxHp) * me.st.value * 0.06);
|
||||
money = applyEvent(money, lines);
|
||||
const paid = Math.min(repair, save.money + money);
|
||||
if (paid) { money -= paid; lines.push([t('r_repair'), -paid]); }
|
||||
save.money += money; save.fame += fame;
|
||||
persist();
|
||||
const gotAch = awardAch({ won, reason: res.reason, hpPct: me.hp / me.maxHp, dealt: me.dealt,
|
||||
lost: ['armour', 'wheels', 'weapon', 'tower'].filter(k => me.lost && me.lost[k]).length, tourWon: st.won });
|
||||
hud();
|
||||
(won ? SFX.win : SFX.lose)();
|
||||
const rows = lines.map(([k, v]) => `<span>${k}</span><span class="${v < 0 ? 'minus' : 'plus'}">${v < 0 ? '−' : '+'}${Kit.fmt(Math.abs(v))}</span>`).join('');
|
||||
setScreen('result');
|
||||
card(`<h1>${won ? t('victory') : t('defeat')}</h1><p>${esc(F.opp.name)}</p>
|
||||
<div class="res"><span>${t('r_dealt')}</span><span>${Math.round(me.dealt)}</span>${rows}
|
||||
<span>${t('hud_fame')}</span><span class="plus">+${Kit.fmt(fame)}</span></div>
|
||||
${achHtml(gotAch)}
|
||||
<div class="row"><button class="primary" id="bTour">🏆 ${t('tournament')}</button></div>`,
|
||||
{ bg: won ? 'bg_win.jpg' : 'bg_lose.jpg' });
|
||||
$('bTour').onclick = () => { SFX.click(); showTournament(); };
|
||||
}
|
||||
|
||||
function endOnlineFight(res, won, me) {
|
||||
if (F.nf) F.nf.stop();
|
||||
if (lobby) lobby.endMatch();
|
||||
@@ -1036,17 +1395,22 @@
|
||||
const db = Math.round(me.dealt * 0.6);
|
||||
if (db) { money += db; lines.push([t('r_dmg_bonus'), db]); }
|
||||
const repair = Math.round((1 - me.hp / me.maxHp) * me.st.value * 0.06);
|
||||
money = applyEvent(money, lines);
|
||||
const paid = Math.min(repair, save.money + money);
|
||||
if (paid) { money -= paid; lines.push([t('r_repair'), -paid]); }
|
||||
save.money += money; save.fame += fame; save.games++;
|
||||
if (won) save.wins++; else if (!draw) save.losses++;
|
||||
persist(); hud();
|
||||
persist();
|
||||
const gotAch = awardAch({ won, reason: res.reason, hpPct: me.hp / me.maxHp, dealt: me.dealt,
|
||||
lost: ['armour', 'wheels', 'weapon', 'tower'].filter(k => me.lost && me.lost[k]).length });
|
||||
hud();
|
||||
if (save.fame > save.best) { save.best = save.fame; persist(); scores.submit({ name: playerName(), score: save.fame, level: save.season }); }
|
||||
const rows = lines.map(([k, v]) => `<span>${k}</span><span class="${v < 0 ? 'minus' : 'plus'}">${v < 0 ? '−' : '+'}${Kit.fmt(Math.abs(v))}</span>`).join('');
|
||||
setScreen('result');
|
||||
card(`<h1>${title}</h1><p>${esc(F.opp.name)} ${F.nf && !F.nf.peerAlive ? t('peer_left') : ''}</p>
|
||||
<div class="res"><span>${t('r_dealt')}</span><span>${Math.round(me.dealt)}</span><span>${t('r_taken')}</span><span>${Math.round(me.taken)}</span>${rows}
|
||||
${fame ? `<span>${t('hud_fame')}</span><span class="plus">+${Kit.fmt(fame)}</span>` : ''}</div>
|
||||
${achHtml(gotAch)}
|
||||
<div class="row"><button class="primary" id="bLobby">${t('back_to_lobby')}</button><button id="bShopO">${t('to_garage')}</button></div>`,
|
||||
{ bg: won ? 'bg_win.jpg' : 'bg_lose.jpg' });
|
||||
$('bLobby').onclick = () => { SFX.click(); showLobby(); };
|
||||
@@ -1128,7 +1492,7 @@
|
||||
addEventListener('blur', () => { if (mode === 'fight' && !(F && F.online)) togglePause(); });
|
||||
// language switch: static texts update themselves (data-i18n), dynamic screens are drawn again
|
||||
L.onChange(() => {
|
||||
hud();
|
||||
hud(); updateShopBar();
|
||||
if (mode === 'title') showTitle();
|
||||
else if (mode === 'garage') shop.render();
|
||||
else if (mode === 'league') showLeague();
|
||||
@@ -1137,11 +1501,37 @@
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------- start
|
||||
// backend settings; applied as soon as they arrive and whenever the admin changes them
|
||||
RC.Live.load(net, v => {
|
||||
LIVE = v;
|
||||
if (LIVE.onlineOff && gameMode === 'online' && save) switchMode('campaign');
|
||||
if (mode === 'title') showTitle(); else if (mode === 'lobby') renderLobby();
|
||||
});
|
||||
if (DEV.get('live')) { // dev: &live=event|off|old|lock (no Firebase needed)
|
||||
const k = DEV.get('live'), now = Date.now();
|
||||
const demo = {
|
||||
event: { event: { id: 'demo', name: { de: 'Schwergewichts-Wochenende', en: 'Heavyweight weekend' }, type: 'prize', prizeMul: 2, from: now - 1000, to: now + 36e5 } },
|
||||
off: { flags: { onlineOff: true, note: { de: 'Wartung', en: 'Maintenance' } } },
|
||||
old: { build: { min: '99999999.9999' } }, // paired with a fake stamp below
|
||||
lock: { unlock: { parts: ['crate', 'sparky', 'rubber', 'lead', 'wedge'] } },
|
||||
motd: { motd: { de: 'Turnier am Samstag um 20 Uhr!', en: 'Tournament on Saturday, 8pm!' } },
|
||||
}[k];
|
||||
if (k === 'old' && !BUILD_ID()) window.RC_BUILD = '20000101.0000';
|
||||
if (demo) LIVE = RC.Live.parse(demo, now, BUILD_ID());
|
||||
}
|
||||
setMode('online'); // every page load starts in online play
|
||||
accounts.resume();
|
||||
if (net && net.enabled) { net.auth.resume(); net.auth.onChange(() => { hud(); if (mode === 'title') showTitle(); }); }
|
||||
hud();
|
||||
if (!hostOk()) {
|
||||
card(`<h1>Robot Clash</h1><p>${t('wrong_host')}</p><p class="credits">${CREDITS}</p>`);
|
||||
} else if (LIVE.needsReload) {
|
||||
// the admin published a newer build; browsers happily serve the cached old file
|
||||
setScreen('intro'); // defined UI state while this card is up
|
||||
card(`<h2>${t('reload_title')}</h2><p>${t('reload_text')}</p>
|
||||
<div class="row"><button class="primary" id="rNow">${t('reload_now')}</button><button id="rSkip">${t('reload_skip')}</button></div>`);
|
||||
$('rNow').onclick = () => location.reload();
|
||||
$('rSkip').onclick = () => { LIVE.needsReload = false; SFX.click(); startGate(startIntro); };
|
||||
} else if (!view) {
|
||||
card(`<h1>Robot Clash</h1><p>${t('no_webgl')}</p><p class="credits">${CREDITS}</p>`);
|
||||
} else if (DEV.has('fight') || DEV.has('play')) {
|
||||
@@ -1156,11 +1546,14 @@
|
||||
if (DEV.get('shoptab') && mode === 'garage') shop.setTab(DEV.get('shoptab'));
|
||||
if (DEV.get('sel') && mode === 'garage') { const id = DEV.get('sel'), p = RC.PARTS[id]; if (p) { const tb = document.querySelector(`.tab[data-slot="${p.slot}"]`); if (tb) tb.click(); const it = document.querySelector(`.item[data-id="${id}"]`); if (it) it.click(); } }
|
||||
// dev: ?play&screen=league|vs|settings|help|lobby|pause opens that screen (layout screenshots)
|
||||
if (DEV.get('gmode')) switchMode(DEV.get('gmode')); // dev: &gmode=campaign|online
|
||||
const scr = DEV.get('screen');
|
||||
if (scr === 'league') { save.beaten = Math.max(save.beaten, 3); showLeague(); }
|
||||
else if (scr === 'vs') showVs(RC.LEAGUE[4]);
|
||||
else if (scr === 'settings') showSettings(openGarage);
|
||||
else if (scr === 'help') showHelp(openGarage);
|
||||
else if (scr === 'tour') { save.money = 3000; startTournament(); }
|
||||
else if (scr === 'ach') { save.fame = 1200; save.ach = { first_win: true, ko: true, rich: true }; showAchievements(openGarage); }
|
||||
else if (scr === 'lobby') {
|
||||
lobbyRows = [{ uid: 'a', name: 'BlechBrecher', flag: 'DE', fame: 1250, state: 'idle' }, { uid: 'b', name: 'SawQueen', flag: 'DE', fame: 430, state: 'inmatch' }, { uid: 'c', name: 'Rostlaube77', flag: 'AT', fame: 90, state: 'idle' }, { uid: 'd', name: 'Flipmaster', flag: 'GB', fame: 600, state: 'idle' }];
|
||||
lobbyRoom = DEV.get('room') || null;
|
||||
@@ -1178,7 +1571,7 @@
|
||||
painter.open(); view.showGarage(save.build, paintObj());
|
||||
}
|
||||
} else if (DEV.has('online') && net.enabled) { startIntroOrTitle(); startOnline(); }
|
||||
else if (DEV.has('title')) startGate(startIntroOrTitle);
|
||||
else if (DEV.has('title')) startIntroOrTitle();
|
||||
else startGate(startIntro);
|
||||
if (DEV.has('tut')) startTutorial(openGarage); // dev: ?play&tut previews the first-start cards
|
||||
if (DEV.has('uicheck') && RC.uiCheckRun) RC.uiCheckRun(); // dev: &uicheck prints layout faults as text
|
||||
|
||||
Reference in New Issue
Block a user