2026-06-21 22:29:00 +09:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
(function (global) {
|
|
|
|
|
const WEATHER_STATES = Object.freeze(["sunny", "cloudy", "light_rain"]);
|
|
|
|
|
|
|
|
|
|
const WeatherSystem = Object.freeze({
|
|
|
|
|
states: WEATHER_STATES,
|
|
|
|
|
|
|
|
|
|
chooseNext(current = "sunny") {
|
|
|
|
|
const choices = current === "light_rain"
|
|
|
|
|
? ["sunny", "cloudy"]
|
|
|
|
|
: ["sunny", "cloudy", "light_rain"];
|
|
|
|
|
return pick(choices);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
resetTimer() {
|
|
|
|
|
return rand(CONFIG.weatherChangeMin, CONFIG.weatherChangeMax);
|
|
|
|
|
},
|
|
|
|
|
|
2026-06-26 19:04:32 +09:00
|
|
|
fixedWeatherFor(worldRef) {
|
|
|
|
|
const fixed = global.TarinaiGround?.fixedWeather?.(worldRef?.groundType || "soil") || "";
|
|
|
|
|
return fixed || null;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
enforceFixedWeather(worldRef) {
|
|
|
|
|
const fixed = this.fixedWeatherFor(worldRef);
|
|
|
|
|
if (!fixed || !worldRef) return false;
|
|
|
|
|
const previous = worldRef.weather || "sunny";
|
|
|
|
|
worldRef.weather = fixed;
|
|
|
|
|
worldRef.nextWeatherChange = this.resetTimer();
|
|
|
|
|
if (previous !== fixed) {
|
|
|
|
|
worldRef.emit?.("weather:changed", { previous, next: fixed });
|
|
|
|
|
worldRef.log?.(`天気: ${weatherLabel(fixed)}`);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
|
2026-06-21 22:29:00 +09:00
|
|
|
shouldDropRainWater(worldRef, dt = 0) {
|
|
|
|
|
return Boolean(
|
|
|
|
|
worldRef?.weather === "light_rain" &&
|
|
|
|
|
Math.random() < Math.max(0, Number(dt) || 0) * 0.12
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
createRainWaterItem(worldRef) {
|
|
|
|
|
const drop = new Item("water", rand(58, worldRef.w - 58), rand(58, worldRef.h - 58));
|
|
|
|
|
drop.amount = rand(24, 58);
|
|
|
|
|
return drop;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
applyNextWeather(worldRef) {
|
|
|
|
|
if (!worldRef) return null;
|
2026-06-26 19:04:32 +09:00
|
|
|
if (this.enforceFixedWeather(worldRef)) return worldRef.weather || "sunny";
|
2026-06-21 22:29:00 +09:00
|
|
|
const previous = worldRef.weather || "sunny";
|
|
|
|
|
const next = this.chooseNext(previous);
|
|
|
|
|
worldRef.weather = next;
|
|
|
|
|
worldRef.nextWeatherChange = this.resetTimer();
|
|
|
|
|
if (next !== previous) {
|
|
|
|
|
worldRef.emit?.("weather:changed", { previous, next });
|
|
|
|
|
worldRef.log?.(`\u5929\u6c17: ${weatherLabel(next)}`);
|
|
|
|
|
}
|
|
|
|
|
return next;
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
global.TarinaiWeatherSystem = WeatherSystem;
|
|
|
|
|
})(typeof window !== "undefined" ? window : globalThis);
|