@shipload/sdk 2.0.0-rc5 → 2.0.0-rc6

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 (44) hide show
  1. package/lib/shipload.d.ts +376 -1008
  2. package/lib/shipload.js +712 -1948
  3. package/lib/shipload.js.map +1 -1
  4. package/lib/shipload.m.js +694 -1924
  5. package/lib/shipload.m.js.map +1 -1
  6. package/package.json +1 -1
  7. package/src/capabilities/crafting.ts +10 -0
  8. package/src/capabilities/guards.ts +0 -5
  9. package/src/capabilities/index.ts +1 -0
  10. package/src/capabilities/storage.ts +0 -8
  11. package/src/contracts/server.ts +103 -220
  12. package/src/data/items.json +15 -15
  13. package/src/data/recipes.ts +129 -0
  14. package/src/derivation/crafting.ts +120 -0
  15. package/src/derivation/index.ts +1 -0
  16. package/src/derivation/stats.ts +91 -15
  17. package/src/derivation/stratum.ts +2 -2
  18. package/src/entities/cargo-utils.ts +6 -64
  19. package/src/entities/container.ts +18 -0
  20. package/src/entities/entity-inventory.ts +0 -4
  21. package/src/entities/inventory-accessor.ts +0 -4
  22. package/src/entities/location.ts +2 -197
  23. package/src/entities/player.ts +1 -274
  24. package/src/entities/ship.ts +0 -21
  25. package/src/entities/warehouse.ts +0 -4
  26. package/src/index-module.ts +34 -41
  27. package/src/managers/actions.ts +38 -90
  28. package/src/managers/context.ts +0 -9
  29. package/src/managers/index.ts +0 -1
  30. package/src/managers/locations.ts +2 -85
  31. package/src/market/items.ts +0 -1
  32. package/src/scheduling/projection.ts +0 -10
  33. package/src/shipload.ts +0 -5
  34. package/src/types/capabilities.ts +1 -9
  35. package/src/types/entity-traits.ts +3 -4
  36. package/src/types/entity.ts +0 -1
  37. package/src/types.ts +5 -25
  38. package/src/utils/system.ts +5 -4
  39. package/src/managers/trades.ts +0 -119
  40. package/src/market/market.ts +0 -195
  41. package/src/market/rolls.ts +0 -8
  42. package/src/trading/collect.ts +0 -938
  43. package/src/trading/deal.ts +0 -207
  44. 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,46 @@ 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: {itemId: number; quantity: number; seed?: bigint}[]
124
+ ): Action {
125
+ const cargoInputs = inputs.map((i) =>
126
+ ServerContract.Types.cargo_item.from({
127
+ item_id: UInt16.from(i.itemId),
128
+ quantity: UInt32.from(i.quantity),
129
+ seed: i.seed !== undefined ? UInt64.from(i.seed) : null,
130
+ })
131
+ )
132
+ return this.server.action('craft', {
133
+ entity_type: entityType,
134
+ id: UInt64.from(entityId),
135
+ recipe_id: UInt16.from(recipeId),
136
+ quantity: UInt32.from(quantity),
137
+ inputs: cargoInputs,
138
+ })
192
139
  }
193
140
 
194
- sellAllCargo(ship: Ship | UInt64Type, cargo?: SellableCargo[]): Action[] {
195
- let shipCargo: SellableCargo[]
196
-
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
- }
205
-
206
- const shipId = ship instanceof Ship ? ship.id : UInt64.from(ship)
141
+ deploy(
142
+ entityType: EntityTypeName,
143
+ entityId: UInt64Type,
144
+ packedItemId: number,
145
+ seed: bigint,
146
+ entityName: string
147
+ ): Action {
148
+ return this.server.action('deploy', {
149
+ entity_type: entityType,
150
+ id: UInt64.from(entityId),
151
+ packed_item_id: UInt16.from(packedItemId),
152
+ seed: UInt64.from(seed),
153
+ entity_name: entityName,
154
+ })
155
+ }
207
156
 
208
- return shipCargo
209
- .filter((c) => c.hasCargo)
210
- .map((c) => this.sellItems(shipId, c.item_id, c.quantity, EntityType.SHIP))
157
+ joinGame(account: NameType, companyName: string): Action[] {
158
+ return [this.foundCompany(account, companyName), this.join(account)]
211
159
  }
212
160
  }
@@ -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,
@@ -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
  }
@@ -20,10 +20,6 @@ export interface LoaderCapability {
20
20
  loaders: ServerContract.Types.loader_stats
21
21
  }
22
22
 
23
- export interface TradeCapability {
24
- trade: ServerContract.Types.trade_stats
25
- }
26
-
27
23
  export interface ExtractorCapability {
28
24
  extractor: ServerContract.Types.extractor_stats
29
25
  }
@@ -42,8 +38,8 @@ export interface EntityCapabilities {
42
38
  engines?: ServerContract.Types.movement_stats
43
39
  generator?: ServerContract.Types.energy_stats
44
40
  loaders?: ServerContract.Types.loader_stats
45
- trade?: ServerContract.Types.trade_stats
46
41
  extractor?: ServerContract.Types.extractor_stats
42
+ crafter?: ServerContract.Types.crafter_stats
47
43
  }
48
44
 
49
45
  export interface EntityState {
@@ -66,10 +62,6 @@ export function capsHasLoaders(caps: EntityCapabilities): boolean {
66
62
  return caps.loaders !== undefined
67
63
  }
68
64
 
69
- export function capsHasTrade(caps: EntityCapabilities): boolean {
70
- return caps.trade !== undefined
71
- }
72
-
73
65
  export function capsHasExtractor(caps: EntityCapabilities): boolean {
74
66
  return caps.extractor !== undefined
75
67
  }
@@ -11,7 +11,6 @@ export interface EntityTraits {
11
11
  isMovable: boolean
12
12
  hasEnergy: boolean
13
13
  hasLoaders: boolean
14
- hasTrade: boolean
15
14
  notFoundError: string
16
15
  }
17
16
 
@@ -20,7 +19,7 @@ export const shipTraits: EntityTraits = {
20
19
  isMovable: true,
21
20
  hasEnergy: true,
22
21
  hasLoaders: true,
23
- hasTrade: true,
22
+
24
23
  notFoundError: 'ship not found',
25
24
  }
26
25
 
@@ -29,7 +28,7 @@ export const warehouseTraits: EntityTraits = {
29
28
  isMovable: false,
30
29
  hasEnergy: false,
31
30
  hasLoaders: true,
32
- hasTrade: false,
31
+
33
32
  notFoundError: 'warehouse not found',
34
33
  }
35
34
 
@@ -38,7 +37,7 @@ export const containerTraits: EntityTraits = {
38
37
  isMovable: true,
39
38
  hasEnergy: false,
40
39
  hasLoaders: false,
41
- hasTrade: false,
40
+
42
41
  notFoundError: 'container not found',
43
42
  }
44
43
 
@@ -25,7 +25,6 @@ export type ShipEntity = Entity &
25
25
  LoaderCapability &
26
26
  MassCapability &
27
27
  ScheduleCapability & {
28
- trade?: ServerContract.Types.trade_stats
29
28
  extractor?: ServerContract.Types.extractor_stats
30
29
  }
31
30
 
package/src/types.ts CHANGED
@@ -12,7 +12,6 @@ import {ServerContract} from './contracts'
12
12
 
13
13
  export const PRECISION = 10000
14
14
 
15
- // Ship constants
16
15
  export const INITIAL_SHIP_GENERATOR_CAPACITY = 350
17
16
  export const INITIAL_SHIP_DRAIN = 25
18
17
  export const INITIAL_SHIP_ENERGY = 350
@@ -22,31 +21,24 @@ export const INITIAL_SHIP_Z = 800
22
21
  export const INITIAL_SHIP_RECHARGE = 10
23
22
  export const INITIAL_SHIP_THRUST = 250
24
23
 
25
- // Loader constants
26
24
  export const INITIAL_LOADER_MASS = 1000
27
25
  export const INITIAL_LOADER_QUANTITY = 1
28
26
  export const INITIAL_LOADER_THRUST = 1
29
27
 
30
- // Warehouse constants
31
28
  export const WAREHOUSE_Z = 500
32
29
  export const INITIAL_WAREHOUSE_CAPACITY = 10000000
33
30
 
34
- // Container constants
35
31
  export const CONTAINER_Z = 300
36
32
  export const INITIAL_CONTAINER_HULLMASS = 50000
37
33
  export const INITIAL_CONTAINER_CAPACITY = 2000000
38
34
 
39
- // Mechanics
40
35
  export const TRAVEL_MAX_DURATION = 86400
41
36
 
42
- // Altitude limits (for UI/calculations)
43
37
  export const MIN_ORBITAL_ALTITUDE = 800
44
38
  export const MAX_ORBITAL_ALTITUDE = 3000
45
39
 
46
- // Legacy alias (deprecated, use INITIAL_SHIP_CAPACITY)
47
40
  export const INITIAL_SHIP_MASS = 500000
48
41
 
49
- // Extractor constants
50
42
  export const INITIAL_EXTRACTOR_RATE = 700
51
43
  export const INITIAL_EXTRACTOR_DRAIN = 2500
52
44
  export const INITIAL_EXTRACTOR_EFFICIENCY = 5000
@@ -74,6 +66,8 @@ export enum TaskType {
74
66
  UNLOAD = 4,
75
67
  EXTRACT = 5,
76
68
  WARP = 6,
69
+ CRAFT = 7,
70
+ DEPLOY = 8,
77
71
  }
78
72
 
79
73
  export enum LocationType {
@@ -84,9 +78,9 @@ export enum LocationType {
84
78
  }
85
79
 
86
80
  export enum TaskCancelable {
87
- NEVER = 0, // Task cannot be cancelled
88
- BEFORE_START = 1, // Task can only be cancelled before it starts
89
- ALWAYS = 2, // Task can always be cancelled
81
+ NEVER = 0,
82
+ BEFORE_START = 1,
83
+ ALWAYS = 2,
90
84
  }
91
85
 
92
86
  export const EntityType = {
@@ -144,8 +138,6 @@ export class Item extends Struct {
144
138
  @Struct.field('string')
145
139
  description!: string
146
140
  @Struct.field(UInt32)
147
- base_price!: UInt32
148
- @Struct.field(UInt32)
149
141
  mass!: UInt32
150
142
  @Struct.field('string')
151
143
  category!: ResourceCategory
@@ -154,15 +146,3 @@ export class Item extends Struct {
154
146
  @Struct.field('string')
155
147
  color!: string
156
148
  }
157
-
158
- @Struct.type('ItemPrice')
159
- export class ItemPrice extends Struct {
160
- @Struct.field(UInt16)
161
- id!: UInt16
162
- @Struct.field(Item)
163
- item!: Item
164
- @Struct.field(UInt32)
165
- price!: UInt32
166
- @Struct.field(UInt16)
167
- supply!: UInt16
168
- }
@@ -2,6 +2,7 @@ import {Checksum256, Checksum256Type, Checksum512, UInt8} from '@wharfkit/antelo
2
2
  import {hash512} from './hash'
3
3
  import {Coordinates, CoordinatesType, LocationType} from '../types'
4
4
  import {ServerContract} from '../contracts'
5
+ import {deriveLocationSize} from '../derivation/location-size'
5
6
  import syllables from '../data/syllables.json'
6
7
  import nebulaAdjectives from '../data/nebula-adjectives.json'
7
8
  import nebulaNouns from '../data/nebula-nouns.json'
@@ -116,9 +117,7 @@ export function deriveLocationStatic(
116
117
  }
117
118
 
118
119
  loc.subtype = UInt8.from(
119
- Number(loc.type) === LocationType.PLANET
120
- ? hashResult.array[2] % 6
121
- : hashResult.array[2]
120
+ Number(loc.type) === LocationType.PLANET ? hashResult.array[2] % 6 : hashResult.array[2]
122
121
  )
123
122
  loc.seed0 = UInt8.from(hashResult.array[3])
124
123
  loc.seed1 = UInt8.from(hashResult.array[4])
@@ -147,8 +146,10 @@ export function deriveLocation(
147
146
  epochSeed: Checksum256Type,
148
147
  coordinates: CoordinatesType
149
148
  ): ServerContract.Types.location_derived {
149
+ const staticProps = deriveLocationStatic(gameSeed, coordinates)
150
150
  return ServerContract.Types.location_derived.from({
151
- static_props: deriveLocationStatic(gameSeed, coordinates),
151
+ static_props: staticProps,
152
152
  epoch_props: deriveLocationEpoch(epochSeed, coordinates),
153
+ size: deriveLocationSize(staticProps),
153
154
  })
154
155
  }
@@ -1,119 +0,0 @@
1
- import {UInt64} from '@wharfkit/antelope'
2
- import {BaseManager} from './base'
3
- import {Ship} from '../entities/ship'
4
- import {Deal, findDealsForShip, FindDealsOptions} from '../trading/deal'
5
- import {
6
- analyzeCollectOptions,
7
- CollectAnalysis,
8
- CollectAnalysisCallbacks,
9
- CollectAnalysisOptions,
10
- } from '../trading/collect'
11
- import {Coordinates, ItemPrice} from '../types'
12
- import {Location, toLocation} from '../entities/location'
13
- import {findNearbyPlanets} from '../travel/travel'
14
- import {getCurrentEpoch} from '../scheduling/epoch'
15
-
16
- export class TradesManager extends BaseManager {
17
- private priceCache = new Map<string, ItemPrice[]>()
18
- private priceCacheEpoch: UInt64 | undefined
19
-
20
- private makePriceCacheKey(location: Coordinates): string {
21
- return `${location.x},${location.y}`
22
- }
23
-
24
- private async createCallbacks(): Promise<CollectAnalysisCallbacks> {
25
- const game = await this.getGame()
26
- const serverState = await this.getState()
27
- const currentEpoch = getCurrentEpoch(game)
28
-
29
- if (!this.priceCacheEpoch || !this.priceCacheEpoch.equals(currentEpoch)) {
30
- this.priceCache.clear()
31
- this.priceCacheEpoch = currentEpoch
32
- }
33
-
34
- const getNearbyLocations = async (
35
- origin: Coordinates,
36
- maxDistance: number
37
- ): Promise<Location[]> => {
38
- const nearby = findNearbyPlanets(game.config.seed, origin, maxDistance)
39
- return nearby.map((d) => toLocation(d.destination))
40
- }
41
-
42
- const getMarketPrices = async (location: Coordinates): Promise<ItemPrice[]> => {
43
- const cacheKey = this.makePriceCacheKey(location)
44
- const cached = this.priceCache.get(cacheKey)
45
- if (cached) {
46
- return cached
47
- }
48
-
49
- const locationWithSupply = await this.context.locations.getLocationComplete(location)
50
- const prices = locationWithSupply.marketPrices || []
51
-
52
- const result = prices.map((price) => {
53
- const actualSupply = locationWithSupply.getSupply(price.id)
54
-
55
- if (actualSupply !== undefined) {
56
- return ItemPrice.from({
57
- id: price.id,
58
- item: price.item,
59
- price: price.price,
60
- supply: actualSupply,
61
- })
62
- }
63
- return price
64
- })
65
-
66
- this.priceCache.set(cacheKey, result)
67
- return result
68
- }
69
-
70
- const getGameSeed = () => game.config.seed
71
- const getState = () => serverState
72
-
73
- return {getNearbyLocations, getMarketPrices, getGameSeed, getState}
74
- }
75
-
76
- clearPriceCache(): void {
77
- this.priceCache.clear()
78
- this.priceCacheEpoch = undefined
79
- }
80
-
81
- async findDeals(
82
- ship: Ship,
83
- originLocation?: Coordinates,
84
- options: FindDealsOptions = {}
85
- ): Promise<Deal[]> {
86
- const origin = originLocation || Coordinates.from(ship.coordinates)
87
- const callbacks = await this.createCallbacks()
88
-
89
- const deals = await findDealsForShip(
90
- ship,
91
- origin,
92
- callbacks.getNearbyLocations,
93
- callbacks.getMarketPrices,
94
- options
95
- )
96
-
97
- return deals
98
- }
99
-
100
- async findBestDeal(
101
- ship: Ship,
102
- originLocation?: Coordinates,
103
- options: FindDealsOptions = {}
104
- ): Promise<Deal | undefined> {
105
- const deals = await this.findDeals(ship, originLocation, {...options, maxDeals: 1})
106
- return deals[0]
107
- }
108
-
109
- async getCollectOptions(
110
- ship: Ship,
111
- arrivedAt?: Coordinates,
112
- options: CollectAnalysisOptions = {}
113
- ): Promise<CollectAnalysis> {
114
- const location = arrivedAt || Coordinates.from(ship.coordinates)
115
- const callbacks = await this.createCallbacks()
116
-
117
- return analyzeCollectOptions(ship, location, callbacks, options)
118
- }
119
- }