@shipload/sdk 2.0.0-rc1 → 2.0.0-rc11

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 (74) hide show
  1. package/lib/shipload.d.ts +1701 -1183
  2. package/lib/shipload.js +6746 -3447
  3. package/lib/shipload.js.map +1 -1
  4. package/lib/shipload.m.js +6429 -3229
  5. package/lib/shipload.m.js.map +1 -1
  6. package/package.json +6 -6
  7. package/src/capabilities/crafting.ts +26 -0
  8. package/src/capabilities/gathering.ts +36 -0
  9. package/src/capabilities/guards.ts +38 -0
  10. package/src/capabilities/hauling.ts +22 -0
  11. package/src/capabilities/index.ts +8 -0
  12. package/src/capabilities/loading.ts +8 -0
  13. package/src/capabilities/modules.ts +57 -0
  14. package/src/capabilities/movement.ts +29 -0
  15. package/src/capabilities/storage.ts +72 -0
  16. package/src/contracts/server.ts +932 -314
  17. package/src/data/capabilities.ts +408 -0
  18. package/src/data/categories.ts +58 -0
  19. package/src/data/colors.ts +53 -0
  20. package/src/data/items.json +17 -0
  21. package/src/data/locations.ts +53 -0
  22. package/src/data/nebula-adjectives.json +211 -0
  23. package/src/data/nebula-nouns.json +151 -0
  24. package/src/data/recipes.ts +571 -0
  25. package/src/data/syllables.json +1386 -780
  26. package/src/data/tiers.ts +45 -0
  27. package/src/derivation/crafting.ts +197 -0
  28. package/src/derivation/index.ts +28 -0
  29. package/src/derivation/location-size.ts +15 -0
  30. package/src/derivation/resources.ts +142 -0
  31. package/src/derivation/stats.ts +146 -0
  32. package/src/derivation/stratum.ts +124 -0
  33. package/src/entities/cargo-utils.ts +46 -9
  34. package/src/entities/container.ts +106 -0
  35. package/src/entities/entity-inventory.ts +13 -13
  36. package/src/entities/inventory-accessor.ts +42 -0
  37. package/src/entities/location.ts +7 -188
  38. package/src/entities/makers.ts +72 -0
  39. package/src/entities/player.ts +1 -273
  40. package/src/entities/ship-deploy.ts +263 -0
  41. package/src/entities/ship.ts +93 -453
  42. package/src/entities/warehouse.ts +34 -148
  43. package/src/errors.ts +4 -4
  44. package/src/index-module.ts +226 -42
  45. package/src/managers/actions.ts +111 -79
  46. package/src/managers/context.ts +0 -9
  47. package/src/managers/entities.ts +22 -5
  48. package/src/managers/index.ts +0 -1
  49. package/src/managers/locations.ts +15 -79
  50. package/src/market/items.ts +30 -0
  51. package/src/nft/description.ts +175 -0
  52. package/src/nft/deserializers.ts +81 -0
  53. package/src/nft/index.ts +2 -0
  54. package/src/resolution/resolve-item.ts +313 -0
  55. package/src/scheduling/accessor.ts +82 -0
  56. package/src/scheduling/projection.ts +158 -54
  57. package/src/scheduling/schedule.ts +24 -0
  58. package/src/shipload.ts +0 -5
  59. package/src/travel/travel.ts +93 -19
  60. package/src/types/capabilities.ts +71 -0
  61. package/src/types/entity-traits.ts +69 -0
  62. package/src/types/entity.ts +39 -0
  63. package/src/types/index.ts +3 -0
  64. package/src/types.ts +76 -33
  65. package/src/utils/hash.ts +1 -1
  66. package/src/utils/system.ts +148 -11
  67. package/src/data/goods.json +0 -23
  68. package/src/managers/trades.ts +0 -119
  69. package/src/market/goods.ts +0 -31
  70. package/src/market/market.ts +0 -209
  71. package/src/market/rolls.ts +0 -8
  72. package/src/trading/collect.ts +0 -939
  73. package/src/trading/deal.ts +0 -208
  74. package/src/trading/trade.ts +0 -203
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@shipload/sdk",
3
3
  "description": "SDKs for Shipload",
4
- "version": "2.0.0-rc1",
4
+ "version": "2.0.0-rc11",
5
5
  "homepage": "https://github.com/shipload/sdk",
6
6
  "license": "MIT",
7
7
  "main": "lib/shipload.js",
8
8
  "module": "lib/shipload.m.js",
9
9
  "types": "lib/shipload.d.ts",
10
- "unpkg": "lib/shipload.bundle.js",
11
10
  "sideEffects": false,
12
11
  "files": [
13
12
  "lib/*",
@@ -17,7 +16,7 @@
17
16
  "prepare": "make"
18
17
  },
19
18
  "dependencies": {
20
- "@wharfkit/antelope": "^1.1.1",
19
+ "@wharfkit/antelope": "1.2.0",
21
20
  "@wharfkit/contract": "^1.2.1",
22
21
  "@wharfkit/session": "^1.3.1",
23
22
  "tslib": "^2.1.0"
@@ -57,8 +56,9 @@
57
56
  "tsconfig-paths": "^4.1.1",
58
57
  "typedoc": "^0.23.14",
59
58
  "typedoc-plugin-mermaid": "^1.10.0",
60
- "typescript": "^4.1.2",
61
- "yarn-deduplicate": "^6.0.2"
59
+ "typescript": "^4.1.2"
62
60
  },
63
- "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
61
+ "overrides": {
62
+ "@wharfkit/antelope": "1.2.0"
63
+ }
64
64
  }
@@ -0,0 +1,26 @@
1
+ import {UInt16, UInt32} from '@wharfkit/antelope'
2
+ import {CRAFT_ENERGY_DIVISOR} from '../types'
3
+ import type {EntityCapabilities} from '../types/capabilities'
4
+ import {ServerContract} from '../contracts'
5
+
6
+ export interface CrafterCapability {
7
+ crafter: ServerContract.Types.crafter_stats
8
+ }
9
+
10
+ export function capsHasCrafter(caps: EntityCapabilities): boolean {
11
+ return caps.crafter !== undefined
12
+ }
13
+
14
+ export function calc_craft_duration(
15
+ speed: number,
16
+ totalInputMass: number,
17
+ quantity: number
18
+ ): UInt32 {
19
+ const duration = Math.floor((totalInputMass * quantity) / speed)
20
+ return UInt32.from(Math.max(duration, 1))
21
+ }
22
+
23
+ export function calc_craft_energy(drain: number, totalInputMass: number): UInt16 {
24
+ const raw = Math.floor((totalInputMass * drain) / CRAFT_ENERGY_DIVISOR)
25
+ return UInt16.from(Math.min(raw, 65535))
26
+ }
@@ -0,0 +1,36 @@
1
+ import {UInt16, UInt32} from '@wharfkit/antelope'
2
+ import {ServerContract} from '../contracts'
3
+ import {PRECISION} from '../types'
4
+
5
+ const GATHER_TIME_SCALE = 100
6
+ const DEPTH_PENALTY_DIVISOR = 5000
7
+ const SPEED_TIME_SCALE = 300
8
+
9
+ export function calc_gather_duration(
10
+ gatherer: ServerContract.Types.gatherer_stats,
11
+ itemMass: number,
12
+ quantity: number,
13
+ stratum: number,
14
+ richness: number
15
+ ): UInt32 {
16
+ const yieldValue = gatherer.yield.toNumber()
17
+ const speed = gatherer.speed.toNumber()
18
+
19
+ if (yieldValue === 0 || speed === 0 || richness === 0) return UInt32.from(0)
20
+
21
+ const massFactor = Math.sqrt(itemMass)
22
+ const depthPenalty = 1 + stratum / DEPTH_PENALTY_DIVISOR
23
+ const richnessMul = richness / 1000
24
+ const gatherTime =
25
+ (quantity * massFactor * GATHER_TIME_SCALE * depthPenalty) / (yieldValue * richnessMul)
26
+ const speedTime = SPEED_TIME_SCALE * Math.log(1 + stratum / speed)
27
+ return UInt32.from(Math.floor(gatherTime + speedTime))
28
+ }
29
+
30
+ export function calc_gather_energy(
31
+ gatherer: ServerContract.Types.gatherer_stats,
32
+ duration: number
33
+ ): UInt16 {
34
+ const energy = Math.floor((duration * gatherer.drain.toNumber()) / PRECISION)
35
+ return UInt16.from(energy)
36
+ }
@@ -0,0 +1,38 @@
1
+ import {
2
+ EnergyCapability,
3
+ GathererCapability,
4
+ LoaderCapability,
5
+ MassCapability,
6
+ MovementCapability,
7
+ ScheduleCapability,
8
+ StorageCapability,
9
+ } from '../types/capabilities'
10
+ import {Entity} from '../types/entity'
11
+
12
+ export function canMove(e: Entity): e is Entity & MovementCapability & EnergyCapability {
13
+ return 'engines' in e && 'generator' in e && 'energy' in e
14
+ }
15
+
16
+ export function hasEnergy(e: Entity): e is Entity & EnergyCapability {
17
+ return 'energy' in e
18
+ }
19
+
20
+ export function hasStorage(e: Entity): e is Entity & StorageCapability {
21
+ return 'capacity' in e && 'cargo' in e
22
+ }
23
+
24
+ export function hasLoaders(e: Entity): e is Entity & LoaderCapability {
25
+ return 'loaders' in e && e.loaders !== undefined
26
+ }
27
+
28
+ export function hasMass(e: Entity): e is Entity & MassCapability {
29
+ return 'hullmass' in e
30
+ }
31
+
32
+ export function hasSchedule(e: Entity): e is Entity & ScheduleCapability {
33
+ return 'schedule' in e
34
+ }
35
+
36
+ export function hasGatherer(e: Entity): e is Entity & GathererCapability {
37
+ return 'gatherer' in e && e.gatherer !== undefined
38
+ }
@@ -0,0 +1,22 @@
1
+ const BASE_HAUL_PENALTY_MILLI = 300
2
+ const HAULER_EFFICIENCY_DENOM = 10000
3
+ const PRECISION = 10000
4
+
5
+ export function computeHaulPenalty(
6
+ totalThrust: number,
7
+ haulCount: number,
8
+ avgEfficiency: number
9
+ ): number {
10
+ if (haulCount === 0) return totalThrust
11
+ const penaltyMilli =
12
+ 1000 +
13
+ Math.floor(
14
+ (haulCount * BASE_HAUL_PENALTY_MILLI * (HAULER_EFFICIENCY_DENOM - avgEfficiency)) /
15
+ HAULER_EFFICIENCY_DENOM
16
+ )
17
+ return Math.floor((totalThrust * 1000) / penaltyMilli)
18
+ }
19
+
20
+ export function computeHaulerDrain(distance: number, drain: number, haulCount: number): number {
21
+ return Math.floor(distance / PRECISION) * drain * haulCount
22
+ }
@@ -0,0 +1,8 @@
1
+ export * from './guards'
2
+ export * from './movement'
3
+ export * from './storage'
4
+ export * from './loading'
5
+ export * from './gathering'
6
+ export * from './crafting'
7
+ export * from './modules'
8
+ export * from './hauling'
@@ -0,0 +1,8 @@
1
+ import {UInt32, UInt64} from '@wharfkit/antelope'
2
+ import {LoaderCapability} from '../types/capabilities'
3
+
4
+ export function calcLoadDuration(entity: LoaderCapability, cargoMass: UInt64): UInt32 {
5
+ const totalThrust = entity.loaders.thrust.toNumber() * entity.loaders.quantity.toNumber()
6
+ if (totalThrust === 0) return UInt32.from(0)
7
+ return UInt32.from(Math.ceil(Number(cargoMass) / totalThrust))
8
+ }
@@ -0,0 +1,57 @@
1
+ export const ITEM_ENGINE_T1 = 10100
2
+ export const ITEM_GENERATOR_T1 = 10101
3
+ export const ITEM_GATHERER_T1 = 10102
4
+ export const ITEM_LOADER_T1 = 10103
5
+ export const ITEM_MANUFACTURING_T1 = 10104
6
+ export const ITEM_STORAGE_T1 = 10105
7
+ export const ITEM_HAULER_T1 = 10106
8
+
9
+ export const MODULE_ANY = 0
10
+ export const MODULE_ENGINE = 1
11
+ export const MODULE_GENERATOR = 2
12
+ export const MODULE_GATHERER = 3
13
+ export const MODULE_LOADER = 4
14
+ export const MODULE_WARP = 5
15
+ export const MODULE_CRAFTER = 6
16
+ export const MODULE_LAUNCHER = 7
17
+ export const MODULE_STORAGE = 8
18
+ export const MODULE_HAULER = 9
19
+
20
+ export interface CargoSeed {
21
+ itemId: number
22
+ seed: bigint
23
+ }
24
+
25
+ export interface ModuleEntry {
26
+ type: number
27
+ installed?: CargoSeed
28
+ }
29
+
30
+ export function moduleAccepts(slotType: number, moduleType: number): boolean {
31
+ return slotType === MODULE_ANY || slotType === moduleType
32
+ }
33
+
34
+ export function getModuleCapabilityType(itemId: number): number {
35
+ switch (itemId) {
36
+ case ITEM_ENGINE_T1:
37
+ return MODULE_ENGINE
38
+ case ITEM_GENERATOR_T1:
39
+ return MODULE_GENERATOR
40
+ case ITEM_GATHERER_T1:
41
+ return MODULE_GATHERER
42
+ case ITEM_LOADER_T1:
43
+ return MODULE_LOADER
44
+ case ITEM_MANUFACTURING_T1:
45
+ return MODULE_CRAFTER
46
+ case ITEM_STORAGE_T1:
47
+ return MODULE_STORAGE
48
+ case ITEM_HAULER_T1:
49
+ return MODULE_HAULER
50
+ default:
51
+ return 0xff
52
+ }
53
+ }
54
+
55
+ export function isModuleItem(itemId: number): boolean {
56
+ return getModuleCapabilityType(itemId) !== 0xff
57
+ }
@@ -0,0 +1,29 @@
1
+ import {UInt32, UInt64} from '@wharfkit/antelope'
2
+ import {EnergyCapability, MovementCapability} from '../types/capabilities'
3
+ import {PRECISION} from '../types'
4
+
5
+ export function maxTravelDistance(entity: MovementCapability): UInt32 {
6
+ return UInt32.from(entity.generator.capacity)
7
+ .dividing(entity.engines.drain)
8
+ .multiplying(PRECISION)
9
+ }
10
+
11
+ export function calcEnergyUsage(entity: MovementCapability, distance: UInt64): UInt64 {
12
+ return distance.dividing(PRECISION).multiplying(entity.engines.drain)
13
+ }
14
+
15
+ export function hasEnergyForDistance(
16
+ entity: MovementCapability & EnergyCapability,
17
+ distance: UInt64
18
+ ): boolean {
19
+ const usage = calcEnergyUsage(entity, distance)
20
+ return UInt64.from(entity.energy).gte(usage)
21
+ }
22
+
23
+ export function energyPercent(entity: MovementCapability & EnergyCapability): number {
24
+ return (Number(entity.energy) / Number(entity.generator.capacity)) * 100
25
+ }
26
+
27
+ export function needsRecharge(entity: MovementCapability & EnergyCapability): boolean {
28
+ return UInt64.from(entity.energy).lt(entity.generator.capacity)
29
+ }
@@ -0,0 +1,72 @@
1
+ import {UInt32, UInt64, UInt64Type} from '@wharfkit/antelope'
2
+ import {ServerContract} from '../contracts'
3
+ import {StorageCapability} from '../types/capabilities'
4
+ import {getItem} from '../market/items'
5
+
6
+ export interface HasCargo {
7
+ cargo: ServerContract.Types.cargo_item[]
8
+ }
9
+
10
+ export interface HasCapacity {
11
+ capacity: UInt32
12
+ }
13
+
14
+ export interface HasCargomass {
15
+ cargomass: UInt32
16
+ }
17
+
18
+ export function calcCargoItemMass(item: ServerContract.Types.cargo_item): UInt64 {
19
+ const itemDef = getItem(item.item_id)
20
+ let mass = UInt64.from(itemDef.mass).multiplying(item.quantity)
21
+
22
+ for (const mod of item.modules) {
23
+ if (mod.installed) {
24
+ const modDef = getItem(mod.installed.item_id)
25
+ mass = mass.adding(modDef.mass)
26
+ }
27
+ }
28
+
29
+ return mass
30
+ }
31
+
32
+ export function calcCargoMass(entity: HasCargo): UInt64 {
33
+ let mass = UInt64.from(0)
34
+ for (const item of entity.cargo) {
35
+ mass = mass.adding(calcCargoItemMass(item))
36
+ }
37
+ return mass
38
+ }
39
+
40
+ export function availableCapacity(entity: StorageCapability): UInt64 {
41
+ const cargoMass = calcCargoMass(entity)
42
+ return entity.capacity.gt(cargoMass)
43
+ ? UInt64.from(entity.capacity).subtracting(cargoMass)
44
+ : UInt64.from(0)
45
+ }
46
+
47
+ export function availableCapacityFromMass(capacity: UInt64Type, cargoMass: UInt64Type): UInt64 {
48
+ const cap = UInt64.from(capacity)
49
+ const mass = UInt64.from(cargoMass)
50
+ return cap.gt(mass) ? cap.subtracting(mass) : UInt64.from(0)
51
+ }
52
+
53
+ export function hasSpace(entity: StorageCapability, goodMass: UInt64, quantity: number): boolean {
54
+ const additional = goodMass.multiplying(quantity)
55
+ return availableCapacity(entity).gte(additional)
56
+ }
57
+
58
+ export function hasSpaceForMass(
59
+ capacity: UInt64Type,
60
+ currentMass: UInt64Type,
61
+ additionalMass: UInt64Type
62
+ ): boolean {
63
+ return UInt64.from(currentMass).adding(additionalMass).lte(capacity)
64
+ }
65
+
66
+ export function isFull(entity: HasCapacity & HasCargomass): boolean {
67
+ return UInt64.from(entity.cargomass).gte(entity.capacity)
68
+ }
69
+
70
+ export function isFullFromMass(capacity: UInt64Type, cargoMass: UInt64Type): boolean {
71
+ return UInt64.from(cargoMass).gte(capacity)
72
+ }