@shipload/sdk 2.0.0-rc5 → 2.0.0-rc7

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.
Files changed (52) hide show
  1. package/README.md +1 -349
  2. package/lib/shipload.d.ts +607 -1113
  3. package/lib/shipload.js +1482 -2077
  4. package/lib/shipload.js.map +1 -1
  5. package/lib/shipload.m.js +1421 -2038
  6. package/lib/shipload.m.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/capabilities/crafting.ts +28 -0
  9. package/src/capabilities/extraction.ts +14 -8
  10. package/src/capabilities/guards.ts +0 -5
  11. package/src/capabilities/index.ts +2 -0
  12. package/src/capabilities/modules.ts +49 -0
  13. package/src/capabilities/storage.ts +0 -8
  14. package/src/contracts/server.ts +231 -313
  15. package/src/data/colors.ts +28 -0
  16. package/src/data/items.json +15 -15
  17. package/src/data/recipes.ts +351 -0
  18. package/src/derivation/crafting.ts +142 -0
  19. package/src/derivation/index.ts +1 -0
  20. package/src/derivation/stats.ts +91 -15
  21. package/src/derivation/stratum.ts +2 -2
  22. package/src/entities/cargo-utils.ts +6 -64
  23. package/src/entities/container.ts +18 -0
  24. package/src/entities/entity-inventory.ts +0 -4
  25. package/src/entities/inventory-accessor.ts +0 -4
  26. package/src/entities/location.ts +2 -197
  27. package/src/entities/makers.ts +10 -9
  28. package/src/entities/player.ts +1 -274
  29. package/src/entities/ship-deploy.ts +89 -0
  30. package/src/entities/ship.ts +14 -27
  31. package/src/entities/warehouse.ts +0 -4
  32. package/src/index-module.ts +66 -41
  33. package/src/managers/actions.ts +77 -88
  34. package/src/managers/context.ts +0 -9
  35. package/src/managers/index.ts +0 -1
  36. package/src/managers/locations.ts +2 -85
  37. package/src/market/items.ts +0 -1
  38. package/src/resolution/resolve-item.ts +242 -0
  39. package/src/scheduling/projection.ts +0 -10
  40. package/src/shipload.ts +0 -5
  41. package/src/travel/travel.ts +3 -3
  42. package/src/types/capabilities.ts +1 -9
  43. package/src/types/entity-traits.ts +3 -4
  44. package/src/types/entity.ts +3 -4
  45. package/src/types.ts +6 -43
  46. package/src/utils/system.ts +5 -4
  47. package/src/managers/trades.ts +0 -119
  48. package/src/market/market.ts +0 -195
  49. package/src/market/rolls.ts +0 -8
  50. package/src/trading/collect.ts +0 -938
  51. package/src/trading/deal.ts +0 -207
  52. package/src/trading/trade.ts +0 -203
@@ -1,15 +1,8 @@
1
1
  import {Action, Int64, Name, NameType, UInt16, UInt32, UInt64, UInt64Type} from '@wharfkit/antelope'
2
2
  import {BaseManager} from './base'
3
- import {Ship} from '../entities/ship'
4
3
  import {CoordinatesType, EntityType, EntityTypeName} from '../types'
5
4
  import {ServerContract} from '../contracts'
6
5
 
7
- interface SellableCargo {
8
- item_id: {toNumber(): number} | number
9
- quantity: {toNumber(): number} | number
10
- hasCargo: boolean
11
- }
12
-
13
6
  export type EntityRefInput = {
14
7
  entityType: EntityTypeName
15
8
  entityId: UInt64Type
@@ -91,71 +84,6 @@ export class ActionsManager extends BaseManager {
91
84
  })
92
85
  }
93
86
 
94
- buyItems(
95
- entityId: UInt64Type,
96
- goodId: UInt64Type,
97
- quantity: UInt64Type,
98
- entityType: EntityTypeName = EntityType.SHIP
99
- ): Action {
100
- return this.server.action('buyitems', {
101
- entity_type: entityType,
102
- id: UInt64.from(entityId),
103
- item_id: UInt16.from(goodId),
104
- quantity: UInt32.from(quantity),
105
- })
106
- }
107
-
108
- sellItems(
109
- entityId: UInt64Type,
110
- goodId: UInt64Type,
111
- quantity: UInt64Type,
112
- entityType: EntityTypeName = EntityType.SHIP
113
- ): Action {
114
- return this.server.action('sellitems', {
115
- entity_type: entityType,
116
- id: UInt64.from(entityId),
117
- item_id: UInt16.from(goodId),
118
- quantity: UInt32.from(quantity),
119
- })
120
- }
121
-
122
- buyShip(account: NameType, name: string): Action {
123
- return this.server.action('buyship', {
124
- account: Name.from(account),
125
- name,
126
- })
127
- }
128
-
129
- buyWarehouse(account: NameType, shipId: UInt64Type, name: string): Action {
130
- return this.server.action('buywarehouse', {
131
- account: Name.from(account),
132
- ship_id: UInt64.from(shipId),
133
- name,
134
- })
135
- }
136
-
137
- buyContainer(account: NameType, shipId: UInt64Type, name: string): Action {
138
- return this.server.action('buycontainer', {
139
- account: Name.from(account),
140
- ship_id: UInt64.from(shipId),
141
- name,
142
- })
143
- }
144
-
145
- takeLoan(account: NameType, amount: UInt64Type): Action {
146
- return this.server.action('takeloan', {
147
- account: Name.from(account),
148
- amount: UInt64.from(amount),
149
- })
150
- }
151
-
152
- payLoan(account: NameType, amount: UInt64Type): Action {
153
- return this.server.action('payloan', {
154
- account: Name.from(account),
155
- amount: UInt64.from(amount),
156
- })
157
- }
158
-
159
87
  foundCompany(account: NameType, name: string): Action {
160
88
  return this.platform.action('foundcompany', {
161
89
  account: Name.from(account),
@@ -187,26 +115,87 @@ export class ActionsManager extends BaseManager {
187
115
  })
188
116
  }
189
117
 
190
- joinGame(account: NameType, companyName: string): Action[] {
191
- return [this.foundCompany(account, companyName), this.join(account)]
118
+ craft(
119
+ entityType: EntityTypeName,
120
+ entityId: UInt64Type,
121
+ recipeId: number,
122
+ quantity: number,
123
+ inputs: ServerContract.ActionParams.Type.cargo_item[]
124
+ ): Action {
125
+ const cargoInputs = inputs.map((i) =>
126
+ ServerContract.Types.cargo_item.from(i)
127
+ )
128
+ return this.server.action('craft', {
129
+ entity_type: entityType,
130
+ id: UInt64.from(entityId),
131
+ recipe_id: UInt16.from(recipeId),
132
+ quantity: UInt32.from(quantity),
133
+ inputs: cargoInputs,
134
+ })
135
+ }
136
+
137
+ blend(
138
+ entityType: EntityTypeName,
139
+ entityId: UInt64Type,
140
+ inputs: ServerContract.ActionParams.Type.cargo_item[]
141
+ ): Action {
142
+ const cargoInputs = inputs.map((i) =>
143
+ ServerContract.Types.cargo_item.from(i)
144
+ )
145
+ return this.server.action('blend', {
146
+ entity_type: entityType,
147
+ id: UInt64.from(entityId),
148
+ inputs: cargoInputs,
149
+ })
192
150
  }
193
151
 
194
- sellAllCargo(ship: Ship | UInt64Type, cargo?: SellableCargo[]): Action[] {
195
- let shipCargo: SellableCargo[]
152
+ deploy(
153
+ entityType: EntityTypeName,
154
+ entityId: UInt64Type,
155
+ packedItemId: number,
156
+ seed: bigint,
157
+ entityName: string
158
+ ): Action {
159
+ return this.server.action('deploy', {
160
+ entity_type: entityType,
161
+ id: UInt64.from(entityId),
162
+ packed_item_id: UInt16.from(packedItemId),
163
+ seed: UInt64.from(seed),
164
+ entity_name: entityName,
165
+ })
166
+ }
196
167
 
197
- if (ship instanceof Ship) {
198
- shipCargo = cargo || ship.inventory
199
- } else {
200
- if (!cargo) {
201
- throw new Error('cargo parameter required when ship is a UInt64Type')
202
- }
203
- shipCargo = cargo
204
- }
168
+ addmodule(
169
+ entityType: EntityTypeName,
170
+ entityId: UInt64Type,
171
+ moduleIndex: number,
172
+ moduleCargoId: UInt64Type,
173
+ targetCargoId: UInt64Type = UInt64.from(0)
174
+ ): Action {
175
+ return this.server.action('addmodule', {
176
+ entity_type: entityType,
177
+ entity_id: UInt64.from(entityId),
178
+ module_index: moduleIndex,
179
+ module_cargo_id: UInt64.from(moduleCargoId),
180
+ target_cargo_id: UInt64.from(targetCargoId),
181
+ })
182
+ }
205
183
 
206
- const shipId = ship instanceof Ship ? ship.id : UInt64.from(ship)
184
+ rmmodule(
185
+ entityType: EntityTypeName,
186
+ entityId: UInt64Type,
187
+ moduleIndex: number,
188
+ targetCargoId: UInt64Type = UInt64.from(0)
189
+ ): Action {
190
+ return this.server.action('rmmodule', {
191
+ entity_type: entityType,
192
+ entity_id: UInt64.from(entityId),
193
+ module_index: moduleIndex,
194
+ target_cargo_id: UInt64.from(targetCargoId),
195
+ })
196
+ }
207
197
 
208
- return shipCargo
209
- .filter((c) => c.hasCargo)
210
- .map((c) => this.sellItems(shipId, c.item_id, c.quantity, EntityType.SHIP))
198
+ joinGame(account: NameType, companyName: string): Action[] {
199
+ return [this.foundCompany(account, companyName), this.join(account)]
211
200
  }
212
201
  }
@@ -6,7 +6,6 @@ import {GameState} from '../entities/gamestate'
6
6
  import {EntitiesManager} from './entities'
7
7
  import {PlayersManager} from './players'
8
8
  import {LocationsManager} from './locations'
9
- import {TradesManager} from './trades'
10
9
  import {EpochsManager} from './epochs'
11
10
  import {ActionsManager} from './actions'
12
11
 
@@ -14,7 +13,6 @@ export class GameContext {
14
13
  private _entities?: EntitiesManager
15
14
  private _players?: PlayersManager
16
15
  private _locations?: LocationsManager
17
- private _trades?: TradesManager
18
16
  private _epochs?: EpochsManager
19
17
  private _actions?: ActionsManager
20
18
 
@@ -48,13 +46,6 @@ export class GameContext {
48
46
  return this._locations
49
47
  }
50
48
 
51
- get trades(): TradesManager {
52
- if (!this._trades) {
53
- this._trades = new TradesManager(this)
54
- }
55
- return this._trades
56
- }
57
-
58
49
  get epochs(): EpochsManager {
59
50
  if (!this._epochs) {
60
51
  this._epochs = new EpochsManager(this)
@@ -4,6 +4,5 @@ export {EntitiesManager} from './entities'
4
4
  export type {EntityType} from './entities'
5
5
  export {PlayersManager} from './players'
6
6
  export {LocationsManager} from './locations'
7
- export {TradesManager} from './trades'
8
7
  export {EpochsManager} from './epochs'
9
8
  export {ActionsManager} from './actions'
@@ -1,55 +1,11 @@
1
- import {Bytes, Checksum256, UInt16Type, UInt64, UInt64Type} from '@wharfkit/antelope'
1
+ import {UInt16Type, UInt64, UInt64Type} from '@wharfkit/antelope'
2
2
  import {BaseManager} from './base'
3
- import {CoordinatesType, coordsToLocationId, Distance, ItemPrice} from '../types'
4
- import {marketPrice, marketPrices} from '../market/market'
3
+ import {CoordinatesType, coordsToLocationId, Distance} from '../types'
5
4
  import {hasSystem} from '../utils/system'
6
5
  import {findNearbyPlanets} from '../travel/travel'
7
- import {Location, toLocation} from '../entities/location'
8
6
  import {ServerContract} from '../contracts'
9
7
 
10
8
  export class LocationsManager extends BaseManager {
11
- async getMarketPrice(location: CoordinatesType, goodId: number): Promise<ItemPrice> {
12
- const game = await this.getGame()
13
- const state = await this.getState()
14
- return marketPrice(location, goodId, game.config.seed, state)
15
- }
16
-
17
- async getMarketPrices(location: CoordinatesType): Promise<ItemPrice[]> {
18
- const game = await this.getGame()
19
- const state = await this.getState()
20
- return marketPrices(location, game.config.seed, state)
21
- }
22
-
23
- async getMarketPricesWithSupply(location: CoordinatesType): Promise<ItemPrice[]> {
24
- const [game, state, supplyRows] = await Promise.all([
25
- this.getGame(),
26
- this.getState(),
27
- this.getSupplyRows(location),
28
- ])
29
-
30
- const prices = marketPrices(location, game.config.seed, state)
31
-
32
- const supplyMap = new Map<number, number>()
33
- for (const row of supplyRows) {
34
- if (UInt64.from(row.epoch).equals(state.epoch)) {
35
- supplyMap.set(Number(row.item_id), Number(row.supply))
36
- }
37
- }
38
-
39
- return prices.map((price) => {
40
- const actualSupply = supplyMap.get(Number(price.id))
41
- if (actualSupply !== undefined) {
42
- return ItemPrice.from({
43
- id: price.id,
44
- item: price.item,
45
- price: price.price,
46
- supply: UInt64.from(actualSupply),
47
- })
48
- }
49
- return price
50
- })
51
- }
52
-
53
9
  async hasSystem(location: CoordinatesType): Promise<boolean> {
54
10
  const game = await this.getGame()
55
11
  return hasSystem(game.config.seed, location)
@@ -63,45 +19,6 @@ export class LocationsManager extends BaseManager {
63
19
  return findNearbyPlanets(game.config.seed, origin, maxDistance)
64
20
  }
65
21
 
66
- async getSupplyRows(location: CoordinatesType) {
67
- const hash = Checksum256.hash(Bytes.from(`${location.x}-${location.y}`, 'utf8'))
68
- return this.server.table('supply').all({
69
- index_position: 'secondary',
70
- from: hash,
71
- to: hash,
72
- })
73
- }
74
-
75
- async getLocationWithPrices(coords: CoordinatesType): Promise<Location> {
76
- const location = toLocation(coords)
77
- const prices = await this.getMarketPrices(location.coordinates)
78
- location.setMarketPrices(prices)
79
- return location
80
- }
81
-
82
- async getLocationWithSupply(coords: CoordinatesType): Promise<Location> {
83
- const location = toLocation(coords)
84
- const [rows, state] = await Promise.all([
85
- this.getSupplyRows(location.coordinates),
86
- this.getState(),
87
- ])
88
- location.setLocationRows(rows, state.epoch)
89
- return location
90
- }
91
-
92
- async getLocationComplete(coords: CoordinatesType): Promise<Location> {
93
- const location = toLocation(coords)
94
- const [prices, rows, state] = await Promise.all([
95
- this.getMarketPrices(location.coordinates),
96
- this.getSupplyRows(location.coordinates),
97
- this.getState(),
98
- ])
99
-
100
- location.setMarketPrices(prices)
101
- location.setLocationRows(rows, state.epoch)
102
- return location
103
- }
104
-
105
22
  async getLocationEntity(
106
23
  id: UInt64Type
107
24
  ): Promise<ServerContract.Types.location_row | undefined> {
@@ -7,7 +7,6 @@ const items: Item[] = itemsData.map((g) =>
7
7
  id: g.id,
8
8
  name: g.name,
9
9
  description: g.description,
10
- base_price: g.base_price,
11
10
  mass: g.mass,
12
11
  category: g.category,
13
12
  tier: g.tier,
@@ -0,0 +1,242 @@
1
+ import {UInt16, UInt64} from '@wharfkit/antelope'
2
+ import type {UInt16Type, UInt64Type} from '@wharfkit/antelope'
3
+ import type {ResourceCategory, ResourceTier} from '../types'
4
+ import {getItem} from '../market/items'
5
+ import {getComponentById, getModuleRecipeByItemId, getEntityRecipeByItemId} from '../data/recipes'
6
+ import {isModuleItem, getModuleCapabilityType, MODULE_ENGINE, MODULE_GENERATOR, MODULE_EXTRACTOR, MODULE_LOADER, MODULE_CRAFTER} from '../capabilities/modules'
7
+ import {decodeCraftedItemStats} from '../derivation/crafting'
8
+ import {deriveResourceStats} from '../derivation/stratum'
9
+ import {getStatDefinitions} from '../derivation/stats'
10
+ import {computeShipHullCapabilities, computeEngineCapabilities, computeGeneratorCapabilities, computeExtractorCapabilities, computeLoaderCapabilities, computeManufacturingCapabilities} from '../entities/ship-deploy'
11
+ import {computeContainerCapabilities} from '../entities/container'
12
+ import {categoryColors, categoryIcons, componentIcon, moduleIcon} from '../data/colors'
13
+ import {ServerContract} from '../contracts'
14
+
15
+ export interface ResolvedItemStat {
16
+ key: string
17
+ label: string
18
+ abbreviation: string
19
+ value: number
20
+ color: string
21
+ category: ResourceCategory
22
+ inverted?: boolean
23
+ }
24
+
25
+ export interface ResolvedAttributeGroup {
26
+ capability: string
27
+ attributes: {label: string; value: number}[]
28
+ }
29
+
30
+ export type ResolvedItemType = 'resource' | 'component' | 'module' | 'entity'
31
+
32
+ export interface ResolvedItem {
33
+ itemId: number
34
+ name: string
35
+ icon: string
36
+ category?: ResourceCategory
37
+ tier: ResourceTier
38
+ mass: number
39
+ itemType: ResolvedItemType
40
+ stats?: ResolvedItemStat[]
41
+ attributes?: ResolvedAttributeGroup[]
42
+ }
43
+
44
+ function toNum(v: UInt16Type): number {
45
+ return Number(UInt16.from(v).value.toString())
46
+ }
47
+
48
+ function toBigSeed(v: UInt64Type): bigint {
49
+ return BigInt(UInt64.from(v).toString())
50
+ }
51
+
52
+ function resolveResource(id: number, seed?: UInt64Type): ResolvedItem {
53
+ const item = getItem(id)
54
+ const cat = item.category
55
+ let stats: ResolvedItemStat[] | undefined
56
+ if (seed !== undefined) {
57
+ const derived = deriveResourceStats(toBigSeed(seed))
58
+ const defs = getStatDefinitions(cat)
59
+ const values = [derived.stat1, derived.stat2, derived.stat3]
60
+ stats = defs.map((d, i) => ({
61
+ key: d.key,
62
+ label: d.label,
63
+ abbreviation: d.abbreviation,
64
+ value: values[i] ?? 0,
65
+ color: categoryColors[cat],
66
+ category: cat,
67
+ inverted: d.inverted,
68
+ }))
69
+ }
70
+ return {
71
+ itemId: id,
72
+ name: String(item.name),
73
+ icon: categoryIcons[cat] ?? '⬡',
74
+ category: cat,
75
+ tier: item.tier,
76
+ mass: Number(item.mass.value.toString()),
77
+ itemType: 'resource',
78
+ stats,
79
+ }
80
+ }
81
+
82
+ function resolveComponent(id: number, seed?: UInt64Type): ResolvedItem {
83
+ const comp = getComponentById(id)!
84
+ let stats: ResolvedItemStat[] | undefined
85
+ if (seed !== undefined) {
86
+ const decoded = decodeCraftedItemStats(id, toBigSeed(seed))
87
+ stats = Object.entries(decoded).map(([key, value]) => {
88
+ const allDefs = getStatDefinitions('metal')
89
+ .concat(getStatDefinitions('precious'))
90
+ .concat(getStatDefinitions('gas'))
91
+ .concat(getStatDefinitions('mineral'))
92
+ .concat(getStatDefinitions('organic'))
93
+ const def = allDefs.find((d) => d.key === key)
94
+ const statDef = comp.stats.find((s) => s.key === key)
95
+ const cat = (statDef?.source ?? 'metal') as ResourceCategory
96
+ return {
97
+ key,
98
+ label: def?.label ?? key,
99
+ abbreviation: def?.abbreviation ?? key.slice(0, 3).toUpperCase(),
100
+ value,
101
+ color: categoryColors[cat],
102
+ category: cat,
103
+ inverted: def?.inverted,
104
+ }
105
+ })
106
+ }
107
+ return {
108
+ itemId: id,
109
+ name: comp.name,
110
+ icon: componentIcon,
111
+ tier: 't1' as ResourceTier,
112
+ mass: comp.mass,
113
+ itemType: 'component',
114
+ stats,
115
+ }
116
+ }
117
+
118
+ function computeCapabilityGroup(moduleType: number, stats: Record<string, number>): ResolvedAttributeGroup | undefined {
119
+ switch (moduleType) {
120
+ case MODULE_ENGINE: {
121
+ const caps = computeEngineCapabilities(stats)
122
+ return {capability: 'Engine', attributes: [
123
+ {label: 'Thrust', value: caps.thrust},
124
+ {label: 'Drain', value: caps.drain},
125
+ ]}
126
+ }
127
+ case MODULE_GENERATOR: {
128
+ const caps = computeGeneratorCapabilities(stats)
129
+ return {capability: 'Generator', attributes: [
130
+ {label: 'Capacity', value: caps.capacity},
131
+ {label: 'Recharge', value: caps.recharge},
132
+ ]}
133
+ }
134
+ case MODULE_EXTRACTOR: {
135
+ const caps = computeExtractorCapabilities(stats)
136
+ return {capability: 'Extractor', attributes: [
137
+ {label: 'Rate', value: caps.rate},
138
+ {label: 'Drain', value: caps.drain},
139
+ {label: 'Depth', value: caps.depth},
140
+ {label: 'Drill', value: caps.drill},
141
+ ]}
142
+ }
143
+ case MODULE_LOADER: {
144
+ const caps = computeLoaderCapabilities(stats)
145
+ return {capability: 'Loader', attributes: [
146
+ {label: 'Mass', value: caps.mass},
147
+ {label: 'Thrust', value: caps.thrust},
148
+ {label: 'Quantity', value: caps.quantity},
149
+ ]}
150
+ }
151
+ case MODULE_CRAFTER: {
152
+ const caps = computeManufacturingCapabilities(stats)
153
+ return {capability: 'Manufacturing', attributes: [
154
+ {label: 'Speed', value: caps.speed},
155
+ {label: 'Drain', value: caps.drain},
156
+ ]}
157
+ }
158
+ default:
159
+ return undefined
160
+ }
161
+ }
162
+
163
+ function resolveModule(id: number, seed?: UInt64Type): ResolvedItem {
164
+ const recipe = getModuleRecipeByItemId(id)!
165
+ let attributes: ResolvedAttributeGroup[] | undefined
166
+ if (seed !== undefined) {
167
+ const stats = decodeCraftedItemStats(id, toBigSeed(seed))
168
+ const modType = getModuleCapabilityType(id)
169
+ const group = computeCapabilityGroup(modType, stats)
170
+ if (group) attributes = [group]
171
+ }
172
+ return {
173
+ itemId: id,
174
+ name: recipe.name,
175
+ icon: moduleIcon,
176
+ tier: 't1' as ResourceTier,
177
+ mass: 0,
178
+ itemType: 'module',
179
+ attributes,
180
+ }
181
+ }
182
+
183
+ function resolveEntity(id: number, seed?: UInt64Type, modules?: ServerContract.Types.module_entry[]): ResolvedItem {
184
+ const recipe = getEntityRecipeByItemId(id)!
185
+ let attributes: ResolvedAttributeGroup[] | undefined
186
+ if (seed !== undefined) {
187
+ const stats = decodeCraftedItemStats(id, toBigSeed(seed))
188
+ attributes = []
189
+
190
+ const isShip = recipe.id === 'ship-t1'
191
+ if (isShip) {
192
+ const hullCaps = computeShipHullCapabilities(stats)
193
+ attributes.push({capability: 'Hull', attributes: [
194
+ {label: 'Mass', value: hullCaps.hullmass},
195
+ {label: 'Capacity', value: hullCaps.capacity},
196
+ ]})
197
+ } else {
198
+ const containerCaps = computeContainerCapabilities(stats)
199
+ attributes.push({capability: 'Hull', attributes: [
200
+ {label: 'Mass', value: containerCaps.hullmass},
201
+ {label: 'Capacity', value: containerCaps.capacity},
202
+ ]})
203
+ }
204
+
205
+ if (modules) {
206
+ for (const mod of modules) {
207
+ if (!mod.installed) continue
208
+ const modItemId = Number(mod.installed.item_id.value.toString())
209
+ const modSeed = BigInt(mod.installed.seed.toString())
210
+ const modStats = decodeCraftedItemStats(modItemId, modSeed)
211
+ const modType = getModuleCapabilityType(modItemId)
212
+ const group = computeCapabilityGroup(modType, modStats)
213
+ if (group) attributes.push(group)
214
+ }
215
+ }
216
+ }
217
+ return {
218
+ itemId: id,
219
+ name: recipe.name,
220
+ icon: componentIcon,
221
+ tier: 't1' as ResourceTier,
222
+ mass: 0,
223
+ itemType: 'entity',
224
+ attributes,
225
+ }
226
+ }
227
+
228
+ export function resolveItem(
229
+ itemId: UInt16Type,
230
+ seed?: UInt64Type,
231
+ modules?: ServerContract.Types.module_entry[]
232
+ ): ResolvedItem {
233
+ const id = toNum(itemId)
234
+
235
+ if (isModuleItem(id)) return resolveModule(id, seed)
236
+
237
+ if (getComponentById(id)) return resolveComponent(id, seed)
238
+
239
+ if (getEntityRecipeByItemId(id)) return resolveEntity(id, seed, modules)
240
+
241
+ return resolveResource(id, seed)
242
+ }
@@ -23,13 +23,11 @@ export interface ProjectedEntity {
23
23
  engines?: ServerContract.Types.movement_stats
24
24
  loaders?: ServerContract.Types.loader_stats
25
25
  generator?: ServerContract.Types.energy_stats
26
- trade?: ServerContract.Types.trade_stats
27
26
  readonly totalMass: UInt64
28
27
 
29
28
  hasMovement(): boolean
30
29
  hasStorage(): boolean
31
30
  hasLoaders(): boolean
32
- hasTrade(): boolean
33
31
 
34
32
  capabilities(): EntityCapabilities
35
33
  state(): EntityState
@@ -42,7 +40,6 @@ export interface Projectable extends ScheduleData {
42
40
  generator?: ServerContract.Types.energy_stats
43
41
  engines?: ServerContract.Types.movement_stats
44
42
  loaders?: ServerContract.Types.loader_stats
45
- trade?: ServerContract.Types.trade_stats
46
43
  capacity?: UInt32
47
44
  cargo: ServerContract.Types.cargo_item[]
48
45
  cargomass: UInt32
@@ -59,7 +56,6 @@ export function createProjectedEntity(entity: Projectable): ProjectedEntity {
59
56
  const loaders = entity.loaders
60
57
  const engines = entity.engines
61
58
  const generator = entity.generator
62
- const trade = entity.trade
63
59
  const capacity = entity.capacity
64
60
 
65
61
  const projected: ProjectedEntity = {
@@ -71,7 +67,6 @@ export function createProjectedEntity(entity: Projectable): ProjectedEntity {
71
67
  engines,
72
68
  generator,
73
69
  loaders,
74
- trade,
75
70
 
76
71
  get totalMass() {
77
72
  let mass = UInt64.from(this.shipMass).adding(this.cargoMass)
@@ -93,10 +88,6 @@ export function createProjectedEntity(entity: Projectable): ProjectedEntity {
93
88
  return capsHasLoaders(this.capabilities())
94
89
  },
95
90
 
96
- hasTrade() {
97
- return this.trade !== undefined
98
- },
99
-
100
91
  capabilities(): EntityCapabilities {
101
92
  return {
102
93
  hullmass: this.shipMass,
@@ -104,7 +95,6 @@ export function createProjectedEntity(entity: Projectable): ProjectedEntity {
104
95
  engines: this.engines,
105
96
  generator: this.generator,
106
97
  loaders: this.loaders,
107
- trade: this.trade,
108
98
  }
109
99
  },
110
100
 
package/src/shipload.ts CHANGED
@@ -7,7 +7,6 @@ import {GameContext} from './managers/context'
7
7
  import {EntitiesManager} from './managers/entities'
8
8
  import {PlayersManager} from './managers/players'
9
9
  import {LocationsManager} from './managers/locations'
10
- import {TradesManager} from './managers/trades'
11
10
  import {EpochsManager} from './managers/epochs'
12
11
  import {ActionsManager} from './managers/actions'
13
12
  import {GameState} from './entities/gamestate'
@@ -94,10 +93,6 @@ export class Shipload {
94
93
  return this._context.locations
95
94
  }
96
95
 
97
- get trades(): TradesManager {
98
- return this._context.trades
99
- }
100
-
101
96
  get epochs(): EpochsManager {
102
97
  return this._context.epochs
103
98
  }
@@ -24,7 +24,7 @@ import {ServerContract} from '../contracts'
24
24
  import {
25
25
  CargoMassInfo,
26
26
  Distance,
27
- INITIAL_SHIP_MASS,
27
+ BASE_ORBITAL_MASS,
28
28
  MAX_ORBITAL_ALTITUDE,
29
29
  MIN_ORBITAL_ALTITUDE,
30
30
  PRECISION,
@@ -35,11 +35,11 @@ import {getItem} from '../market/items'
35
35
  import {hasSystem} from '../utils/system'
36
36
 
37
37
  export function calc_orbital_altitude(mass: number): number {
38
- if (mass <= INITIAL_SHIP_MASS) {
38
+ if (mass <= BASE_ORBITAL_MASS) {
39
39
  return MIN_ORBITAL_ALTITUDE
40
40
  }
41
41
 
42
- const ratio = mass / INITIAL_SHIP_MASS
42
+ const ratio = mass / BASE_ORBITAL_MASS
43
43
  const capRatio = 10.0
44
44
  let scale = Math.log(ratio) / Math.log(capRatio)
45
45
  scale = Math.min(scale, 1.0)