This commit is contained in:
33333-33333 2026-07-11 21:13:39 +09:00
commit d14550dad6
78 changed files with 2827 additions and 563 deletions

View file

@ -3,6 +3,53 @@
// Layer: entity-runtime/tarinai/update-system
// Owns local family/friend/grass/nest comfort environment effects.
(function (global) {
function parasolFootprint(item = null) {
if (!item || item.dead || item.type !== "rain_shelter") return null;
const r = Math.max(30, Number(item.r || 50) || 50);
// The pole foot is the visual and physical center of the shade.
return {
centerX: Number(item.x || 0),
centerY: Number(item.y || 0) + r * 0.84,
radiusX: r * 1.58,
radiusY: r * 0.68,
};
}
function parasolRange(item = null) {
return parasolFootprint(item)?.radiusX || 0;
}
function parasolContains(item = null, x = 0, y = 0) {
const footprint = parasolFootprint(item);
if (!footprint) return false;
const nx = (Number(x || 0) - footprint.centerX) / Math.max(1, footprint.radiusX);
const ny = (Number(y || 0) - footprint.centerY) / Math.max(1, footprint.radiusY);
return nx * nx + ny * ny <= 1;
}
function parasolAt(worldRef, x, y) {
if (!worldRef) return null;
const candidates = typeof worldRef.itemsOfType === "function"
? worldRef.itemsOfType("rain_shelter")
: (worldRef.nearbyItems?.(x, y, 240) || []);
let best = null;
let bestRatio = Infinity;
for (const item of candidates || []) {
const footprint = parasolFootprint(item);
if (!footprint) continue;
const nx = (Number(x || 0) - footprint.centerX) / Math.max(1, footprint.radiusX);
const ny = (Number(y || 0) - footprint.centerY) / Math.max(1, footprint.radiusY);
const ratio = Math.sqrt(nx * nx + ny * ny);
if (ratio <= 1 && ratio < bestRatio) { best = item; bestRatio = ratio; }
}
return best;
}
function shelterRange(item = null) { return parasolRange(item); }
function shelterAt(worldRef, x, y) { return parasolAt(worldRef, x, y); }
function isSheltered(worldRef, x, y) { return Boolean(parasolAt(worldRef, x, y)); }
function blocksWeatherAt(worldRef, x, y) { return Boolean(parasolAt(worldRef, x, y)); }
function updateBody(dt) {
const parent = this.parentToFollow ? this.parentToFollow() : null;
if (parent && dist(this, parent) < 96) {
@ -30,7 +77,17 @@
if (!it || it.dead || it.type !== "nest_box") continue;
nestComfort += clamp(1 - distXY(this.x, this.y, it.x, it.y) / 120, 0, 1);
}
let rainShelterComfort = 0;
const rainShelter = parasolAt(this.world, this.x, this.y);
if (rainShelter && (this.world?.weather || "") === "light_rain") {
const range = parasolRange(rainShelter);
rainShelterComfort = clamp(1 - distXY(this.x, this.y, rainShelter.x, rainShelter.y) / range, 0.25, 1);
}
if (nestComfort > 0) applyNeedRelief(this, { sleep: -dt * Math.min(4, nestComfort * 3), safety: -dt * Math.min(5, nestComfort * 4) });
if (rainShelterComfort > 0) {
applyNeedRelief(this, { safety: -dt * Math.min(6, rainShelterComfort * 5), health: -dt * Math.min(3, rainShelterComfort * 2), fulfill: -dt * Math.min(2, rainShelterComfort * 1.2) });
if (this.state === "panic") this.fearTimer = Math.max(0, this.fearTimer - dt * Math.min(0.35, rainShelterComfort * 0.08));
}
if (grassComfort > 0) {
applyNeedRelief(this, { fulfill: -dt * Math.min(2, grassComfort * 0.5), safety: -dt * Math.min(1.5, grassComfort * 0.4) });
if (this.state === "panic") this.fearTimer = Math.max(0, this.fearTimer - dt * Math.min(0.22, grassComfort * 0.06));
@ -45,6 +102,9 @@
return true;
}
const parasolSystem = Object.freeze({ parasolFootprint, parasolRange, parasolContains, parasolAt, shelterRange, shelterAt, isSheltered, blocksWeatherAt });
global.TarinaiParasolSystem = parasolSystem;
global.TarinaiRainShelterSystem = parasolSystem;
global.TarinaiLocalEnvironmentSystem = Object.freeze({
updateOne,
});