many
This commit is contained in:
parent
0b9ff1363b
commit
0a6148c73f
67 changed files with 2653 additions and 1519 deletions
49
js/weather_system.js
Normal file
49
js/weather_system.js
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
"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);
|
||||
},
|
||||
|
||||
shouldDropRainWater(worldRef, dt = 0) {
|
||||
return Boolean(
|
||||
worldRef?.weather === "light_rain" &&
|
||||
(worldRef.itemCounts?.water || 0) < 24 &&
|
||||
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;
|
||||
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);
|
||||
Loading…
Add table
Add a link
Reference in a new issue