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