@shipload/sdk 1.0.0-next.67 → 1.0.0-next.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/shipload.m.js CHANGED
@@ -20081,7 +20081,21 @@ function depotTransferDuration(params) {
20081
20081
  }
20082
20082
 
20083
20083
  const CIVIC_TRANSFER_PER_PLAYER_CAP = 4;
20084
- function civicShuttleBays(modules, entityItemId, lanes) {
20084
+ function unfinishedTasks(lane, now) {
20085
+ if (!lane)
20086
+ return 0;
20087
+ const startedMs = lane.schedule.started.toDate().getTime();
20088
+ const nowMs = now.getTime();
20089
+ let endSec = 0;
20090
+ let count = 0;
20091
+ for (const task of lane.schedule.tasks) {
20092
+ endSec += task.duration.toNumber();
20093
+ if (startedMs + endSec * 1000 > nowMs)
20094
+ count++;
20095
+ }
20096
+ return count;
20097
+ }
20098
+ function civicShuttleBays(modules, entityItemId, lanes, now = new Date()) {
20085
20099
  const bays = [];
20086
20100
  for (let slotIndex = 0; slotIndex < modules.length; slotIndex++) {
20087
20101
  const installed = modules[slotIndex].installed;
@@ -20092,7 +20106,7 @@ function civicShuttleBays(modules, entityItemId, lanes) {
20092
20106
  const laneKey = laneKeyForModule(slotIndex);
20093
20107
  const loader = resolveLaneLoader(modules, entityItemId, laneKey);
20094
20108
  const lane = lanes.find((l) => l.lane_key.toNumber() === laneKey);
20095
- const queued = lane ? lane.schedule.tasks.length : 0;
20109
+ const queued = unfinishedTasks(lane, now);
20096
20110
  bays.push({
20097
20111
  laneKey,
20098
20112
  slotIndex,
@@ -20105,11 +20119,11 @@ function civicShuttleBays(modules, entityItemId, lanes) {
20105
20119
  }
20106
20120
  return bays;
20107
20121
  }
20108
- function selectCivicShuttleBay(modules, entityItemId, lanes) {
20109
- const bays = civicShuttleBays(modules, entityItemId, lanes);
20122
+ function selectCivicShuttleBay(modules, entityItemId, lanes, now = new Date()) {
20123
+ const bays = civicShuttleBays(modules, entityItemId, lanes, now);
20110
20124
  return bays.find((bay) => bay.queued === 0) ?? bays[0];
20111
20125
  }
20112
- function pendingCivicTransfers(entity) {
20126
+ function pendingCivicTransfers(entity, now = new Date()) {
20113
20127
  const tailIndex = new Map();
20114
20128
  for (const l of entity.lanes ?? []) {
20115
20129
  tailIndex.set(l.lane_key.toNumber(), l.schedule.tasks.length - 1);
@@ -20123,6 +20137,7 @@ function pendingCivicTransfers(entity) {
20123
20137
  if (!pull || !push)
20124
20138
  continue;
20125
20139
  const isTail = tailIndex.get(entry.laneKey) === entry.taskIndex;
20140
+ const complete = entry.completesAt.getTime() <= now.getTime();
20126
20141
  out.push({
20127
20142
  laneKey: entry.laneKey,
20128
20143
  taskIndex: entry.taskIndex,
@@ -20132,17 +20147,19 @@ function pendingCivicTransfers(entity) {
20132
20147
  startsAt: entry.startsAt,
20133
20148
  completesAt: entry.completesAt,
20134
20149
  isTail,
20135
- callable: isTail && !entry.task.entitygroup,
20150
+ complete,
20151
+ callable: isTail && !complete && !entry.task.entitygroup,
20136
20152
  });
20137
20153
  }
20138
20154
  return out;
20139
20155
  }
20140
- function civicTransfersFrom(entity, senderIds) {
20156
+ function civicTransfersFrom(entity, senderIds, now = new Date()) {
20141
20157
  const owned = new Set(senderIds.map((id) => String(id)));
20142
- return pendingCivicTransfers(entity).filter((t) => owned.has(String(t.senderId)));
20158
+ return pendingCivicTransfers(entity, now).filter((t) => owned.has(String(t.senderId)));
20143
20159
  }
20144
- function civicTransfersAtCap(entity, senderIds) {
20145
- return civicTransfersFrom(entity, senderIds).length >= CIVIC_TRANSFER_PER_PLAYER_CAP;
20160
+ function civicTransfersAtCap(entity, senderIds, now = new Date()) {
20161
+ return (civicTransfersFrom(entity, senderIds, now).filter((t) => !t.complete).length >=
20162
+ CIVIC_TRANSFER_PER_PLAYER_CAP);
20146
20163
  }
20147
20164
 
20148
20165
  var citizenryAdjectives = [