a
This commit is contained in:
parent
d163ceb291
commit
f6d7412744
94 changed files with 3836 additions and 1226 deletions
|
|
@ -73,6 +73,50 @@
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
function nestOccupantPriority(tarinai) {
|
||||
if (!tarinai) return -1;
|
||||
if (tarinai.isTarinaiChampion) return 2;
|
||||
if (tarinai.isZunchiSlave) return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
function lowerPriorityNestOccupant(worldRef, box, entrant, occupants = null) {
|
||||
const entrantPriority = nestOccupantPriority(entrant);
|
||||
const list = Array.isArray(occupants) ? occupants : nestBoxOccupants(worldRef, box, Infinity);
|
||||
let best = null;
|
||||
let bestPriority = Infinity;
|
||||
for (const occupant of list || []) {
|
||||
if (!occupant || occupant.dead || occupant === entrant) continue;
|
||||
const priority = nestOccupantPriority(occupant);
|
||||
if (priority >= entrantPriority) continue;
|
||||
if (priority < bestPriority) {
|
||||
best = occupant;
|
||||
bestPriority = priority;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
function lowerPriorityNestReservation(worldRef, box, entrant) {
|
||||
if (!worldRef || !box || !entrant) return null;
|
||||
const now = Number(worldRef.time || 0) || 0;
|
||||
const entrantPriority = nestOccupantPriority(entrant);
|
||||
let best = null;
|
||||
let bestPriority = Infinity;
|
||||
for (const candidate of worldRef.tarinai || []) {
|
||||
if (!candidate || candidate.dead || candidate === entrant) continue;
|
||||
if (!tarinaiIsReservingNest(candidate, box, now)) continue;
|
||||
const priority = nestOccupantPriority(candidate);
|
||||
if (priority >= entrantPriority) continue;
|
||||
if (priority < bestPriority) {
|
||||
best = candidate;
|
||||
bestPriority = priority;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
function nestBoxReservationCount(worldRef, box) {
|
||||
if (!worldRef || !box || box.dead || !isNestContainer(box)) return 0;
|
||||
const now = Number(worldRef.time || 0) || 0;
|
||||
|
|
@ -113,8 +157,11 @@
|
|||
if (sleepTargetBlocked(worldRef, tarinai, item)) return false;
|
||||
const capacity = isNestContainer(item) ? nestBoxCapacity(worldRef, item) : 1;
|
||||
const occupancy = bedOccupancy(worldRef, item);
|
||||
if (tarinai?.isTarinaiChampion && item.type === "nest_box") return true;
|
||||
return occupancy < capacity || tarinai.target === item || (tarinai.insideNestBoxId && tarinai.insideNestBoxId === item.id);
|
||||
if (tarinai.target === item || (tarinai.insideNestBoxId && tarinai.insideNestBoxId === item.id)) return true;
|
||||
if (occupancy < capacity) return true;
|
||||
if (!isNestContainer(item)) return false;
|
||||
const occupants = nestBoxOccupants(worldRef, item, Infinity);
|
||||
return Boolean(lowerPriorityNestOccupant(worldRef, item, tarinai, occupants) || lowerPriorityNestReservation(worldRef, item, tarinai));
|
||||
}
|
||||
|
||||
function findStructure(worldRef, tarinai, opts = {}) {
|
||||
|
|
@ -195,5 +242,7 @@
|
|||
nearestSleepPlaceOfType,
|
||||
findPrioritySleepPlaceBeforeGrassBedBuild,
|
||||
findNearestSleepPlace,
|
||||
nestOccupantPriority,
|
||||
lowerPriorityNestOccupant,
|
||||
});
|
||||
})(typeof window !== "undefined" ? window : globalThis);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue