@shipload/sdk 0.7.1 → 1.0.0-next.0

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
@@ -0,0 +1,76 @@
1
+ import type {Name, UInt16, UInt32} from '@wharfkit/antelope'
2
+ import type {ServerContract} from '../contracts'
3
+
4
+ export interface MovementCapability {
5
+ engines: ServerContract.Types.movement_stats
6
+ generator: ServerContract.Types.energy_stats
7
+ }
8
+
9
+ export interface EnergyCapability {
10
+ energy: UInt16
11
+ }
12
+
13
+ export interface StorageCapability {
14
+ capacity: UInt32
15
+ cargomass: UInt32
16
+ cargo: ServerContract.Types.cargo_item[]
17
+ }
18
+
19
+ export interface LoaderCapability {
20
+ loaders: ServerContract.Types.loader_stats
21
+ }
22
+
23
+ export interface GathererCapability {
24
+ gatherer: ServerContract.Types.gatherer_stats
25
+ }
26
+
27
+ export interface MassCapability {
28
+ hullmass: UInt32
29
+ }
30
+
31
+ export interface ScheduleCapability {
32
+ schedule?: ServerContract.Types.schedule
33
+ }
34
+
35
+ export interface EntityCapabilities {
36
+ hullmass?: UInt32
37
+ capacity?: UInt32
38
+ engines?: ServerContract.Types.movement_stats
39
+ generator?: ServerContract.Types.energy_stats
40
+ loaders?: ServerContract.Types.loader_stats
41
+ gatherer?: ServerContract.Types.gatherer_stats
42
+ crafter?: ServerContract.Types.crafter_stats
43
+ hauler?: ServerContract.Types.hauler_stats
44
+ }
45
+
46
+ export interface EntityState {
47
+ owner: Name
48
+ location: ServerContract.Types.coordinates
49
+ energy?: UInt16
50
+ cargomass: UInt32
51
+ cargo: ServerContract.Types.cargo_item[]
52
+ }
53
+
54
+ export function capsHasMovement(caps: EntityCapabilities): boolean {
55
+ return caps.engines !== undefined && caps.generator !== undefined
56
+ }
57
+
58
+ export function capsHasStorage(caps: EntityCapabilities): boolean {
59
+ return caps.capacity !== undefined
60
+ }
61
+
62
+ export function capsHasLoaders(caps: EntityCapabilities): boolean {
63
+ return caps.loaders !== undefined
64
+ }
65
+
66
+ export function capsHasGatherer(caps: EntityCapabilities): boolean {
67
+ return caps.gatherer !== undefined
68
+ }
69
+
70
+ export function capsHasMass(caps: EntityCapabilities): boolean {
71
+ return caps.hullmass !== undefined
72
+ }
73
+
74
+ export function capsHasHauler(caps: EntityCapabilities): boolean {
75
+ return caps.hauler !== undefined
76
+ }
@@ -0,0 +1,69 @@
1
+ import {Name} from '@wharfkit/antelope'
2
+
3
+ export const ENTITY_SHIP = Name.from('ship')
4
+ export const ENTITY_WAREHOUSE = Name.from('warehouse')
5
+ export const ENTITY_CONTAINER = Name.from('container')
6
+
7
+ export type EntityTypeName = 'ship' | 'warehouse' | 'container'
8
+
9
+ export interface EntityTraits {
10
+ typeName: Name
11
+ isMovable: boolean
12
+ hasEnergy: boolean
13
+ hasLoaders: boolean
14
+ notFoundError: string
15
+ }
16
+
17
+ export const shipTraits: EntityTraits = {
18
+ typeName: ENTITY_SHIP,
19
+ isMovable: true,
20
+ hasEnergy: true,
21
+ hasLoaders: true,
22
+
23
+ notFoundError: 'ship not found',
24
+ }
25
+
26
+ export const warehouseTraits: EntityTraits = {
27
+ typeName: ENTITY_WAREHOUSE,
28
+ isMovable: false,
29
+ hasEnergy: false,
30
+ hasLoaders: true,
31
+
32
+ notFoundError: 'warehouse not found',
33
+ }
34
+
35
+ export const containerTraits: EntityTraits = {
36
+ typeName: ENTITY_CONTAINER,
37
+ isMovable: true,
38
+ hasEnergy: false,
39
+ hasLoaders: false,
40
+
41
+ notFoundError: 'container not found',
42
+ }
43
+
44
+ export function getEntityTraits(entityType: Name | EntityTypeName): EntityTraits {
45
+ const typeName = typeof entityType === 'string' ? entityType : entityType.toString()
46
+
47
+ switch (typeName) {
48
+ case 'ship':
49
+ return shipTraits
50
+ case 'warehouse':
51
+ return warehouseTraits
52
+ case 'container':
53
+ return containerTraits
54
+ default:
55
+ throw new Error(`Unknown entity type: ${typeName}`)
56
+ }
57
+ }
58
+
59
+ export function isShip(entity: {type?: Name}): boolean {
60
+ return entity.type?.equals(ENTITY_SHIP) ?? false
61
+ }
62
+
63
+ export function isWarehouse(entity: {type?: Name}): boolean {
64
+ return entity.type?.equals(ENTITY_WAREHOUSE) ?? false
65
+ }
66
+
67
+ export function isContainer(entity: {type?: Name}): boolean {
68
+ return entity.type?.equals(ENTITY_CONTAINER) ?? false
69
+ }
@@ -0,0 +1,39 @@
1
+ import type {Name, UInt64} from '@wharfkit/antelope'
2
+ import type {ServerContract} from '../contracts'
3
+ import type {Coordinates} from '../types'
4
+ import type {
5
+ EnergyCapability,
6
+ LoaderCapability,
7
+ MassCapability,
8
+ MovementCapability,
9
+ ScheduleCapability,
10
+ StorageCapability,
11
+ } from './capabilities'
12
+
13
+ export interface Entity {
14
+ id: UInt64
15
+ type: Name
16
+ owner: Name
17
+ entity_name: string
18
+ location: Coordinates | ServerContract.Types.coordinates
19
+ }
20
+
21
+ export type ShipEntity = Entity &
22
+ Partial<MovementCapability> &
23
+ Partial<EnergyCapability> &
24
+ StorageCapability &
25
+ Partial<LoaderCapability> &
26
+ MassCapability &
27
+ ScheduleCapability & {
28
+ gatherer?: ServerContract.Types.gatherer_stats
29
+ }
30
+
31
+ export type WarehouseEntity = Entity &
32
+ StorageCapability &
33
+ Partial<LoaderCapability> &
34
+ MassCapability &
35
+ ScheduleCapability
36
+
37
+ export type ContainerEntity = Entity & StorageCapability & MassCapability & ScheduleCapability
38
+
39
+ export type AnyEntity = ShipEntity | WarehouseEntity | ContainerEntity
@@ -0,0 +1,3 @@
1
+ export * from './capabilities'
2
+ export * from './entity'
3
+ export * from './entity-traits'
package/src/types.ts CHANGED
@@ -1,16 +1,106 @@
1
- import {Struct, UInt16, UInt16Type, UInt64, UInt64Type} from '@wharfkit/antelope'
1
+ import {
2
+ type Int64Type,
3
+ Name,
4
+ type UInt16,
5
+ type UInt16Type,
6
+ type UInt32,
7
+ type UInt32Type,
8
+ UInt64,
9
+ } from '@wharfkit/antelope'
2
10
  import {ServerContract} from './contracts'
3
11
 
4
12
  export const PRECISION = 10000
5
- export const TRAVEL_MAXMASS_PENALTY = 5 // Penalty (in seconds) for exceeding the maximum mass per 1000 unit
13
+ export const CRAFT_ENERGY_DIVISOR = 150000
6
14
 
7
- export interface CameraPosition extends ServerContract.ActionParams.Type.coordinates {
8
- z: number
15
+ export const WAREHOUSE_Z = 500
16
+
17
+ export const CONTAINER_Z = 300
18
+
19
+ export const TRAVEL_MAX_DURATION = 86400
20
+
21
+ export const MIN_ORBITAL_ALTITUDE = 800
22
+ export const MAX_ORBITAL_ALTITUDE = 3000
23
+
24
+ export const BASE_ORBITAL_MASS = 100000
25
+
26
+ export interface ShipLike {
27
+ coordinates: ServerContract.Types.coordinates
28
+ hullmass?: UInt32
29
+ energy?: UInt16
30
+ engines?: ServerContract.Types.movement_stats
31
+ generator?: ServerContract.Types.energy_stats
32
+ loaders?: ServerContract.Types.loader_stats
33
+ hauler?: ServerContract.Types.hauler_stats
34
+ capacity?: UInt32
35
+ }
36
+
37
+ export interface CargoMassInfo {
38
+ item_id: UInt16Type
39
+ quantity: UInt32Type
40
+ }
41
+
42
+ export enum TaskType {
43
+ IDLE = 0,
44
+ TRAVEL = 1,
45
+ RECHARGE = 2,
46
+ LOAD = 3,
47
+ UNLOAD = 4,
48
+ GATHER = 5,
49
+ WARP = 6,
50
+ CRAFT = 7,
51
+ DEPLOY = 8,
52
+ WRAP = 9,
53
+ UNWRAP = 10,
54
+ }
55
+
56
+ export enum LocationType {
57
+ EMPTY = 0,
58
+ PLANET = 1,
59
+ ASTEROID = 2,
60
+ NEBULA = 3,
61
+ }
62
+
63
+ export enum TaskCancelable {
64
+ NEVER = 0,
65
+ BEFORE_START = 1,
66
+ ALWAYS = 2,
67
+ }
68
+
69
+ export const EntityType = {
70
+ SHIP: Name.from('ship'),
71
+ WAREHOUSE: Name.from('warehouse'),
72
+ CONTAINER: Name.from('container'),
73
+ } as const
74
+
75
+ export type EntityTypeName = (typeof EntityType)[keyof typeof EntityType]
76
+
77
+ export type CoordinatesType =
78
+ | Coordinates
79
+ | ServerContract.Types.coordinates
80
+ | {x: Int64Type; y: Int64Type}
81
+
82
+ export class Coordinates extends ServerContract.Types.coordinates {
83
+ static from(value: CoordinatesType): Coordinates {
84
+ return super.from(value) as Coordinates
85
+ }
86
+
87
+ equals(other: CoordinatesType): boolean {
88
+ const coords = Coordinates.from(other)
89
+ return this.x.equals(coords.x) && this.y.equals(coords.y)
90
+ }
91
+
92
+ toLocationId(): UInt64 {
93
+ return coordsToLocationId(this)
94
+ }
9
95
  }
10
96
 
11
- export interface Dimensions {
12
- width: number
13
- height: number
97
+ export function coordsToLocationId(coords: CoordinatesType): UInt64 {
98
+ const c = Coordinates.from(coords)
99
+ const mask = BigInt(0xffffffff)
100
+ const x = BigInt(c.x.toNumber()) & mask
101
+ const y = BigInt(c.y.toNumber()) & mask
102
+ const id = (x << BigInt(32)) | y
103
+ return UInt64.from(id)
14
104
  }
15
105
 
16
106
  export interface Distance {
@@ -19,38 +109,53 @@ export interface Distance {
19
109
  distance: UInt16
20
110
  }
21
111
 
22
- @Struct.type('good')
23
- export class Good extends Struct {
24
- @Struct.field(UInt16)
25
- id!: UInt16
26
- @Struct.field('string')
27
- name!: string
28
- @Struct.field('string')
29
- description!: string
30
- @Struct.field(UInt64)
31
- base_price!: UInt64
32
- @Struct.field(UInt64)
33
- mass!: UInt64
112
+ export type ItemType = 'resource' | 'component' | 'module' | 'entity'
113
+ export type ResourceCategory = 'ore' | 'crystal' | 'gas' | 'regolith' | 'biomass'
114
+ export type ModuleType =
115
+ | 'any'
116
+ | 'engine'
117
+ | 'generator'
118
+ | 'gatherer'
119
+ | 'loader'
120
+ | 'warp'
121
+ | 'crafter'
122
+ | 'launcher'
123
+ | 'storage'
124
+ | 'hauler'
125
+
126
+ export const TIER_ADJECTIVES: Record<number, string> = {
127
+ 1: 'Crude',
128
+ 2: 'Dense',
129
+ 3: 'Pure',
130
+ 4: 'Prime',
131
+ 5: 'Pristine',
132
+ 6: 'Radiant',
133
+ 7: 'Exotic',
134
+ 8: 'Mythic',
135
+ 9: 'Cosmic',
136
+ 10: 'Ascendant',
137
+ }
138
+
139
+ export const CATEGORY_LABELS: Record<ResourceCategory, string> = {
140
+ ore: 'Ore',
141
+ crystal: 'Crystal',
142
+ gas: 'Gas',
143
+ regolith: 'Regolith',
144
+ biomass: 'Biomass',
34
145
  }
35
146
 
36
- export interface GoodType {
37
- id: UInt16Type
147
+ export interface Item {
148
+ id: number
38
149
  name: string
39
150
  description: string
40
- base_price: UInt64Type
41
- mass: UInt64Type
151
+ color: string
152
+ mass: number
153
+ type: ItemType
154
+ tier: number
155
+ category?: ResourceCategory
156
+ moduleType?: ModuleType
42
157
  }
43
158
 
44
- @Struct.type('GoodPrice')
45
- export class GoodPrice extends Struct {
46
- @Struct.field(UInt16)
47
- id!: UInt16
48
- @Struct.field(Good)
49
- good!: Good
50
- @Struct.field(UInt64)
51
- price!: UInt64
52
- @Struct.field(UInt64)
53
- supply!: UInt64
159
+ export function formatTier(tier: number): string {
160
+ return 'T' + tier
54
161
  }
55
-
56
- export interface Coordinates extends ServerContract.ActionParams.Type.coordinates {}
@@ -1,6 +1,6 @@
1
- import {Bytes, Checksum256, Checksum256Type, Checksum512} from '@wharfkit/antelope'
1
+ import {Bytes, Checksum256, type Checksum256Type, Checksum512} from '@wharfkit/antelope'
2
2
 
3
- export function hash(seed: Checksum256Type, string: string): Checksum512 {
3
+ export function hash(seed: Checksum256Type, string: string): Checksum256 {
4
4
  const bytes = Bytes.from(`${seed}${string}`, 'utf8')
5
5
  return Checksum256.hash(bytes)
6
6
  }
@@ -0,0 +1,168 @@
1
+ import {Checksum256, type Checksum256Type, type Checksum512, UInt8} from '@wharfkit/antelope'
2
+ import {hash512} from './hash'
3
+ import {Coordinates, type CoordinatesType, LocationType} from '../types'
4
+ import {ServerContract} from '../contracts'
5
+ import {deriveLocationSize} from '../derivation/location-size'
6
+ import syllables from '../data/syllables.json'
7
+ import nebulaAdjectives from '../data/nebula-adjectives.json'
8
+ import nebulaNouns from '../data/nebula-nouns.json'
9
+
10
+ const LOCATION_EXISTS_THRESHOLD = 0x10
11
+ const LOCATION_ACTIVE_THRESHOLD = 0x80
12
+
13
+ export function getLocationType(
14
+ gameSeed: Checksum256Type,
15
+ coordinates: CoordinatesType
16
+ ): LocationType {
17
+ const seed = Checksum256.from(gameSeed)
18
+ const str = ['system', coordinates.x, coordinates.y].join('-')
19
+ const hashResult = hash512(seed, str)
20
+
21
+ if (hashResult.array[0] >= LOCATION_EXISTS_THRESHOLD) {
22
+ return LocationType.EMPTY
23
+ }
24
+
25
+ if (hashResult.array[1] < 96) {
26
+ return LocationType.PLANET
27
+ } else if (hashResult.array[1] < 176) {
28
+ return LocationType.ASTEROID
29
+ }
30
+ return LocationType.NEBULA
31
+ }
32
+
33
+ export function isGatherableLocation(locationType: LocationType): boolean {
34
+ return locationType !== LocationType.EMPTY
35
+ }
36
+
37
+ export function getLocationTypeName(type: LocationType): string {
38
+ switch (type) {
39
+ case LocationType.EMPTY:
40
+ return 'Empty'
41
+ case LocationType.PLANET:
42
+ return 'Planet'
43
+ case LocationType.ASTEROID:
44
+ return 'Asteroid'
45
+ case LocationType.NEBULA:
46
+ return 'Nebula'
47
+ }
48
+ }
49
+
50
+ function uint16(hash: Checksum512, offset: number): number {
51
+ return (hash.array[offset] << 8) | hash.array[offset + 1]
52
+ }
53
+
54
+ function generatePlanetName(hashResult: Checksum512): string {
55
+ const syllableCount = 2 + (hashResult.array[0] % 2)
56
+ const name: string[] = []
57
+ for (let i = 0; i < syllableCount; i++) {
58
+ const index = uint16(hashResult, 1 + i * 2) % syllables.length
59
+ const syllable = syllables[index]
60
+ name.push(i > 0 ? syllable.toLowerCase() : syllable)
61
+ }
62
+ return name.join('')
63
+ }
64
+
65
+ function generateAsteroidName(hashResult: Checksum512): string {
66
+ const A = 65
67
+ const letter1 = String.fromCharCode(A + (hashResult.array[0] % 26))
68
+ const letter2 = String.fromCharCode(A + (hashResult.array[1] % 26))
69
+ const num = (uint16(hashResult, 2) % 9000) + 1000
70
+ return `${letter1}${letter2}-${num}`
71
+ }
72
+
73
+ function generateNebulaName(hashResult: Checksum512): string {
74
+ const adjIdx = uint16(hashResult, 0) % nebulaAdjectives.length
75
+ const nounIdx = uint16(hashResult, 2) % nebulaNouns.length
76
+ return `${nebulaAdjectives[adjIdx]} ${nebulaNouns[nounIdx]}`
77
+ }
78
+
79
+ export function getSystemName(gameSeed: Checksum256Type, location: CoordinatesType): string {
80
+ const seed = Checksum256.from(gameSeed)
81
+ const locationType = getLocationType(seed, location)
82
+ if (locationType === LocationType.EMPTY) {
83
+ throw new Error("System doesn't exist at location")
84
+ }
85
+ const seedStr = `${location.x}-${location.y}-${locationType}-name`
86
+ const hashResult = hash512(seed, seedStr)
87
+ switch (locationType) {
88
+ case LocationType.PLANET:
89
+ return generatePlanetName(hashResult)
90
+ case LocationType.ASTEROID:
91
+ return generateAsteroidName(hashResult)
92
+ case LocationType.NEBULA:
93
+ return generateNebulaName(hashResult)
94
+ default:
95
+ return generatePlanetName(hashResult)
96
+ }
97
+ }
98
+
99
+ export function hasSystem(gameSeed: Checksum256Type, coordinates: CoordinatesType): boolean {
100
+ return getLocationType(gameSeed, coordinates) !== LocationType.EMPTY
101
+ }
102
+
103
+ export function deriveLocationStatic(
104
+ gameSeed: Checksum256Type,
105
+ coordinates: CoordinatesType
106
+ ): ServerContract.Types.location_static {
107
+ const seed = Checksum256.from(gameSeed)
108
+ const coords = Coordinates.from(coordinates)
109
+ const str = `system-${coords.x}-${coords.y}`
110
+ const hashResult = hash512(seed, str)
111
+
112
+ const loc = ServerContract.Types.location_static.from({
113
+ coords: coords,
114
+ type: LocationType.EMPTY,
115
+ subtype: 0,
116
+ seed0: 0,
117
+ seed1: 0,
118
+ })
119
+
120
+ if (hashResult.array[0] >= LOCATION_EXISTS_THRESHOLD) {
121
+ return loc
122
+ }
123
+
124
+ if (hashResult.array[1] < 96) {
125
+ loc.type = UInt8.from(LocationType.PLANET)
126
+ } else if (hashResult.array[1] < 176) {
127
+ loc.type = UInt8.from(LocationType.ASTEROID)
128
+ } else {
129
+ loc.type = UInt8.from(LocationType.NEBULA)
130
+ }
131
+
132
+ loc.subtype = UInt8.from(
133
+ Number(loc.type) === LocationType.PLANET ? hashResult.array[2] % 6 : hashResult.array[2]
134
+ )
135
+ loc.seed0 = UInt8.from(hashResult.array[3])
136
+ loc.seed1 = UInt8.from(hashResult.array[4])
137
+
138
+ return loc
139
+ }
140
+
141
+ export function deriveLocationEpoch(
142
+ epochSeed: Checksum256Type,
143
+ coordinates: CoordinatesType
144
+ ): ServerContract.Types.location_epoch {
145
+ const seed = Checksum256.from(epochSeed)
146
+ const coords = Coordinates.from(coordinates)
147
+ const str = `system-epoch-${coords.x}-${coords.y}`
148
+ const hashResult = hash512(seed, str)
149
+
150
+ return ServerContract.Types.location_epoch.from({
151
+ active: hashResult.array[0] < LOCATION_ACTIVE_THRESHOLD,
152
+ seed0: hashResult.array[1],
153
+ seed1: hashResult.array[2],
154
+ })
155
+ }
156
+
157
+ export function deriveLocation(
158
+ gameSeed: Checksum256Type,
159
+ epochSeed: Checksum256Type,
160
+ coordinates: CoordinatesType
161
+ ): ServerContract.Types.location_derived {
162
+ const staticProps = deriveLocationStatic(gameSeed, coordinates)
163
+ return ServerContract.Types.location_derived.from({
164
+ static_props: staticProps,
165
+ epoch_props: deriveLocationEpoch(epochSeed, coordinates),
166
+ size: deriveLocationSize(staticProps),
167
+ })
168
+ }
package/src/goods.ts DELETED
@@ -1,124 +0,0 @@
1
- import {UInt16, UInt16Type, UInt64} from '@wharfkit/antelope'
2
- import {Coordinates, Good, GoodType, PRECISION} from './types'
3
-
4
- // List of goods with titles and descriptions
5
- const goods: GoodType[] = [
6
- {
7
- id: 1,
8
- name: 'FizzGlo',
9
- description: 'Pops with flavor! A neon drink that makes your burps glow.',
10
- base_price: 50,
11
- mass: 35_000,
12
- },
13
- // {
14
- // id: 2,
15
- // name: 'ZapSnacks',
16
- // description: 'Electric taste! Spicy edible energy sparks for a tongue-tingling experience.',
17
- // base_price: 0,
18
- // mass: 0,
19
- // },
20
- {
21
- id: 3,
22
- name: 'Blob Buddies',
23
- description: 'Squishy friends! Clingy, cute and mood-matching pet blobs for every home!',
24
- base_price: 95,
25
- mass: 60_000,
26
- },
27
- {
28
- id: 4,
29
- name: 'TuneTooth',
30
- description: 'Whistle while you eat! Edible instrument treats that play tunes when chewed.',
31
- base_price: 145,
32
- mass: 75_000,
33
- },
34
- {
35
- id: 5,
36
- name: 'SunPods',
37
- description: 'Miniature suns in your pocket providing on-demand light & warmth.',
38
- base_price: 295,
39
- mass: 135_000,
40
- },
41
- // {
42
- // id: 6,
43
- // name: 'Fuzzix',
44
- // description: 'Pocket-sized quantum fluff generator for instant comfy.',
45
- // base_price: 0,
46
- // mass: 0,
47
- // },
48
- {
49
- id: 7,
50
- name: 'GlowGo',
51
- description: 'Ingestible bioluminescent jelly, your inside glows in the dark!',
52
- base_price: 650,
53
- mass: 255_000,
54
- },
55
- // {
56
- // id: 8,
57
- // name: 'KrackleKaps',
58
- // description: 'Capsules packed with tiny firecrackers, spice up meals and parties.',
59
- // base_price: 0,
60
- // mass: 0,
61
- // },
62
- {
63
- id: 9,
64
- name: 'PlasmaMints',
65
- description: 'Hypercharged candy giving plasma breath capable of cutting through steel.',
66
- base_price: 3450,
67
- mass: 1_100_000,
68
- },
69
- {
70
- id: 10,
71
- name: 'TimeTreats',
72
- description: 'Confectionery morsels releasing slow-mo effect over a limited period.',
73
- base_price: 8500,
74
- mass: 2_100_000,
75
- },
76
- {
77
- id: 11,
78
- name: 'QuantumQuencher',
79
- description:
80
- 'Bottled hyper-fluid quenching thirst across multiple parallel realities simultaneously.',
81
- base_price: 20_500,
82
- mass: 4_100_000,
83
- },
84
- // {
85
- // id: 12,
86
- // name: 'TransmatterTruffles',
87
- // description: 'Delectable chocolates instantly teleporting consumers short distances.',
88
- // base_price: 0,
89
- // mass: 0,
90
- // },
91
- {
92
- id: 13,
93
- name: 'MemoryGum',
94
- description: 'Chewable gum storing or replaying memories while being chewed.',
95
- base_price: 52_500,
96
- mass: 9_500_000,
97
- },
98
- {
99
- id: 14,
100
- name: 'SymbioSnack',
101
- description: 'Edible alien larvae adopting owner’s taste preference upon consumption.',
102
- base_price: 115_000,
103
- mass: 16_000_000,
104
- },
105
- ]
106
-
107
- export const goodIds = goods.map((g) => g.id)
108
-
109
- export function getGood(good_id: UInt16Type): Good {
110
- const good = goods.find((g) => UInt16.from(good_id).equals(g.id))
111
- if (!good) {
112
- throw new Error('Good does not exist')
113
- }
114
- return Good.from({
115
- ...good,
116
- id: UInt16.from(good.id),
117
- base_price: UInt64.from(good.base_price),
118
- mass: UInt64.from(good.mass).multiplying(PRECISION),
119
- })
120
- }
121
-
122
- export function getGoods(): Good[] {
123
- return goods.map((g) => getGood(g.id))
124
- }