From 9a3e9d4757aff6cd11eafb28d45b24d0e0ae415e Mon Sep 17 00:00:00 2001 From: root Date: Mon, 9 Mar 2026 03:00:55 +0000 Subject: [PATCH] fix(server): prioritize stockpile dropoff over wandering after gathering Co-Authored-By: Claude Opus 4.6 --- server/src/systems/gatheringSystem.ts | 29 ++++++++++++--------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/server/src/systems/gatheringSystem.ts b/server/src/systems/gatheringSystem.ts index 0e24541..ba26717 100644 --- a/server/src/systems/gatheringSystem.ts +++ b/server/src/systems/gatheringSystem.ts @@ -38,24 +38,21 @@ export function gatheringSystem(world: World, map: GameMap): void { } world.removeComponent(entity, 'gatheringState'); - // Decide next action - if (needs.productivity >= PRODUCTIVITY_THRESHOLD) { - brain.currentGoal = 'wander'; - } else { - // Check if a stockpile exists for drop-off - let hasStockpile = false; - for (const sEntity of world.query('structure')) { - const sData = world.getComponent(sEntity, 'structure'); - if (sData && sData.type === 'stockpile' && sData.buildProgress === undefined) { - hasStockpile = true; - break; - } + // Decide next action: always drop off first if possible + let hasStockpile = false; + for (const sEntity of world.query('structure')) { + const sData = world.getComponent(sEntity, 'structure'); + if (sData && sData.type === 'stockpile' && sData.buildProgress === undefined) { + hasStockpile = true; + break; } - if (hasStockpile && inv && inv.size > 0) { - brain.currentGoal = 'dropoff'; - } - // else brain stays on 'gather', npcBrain will pick new target next tick } + if (hasStockpile && inv && inv.size > 0) { + brain.currentGoal = 'dropoff'; + } else if (needs.productivity >= PRODUCTIVITY_THRESHOLD) { + brain.currentGoal = 'wander'; + } + // else brain stays on 'gather', npcBrain will pick new target next tick } continue; }