@shipload/sdk 1.0.0-next.4 → 1.0.0-next.40
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.d.ts +2473 -973
- package/lib/shipload.js +11529 -5211
- package/lib/shipload.js.map +1 -1
- package/lib/shipload.m.js +11338 -5162
- package/lib/shipload.m.js.map +1 -1
- package/lib/testing.d.ts +970 -0
- package/lib/testing.js +4013 -0
- package/lib/testing.js.map +1 -0
- package/lib/testing.m.js +4007 -0
- package/lib/testing.m.js.map +1 -0
- package/package.json +15 -2
- package/src/capabilities/craftable.ts +51 -0
- package/src/capabilities/crafting.test.ts +7 -0
- package/src/capabilities/crafting.ts +5 -6
- package/src/capabilities/gathering.test.ts +16 -0
- package/src/capabilities/gathering.ts +35 -18
- package/src/capabilities/index.ts +0 -1
- package/src/capabilities/modules.ts +9 -0
- package/src/capabilities/storage.ts +16 -1
- package/src/contracts/platform.ts +231 -3
- package/src/contracts/server.ts +1021 -481
- package/src/coordinates/address.ts +88 -0
- package/src/coordinates/constants.test.ts +15 -0
- package/src/coordinates/constants.ts +23 -0
- package/src/coordinates/index.ts +15 -0
- package/src/coordinates/memo.test.ts +47 -0
- package/src/coordinates/memo.ts +20 -0
- package/src/coordinates/permutation.ts +77 -0
- package/src/coordinates/regions.ts +48 -0
- package/src/coordinates/sectors.ts +115 -0
- package/src/data/capabilities.ts +12 -5
- package/src/data/capability-formulas.ts +14 -7
- package/src/data/catalog.ts +0 -5
- package/src/data/colors.ts +14 -47
- package/src/data/entities.json +76 -10
- package/src/data/item-ids.ts +18 -12
- package/src/data/items.json +321 -38
- package/src/data/kind-registry.json +109 -0
- package/src/data/kind-registry.ts +165 -0
- package/src/data/metadata.ts +119 -33
- package/src/data/recipes-runtime.ts +3 -23
- package/src/data/recipes.json +238 -117
- package/src/derivation/build-methods.ts +45 -0
- package/src/derivation/capabilities.test.ts +151 -0
- package/src/derivation/capabilities.ts +512 -0
- package/src/derivation/capability-mappings.ts +9 -12
- package/src/derivation/crafting.ts +23 -24
- package/src/derivation/index.ts +25 -2
- package/src/derivation/recipe-usage.test.ts +78 -0
- package/src/derivation/recipe-usage.ts +141 -0
- package/src/derivation/reserve-regen.ts +34 -0
- package/src/derivation/resources.ts +125 -38
- package/src/derivation/rollups.test.ts +55 -0
- package/src/derivation/rollups.ts +56 -0
- package/src/derivation/stars.test.ts +51 -0
- package/src/derivation/stars.ts +15 -0
- package/src/derivation/stats.ts +6 -6
- package/src/derivation/stratum.ts +17 -20
- package/src/derivation/tiers.ts +40 -7
- package/src/derivation/wormhole.ts +136 -0
- package/src/entities/entity.ts +98 -0
- package/src/entities/gamestate.ts +3 -28
- package/src/entities/makers.ts +124 -134
- package/src/entities/slot-multiplier.ts +43 -0
- package/src/errors.ts +12 -16
- package/src/format.ts +26 -4
- package/src/index-module.ts +267 -47
- package/src/managers/actions.ts +528 -95
- package/src/managers/base.ts +6 -2
- package/src/managers/construction-types.ts +80 -0
- package/src/managers/construction.ts +412 -0
- package/src/managers/context.ts +20 -1
- package/src/managers/coordinates.ts +14 -0
- package/src/managers/entities.ts +18 -66
- package/src/managers/epochs.ts +40 -0
- package/src/managers/index.ts +17 -1
- package/src/managers/locations.ts +25 -29
- package/src/managers/nft.test.ts +14 -0
- package/src/managers/nft.ts +70 -0
- package/src/managers/plot.ts +122 -0
- package/src/nft/atomicassets.abi.json +1342 -0
- package/src/nft/atomicassets.ts +237 -0
- package/src/nft/atomicdata.ts +130 -0
- package/src/nft/buildImmutableData.ts +338 -0
- package/src/nft/description.ts +98 -24
- package/src/nft/index.ts +3 -0
- package/src/planner/index.ts +127 -0
- package/src/planner/planner.test.ts +319 -0
- package/src/resolution/describe-module.ts +18 -13
- package/src/resolution/display-name.ts +38 -10
- package/src/resolution/resolve-item.test.ts +37 -0
- package/src/resolution/resolve-item.ts +55 -24
- package/src/scheduling/accessor.ts +68 -22
- package/src/scheduling/availability.ts +108 -0
- package/src/scheduling/cancel.test.ts +348 -0
- package/src/scheduling/cancel.ts +209 -0
- package/src/scheduling/energy.ts +47 -0
- package/src/scheduling/idle-resolve.ts +45 -0
- package/src/scheduling/lane-core.ts +128 -0
- package/src/scheduling/lanes.test.ts +249 -0
- package/src/scheduling/lanes.ts +198 -0
- package/src/scheduling/projection.ts +209 -105
- package/src/scheduling/schedule.ts +241 -104
- package/src/scheduling/task-cargo.ts +46 -0
- package/src/shipload.ts +21 -1
- package/src/subscriptions/manager.ts +229 -142
- package/src/subscriptions/mappers.ts +5 -8
- package/src/subscriptions/types.ts +11 -3
- package/src/testing/catalog-hash.ts +19 -0
- package/src/testing/index.ts +2 -0
- package/src/testing/projection-parity.ts +167 -0
- package/src/travel/reach.ts +23 -0
- package/src/travel/route-planner.ts +196 -0
- package/src/travel/travel.ts +200 -112
- package/src/types/capabilities.ts +29 -6
- package/src/types/entity.ts +3 -3
- package/src/types/index.ts +0 -1
- package/src/types.ts +28 -13
- package/src/utils/cargo.ts +27 -0
- package/src/utils/display-name.ts +70 -0
- package/src/utils/system.ts +36 -24
- package/src/capabilities/loading.ts +0 -8
- package/src/entities/container.ts +0 -108
- package/src/entities/ship-deploy.ts +0 -259
- package/src/entities/ship.ts +0 -204
- package/src/entities/warehouse.ts +0 -119
- package/src/types/entity-traits.ts +0 -69
package/src/managers/actions.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
Action,
|
|
3
|
+
Checksum256,
|
|
4
|
+
type Checksum256Type,
|
|
3
5
|
Int64,
|
|
6
|
+
type Int64Type,
|
|
4
7
|
Name,
|
|
5
8
|
type NameType,
|
|
9
|
+
Transaction,
|
|
10
|
+
UInt8,
|
|
11
|
+
type UInt8Type,
|
|
6
12
|
UInt16,
|
|
7
13
|
type UInt16Type,
|
|
8
14
|
UInt32,
|
|
@@ -11,11 +17,147 @@ import {
|
|
|
11
17
|
type UInt64Type,
|
|
12
18
|
} from '@wharfkit/antelope'
|
|
13
19
|
import {BaseManager} from './base'
|
|
14
|
-
import {
|
|
20
|
+
import {Coordinates, PRECISION, type CoordinatesType} from '../types'
|
|
15
21
|
import {ServerContract} from '../contracts'
|
|
22
|
+
import {ATOMICASSETS_ABI, SHIPLOAD_COLLECTION} from '../nft/atomicassets'
|
|
23
|
+
import {getItem} from '../data/catalog'
|
|
24
|
+
|
|
25
|
+
const CHARGE_K = 1n
|
|
26
|
+
const ENERGY_DIVISOR = 1_000_000n
|
|
27
|
+
const UINT32_MAX = 4_294_967_295
|
|
28
|
+
const UINT32_MAX_BIGINT = 4_294_967_295n
|
|
29
|
+
const UINT32_MOD = 4_294_967_296n
|
|
30
|
+
const UINT64_MAX = 18_446_744_073_709_551_615n
|
|
31
|
+
const PRECISION_BIGINT = BigInt(PRECISION)
|
|
32
|
+
|
|
33
|
+
export type LaunchNumericInput =
|
|
34
|
+
| number
|
|
35
|
+
| bigint
|
|
36
|
+
| string
|
|
37
|
+
| {toNumber(): number}
|
|
38
|
+
| {toString(): string}
|
|
39
|
+
|
|
40
|
+
export interface LaunchStatsInput {
|
|
41
|
+
charge_rate?: LaunchNumericInput
|
|
42
|
+
chargeRate?: LaunchNumericInput
|
|
43
|
+
velocity: LaunchNumericInput
|
|
44
|
+
drain: LaunchNumericInput
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface LaunchQuoteLauncher {
|
|
48
|
+
coordinates: CoordinatesType
|
|
49
|
+
launcher: LaunchStatsInput
|
|
50
|
+
generator?: {capacity: LaunchNumericInput}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface LaunchQuoteCatcher {
|
|
54
|
+
coordinates: CoordinatesType
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface LaunchQuote {
|
|
58
|
+
chargeTime: number
|
|
59
|
+
flightTime: number
|
|
60
|
+
arrival: Date
|
|
61
|
+
energyCost: number
|
|
62
|
+
maxReach: bigint
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function toNumber(value: LaunchNumericInput): number {
|
|
66
|
+
if (typeof value === 'number') return Math.trunc(value)
|
|
67
|
+
if (typeof value === 'bigint') return Number(value)
|
|
68
|
+
if (typeof value === 'string') return Number(value)
|
|
69
|
+
if ('toNumber' in value && typeof value.toNumber === 'function') return value.toNumber()
|
|
70
|
+
return Number(value.toString())
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function requiredNumber(value: LaunchNumericInput | undefined, label: string): number {
|
|
74
|
+
if (value === undefined) throw new Error(`launch quote requires ${label}`)
|
|
75
|
+
return toNumber(value)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function toBigInt(value: LaunchNumericInput | undefined): bigint {
|
|
79
|
+
if (value === undefined) return 0n
|
|
80
|
+
if (typeof value === 'bigint') return value
|
|
81
|
+
if (typeof value === 'number') return BigInt(Math.trunc(value))
|
|
82
|
+
if (typeof value === 'string') return BigInt(value)
|
|
83
|
+
return BigInt(value.toString())
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function saturatingMul(lhs: bigint, rhs: bigint): bigint {
|
|
87
|
+
if (lhs !== 0n && rhs > UINT64_MAX / lhs) {
|
|
88
|
+
return UINT64_MAX
|
|
89
|
+
}
|
|
90
|
+
return lhs * rhs
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function clampLaunchResult(value: bigint): number {
|
|
94
|
+
if (value < 1n) return 1
|
|
95
|
+
if (value > UINT32_MAX_BIGINT) return UINT32_MAX
|
|
96
|
+
return Number(value)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function toUint32(value: bigint): bigint {
|
|
100
|
+
return value % UINT32_MOD
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function calcDistance(origin: CoordinatesType, destination: CoordinatesType): bigint {
|
|
104
|
+
const a = Coordinates.from(origin)
|
|
105
|
+
const b = Coordinates.from(destination)
|
|
106
|
+
const dx = toNumber(a.x) - toNumber(b.x)
|
|
107
|
+
const dy = toNumber(a.y) - toNumber(b.y)
|
|
108
|
+
return BigInt(Math.trunc(Math.sqrt(dx * dx + dy * dy) * PRECISION))
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function calcCargoItemMassUint32(item: ServerContract.ActionParams.Type.cargo_item): bigint {
|
|
112
|
+
let mass = toUint32(BigInt(getItem(item.item_id).mass) * toUint32(toBigInt(item.quantity)))
|
|
113
|
+
|
|
114
|
+
for (const mod of item.modules) {
|
|
115
|
+
if (mod.installed) {
|
|
116
|
+
mass = toUint32(mass + BigInt(getItem(mod.installed.item_id).mass))
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return mass
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function calcPayloadMass(items: ServerContract.ActionParams.Type.cargo_item[]): bigint {
|
|
124
|
+
let mass = 0n
|
|
125
|
+
for (const item of items) {
|
|
126
|
+
mass = toUint32(mass + calcCargoItemMassUint32(item))
|
|
127
|
+
}
|
|
128
|
+
return mass
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function calcChargeTime(chargeRate: number, mass: bigint): number {
|
|
132
|
+
const rate = BigInt(chargeRate || 1)
|
|
133
|
+
return clampLaunchResult((mass * CHARGE_K) / rate)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function calcFlightTime(velocity: number, distance: bigint): number {
|
|
137
|
+
const v = BigInt(velocity || 1)
|
|
138
|
+
return clampLaunchResult(distance / (v * PRECISION_BIGINT))
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function calcLaunchEnergy(drain: number, mass: bigint, distance: bigint): number {
|
|
142
|
+
const e =
|
|
143
|
+
saturatingMul(saturatingMul(mass, distance / PRECISION_BIGINT), BigInt(drain)) /
|
|
144
|
+
ENERGY_DIVISOR
|
|
145
|
+
return clampLaunchResult(e)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function calcMaxReach(energyBudget: bigint, mass: bigint, drain: number): bigint {
|
|
149
|
+
if (energyBudget < 1n) return 0n
|
|
150
|
+
if (energyBudget >= UINT32_MAX_BIGINT || mass === 0n || drain === 0) return UINT64_MAX
|
|
151
|
+
|
|
152
|
+
const numerator = (energyBudget + 1n) * ENERGY_DIVISOR - 1n
|
|
153
|
+
const denominator = mass * BigInt(drain)
|
|
154
|
+
const distanceUnits = numerator / denominator
|
|
155
|
+
const maxDistance = distanceUnits * PRECISION_BIGINT + (PRECISION_BIGINT - 1n)
|
|
156
|
+
return maxDistance > UINT64_MAX ? UINT64_MAX : maxDistance
|
|
157
|
+
}
|
|
16
158
|
|
|
17
159
|
export type EntityRefInput = {
|
|
18
|
-
entityType:
|
|
160
|
+
entityType: NameType
|
|
19
161
|
entityId: UInt64Type
|
|
20
162
|
}
|
|
21
163
|
|
|
@@ -25,7 +167,6 @@ export class ActionsManager extends BaseManager {
|
|
|
25
167
|
const y = Int64.from(destination.y)
|
|
26
168
|
|
|
27
169
|
return this.server.action('travel', {
|
|
28
|
-
entity_type: EntityType.SHIP,
|
|
29
170
|
id: UInt64.from(shipId),
|
|
30
171
|
x,
|
|
31
172
|
y,
|
|
@@ -33,13 +174,17 @@ export class ActionsManager extends BaseManager {
|
|
|
33
174
|
})
|
|
34
175
|
}
|
|
35
176
|
|
|
36
|
-
|
|
37
|
-
|
|
177
|
+
private entityRefs(entities: EntityRefInput[]) {
|
|
178
|
+
return entities.map((e) =>
|
|
38
179
|
ServerContract.Types.entity_ref.from({
|
|
39
180
|
entity_type: e.entityType,
|
|
40
181
|
entity_id: UInt64.from(e.entityId),
|
|
41
182
|
})
|
|
42
183
|
)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
grouptravel(entities: EntityRefInput[], destination: CoordinatesType, recharge = true): Action {
|
|
187
|
+
const entityRefs = this.entityRefs(entities)
|
|
43
188
|
const x = Int64.from(destination.x)
|
|
44
189
|
const y = Int64.from(destination.y)
|
|
45
190
|
|
|
@@ -51,13 +196,46 @@ export class ActionsManager extends BaseManager {
|
|
|
51
196
|
})
|
|
52
197
|
}
|
|
53
198
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
199
|
+
transit(shipId: UInt64Type, entrance: CoordinatesType, exit: CoordinatesType): Action {
|
|
200
|
+
return this.server.action('transit', {
|
|
201
|
+
id: UInt64.from(shipId),
|
|
202
|
+
ax: Int64.from(entrance.x),
|
|
203
|
+
ay: Int64.from(entrance.y),
|
|
204
|
+
bx: Int64.from(exit.x),
|
|
205
|
+
by: Int64.from(exit.y),
|
|
206
|
+
})
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
grouptransit(
|
|
210
|
+
entities: EntityRefInput[],
|
|
211
|
+
entrance: CoordinatesType,
|
|
212
|
+
exit: CoordinatesType
|
|
58
213
|
): Action {
|
|
214
|
+
const entityRefs = this.entityRefs(entities)
|
|
215
|
+
return this.server.action('grouptransit', {
|
|
216
|
+
entities: entityRefs,
|
|
217
|
+
ax: Int64.from(entrance.x),
|
|
218
|
+
ay: Int64.from(entrance.y),
|
|
219
|
+
bx: Int64.from(exit.x),
|
|
220
|
+
by: Int64.from(exit.y),
|
|
221
|
+
})
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
getwormhole(x: Int64Type, y: Int64Type): Action {
|
|
225
|
+
return this.server.action('getwormhole', {x: Int64.from(x), y: Int64.from(y)})
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
getdistance(origin: CoordinatesType, destination: CoordinatesType): Action {
|
|
229
|
+
return this.server.action('getdistance', {
|
|
230
|
+
ax: Int64.from(origin.x),
|
|
231
|
+
ay: Int64.from(origin.y),
|
|
232
|
+
bx: Int64.from(destination.x),
|
|
233
|
+
by: Int64.from(destination.y),
|
|
234
|
+
})
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
resolve(entityId: UInt64Type, count?: UInt64Type): Action {
|
|
59
238
|
const params: ServerContract.ActionParams.resolve = {
|
|
60
|
-
entity_type: entityType,
|
|
61
239
|
id: UInt64.from(entityId),
|
|
62
240
|
}
|
|
63
241
|
if (count !== undefined) {
|
|
@@ -66,45 +244,103 @@ export class ActionsManager extends BaseManager {
|
|
|
66
244
|
return this.server.action('resolve', params)
|
|
67
245
|
}
|
|
68
246
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
247
|
+
resolveall(owner: NameType): Action {
|
|
248
|
+
return this.server.action('resolveall', {
|
|
249
|
+
owner: Name.from(owner),
|
|
250
|
+
})
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
cancel(entityId: UInt64Type, laneKey: number, count: UInt64Type): Action {
|
|
74
254
|
return this.server.action('cancel', {
|
|
75
|
-
entity_type: entityType,
|
|
76
255
|
id: UInt64.from(entityId),
|
|
256
|
+
lane_key: UInt8.from(laneKey),
|
|
77
257
|
count: UInt64.from(count),
|
|
78
258
|
})
|
|
79
259
|
}
|
|
80
260
|
|
|
81
|
-
recharge(entityId: UInt64Type
|
|
261
|
+
recharge(entityId: UInt64Type): Action {
|
|
82
262
|
return this.server.action('recharge', {
|
|
83
|
-
entity_type: entityType,
|
|
84
263
|
id: UInt64.from(entityId),
|
|
85
264
|
})
|
|
86
265
|
}
|
|
87
266
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
267
|
+
rename(entityId: UInt64Type, name: string): Action {
|
|
268
|
+
return this.server.action('rename', {
|
|
269
|
+
id: UInt64.from(entityId),
|
|
270
|
+
name,
|
|
271
|
+
})
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
refrshentity(entityId: UInt64Type): Action {
|
|
275
|
+
return this.server.action('refrshentity', {
|
|
276
|
+
entity_id: UInt64.from(entityId),
|
|
277
|
+
})
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
load(
|
|
281
|
+
id: UInt64Type,
|
|
282
|
+
fromId: UInt64Type,
|
|
283
|
+
items: ServerContract.ActionParams.Type.cargo_item[]
|
|
96
284
|
): Action {
|
|
97
|
-
return this.server.action('
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
dest_id: UInt64.from(destId),
|
|
102
|
-
item_id: UInt16.from(itemId),
|
|
103
|
-
stats: UInt64.from(stats),
|
|
104
|
-
quantity: UInt32.from(quantity),
|
|
285
|
+
return this.server.action('load', {
|
|
286
|
+
id: UInt64.from(id),
|
|
287
|
+
from_id: UInt64.from(fromId),
|
|
288
|
+
items,
|
|
105
289
|
})
|
|
106
290
|
}
|
|
107
291
|
|
|
292
|
+
unload(
|
|
293
|
+
id: UInt64Type,
|
|
294
|
+
toId: UInt64Type,
|
|
295
|
+
items: ServerContract.ActionParams.Type.cargo_item[]
|
|
296
|
+
): Action {
|
|
297
|
+
return this.server.action('unload', {
|
|
298
|
+
id: UInt64.from(id),
|
|
299
|
+
to_id: UInt64.from(toId),
|
|
300
|
+
items,
|
|
301
|
+
})
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
launch(
|
|
305
|
+
launcherId: UInt64Type,
|
|
306
|
+
catcherId: UInt64Type,
|
|
307
|
+
items: ServerContract.ActionParams.Type.cargo_item[]
|
|
308
|
+
): Action {
|
|
309
|
+
return this.server.action('launch', {
|
|
310
|
+
launcher_id: UInt64.from(launcherId),
|
|
311
|
+
catcher_id: UInt64.from(catcherId),
|
|
312
|
+
items,
|
|
313
|
+
})
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
getLaunchQuote(
|
|
317
|
+
launcher: LaunchQuoteLauncher,
|
|
318
|
+
catcher: LaunchQuoteCatcher,
|
|
319
|
+
items: ServerContract.ActionParams.Type.cargo_item[],
|
|
320
|
+
start = new Date()
|
|
321
|
+
): LaunchQuote {
|
|
322
|
+
const chargeRate = requiredNumber(
|
|
323
|
+
launcher.launcher.charge_rate ?? launcher.launcher.chargeRate,
|
|
324
|
+
'launcher charge rate'
|
|
325
|
+
)
|
|
326
|
+
const velocity = requiredNumber(launcher.launcher.velocity, 'launcher velocity')
|
|
327
|
+
const drain = requiredNumber(launcher.launcher.drain, 'launcher drain')
|
|
328
|
+
const mass = calcPayloadMass(items)
|
|
329
|
+
const distance = calcDistance(launcher.coordinates, catcher.coordinates)
|
|
330
|
+
const chargeTime = calcChargeTime(chargeRate, mass)
|
|
331
|
+
const flightTime = calcFlightTime(velocity, distance)
|
|
332
|
+
const energyCost = calcLaunchEnergy(drain, mass, distance)
|
|
333
|
+
const maxReach = calcMaxReach(toBigInt(launcher.generator?.capacity), mass, drain)
|
|
334
|
+
|
|
335
|
+
return {
|
|
336
|
+
chargeTime,
|
|
337
|
+
flightTime,
|
|
338
|
+
arrival: new Date(start.getTime() + (chargeTime + flightTime) * 1000),
|
|
339
|
+
energyCost,
|
|
340
|
+
maxReach,
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
108
344
|
foundCompany(account: NameType, name: string): Action {
|
|
109
345
|
return this.platform.action('foundcompany', {
|
|
110
346
|
account: Name.from(account),
|
|
@@ -119,35 +355,50 @@ export class ActionsManager extends BaseManager {
|
|
|
119
355
|
}
|
|
120
356
|
|
|
121
357
|
gather(
|
|
122
|
-
|
|
123
|
-
|
|
358
|
+
sourceId: UInt64Type,
|
|
359
|
+
destinationId: UInt64Type,
|
|
124
360
|
stratum: UInt16Type,
|
|
125
|
-
quantity: UInt32Type
|
|
361
|
+
quantity: UInt32Type,
|
|
362
|
+
slot?: UInt8Type
|
|
126
363
|
): Action {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
entity_id: UInt64.from(source.entityId),
|
|
131
|
-
}),
|
|
132
|
-
destination: ServerContract.Types.entity_ref.from({
|
|
133
|
-
entity_type: destination.entityType,
|
|
134
|
-
entity_id: UInt64.from(destination.entityId),
|
|
135
|
-
}),
|
|
364
|
+
const params: ServerContract.ActionParams.gather = {
|
|
365
|
+
source_id: UInt64.from(sourceId),
|
|
366
|
+
destination_id: UInt64.from(destinationId),
|
|
136
367
|
stratum: UInt16.from(stratum),
|
|
137
368
|
quantity: UInt32.from(quantity),
|
|
369
|
+
}
|
|
370
|
+
if (slot !== undefined) {
|
|
371
|
+
params.slot = UInt8.from(slot)
|
|
372
|
+
}
|
|
373
|
+
return this.server.action('gather', params)
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Packs N gather actions into one Transaction; the wallet/session fills in TAPoS at sign time.
|
|
377
|
+
bundleGather(
|
|
378
|
+
gathers: {
|
|
379
|
+
sourceId: UInt64Type
|
|
380
|
+
destinationId: UInt64Type
|
|
381
|
+
stratum: UInt16Type
|
|
382
|
+
quantity: UInt32Type
|
|
383
|
+
slot?: UInt8Type
|
|
384
|
+
}[]
|
|
385
|
+
): Transaction {
|
|
386
|
+
const actions = gathers.map(({sourceId, destinationId, stratum, quantity, slot}) =>
|
|
387
|
+
this.gather(sourceId, destinationId, stratum, quantity, slot)
|
|
388
|
+
)
|
|
389
|
+
return Transaction.from({
|
|
390
|
+
expiration: 0,
|
|
391
|
+
ref_block_num: 0,
|
|
392
|
+
ref_block_prefix: 0,
|
|
393
|
+
actions,
|
|
138
394
|
})
|
|
139
395
|
}
|
|
140
396
|
|
|
141
|
-
warp(
|
|
142
|
-
entityId: UInt64Type,
|
|
143
|
-
destination: CoordinatesType,
|
|
144
|
-
entityType: EntityTypeName = EntityType.SHIP
|
|
145
|
-
): Action {
|
|
397
|
+
warp(entityId: UInt64Type, destination: CoordinatesType): Action {
|
|
146
398
|
const x = Int64.from(destination.x)
|
|
147
399
|
const y = Int64.from(destination.y)
|
|
148
400
|
|
|
149
401
|
return this.server.action('warp', {
|
|
150
|
-
entity_type: entityType,
|
|
151
402
|
id: UInt64.from(entityId),
|
|
152
403
|
x,
|
|
153
404
|
y,
|
|
@@ -155,96 +406,278 @@ export class ActionsManager extends BaseManager {
|
|
|
155
406
|
}
|
|
156
407
|
|
|
157
408
|
craft(
|
|
158
|
-
entityType: EntityTypeName,
|
|
159
409
|
entityId: UInt64Type,
|
|
160
410
|
recipeId: number,
|
|
161
411
|
quantity: number,
|
|
162
|
-
inputs: ServerContract.ActionParams.Type.cargo_item[]
|
|
412
|
+
inputs: ServerContract.ActionParams.Type.cargo_item[],
|
|
413
|
+
target?: UInt64Type,
|
|
414
|
+
slot?: UInt8Type
|
|
163
415
|
): Action {
|
|
164
|
-
const
|
|
165
|
-
return this.server.action('craft', {
|
|
166
|
-
entity_type: entityType,
|
|
416
|
+
const params: ServerContract.ActionParams.craft = {
|
|
167
417
|
id: UInt64.from(entityId),
|
|
168
418
|
recipe_id: UInt16.from(recipeId),
|
|
169
419
|
quantity: UInt32.from(quantity),
|
|
170
|
-
inputs
|
|
171
|
-
}
|
|
420
|
+
inputs,
|
|
421
|
+
}
|
|
422
|
+
if (target !== undefined) {
|
|
423
|
+
params.target = UInt64.from(target)
|
|
424
|
+
}
|
|
425
|
+
if (slot !== undefined) {
|
|
426
|
+
params.slot = UInt8.from(slot)
|
|
427
|
+
}
|
|
428
|
+
return this.server.action('craft', params)
|
|
172
429
|
}
|
|
173
430
|
|
|
174
|
-
blend(
|
|
175
|
-
entityType: EntityTypeName,
|
|
176
|
-
entityId: UInt64Type,
|
|
177
|
-
inputs: ServerContract.ActionParams.Type.cargo_item[]
|
|
178
|
-
): Action {
|
|
179
|
-
const cargoInputs = inputs.map((i) => ServerContract.Types.cargo_item.from(i))
|
|
431
|
+
blend(entityId: UInt64Type, inputs: ServerContract.ActionParams.Type.cargo_item[]): Action {
|
|
180
432
|
return this.server.action('blend', {
|
|
181
|
-
entity_type: entityType,
|
|
182
433
|
id: UInt64.from(entityId),
|
|
183
|
-
inputs
|
|
434
|
+
inputs,
|
|
184
435
|
})
|
|
185
436
|
}
|
|
186
437
|
|
|
187
|
-
deploy(
|
|
188
|
-
entityType: EntityTypeName,
|
|
189
|
-
entityId: UInt64Type,
|
|
190
|
-
packedItemId: number,
|
|
191
|
-
stats: bigint
|
|
192
|
-
): Action {
|
|
438
|
+
deploy(entityId: UInt64Type, ref: ServerContract.ActionParams.Type.cargo_ref): Action {
|
|
193
439
|
return this.server.action('deploy', {
|
|
194
|
-
entity_type: entityType,
|
|
195
440
|
id: UInt64.from(entityId),
|
|
196
|
-
|
|
197
|
-
|
|
441
|
+
ref,
|
|
442
|
+
})
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
claimplot(
|
|
446
|
+
entityId: UInt64Type,
|
|
447
|
+
targetItemId: UInt16Type,
|
|
448
|
+
coords: ServerContract.ActionParams.Type.coordinates
|
|
449
|
+
): Action {
|
|
450
|
+
return this.server.action('claimplot', {
|
|
451
|
+
builder_id: UInt64.from(entityId),
|
|
452
|
+
target_item_id: UInt16.from(targetItemId),
|
|
453
|
+
coords,
|
|
454
|
+
})
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
buildplot(entityId: UInt64Type, plotId: UInt64Type): Action {
|
|
458
|
+
return this.server.action('buildplot', {
|
|
459
|
+
builder_id: UInt64.from(entityId),
|
|
460
|
+
plot_id: UInt64.from(plotId),
|
|
198
461
|
})
|
|
199
462
|
}
|
|
200
463
|
|
|
201
464
|
addmodule(
|
|
202
|
-
entityType: EntityTypeName,
|
|
203
465
|
entityId: UInt64Type,
|
|
204
466
|
moduleIndex: number,
|
|
205
|
-
|
|
206
|
-
|
|
467
|
+
moduleRef: ServerContract.ActionParams.Type.cargo_ref,
|
|
468
|
+
targetRef: ServerContract.ActionParams.Type.cargo_ref | null = null
|
|
207
469
|
): Action {
|
|
208
470
|
return this.server.action('addmodule', {
|
|
209
|
-
entity_type: entityType,
|
|
210
471
|
entity_id: UInt64.from(entityId),
|
|
211
472
|
module_index: moduleIndex,
|
|
212
|
-
|
|
213
|
-
|
|
473
|
+
module_ref: moduleRef,
|
|
474
|
+
target_ref: targetRef ?? undefined,
|
|
214
475
|
})
|
|
215
476
|
}
|
|
216
477
|
|
|
217
478
|
rmmodule(
|
|
218
|
-
entityType: EntityTypeName,
|
|
219
479
|
entityId: UInt64Type,
|
|
220
480
|
moduleIndex: number,
|
|
221
|
-
|
|
481
|
+
targetRef: ServerContract.ActionParams.Type.cargo_ref | null = null
|
|
222
482
|
): Action {
|
|
223
483
|
return this.server.action('rmmodule', {
|
|
224
|
-
entity_type: entityType,
|
|
225
484
|
entity_id: UInt64.from(entityId),
|
|
226
485
|
module_index: moduleIndex,
|
|
227
|
-
|
|
486
|
+
target_ref: targetRef ?? undefined,
|
|
487
|
+
})
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
swapmodule(
|
|
491
|
+
entityId: UInt64Type,
|
|
492
|
+
moduleIndex: number,
|
|
493
|
+
moduleRef: ServerContract.ActionParams.Type.cargo_ref
|
|
494
|
+
): Action {
|
|
495
|
+
return this.server.action('swapmodule', {
|
|
496
|
+
entity_id: UInt64.from(entityId),
|
|
497
|
+
module_index: moduleIndex,
|
|
498
|
+
module_ref: moduleRef,
|
|
228
499
|
})
|
|
229
500
|
}
|
|
230
501
|
|
|
231
|
-
wrap(
|
|
502
|
+
async wrap(
|
|
232
503
|
owner: NameType,
|
|
233
|
-
entityType: EntityTypeName,
|
|
234
504
|
entityId: UInt64Type,
|
|
505
|
+
nexusId: UInt64Type,
|
|
235
506
|
cargoId: UInt64Type,
|
|
236
|
-
quantity: UInt64Type
|
|
237
|
-
|
|
238
|
-
|
|
507
|
+
quantity: UInt64Type,
|
|
508
|
+
opts: {claimRam?: boolean} = {}
|
|
509
|
+
): Promise<Action[]> {
|
|
510
|
+
const actions: Action[] = [
|
|
511
|
+
this.platform.action('wrapcargo', {
|
|
512
|
+
game: this.server.account,
|
|
513
|
+
owner: Name.from(owner),
|
|
514
|
+
entity_id: UInt64.from(entityId),
|
|
515
|
+
nexus_id: UInt64.from(nexusId),
|
|
516
|
+
cargo_id: UInt64.from(cargoId),
|
|
517
|
+
quantity: UInt64.from(quantity),
|
|
518
|
+
}),
|
|
519
|
+
]
|
|
520
|
+
const claimRam =
|
|
521
|
+
opts.claimRam ?? (this.atomicAssetsAccount ?? 'atomicassets') !== 'atomicassets'
|
|
522
|
+
if (claimRam) {
|
|
523
|
+
actions.push(this.setLastPayer(owner, SHIPLOAD_COLLECTION))
|
|
524
|
+
}
|
|
525
|
+
return actions
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
undeploy(hostId: UInt64Type, targetId: UInt64Type): Action {
|
|
529
|
+
return this.server.action('undeploy', {
|
|
530
|
+
host_id: UInt64.from(hostId),
|
|
531
|
+
target_id: UInt64.from(targetId),
|
|
532
|
+
})
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
claimStarter(owner: NameType): Action {
|
|
536
|
+
return this.server.action('claimstarter', {
|
|
239
537
|
owner: Name.from(owner),
|
|
240
|
-
|
|
538
|
+
})
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
async wrapEntity(
|
|
542
|
+
owner: NameType,
|
|
543
|
+
entityId: UInt64Type,
|
|
544
|
+
nexusId: UInt64Type,
|
|
545
|
+
opts: {claimRam?: boolean} = {}
|
|
546
|
+
): Promise<Action[]> {
|
|
547
|
+
const actions: Action[] = [
|
|
548
|
+
this.platform.action('wrapentity', {
|
|
549
|
+
game: this.server.account,
|
|
550
|
+
owner: Name.from(owner),
|
|
551
|
+
entity_id: UInt64.from(entityId),
|
|
552
|
+
nexus_id: UInt64.from(nexusId),
|
|
553
|
+
}),
|
|
554
|
+
]
|
|
555
|
+
const claimRam =
|
|
556
|
+
opts.claimRam ?? (this.atomicAssetsAccount ?? 'atomicassets') !== 'atomicassets'
|
|
557
|
+
if (claimRam) {
|
|
558
|
+
actions.push(this.setLastPayer(owner, SHIPLOAD_COLLECTION))
|
|
559
|
+
}
|
|
560
|
+
return actions
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
placecargo(owner: NameType, hostId: UInt64Type, assetId: UInt64Type): Action {
|
|
564
|
+
return this.server.action('placecargo', {
|
|
565
|
+
owner: Name.from(owner),
|
|
566
|
+
host_id: UInt64.from(hostId),
|
|
567
|
+
asset_id: UInt64.from(assetId),
|
|
568
|
+
})
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
placeentity(owner: NameType, assetId: UInt64Type, targetNexusId: UInt64Type): Action {
|
|
572
|
+
return this.server.action('placeentity', {
|
|
573
|
+
owner: Name.from(owner),
|
|
574
|
+
asset_id: UInt64.from(assetId),
|
|
575
|
+
target_nexus_id: UInt64.from(targetNexusId),
|
|
576
|
+
})
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
transferForUnwrap(owner: NameType, assetId: UInt64Type): Action {
|
|
580
|
+
return Action.from(
|
|
581
|
+
{
|
|
582
|
+
account: this.atomicAssetsAccount,
|
|
583
|
+
name: 'transfer',
|
|
584
|
+
authorization: [{actor: Name.from(owner), permission: 'active'}],
|
|
585
|
+
data: {
|
|
586
|
+
from: Name.from(owner),
|
|
587
|
+
to: this.platform.account,
|
|
588
|
+
asset_ids: [UInt64.from(assetId)],
|
|
589
|
+
memo: 'unwrap',
|
|
590
|
+
},
|
|
591
|
+
},
|
|
592
|
+
ATOMICASSETS_ABI
|
|
593
|
+
)
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// Two top-level actions the wallet signs to unwrap an NFT into a host's cargo.
|
|
597
|
+
unwrapCargoTx(owner: NameType, assetId: UInt64Type, hostId: UInt64Type): Action[] {
|
|
598
|
+
return [this.transferForUnwrap(owner, assetId), this.placecargo(owner, hostId, assetId)]
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// Two top-level actions the wallet signs to place an entity NFT at a nexus.
|
|
602
|
+
unwrapEntityTx(owner: NameType, assetId: UInt64Type, targetNexusId: UInt64Type): Action[] {
|
|
603
|
+
return [
|
|
604
|
+
this.transferForUnwrap(owner, assetId),
|
|
605
|
+
this.placeentity(owner, assetId, targetNexusId),
|
|
606
|
+
]
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
setRamPayer(newPayer: NameType, assetId: UInt64Type): Action {
|
|
610
|
+
return Action.from(
|
|
611
|
+
{
|
|
612
|
+
account: this.atomicAssetsAccount,
|
|
613
|
+
name: 'setrampayer',
|
|
614
|
+
authorization: [{actor: Name.from(newPayer), permission: 'active'}],
|
|
615
|
+
data: {new_payer: Name.from(newPayer), asset_id: UInt64.from(assetId)},
|
|
616
|
+
},
|
|
617
|
+
ATOMICASSETS_ABI
|
|
618
|
+
)
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
setLastPayer(owner: NameType, collectionName: NameType): Action {
|
|
622
|
+
return Action.from(
|
|
623
|
+
{
|
|
624
|
+
account: this.atomicAssetsAccount,
|
|
625
|
+
name: 'setlastpayer',
|
|
626
|
+
authorization: [{actor: Name.from(owner), permission: 'active'}],
|
|
627
|
+
data: {owner: Name.from(owner), collection_name: Name.from(collectionName)},
|
|
628
|
+
},
|
|
629
|
+
ATOMICASSETS_ABI
|
|
630
|
+
)
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
demolish(entityId: UInt64Type): Action {
|
|
634
|
+
return this.server.action('demolish', {
|
|
241
635
|
entity_id: UInt64.from(entityId),
|
|
242
|
-
cargo_id: UInt64.from(cargoId),
|
|
243
|
-
quantity: UInt64.from(quantity),
|
|
244
636
|
})
|
|
245
637
|
}
|
|
246
638
|
|
|
247
639
|
joinGame(account: NameType, companyName: string): Action[] {
|
|
248
640
|
return [this.foundCompany(account, companyName), this.join(account)]
|
|
249
641
|
}
|
|
642
|
+
|
|
643
|
+
commit(oracleId: NameType, epoch: UInt64Type, commit: Checksum256Type): Action {
|
|
644
|
+
return this.server.action('commit', {
|
|
645
|
+
oracle_id: Name.from(oracleId),
|
|
646
|
+
epoch: UInt64.from(epoch),
|
|
647
|
+
commit: Checksum256.from(commit),
|
|
648
|
+
})
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
reveal(oracleId: NameType, epoch: UInt64Type, reveal: Checksum256Type): Action {
|
|
652
|
+
return this.server.action('reveal', {
|
|
653
|
+
oracle_id: Name.from(oracleId),
|
|
654
|
+
epoch: UInt64.from(epoch),
|
|
655
|
+
reveal: Checksum256.from(reveal),
|
|
656
|
+
})
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
addoracle(oracleId: NameType): Action {
|
|
660
|
+
return this.server.action('addoracle', {
|
|
661
|
+
oracle_id: Name.from(oracleId),
|
|
662
|
+
})
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
removeoracle(oracleId: NameType): Action {
|
|
666
|
+
return this.server.action('removeoracle', {
|
|
667
|
+
oracle_id: Name.from(oracleId),
|
|
668
|
+
})
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
setthreshold(threshold: UInt8Type): Action {
|
|
672
|
+
return this.server.action('setthreshold', {
|
|
673
|
+
threshold: UInt8.from(threshold),
|
|
674
|
+
})
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
cleanrsvp(epoch: UInt64Type, maxRows: UInt64Type): Action {
|
|
678
|
+
return this.server.action('cleanrsvp', {
|
|
679
|
+
epoch: UInt64.from(epoch),
|
|
680
|
+
max_rows: UInt64.from(maxRows),
|
|
681
|
+
})
|
|
682
|
+
}
|
|
250
683
|
}
|