Options
All
  • Public
  • Public/Protected
  • All
Menu

Module simulation

This file contains mostly functions which simulates Solidity contract's logic client-side, and therefore reducing the network capacity load.

Type aliases

ObfuscatedAction

ObfuscatedAction: object

This type represents data, which are created from action parameters in order to obfuscate the meaning of this action to the contract

Type declaration

  • hash: string

    Hashed parameters of the action. This hash is sent to the contract in the commit phase, and later, when the action should be executed, the contract must receive full action parameters (and the nonce), which are hashed to this exact value.

  • nonce: BigNumber

    Random 256bit number, which were used for the creation of the hash, and must be sent to the contract later, in order to verify the action.

Functions

Const estimateAttackDuration

  • This function simulates contract's estimation of time, which is needed for player to recover from his attack attempt (successful or unsuccessful) and to be able to perform another action.

    Parameters

    • player: PlayerInfo

      Player, for whom the estimation is being done

    • targetTile: TileInfo

      Position, on which the attack's target is standing

    Returns number | false

    Number of blocks, which are needed for the player to recover from his attack attempt, or false, if the attack's target is not in the right distance for attack.

Const estimateGotoDuration

  • estimateGotoDuration(player: PlayerInfo, tile: TileInfo, item: string | undefined): number | false
  • This function simulates contract's estimation of time, which is needed for player to get from his current location to the destination tile, possibly equipped with the given item.

    Parameters

    • player: PlayerInfo

      Player, for whom the estimation is being done

    • tile: TileInfo

      Destination location, where the player is heading

    • item: string | undefined

      Item, which is boosting player's moving skill, or undefined, if there isn't any

    Returns number | false

    Number of blocks, which are needed for this player to get to the destination tile, or false, if the destination terrain is not walkable or it is too distant

Const estimateMineDuration

  • estimateMineDuration(player: PlayerInfo, terrain: TerrainType, item: string | undefined): number | false
  • This function simulates contract's estimation of time, which is needed for player to mine the resource on his current location, possibly equipped with the given item.

    Parameters

    • player: PlayerInfo

      Player, for whom the estimation is being done

    • terrain: TerrainType

      Terrain type, which the player wants to mine

    • item: string | undefined

      Item, which is boosting player's mining skill, or undefined, if there isn't any

    Returns number | false

    Number of blocks, which are needed for this player to mine the resource given, or false, if this terrain type cannot be mined

Const getDistance

  • getDistance(a: XY, b: XY): number
  • Calculates Manhattan distance between two locations, as calculated by contract

    Parameters

    • a: XY

      First location

    • b: XY

      Second location

    Returns number

    Distance between given locations

Const getGameSchedule

  • getGameSchedule(blockNum: number): object
  • Function returns current game phase and important schedule info, based on the given block number

    Parameters

    • blockNum: number

      Number of block for which the schedule info is demanded

    Returns object

    Current game phase (INIT or GAME), block number when the last INIT phase has started, and number of blocks after which the phase should change

    • phase: "INIT" | "GAME"
    • turnStart: number
    • untilChange: number

Const getHashesForItemSpawn

  • Function gets current block number from the blockchain, then calculates the last blocks which function as a seed for item spawning, and returns their hashes.

    Parameters

    Returns Promise<string[]>

    Array of hashes of blocks, which is then used for checking, whether there are spawned items

Const getItemPickedIncluded

  • getItemPickedIncluded(worldX: integer, worldY: integer, hashes: string[]): string | undefined
  • Function returns item, which is spawned at the given location, according to the given hashes

    Parameters

    • worldX: integer

      X coordinate on the map

    • worldY: integer

      Y coordinate on the map

    • hashes: string[]

      Array of block hashes (as returned by getHashesForItemSpawn), which are used for item spawning

    Returns string | undefined

    Identifier of item currently spawned at the given location, or undefined if there isn't any

Const getItemSpawn

  • getItemSpawn(worldX: integer, worldY: integer, blockHash: string): string | undefined
  • This function simulates contract's item spawning logic by getting the location on the map and hash of the block, and returning identifier of item currently spawned at that location

    Parameters

    • worldX: integer

      X coordinate on the map

    • worldY: integer

      Y coordinate on the map

    • blockHash: string

      Block hash

    Returns string | undefined

    Identifier of item currently spawned at the given location according to the given hash, or undefined, when there is no spawned item

Const getItemStat

  • getItemStat(stat: number, item: BigNumber): number
  • This function simulates contract's assigning of item stat to the item.

    Parameters

    • stat: number

      Type of stat which is demanded (0 = moving, 1 = mining, 2 = combat)

    • item: BigNumber

      Item identifier in form of 256bit number

    Returns number

    Item stat value as integer between 0 and 100

Const getItemStats

  • getItemStats(item: string): object
  • This function returns all item stats for the given item

    Parameters

    • item: string

      Item identifier as string

    Returns object

    Item stats for the given item

    • combat: number
    • mining: number
    • moving: number

Const getTerrainType

  • getTerrainType(x: integer, y: integer, turnSeed: integer): TerrainType
  • This function simulates contract's terrain generation by returning the terrain type at the given location, according to the given turn seed.

    Parameters

    • x: integer

      X coordinate on the map

    • y: integer

      Y coordinate on the map

    • turnSeed: integer

      Seed of current game turn, as returned by getTurnSeed

    Returns TerrainType

    Terrain type at the given location

Const getTurnSeed

  • Function gets current turn seed, which is used for terrain generation.

    Parameters

    Returns number

    Seed of current game turn

Const isRegistered

  • isRegistered(registered: number, blockNum: number): boolean
  • Function compares number of current block and number of block, when the player registered for the last time, and returns whether he is registered in the current turn.

    Parameters

    • registered: number

      Block number, when the player registered himself

    • blockNum: number

      Current block number

    Returns boolean

    True if the player is registered in current turn, false otherwise

Const noise2d

  • noise2d(_x: int256, _y: int256): int256
  • Implementation of discrete 2D Perlin noise, converted from Solidity to TypeScript. Simulates contract's noise generation.

    Parameters

    • _x: int256
    • _y: int256

    Returns int256

Const noise3d

  • noise3d(_x: int256, _y: int256, _z: int256): int256
  • Implementation of discrete 3D Perlin noise, converted from Solidity to TypeScript. Simulates contract's noise generation.

    Parameters

    • _x: int256
    • _y: int256
    • _z: int256

    Returns int256

Const obfuscateAttack

  • This function takes parameters for the attack action, and returns it in an obfuscated form.

    Parameters

    • target: PlayerInfo

      Player, which should be attacked by this action

    • item: string | undefined

      Item, which is boosting player's combat skill, or undefined, if there isn't any

    Returns ObfuscatedAction

    Obfuscated attack action

Const obfuscateGoto

  • This function takes parameters for the goto action, and returns it in an obfuscated form.

    Parameters

    • location: XY

      Destination of the goto action

    • item: string | undefined

      Item, which is boosting player's moving skill, or undefined, if there isn't any

    Returns ObfuscatedAction

    Obfuscated goto action

Const obfuscateMine

  • This function takes parameters for the mine action, and returns it in an obfuscated form.

    Parameters

    • item: string | undefined

      Item, which is boosting player's mining skill, or undefined, if there isn't any

    Returns ObfuscatedAction

    Obfuscated mine action

Const reduceByStat

  • reduceByStat(value: number, skill: number): number
  • This function simulates contract's reduction of numeric value (usually time) by player's skill. Value is unchanged if the skill is 0, and halved if the skill is 200.

    Parameters

    • value: number

      Positive numeric value, representing usually time needed for the action

    • skill: number

      Player's skill, must be integer between 0 and 200

    Returns number

    Initial value reduced by the skill

Generated using TypeDoc