@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
@@ -1,209 +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
- // NOTE: Contract has bug where 1/3 is integer division = 0, so pow(ships, 0) = 1
167
- // TODO: Update this when contract is fixed to use (double)1/(double)3
168
- const ship = Math.pow(Number(state.ships), 0)
169
- const goodIdNum = Number(goodId)
170
- return Math.floor((128 / goodIdNum) * percent * ship * epoch)
171
- }
172
-
173
- export function marketPrice(
174
- location: ServerContract.ActionParams.Type.coordinates,
175
- goodId: UInt16Type,
176
- gameSeed: Checksum256Type,
177
- state: ServerContract.Types.state_row
178
- ): GoodPrice {
179
- const good = getGood(goodId)
180
- let price = Number(good.base_price)
181
-
182
- // Rarity multiplier of the deal (changes with epoch)
183
- // Large impact range on price, from 0.285x to 3.0x
184
- const rarityMultiplier = getRarityMultiplier(gameSeed, state.seed, location, goodId)
185
- price *= rarityMultiplier
186
-
187
- // Location multiplier of the deal (static, based on game seed)
188
- // Small impact range on price, from 1.0x to 1.5x
189
- const locationMultiplier = getLocationMultiplier(gameSeed, location, goodId)
190
- price *= locationMultiplier
191
-
192
- // Determine the current supply of the good at the location
193
- const supply = getSupply(gameSeed, state, location, goodId)
194
-
195
- return GoodPrice.from({
196
- id: goodId,
197
- good,
198
- price: UInt32.from(price),
199
- supply: UInt16.from(supply),
200
- })
201
- }
202
-
203
- export function marketPrices(
204
- location: ServerContract.ActionParams.Type.coordinates,
205
- gameSeed: Checksum256Type,
206
- state: ServerContract.Types.state_row
207
- ): GoodPrice[] {
208
- return getGoods().map((good) => marketPrice(location, good.id, gameSeed, state))
209
- }
@@ -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
- }