@shipload/sdk 2.0.0-rc6 → 2.0.0-rc8

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shipload/sdk",
3
3
  "description": "SDKs for Shipload",
4
- "version": "2.0.0-rc6",
4
+ "version": "2.0.0-rc8",
5
5
  "homepage": "https://github.com/shipload/sdk",
6
6
  "license": "MIT",
7
7
  "main": "lib/shipload.js",
@@ -1,3 +1,5 @@
1
+ import {UInt16, UInt32} from '@wharfkit/antelope'
2
+ import {PRECISION} from '../types'
1
3
  import type {EntityCapabilities} from '../types/capabilities'
2
4
  import {ServerContract} from '../contracts'
3
5
 
@@ -8,3 +10,19 @@ export interface CrafterCapability {
8
10
  export function capsHasCrafter(caps: EntityCapabilities): boolean {
9
11
  return caps.crafter !== undefined
10
12
  }
13
+
14
+ export function calc_craft_duration(
15
+ speed: number,
16
+ totalInputMass: number,
17
+ quantity: number
18
+ ): UInt32 {
19
+ const duration = Math.floor((totalInputMass * quantity) / speed)
20
+ return UInt32.from(Math.max(duration, 1))
21
+ }
22
+
23
+ export function calc_craft_energy(
24
+ drain: number,
25
+ duration: number
26
+ ): UInt16 {
27
+ return UInt16.from(Math.floor((duration * drain) / PRECISION))
28
+ }
@@ -2,23 +2,29 @@ import {UInt16, UInt32} from '@wharfkit/antelope'
2
2
  import {ServerContract} from '../contracts'
3
3
  import {PRECISION} from '../types'
4
4
 
5
+ const EXTRACTION_TIME_SCALE = 100
6
+ const DEPTH_PENALTY_DIVISOR = 5000
7
+ const DRILL_TIME_SCALE = 300
8
+
5
9
  export function calc_extraction_duration(
6
10
  extractor: ServerContract.Types.extractor_stats,
7
- cargoMass: number,
11
+ itemMass: number,
12
+ quantity: number,
8
13
  stratum: number,
9
14
  richness: number
10
15
  ): UInt32 {
11
16
  const rate = extractor.rate.toNumber()
12
- const efficiency = extractor.efficiency.toNumber()
13
17
  const drill = extractor.drill.toNumber()
14
18
 
15
- const rateProduct = Math.floor((rate * richness * efficiency) / PRECISION)
16
- if (rateProduct === 0) return UInt32.from(0)
17
-
18
- const extractionTime = Math.floor((cargoMass * PRECISION) / rateProduct)
19
- const drillTime = Math.floor(stratum / drill)
19
+ if (rate === 0 || drill === 0 || richness === 0) return UInt32.from(0)
20
20
 
21
- return UInt32.from(extractionTime + drillTime)
21
+ const massFactor = Math.sqrt(itemMass)
22
+ const depthPenalty = 1 + stratum / DEPTH_PENALTY_DIVISOR
23
+ const richnessMul = richness / 1000
24
+ const extractionTime = quantity * massFactor * EXTRACTION_TIME_SCALE * depthPenalty
25
+ / (rate * richnessMul)
26
+ const drillTime = DRILL_TIME_SCALE * Math.log(1 + stratum / drill)
27
+ return UInt32.from(Math.floor(extractionTime + drillTime))
22
28
  }
23
29
 
24
30
  export function calc_extraction_energy(
@@ -4,3 +4,4 @@ export * from './storage'
4
4
  export * from './loading'
5
5
  export * from './extraction'
6
6
  export * from './crafting'
7
+ export * from './modules'
@@ -0,0 +1,49 @@
1
+ export const ITEM_ENGINE_T1 = 10006
2
+ export const ITEM_GENERATOR_T1 = 10007
3
+ export const ITEM_EXTRACTOR_T1 = 10014
4
+ export const ITEM_LOADER_T1 = 10015
5
+ export const ITEM_MANUFACTURING_T1 = 10016
6
+
7
+ export const MODULE_ANY = 0
8
+ export const MODULE_ENGINE = 1
9
+ export const MODULE_GENERATOR = 2
10
+ export const MODULE_EXTRACTOR = 3
11
+ export const MODULE_LOADER = 4
12
+ export const MODULE_WARP = 5
13
+ export const MODULE_CRAFTER = 6
14
+ export const MODULE_LAUNCHER = 7
15
+
16
+ export interface CargoSeed {
17
+ itemId: number
18
+ seed: bigint
19
+ }
20
+
21
+ export interface ModuleEntry {
22
+ type: number
23
+ installed?: CargoSeed
24
+ }
25
+
26
+ export function moduleAccepts(slotType: number, moduleType: number): boolean {
27
+ return slotType === MODULE_ANY || slotType === moduleType
28
+ }
29
+
30
+ export function getModuleCapabilityType(itemId: number): number {
31
+ switch (itemId) {
32
+ case ITEM_ENGINE_T1:
33
+ return MODULE_ENGINE
34
+ case ITEM_GENERATOR_T1:
35
+ return MODULE_GENERATOR
36
+ case ITEM_EXTRACTOR_T1:
37
+ return MODULE_EXTRACTOR
38
+ case ITEM_LOADER_T1:
39
+ return MODULE_LOADER
40
+ case ITEM_MANUFACTURING_T1:
41
+ return MODULE_CRAFTER
42
+ default:
43
+ return 0xff
44
+ }
45
+ }
46
+
47
+ export function isModuleItem(itemId: number): boolean {
48
+ return getModuleCapabilityType(itemId) !== 0xff
49
+ }