90 lines
5.3 KiB
JavaScript
90 lines
5.3 KiB
JavaScript
"use strict";
|
|
|
|
(function (global) {
|
|
const MAX_PENDING_LOSSES = 16;
|
|
|
|
|
|
function relationWithDead(observer, dead, worldRef) {
|
|
if (!observer || !dead || observer === dead) return "";
|
|
const deadFamily = worldRef?.tarinaiFamilyKey ? worldRef.tarinaiFamilyKey(dead) : (dead.familyKey || "");
|
|
const observerFamily = observer.familyKey || observer.archiveKey || observer.id || "";
|
|
const deadId = dead.id || dead.releasedLiveId || "";
|
|
const observerId = observer.id || observer.liveId || "";
|
|
if (deadFamily && (observer.parents || []).includes(deadFamily)) return "\u89aa";
|
|
if (deadFamily && (observer.children || []).includes(deadFamily)) return "\u5b50";
|
|
if (observerFamily && (dead.parents || []).includes(observerFamily)) return "\u5b50";
|
|
if (observerFamily && (dead.children || []).includes(observerFamily)) return "\u89aa";
|
|
const rel = deadId ? observer.relationships?.[deadId] : null;
|
|
const reverse = observerId ? dead.relationships?.[observerId] : null;
|
|
if ((rel?.affinity || 0) >= (global.FRIEND_AFFINITY_THRESHOLD || 14) || (reverse?.affinity || 0) >= (global.FRIEND_AFFINITY_THRESHOLD || 14)) return "\u53cb\u9054";
|
|
return "";
|
|
}
|
|
|
|
function applyLiveDeathShock(observer, dead, relation, worldRef) {
|
|
const strong = relation === "\u89aa" || relation === "\u5b50";
|
|
if (observer.state === "sleep" || observer.state === "seek_bed") observer.goIdle?.("\u8eab\u8fd1\u306a\u500b\u4f53\u306e\u6b7b\u306b\u6c17\u3065\u3044\u305f");
|
|
const stress = strong ? 18 : 11;
|
|
const fear = strong ? 2.1 : 1.45;
|
|
if (observer.enterPanic) {
|
|
const relLabel = relation || "\u8eab\u8fd1\u306a\u500b\u4f53";
|
|
observer.lastPanicDetail = `${dead.name || "\u8eab\u8fd1\u306a\u500b\u4f53"}\uff08${relLabel}\uff09\u306e\u6b7b\u306b\u6c17\u4ed8\u3044\u305f`;
|
|
observer.enterPanic({ threat: dead, reason: `${dead.name || "\u8eab\u8fd1\u306a\u500b\u4f53"}\uff08${relLabel}\uff09\u306e\u6b7b\u306b\u6c17\u4ed8\u3044\u3066\u3001\u30d1\u30cb\u30c3\u30af\u306b\u306a\u3063\u3066\u3044\u308b\u3002`, fear, stress, cause: "relation_death", bubble: "!!", bubbleColor: "rgba(60,50,68,0.82)" });
|
|
}
|
|
else {
|
|
observer.sleeping = false;
|
|
observer.setActionState?.("panic", { target: observer.panicDestination ? observer.panicDestination(dead) : null, reason: `${dead.name || "\u8eab\u8fd1\u306a\u500b\u4f53"}\uff08${relation || "\u8eab\u8fd1\u306a\u500b\u4f53"}\uff09\u306e\u6b7b\u306b\u6c17\u4ed8\u3044\u3066\u3001\u30d1\u30cb\u30c3\u30af\u306b\u306a\u3063\u3066\u3044\u308b\u3002`, wake: true });
|
|
observer.fearTimer = Math.max(observer.fearTimer || 0, fear);
|
|
if (typeof applyNeedShock === "function") applyNeedShock(observer, { safety: stress * 1.6, social: stress * 1.4 });
|
|
observer.bubble?.("!!", 1.0, "rgba(60,50,68,0.82)");
|
|
}
|
|
observer.recordChangeCause?.(`${relation}\u306e\u6b7b\u4ea1`, "\u30b9\u30c8\u30ec\u30b9", { value: stress });
|
|
observer.addRecord?.(`${dead.name || "\u8eab\u8fd1\u306a\u500b\u4f53"}\u306e\u6b7b\u306b\u6c17\u3065\u3044\u3066\u30d1\u30cb\u30c3\u30af\u306b\u306a\u3063\u305f\u3002`, "death");
|
|
}
|
|
|
|
function notifyDeathToRelations(dead, reason = "") {
|
|
const worldRef = this || global.world;
|
|
if (!worldRef || !dead) return;
|
|
const deadFamily = worldRef.tarinaiFamilyKey ? worldRef.tarinaiFamilyKey(dead) : (dead.familyKey || "");
|
|
const deadId = dead.id || dead.releasedLiveId || "";
|
|
let liveHits = 0;
|
|
for (const other of worldRef.tarinai || []) {
|
|
if (!other || other === dead || other.dead) continue;
|
|
const relation = relationWithDead(other, dead, worldRef);
|
|
if (!relation) continue;
|
|
applyLiveDeathShock(other, dead, relation, worldRef);
|
|
liveHits += 1;
|
|
}
|
|
for (const entry of (global.TarinaiFreezeSystem?.frozenList?.(worldRef) || [])) {
|
|
const data = entry.data || entry;
|
|
const relation = relationWithDead(data, dead, worldRef);
|
|
if (!relation) continue;
|
|
if (!Array.isArray(entry.pendingLosses)) entry.pendingLosses = [];
|
|
const duplicate = entry.pendingLosses.some(l => (deadFamily && l.familyKey === deadFamily) || (deadId && l.liveId === deadId));
|
|
if (!duplicate) {
|
|
entry.pendingLosses.unshift({
|
|
relation,
|
|
name: dead.name || "\u305f\u308a\u306a\u3044",
|
|
familyKey: deadFamily,
|
|
liveId: deadId,
|
|
reason: reason || dead.deathReason || "\u6b7b\u4ea1",
|
|
time: worldRef.time || 0,
|
|
});
|
|
if (entry.pendingLosses.length > MAX_PENDING_LOSSES) entry.pendingLosses.length = MAX_PENDING_LOSSES;
|
|
}
|
|
}
|
|
if (liveHits) worldRef.log?.(`${dead.name || "\u305f\u308a\u306a\u3044"}\u306e\u6b7b\u306b\u3001\u8eab\u8fd1\u306a\u500b\u4f53\u304c\u52d5\u63fa\u3057\u305f\u3002`, "death", { participants: [dead] });
|
|
global.TarinaiFreezeSystem?.saveFrozenStore?.(worldRef);
|
|
global.TarinaiFreezeSystem?.renderFrozenPanel?.(worldRef);
|
|
}
|
|
|
|
function patchWorldPrototype() {
|
|
const apply = (proto) => { proto.notifyDeathToRelations = notifyDeathToRelations; };
|
|
if (global.TarinaiPatcher?.patchWorld?.("relationEvents", apply)) return;
|
|
const World = global.World;
|
|
if (!World) return;
|
|
apply(World.prototype);
|
|
}
|
|
|
|
global.TarinaiRelationEvents = { relationWithDead, applyLiveDeathShock, notifyDeathToRelations, patchWorldPrototype };
|
|
patchWorldPrototype();
|
|
})(typeof window !== "undefined" ? window : globalThis);
|