tarinai/js/tarinai_sunbath_system.js

49 lines
2.3 KiB
JavaScript
Raw Normal View History

2026-06-26 12:46:32 +09:00
"use strict";
// Layer: entity-runtime/tarinai/update-system
// Owns active sunbath timer, sprite frame cycling, and recovery finish logic.
(function (global) {
2026-06-26 19:04:32 +09:00
function updateBody(dt) {
2026-06-26 12:46:32 +09:00
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));
2026-06-30 13:40:36 +09:00
const felt = this.world?.feltTemperatureFor?.(this) ?? this.world?.temperatureAt?.(this.x, this.y, this) ?? this.feltTemperature ?? this.tempComfort ?? (CONFIG.standardTemperature ?? 15);
2026-07-03 20:57:02 +09:00
if (!this.isSunbathTime() || Number(felt) >= 22 || this.hunger > 82 || this.energy < 8 || this.state === "panic" || this.fightDisease || this.stuckPushpinId || this.currentLodgedPin?.()) this.sunbathTimer = 0;
2026-06-26 12:46:32 +09:00
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;
2026-06-26 19:04:32 +09:00
updateBody.call(tarinai, dt);
2026-06-26 12:46:32 +09:00
return true;
}
global.TarinaiSunbathSystem = Object.freeze({
updateOne,
});
})(typeof window !== "undefined" ? window : globalThis);