Backend/GameLogic/GameManager.default
-
EventEmitter
↳
default
- account
- captureZoneGenerator
- contractConstants
- contractsAPI
- diagnostics
- diagnosticsInterval
- endTimeSeconds
- entityStore
- ethConnection
- hashConfig
- hashRate
- homeLocation
- minerManager
- networkHealth$
- networkHealthInterval
- paused
- paused$
- persistentChunkStore
- planetHashMimc
- playerInterval
- players
- playersUpdated$
- safeMode
- scoreboardInterval
- settingsSubscription
- snarkHelper
- terminal
- useMockHash
- worldRadius
- activateArtifact
- addAccount
- addNewChunk
- biomebasePerlin
- bulkAddNewChunks
- bulkHardRefreshPlanets
- buyHat
- capturePlanet
- checkGameHasEnded
- clearEmoji
- deactivateArtifact
- depositArtifact
- destroy
- findArtifact
- findRandomHomePlanet
- forceTick
- getAccount
- getActiveArtifact
- getAddress
- getAllOwnedPlanets
- getAllPlanets
- getAllPlayers
- getAllVoyages
- getArtifactMap
- getArtifactUpdated$
- getArtifactWithId
- getArtifactsWithIds
- getCaptureZoneGenerator
- getCaptureZones
- getChunk
- getChunkStore
- getClaimedLocations
- getConstructors
- getContract
- getContractAPI
- getContractAddress
- getContractConstants
- getCurrentlyExploringChunk
- getDefaultSpaceJunkForPlanetLevel
- getDiagnostics
- getDist
- getDistCoords
- getEndTimeSeconds
- getEnergyArrivingForMove
- getEnergyCurveAtPercent
- getEnergyNeededForMove
- getEnergyOfPlayer
- getEthConnection
- getExploredChunks
- getGameObjects
- getHashConfig
- getHashesPerSec
- getHomeCoords
- getHomeHash
- getLocationOfPlanet
- getMaxMoveDist
- getMiningPattern
- getMyArtifactMap
- getMyArtifacts
- getMyArtifactsUpdated$
- getMyBalance
- getMyBalance$
- getMyBalanceEth
- getMyPlanetMap
- getMyPlanets
- getMyPlanetsUpdated$
- getMyScore
- getNextBroadcastAvailableTimestamp
- getNextClaimAvailableTimestamp
- getNextRevealCountdownInfo
- getNotificationsManager
- getPaused
- getPaused$
- getPerlinThresholds
- getPlanetLevel
- getPlanetMap
- getPlanetRarity
- getPlanetUpdated$
- getPlanetWithCoords
- getPlanetWithId
- getPlanetsInRange
- getPlanetsInWorldRectangle
- getPlanetsWithIds
- getPlayer
- getPlayerScore
- getPlayerSpaceJunk
- getPlayerSpaceJunkLimit
- getPrivateKey
- getRangeBuff
- getRevealedLocations
- getSafeMode
- getSignedTwitter
- getSilverCurveAtPercent
- getSilverOfPlayer
- getSnarkHelper
- getSpaceships
- getSpeedBuff
- getStalePlanetWithId
- getTemperature
- getTimeForMove
- getTokenMintEndTimeSeconds
- getTwitter
- getUIEventEmitter
- getUnconfirmedMoves
- getUnconfirmedUpgrades
- getUnconfirmedWormholeActivations
- getUniverseTotalEnergy
- getUpgrade
- getWorldRadius
- getWorldSilver
- getWormholeFactors
- getWormholes
- hardRefreshArtifact
- hardRefreshPlanet
- hardRefreshPlayer
- hasJoinedGame
- hasMinedChunk
- initMiningManager
- invadePlanet
- isAdmin
- isMining
- isPlanetMineable
- isRoundOver
- joinGame
- listenForNewBlock
- loadContract
- loadPlugins
- locationBigIntFromCoords
- locationFromCoords
- move
- onTxCancelled
- onTxConfirmed
- onTxReverted
- onTxSubmit
- prospectPlanet
- refreshNetworkHealth
- refreshScoreboard
- refreshServerPlanetStates
- refreshTwitters
- revealLocation
- savePlugins
- setMinerCores
- setMiningPattern
- setPlanetEmoji
- setPlayerTwitters
- setRadius
- setSafeMode
- setSnarkCacheSize
- softRefreshPlanet
- spaceTypeFromPerlin
- spaceTypePerlin
- startExplore
- stopExplore
- submitDisconnectTwitter
- submitPlanetMessage
- submitTransaction
- submitVerifyTwitter
- testNotification
- timeUntilNextBroadcastAvailable
- transferOwnership
- updateDiagnostics
- upgrade
- uploadDiagnostics
- verifyMessage
- waitForPlanet
- withdrawArtifact
- withdrawSilver
- create
• Private
new default(terminal
, account
, players
, touchedPlanets
, allTouchedPlanetIds
, revealedCoords
, claimedCoords
, worldRadius
, unprocessedArrivals
, unprocessedPlanetArrivalIds
, contractsAPI
, contractConstants
, persistentChunkStore
, snarkHelper
, homeLocation
, useMockHash
, artifacts
, ethConnection
, paused
)
Name | Type |
---|---|
terminal |
MutableRefObject <undefined | TerminalHandle > |
account |
undefined | EthAddress |
players |
Map <string , Player > |
touchedPlanets |
Map <LocationId , Planet > |
allTouchedPlanetIds |
Set <LocationId > |
revealedCoords |
Map <LocationId , RevealedCoords > |
claimedCoords |
Map <LocationId , ClaimedCoords > |
worldRadius |
number |
unprocessedArrivals |
Map <VoyageId , QueuedArrival > |
unprocessedPlanetArrivalIds |
Map <LocationId , VoyageId []> |
contractsAPI |
ContractsAPI |
contractConstants |
ContractConstants |
persistentChunkStore |
default |
snarkHelper |
default |
homeLocation |
undefined | WorldLocation |
useMockHash |
boolean |
artifacts |
Map <ArtifactId , Artifact > |
ethConnection |
EthConnection |
paused |
boolean |
EventEmitter.constructor
• Private
Readonly
account: undefined
| EthAddress
The ethereum address of the player who is currently logged in. We support 'no account',
represented by undefined
in the case when you want to simply load the game state from the
contract and view it without be able to make any moves.
• Private
captureZoneGenerator: undefined
| CaptureZoneGenerator
Generates capture zones.
• Private
Readonly
contractConstants: ContractConstants
Game parameters set by the contract. Stuff like perlin keys, which are important for mining the correct universe, or the time multiplier, which allows us to tune how quickly voyages go.
todo
move this into a separate GameConfiguration
class.
• Private
Readonly
contractsAPI: ContractsAPI
Allows us to make contract calls, and execute transactions. Be careful about how you use this guy. You don't want to cause your client to send an excessive amount of traffic to whatever node you're connected to.
Interacting with the blockchain isn't free, and we need to be mindful about about the way our application interacts with the blockchain. The current rate limiting strategy consists of three points:
- data that needs to be fetched often should be fetched in bulk.
- rate limit smart contract calls (reads from the blockchain), implemented by {@link ContractCaller} and transactions (writes to the blockchain on behalf of the player), implemented by {@link TxExecutor} via two separately tuned {@link ThrottledConcurrentQueue}s.
• Private
diagnostics: Diagnostics
Diagnostic information about the game.
• Private
diagnosticsInterval: Timer
Handle to an interval that periodically uploads diagnostic information from this client.
• Private
Readonly
endTimeSeconds: number
= 1948939200
todo
change this to the correct timestamp each round.
• Private
Readonly
entityStore: GameObjects
This variable contains the internal state of objects that live in the game world.
• Private
Readonly
ethConnection: EthConnection
An interface to the blockchain that is a little bit lower-level than ContractsAPI. It allows us to do basic operations such as wait for a transaction to complete, check the player's address and balance, etc.
• Private
Readonly
hashConfig: HashConfig
Each round we change the hash configuration of the game. The hash configuration is download from the blockchain, and essentially acts as a salt, permuting the universe into a unique configuration for each new round.
todo
deduplicate this and useMockHash
somehow.
• Private
hashRate: number
Continuously updated value representing the total hashes per second that the game is currently mining the universe at.
todo
keep this in {@link MinerManager}
• Private
homeLocation: undefined
| WorldLocation
The spawn location of the current player.
todo,
make this smarter somehow. It's really annoying to have to import world coordinates, and
get them wrong or something. Maybe we need to mark a planet, once it's been initialized
contract-side, as the homeworld of the user who initialized on it. That way, when you import a
new account into the game, and you import map data that contains your home planet, the client
would be able to automatically detect which planet is the player's home planet.
todo
move this into a new PlayerState
class.
• Private
Optional
minerManager: default
Manages the process of mining new space territory.
• networkHealth$: Monomitter
<NetworkHealthSummary
>
Emits whenever we load the network health summary from the webserver, which is derived from diagnostics that the client sends up to the webserver as well.
• Private
networkHealthInterval: Timer
Handle to an interval that periodically refreshes the network's health from our webserver.
• Private
paused: boolean
• paused$: Monomitter
<boolean
>
• Private
Readonly
persistentChunkStore: default
An object that syncs any newly added or deleted chunks to the player's IndexedDB.
todo
it also persists other game data to IndexedDB. This class needs to be renamed GameSaver
or something like that.
• Private
Readonly
planetHashMimc: (...inputs
: number
[]) => BigInteger
▸ (...inputs
): BigInteger
The aforementioned hash function. In debug mode where DISABLE_ZK_CHECKS
is on, we use a
faster hash function. Othewise, in production mode, use MiMC hash (https://byt3bit.github.io/primesym/).
Name | Type |
---|---|
...inputs |
number [] |
BigInteger
• Private
playerInterval: Timer
Handle to an interval that periodically refreshes some information about the player from the blockchain.
todo
move this into a new PlayerState
class.
• Private
Readonly
players: Map
<string
, Player
>
Map from ethereum addresses to player objects. This isn't stored in GameObjects, because it's not techincally an entity that exists in the world. A player just controls planets and artifacts that do exist in the world.
todo
move this into a new Players
class.
• Readonly
playersUpdated$: Monomitter
<void
>
Whenever we refresh the players twitter accounts or scores, we publish an event here.
• Private
safeMode: boolean
Setting to allow players to start game without plugins that were running during the previous run of the game client. By default, the game launches plugins that were running that were running when the game was last closed.
• Private
scoreboardInterval: Timer
Handle to an interval that periodically refreshes the scoreboard from our webserver.
• Private
settingsSubscription: undefined
| Subscription
Subscription to act on setting changes
• Private
Readonly
snarkHelper: default
Responsible for generating snark proofs.
• Private
Readonly
terminal: MutableRefObject
<undefined
| TerminalHandle
>
Kind of hacky, but we store a reference to the terminal that the player sees when the initially load into the game. This is the same exact terminal that appears inside the collapsable right bar of the game.
• Private
Readonly
useMockHash: boolean
In debug builds of the game, we can connect to a set of contracts deployed to a local blockchain, which are tweaked to not verify planet hashes, meaning we can use a faster hash function with similar properties to mimc. This allows us to mine the map faster in debug mode.
todo
move this into a separate GameConfiguration
class.
• Private
worldRadius: number
Sometimes the universe gets bigger... Sometimes it doesn't.
todo
move this into a new GameConfiguration
class.
• get
captureZoneGeneratedEmitter(): undefined
| Monomitter
<CaptureZonesGeneratedEvent
>
Emits when new capture zones are generated.
undefined
| Monomitter
<CaptureZonesGeneratedEvent
>
• get
planetRarity(): number
number
▸ activateArtifact(locationId
, artifactId
, wormholeTo
, bypassChecks?
): Promise
<Transaction
<UnconfirmedActivateArtifact
>>
Name | Type | Default value |
---|---|---|
locationId |
LocationId |
undefined |
artifactId |
ArtifactId |
undefined |
wormholeTo |
undefined | LocationId |
undefined |
bypassChecks |
boolean |
false |
Promise
<Transaction
<UnconfirmedActivateArtifact
>>
▸ addAccount(coords
): Promise
<boolean
>
Initializes a new player's game to start at the given home planet. Must have already initialized the player on the contract.
Name | Type |
---|---|
coords |
WorldCoords |
Promise
<boolean
>
▸ addNewChunk(chunk
): default
Makes this game manager aware of a new chunk - which includes its location, size, as well as all of the planets contained in that chunk. Causes the client to load all of the information about those planets from the blockchain.
Name | Type |
---|---|
chunk |
Chunk |
▸ biomebasePerlin(coords
, floor
): number
Gets the biome perlin valie at the given location in the world.
Name | Type |
---|---|
coords |
WorldCoords |
floor |
boolean |
number
▸ bulkAddNewChunks(chunks
): Promise
<void
>
To add multiple chunks at once, use this function rather than addNewChunk
, in order
to load all of the associated planet data in an efficient manner.
Name | Type |
---|---|
chunks |
Chunk [] |
Promise
<void
>
▸ Private
bulkHardRefreshPlanets(planetIds
): Promise
<void
>
Name | Type |
---|---|
planetIds |
LocationId [] |
Promise
<void
>
▸ buyHat(planetId
, _bypassChecks?
): Promise
<Transaction
<UnconfirmedBuyHat
>>
Submits a transaction to the blockchain to buy a hat for the given planet. You must own the planet. Warning costs real xdai. Hats are permanently locked to a planet. They are purely cosmetic and a great way to BM your opponents or just look your best. Just like in the real world, more money means more hat.
Name | Type | Default value |
---|---|---|
planetId |
LocationId |
undefined |
_bypassChecks |
boolean |
false |
Promise
<Transaction
<UnconfirmedBuyHat
>>
▸ capturePlanet(locationId
): Promise
<Transaction
<UnconfirmedCapturePlanet
>>
Name | Type |
---|---|
locationId |
LocationId |
Promise
<Transaction
<UnconfirmedCapturePlanet
>>
▸ Private
checkGameHasEnded(): boolean
boolean
▸ clearEmoji(locationId
): Promise
<void
>
If you are the owner of this planet, you can delete the emoji that is hovering above the planet.
Name | Type |
---|---|
locationId |
LocationId |
Promise
<void
>
▸ deactivateArtifact(locationId
, artifactId
, bypassChecks?
): Promise
<Transaction
<UnconfirmedDeactivateArtifact
>>
Name | Type | Default value |
---|---|---|
locationId |
LocationId |
undefined |
artifactId |
ArtifactId |
undefined |
bypassChecks |
boolean |
false |
Promise
<Transaction
<UnconfirmedDeactivateArtifact
>>
▸ depositArtifact(locationId
, artifactId
): Promise
<Transaction
<UnconfirmedDepositArtifact
>>
Submits a transaction to the blockchain to deposit an artifact on a given planet. You must own the planet and you must own the artifact directly (can't be locked in contract)
Name | Type |
---|---|
locationId |
LocationId |
artifactId |
ArtifactId |
Promise
<Transaction
<UnconfirmedDepositArtifact
>>
▸ destroy(): void
void
▸ findArtifact(planetId
, bypassChecks?
): Promise
<Transaction
<UnconfirmedFindArtifact
>>
Calls the contract to find an artifact on the given planet.
Name | Type | Default value |
---|---|---|
planetId |
LocationId |
undefined |
bypassChecks |
boolean |
false |
Promise
<Transaction
<UnconfirmedFindArtifact
>>
▸ Private
findRandomHomePlanet(): Promise
<LocatablePlanet
>
Promise
<LocatablePlanet
>
▸ forceTick(locationId
): void
Name | Type |
---|---|
locationId |
LocationId |
void
▸ getAccount(): undefined
| EthAddress
Gets the address of the player logged into this game manager.
undefined
| EthAddress
▸ getActiveArtifact(planet
): undefined
| Artifact
Gets the active artifact on this planet, if one exists.
Name | Type |
---|---|
planet |
Planet |
undefined
| Artifact
▸ getAddress(): undefined
| EthAddress
undefined
| EthAddress
▸ getAllOwnedPlanets(): Planet
[]
Gets a list of planets that have an owner.
Planet
[]
▸ getAllPlanets(): Iterable
<Planet
>
Gets all planets. This means all planets that are in the contract, and also all planets that have been mined locally. Does not update planets if they are stale. NOT PERFORMANT - for scripting only.
Iterable
<Planet
>
▸ getAllPlayers(): Player
[]
Gets a list of all the players in the game (not just the ones you've encounterd)
Player
[]
▸ getAllVoyages(): QueuedArrival
[]
Gets all voyages that have not completed.
QueuedArrival
[]
▸ getArtifactMap(): Map
<ArtifactId
, Artifact
>
Return a reference to the artifact map
Map
<ArtifactId
, Artifact
>
▸ getArtifactUpdated$(): Monomitter
<ArtifactId
>
Monomitter
<ArtifactId
>
▸ getArtifactWithId(artifactId?
): undefined
| Artifact
Gets the artifact with the given id. Null if no artifact with id exists.
Name | Type |
---|---|
artifactId? |
ArtifactId |
undefined
| Artifact
▸ getArtifactsWithIds(artifactIds?
): (undefined
| Artifact
)[]
Gets the artifacts with the given ids, including ones we know exist but haven't been loaded,
represented by undefined
.
Name | Type | Default value |
---|---|---|
artifactIds |
ArtifactId [] |
[] |
(undefined
| Artifact
)[]
▸ getCaptureZoneGenerator(): undefined
| CaptureZoneGenerator
undefined
| CaptureZoneGenerator
▸ getCaptureZones(): Set
<CaptureZone
>
Set
<CaptureZone
>
▸ getChunk(chunkFootprint
): undefined
| Chunk
Name | Type |
---|---|
chunkFootprint |
Rectangle |
undefined
| Chunk
▸ getChunkStore(): default
▸ getClaimedLocations(): Map
<LocationId
, ClaimedLocation
>
Gets a map of all location IDs which have been claimed.
Map
<LocationId
, ClaimedLocation
>
▸ getConstructors(): Object
Returns constructors of classes that may be useful for developing plugins.
Object
Name | Type |
---|---|
MinerManager |
typeof default |
SpiralPattern |
typeof SpiralPattern |
SwissCheesePattern |
typeof SwissCheesePattern |
TowardsCenterPattern |
typeof TowardsCenterPattern |
TowardsCenterPatternV2 |
typeof TowardsCenterPatternV2 |
▸ getContract(): DarkForest
DarkForest
▸ getContractAPI(): ContractsAPI
Get the thing that handles contract interaction.
▸ getContractAddress(): EthAddress
Gets the address of the DarkForest
contract, which is the 'backend' of the game.
EthAddress
▸ getContractConstants(): ContractConstants
▸ getCurrentlyExploringChunk(): undefined
| Rectangle
Gets the rectangle bounding the chunk that the miner is currently in the process of hashing.
undefined
| Rectangle
▸ getDefaultSpaceJunkForPlanetLevel(level
): number
Name | Type |
---|---|
level |
number |
number
▸ getDiagnostics(): Diagnostics
Gets some diagnostic information about the game. Returns a copy, you can't modify it.
Diagnostics
▸ getDist(fromId
, toId
): number
Gets the distance between two planets. Throws an exception if you don't know the location of either planet. Takes into account wormholes.
Name | Type |
---|---|
fromId |
LocationId |
toId |
LocationId |
number
▸ getDistCoords(fromCoords
, toCoords
): number
Gets the distance between two coordinates in space.
Name | Type |
---|---|
fromCoords |
WorldCoords |
toCoords |
WorldCoords |
number
▸ getEndTimeSeconds(): number
The game ends at a particular time in the future - get this time measured in seconds from the epoch.
number
▸ getEnergyArrivingForMove(fromId
, toId
, distance
, sentEnergy
, abandoning
): number
Gets the amount of energy that would arrive if a voyage with the given parameters was to occur. The toPlanet is optional, in case you want an estimate that doesn't include wormhole speedups.
Name | Type |
---|---|
fromId |
LocationId |
toId |
undefined | LocationId |
distance |
undefined | number |
sentEnergy |
number |
abandoning |
boolean |
number
▸ getEnergyCurveAtPercent(planet
, percent
): number
returns timestamp (seconds) that planet will reach percent% of energycap time may be in the past
Name | Type |
---|---|
planet |
Planet |
percent |
number |
number
▸ getEnergyNeededForMove(fromId
, toId
, arrivingEnergy
, abandoning?
): number
Gets the amount of energy needed in order for a voyage from the given to the given planet to arrive with your desired amount of energy.
Name | Type | Default value |
---|---|---|
fromId |
LocationId |
undefined |
toId |
LocationId |
undefined |
arrivingEnergy |
number |
undefined |
abandoning |
boolean |
false |
number
▸ getEnergyOfPlayer(player
): number
Gets the total amount of energy that lives on planets that the given player owns.
Name | Type |
---|---|
player |
EthAddress |
number
▸ getEthConnection(): EthConnection
EthConnection
▸ getExploredChunks(): Iterable
<Chunk
>
Gets all the map chunks that this client is aware of. Chunks may have come from mining, or from importing map data.
Iterable
<Chunk
>
▸ getGameObjects(): GameObjects
Gets a reference to the game's internal representation of the world state. This includes voyages, planets, artifacts, and active wormholes,
▸ getHashConfig(): HashConfig
Gets the HASH CONFIG
▸ getHashesPerSec(): number
Gets the amount of hashes per second that the miner manager is calculating.
number
▸ getHomeCoords(): undefined
| WorldCoords
Gets the location of your home planet.
undefined
| WorldCoords
▸ getHomeHash(): undefined
| LocationId
Gets the hash of the location of your home planet.
undefined
| LocationId
▸ getLocationOfPlanet(planetId
): undefined
| WorldLocation
Gets the location of the given planet. Returns undefined if the planet does not exist, or if we do not know the location of this planet NOT update the planet if the planet is stale, which means this function is fast.
Name | Type |
---|---|
planetId |
LocationId |
undefined
| WorldLocation
▸ getMaxMoveDist(planetId
, sendingPercent
, abandoning
): number
Gets the maximuim distance that you can send your energy from the given planet, using the given percentage of that planet's current silver.
Name | Type |
---|---|
planetId |
LocationId |
sendingPercent |
number |
abandoning |
boolean |
number
▸ getMiningPattern(): undefined
| MiningPattern
Gets the mining pattern that the miner is currently using.
undefined
| MiningPattern
▸ getMyArtifactMap(): Map
<ArtifactId
, Artifact
>
Return a reference to the map of my artifacts
Map
<ArtifactId
, Artifact
>
▸ getMyArtifacts(): Artifact
[]
gets both deposited artifacts that are on planets i own as well as artifacts i own
Artifact
[]
▸ getMyArtifactsUpdated$(): Monomitter
<Map
<ArtifactId
, Artifact
>>
Monomitter
<Map
<ArtifactId
, Artifact
>>
▸ getMyBalance(): BigNumber
Gets the balance of the account
BigNumber
▸ getMyBalance$(): Monomitter
<BigNumber
>
Returns the monomitter which publishes events whenever the player's balance changes.
Monomitter
<BigNumber
>
▸ getMyBalanceEth(): number
Gets the balance of the account measured in Eth (i.e. in full units of the chain).
number
▸ getMyPlanetMap(): Map
<LocationId
, Planet
>
Return a reference to the map of my planets
Map
<LocationId
, Planet
>
▸ getMyPlanets(): Planet
[]
Gets a list of the planets that the player logged into this GameManager
owns.
Planet
[]
▸ getMyPlanetsUpdated$(): Monomitter
<Map
<LocationId
, Planet
>>
Monomitter
<Map
<LocationId
, Planet
>>
▸ getMyScore(): undefined
| number
Get the score of the currently logged-in account.
undefined
| number
▸ getNextBroadcastAvailableTimestamp(): number
Gets the timestamp (ms) of the next time that we can broadcast the coordinates of a planet.
number
▸ getNextClaimAvailableTimestamp(): number
Gets the timestamp (ms) of the next time that we can claim a planet.
number
▸ getNextRevealCountdownInfo(): RevealCountdownInfo
Returns info about the next time you can broadcast coordinates
▸ getNotificationsManager(): default
▸ getPaused(): boolean
boolean
▸ getPaused$(): Monomitter
<boolean
>
Monomitter
<boolean
>
▸ getPerlinThresholds(): [number
, number
, number
]
The perlin value at each coordinate determines the space type. There are four space
types, which means there are four ranges on the number line that correspond to
each space type. This function returns the boundary values between each of these
four ranges: PERLIN_THRESHOLD_1
, PERLIN_THRESHOLD_2
, PERLIN_THRESHOLD_3
.
[number
, number
, number
]
▸ getPlanetLevel(planetId
): undefined
| PlanetLevel
Gets the level of the given planet. Returns undefined if the planet does not exist. Does NOT update the planet if the planet is stale, which means this function is fast.
Name | Type |
---|---|
planetId |
LocationId |
undefined
| PlanetLevel
▸ getPlanetMap(): Map
<LocationId
, Planet
>
Return a reference to the planet map
Map
<LocationId
, Planet
>
▸ getPlanetRarity(): number
Gets the rarity of planets in the universe
number
▸ getPlanetUpdated$(): Monomitter
<LocationId
>
Monomitter
<LocationId
>
▸ getPlanetWithCoords(coords
): undefined
| LocatablePlanet
Gets the planet that is located at the given coordinates. Returns undefined if not a valid location or if no planet exists at location. If the planet needs to be updated (because some time has passed since we last updated the planet), then updates that planet first.
Name | Type |
---|---|
coords |
WorldCoords |
undefined
| LocatablePlanet
▸ getPlanetWithId(planetId
): undefined
| Planet
Gets the planet with the given hash. Returns undefined if the planet is neither in the contract nor has been discovered locally. If the planet needs to be updated (because some time has passed since we last updated the planet), then updates that planet first.
Name | Type |
---|---|
planetId |
undefined | LocationId |
undefined
| Planet
▸ getPlanetsInRange(planetId
, sendingPercent
, abandoning
): Planet
[]
Gets all the planets that you can reach with at least 1 energy from the given planet. Does not take into account wormholes.
Name | Type |
---|---|
planetId |
LocationId |
sendingPercent |
number |
abandoning |
boolean |
Planet
[]
▸ getPlanetsInWorldRectangle(worldX
, worldY
, worldWidth
, worldHeight
, levels
, planetLevelToRadii
, updateIfStale?
): LocatablePlanet
[]
Gets the ids of all the planets that are both within the given bounding box (defined by its bottom
left coordinate, width, and height) in the world and of a level that was passed in via the
planetLevels
parameter.
Name | Type | Default value |
---|---|---|
worldX |
number |
undefined |
worldY |
number |
undefined |
worldWidth |
number |
undefined |
worldHeight |
number |
undefined |
levels |
number [] |
undefined |
planetLevelToRadii |
Map <number , Radii > |
undefined |
updateIfStale |
boolean |
true |
LocatablePlanet
[]
▸ getPlanetsWithIds(planetId
): Planet
[]
Gets a list of planets in the client's memory with the given ids. If a planet with the given id doesn't exist, no entry for that planet will be returned in the result.
Name | Type |
---|---|
planetId |
LocationId [] |
Planet
[]
▸ getPlayer(address?
): undefined
| Player
Gets either the given player, or if no address was provided, gets the player that is logged this client.
Name | Type |
---|---|
address? |
EthAddress |
undefined
| Player
▸ getPlayerScore(addr
): undefined
| number
Name | Type |
---|---|
addr |
EthAddress |
undefined
| number
▸ getPlayerSpaceJunk(addr
): undefined
| number
Name | Type |
---|---|
addr |
EthAddress |
undefined
| number
▸ getPlayerSpaceJunkLimit(addr
): undefined
| number
Name | Type |
---|---|
addr |
EthAddress |
undefined
| number
▸ getPrivateKey(): undefined
| string
Gets the private key of the burner wallet used by this account.
undefined
| string
▸ getRangeBuff(abandoning
): number
Name | Type |
---|---|
abandoning |
boolean |
number
▸ getRevealedLocations(): Map
<LocationId
, RevealedLocation
>
Gets a map of all location IDs whose coords have been publically revealed
Map
<LocationId
, RevealedLocation
>
▸ getSafeMode(): boolean
boolean
▸ getSignedTwitter(twitter
): Promise
<string
>
Signs the given twitter handle with the private key of the current user. Used to verify that the person who owns the Dark Forest account was the one that attempted to link a twitter to their account.
Name | Type |
---|---|
twitter |
string |
Promise
<string
>
▸ getSilverCurveAtPercent(planet
, percent
): undefined
| number
returns timestamp (seconds) that planet will reach percent% of silcap if doesn't produce silver, returns undefined if already over percent% of silcap,
Name | Type |
---|---|
planet |
Planet |
percent |
number |
undefined
| number
▸ getSilverOfPlayer(player
): number
Gets the total amount of silver that lives on planets that the given player owns.
Name | Type |
---|---|
player |
EthAddress |
number
▸ getSnarkHelper(): default
▸ Private
getSpaceships(): Promise
<void
>
Promise
<void
>
▸ getSpeedBuff(abandoning
): number
Right now the only buffs supported in this way are speed/range buffs from Abandoning a planet.
The abandoning argument is used when interacting with this function programmatically.
Name | Type |
---|---|
abandoning |
boolean |
number
▸ getStalePlanetWithId(planetId
): undefined
| Planet
Name | Type |
---|---|
planetId |
LocationId |
undefined
| Planet
▸ getTemperature(coords
): number
Gets the temperature of a given location.
Name | Type |
---|---|
coords |
WorldCoords |
number
▸ getTimeForMove(fromId
, toId
, abandoning?
): number
Gets the amount of time, in seconds that a voyage between from the first to the second planet would take.
Name | Type | Default value |
---|---|---|
fromId |
LocationId |
undefined |
toId |
LocationId |
undefined |
abandoning |
boolean |
false |
number
▸ getTokenMintEndTimeSeconds(): number
Dark Forest tokens can only be minted up to a certain time - get this time measured in seconds from epoch.
number
▸ getTwitter(address
): undefined
| string
Gets the twitter handle of the given ethereum account which is associated with Dark Forest.
Name | Type |
---|---|
address |
undefined | EthAddress |
undefined
| string
▸ getUIEventEmitter(): default
Helpful for listening to user input events.
▸ getUnconfirmedMoves(): Transaction
<UnconfirmedMove
>[]
Gets all moves that this client has queued to be uploaded to the contract, but have not been successfully confirmed yet.
Transaction
<UnconfirmedMove
>[]
▸ getUnconfirmedUpgrades(): Transaction
<UnconfirmedUpgrade
>[]
Gets all upgrades that this client has queued to be uploaded to the contract, but have not been successfully confirmed yet.
Transaction
<UnconfirmedUpgrade
>[]
▸ getUnconfirmedWormholeActivations(): Transaction
<UnconfirmedActivateArtifact
>[]
Transaction
<UnconfirmedActivateArtifact
>[]
▸ getUniverseTotalEnergy(): number
Gets the total amount of energy that lives on a planet that somebody owns.
number
▸ getUpgrade(branch
, level
): Upgrade
Returns the upgrade that would be applied to a planet given a particular upgrade branch (defense, range, speed) and level of upgrade.
Name | Type |
---|---|
branch |
number |
level |
number |
Upgrade
▸ getWorldRadius(): number
Gets the radius of the playable area of the universe.
number
▸ getWorldSilver(): number
Gets the total amount of silver that lives on a planet that somebody owns.
number
▸ getWormholeFactors(fromPlanet
, toPlanet
): undefined
| { distanceFactor
: number
; speedFactor
: number
}
If there's an active artifact on either of these planets which happens to be a wormhole which is active and targetting the other planet, return the wormhole boost which is greater. Values represent a multiplier.
Name | Type |
---|---|
fromPlanet |
Planet |
toPlanet |
Planet |
undefined
| { distanceFactor
: number
; speedFactor
: number
}
▸ getWormholes(): Iterable
<Wormhole
>
Iterable
<Wormhole
>
▸ hardRefreshArtifact(artifactId
): Promise
<void
>
Name | Type |
---|---|
artifactId |
ArtifactId |
Promise
<void
>
▸ hardRefreshPlanet(planetId
): Promise
<void
>
Name | Type |
---|---|
planetId |
LocationId |
Promise
<void
>
▸ Private
hardRefreshPlayer(address?
): Promise
<void
>
Name | Type |
---|---|
address? |
EthAddress |
Promise
<void
>
▸ hasJoinedGame(): boolean
Whether or not this client has successfully found and landed on a home planet.
boolean
▸ hasMinedChunk(chunkLocation
): boolean
Whether or not the given rectangle has been mined.
Name | Type |
---|---|
chunkLocation |
Rectangle |
boolean
▸ Private
initMiningManager(homeCoords
, cores?
): void
Name | Type |
---|---|
homeCoords |
WorldCoords |
cores? |
number |
void
▸ invadePlanet(locationId
): Promise
<Transaction
<UnconfirmedInvadePlanet
>>
Name | Type |
---|---|
locationId |
LocationId |
Promise
<Transaction
<UnconfirmedInvadePlanet
>>
▸ isAdmin(): boolean
boolean
▸ isMining(): boolean
Whether or not the miner is currently exploring space.
boolean
▸ isPlanetMineable(p
): boolean
Whether or not the given planet is capable of minting an artifact.
Name | Type |
---|---|
p |
Planet |
boolean
▸ isRoundOver(): boolean
Returns whether or not the current round has ended.
boolean
▸ joinGame(beforeRetry
): Promise
<void
>
Attempts to join the game. Should not be called once you've already joined.
Name | Type |
---|---|
beforeRetry |
(e : Error ) => Promise <boolean > |
Promise
<void
>
▸ listenForNewBlock(): void
void
▸ loadContract<T
>(contractAddress
, contractABI
): Promise
<T
>
Returns an instance of a Contract
from the ethersjs library. This is the library we use to
connect to the blockchain. For documentation about how Contract
works, see:
https://docs.ethers.io/v5/api/contract/contract/
Also, registers your contract in the system to make calls against it and to reload it when necessary (such as the RPC endpoint changing).
Name | Type |
---|---|
T |
extends Contract <T > |
Name | Type |
---|---|
contractAddress |
string |
contractABI |
ContractInterface |
Promise
<T
>
▸ loadPlugins(): Promise
<SerializedPlugin
[]>
Load the serialized versions of all the plugins that this player has.
Promise
<SerializedPlugin
[]>
▸ locationBigIntFromCoords(coords
): BigInteger
Name | Type |
---|---|
coords |
WorldCoords |
BigInteger
▸ Private
locationFromCoords(coords
): WorldLocation
computes the WorldLocation object corresponding to a set of coordinates very slow since it actually calculates the hash; do not use in render loop
Name | Type |
---|---|
coords |
WorldCoords |
WorldLocation
▸ move(from
, to
, forces
, silver
, artifactMoved?
, abandoning?
, bypassChecks?
): Promise
<Transaction
<UnconfirmedMove
>>
Submits a transaction to the blockchain to move the given amount of resources from the given planet to the given planet.
Name | Type | Default value |
---|---|---|
from |
LocationId |
undefined |
to |
LocationId |
undefined |
forces |
number |
undefined |
silver |
number |
undefined |
artifactMoved? |
ArtifactId |
undefined |
abandoning |
boolean |
false |
bypassChecks |
boolean |
false |
Promise
<Transaction
<UnconfirmedMove
>>
▸ Private
onTxCancelled(tx
): void
Name | Type |
---|---|
tx |
Transaction <TxIntent > |
void
▸ Private
onTxConfirmed(tx
): void
Name | Type |
---|---|
tx |
Transaction <TxIntent > |
void
▸ Private
onTxReverted(tx
): void
Name | Type |
---|---|
tx |
Transaction <TxIntent > |
void
▸ Private
onTxSubmit(tx
): void
Name | Type |
---|---|
tx |
Transaction <TxIntent > |
void
▸ prospectPlanet(planetId
, bypassChecks?
): Promise
<Transaction
<UnconfirmedProspectPlanet
>>
Name | Type | Default value |
---|---|---|
planetId |
LocationId |
undefined |
bypassChecks |
boolean |
false |
Promise
<Transaction
<UnconfirmedProspectPlanet
>>
▸ Private
refreshNetworkHealth(): Promise
<void
>
Promise
<void
>
▸ Private
refreshScoreboard(): Promise
<void
>
Promise
<void
>
▸ refreshServerPlanetStates(planetIds
): Promise
<void
>
We have two locations which planet state can live: on the server, and on the blockchain. We use the blockchain for the 'physics' of the universe, and the webserver for optional 'add-on' features, which are cryptographically secure, but live off-chain.
This function loads the planet states which live on the server. Plays nicely with our notifications system and sets the appropriate loading state values on the planet.
Name | Type |
---|---|
planetIds |
LocationId [] |
Promise
<void
>
▸ Private
refreshTwitters(): Promise
<void
>
Promise
<void
>
▸ revealLocation(planetId
): Promise
<Transaction
<UnconfirmedReveal
>>
Reveals a planet's location on-chain.
Name | Type |
---|---|
planetId |
LocationId |
Promise
<Transaction
<UnconfirmedReveal
>>
▸ savePlugins(savedPlugins
): Promise
<void
>
Overwrites all the saved plugins to equal the given array of plugins.
Name | Type |
---|---|
savedPlugins |
SerializedPlugin [] |
Promise
<void
>
▸ setMinerCores(nCores
): void
Set the amount of cores to mine the universe with. More cores equals faster!
Name | Type |
---|---|
nCores |
number |
void
▸ setMiningPattern(pattern
): void
Sets the mining pattern of the miner. This kills the old miner and starts this one.
Name | Type |
---|---|
pattern |
MiningPattern |
void
▸ setPlanetEmoji(locationId
, emojiStr
): Promise
<void
>
If you are the owner of this planet, you can set an 'emoji' to hover above the planet.
emojiStr
must be a string that contains a single emoji, otherwise this function will throw an
error.
The emoji is stored off-chain in a postgres database. We verify planet ownership via a contract call from the webserver, and by verifying that the request to add (or remove) an emoji from a planet was signed by the owner.
Name | Type |
---|---|
locationId |
LocationId |
emojiStr |
string |
Promise
<void
>
▸ Private
setPlayerTwitters(twitters
): void
Name | Type |
---|---|
twitters |
AddressTwitterMap |
void
▸ Private
setRadius(worldRadius
): void
Name | Type |
---|---|
worldRadius |
number |
void
▸ setSafeMode(safeMode
): void
Name | Type |
---|---|
safeMode |
boolean |
void
▸ setSnarkCacheSize(size
): void
Changes the amount of move snark proofs that are cached.
Name | Type |
---|---|
size |
number |
void
▸ Private
softRefreshPlanet(planetId
): Promise
<void
>
Name | Type |
---|---|
planetId |
LocationId |
Promise
<void
>
▸ spaceTypeFromPerlin(perlin
): SpaceType
Each coordinate lives in a particular type of space, determined by a smooth random function called 'perlin noise.
Name | Type |
---|---|
perlin |
number |
SpaceType
▸ spaceTypePerlin(coords
, floor
): number
Gets the perlin value at the given location in the world. SpaceType is based on this value.
Name | Type |
---|---|
coords |
WorldCoords |
floor |
boolean |
number
▸ startExplore(): void
Starts the miner.
void
▸ stopExplore(): void
Stops the miner.
void
▸ submitDisconnectTwitter(twitter
): Promise
<void
>
Name | Type |
---|---|
twitter |
string |
Promise
<void
>
▸ Private
submitPlanetMessage(locationId
, type
, body
): Promise
<void
>
The planet emoji feature is built on top of a more general 'Planet Message' system, which allows players to upload pieces of data called 'Message's to planets that they own. Emojis are just one type of message. Their implementation leaves the door open to more off-chain data.
Name | Type |
---|---|
locationId |
LocationId |
type |
PlanetMessageType |
body |
unknown |
Promise
<void
>
▸ submitTransaction<T
>(txIntent
, overrides?
): Promise
<Transaction
<T
>>
Name | Type |
---|---|
T |
extends TxIntent |
Name | Type |
---|---|
txIntent |
T |
overrides? |
TransactionRequest |
Promise
<Transaction
<T
>>
▸ submitVerifyTwitter(twitter
): Promise
<boolean
>
Once you have posted the verification tweet - complete the twitter-account-linking process by telling the Dark Forest webserver to look at that tweet.
Name | Type |
---|---|
twitter |
string |
Promise
<boolean
>
▸ testNotification(): void
void
▸ timeUntilNextBroadcastAvailable(): number
Gets the amount of time (ms) until the next time the current player can broadcast a planet.
number
▸ transferOwnership(planetId
, newOwner
, bypassChecks?
): Promise
<Transaction
<UnconfirmedPlanetTransfer
>>
Name | Type | Default value |
---|---|---|
planetId |
LocationId |
undefined |
newOwner |
EthAddress |
undefined |
bypassChecks |
boolean |
false |
Promise
<Transaction
<UnconfirmedPlanetTransfer
>>
▸ updateDiagnostics(updateFn
): void
Updates the diagnostic info of the game using the supplied function. Ideally, each spot in the codebase that would like to record a metric is able to update its specific metric in a convenient manner.
Name | Type |
---|---|
updateFn |
(d : Diagnostics ) => void |
void
▸ upgrade(planetId
, branch
, _bypassChecks?
): Promise
<Transaction
<UnconfirmedUpgrade
>>
Submits a transaction to the blockchain to upgrade the given planet with the given upgrade branch. You must own the planet, and have enough silver on it to complete the upgrade.
Name | Type | Default value |
---|---|---|
planetId |
LocationId |
undefined |
branch |
number |
undefined |
_bypassChecks |
boolean |
false |
Promise
<Transaction
<UnconfirmedUpgrade
>>
▸ Private
uploadDiagnostics(): Promise
<void
>
Promise
<void
>
▸ Private
verifyMessage(message
): Promise
<boolean
>
Checks that a message signed by {@link GameManager#signMessage} was signed by the address that it claims it was signed by.
Name | Type |
---|---|
message |
SignedMessage <unknown > |
Promise
<boolean
>
▸ waitForPlanet<T
>(locationId
, predicate
): Promise
<T
>
Listen for changes to a planet take action, eg. waitForPlanet("yourAsteroidId", ({current}) => current.silverCap / current.silver > 90) .then(() => { // Send Silver to nearby planet })
Name |
---|
T |
Name | Type | Description |
---|---|---|
locationId |
LocationId |
A locationId to watch for updates |
predicate |
(__namedParameters : Diff <Planet >) => undefined | T |
a function that accepts a Diff and should return a truth-y value, value will be passed to promise.resolve() |
Promise
<T
>
a promise that will resolve with results returned from the predicate function
▸ withdrawArtifact(locationId
, artifactId
, bypassChecks?
): Promise
<Transaction
<UnconfirmedWithdrawArtifact
>>
Withdraws the artifact that is locked up on the given planet.
Name | Type | Default value |
---|---|---|
locationId |
LocationId |
undefined |
artifactId |
ArtifactId |
undefined |
bypassChecks |
boolean |
true |
Promise
<Transaction
<UnconfirmedWithdrawArtifact
>>
▸ withdrawSilver(locationId
, amount
, bypassChecks?
): Promise
<Transaction
<UnconfirmedWithdrawSilver
>>
Name | Type | Default value |
---|---|---|
locationId |
LocationId |
undefined |
amount |
number |
undefined |
bypassChecks |
boolean |
false |
Promise
<Transaction
<UnconfirmedWithdrawSilver
>>
▸ Static
create(__namedParameters
): Promise
<default
>
Name | Type |
---|---|
__namedParameters |
Object |
__namedParameters.connection |
EthConnection |
__namedParameters.contractAddress |
EthAddress |
__namedParameters.terminal |
MutableRefObject <undefined | TerminalHandle > |
Promise
<default
>