From f8031af424b36d72effddce5d60bd7cba621dc16 Mon Sep 17 00:00:00 2001 From: uwap Date: Sat, 3 Jan 2026 09:44:38 +0100 Subject: [PATCH] Fix withdraw amount calculations --- src/Tasks/Withdraw.ts | 5 ++++- src/index.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Tasks/Withdraw.ts b/src/Tasks/Withdraw.ts index 70054f6..559be24 100644 --- a/src/Tasks/Withdraw.ts +++ b/src/Tasks/Withdraw.ts @@ -46,13 +46,16 @@ export const runWithdraw = profiler.registerFN( const capacity = creep.store.getFreeCapacity(opts.resource); const amount = Math.min(opts.amount ?? capacity, opts.limit ?? capacity - creep.store.getUsedCapacity(opts.resource)); + const amountS = target != null && "store" in target + ? target.store.getUsedCapacity(opts.resource) + : amount; if (amount <= 0) { return TaskStatus.DONE; } if (target == null - || creep.withdraw(target, opts.resource, amount) === ERR_NOT_IN_RANGE) { + || creep.withdraw(target, opts.resource, amountS) === ERR_NOT_IN_RANGE) { creep.travelTo(task.targetPos); return TaskStatus.IN_PROGRESS; } diff --git a/src/index.ts b/src/index.ts index 6882ffd..ade1745 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import "../deps/Traveler/Traveler.js"; +import "../deps/Traveler/Traveler.ts"; import "../deps/Traveler/index.d.ts"; import "./Proto"; import profiler from "screeps-profiler";