This commit is contained in:
33333-33333 2026-06-28 13:40:41 +09:00
commit f500279abd
93 changed files with 1893 additions and 1198 deletions

View file

@ -13,7 +13,7 @@
if ("target" in opts) this.target = opts.target;
if (opts.reason != null) this.thought = String(opts.reason || "");
if (opts.clearTarget) this.target = null;
const wakingNow = Boolean(opts.wake) || (wasSleeping && nextState !== "sleep" && opts.sleeping === false);
const wakingNow = wasSleeping && (Boolean(opts.wake) || (nextState !== "sleep" && opts.sleeping === false));
if (wakingNow) this.consumePendingGrassBedOnWake?.(opts.reason || "wake");
if (opts.sleeping != null) this.sleeping = Boolean(opts.sleeping);
if (opts.wake) {
@ -26,7 +26,7 @@
const reason = String(opts.reason ?? this.thought ?? "");
if (nextState === "idle") {
if (typeof clearBehavior === "function") clearBehavior(this, reason || "待っている");
if (typeof clearBehavior === "function") clearBehavior(this, reason || "\u5f85\u3063\u3066\u3044\u308b");
else if (typeof clearTarinaiBehavior === "function") clearTarinaiBehavior(this, { clearTarget: !!opts.clearTarget });
return true;
}
@ -139,16 +139,31 @@
consumePendingGrassBedOnWake(reason = "wake") {
const worldRef = this.world || null;
const sessionTargetId = this.sleepSession?.targetId || this.pendingGrassBedWakeId || null;
const session = this.sleepSession || null;
const sessionTargetId = session?.targetId || this.pendingGrassBedWakeId || null;
const bySession = sessionTargetId && worldRef?.itemById ? worldRef.itemById(sessionTargetId) : null;
const byItems = sessionTargetId ? (worldRef?.items || []).find(it => it && it.id === sessionTargetId) : null;
const candidates = [this.target, bySession, byItems];
let bed = candidates.find(it => it && !it.dead && it.type === "grass_bed" && (it.singleUsePending || it.singleUseConsumedById === this.id || (this.sleepSession?.consumesGrassBedOnWake && it.id === sessionTargetId)));
if (!bed && (this.sleepSession?.consumesGrassBedOnWake || sessionTargetId)) {
let bed = candidates.find(it => it && !it.dead && it.type === "grass_bed" && (it.singleUsePending || it.singleUseConsumedById === this.id || (session?.consumesGrassBedOnWake && it.id === sessionTargetId)));
if (!bed && (session?.consumesGrassBedOnWake || sessionTargetId)) {
bed = (worldRef?.items || []).find(it => it && !it.dead && it.type === "grass_bed"
&& (it.id === sessionTargetId || (it.singleUsePending && (it.singleUseConsumedById === this.id || it.ownerId === this.id))));
}
if (!bed) return false;
const now = Number(worldRef?.time || 0) || 0;
const started = Number(session?.startedAt);
const sleptFor = Number.isFinite(started) ? Math.max(0, now - started) : 0;
const wasActuallySleeping = Boolean((this.state === "sleep" || this.sleeping || session) && session?.consumesGrassBedOnWake);
// Reserve-on-use must not consume the simple bed. It is consumed only by
// a real wake after sleep has started; pre-sleep wake flags just release
// the reservation and leave the bed intact.
if (!wasActuallySleeping || sleptFor < 0.75) {
if (bed.singleUseConsumedById === this.id) bed.singleUseConsumedById = "";
if (bed.singleUsePending && (!bed.singleUseConsumedById || bed.singleUseConsumedById === this.id)) bed.singleUsePending = false;
this.pendingGrassBedWakeId = "";
if (session) session.consumesGrassBedOnWake = false;
return false;
}
this.pendingGrassBedWakeId = "";
return window.TarinaiStructureLifecycle?.consumeGrassBedOnWake?.(worldRef, bed, this, reason) || false;
},