@shipload/sdk 1.0.0-next.23 → 1.0.0-next.25

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.
@@ -10,6 +10,7 @@ import type {
10
10
  FinalizerEntityRef,
11
11
  InboundTransfer,
12
12
  Reservation,
13
+ ScheduledBuild,
13
14
  SourceCargoStack,
14
15
  SourceEntityRef,
15
16
  } from './construction-types'
@@ -22,11 +23,12 @@ export class ConstructionManager extends BaseManager {
22
23
  getTarget(
23
24
  entity: ServerContract.Types.entity_row,
24
25
  cargo: ServerContract.Types.cargo_row[],
25
- activeTask?: ServerContract.Types.task
26
+ activeTask?: ServerContract.Types.task,
27
+ scheduledBuild?: ScheduledBuild
26
28
  ): BuildableTarget | null {
27
29
  const kind = entity.kind.toString()
28
30
  if (kind === 'plot') {
29
- return this.plot.buildableTarget(entity, cargo, activeTask)
31
+ return this.plot.buildableTarget(entity, cargo, activeTask, scheduledBuild)
30
32
  }
31
33
  return null
32
34
  }
@@ -140,6 +142,53 @@ export class ConstructionManager extends BaseManager {
140
142
  return out
141
143
  }
142
144
 
145
+ scheduledBuildFor(
146
+ plotId: UInt64,
147
+ entities: ServerContract.Types.entity_info[],
148
+ now: Date
149
+ ): ScheduledBuild | null {
150
+ return this.scheduledBuildsByTarget(entities, now).get(plotId.toString()) ?? null
151
+ }
152
+
153
+ scheduledBuildsByTarget(
154
+ entities: ServerContract.Types.entity_info[],
155
+ now: Date
156
+ ): Map<string, ScheduledBuild> {
157
+ const nowMs = now.getTime()
158
+ const best = new Map<string, ScheduledBuild>()
159
+ for (const entity of entities) {
160
+ const schedule = entity.schedule
161
+ if (!schedule) continue
162
+ const startedMs = schedule.started.toDate().getTime()
163
+ const tasks = schedule.tasks
164
+ let cumulativeSec = 0
165
+ for (let i = 0; i < tasks.length; i++) {
166
+ const task = tasks[i]
167
+ const startSec = cumulativeSec
168
+ cumulativeSec += task.duration.toNumber()
169
+ if (task.type.toNumber() !== TaskType.BUILDPLOT) continue
170
+ if (!task.entitytarget) continue
171
+ const completesAt = startedMs + cumulativeSec * 1000
172
+ if (completesAt < nowMs) continue
173
+ const startsAt = startedMs + startSec * 1000
174
+ const targetId = task.entitytarget.entity_id.toString()
175
+ const candidate: ScheduledBuild = {
176
+ shipId: entity.id,
177
+ shipName: entity.entity_name || entity.id.toString(),
178
+ hasStarted: startsAt <= nowMs,
179
+ startsAt,
180
+ completesAt,
181
+ trailingCancelCount: tasks.length - 1 - i,
182
+ }
183
+ const existing = best.get(targetId)
184
+ if (!existing || candidate.completesAt < existing.completesAt) {
185
+ best.set(targetId, candidate)
186
+ }
187
+ }
188
+ }
189
+ return best
190
+ }
191
+
143
192
  reservationsFrom(
144
193
  sourceEntityId: UInt64,
145
194
  entities: ServerContract.Types.entity_info[]
@@ -27,7 +27,8 @@ export class GameContext {
27
27
  constructor(
28
28
  public readonly client: APIClient,
29
29
  public readonly server: Contract,
30
- public readonly platform: Contract
30
+ public readonly platform: Contract,
31
+ public readonly atomicAssetsAccount: string = 'atomicassets'
31
32
  ) {}
32
33
 
33
34
  get entities(): EntitiesManager {
@@ -20,5 +20,6 @@ export type {
20
20
  FinalizerEntityRef,
21
21
  FinalizerCapability,
22
22
  InboundTransfer,
23
+ ScheduledBuild,
23
24
  Reservation,
24
25
  } from './construction-types'
@@ -1,10 +1,10 @@
1
- import type {UInt16Type} from '@wharfkit/antelope'
1
+ import {BlockTimestamp, type UInt16Type} from '@wharfkit/antelope'
2
2
  import {BaseManager} from './base'
3
3
  import type {CoordinatesType, Distance} from '../types'
4
4
  import {hasSystem} from '../utils/system'
5
5
  import {findNearbyPlanets} from '../travel/travel'
6
6
  import type {ServerContract} from '../contracts'
7
- import {type DerivedStratum, deriveStrata} from '../derivation'
7
+ import {type DerivedStratum, deriveStrata, getEffectiveReserve} from '../derivation'
8
8
 
9
9
  export interface LocationStratum extends DerivedStratum {
10
10
  reserveMax: number
@@ -24,7 +24,10 @@ export class LocationsManager extends BaseManager {
24
24
  return findNearbyPlanets(game.config.seed, origin, maxDistance)
25
25
  }
26
26
 
27
- async getStrata(coords: CoordinatesType): Promise<LocationStratum[]> {
27
+ async getStrata(
28
+ coords: CoordinatesType,
29
+ now: BlockTimestamp = BlockTimestamp.fromMilliseconds(Date.now())
30
+ ): Promise<LocationStratum[]> {
28
31
  const game = await this.getGame()
29
32
  const state = await this.getState()
30
33
 
@@ -36,15 +39,26 @@ export class LocationsManager extends BaseManager {
36
39
  y: coords.y,
37
40
  })) as ServerContract.Types.stratum_remaining[]
38
41
 
39
- const overrideMap = new Map<number, number>()
42
+ const epochSeconds = Number(game.config.epochtime)
43
+ const overrideMap = new Map<number, ServerContract.Types.stratum_remaining>()
40
44
  for (const o of overrides) {
41
- overrideMap.set(Number(o.stratum), Number(o.remaining))
45
+ overrideMap.set(Number(o.stratum), o)
42
46
  }
43
47
 
44
- return derived.map((s) => ({
45
- ...s,
46
- reserveMax: s.reserve,
47
- reserve: overrideMap.get(s.index) ?? s.reserve,
48
- }))
48
+ return derived.map((s) => {
49
+ const override = overrideMap.get(s.index)
50
+ const reserve = override
51
+ ? getEffectiveReserve(
52
+ {
53
+ remaining: override.remaining,
54
+ max_reserve: s.reserve,
55
+ last_block: override.last_block,
56
+ },
57
+ now,
58
+ epochSeconds
59
+ )
60
+ : s.reserve
61
+ return {...s, reserveMax: s.reserve, reserve}
62
+ })
49
63
  }
50
64
  }
@@ -6,7 +6,7 @@ import {calc_craft_duration} from '../capabilities/crafting'
6
6
  import {TaskType} from '../types'
7
7
  import {BaseManager} from './base'
8
8
  import type {ServerContract} from '../contracts'
9
- import type {BuildableTarget} from './construction-types'
9
+ import type {BuildableTarget, ScheduledBuild} from './construction-types'
10
10
 
11
11
  export interface PlotProgressInputRow {
12
12
  itemId: number
@@ -67,7 +67,8 @@ export class PlotManager extends BaseManager {
67
67
  buildableTarget(
68
68
  plot: ServerContract.Types.entity_row,
69
69
  cargo: ServerContract.Types.cargo_row[],
70
- activeTask?: ServerContract.Types.task
70
+ activeTask?: ServerContract.Types.task,
71
+ scheduledBuild?: ScheduledBuild
71
72
  ): BuildableTarget {
72
73
  const progress = this.progress(plot, cargo)
73
74
  const targetItemId = Number(plot.item_id.toString())
@@ -79,10 +80,12 @@ export class PlotManager extends BaseManager {
79
80
 
80
81
  let state: BuildableTarget['state']
81
82
  const taskType = activeTask?.type.toNumber()
82
- if (taskType === TaskType.CLAIMPLOT) {
83
- state = 'initializing'
84
- } else if (taskType === TaskType.BUILDPLOT) {
83
+ if (scheduledBuild?.hasStarted) {
85
84
  state = 'finalizing'
85
+ } else if (scheduledBuild) {
86
+ state = 'scheduled'
87
+ } else if (taskType === TaskType.CLAIMPLOT) {
88
+ state = 'initializing'
86
89
  } else if (progress.isComplete) {
87
90
  state = 'ready'
88
91
  } else {
@@ -101,6 +104,7 @@ export class PlotManager extends BaseManager {
101
104
  finalizeAction: Name.from('buildplot'),
102
105
  finalizerCapability: 'crafter',
103
106
  activeTask,
107
+ scheduledBuild,
104
108
  }
105
109
  }
106
110