'use strict'; // t1198: Offline Strijd result shows "X opponents defeated" over all rounds. const { describe, it } = require('node:test'); const assert = require('node:assert/strict'); const { makeGame, Planet, Rng } = require('./helpers.js'); const Offline = require('../src/offline.js'); const I18n = require('../src/i18n.js'); function knockOutAll (battle, player) { for (const b of battle.bots) b.core.state = 'gameover'; battle.tick(0.016, player); } describe('Offline defeated counter (t1198)', () => { it('counts every opponent knocked out, across rounds, once each', () => { const battle = Offline.createBattle({ playerPlanet: Planet.defaultPlanet(), rng: Rng.create(3), round: 1 }); const player = makeGame({ noSpawn: true }); assert.equal(battle.defeated, 0); knockOutAll(battle, player); // round 1: 1 bot assert.equal(battle.state, 'round_won'); assert.equal(battle.defeated, 1); battle.tick(0.016, player); // no double count assert.equal(battle.defeated, 1); battle.advanceRound(); // round 2: 2 bots const n2 = battle.bots.length; battle.bots[0].core.state = 'gameover'; battle.tick(0.016, player); assert.equal(battle.defeated, 2, 'one of round 2 out'); player.state = 'gameover'; // player loses round 2 battle.tick(0.016, player); assert.equal(battle.state, 'lost'); assert.equal(battle.defeated, 2, 'remaining bots of the lost round are not counted'); assert.ok(n2 >= 2); }); it('i18n: singular / plural in every language, no skill line left', () => { const cat = require('../server/lib/i18n.json'); for (const loc of cat.localeIds) { I18n.setLocale ? I18n.setLocale(loc) : (I18n.locale = loc); const one = I18n.plural('offline.defeated', 1, { n: 1 }); const many = I18n.plural('offline.defeated', 7, { n: 7 }); assert.ok(one.includes('1') && many.includes('7'), loc + ': ' + one + ' / ' + many); assert.equal(cat.locales[loc]['offline.detail'], undefined, loc + ' old detail removed'); } I18n.setLocale ? I18n.setLocale('nl') : (I18n.locale = 'nl'); assert.equal(I18n.plural('offline.defeated', 1, { n: 1 }), '1 tegenstander verslagen'); assert.equal(I18n.plural('offline.defeated', 3, { n: 3 }), '3 tegenstanders verslagen'); I18n.setLocale ? I18n.setLocale('en') : (I18n.locale = 'en'); }); });