duu
This commit is contained in:
parent
88f618cadf
commit
8f9f5b5100
108 changed files with 2139 additions and 1500 deletions
|
|
@ -8,7 +8,7 @@
|
|||
const clampFn = typeof clamp === "function" ? clamp : ((v, a, b) => Math.max(a, Math.min(b, v)));
|
||||
|
||||
function isNestContainer(item) {
|
||||
return Boolean(item && (typeof global.isNestContainerType === "function" ? global.isNestContainerType(item.type) : (item.type === "nest_box" || item.type === "pipe")));
|
||||
return Boolean(global.TarinaiToolRuntime?.isNestContainerItem?.(item, { alive: false }));
|
||||
}
|
||||
|
||||
function isSleepFurniture(item) {
|
||||
|
|
@ -23,13 +23,27 @@
|
|||
return Boolean(worldRef.targetBlockedByObstacle?.(tarinai, item, Math.max(18, (tarinai.radius || 20) * 0.65)));
|
||||
}
|
||||
|
||||
function pipeItems(worldRef) {
|
||||
return (worldRef?.items || []).filter(it => it && !it.dead && it.type === "pipe");
|
||||
}
|
||||
|
||||
function tarinaiInsidePipeNetwork(worldRef, t) {
|
||||
if (!worldRef || !t || t.dead || !t.insideNestBoxId) return false;
|
||||
const holder = typeof worldRef.nestBoxById === "function" ? worldRef.nestBoxById(t.insideNestBoxId) : (worldRef.items || []).find(it => it && !it.dead && it.id === t.insideNestBoxId);
|
||||
return holder?.type === "pipe";
|
||||
}
|
||||
|
||||
function nestBoxCapacity(worldRef, box = null) {
|
||||
return typeof worldRef?.nestBoxCapacity === "function" ? worldRef.nestBoxCapacity(box) : (box?.type === "pipe" ? 3 : 5);
|
||||
if (typeof worldRef?.nestBoxCapacity === "function") return worldRef.nestBoxCapacity(box);
|
||||
if (box?.type === "pipe") return Math.max(3, pipeItems(worldRef).length * 3);
|
||||
return 5;
|
||||
}
|
||||
|
||||
function nestBoxOccupants(worldRef, box, limit = 5) {
|
||||
if (!worldRef || !box || box.dead || !isNestContainer(box)) return [];
|
||||
const occupants = (worldRef.tarinai || []).filter(t => t && !t.dead && t.insideNestBoxId === box.id);
|
||||
const occupants = box.type === "pipe"
|
||||
? (worldRef.tarinai || []).filter(t => tarinaiInsidePipeNetwork(worldRef, t))
|
||||
: (worldRef.tarinai || []).filter(t => t && !t.dead && t.insideNestBoxId === box.id);
|
||||
return Number.isFinite(limit) ? occupants.slice(0, Math.max(0, limit)) : occupants;
|
||||
}
|
||||
|
||||
|
|
@ -41,11 +55,21 @@
|
|||
return true;
|
||||
}
|
||||
|
||||
function tarinaiTargetContainer(t) {
|
||||
const target = t?.target || null;
|
||||
return isNestContainer(target) ? target : (isNestContainer(target?.shelterItem) ? target.shelterItem : (isNestContainer(target?.hostItem) ? target.hostItem : null));
|
||||
}
|
||||
|
||||
function tarinaiIsReservingNest(t, box, now = 0) {
|
||||
if (!t || t.dead || !box || t.insideNestBoxId === box.id) return false;
|
||||
if (t.target !== box) return false;
|
||||
if (!t || t.dead || !box) return false;
|
||||
if (box.type === "pipe" && t.insideNestBoxId && tarinaiInsidePipeNetwork(t.world || null, t)) return false;
|
||||
if (box.type !== "pipe" && t.insideNestBoxId === box.id) return false;
|
||||
const target = tarinaiTargetContainer(t);
|
||||
if (box.type === "pipe") {
|
||||
if (target?.type !== "pipe") return false;
|
||||
} else if (target !== box) return false;
|
||||
if (t._nestBoxAvoidId === box.id && now < (t._nestBoxAvoidUntil || -Infinity)) return false;
|
||||
const seekingNest = t.state === "seek_bed" || t.state === "sleep" || t.sleeping || t.behavior?.actionId === "sleep_in_bed";
|
||||
const seekingNest = t.state === "seek_bed" || t.state === "sleep" || t.sleeping || t.state === "seek_temperature" || t.behavior?.actionId === "sleep_in_bed";
|
||||
if (!seekingNest) return false;
|
||||
return true;
|
||||
}
|
||||
|
|
@ -83,6 +107,7 @@
|
|||
function sleepPlaceAvailableFor(worldRef, tarinai, item) {
|
||||
if (!worldRef || !tarinai || !item || item.dead || !isSleepFurniture(item)) return false;
|
||||
if (Number(item.unreachableUntil || 0) > Number(worldRef.time || 0)) return false;
|
||||
if (item.type === "nest_box" && globalThis.TarinaiItemDynamicToolSystem?.nestBoxFireActive?.(item)) return false;
|
||||
if (item.abandonedById && item.abandonedById === tarinai?.id && Number(item.abandonedUntil || 0) > Number(worldRef.time || 0)) return false;
|
||||
if (tarinai.shouldAvoidTarget?.(item)) return false;
|
||||
if (worldRef?.sleepTargetTemperatureBlocked?.(tarinai, item)) return false;
|
||||
|
|
@ -155,14 +180,12 @@
|
|||
}
|
||||
|
||||
global.TarinaiNestSleepSystem = Object.freeze({
|
||||
isNestContainer,
|
||||
isSleepFurniture,
|
||||
isTarinaiHiddenInNestBox,
|
||||
nestBoxOccupants,
|
||||
bedOccupancy,
|
||||
bedComfort,
|
||||
sleepPlaceAvailableFor,
|
||||
findStructure,
|
||||
findOwnedStructure,
|
||||
findUnownedStructure,
|
||||
nearestSleepPlaceOfType,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue