tarinai/js/item_lifecycle_growth_system.js
2026-07-05 18:01:36 +09:00

28 lines
1.3 KiB
JavaScript

"use strict";
// Layer: entity-runtime/items/growth-system
// Owns zunchi lifecycle stage ticking. Grass growth is handled by
// simulation_item_ant_system.js via sparse random stage advances.
(function (global) {
function updateZunchiLifecycle(item, dt, worldRef) {
if (!item || item.dead || item.type !== "zunchi") return false;
item.lifecycleTimer += dt;
const interval = item.lifecycleInterval || (0.95 + stableUnit(item.id, "zunchi-life") * 0.45);
if (item.lifecycleTimer < interval) return false;
const groundId = worldRef?.groundType || "soil";
const groundDecayMul = Number(global.TarinaiGround?.zunchiDecayMultiplier?.(groundId) || 1) || 1;
const maxLifecycleDt = groundDecayMul >= 100 ? 0.35 : 2.4;
const lifecycleDt = Math.min(item.lifecycleTimer, maxLifecycleDt);
item.lifecycleTimer = Math.max(0, item.lifecycleTimer - lifecycleDt);
global.TarinaiItemDynamicZunchiSystem.updateLifecycle(item, lifecycleDt, worldRef);
return true;
}
function update(item, dt, worldRef) {
if (!item || item.dead) return { done: true };
if (item.type === "zunchi") updateZunchiLifecycle(item, dt, worldRef);
return { done: false };
}
global.TarinaiItemGrowthSystem = Object.freeze({ update });
})(typeof window !== "undefined" ? window : globalThis);