mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 12:15:44 +01:00
API: Add nextUpdate()
promise for systems with bonus time (#845)
This commit is contained in:
parent
daa7a22786
commit
61c311a126
@ -4,7 +4,7 @@
|
||||
|
||||
## Bladeburner.getBonusTime() method
|
||||
|
||||
Get bladeburner bonus time.
|
||||
Get Bladeburner bonus time.
|
||||
|
||||
**Signature:**
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
## Bladeburner.getStamina() method
|
||||
|
||||
Get bladeburner stamina.
|
||||
Get Bladeburner stamina.
|
||||
|
||||
**Signature:**
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
## Bladeburner.inBladeburner() method
|
||||
|
||||
Returns whether player is a member of bladeburner division. Does not require API access.
|
||||
Returns whether player is a member of Bladeburner division. Does not require API access.
|
||||
|
||||
**Signature:**
|
||||
|
||||
@ -15,7 +15,7 @@ inBladeburner(): boolean;
|
||||
|
||||
boolean
|
||||
|
||||
whether player is a member of bladeburner division.
|
||||
whether player is a member of Bladeburner division.
|
||||
|
||||
## Remarks
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
## Bladeburner.joinBladeburnerDivision() method
|
||||
|
||||
Join the bladeburner division.
|
||||
Join the Bladeburner division.
|
||||
|
||||
**Signature:**
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
## Bladeburner.joinBladeburnerFaction() method
|
||||
|
||||
Join the bladeburner faction.
|
||||
Join the Bladeburner faction.
|
||||
|
||||
**Signature:**
|
||||
|
||||
|
@ -31,7 +31,7 @@ You have to be employed in the Bladeburner division and be in BitNode-7 or have
|
||||
| [getActionTime(type, name)](./bitburner.bladeburner.getactiontime.md) | Get the time to complete an action. |
|
||||
| [getBlackOpNames()](./bitburner.bladeburner.getblackopnames.md) | List all black ops. |
|
||||
| [getBlackOpRank(name)](./bitburner.bladeburner.getblackoprank.md) | Get black op required rank. |
|
||||
| [getBonusTime()](./bitburner.bladeburner.getbonustime.md) | Get bladeburner bonus time. |
|
||||
| [getBonusTime()](./bitburner.bladeburner.getbonustime.md) | Get Bladeburner bonus time. |
|
||||
| [getCity()](./bitburner.bladeburner.getcity.md) | Get current city. |
|
||||
| [getCityChaos(city)](./bitburner.bladeburner.getcitychaos.md) | Get chaos of a city. |
|
||||
| [getCityCommunities(city)](./bitburner.bladeburner.getcitycommunities.md) | Get number of communities in a city. |
|
||||
@ -46,16 +46,17 @@ You have to be employed in the Bladeburner division and be in BitNode-7 or have
|
||||
| [getSkillNames()](./bitburner.bladeburner.getskillnames.md) | List all skills. |
|
||||
| [getSkillPoints()](./bitburner.bladeburner.getskillpoints.md) | Get bladeburner skill points. |
|
||||
| [getSkillUpgradeCost(skillName, count)](./bitburner.bladeburner.getskillupgradecost.md) | Get cost to upgrade skill. |
|
||||
| [getStamina()](./bitburner.bladeburner.getstamina.md) | Get bladeburner stamina. |
|
||||
| [getStamina()](./bitburner.bladeburner.getstamina.md) | Get Bladeburner stamina. |
|
||||
| [getTeamSize(type, name)](./bitburner.bladeburner.getteamsize.md) | Get team size. |
|
||||
| [inBladeburner()](./bitburner.bladeburner.inbladeburner.md) | Returns whether player is a member of bladeburner division. Does not require API access. |
|
||||
| [joinBladeburnerDivision()](./bitburner.bladeburner.joinbladeburnerdivision.md) | Join the bladeburner division. |
|
||||
| [joinBladeburnerFaction()](./bitburner.bladeburner.joinbladeburnerfaction.md) | Join the bladeburner faction. |
|
||||
| [inBladeburner()](./bitburner.bladeburner.inbladeburner.md) | Returns whether player is a member of Bladeburner division. Does not require API access. |
|
||||
| [joinBladeburnerDivision()](./bitburner.bladeburner.joinbladeburnerdivision.md) | Join the Bladeburner division. |
|
||||
| [joinBladeburnerFaction()](./bitburner.bladeburner.joinbladeburnerfaction.md) | Join the Bladeburner faction. |
|
||||
| [nextUpdate()](./bitburner.bladeburner.nextupdate.md) | Sleep until the next Bladeburner update has happened. |
|
||||
| [setActionAutolevel(type, name, autoLevel)](./bitburner.bladeburner.setactionautolevel.md) | Set an action autolevel. |
|
||||
| [setActionLevel(type, name, level)](./bitburner.bladeburner.setactionlevel.md) | Set the level of an action. |
|
||||
| [setTeamSize(type, name, size)](./bitburner.bladeburner.setteamsize.md) | Set team size. |
|
||||
| [startAction(type, name)](./bitburner.bladeburner.startaction.md) | Start an action. |
|
||||
| [stopBladeburnerAction()](./bitburner.bladeburner.stopbladeburneraction.md) | Stop current action. |
|
||||
| [switchCity(city)](./bitburner.bladeburner.switchcity.md) | Travel to another city in bladeburner. |
|
||||
| [switchCity(city)](./bitburner.bladeburner.switchcity.md) | Travel to another city in Bladeburner. |
|
||||
| [upgradeSkill(skillName, count)](./bitburner.bladeburner.upgradeskill.md) | Upgrade skill. |
|
||||
|
||||
|
37
markdown/bitburner.bladeburner.nextupdate.md
Normal file
37
markdown/bitburner.bladeburner.nextupdate.md
Normal file
@ -0,0 +1,37 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [Bladeburner](./bitburner.bladeburner.md) > [nextUpdate](./bitburner.bladeburner.nextupdate.md)
|
||||
|
||||
## Bladeburner.nextUpdate() method
|
||||
|
||||
Sleep until the next Bladeburner update has happened.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
nextUpdate(): Promise<number>;
|
||||
```
|
||||
**Returns:**
|
||||
|
||||
Promise<number>
|
||||
|
||||
Promise that resolves to the number of milliseconds of Bladeburner time that were processed in the previous update (1000 - 5000 ms).
|
||||
|
||||
## Remarks
|
||||
|
||||
RAM cost: 1 GB
|
||||
|
||||
The amount of real time spent asleep between updates can vary due to "bonus time" (usually 1 second).
|
||||
|
||||
## Example
|
||||
|
||||
|
||||
```js
|
||||
while (true) {
|
||||
const duration = await ns.bladeburner.nextUpdate();
|
||||
ns.print(`Bladeburner Division completed ${ns.tFormat(duration)} of actions.`);
|
||||
ns.print(`Bonus time remaining: ${ns.tFormat(ns.bladeburner.getBonusTime())}`);
|
||||
// Manage the Bladeburner division
|
||||
}
|
||||
```
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
## Bladeburner.switchCity() method
|
||||
|
||||
Travel to another city in bladeburner.
|
||||
Travel to another city in Bladeburner.
|
||||
|
||||
**Signature:**
|
||||
|
||||
|
@ -39,6 +39,7 @@ export interface Corporation extends WarehouseAPI, OfficeAPI
|
||||
| [issueDividends(rate)](./bitburner.corporation.issuedividends.md) | Issue dividends |
|
||||
| [issueNewShares(amount)](./bitburner.corporation.issuenewshares.md) | Issue new shares |
|
||||
| [levelUpgrade(upgradeName)](./bitburner.corporation.levelupgrade.md) | Level an upgrade. |
|
||||
| [nextUpdate()](./bitburner.corporation.nextupdate.md) | Sleep until the next Corporation update has happened. |
|
||||
| [purchaseUnlock(upgradeName)](./bitburner.corporation.purchaseunlock.md) | Unlock an upgrade |
|
||||
| [sellShares(amount)](./bitburner.corporation.sellshares.md) | Sell Shares. Transfer shares from the CEO to public traders to receive money in the player's wallet. |
|
||||
|
||||
|
41
markdown/bitburner.corporation.nextupdate.md
Normal file
41
markdown/bitburner.corporation.nextupdate.md
Normal file
@ -0,0 +1,41 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [Corporation](./bitburner.corporation.md) > [nextUpdate](./bitburner.corporation.nextupdate.md)
|
||||
|
||||
## Corporation.nextUpdate() method
|
||||
|
||||
Sleep until the next Corporation update has happened.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
nextUpdate(): Promise<CorpStateName>;
|
||||
```
|
||||
**Returns:**
|
||||
|
||||
Promise<[CorpStateName](./bitburner.corpstatename.md)<!-- -->>
|
||||
|
||||
Promise that resolves to the name of the state that was just processed.
|
||||
|
||||
I.e. when the state is PURCHASE, it means purchasing has just happened. Note that this is the state just before `getCorporation().state`<!-- -->.
|
||||
|
||||
Possible states are START, PURCHASE, PRODUCTION, EXPORT, SALE.
|
||||
|
||||
## Remarks
|
||||
|
||||
RAM cost: 1 GB
|
||||
|
||||
The amount of real time spent asleep between updates can vary due to "bonus time" (usually 200 milliseconds - 2 seconds).
|
||||
|
||||
## Example
|
||||
|
||||
|
||||
```js
|
||||
while (true) {
|
||||
const prevState = await ns.corporation.nextUpdate();
|
||||
const nextState = ns.corporation.getCorporation().state;
|
||||
ns.print(`Corporation finished with ${prevState}, next will be ${nextState}.`);
|
||||
// Manage the Corporation
|
||||
}
|
||||
```
|
||||
|
@ -38,10 +38,11 @@ If you are not in BitNode-2, then you must have Source-File 2 in order to use th
|
||||
| [getTaskNames()](./bitburner.gang.gettasknames.md) | List member task names. |
|
||||
| [getTaskStats(name)](./bitburner.gang.gettaskstats.md) | Get stats of a task. |
|
||||
| [inGang()](./bitburner.gang.ingang.md) | Check if you're in a gang. |
|
||||
| [nextUpdate()](./bitburner.gang.nextupdate.md) | Sleeps until the next Gang update has happened. |
|
||||
| [purchaseEquipment(memberName, equipName)](./bitburner.gang.purchaseequipment.md) | Purchase an equipment for a gang member. |
|
||||
| [recruitMember(name)](./bitburner.gang.recruitmember.md) | Recruit a new gang member. |
|
||||
| [renameMember(memberName, newName)](./bitburner.gang.renamemember.md) | Rename a Gang member to a new unique name. |
|
||||
| [respectForNextRecruit()](./bitburner.gang.respectfornextrecruit.md) | Check the amount of Respect needed for your next gang recruit. |
|
||||
| [setMemberTask(memberName, taskName)](./bitburner.gang.setmembertask.md) | Set gang member to task. |
|
||||
| [setTerritoryWarfare(engage)](./bitburner.gang.setterritorywarfare.md) | Enable/Disable territory warfare. |
|
||||
| [setTerritoryWarfare(engage)](./bitburner.gang.setterritorywarfare.md) | Enable/Disable territory clashes. |
|
||||
|
||||
|
37
markdown/bitburner.gang.nextupdate.md
Normal file
37
markdown/bitburner.gang.nextupdate.md
Normal file
@ -0,0 +1,37 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [Gang](./bitburner.gang.md) > [nextUpdate](./bitburner.gang.nextupdate.md)
|
||||
|
||||
## Gang.nextUpdate() method
|
||||
|
||||
Sleeps until the next Gang update has happened.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
nextUpdate(): Promise<number>;
|
||||
```
|
||||
**Returns:**
|
||||
|
||||
Promise<number>
|
||||
|
||||
Promise that resolves to the number of milliseconds of Gang time that were processed in the previous update (2000 - 5000 ms).
|
||||
|
||||
## Remarks
|
||||
|
||||
RAM cost: 1 GB
|
||||
|
||||
The amount of real time spent asleep between updates can vary due to "bonus time".
|
||||
|
||||
## Example
|
||||
|
||||
|
||||
```js
|
||||
while (true) {
|
||||
const duration = await ns.gang.nextUpdate();
|
||||
ns.print(`Gang completed ${ns.tFormat(duration)} of activity.`);
|
||||
ns.print(`Bonus time remaining: ${ns.tFormat(ns.gang.getBonusTime())}`);
|
||||
// Manage the Gang
|
||||
}
|
||||
```
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
## Gang.setTerritoryWarfare() method
|
||||
|
||||
Enable/Disable territory warfare.
|
||||
Enable/Disable territory clashes.
|
||||
|
||||
**Signature:**
|
||||
|
||||
@ -16,7 +16,7 @@ setTerritoryWarfare(engage: boolean): void;
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| engage | boolean | Whether or not to engage in territory warfare. |
|
||||
| engage | boolean | Whether or not to engage in territory clashes. |
|
||||
|
||||
**Returns:**
|
||||
|
||||
@ -26,5 +26,5 @@ void
|
||||
|
||||
RAM cost: 2 GB
|
||||
|
||||
Set whether or not the gang should engage in territory warfare
|
||||
Set whether or not the gang should engage in territory clashes
|
||||
|
||||
|
@ -25,7 +25,7 @@ interface GangGenInfo
|
||||
| [respectGainRate](./bitburner.ganggeninfo.respectgainrate.md) | | number | Respect earned per game cycle |
|
||||
| [territory](./bitburner.ganggeninfo.territory.md) | | number | Amount of territory held |
|
||||
| [territoryClashChance](./bitburner.ganggeninfo.territoryclashchance.md) | | number | Clash chance |
|
||||
| [territoryWarfareEngaged](./bitburner.ganggeninfo.territorywarfareengaged.md) | | boolean | Indicating if territory warfare is enabled |
|
||||
| [territoryWarfareEngaged](./bitburner.ganggeninfo.territorywarfareengaged.md) | | boolean | Indicating if territory clashes are enabled |
|
||||
| [wantedLevel](./bitburner.ganggeninfo.wantedlevel.md) | | number | Gang's wanted level |
|
||||
| [wantedLevelGainRate](./bitburner.ganggeninfo.wantedlevelgainrate.md) | | number | Wanted level gained/lost per game cycle (negative for losses) |
|
||||
| [wantedPenalty](./bitburner.ganggeninfo.wantedpenalty.md) | | number | Number indicating the current wanted penalty |
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
## GangGenInfo.territoryWarfareEngaged property
|
||||
|
||||
Indicating if territory warfare is enabled
|
||||
Indicating if territory clashes are enabled
|
||||
|
||||
**Signature:**
|
||||
|
||||
|
27
markdown/bitburner.tix.getbonustime.md
Normal file
27
markdown/bitburner.tix.getbonustime.md
Normal file
@ -0,0 +1,27 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [TIX](./bitburner.tix.md) > [getBonusTime](./bitburner.tix.getbonustime.md)
|
||||
|
||||
## TIX.getBonusTime() method
|
||||
|
||||
Get Stock Market bonus time.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
getBonusTime(): number;
|
||||
```
|
||||
**Returns:**
|
||||
|
||||
number
|
||||
|
||||
Amount of accumulated “bonus time” (milliseconds) for the Stock Market mechanic.
|
||||
|
||||
## Remarks
|
||||
|
||||
RAM cost: 0 GB
|
||||
|
||||
“Bonus time” is accumulated when the game is offline or if the game is inactive in the browser.
|
||||
|
||||
Stock Market prices update more frequently during “bonus time”.
|
||||
|
@ -21,6 +21,7 @@ export interface TIX
|
||||
| [cancelOrder(sym, shares, price, type, pos)](./bitburner.tix.cancelorder.md) | Cancel order for stocks. |
|
||||
| [getAskPrice(sym)](./bitburner.tix.getaskprice.md) | Returns the ask price of that stock. |
|
||||
| [getBidPrice(sym)](./bitburner.tix.getbidprice.md) | Returns the bid price of that stock. |
|
||||
| [getBonusTime()](./bitburner.tix.getbonustime.md) | Get Stock Market bonus time. |
|
||||
| [getConstants()](./bitburner.tix.getconstants.md) | Get game constants for the stock market mechanic. |
|
||||
| [getForecast(sym)](./bitburner.tix.getforecast.md) | Returns the probability that the specified stock’s price will increase (as opposed to decrease) during the next tick. |
|
||||
| [getMaxShares(sym)](./bitburner.tix.getmaxshares.md) | Returns the maximum number of shares of a stock. |
|
||||
@ -36,6 +37,7 @@ export interface TIX
|
||||
| [has4SDataTIXAPI()](./bitburner.tix.has4sdatatixapi.md) | Returns true if the player has access to the 4SData TIX API |
|
||||
| [hasTIXAPIAccess()](./bitburner.tix.hastixapiaccess.md) | Returns true if the player has access to the TIX API |
|
||||
| [hasWSEAccount()](./bitburner.tix.haswseaccount.md) | Returns true if the player has access to a WSE Account |
|
||||
| [nextUpdate()](./bitburner.tix.nextupdate.md) | Sleep until the next Stock Market price update has happened. |
|
||||
| [placeOrder(sym, shares, price, type, pos)](./bitburner.tix.placeorder.md) | Place order for stocks. |
|
||||
| [purchase4SMarketData()](./bitburner.tix.purchase4smarketdata.md) | Purchase 4S Market Data Access. |
|
||||
| [purchase4SMarketDataTixApi()](./bitburner.tix.purchase4smarketdatatixapi.md) | Purchase 4S Market Data TIX API Access. |
|
||||
|
35
markdown/bitburner.tix.nextupdate.md
Normal file
35
markdown/bitburner.tix.nextupdate.md
Normal file
@ -0,0 +1,35 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [bitburner](./bitburner.md) > [TIX](./bitburner.tix.md) > [nextUpdate](./bitburner.tix.nextupdate.md)
|
||||
|
||||
## TIX.nextUpdate() method
|
||||
|
||||
Sleep until the next Stock Market price update has happened.
|
||||
|
||||
**Signature:**
|
||||
|
||||
```typescript
|
||||
nextUpdate(): Promise<number>;
|
||||
```
|
||||
**Returns:**
|
||||
|
||||
Promise<number>
|
||||
|
||||
Promise that resolves to the number of milliseconds of Stock Market time that were processed in the previous update (always 6000 ms).
|
||||
|
||||
## Remarks
|
||||
|
||||
RAM cost: 1 GB
|
||||
|
||||
The amount of real time spent asleep between updates can vary due to "bonus time" (usually 4 seconds - 6 seconds).
|
||||
|
||||
## Example
|
||||
|
||||
|
||||
```js
|
||||
while (true) {
|
||||
await ns.stock.nextUpdate();
|
||||
// Manage your stock portfolio
|
||||
}
|
||||
```
|
||||
|
@ -43,6 +43,8 @@ export interface BlackOpsAttempt {
|
||||
action?: BlackOperation;
|
||||
}
|
||||
|
||||
export const BladeburnerResolvers: ((msProcessed: number) => void)[] = [];
|
||||
|
||||
export class Bladeburner {
|
||||
numHosp = 0;
|
||||
moneyLost = 0;
|
||||
@ -2062,6 +2064,11 @@ export class Bladeburner {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle "nextUpdate" resolvers after this update
|
||||
for (const resolve of BladeburnerResolvers.splice(0)) {
|
||||
resolve(seconds * 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,8 @@ import { formatMoney } from "../ui/formatNumber";
|
||||
import { isPositiveInteger } from "../types";
|
||||
import { createEnumKeyedRecord, getRecordValues } from "../Types/Record";
|
||||
|
||||
export const CorporationResolvers: ((prevState: CorpStateName) => void)[] = [];
|
||||
|
||||
interface IParams {
|
||||
name?: string;
|
||||
seedFunded?: boolean;
|
||||
@ -170,6 +172,11 @@ export class Corporation {
|
||||
}
|
||||
|
||||
this.state.nextState();
|
||||
|
||||
// Handle "nextUpdate" resolvers after this update
|
||||
for (const resolve of CorporationResolvers.splice(0)) {
|
||||
resolve(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,9 @@ import { WorkerScript } from "../Netscript/WorkerScript";
|
||||
import { Player } from "@player";
|
||||
import { PowerMultiplier } from "./data/power";
|
||||
import { FactionName } from "@enums";
|
||||
import { CONSTANTS } from "../Constants";
|
||||
|
||||
export const GangResolvers: ((msProcessed: number) => void)[] = [];
|
||||
|
||||
export class Gang {
|
||||
facName: FactionName;
|
||||
@ -102,6 +105,11 @@ export class Gang {
|
||||
} catch (e: unknown) {
|
||||
console.error(`Exception caught when processing Gang: ${e}`);
|
||||
}
|
||||
|
||||
// Handle "nextUpdate" resolvers after this update
|
||||
for (const resolve of GangResolvers.splice(0)) {
|
||||
resolve(cycles * CONSTANTS.MilliPerCycle);
|
||||
}
|
||||
}
|
||||
|
||||
/** Process respect/wanted/money gains
|
||||
|
@ -80,6 +80,8 @@ export const RamCostConstants = {
|
||||
InfiltrationGetLocations: 5,
|
||||
InfiltrationGetInfiltrations: 15,
|
||||
StanekAcceptGift: 2,
|
||||
|
||||
CycleTiming: 1,
|
||||
};
|
||||
|
||||
function SF4Cost(cost: number): () => number {
|
||||
@ -124,6 +126,8 @@ const stock = {
|
||||
hasTIXAPIAccess: 0.05,
|
||||
has4SData: 0.05,
|
||||
has4SDataTIXAPI: 0.05,
|
||||
getBonusTime: 0,
|
||||
nextUpdate: RamCostConstants.CycleTiming,
|
||||
getSymbols: RamCostConstants.GetStock,
|
||||
getPrice: RamCostConstants.GetStock,
|
||||
getOrganization: RamCostConstants.GetStock,
|
||||
@ -235,6 +239,7 @@ const gang = {
|
||||
setTerritoryWarfare: RamCostConstants.GangApiBase / 2,
|
||||
getChanceToWinClash: RamCostConstants.GangApiBase,
|
||||
getBonusTime: 0,
|
||||
nextUpdate: RamCostConstants.CycleTiming,
|
||||
} as const;
|
||||
|
||||
// Bladeburner API
|
||||
@ -277,6 +282,7 @@ const bladeburner = {
|
||||
joinBladeburnerFaction: RamCostConstants.BladeburnerApiBase,
|
||||
joinBladeburnerDivision: RamCostConstants.BladeburnerApiBase,
|
||||
getBonusTime: 0,
|
||||
nextUpdate: RamCostConstants.CycleTiming,
|
||||
} as const;
|
||||
|
||||
const infiltration = {
|
||||
@ -356,6 +362,8 @@ const grafting = {
|
||||
const corporation = {
|
||||
hasCorporation: 0, // This one is free
|
||||
getConstants: 0,
|
||||
getBonusTime: 0,
|
||||
nextUpdate: RamCostConstants.CycleTiming,
|
||||
getIndustryData: RamCostConstants.CorporationInfo,
|
||||
getMaterialData: RamCostConstants.CorporationInfo,
|
||||
issueNewShares: RamCostConstants.CorporationAction,
|
||||
@ -377,7 +385,6 @@ const corporation = {
|
||||
issueDividends: RamCostConstants.CorporationAction,
|
||||
buyBackShares: RamCostConstants.CorporationAction,
|
||||
sellShares: RamCostConstants.CorporationAction,
|
||||
getBonusTime: 0,
|
||||
sellMaterial: RamCostConstants.CorporationAction,
|
||||
sellProduct: RamCostConstants.CorporationAction,
|
||||
discontinueProduct: RamCostConstants.CorporationAction,
|
||||
|
@ -3,7 +3,7 @@ import type { Action } from "../Bladeburner/Action";
|
||||
import type { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
||||
|
||||
import { Player } from "@player";
|
||||
import { Bladeburner } from "../Bladeburner/Bladeburner";
|
||||
import { Bladeburner, BladeburnerResolvers } from "../Bladeburner/Bladeburner";
|
||||
import { currentNodeMults } from "../BitNode/BitNodeMultipliers";
|
||||
import { BlackOperation } from "../Bladeburner/BlackOperation";
|
||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||
@ -329,5 +329,8 @@ export function NetscriptBladeburner(): InternalAPI<INetscriptBladeburner> {
|
||||
const bladeburner = getBladeburner(ctx);
|
||||
return Math.round(bladeburner.storedCycles / 5) * 1000;
|
||||
},
|
||||
nextUpdate: () => () => {
|
||||
return new Promise<number>((res) => BladeburnerResolvers.push(res));
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import { Product } from "../Corporation/Product";
|
||||
import { Material } from "../Corporation/Material";
|
||||
import { Warehouse } from "../Corporation/Warehouse";
|
||||
import { Division } from "../Corporation/Division";
|
||||
import { Corporation } from "../Corporation/Corporation";
|
||||
import { Corporation, CorporationResolvers } from "../Corporation/Corporation";
|
||||
import { cloneDeep, omit } from "lodash";
|
||||
|
||||
import {
|
||||
@ -15,6 +15,7 @@ import {
|
||||
OfficeAPI,
|
||||
CorpResearchName,
|
||||
CorpMaterialName,
|
||||
CorpStateName,
|
||||
} from "@nsdefs";
|
||||
|
||||
import {
|
||||
@ -787,6 +788,10 @@ export function NetscriptCorporation(): InternalAPI<NSCorporation> {
|
||||
checkAccess(ctx);
|
||||
return Math.round(getCorporation().storedCycles / 5) * 1000;
|
||||
},
|
||||
nextUpdate: (ctx) => () => {
|
||||
checkAccess(ctx);
|
||||
return new Promise<CorpStateName>((res) => CorporationResolvers.push(res));
|
||||
},
|
||||
};
|
||||
|
||||
// Removed functions
|
||||
|
@ -4,6 +4,7 @@ import type { GangMember } from "../Gang/GangMember";
|
||||
import type { GangMemberTask } from "../Gang/GangMemberTask";
|
||||
import type { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
||||
|
||||
import { GangResolvers } from "../Gang/Gang";
|
||||
import { Player } from "@player";
|
||||
import { FactionName } from "@enums";
|
||||
import { GangConstants } from "../Gang/data/Constants";
|
||||
@ -323,5 +324,8 @@ export function NetscriptGang(): InternalAPI<IGang> {
|
||||
const gang = getGang(ctx);
|
||||
return Math.round(gang.storedCycles / 5) * 1000;
|
||||
},
|
||||
nextUpdate: () => () => {
|
||||
return new Promise<number>((res) => GangResolvers.push(res));
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -1,6 +1,13 @@
|
||||
import { Player } from "../Player";
|
||||
import { buyStock, sellStock, shortStock, sellShort } from "../StockMarket/BuyingAndSelling";
|
||||
import { StockMarket, SymbolToStockMap, placeOrder, cancelOrder, initStockMarket } from "../StockMarket/StockMarket";
|
||||
import {
|
||||
StockMarket,
|
||||
SymbolToStockMap,
|
||||
placeOrder,
|
||||
cancelOrder,
|
||||
initStockMarket,
|
||||
StockMarketResolvers,
|
||||
} from "../StockMarket/StockMarket";
|
||||
import { getBuyTransactionCost, getSellTransactionGain } from "../StockMarket/StockMarketHelpers";
|
||||
import { PositionType, OrderType, StockSymbol } from "@enums";
|
||||
import {
|
||||
@ -403,5 +410,13 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
|
||||
helpers.log(ctx, () => "Purchased TIX API");
|
||||
return true;
|
||||
},
|
||||
getBonusTime: (ctx) => () => {
|
||||
checkTixApiAccess(ctx);
|
||||
return Math.round(StockMarket.storedCycles / 5) * 1000;
|
||||
},
|
||||
nextUpdate: (ctx) => () => {
|
||||
checkTixApiAccess(ctx);
|
||||
return new Promise<number>((res) => StockMarketResolvers.push(res));
|
||||
},
|
||||
};
|
||||
}
|
||||
|
120
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
120
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -1537,6 +1537,40 @@ export interface TIX {
|
||||
* @returns True if you successfully purchased it or if you already have access, false otherwise.
|
||||
*/
|
||||
purchaseTixApi(): boolean;
|
||||
|
||||
/**
|
||||
* Get Stock Market bonus time.
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
* “Bonus time” is accumulated when the game is offline or if the game is inactive in the browser.
|
||||
*
|
||||
* Stock Market prices update more frequently during “bonus time”.
|
||||
*
|
||||
* @returns Amount of accumulated “bonus time” (milliseconds) for the Stock Market mechanic.
|
||||
*/
|
||||
getBonusTime(): number;
|
||||
|
||||
/**
|
||||
* Sleep until the next Stock Market price update has happened.
|
||||
* @remarks
|
||||
* RAM cost: 1 GB
|
||||
*
|
||||
* The amount of real time spent asleep between updates can vary due to "bonus time"
|
||||
* (usually 4 seconds - 6 seconds).
|
||||
*
|
||||
* @returns Promise that resolves to the number of milliseconds of Stock Market time
|
||||
* that were processed in the previous update (always 6000 ms).
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* while (true) {
|
||||
* await ns.stock.nextUpdate();
|
||||
* // Manage your stock portfolio
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
nextUpdate(): Promise<number>;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -3199,7 +3233,7 @@ export interface Bladeburner {
|
||||
getCity(): CityName;
|
||||
|
||||
/**
|
||||
* Travel to another city in bladeburner.
|
||||
* Travel to another city in Bladeburner.
|
||||
* @remarks
|
||||
* RAM cost: 4 GB
|
||||
* Attempts to switch to the specified city (for Bladeburner only).
|
||||
@ -3212,7 +3246,7 @@ export interface Bladeburner {
|
||||
switchCity(city: CityName | `${CityName}`): boolean;
|
||||
|
||||
/**
|
||||
* Get bladeburner stamina.
|
||||
* Get Bladeburner stamina.
|
||||
* @remarks
|
||||
* RAM cost: 4 GB
|
||||
* Returns an array with two elements:
|
||||
@ -3229,7 +3263,7 @@ export interface Bladeburner {
|
||||
getStamina(): [number, number];
|
||||
|
||||
/**
|
||||
* Join the bladeburner faction.
|
||||
* Join the Bladeburner faction.
|
||||
* @remarks
|
||||
* RAM cost: 4 GB
|
||||
* Attempts to join the Bladeburner faction.
|
||||
@ -3243,7 +3277,7 @@ export interface Bladeburner {
|
||||
joinBladeburnerFaction(): boolean;
|
||||
|
||||
/**
|
||||
* Join the bladeburner division.
|
||||
* Join the Bladeburner division.
|
||||
* @remarks
|
||||
* RAM cost: 4 GB
|
||||
*
|
||||
@ -3258,7 +3292,7 @@ export interface Bladeburner {
|
||||
joinBladeburnerDivision(): boolean;
|
||||
|
||||
/**
|
||||
* Get bladeburner bonus time.
|
||||
* Get Bladeburner bonus time.
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
*
|
||||
@ -3274,11 +3308,34 @@ export interface Bladeburner {
|
||||
*/
|
||||
getBonusTime(): number;
|
||||
|
||||
/** Returns whether player is a member of bladeburner division. Does not require API access.
|
||||
/**
|
||||
* Sleep until the next Bladeburner update has happened.
|
||||
* @remarks
|
||||
* RAM cost: 1 GB
|
||||
*
|
||||
* @returns whether player is a member of bladeburner division. */
|
||||
* The amount of real time spent asleep between updates can vary due to "bonus time"
|
||||
* (usually 1 second).
|
||||
*
|
||||
* @returns Promise that resolves to the number of milliseconds of Bladeburner time
|
||||
* that were processed in the previous update (1000 - 5000 ms).
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* while (true) {
|
||||
* const duration = await ns.bladeburner.nextUpdate();
|
||||
* ns.print(`Bladeburner Division completed ${ns.tFormat(duration)} of actions.`);
|
||||
* ns.print(`Bonus time remaining: ${ns.tFormat(ns.bladeburner.getBonusTime())}`);
|
||||
* // Manage the Bladeburner division
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
nextUpdate(): Promise<number>;
|
||||
|
||||
/** Returns whether player is a member of Bladeburner division. Does not require API access.
|
||||
* @remarks
|
||||
* RAM cost: 1 GB
|
||||
*
|
||||
* @returns whether player is a member of Bladeburner division. */
|
||||
inBladeburner(): boolean;
|
||||
}
|
||||
|
||||
@ -3681,6 +3738,28 @@ export interface Gang {
|
||||
* @returns Bonus time for the Gang mechanic in milliseconds.
|
||||
*/
|
||||
getBonusTime(): number;
|
||||
|
||||
/**
|
||||
* Sleeps until the next Gang update has happened.
|
||||
* @remarks
|
||||
* RAM cost: 1 GB
|
||||
*
|
||||
* The amount of real time spent asleep between updates can vary due to "bonus time".
|
||||
*
|
||||
* @returns Promise that resolves to the number of milliseconds of Gang time
|
||||
* that were processed in the previous update (2000 - 5000 ms).
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* while (true) {
|
||||
* const duration = await ns.gang.nextUpdate();
|
||||
* ns.print(`Gang completed ${ns.tFormat(duration)} of activity.`);
|
||||
* ns.print(`Bonus time remaining: ${ns.tFormat(ns.gang.getBonusTime())}`);
|
||||
* // Manage the Gang
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
nextUpdate(): Promise<number>;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -7490,6 +7569,33 @@ export interface Corporation extends WarehouseAPI, OfficeAPI {
|
||||
* “Bonus time” makes the game progress faster.
|
||||
* @returns Bonus time for the Corporation mechanic in milliseconds. */
|
||||
getBonusTime(): number;
|
||||
|
||||
/**
|
||||
* Sleep until the next Corporation update has happened.
|
||||
* @remarks
|
||||
* RAM cost: 1 GB
|
||||
*
|
||||
* The amount of real time spent asleep between updates can vary due to "bonus time"
|
||||
* (usually 200 milliseconds - 2 seconds).
|
||||
*
|
||||
* @returns Promise that resolves to the name of the state that was just processed.
|
||||
*
|
||||
* I.e. when the state is PURCHASE, it means purchasing has just happened.
|
||||
* Note that this is the state just before `getCorporation().state`.
|
||||
*
|
||||
* Possible states are START, PURCHASE, PRODUCTION, EXPORT, SALE.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* while (true) {
|
||||
* const prevState = await ns.corporation.nextUpdate();
|
||||
* const nextState = ns.corporation.getCorporation().state;
|
||||
* ns.print(`Corporation finished with ${prevState}, next will be ${nextState}.`);
|
||||
* // Manage the Corporation
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
nextUpdate(): Promise<CorpStateName>;
|
||||
}
|
||||
|
||||
/** Product rating information
|
||||
|
@ -24,6 +24,8 @@ export let StockMarket: IStockMarket = {
|
||||
// Gross type, needs to be addressed
|
||||
export const SymbolToStockMap: Record<string, Stock> = {}; // Maps symbol -> Stock object
|
||||
|
||||
export const StockMarketResolvers: ((msProcessed: number) => void)[] = [];
|
||||
|
||||
export function placeOrder(
|
||||
stock: Stock,
|
||||
shares: number,
|
||||
@ -277,4 +279,9 @@ export function processStockPrices(numCycles = 1): void {
|
||||
// Shares required for price movement gradually approaches max over time
|
||||
stock.shareTxUntilMovement = Math.min(stock.shareTxUntilMovement + 10, stock.shareTxForMovement);
|
||||
}
|
||||
|
||||
// Handle "nextUpdate" resolvers after this update
|
||||
for (const resolve of StockMarketResolvers.splice(0)) {
|
||||
resolve(StockMarketConstants.msPerStockUpdate);
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
"toolPackages": [
|
||||
{
|
||||
"packageName": "@microsoft/api-extractor",
|
||||
"packageVersion": "7.34.2"
|
||||
"packageVersion": "7.38.0"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user