tarinai/js/tarinai_sunbath_system.js
2026-07-11 21:13:39 +09:00

51 lines
2.5 KiB
JavaScript

"use strict";
// Layer: entity-runtime/tarinai/update-system
// Owns active sunbath timer, sprite frame cycling, and recovery finish logic.
(function (global) {
function updateBody(dt) {
if ((this.sunbathTimer || 0) <= 0) return;
this.sunbathTimer = Math.max(0, (this.sunbathTimer || 0) - dt);
this.sunbathFrameTimer = Math.max(0, (this.sunbathFrameTimer || 0) - dt);
if ((this.sunbathFrameTimer || 0) <= 0) {
const prev = this._activeSunbathSpriteId || (this.sunbathSpriteId ? this.sunbathSpriteId() : this.sunbathSpriteVariant);
const next = this.randomSunbathSpriteId ? this.randomSunbathSpriteId(prev, { readyOnly: true }) : `sunbath_${1 + Math.floor(Math.random() * 3)}`;
if (next && next !== prev && (!this.isSunbathSpriteReady || this.isSunbathSpriteReady(next))) {
this._activeSunbathSpriteId = next;
this._lastRenderableSunbathSpriteId = next;
this.sunbathSpriteVariant = next;
this.visibleSpriteId = next;
this.spriteLockUntil = 0;
} else {
this.sunbathSpriteVariant = prev;
this.visibleSpriteId = prev;
}
this.sunbathFrameTimer = 0.5;
}
this.energy = clamp((this.energy || 0) + dt * 0.03, 0, typeof tarinaiMaxEnergy === "function" ? tarinaiMaxEnergy(this) : (Number(this.maxEnergy) || 100));
const felt = this.world?.feltTemperatureFor?.(this) ?? this.world?.temperatureAt?.(this.x, this.y, this) ?? this.feltTemperature ?? this.tempComfort ?? (CONFIG.standardTemperature ?? 15);
const parasolSystem = globalThis.TarinaiParasolSystem || globalThis.TarinaiRainShelterSystem;
const sunlightBlocked = parasolSystem?.blocksWeatherAt?.(this.world, this.x, this.y) || false;
if (!this.isSunbathTime() || sunlightBlocked || Number(felt) >= 22 || this.hunger > 82 || this.energy < 8 || this.state === "panic" || this.fightDisease || this.stuckPushpinId || this.currentLodgedPin?.()) this.sunbathTimer = 0;
if ((this.sunbathTimer || 0) <= 0 && this.state === "sunbath") {
this.finishSunbath?.();
this._activeSunbathSpriteId = "";
this.visibleSpriteId = "";
this.spriteLockUntil = 0;
this.sunbathAnchorX = null;
this.sunbathAnchorY = null;
this.goIdle("\u65e5\u5149\u6d74\u3092\u7d42\u3048\u305f");
}
}
function updateOne(tarinai, dt) {
if (!tarinai || tarinai.dead) return false;
updateBody.call(tarinai, dt);
return true;
}
global.TarinaiSunbathSystem = Object.freeze({
updateOne,
});
})(typeof window !== "undefined" ? window : globalThis);