This commit is contained in:
33333-33333 2026-06-23 22:39:20 +09:00
commit 8bd4405fe8
33 changed files with 2478 additions and 610 deletions

View file

@ -7,25 +7,31 @@
Object.defineProperties(Tarinai.prototype, Object.getOwnPropertyDescriptors({
setActionState(state, opts = {}) {
if (this.dead) return false;
this.state = state || "idle";
const nextState = state || "idle";
this.state = nextState;
if ("target" in opts) this.target = opts.target;
if (opts.reason != null) this.thought = String(opts.reason || "");
if (opts.clearTarget) this.target = null;
if (opts.sleeping != null) this.sleeping = Boolean(opts.sleeping);
if (opts.wake) {
this.sleeping = false;
this.sleepSession = null;
if (this.insideNestBoxId && this.leaveNestBox) this.leaveNestBox(this.world?.nestBoxById?.(this.insideNestBoxId));
this.insideNestBoxId = "";
}
if (nextState !== "sleep" && opts.sleeping === false) this.sleepSession = null;
return true;
},
beginEating(item = null, reason = "") {
return this.setActionState("eat", {
const text = reason || (item?.type && typeof toolLabel === "function" ? `${toolLabel(item.type)}を食べている` : "食べている");
const ok = this.setActionState("eat", {
target: item || null,
reason: reason || (item?.type && typeof toolLabel === "function" ? `${toolLabel(item.type)}を食べている` : "食べている"),
reason: text,
sleeping: false,
});
if (typeof setLiveActionText === "function") setLiveActionText(this, { need: "food", actionId: "eat_food", actionLabel: "食べている", reasonText: text, target: item || null, phase: "perform", source: "behavior" });
return ok;
},
currentLodgedPin() {
@ -42,17 +48,43 @@
},
goIdle(reason = "") {
if (typeof clearActiveBehavior === "function") clearActiveBehavior(this, reason || this.thought || "待っている");
return this.setActionState("idle", { target: null, reason: reason || this.thought || "待っている", sleeping: false });
},
startSleeping(target = null, reason = "") {
return this.setActionState("sleep", { target, reason: reason || (target?.type === "nest_box" ? "巣箱の中で眠っている" : "眠っている"), sleeping: true });
const now = this.world?.time || 0;
if (!this.sleepSession) {
const inFurniture = Boolean(target);
this.sleepSession = {
startedAt: now,
minDuration: inFurniture ? rand(16, 28) : rand(10, 18),
targetEnergy: inFurniture ? rand(84, 94) : rand(74, 86),
maxDuration: inFurniture ? rand(42, 68) : rand(28, 48),
targetId: target?.id || null,
};
}
this.intent = this.intent || { need: "sleep", tiedNeeds: ["sleep"], actionId: target ? "sleep_in_bed" : "sleep_anywhere", actionLabel: reason || "眠っている", reasonText: "ねむいので、眠っている。", startedAt: now };
this.currentAction = this.currentAction || { id: this.intent.actionId || "sleep", need: "sleep", startedAt: this.sleepSession.startedAt, minDuration: this.sleepSession.minDuration, lockSeconds: this.sleepSession.minDuration };
const text = reason || (target?.type === "nest_box" ? "巣箱の中で眠っている" : "眠っている");
if (typeof setLiveActionText === "function") setLiveActionText(this, { need: "sleep", actionId: target ? "sleep_in_bed" : "sleep_anywhere", actionLabel: "眠っている", reasonText: text, target, phase: "perform", source: "behavior" });
return this.setActionState("sleep", { target, reason: text, sleeping: true });
},
seekTarget(state, target = null, reason = "") {
return this.setActionState(state, { target, reason, sleeping: false });
},
forceBehavior(actionId = "", opts = {}) {
if (typeof queueForcedTarinaiBehavior !== "function") return false;
return queueForcedTarinaiBehavior(this, actionId, opts);
},
currentBehaviorText() {
if (typeof activeBehaviorText === "function") return activeBehaviorText(this);
return String(this.activeBehavior?.presentText || this.activeBehavior?.reasonText || this.thought || "").trim();
},
enterPanic(opts = {}) {
if (this.dead) return false;
const profile = this.personalityProfile ? this.personalityProfile() : { fear: 1 };