@shipload/sdk 0.7.1 → 1.0.0-beta1

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 (94) hide show
  1. package/lib/shipload.d.ts +2730 -287
  2. package/lib/shipload.js +10862 -2229
  3. package/lib/shipload.js.map +1 -1
  4. package/lib/shipload.m.js +10434 -2171
  5. package/lib/shipload.m.js.map +1 -1
  6. package/package.json +11 -20
  7. package/src/capabilities/crafting.ts +22 -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 +86 -0
  14. package/src/capabilities/movement.ts +29 -0
  15. package/src/capabilities/storage.ts +159 -0
  16. package/src/contracts/server.ts +1389 -285
  17. package/src/data/capabilities.ts +408 -0
  18. package/src/data/catalog.ts +135 -0
  19. package/src/data/categories.ts +55 -0
  20. package/src/data/colors.ts +84 -0
  21. package/src/data/entities.json +50 -0
  22. package/src/data/item-ids.ts +75 -0
  23. package/src/data/items.json +252 -0
  24. package/src/data/locations.ts +53 -0
  25. package/src/data/metadata.ts +208 -0
  26. package/src/data/nebula-adjectives.json +211 -0
  27. package/src/data/nebula-nouns.json +151 -0
  28. package/src/data/recipes-runtime.ts +65 -0
  29. package/src/data/recipes.json +878 -0
  30. package/src/data/syllables.json +1790 -0
  31. package/src/data/tiers.ts +45 -0
  32. package/src/derivation/crafting.ts +350 -0
  33. package/src/derivation/index.ts +32 -0
  34. package/src/derivation/location-size.ts +15 -0
  35. package/src/derivation/resources.ts +112 -0
  36. package/src/derivation/stats.ts +146 -0
  37. package/src/derivation/strata.ts +43 -0
  38. package/src/derivation/stratum.ts +134 -0
  39. package/src/derivation/tiers.ts +54 -0
  40. package/src/entities/cargo-utils.ts +84 -0
  41. package/src/entities/container.ts +108 -0
  42. package/src/entities/entity-inventory.ts +39 -0
  43. package/src/entities/gamestate.ts +152 -0
  44. package/src/entities/inventory-accessor.ts +42 -0
  45. package/src/entities/location.ts +60 -0
  46. package/src/entities/makers.ts +196 -0
  47. package/src/entities/player.ts +15 -0
  48. package/src/entities/ship-deploy.ts +258 -0
  49. package/src/entities/ship.ts +204 -0
  50. package/src/entities/warehouse.ts +119 -0
  51. package/src/errors.ts +100 -9
  52. package/src/format.ts +12 -0
  53. package/src/index-module.ts +317 -7
  54. package/src/managers/actions.ts +250 -0
  55. package/src/managers/base.ts +25 -0
  56. package/src/managers/context.ts +114 -0
  57. package/src/managers/entities.ts +103 -0
  58. package/src/managers/epochs.ts +47 -0
  59. package/src/managers/index.ts +9 -0
  60. package/src/managers/locations.ts +68 -0
  61. package/src/managers/players.ts +13 -0
  62. package/src/nft/description.ts +176 -0
  63. package/src/nft/deserializers.ts +83 -0
  64. package/src/nft/index.ts +2 -0
  65. package/src/resolution/describe-module.ts +166 -0
  66. package/src/resolution/display-name.ts +39 -0
  67. package/src/resolution/resolve-item.ts +358 -0
  68. package/src/scheduling/accessor.ts +82 -0
  69. package/src/{epoch.ts → scheduling/epoch.ts} +1 -1
  70. package/src/scheduling/projection.ts +463 -0
  71. package/src/scheduling/schedule.ts +179 -0
  72. package/src/shipload.ts +47 -160
  73. package/src/subscriptions/connection.ts +154 -0
  74. package/src/subscriptions/debug.ts +17 -0
  75. package/src/subscriptions/index.ts +5 -0
  76. package/src/subscriptions/manager.ts +240 -0
  77. package/src/subscriptions/mappers.ts +28 -0
  78. package/src/subscriptions/types.ts +143 -0
  79. package/src/travel/travel.ts +500 -0
  80. package/src/types/capabilities.ts +76 -0
  81. package/src/types/entity-traits.ts +69 -0
  82. package/src/types/entity.ts +39 -0
  83. package/src/types/index.ts +3 -0
  84. package/src/types.ts +140 -35
  85. package/src/{hash.ts → utils/hash.ts} +2 -2
  86. package/src/utils/system.ts +168 -0
  87. package/src/goods.ts +0 -124
  88. package/src/market.ts +0 -214
  89. package/src/rolls.ts +0 -8
  90. package/src/ship.ts +0 -36
  91. package/src/state.ts +0 -0
  92. package/src/syllables.ts +0 -1184
  93. package/src/system.ts +0 -37
  94. package/src/travel.ts +0 -259
package/src/market.ts DELETED
@@ -1,214 +0,0 @@
1
- import {Coordinates, GoodPrice} from './types'
2
- import {getGood, getGoods} from './goods'
3
- import {Checksum256Type, UInt16Type, UInt64} from '@wharfkit/antelope'
4
- import {roll} from './rolls'
5
- import {ServerContract} from './contracts'
6
-
7
- export enum Rarities {
8
- legendary = 'LEGENDARY',
9
- epic = 'EPIC',
10
- rare = 'RARE',
11
- uncommon = 'UNCOMMON',
12
- common = 'COMMON',
13
- trash = 'TRASH',
14
- }
15
-
16
- export interface Rarity {
17
- rarity: Rarities // The rarity description of this price
18
- minMultiplier: number // The minimum multiplier for this rarity
19
- maxMultiplier: number // The maximum multiplier for this rarity
20
- }
21
-
22
- export function generateLocationSeed(
23
- epochSeed: Checksum256Type,
24
- location: Coordinates,
25
- entitySalt: string
26
- ) {
27
- return `${epochSeed}${location.x}${location.y}${entitySalt}`
28
- }
29
-
30
- export function getRarity(
31
- gameSeed: Checksum256Type,
32
- epochSeed: Checksum256Type,
33
- location: Coordinates,
34
- good_id: UInt16Type
35
- ): Rarity {
36
- const seed = `${epochSeed}${location.x}${location.y}${good_id}rarity`
37
- const rarityRoll = roll(gameSeed, seed)
38
-
39
- if (rarityRoll < 13) {
40
- // (Orange) ~0.02% chance = incredibly high value
41
- return {
42
- rarity: Rarities.legendary,
43
- minMultiplier: 2.25,
44
- maxMultiplier: 3.0,
45
- }
46
- } else if (rarityRoll < 176) {
47
- // (Purple) ~0.25% chance = super high value
48
- return {
49
- rarity: Rarities.epic,
50
- minMultiplier: 1.75,
51
- maxMultiplier: 2.25,
52
- }
53
- } else if (rarityRoll < 996) {
54
- // (Blue) ~1.25% chance = very high value
55
- return {
56
- rarity: Rarities.rare,
57
- minMultiplier: 1.4,
58
- maxMultiplier: 1.75,
59
- }
60
- } else if (rarityRoll < 2966) {
61
- // (Green) ~3.00% chance = high value
62
- return {
63
- rarity: Rarities.uncommon,
64
- minMultiplier: 1.225,
65
- maxMultiplier: 1.4,
66
- }
67
- } else if (rarityRoll < 19568) {
68
- // (White) ~25.33% chance = slightly higher value
69
- return {
70
- rarity: Rarities.common,
71
- minMultiplier: 1.07,
72
- maxMultiplier: 1.225,
73
- }
74
- } else if (rarityRoll < 45988) {
75
- // ~40.30% chance = no value change
76
- return {
77
- rarity: Rarities.trash,
78
- minMultiplier: 1,
79
- maxMultiplier: 1.07,
80
- } // Product is not available
81
- } else if (rarityRoll < 62508) {
82
- // (White) ~25.33% chance = slightly lower value
83
- return {
84
- rarity: Rarities.common,
85
- minMultiplier: 0.925,
86
- maxMultiplier: 1,
87
- }
88
- } else if (rarityRoll < 64518) {
89
- // (Green) ~3.00% chance = low value
90
- return {
91
- rarity: Rarities.uncommon,
92
- minMultiplier: 0.77,
93
- maxMultiplier: 0.925,
94
- }
95
- } else if (rarityRoll < 65437) {
96
- // (Blue) ~1.25% chance = very low value
97
- return {
98
- rarity: Rarities.rare,
99
- minMultiplier: 0.595,
100
- maxMultiplier: 0.77,
101
- }
102
- } else if (rarityRoll < 65523) {
103
- // (Purple) ~0.25% chance = super low value
104
- return {
105
- rarity: Rarities.epic,
106
- minMultiplier: 0.41,
107
- maxMultiplier: 0.595,
108
- }
109
- } else {
110
- // (Orange) ~0.02% chance = incredibly low value
111
- return {
112
- rarity: Rarities.legendary,
113
- minMultiplier: 0.285,
114
- maxMultiplier: 0.41,
115
- }
116
- }
117
- }
118
-
119
- export function getRarityMultiplier(
120
- gameSeed: Checksum256Type,
121
- epochSeed: Checksum256Type,
122
- location: Coordinates,
123
- good_id: UInt16Type
124
- ): number {
125
- const rarity = getRarity(gameSeed, epochSeed, location, good_id)
126
- const range = rarity.maxMultiplier - rarity.minMultiplier
127
- const seed = `${epochSeed}${location.x}${location.y}${good_id}raritymultiplier`
128
- const r = roll(gameSeed, seed)
129
- return rarity.minMultiplier + (r / 65535) * range
130
- }
131
-
132
- export function getLocationMultiplier(
133
- gameSeed: Checksum256Type,
134
- location: Coordinates,
135
- good_id: UInt16Type
136
- ): number {
137
- const seed = `${location.x}${location.y}${good_id}locationmultiplier`
138
- const r = roll(gameSeed, seed)
139
- if (r < 13) {
140
- return 0.75
141
- } else if (r < 176) {
142
- return 0.8
143
- } else if (r < 996) {
144
- return 0.85
145
- } else if (r < 2966) {
146
- return 0.9
147
- } else if (r < 19568) {
148
- return 0.95
149
- } else if (r < 45988) {
150
- return 1
151
- } else if (r < 62508) {
152
- return 1.05
153
- } else if (r < 64518) {
154
- return 1.1
155
- } else if (r < 65437) {
156
- return 1.15
157
- } else if (r < 65523) {
158
- return 1.2
159
- } else {
160
- return 1.25
161
- }
162
- }
163
-
164
- export function getSupply(
165
- gameSeed: Checksum256Type,
166
- state: ServerContract.Types.state_row,
167
- location: Coordinates,
168
- good_id: UInt16Type
169
- ): number {
170
- const seed = `${state.seed}${location.x}${location.y}${good_id}supply`
171
- const r = roll(gameSeed, seed)
172
- const percent = r / 65535
173
- const epoch = 1 + Number(state.epoch) / 90
174
- const ship = Math.pow(Number(state.ships), 1 / 3)
175
- return UInt64.from((128 / good_id) * percent * ship * epoch).toNumber()
176
- }
177
-
178
- export function marketprice(
179
- location: ServerContract.ActionParams.Type.coordinates,
180
- good_id: UInt16Type,
181
- gameSeed: Checksum256Type,
182
- state: ServerContract.Types.state_row
183
- ): GoodPrice {
184
- const good = getGood(good_id)
185
- let price = Number(good.base_price)
186
-
187
- // Rarity multiplier of the deal (changes with epoch)
188
- // Large impact range on price, from 0.285x to 3.0x
189
- const rarityMultiplier = getRarityMultiplier(gameSeed, state.seed, location, good_id)
190
- price *= rarityMultiplier
191
-
192
- // Location multiplier of the deal (static, based on game seed)
193
- // Small impact range on price, from 1.0x to 1.5x
194
- const locationMultiplier = getLocationMultiplier(gameSeed, location, good_id)
195
- price *= locationMultiplier
196
-
197
- // Determine the current supply of the good at the location
198
- const supply = getSupply(gameSeed, state, location, good_id)
199
-
200
- return GoodPrice.from({
201
- id: good_id,
202
- good,
203
- price: UInt64.from(price),
204
- supply: UInt64.from(supply),
205
- })
206
- }
207
-
208
- export function marketprices(
209
- location: ServerContract.ActionParams.Type.coordinates,
210
- gameSeed: Checksum256Type,
211
- state: ServerContract.Types.state_row
212
- ): GoodPrice[] {
213
- return getGoods().map((good) => marketprice(location, good.id, gameSeed, state))
214
- }
package/src/rolls.ts DELETED
@@ -1,8 +0,0 @@
1
- import {Checksum256Type} from '@wharfkit/antelope'
2
- import {hash512} from './hash'
3
-
4
- export function roll(game_seed: Checksum256Type, roll_seed: string): number {
5
- const hash = hash512(game_seed, roll_seed)
6
- // Combine the first two bytes to form a uint16_t value
7
- return (hash.array[0] << 8) | hash.array[1]
8
- }
package/src/ship.ts DELETED
@@ -1,36 +0,0 @@
1
- import {UInt32} from '@wharfkit/antelope'
2
- import {ServerContract} from './contracts'
3
- import {PRECISION} from './types'
4
- import {travelplanDuration} from './travel'
5
-
6
- export class Ship extends ServerContract.Types.ship_row {
7
- get maxDistance(): UInt32 {
8
- return this.stats.capacity.dividing(this.stats.drain).multiplying(PRECISION)
9
- }
10
-
11
- get traveling(): boolean {
12
- return !!this.travelplan
13
- }
14
-
15
- get arrived(): boolean {
16
- if (!this.travelplan) {
17
- throw new Error('Ship is not traveling')
18
- }
19
- const depart = this.travelplan.departure.toDate()
20
- const arrive = new Date(
21
- depart.getTime() + Number(travelplanDuration(this.travelplan)) * 1000
22
- )
23
- return new Date() >= arrive
24
- }
25
-
26
- get eta(): number {
27
- if (!this.travelplan) {
28
- throw new Error('Ship is not traveling')
29
- }
30
- const depart = this.travelplan.departure.toDate()
31
- const arrive = new Date(
32
- depart.getTime() + Number(travelplanDuration(this.travelplan)) * 1000
33
- )
34
- return arrive.getTime() - new Date().getTime()
35
- }
36
- }
package/src/state.ts DELETED
File without changes