This commit is contained in:
33333-33333 2026-06-29 21:02:04 +09:00
commit e00bfd8879
51 changed files with 1203 additions and 833 deletions

View file

@ -12,9 +12,13 @@
return Boolean(item && (item.roles?.sleepPlace || (typeof global.isSleepFurnitureType === "function" ? global.isSleepFurnitureType(item.type) : (item.type === "bed" || item.type === "nest_box" || item.type === "grass_bed"))));
}
function sleepTargetBlocked(worldRef, tarinai, item) {
if (!worldRef || !tarinai || !item) return false;
return Boolean(worldRef.targetBlockedByObstacle?.(tarinai, item, Math.max(18, (tarinai.radius || 20) * 0.65)));
}
function nestBoxCapacity(worldRef, box = null) {
if (worldRef?.nestBoxCapacity && worldRef.nestBoxCapacity !== nestBoxCapacityFacade) return worldRef.nestBoxCapacity(box);
return 5;
return typeof worldRef?.nestBoxCapacity === "function" ? worldRef.nestBoxCapacity(box) : 5;
}
function nestBoxOccupants(worldRef, box, limit = 5) {
@ -72,6 +76,7 @@
function sleepPlaceAvailableFor(worldRef, tarinai, item) {
if (!worldRef || !tarinai || !item || item.dead || !isSleepFurniture(item)) return false;
if (tarinai.shouldAvoidTarget?.(item)) return false;
if (sleepTargetBlocked(worldRef, tarinai, item)) return false;
const capacity = item.type === "nest_box" ? nestBoxCapacity(worldRef, item) : 1;
const occupancy = bedOccupancy(worldRef, item);
return occupancy < capacity || (tarinai.insideNestBoxId && tarinai.insideNestBoxId === item.id);
@ -82,6 +87,7 @@
for (const item of worldRef?.items || []) {
if (!item?.isStructure || item.dead || item.ownerId !== tarinai?.id) continue;
if (type && item.type !== type) continue;
if (sleepTargetBlocked(worldRef, tarinai, item)) continue;
const d = distFn(tarinai, item);
if (d < bestD) { best = item; bestD = d; }
}
@ -94,6 +100,7 @@
if (!item?.isStructure || item.dead || item.ownerId) continue;
if (type && item.type !== type) continue;
if (tarinai?.shouldAvoidTarget?.(item)) continue;
if (sleepTargetBlocked(worldRef, tarinai, item)) continue;
const d = distFn(tarinai, item);
if (d < bestD) { best = item; bestD = d; }
}
@ -129,9 +136,6 @@
|| null;
}
// Named separately so nestBoxCapacity() can detect and avoid recursive facade calls.
function nestBoxCapacityFacade(box) { return nestBoxCapacity(this, box); }
global.TarinaiNestSleepSystem = Object.freeze({
isSleepFurniture,
isTarinaiHiddenInNestBox,