/** * Clima por sala: lluvia permanente que cae por un techo roto (`weather.rain`). * * Dentro de la zona de lluvia todo se comporta como con la LLUVIA del héroe activa: las burbujas * revientan, el aliento de HIELO crea bloques y la lava cercana se enfría. `isRainingAt` es la consulta * común (lluvia del héroe O zona de lluvia). * Props: { w, h } (centro en x, y). */ import * as THREE from 'three'; import { Entity } from '../core/entity'; import type { Game } from '../core/game'; import type { Props } from '../core/types'; import { isToolOn } from '../core/slots'; import { kitMat } from './kit/util'; let dropGeo: THREE.BufferGeometry | null = null; const dropMat = kitMat('wxDrop', { color: 0xbfe6ff, emissive: 0x7fc8ff, emissiveIntensity: 0.35, transparent: true, opacity: 0.6, depthWrite: false }); export class RainZone extends Entity { readonly w: number; readonly h: number; private readonly drops: THREE.InstancedMesh; private readonly seeds: Float32Array; private readonly tmp = new THREE.Object3D(); constructor(p: Props) { super(); this.w = p.w ?? 10; this.h = p.h ?? 12; this.team = 'neutral'; this.tags.add('rainzone'); if (!dropGeo) { dropGeo = new THREE.BoxGeometry(0.035, 0.5, 0.035); dropGeo.userData.shared = true; } const n = Math.round(this.w * this.h * 0.6); this.drops = new THREE.InstancedMesh(dropGeo, dropMat, n); this.drops.frustumCulled = false; this.seeds = new Float32Array(n * 3); for (let i = 0; i < n; i++) { this.seeds[i * 3] = Math.random(); this.seeds[i * 3 + 1] = Math.random(); this.seeds[i * 3 + 2] = (Math.random() - 0.5) * 2.2; } this.view.add(this.drops); } contains(x: number, y: number): boolean { return Math.abs(x - this.x) < this.w / 2 && Math.abs(y - this.y) < this.h / 2 + 1; } render(alpha: number, dt: number): void { super.render(alpha, dt); const t = this.game.time; const n = this.drops.count; for (let i = 0; i < n; i++) { const sx = this.seeds[i * 3]; const sy = this.seeds[i * 3 + 1]; const u = (sy + t * 1.6) % 1; this.tmp.position.set((sx - 0.5) * this.w - u * 0.4, (0.5 - u) * this.h, this.seeds[i * 3 + 2]); this.tmp.rotation.z = 0.12; this.tmp.updateMatrix(); this.drops.setMatrixAt(i, this.tmp.matrix); } this.drops.instanceMatrix.needsUpdate = true; } } /** ¿Llueve aquí? (lluvia del héroe activa o dentro de una sala con lluvia). */ export function isRainingAt(game: Game, x: number, y: number): boolean { if (isToolOn(game.state, 'rain')) return true; for (const e of game.allByTag('rainzone')) if ((e as RainZone).contains(x, y)) return true; return false; } export function installWeather(game: Game): void { game.register('weather.rain', (_g, _x, _y, p) => new RainZone(p)); }