'use strict'; // t1197/t1198: combo — each match adds +1% jump height (max +30%) (additive with the // landing-chain bonus); resets after 5 s without a match. const { describe, it } = require('node:test'); const assert = require('node:assert/strict'); const { makeGame, almost, GameCore, Planet } = require('./helpers.js'); function run (g, secs) { for (let t = 0; t < secs - 1e-9; t += 0.05) g.tick(0.05); } function freshMatch (g, color) { const h = makeGame({ noSpawn: true }); h.combo = g.combo; h.comboAge = g.comboAge; h.place(0, 0, color); h.place(1, 0, color); h.place(2, 0, color); const l = h.resolveMatches(); g.combo = h.combo; g.comboAge = h.comboAge; g.lastChainIndicator = h.lastChainIndicator; return l[0]; } describe('Match combo (t1197)', () => { const base = () => Planet.jumpHeight(makeGame({ noSpawn: true }).planet, 3, false); it('constants', () => { assert.equal(GameCore.COMBO_STEP, 0.01); assert.equal(GameCore.COMBO_MAX_STEPS, 30); assert.equal(GameCore.COMBO_RESET_S, 5); }); it('first match +0%, then +1%, +2%, ... per earlier match in the combo', () => { const g = makeGame({ noSpawn: true }); for (let k = 0; k < 4; k++) { const l = freshMatch(g, 1 + (k % 3)); assert.ok(almost(l.comboBonus, 0.01 * k, 1e-12), 'k=' + k); assert.ok(almost(l.jumpHeight, base() * (1 + 0.01 * k), 1e-9)); assert.equal(g.combo, k + 1); } assert.equal(g.lastChainIndicator.bonusPct, 3); assert.equal(g.comboBonusPct(), 4); }); it('adds to the landing-chain bonus (chain 1 + 2 combo matches = +27%)', () => { const g = makeGame({ noSpawn: true }); g.combo = 2; g.place(0, 0, 2); g.place(1, 0, 2); const cluster = { id: g.nextClusterId++, jumpHeight: 3, vy: 0, decel: 0, phase: 'down', landingChain: 0 }; g.clusters[cluster.id] = cluster; const b = g.createBlock(2, 0, 2, 'flying'); b.clusterId = cluster.id; g.landCluster(cluster, [b]); const l = g.resolveMatches()[0]; assert.ok(almost(l.chainBonus, 1.27, 1e-12)); assert.equal(g.lastChainIndicator.bonusPct, 27); }); it('combo bonus is capped at +30% (0.01 * min(combo, 30))', () => { for (const [combo, pct] of [[29, 29], [30, 30], [31, 30], [100, 30]]) { const g = makeGame({ noSpawn: true }); g.combo = combo; const l = freshMatch(g, 1); assert.ok(almost(l.comboBonus, pct / 100, 1e-12), 'combo ' + combo); assert.ok(almost(l.jumpHeight, base() * (1 + pct / 100), 1e-9)); assert.equal(g.lastChainIndicator.bonusPct, pct); } const g = makeGame({ noSpawn: true }); g.combo = 50; assert.equal(g.comboBonusPct(), 30); }); it('the cap does not touch the landing chain (chain 1 + capped combo = +55%)', () => { const g = makeGame({ noSpawn: true }); g.combo = 40; g.place(0, 0, 2); g.place(1, 0, 2); const cluster = { id: g.nextClusterId++, jumpHeight: 3, vy: 0, decel: 0, phase: 'down', landingChain: 0 }; g.clusters[cluster.id] = cluster; const b = g.createBlock(2, 0, 2, 'flying'); b.clusterId = cluster.id; g.landCluster(cluster, [b]); const l = g.resolveMatches()[0]; assert.ok(almost(l.chainBonus, 1.55, 1e-12)); }); it('HUD number (t1200) is only the combo part: 0.01 * min(combo, 30), landing chain excluded', () => { const g = makeGame({ noSpawn: true }); assert.equal(g.comboBonusPct(), 0, 'nothing to show before a match'); freshMatch(g, 1); assert.equal(g.comboBonusPct(), 1); g.combo = 2; g.place(0, 0, 2); g.place(1, 0, 2); const cluster = { id: g.nextClusterId++, jumpHeight: 3, vy: 0, decel: 0, phase: 'down', landingChain: 0 }; g.clusters[cluster.id] = cluster; const b = g.createBlock(2, 0, 2, 'flying'); b.clusterId = cluster.id; g.landCluster(cluster, [b]); const l = g.resolveMatches()[0]; assert.ok(almost(l.chainBonus, 1.27, 1e-12), 'jump still gets chain + combo'); assert.equal(g.comboBonusPct(), 3, 'HUD shows only the combo (3 matches), not +27%'); g.combo = 45; assert.equal(g.comboBonusPct(), 30, 'capped'); for (let t = 0; t < 5.1; t += 0.05) g.tick(0.05); assert.equal(g.comboBonusPct(), 0, 'hidden again after the combo resets'); }); it('resets after 5 s without a match, not before', () => { const g = makeGame({ noSpawn: true }); freshMatch(g, 1); freshMatch(g, 2); assert.equal(g.combo, 2); run(g, 4.9); assert.equal(g.combo, 2, 'still alive at 4.9 s'); freshMatch(g, 3); // a match restarts the 5 s window assert.equal(g.combo, 3); run(g, 4.0); assert.equal(g.combo, 3); run(g, 1.1); assert.equal(g.combo, 0, 'gone after 5 s without a match'); const l = freshMatch(g, 1); assert.equal(l.comboBonus, 0); }); it('bots share it: an offline bot core is a GameCore with the same combo', () => { const Offline = require('../src/offline.js'); const battle = Offline.createBattle({ playerPlanet: Planet.defaultPlanet(), rng: () => 0.5 }); const bot = battle.bots[0].core; assert.equal(bot.combo, 0); assert.equal(typeof bot.comboBonusPct, 'function'); }); });