@shipload/sdk 2.0.0-rc2 → 2.0.0-rc3

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.
package/src/types.ts CHANGED
@@ -62,7 +62,7 @@ export interface ShipLike {
62
62
  }
63
63
 
64
64
  export interface CargoMassInfo {
65
- good_id: UInt16Type
65
+ item_id: UInt16Type
66
66
  quantity: UInt32Type
67
67
  }
68
68
 
@@ -73,6 +73,7 @@ export enum TaskType {
73
73
  LOAD = 3,
74
74
  UNLOAD = 4,
75
75
  EXTRACT = 5,
76
+ WARP = 6,
76
77
  }
77
78
 
78
79
  export enum LocationType {
@@ -131,8 +132,11 @@ export interface Distance {
131
132
  distance: UInt16
132
133
  }
133
134
 
134
- @Struct.type('good')
135
- export class Good extends Struct {
135
+ export type ResourceCategory = 'metal' | 'gas' | 'mineral' | 'organic'
136
+ export type ResourceRarity = 'common' | 'uncommon' | 'rare' | 'epic' | 'legendary'
137
+
138
+ @Struct.type('item')
139
+ export class Item extends Struct {
136
140
  @Struct.field(UInt16)
137
141
  id!: UInt16
138
142
  @Struct.field('string')
@@ -143,14 +147,20 @@ export class Good extends Struct {
143
147
  base_price!: UInt32
144
148
  @Struct.field(UInt32)
145
149
  mass!: UInt32
150
+ @Struct.field('string')
151
+ category!: ResourceCategory
152
+ @Struct.field('string')
153
+ rarity!: ResourceRarity
154
+ @Struct.field('string')
155
+ color!: string
146
156
  }
147
157
 
148
- @Struct.type('GoodPrice')
149
- export class GoodPrice extends Struct {
158
+ @Struct.type('ItemPrice')
159
+ export class ItemPrice extends Struct {
150
160
  @Struct.field(UInt16)
151
161
  id!: UInt16
152
- @Struct.field(Good)
153
- good!: Good
162
+ @Struct.field(Item)
163
+ item!: Item
154
164
  @Struct.field(UInt32)
155
165
  price!: UInt32
156
166
  @Struct.field(UInt16)
@@ -1,6 +1,6 @@
1
1
  import {Checksum256, Checksum256Type, UInt8} from '@wharfkit/antelope'
2
2
  import {hash512} from './hash'
3
- import {Coordinates, CoordinatesType, LocationType, PRECISION} from '../types'
3
+ import {Coordinates, CoordinatesType, LocationType} from '../types'
4
4
  import {ServerContract} from '../contracts'
5
5
  import syllables from '../data/syllables.json'
6
6
 
@@ -28,7 +28,7 @@ export function getLocationType(
28
28
  }
29
29
 
30
30
  export function isExtractableLocation(locationType: LocationType): boolean {
31
- return locationType === LocationType.ASTEROID || locationType === LocationType.NEBULA
31
+ return locationType !== LocationType.EMPTY
32
32
  }
33
33
 
34
34
  export function getSystemName(gameSeed: Checksum256Type, location: CoordinatesType): string {
@@ -81,7 +81,11 @@ export function deriveLocationStatic(
81
81
  loc.type = UInt8.from(LocationType.NEBULA)
82
82
  }
83
83
 
84
- loc.subtype = UInt8.from(hashResult.array[2])
84
+ loc.subtype = UInt8.from(
85
+ Number(loc.type) === LocationType.PLANET
86
+ ? hashResult.array[2] % 6
87
+ : hashResult.array[2]
88
+ )
85
89
  loc.seed0 = UInt8.from(hashResult.array[3])
86
90
  loc.seed1 = UInt8.from(hashResult.array[4])
87
91
 
@@ -114,42 +118,3 @@ export function deriveLocation(
114
118
  epoch_props: deriveLocationEpoch(epochSeed, coordinates),
115
119
  })
116
120
  }
117
-
118
- export function deriveLocationMixture(
119
- location: ServerContract.Types.location_derived,
120
- epochSeed: Checksum256Type
121
- ): ServerContract.Types.mixture_info {
122
- const locationType = location.static_props.type.toNumber()
123
-
124
- if (locationType === LocationType.NEBULA) {
125
- return ServerContract.Types.mixture_info.from({
126
- components: [{good_id: 1, purity: PRECISION}],
127
- })
128
- }
129
-
130
- if (locationType === LocationType.ASTEROID) {
131
- const seed = Checksum256.from(epochSeed)
132
- const coords = location.static_props.coords
133
- const str = `mixture-${coords.x}-${coords.y}`
134
- const hashResult = hash512(seed, str)
135
-
136
- const ironPrimary = location.static_props.subtype.toNumber() % 2 === 0
137
- const purityRange = 0.3
138
- const purityRoll = hashResult.array[0] / 255
139
- const primaryPurity = 0.5 + purityRoll * purityRange
140
-
141
- const primaryId = ironPrimary ? 26 : 29
142
- const secondaryId = ironPrimary ? 29 : 26
143
- const primaryAmt = Math.floor(primaryPurity * PRECISION)
144
- const secondaryAmt = PRECISION - primaryAmt
145
-
146
- return ServerContract.Types.mixture_info.from({
147
- components: [
148
- {good_id: primaryId, purity: primaryAmt},
149
- {good_id: secondaryId, purity: secondaryAmt},
150
- ],
151
- })
152
- }
153
-
154
- return ServerContract.Types.mixture_info.from({components: []})
155
- }
@@ -1,23 +0,0 @@
1
- [
2
- {
3
- "id": 1,
4
- "name": "Hydrogen",
5
- "description": "A lightweight fuel source essential for interstellar travel.",
6
- "base_price": 50,
7
- "mass": 15000
8
- },
9
- {
10
- "id": 26,
11
- "name": "Iron",
12
- "description": "A versatile metal used in construction and manufacturing.",
13
- "base_price": 125,
14
- "mass": 40000
15
- },
16
- {
17
- "id": 29,
18
- "name": "Copper",
19
- "description": "A conductive metal vital for electronics and wiring.",
20
- "base_price": 200,
21
- "mass": 60000
22
- }
23
- ]
@@ -1,31 +0,0 @@
1
- import {UInt16, UInt16Type, UInt32} from '@wharfkit/antelope'
2
- import {Good} from '../types'
3
- import goodsData from '../data/goods.json'
4
-
5
- const goods = goodsData as Array<{
6
- id: number
7
- name: string
8
- description: string
9
- base_price: number
10
- mass: number
11
- }>
12
-
13
- export const goodIds = goods.map((g) => g.id)
14
-
15
- export function getGood(goodId: UInt16Type): Good {
16
- const good = goods.find((g) => UInt16.from(goodId).equals(g.id))
17
- if (!good) {
18
- throw new Error('Good does not exist')
19
- }
20
- return Good.from({
21
- id: UInt16.from(good.id),
22
- name: good.name,
23
- description: good.description,
24
- base_price: UInt32.from(good.base_price),
25
- mass: UInt32.from(good.mass),
26
- })
27
- }
28
-
29
- export function getGoods(): Good[] {
30
- return goods.map((g) => getGood(g.id))
31
- }