import type { Entity } from '../../core/entity'; import type { Game } from '../../core/game'; import type { ZoneDef } from '../../core/types'; import type { KitZoneContext } from '../kit/context'; import { vfxAmbient } from '../../vfx/index'; import { Invasion } from './invasion'; import { Barrier, awning, invisibleWall, playableBuilding, spawnWaveLocal, type WaveSpec } from './shared'; /** * CIUDAD EMOJI 🏙️ — zona inicial (partida nueva: spawn 'default'). * * x -14..30 Barrio de Emma: casa de Emma, buzón, vecinos. Primer edificio trepable * SOLO con burbujas (toldo → burbujas → tejado, cofre 'emma-roof' con * diamantes). Enseña a saltar (cajas). * x 30..72 Calle de las tiendas: toldos → tejados → torre (monedas, ruta alta). * x 72..100 Obras: zanja con plataforma móvil, ascensor de grúa a un andamio alto. Checkpoint 'plaza'. * x 100..140 Plaza Mayor (ARENA x 103..139): Luna (atardecer) y la horda (noche). * x 140..186 Escuela y parque: tejados encadenados hasta el cofre 'city-roof'. Teletransporte. * x 186..212 Camino a la laguna: barrera 🚧 hasta 'horde.cleared', salida → lagoon 'from-city'. * * Métricas del héroe (TUNING): salto ≈ 2.9 u de alto, doble salto ≈ 4.7 u; alcance horizontal * ≈ 5 u con un salto y ≈ 8.5 u con doble. Escalones ≤ 2.6 (simple) y ≤ 4.3 (doble), huecos ≤ 7. * * Guion: Emma activa el atardecer y a Luna; tras vencerla, una sola horda defensiva abre la laguna. */ const ARENA = { x0: 103, x1: 139, floor: 0 }; /** Zona de la Luna: lejos de los edificios trepables de los extremos. */ const LUNA_ARENA = { x0: 109, x1: 133, floor: 0 }; const GATE_X = 192; type Phase = 0 | 1 | 2 | 3; interface CityRt { phase: Phase; visitT: number; cycleStep: number; left: Barrier; right: Barrier; gate: Barrier; luna: Entity | null; /** Barreras de la arena cerradas (combate en curso). */ locked: boolean; wave: number; wavePending: (() => number) | null; waveList: Entity[]; waveBreak: number; invasion: Invasion; } let rt: CityRt | null = null; function phaseOf(g: Game): Phase { const s = g.state; if (s.has('horde.cleared')) return 3; if (s.has('luna.defeated')) return 2; if (s.has('emma.met')) return 1; return 0; } function heroInArena(g: Game): boolean { const h = g.hero; return !!h && h.alive && h.x > ARENA.x0 + 1.4 && h.x < ARENA.x1 - 1.4; } function spawnLuna(g: Game, r: CityRt): void { if (r.luna && !r.luna.dead) return; r.luna = g.spawn('boss.luna', (ARENA.x0 + ARENA.x1) / 2, 5, { id: 'luna', arena: { ...LUNA_ARENA } }); } function lockArena(g: Game, r: CityRt, on: boolean): void { r.locked = on; r.left.setClosed(on); r.right.setClosed(on); if (on) g.gfx.cam.shake(0.25, 0.4); } // ── horda ── const W = (type: string, x: number, y: number, delay: number): WaveSpec => ({ type, x, y, delay, props: { arena: { ...ARENA }, aggro: true, anytime: true } }); function waveSpecs(n: number): WaveSpec[] { const a = ARENA.x0; const b = ARENA.x1; const m = (a + b) / 2; return [ W('enemy.robot', a + 4, 0, 0), W('enemy.robot', b - 4, 0, 0.35), W('enemy.ghost', a + 8, 3.5, 0.8), W('enemy.ghost', b - 8, 3.5, 1.15), W('enemy.robot', m, 0, 1.7), ]; } const WAVE_TEXT = ['', 'Robots y fantasmas bloquean el camino']; const WAVE_EMOJI = ['', '🤖']; function startWave(g: Game, r: CityRt, n: number): void { r.wave = n; g.state.set('horde.wave', n); g.ui.banner('¡Defiende la ciudad!', WAVE_TEXT[1], WAVE_EMOJI[1]); g.audio.sfx('boss_roar', { volume: 0.5, pitch: 1.3 }); const w = spawnWaveLocal(g, waveSpecs(n)); r.waveList = w.list; r.wavePending = w.pending; r.waveBreak = 0; } function hordeTick(g: Game, r: CityRt, dt: number): void { if (g.state.has('horde.cleared')) { lockArena(g, r, false); return; } if (!r.locked) { // Tras un game over el checkpoint deja reaparecer fuera del área de batalla. // El cierre se activa al cruzar de nuevo a la plaza, no al cargar la ciudad. if (!heroInArena(g)) return; lockArena(g, r, true); g.audio.music('boss'); r.wave = 0; r.waveBreak = 1.6; } if (r.waveBreak > 0) { r.waveBreak -= dt; if (r.waveBreak <= 0) startWave(g, r, Math.min(1, r.wave + 1)); return; } if (!r.wavePending) return; const alive = r.waveList.some((e) => !e.dead); if (alive || r.wavePending() > 0) return; r.wavePending = null; g.state.set('horde.cleared', true); g.state.save(); lockArena(g, r, false); g.audio.music('city-night'); g.ui.banner('¡La plaza está a salvo!', 'Solo quedan robots y fantasmas derrotados', '🌙'); } /** Aplica el estado visual/sonoro de una fase. `instant` = al entrar en la zona (recarga). */ function applyPhase(g: Game, r: CityRt, p: Phase, instant: boolean): void { r.phase = p; const t = instant ? 0 : 3; if (p === 0) { g.gfx.setEnv('city-day', t); r.gate.setClosed(true, true); lockArena(g, r, false); } else if (p === 1) { g.gfx.setEnv('city-dusk', t); if (instant) g.audio.music('city'); r.gate.setClosed(true, true); spawnLuna(g, r); if (!instant) { g.audio.sfx('thunder', { volume: 0.5 }); g.gfx.cam.shake(0.3, 0.6); } } else if (p === 2) { g.gfx.setEnv('city-night', t); r.gate.setClosed(true, true); lockArena(g, r, false); r.wave = 0; r.wavePending = null; r.waveList = []; r.waveBreak = 0; g.audio.music('city-night'); vfxAmbient(g, 'fireflies', { density: 0.5 }); } else { g.gfx.setEnv('city-day', instant ? 0 : 4); g.audio.music('city'); vfxAmbient(g, 'leaves', { density: 0.35 }); if (instant) { r.gate.setClosed(false, true); g.state.set('city.cycleReady', true); lockArena(g, r, false); } else { lockArena(g, r, false); g.after(1.2, () => { r.gate.setClosed(false); g.state.set('city.cycleReady', true); g.vfx.burst('confetti', GATE_X, 2, { count: 40 }); g.audio.sfx('victory', { volume: 0.7 }); g.ui.toast('¡Amanece! El camino a la laguna está abierto', '🫧'); }); } } } export const cityZone: ZoneDef = { id: 'city', name: 'Ciudad Emoji', emoji: '🏙️', bounds: { minX: -14, maxX: 212, minY: -4, maxY: 17 }, spawns: { default: { x: -5, y: 0 }, 'tp-city': { x: 178, y: 0 }, tiendas: { x: 27, y: 0 }, plaza: { x: 97, y: 0 }, 'horde-plaza': { x: 100, y: 0 }, 'from-lagoon': { x: 204, y: 0 }, }, env: 'city-day', music: 'city', build(z) { const k = z as KitZoneContext; const g = z.game; z.backdrop('city', { horizon: -0.5 }); // ───────── suelo ───────── z.ground(-14, 76, 0, { style: 'city' }); z.ground(83, 100, 0, { style: 'city' }); z.ground(100, 140, 0, { style: 'stone' }); z.ground(140, 168, 0, { style: 'city' }); z.ground(168, 186, 0, { style: 'grass' }); z.ground(186, 212, 0, { style: 'grass' }); invisibleWall(g, -14.5, 0, 20); invisibleWall(g, 212.5, 0, 20); // ═════════ A. Barrio de Emma (x -14..30) ═════════ // Primer edificio trepable (6 plantas, cubierta 8.33): SOLO con burbujas. // Ruta: suelo → toldo (2.2, salto simple) → burbujas → tejado (8.33). // Sin burbujas es inalcanzable: desde el toldo el doble salto llega a 6.9 < 8.33. // Con burbujas: doble salto desde el toldo (≈6.9) + 1 burbuja y salto (≈+2.9) = 9.8. const emmaRoof = playableBuilding(z, -11.5, 6, 4.5, 0xf27a7a); awning(z, -11.5, 2.2, 4.2, 0xffc928); z.spawn('item.coin', -11.5, 3.4); z.spawn('item.coin', -11.5, 5.6); z.spawn('item.coin', -12.8, emmaRoof + 1.2); z.spawn('item.chest', -11.5, emmaRoof, { id: 'emma-roof', contains: 'diamond' }); // El cofre solo admite un diamante ('diamond'): el segundo va suelto en el tejado. z.spawn('item.diamond', -10.2, emmaRoof + 1.1); z.prop('house', 2, 0, { z: -3, color: 0xfff1d6, roof: 0xff6fa8 }); z.decor('💖', 2, 3.4, { z: -1.8, scale: 0.8 }); z.prop('house', 15, 0, { z: -3.4, color: 0xd9f2ff, roof: 0x2fa8f5 }); z.prop('tree', -7.5, 0, { z: -2.6, fruit: true }); z.prop('tree', 9.5, 0, { z: -2.2 }); z.prop('lamp', -2.5, 0); z.prop('lamp', 12.5, 0); z.prop('bench', 7.5, 0, { z: -1.5 }); z.prop('fence', -0.5, 0, { z: -1.6, width: 4 }); z.prop('fence', 18, 0, { z: -1.8, width: 3 }); z.prop('sign', -9, 0, { text: '¡Bienvenido a Ciudad Emoji!' }); z.decor('📮', 0.2, 0, { z: -0.9, scale: 1.1 }); z.decor('🐈', 8.6, 1.05, { z: -1.4, scale: 0.7 }); z.decor('🌷', -4.5, 0, { z: -0.7, scale: 0.6, sway: true }); z.decor('🌻', 4.8, 0, { z: -0.8, scale: 0.8, sway: true }); k.scatter('flower', -12, 18, 0, 8, { z: -1.9, zJitter: 0.3 }); z.decor('🚗', -6, 0, { z: -4.6, scale: 1.7 }); z.decor('🚙', 22, 0, { z: -4.6, scale: 1.7, flipX: true }); z.spawn('npc.emma', 5, 0); z.spawn('npc.generic', 10.5, 0, { id: 'pepa', emoji: '👵', name: 'Doña Pepa', color: 0xa455f0, lines: [ '¡Ay, qué alegría ver una cara redonda y sonriente!', 'Mi gato se pasa el día en ese banco. Dice que es su oficina.', 'Si ves monedas por los tejados, ¡cógelas! En la tienda valen oro. 🪙', ], }); // Enseñar a saltar: cajas (1 u) y pila de 2 z.prop('crate', 20, 0, { solid: true }); z.prop('crate', 23.2, 0, { solid: true }); z.prop('crate', 23.2, 1, { solid: true, color: 0xd99a5b }); z.spawn('item.coin', 20, 2.2); z.spawn('item.coin', 23.2, 3.3); z.spawn('item.coin', 26, 2.2); z.spawn('item.checkpoint', 28, 0, { spawn: 'tiendas' }); // ═════════ B. Calle de las tiendas (x 30..72) ═════════ // Heladería 🍦 (2 plantas, cubierta 3.13) con toldo rosa (2.1) const t1 = playableBuilding(z, 36, 2, 5, 0xff9ad0, { roofTop: false }); awning(z, 36, 2.1, 4.2, 0xf2452e); z.spawn('npc.generic', 33.5, 0, { id: 'heladero', emoji: '👨‍🍳', name: 'Heladero Tito', color: 0xf4f1ff, lines: [ '¡Helados de emoji! Hoy hay sabor 🌈 arcoíris y sabor 🌶️ "no lo pruebes".', 'Puedes saltar sobre mi toldo, pero no me lo pises con barro, ¿eh?', ], }); z.spawn('item.coin', 36, t1 + 1.2); // Tienda 🏪 (3 plantas, 4.43) con toldo verde (2.3) const t2 = playableBuilding(z, 45, 3, 5, 0x6ec3f4); awning(z, 45, 2.3, 4.4, 0x5bd23c); z.spawn('item.coin', 44, t2 + 1.2); z.spawn('item.coin', 46, t2 + 1.2); // Torre lila (5 plantas, 7.03): desde la tienda es un doble salto const t3 = playableBuilding(z, 54, 5, 4, 0xa98ee8, { roofTop: false }); z.decor('📡', 55, t3, { z: -0.9, scale: 1.1 }); z.spawn('item.coin', 53, t3 + 1.3); z.spawn('item.coin', 55, t3 + 1.3); z.spawn('item.heart', 54, t3 + 0.2); // Cartel publicitario flotante tras la torre (ruta alta → baja de nuevo) z.platform(61, 5.6, 3, { style: 'metal' }); z.spawn('item.coin', 64.5, 3.5); z.prop('building', 63, 0, { floors: 3, width: 4, z: -4.2, color: 0xffd36a }); z.prop('lamp', 40.5, 0); z.prop('lamp', 50, 0); z.prop('lamp', 67, 0); z.decor('🚦', 31, 0, { z: -1.2, scale: 1.4 }); z.decor('🚲', 49.5, 0, { z: -0.9, scale: 1 }); z.decor('🧯', 58, 0, { z: 0.9, scale: 0.6 }); z.decor('🛵', 41, 0, { z: -4.4, scale: 1.4 }); z.decor('🚕', 59, 0, { z: -4.6, scale: 1.7 }); z.decor('🗑️', 51.5, 0, { z: -0.9, scale: 0.7 }); // jardineras z.block(66, 0.4, 2.2, 0.8, { style: 'grass' }); z.prop('bush', 66, 0.8, { z: -0.4, flowers: true, scale: 0.8 }); z.block(70, 0.4, 2.2, 0.8, { style: 'grass' }); z.prop('bush', 70, 0.8, { z: -0.4, berries: true, scale: 0.8 }); z.spawn('enemy.robot', 60, 0, { patrol: [56, 64] }); // ═════════ C. Obras (x 72..100) ═════════ z.decor('🏗️', 89, 0, { z: -5.5, scale: 9 }); z.prop('sign', 73.5, 0, { text: '⚠️ ¡Obras!' }); // Zanja 76..83: plataforma móvil (o doble salto) z.platform(79.5, 0.4, 2.2, { style: 'metal', move: { dx: 4, period: 3.4 } }); z.decor('🚧', 75.4, 0, { z: 0.9, scale: 0.9 }); z.decor('🚧', 83.6, 0, { z: 0.9, scale: 0.9 }); z.spawn('item.coin', 79.5, 3.4); // Ascensor de la grúa: sube de y≈1 a y≈9 z.platform(87.5, 5, 2.4, { style: 'metal', move: { dy: 8.4, period: 6.5 } }); z.decor('⛓️', 87.5, 9.6, { z: -0.6, scale: 0.9 }); // andamio alto (ruta secreta: monedas + corazón) z.platform(92, 9.2, 4, { style: 'wood' }); z.platform(97.5, 10.4, 3, { style: 'wood' }); z.spawn('item.coin', 91, 10.4); z.spawn('item.coin', 93, 10.4); z.spawn('item.diamond', 97.5, 11.4); z.prop('crate', 90.5, 0, { solid: true }); z.prop('crate', 91.5, 0, { solid: true, color: 0xd99a5b }); z.prop('crate', 91, 1, { solid: true }); z.prop('barrel', 85, 0, { z: -1.2 }); z.decor('🧱', 94, 0, { z: -1, scale: 0.8 }); z.decor('🦺', 94.8, 0, { z: -1.4, scale: 0.7 }); z.spawn('npc.generic', 84.8, 0, { id: 'obrero', emoji: '👷', name: 'Obrero Ramón', color: 0xffc928, lines: [ '¡Cuidado con la zanja! Salta, y en el aire vuelve a saltar: ¡doble salto!', 'El ascensor de la grúa sube hasta el andamio. Arriba se me cayó algo brillante...', ], }); z.spawn('enemy.robot', 95, 0, { patrol: [93, 98] }); z.spawn('item.checkpoint', 101.2, 0, { spawn: 'plaza' }); // ═════════ D. Plaza Mayor / arena (x 100..140) ═════════ z.decor('⛲', 121, 0, { z: -2.6, scale: 3.4 }); z.prop('building', 112, 0, { floors: 4, width: 5, z: -4.5, color: 0xf2a65a }); z.prop('building', 131, 0, { floors: 5, width: 4.5, z: -4.5, color: 0x7fd6a6 }); for (const x of [107, 115, 127, 135]) z.prop('lamp', x, 0, { z: -1.2 }); z.prop('bench', 111, 0, { z: -1.6 }); z.prop('bench', 131, 0, { z: -1.6 }); z.decor('🕊️', 117.4, 0, { z: -1, scale: 0.6 }); z.decor('🕊️', 125.2, 0, { z: -1.1, scale: 0.55, flipX: true }); // Edificios trepables en los extremos de la plaza (toldo → tejado) y pasarela alta de nubes hasta la nube // central. Todo queda por encima de 5.6 u o fuera de la zona de la Luna (LUNA_ARENA), para que aturdida // siempre se pueda golpear o pisar sin plataformas en medio. for (const [bx, col, aw] of [[105.2, 0xff9ad0, 0x2fa8f5], [136.8, 0x9ad0ff, 0xf2452e]] as const) { const top = playableBuilding(z, bx, 3, 3.6, col, { roofTop: false }); awning(z, bx, 2.2, 3.0, aw); z.spawn('item.coin', bx, top + 1.2); } z.platform(110.6, 5.6, 2.6, { style: 'cloud' }); z.platform(115.6, 6.3, 2.6, { style: 'cloud' }); z.platform(121, 5.6, 3.4, { style: 'cloud' }); z.platform(126.4, 6.3, 2.6, { style: 'cloud' }); z.platform(131.4, 5.6, 2.6, { style: 'cloud' }); const phaseAtBuild = phaseOf(g); void phaseAtBuild; // Las barreras de la arena nacen ABIERTAS: solo se cierran cuando el héroe entra en la plaza // (si no, al reaparecer en el punto de control de fuera quedaría encerrado fuera de la batalla). const left = g.add(new Barrier(ARENA.x0 - 0.5, 0, { color: 0xa455f0, emoji: '🚧', height: 26, closed: false })); const right = g.add(new Barrier(ARENA.x1 + 0.5, 0, { color: 0xa455f0, emoji: '🚧', height: 26, closed: false })); // ═════════ E. Escuela y parque (x 140..186) ═════════ const sc = playableBuilding(z, 148.5, 3, 7, 0xffd36a, { roofTop: false }); z.decor('🔔', 148.5, sc, { z: -0.9, scale: 0.8 }); awning(z, 143.6, 2.2, 2.6, 0x2fa8f5); const tw = playableBuilding(z, 158, 5, 4, 0xf27a7a, { roofTop: false }); z.spawn('item.coin', 158, tw + 1.2); // depósito de agua sobre pilares: el cofre del tejado z.platform(165.5, tw + 2.5, 3.2, { style: 'metal' }); z.decor('🛢️', 166.6, tw + 2.5, { z: -0.9, scale: 1.1 }); z.spawn('item.chest', 165.2, tw + 2.5, { id: 'city-roof', contains: 'diamond' }); z.spawn('item.coin', 162, tw + 3.4); z.decor('🏀', 154, 0, { z: -0.9, scale: 0.6 }); z.decor('🎒', 144.5, 0, { z: -1, scale: 0.7 }); z.spawn('npc.generic', 152.5, 0, { id: 'nino', emoji: '🧒', name: 'Lalo', color: 0x2fa8f5, lines: [ 'Dicen que en la laguna vive un guardián muy sabio... ¿o era un pez muy listo?', '¡Desde el tejado de la escuela se ve el depósito de agua! Nadie ha subido nunca...', ], }); // parque z.prop('tree', 171, 0, { z: -2.4, fruit: true }); z.prop('tree', 183, 0, { z: -3 }); z.prop('pine', 176.5, 0, { z: -3.6 }); z.prop('bush', 173.5, 0, { z: -1.2, flowers: true }); z.prop('bench', 180, 0, { z: -1.5, color: 0x5bd23c }); z.prop('lamp', 168.5, 0); z.decor('🎠', 175, 0, { z: -2.4, scale: 2.4 }); for (const [x, y, e] of [[172.5, 2.6, '🎈'], [173.1, 3, '🎈'], [180.8, 2.2, '🎈']] as const) { z.decor(e, x, y, { z: -1.3, scale: 0.75, sway: true }); } k.scatter('flower', 168, 186, 0, 9, { z: -0.9, zJitter: 0.5 }); z.spawn('item.teleporter', 178, 0, { id: 'city' }); // ═════════ F. Camino a la laguna (x 186..212) ═════════ z.prop('fence', 189, 0, { z: -1.4, width: 4 }); z.prop('sign', 189.6, 0, { text: '🚧 Cerrado hasta el amanecer', z: 0.2 }); z.spawn('npc.generic', 186.6, 0, { id: 'guardia', emoji: '👮', name: 'Agente Lupe', color: 0x3b2fb8, lines: [ 'Alto ahí. El camino a la laguna está cerrado por la invasión.', 'Cuando la ciudad vuelva a estar a salvo y amanezca, abriré la barrera. ¡Palabra de agente!', ], }); const gate = g.add(new Barrier(GATE_X, 0, { color: 0xf2452e, emoji: '🚧', closed: true })); z.prop('palm', 197, 0, { z: -2.4, lean: 0.5 }); z.prop('tree', 205, 0, { z: -3.2 }); z.prop('reeds', 201, 0, { z: -0.8 }); z.prop('rock', 207.5, 0, { z: -1.6 }); z.prop('sign', 206.6, 0, { emoji: '🫧', z: -0.8 }); z.decor('🦆', 199.5, 0, { z: -1.1, scale: 0.6 }); z.exit(210.4, 1.5, 2, 3, 'lagoon', 'from-city', { arrow: 'right' }); // ───────── primer plano (z>0) y fondo ───────── k.scatter('grassTuft', 168, 210, 0, 12, { z: 1.2, zJitter: 0.2 }); for (const x of [-3.5, 25.5, 62.5, 145.5]) z.decor('🌼', x, 0, { z: 1.15, scale: 0.45, sway: true }); z.decor('🚒', 70, 0, { z: -4.8, scale: 1.8, flipX: true }); z.decor('🚌', 160, 0, { z: -4.8, scale: 2 }); for (const [x, y, s] of [[-2, 11, 1.6], [30, 12.5, 2], [70, 13, 1.7], [118, 13.5, 2.2], [160, 12.5, 1.6], [196, 11.5, 1.9]]) { z.prop('cloud', x, y, { z: -9, scale: s }); } rt = { phase: 0, visitT: 0, cycleStep: -1, left, right, gate, luna: null, locked: false, wave: 0, wavePending: null, waveList: [], waveBreak: 0, invasion: new Invasion(g, [ { id: 'city-shops', name: 'Calle de las tiendas', x0: 30.5, x1: 71.5, enemies: [ ['enemy.robot', 42, 0], ['enemy.bee', 47, 5.5], ['enemy.ghost', 51, 3.5], ['enemy.robot', 63, 0], ['enemy.bee', 61, 8], ['enemy.bat', 67, 9], ['enemy.ghost', 56, 9.5], ], }, ]), }; }, onEnter(game) { if (!rt) return; rt.visitT = 0; rt.cycleStep = -1; rt.locked = false; rt.luna = null; rt.wave = 0; rt.wavePending = null; rt.waveList = []; rt.waveBreak = 0; vfxAmbient(game, null); // si la horda estaba a medias, se reanuda en su ola al volver a entrar en la plaza applyPhase(game, rt, phaseOf(game), true); }, update(game, dt) { const r = rt; if (!r) return; const p = phaseOf(game); if (p !== r.phase) applyPhase(game, r, p, false); if (p === 3) r.invasion.update(game); // Si el héroe está FUERA de las barreras con la arena cerrada (reapareció en el punto de control), // se abren y el combate se reinicia cuando vuelva a entrar. const hx = game.hero?.x ?? 0; if (r.locked && game.hero?.alive && (hx < ARENA.x0 - 0.6 || hx > ARENA.x1 + 0.6)) { lockArena(game, r, false); (r.waveList as { cancelled?: boolean }).cancelled = true; for (const e of r.waveList) if (!e.dead) e.kill(); r.waveList = []; r.wavePending = null; r.wave = 0; r.waveBreak = 0; game.audio.music(r.phase === 2 ? 'city-night' : 'city'); } if (p === 3) { r.visitT += dt; const segment = Math.floor(r.visitT / 22) % 3; const key = segment === 0 ? 'city-day' : segment === 1 ? 'city-dusk' : 'city-night'; if (segment !== r.cycleStep) { r.cycleStep = segment; game.gfx.setEnv(key, 6); } } if (r.phase === 1) { if (!r.locked && heroInArena(game)) { lockArena(game, r, true); game.audio.music('boss'); } } else if (r.phase === 2) { hordeTick(game, r, dt); } }, onExit(game) { vfxAmbient(game, null); rt = null; }, };