@shipload/sdk 2.0.0-rc2 → 2.0.0-rc21

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