mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-18 15:28:43 +02:00
Adding Basic Gameplay to documentation
This commit is contained in:
36
doc/source/netscript/netscript1.rst
Normal file
36
doc/source/netscript/netscript1.rst
Normal file
@@ -0,0 +1,36 @@
|
||||
.. _netscript1:
|
||||
|
||||
Netscript 1.0
|
||||
=============
|
||||
Netscript 1.0 is implemented using a modified version of Neil Fraser's
|
||||
`JS-Interpreter <https://github.com/NeilFraser/JS-Interpreter>`_.
|
||||
|
||||
This is an ES5 JavaScript interpreter. This means that (almost) any JavaScript feature
|
||||
that is available in ES5 is also available in Netscript 1.0. However, this also means
|
||||
that the interpreter does not natively support any JavaScript features introduced in versions
|
||||
ES6 or after.
|
||||
|
||||
If you are confused by the ES5/ES6/etc. terminology, consider reading this:
|
||||
`WTF is ES6, ES8, ES2017, ECMAScript... <https://codeburst.io/javascript-wtf-is-es6-es8-es-2017-ecmascript-dca859e4821c>`_
|
||||
|
||||
Netscript 1.0 scripts end with the ".script" extension in their filenames.
|
||||
|
||||
Which ES6+ features are supported?
|
||||
----------------------------------
|
||||
|
||||
Netscript 1.0 is a ES5 interpreter, but the following features from versions ES6 and
|
||||
above are supported as well.
|
||||
|
||||
If there is an additional ES6+ feature you would like to see implemented with a polyfill,
|
||||
feel free to `open an issue <https://github.com/danielyxie/bitburner/issues>`_ (and provide
|
||||
the polyfill if possible).
|
||||
|
||||
* import - See :ref:`netscriptimporting`
|
||||
* `Array <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array>`_
|
||||
* `find() <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find>`_
|
||||
* `findIndex() <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex>`_
|
||||
* `includes() <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes>`_
|
||||
* `String <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String>`_
|
||||
* `endsWith() <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith>`_
|
||||
* `includes() <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes>`_
|
||||
* `startsWith() <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith>`_
|
||||
61
doc/source/netscript/netscriptadvancedfunctions.rst
Normal file
61
doc/source/netscript/netscriptadvancedfunctions.rst
Normal file
@@ -0,0 +1,61 @@
|
||||
Netscript Advanced Functions
|
||||
============================
|
||||
|
||||
These Netscript functions become relevant later on in the game. They are put on a separate page because
|
||||
they contain spoilers for the game.
|
||||
|
||||
getBitNodeMultipliers
|
||||
^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. js:function:: getBitNodeMultipliers()
|
||||
|
||||
Returns an object containing the current BitNode multipliers. This function requires Source-File 5 in order
|
||||
to run. The multipliers are returned in integer forms (e.g. 1.5 instead of 150%). The multipliers represent
|
||||
the difference between the current BitNode and the original BitNode (BitNode-1). For example, if the
|
||||
*CrimeMoney* multiplier has a value of 0.1, then that means that committing crimes in the current BitNode
|
||||
will only give 10% of the money you would have received in BitNode-1. The object has the following structure,
|
||||
(subject to change in the future)::
|
||||
|
||||
{
|
||||
ServerMaxMoney: 1,
|
||||
ServerStartingMoney: 1,
|
||||
ServerGrowthRate: 1,
|
||||
ServerWeakenRate: 1,
|
||||
ServerStartingSecurity: 1,
|
||||
ManualHackMoney: 1,
|
||||
ScriptHackMoney: 1,
|
||||
CompanyWorkMoney: 1,
|
||||
CrimeMoney: 1,
|
||||
HacknetNodeMoney: 1,
|
||||
CompanyWorkExpGain: 1,
|
||||
ClassGymExpGain: 1,
|
||||
FactionWorkExpGain: 1,
|
||||
HackExpGain: 1,
|
||||
CrimeExpGain: 1,
|
||||
FactionWorkRepGain: 1,
|
||||
FactionPassiveRepGain: 1,
|
||||
AugmentationRepCost: 1,
|
||||
AugmentationMoneyCost: 1,
|
||||
}
|
||||
|
||||
Example::
|
||||
|
||||
mults = getBitNodeMultipliers();
|
||||
print(mults.ServerMaxMoney);
|
||||
print(mults.HackExpGain);
|
||||
|
||||
getHackTime, getGrowTime, & getWeakenTime
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
The :js:func:`getHackTime`, :js:func:`getGrowTime`, and :js:func:`getWeakenTime`
|
||||
all take an additional third optional parameter for specifying a specific intelligence
|
||||
level to see how that would affect the hack/grow/weaken times. This parameter
|
||||
defaults to your current intelligence level.
|
||||
|
||||
(Intelligence is unlocked after obtaining Source-File 5).
|
||||
|
||||
The function signatures are then::
|
||||
|
||||
getHackTime(hostname/ip[, hackLvl=current level, intLvl=current level])
|
||||
getGrowTime(hostname/ip[, hackLvl=current level, intLvl=current level])
|
||||
getWeakenTime(hostname/ip[, hackLvl=current level, intLvl=current level])
|
||||
562
doc/source/netscript/netscriptbladeburnerapi.rst
Normal file
562
doc/source/netscript/netscriptbladeburnerapi.rst
Normal file
@@ -0,0 +1,562 @@
|
||||
Netscript Bladeburner API
|
||||
=========================
|
||||
Netscript provides the following API for interacting with the game's Bladeburner mechanic.
|
||||
|
||||
The Bladeburner API is **not** immediately available to the player and must be unlocked
|
||||
later in the game
|
||||
|
||||
**WARNING: This page contains spoilers for the game**
|
||||
|
||||
The Bladeburner API is unlocked in BitNode-7. If you are in BitNode-7, you will
|
||||
automatically gain access to this API. Otherwise, you must have Source-File 7 in
|
||||
order to use this API in other BitNodes
|
||||
|
||||
**Bladeburner API functions must be accessed through the 'bladeburner' namespace**
|
||||
|
||||
In :ref:`netscript1`::
|
||||
|
||||
bladeburner.getContractNames();
|
||||
bladeburner.startAction("general", "Training");
|
||||
|
||||
In :ref:`netscriptjs`::
|
||||
|
||||
ns.bladeburner.getContractNames();
|
||||
ns.bladeburner.startAction("general", "Training");
|
||||
|
||||
.. _bladeburner_action_types:
|
||||
|
||||
Bladeburner Action Types
|
||||
------------------------
|
||||
|
||||
Several functions in the Bladeburner API require you to specify an action using
|
||||
its type and name. The following are valid values when specifying the action's type:
|
||||
|
||||
**Contracts**
|
||||
* contract
|
||||
* contracts
|
||||
* contr
|
||||
|
||||
**Operations**
|
||||
* operation
|
||||
* operations
|
||||
* op
|
||||
* ops
|
||||
|
||||
**Black Ops**
|
||||
* blackoperation
|
||||
* black operation
|
||||
* black operations
|
||||
* black op
|
||||
* black ops
|
||||
* blackop
|
||||
* blackops
|
||||
|
||||
**General Actions (Training, Field Analysis, Recruitment)**
|
||||
* general
|
||||
* general action
|
||||
* gen
|
||||
|
||||
getContractNames
|
||||
----------------
|
||||
|
||||
.. js:function:: getContractNames()
|
||||
|
||||
Returns an array of strings containing the names of all Bladeburner contracts
|
||||
|
||||
getOperationNames
|
||||
-----------------
|
||||
|
||||
.. js:function:: getOperationNames()
|
||||
|
||||
Returns an array of strings containing the names of all Bladeburner operations
|
||||
|
||||
getBlackOpNames
|
||||
---------------
|
||||
|
||||
.. js:function:: getBlackOpNames()
|
||||
|
||||
Returns an array of strings containing the names of all Bladeburner Black Ops
|
||||
|
||||
getGeneralActionNames
|
||||
---------------------
|
||||
|
||||
.. js:function:: getGeneralActionNames()
|
||||
|
||||
Returns an array of strings containing the names of all general Bladeburner actions
|
||||
|
||||
getSkillNames
|
||||
-------------
|
||||
|
||||
.. js:function:: getSkillNames()
|
||||
|
||||
Returns an array of strings containing the names of all Bladeburner skills
|
||||
|
||||
startAction
|
||||
-----------
|
||||
|
||||
.. js:function:: startAction(type, name)
|
||||
|
||||
:param string type: Type of action. See :ref:`bladeburner_action_types`
|
||||
:param string name: Name of action. Must be an exact match
|
||||
|
||||
Attempts to start the specified Bladeburner action. Returns true if the action
|
||||
was started successfully, and false otherwise.
|
||||
|
||||
stopBladeburnerAction
|
||||
---------------------
|
||||
|
||||
.. js:function:: stopBladeburnerAction()
|
||||
|
||||
Stops the current Bladeburner action
|
||||
|
||||
getCurrentAction
|
||||
----------------
|
||||
|
||||
.. js:function:: getCurrentAction()
|
||||
|
||||
Returns an object that represents the player's current Bladeburner action::
|
||||
|
||||
{
|
||||
type: Type of Action
|
||||
name: Name of Action
|
||||
}
|
||||
|
||||
If the player is not performing an action, the function will return an object
|
||||
with the 'type' property set to "Idle".
|
||||
|
||||
getActionTime
|
||||
-------------
|
||||
|
||||
.. js:function:: getActionTime(type, name)
|
||||
|
||||
:param string type: Type of action. See :ref:`bladeburner_action_types`
|
||||
:param string name: Name of action. Must be an exact match
|
||||
|
||||
Returns the number of seconds it takes to complete the specified action
|
||||
|
||||
getActionEstimatedSuccessChance
|
||||
-------------------------------
|
||||
|
||||
.. js:function:: getActionEstimatedSuccessChance(type, name)
|
||||
|
||||
:param string type: Type of action. See :ref:`bladeburner_action_types`
|
||||
:param string name: Name of action. Must be an exact match
|
||||
|
||||
Returns the estimated success chance for the specified action. This chance
|
||||
is returned as a decimal value, NOT a percentage (e.g. if you have an estimated
|
||||
success chance of 80%, then this function will return 0.80, NOT 80).
|
||||
|
||||
getActionRepGain
|
||||
----------------
|
||||
|
||||
.. js:function:: getActionRepGain(type, name[, level=current level])
|
||||
|
||||
:param string type: Type of action. See :ref:`bladeburner_action_types`
|
||||
:param string name: Name of action. Must be an exact match
|
||||
:param number level: Optional action level at which to calculate the gain
|
||||
|
||||
Returns the average Bladeburner reputation gain for successfully completing
|
||||
the specified action. Note that this value is an 'average' and the real
|
||||
reputation gain may vary slightly from this value.
|
||||
|
||||
getActionCountRemaining
|
||||
-----------------------
|
||||
|
||||
.. js:function:: getActionCountRemaining(type, name)
|
||||
|
||||
:param string type: Type of action. See :ref:`bladeburner_action_types`
|
||||
:param string name: Name of action. Must be an exact match
|
||||
|
||||
Returns the remaining count of the specified action.
|
||||
|
||||
Note that this is meant to be used for Contracts and Operations.
|
||||
This function will return 'Infinity' for actions such as Training and Field Analysis.
|
||||
|
||||
getActionMaxLevel
|
||||
-----------------
|
||||
|
||||
.. js:function:: getActionMaxLevel(type, name)
|
||||
|
||||
:param string type: Type of action. See :ref:`bladeburner_action_types`
|
||||
:param string name: Name of action. Must be an exact match
|
||||
|
||||
Returns the maximum level for this action.
|
||||
|
||||
Returns -1 if an invalid action is specified.
|
||||
|
||||
getActionCurrentLevel
|
||||
---------------------
|
||||
|
||||
.. js:function:: getActionCurrentLevel(type, name)
|
||||
|
||||
:param string type: Type of action. See :ref:`bladeburner_action_types`
|
||||
:param string name: Name of action. Must be an exact match
|
||||
|
||||
Returns the current level of this action.
|
||||
|
||||
Returns -1 if an invalid action is specified.
|
||||
|
||||
getActionAutolevel
|
||||
------------------
|
||||
|
||||
.. js:function:: getActionAutolevel(type, name)
|
||||
|
||||
:param string type: Type of action. See :ref:`bladeburner_action_types`
|
||||
:param string name: Name of action. Must be an exact match
|
||||
|
||||
Return a boolean indicating whether or not this action is currently set to autolevel.
|
||||
|
||||
Returns false if an invalid action is specified.
|
||||
|
||||
setActionAutolevel
|
||||
------------------
|
||||
|
||||
.. js:function:: setActionAutolevel(type, name, autoLevel)
|
||||
|
||||
:param string type: Type of action. See :ref:`bladeburner_action_types`
|
||||
:param string name: Name of action. Must be an exact match
|
||||
:param boolean autoLevel: Whether or not to autolevel this action
|
||||
|
||||
Enable/disable autoleveling for the specified action.
|
||||
|
||||
setActionLevel
|
||||
--------------
|
||||
|
||||
.. js:function:: setActionLevel(type, name, level)
|
||||
|
||||
:param string type: Type of action. See :ref:`bladeburner_action_types`
|
||||
:param string name: Name of action. Must be an exact match
|
||||
:param level int: Level to set this action to
|
||||
|
||||
Set the level for the specified action.
|
||||
|
||||
getRank
|
||||
-------
|
||||
|
||||
.. js:function:: getRank()
|
||||
|
||||
Returns the player's Bladeburner Rank
|
||||
|
||||
getSkillPoints
|
||||
--------------
|
||||
|
||||
.. js:function:: getSkillPoints()
|
||||
|
||||
Returns the number of Bladeburner skill points you have
|
||||
|
||||
getSkillLevel
|
||||
-------------
|
||||
|
||||
.. js:function:: getSkillLevel(skillName="")
|
||||
|
||||
:param string skillName: Name of skill. Case-sensitive and must be an exact match
|
||||
|
||||
This function returns your level in the specified skill.
|
||||
|
||||
The function returns -1 if an invalid skill name is passed in
|
||||
|
||||
getSkillUpgradeCost
|
||||
-------------------
|
||||
|
||||
.. js:function:: getSkillUpgradeCost(skillName="")
|
||||
|
||||
:param string skillName: Name of skill. Case-sensitive and must be an exact match
|
||||
|
||||
This function returns the number of skill points needed to upgrade the
|
||||
specified skill.
|
||||
|
||||
The function returns -1 if an invalid skill name is passed in.
|
||||
|
||||
upgradeSkill
|
||||
------------
|
||||
|
||||
.. js:function:: upgradeSkill(skillName)
|
||||
|
||||
:param string skillName: Name of Skill to be upgraded. Case-sensitive and must be an exact match
|
||||
|
||||
Attempts to upgrade the specified Bladeburner skill. Returns true if the
|
||||
skill is successfully upgraded, and false otherwise
|
||||
|
||||
getTeamSize
|
||||
-----------
|
||||
|
||||
.. js:function:: getTeamSize(type, name)
|
||||
|
||||
:param string type: Type of action. See :ref:`bladeburner_action_types`
|
||||
:param string name: Name of action. Must be an exact match
|
||||
|
||||
Returns the number of Bladeburner team members you have assigned to the
|
||||
specified action.
|
||||
|
||||
Setting a team is only applicable for Operations and BlackOps. This function
|
||||
will return 0 for other action types.
|
||||
|
||||
setTeamSize
|
||||
-----------
|
||||
|
||||
.. js:function:: setTeamSize(type, name, size)
|
||||
|
||||
:param string type: Type of action. See :ref:`bladeburner_action_types`
|
||||
:param string name: Name of action. Must be an exact match
|
||||
:param int size: Number of team members to set. Will be converted using Math.round()
|
||||
|
||||
Set the team size for the specified Bladeburner action.
|
||||
|
||||
Returns the team size that was set, or -1 if the function failed.
|
||||
|
||||
getCityEstimatedPopulation
|
||||
--------------------------
|
||||
|
||||
.. js:function:: getCityEstimatedPopulation(cityName)
|
||||
|
||||
:param string cityName: Name of city. Case-sensitive
|
||||
|
||||
Returns the estimated number of Synthoids in the specified city, or -1
|
||||
if an invalid city was specified.
|
||||
|
||||
getCityEstimatedCommunities
|
||||
---------------------------
|
||||
|
||||
.. js:function:: getCityEstimatedCommunities(cityName)
|
||||
|
||||
:param string cityName: Name of city. Case-sensitive
|
||||
|
||||
Returns the estimated number of Synthoid communities in the specified city,
|
||||
or -1 if an invalid city was specified.
|
||||
|
||||
getCityChaos
|
||||
------------
|
||||
|
||||
.. js:function:: getCityChaos(cityName)
|
||||
|
||||
:param string cityName: Name of city. Case-sensitive
|
||||
|
||||
Returns the chaos in the specified city, or -1 if an invalid city was specified
|
||||
|
||||
switchCity
|
||||
----------
|
||||
|
||||
.. js:function:: switchCity(cityName)
|
||||
|
||||
:param string cityName: Name of city
|
||||
|
||||
Attempts to switch to the specified city (for Bladeburner only).
|
||||
|
||||
Returns true if successful, and false otherwise
|
||||
|
||||
getStamina
|
||||
----------
|
||||
|
||||
.. js:function:: getStamina()
|
||||
|
||||
Returns an array with two elements:
|
||||
|
||||
[Current stamina, Max stamina]
|
||||
|
||||
Example usage::
|
||||
|
||||
function getStaminaPercentage() {
|
||||
let res = bladeburner.getStamina();
|
||||
return res[0] / res[1];
|
||||
}
|
||||
|
||||
joinBladeburnerFaction
|
||||
----------------------
|
||||
|
||||
.. js:function:: joinBladeburnerFaction()
|
||||
|
||||
Attempts to join the Bladeburner faction.
|
||||
|
||||
Returns true if you successfully join the Bladeburner faction, or if
|
||||
you are already a member.
|
||||
|
||||
Returns false otherwise.
|
||||
|
||||
joinBladeburnerDivision
|
||||
-----------------------
|
||||
|
||||
.. js:function:: joinBladeburnerDivision()
|
||||
|
||||
Attempts to join the Bladeburner division.
|
||||
|
||||
Returns true if you successfully join the Bladeburner division, or if you
|
||||
are already a member.
|
||||
|
||||
Returns false otherwise
|
||||
|
||||
getBonusTime
|
||||
------------
|
||||
|
||||
.. js:function:: getBonusTime()
|
||||
|
||||
Returns the amount of accumulated "bonus time" (seconds) for the Bladeburner mechanic.
|
||||
|
||||
"Bonus time" is accumulated when the game is offline or if the game is
|
||||
inactive in the browser.
|
||||
|
||||
"Bonus time" makes the game progress faster, up to 5x the normal speed.
|
||||
For example, if an action takes 30 seconds to complete but you've accumulated
|
||||
over 30 seconds in bonus time, then the action will only take 6 seconds
|
||||
in real life to complete.
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
**Basic example usage**::
|
||||
|
||||
tprint(bladeburner.getContractNames());
|
||||
tprint(bladeburner.getOperationNames());
|
||||
tprint(bladeburner.getBlackOpNames());
|
||||
tprint(bladeburner.getGeneralActionNames());
|
||||
tprint(bladeburner.getSkillNames());
|
||||
tprint(bladeburner.getActionTime("contract", "Tracking"));
|
||||
tprint("Rank: " + bladeburner.getRank());
|
||||
tprint("Skill Points: " + bladeburner.getSkillPoints());
|
||||
tprint("Cloak Skill Level: " + bladeburner.getSkillLevel("Cloak"));
|
||||
tprint("Trying to upgradeSkill: " + bladeburner.upgradeSkill("Cloak"));
|
||||
tprint("Skill Points remaining: " + bladeburner.getSkillPoints());
|
||||
|
||||
tprint("Trying to switch to a nonexistent city: " + bladeburner.switchCity("lskgns"));
|
||||
|
||||
var chongqing = "Chongqing";
|
||||
tprint("Trying to switch to Chongqing: " + bladeburner.switchCity(chongqing));
|
||||
tprint("Chongqing chaos: " + bladeburner.getCityChaos(chongqing));
|
||||
tprint("Chongqing estimated pop: " + bladeburner.getCityEstimatedPopulation(chongqing));
|
||||
tprint("Chonqging estimated communities: " + bladeburner.getCityEstimatedCommunities(chongqing));
|
||||
|
||||
**Bladeburner handler example**. Note that this avoids the need of using the *bladeburner* namespace
|
||||
identifier by attaching the Bladeburner API functions to an object::
|
||||
|
||||
const FIELD_ANALYSIS_INTERVAL = 10; //Number of minutes between field analysis states
|
||||
const FIELD_ANALYSIS_DURATION = 5; //Duration in minutes
|
||||
|
||||
function BladeburnerHandler(ns, params) {
|
||||
//Netscript environment becomes part of the instance
|
||||
this.ns = ns;
|
||||
|
||||
//Netscript bladeburner API becomes part of this instance
|
||||
for (var bladeburnerFn in ns.bladeburner) {
|
||||
this[bladeburnerFn] = ns.bladeburner[bladeburnerFn];
|
||||
}
|
||||
|
||||
this.fieldAnalysis = {
|
||||
inProgress: params.startFieldAnalysis ? true : false,
|
||||
cyclesRemaining: params.startFieldAnalysis ? FIELD_ANALYSIS_DURATION : 0,
|
||||
cyclesSince: params.startFieldAnalysis ? FIELD_ANALYSIS_INTERVAL : 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
BladeburnerHandler.prototype.getStaminaPercentage = function() {
|
||||
var res = this.getStamina();
|
||||
return 100 * (res[0] / res[1]);
|
||||
}
|
||||
|
||||
BladeburnerHandler.prototype.hasSimulacrum = function() {
|
||||
var augs = this.ns.getOwnedAugmentations();
|
||||
return augs.includes("The Blade's Simulacrum");
|
||||
}
|
||||
|
||||
BladeburnerHandler.prototype.handle = function() {
|
||||
//If we're doing something else manually (without Simlacrum),
|
||||
//it overrides Bladeburner stuff
|
||||
if (!this.hasSimulacrum() && this.ns.isBusy()) {
|
||||
this.ns.print("Idling bc player is busy with some other action");
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.fieldAnalysis.inProgress) {
|
||||
--(this.fieldAnalysis.cyclesRemaining);
|
||||
if (this.fieldAnalysis.cyclesRemaining < 0) {
|
||||
this.fieldAnalysis.inProgress = false;
|
||||
this.fieldAnalysis.cyclesSince = 0;
|
||||
return this.handle();
|
||||
} else {
|
||||
this.startAction("general", "Field Analysis");
|
||||
this.ns.print("handler is doing field analyis for " +
|
||||
(this.fieldAnalysis.cyclesRemaining+1) + " more mins");
|
||||
return 31; //Field Analysis Time + 1
|
||||
}
|
||||
} else {
|
||||
++(this.fieldAnalysis.cyclesSince);
|
||||
if (this.fieldAnalysis.cyclesSince > FIELD_ANALYSIS_INTERVAL) {
|
||||
this.fieldAnalysis.inProgress = true;
|
||||
this.fieldAnalysis.cyclesRemaining = FIELD_ANALYSIS_DURATION;
|
||||
return this.handle();
|
||||
}
|
||||
}
|
||||
|
||||
this.stopBladeburnerAction();
|
||||
|
||||
var staminaPerc = this.getStaminaPercentage();
|
||||
if (staminaPerc < 55) {
|
||||
this.ns.print("handler is starting training due to low stamina percentage");
|
||||
this.startAction("general", "Training");
|
||||
return 31; //Training time + 1
|
||||
} else {
|
||||
var action = this.chooseAction();
|
||||
this.ns.print("handler chose " + action.name + " " + action.type + " through chooseAction()");
|
||||
this.startAction(action.type, action.name);
|
||||
return (this.getActionTime(action.type, action.name) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
BladeburnerHandler.prototype.chooseAction = function() {
|
||||
//Array of all Operations
|
||||
var ops = this.getOperationNames();
|
||||
|
||||
//Sort Operations in order of increasing success chance
|
||||
ops.sort((a, b)=>{
|
||||
return this.getActionEstimatedSuccessChance("operation", a) -
|
||||
this.getActionEstimatedSuccessChance("operation", b);
|
||||
});
|
||||
|
||||
//Loop through until you find one with 99+% success chance
|
||||
for (let i = 0; i < ops.length; ++i) {
|
||||
let successChance = this.getActionEstimatedSuccessChance("operation", ops[i]);
|
||||
let count = this.getActionCountRemaining("operation", ops[i]);
|
||||
if (successChance >= 0.99 && count > 10) {
|
||||
return {type: "operation", name: ops[i]};
|
||||
}
|
||||
}
|
||||
|
||||
//Repeat for Contracts
|
||||
var contracts = this.getContractNames();
|
||||
contracts.sort((a, b)=>{
|
||||
return this.getActionEstimatedSuccessChance("contract", a) -
|
||||
this.getActionEstimatedSuccessChance("contract", b);
|
||||
});
|
||||
|
||||
for (let i = 0; i < contracts.length; ++i) {
|
||||
let successChance = this.getActionEstimatedSuccessChance("contract", contracts[i]);
|
||||
let count = this.getActionCountRemaining("contract", contracts[i]);
|
||||
if (successChance >= 0.80 && count > 10) {
|
||||
return {type: "contract", name: contracts[i]};
|
||||
}
|
||||
}
|
||||
|
||||
return {type:"general", name:"Training"};
|
||||
}
|
||||
|
||||
|
||||
BladeburnerHandler.prototype.process = async function() {
|
||||
await this.ns.sleep(this.handle() * 1000);
|
||||
}
|
||||
|
||||
export async function main(ns) {
|
||||
//Check if Bladeburner is available. This'll throw a runtime error if it's not
|
||||
ns.bladeburner.getContractNames();
|
||||
|
||||
var startFieldAnalysis = true;
|
||||
if (ns.args.length >= 1 && ns.args[0] == "false") {
|
||||
startFieldAnalysis = false;
|
||||
}
|
||||
|
||||
var handler = new BladeburnerHandler(ns, {
|
||||
startFieldAnalysis: startFieldAnalysis
|
||||
});
|
||||
while(true) {
|
||||
await handler.process();
|
||||
}
|
||||
}
|
||||
88
doc/source/netscript/netscriptcodingcontractapi.rst
Normal file
88
doc/source/netscript/netscriptcodingcontractapi.rst
Normal file
@@ -0,0 +1,88 @@
|
||||
.. _netscriptcodingcontractapi:
|
||||
|
||||
Netscript Coding Contract API
|
||||
=============================
|
||||
Netscript provides the following API for interacting with
|
||||
:ref:`codingcontracts`.
|
||||
|
||||
**The Coding Contract API must be accessed through the 'codingcontract' namespace**
|
||||
|
||||
In :ref:`netscript1`::
|
||||
|
||||
codingcontract.getDescription("foo.cct", "home");
|
||||
codingcontract.attempt(1, "foo.cct", "foodnstuff");
|
||||
|
||||
In :ref:`netscriptjs`::
|
||||
|
||||
ns.codingcontract.getDescription("foo.cct", "home");
|
||||
ns.codingcontract.attempt(1, "foo.cct", "foodnstuff");
|
||||
|
||||
attempt
|
||||
-------
|
||||
|
||||
.. js:function:: attempt(answer, fn[, hostname/ip=current ip])
|
||||
|
||||
:param answer: Solution for the contract
|
||||
:param string fn: Filename of the contract
|
||||
:param string hostname/ip: Hostname or IP of the server containing the contract.
|
||||
Optional. Defaults to current server if not provided
|
||||
|
||||
Attempts to solve the Coding Contract with the provided solution.
|
||||
|
||||
:returns: Boolean indicating whether the solution was correct
|
||||
|
||||
getContractType
|
||||
---------------
|
||||
|
||||
.. js:function:: getContractType(fn[, hostname/ip=current ip])
|
||||
|
||||
:param string fn: Filename of the contract
|
||||
:param string hostname/ip: Hostname or IP of the server containing the contract.
|
||||
Optional. Defaults to current server if not provided
|
||||
|
||||
Returns a name describing the type of problem posed by the Coding Contract.
|
||||
(e.g. Find Largest Prime Factor, Total Ways to Sum, etc.)
|
||||
|
||||
:returns: A string with the contract's problem type
|
||||
|
||||
getDescription
|
||||
--------------
|
||||
|
||||
.. js:function:: getDescription(fn[, hostname/ip=current ip])
|
||||
|
||||
:param string fn: Filename of the contract
|
||||
:param string hostname/ip: Hostname or IP of the server containing the contract.
|
||||
Optional. Defaults to current server if not provided
|
||||
|
||||
Get the full text description for the problem posed by the Coding Contract
|
||||
|
||||
:returns: A string with the contract's text description
|
||||
|
||||
getData
|
||||
-------
|
||||
|
||||
.. js:function:: getData(fn[, hostname/ip=current ip])
|
||||
|
||||
:param string fn: Filename of the contract
|
||||
:param string hostname/ip: Hostname or IP of the server containing the contract.
|
||||
Optional. Defaults to current server if not provided
|
||||
|
||||
Get the data associated with the specific Coding Contract. Note that this is
|
||||
not the same as the contract's description. This is just the data that
|
||||
the contract wants you to act on in order to solve
|
||||
|
||||
:returns: The specified contract's data
|
||||
|
||||
getNumTriesRemaining
|
||||
--------------------
|
||||
|
||||
.. js:function:: getNumTriesRemaining(fn[, hostname/ip=current ip])
|
||||
|
||||
:param string fn: Filename of the contract
|
||||
:param string hostname/ip: Hostname or IP of the server containing the contract.
|
||||
Optional. Defaults to current server if not provided
|
||||
|
||||
Get the number of tries remaining on the contract before it
|
||||
self-destructs.
|
||||
|
||||
:returns: Number indicating how many attempts are remaining
|
||||
1199
doc/source/netscript/netscriptfunctions.rst
Normal file
1199
doc/source/netscript/netscriptfunctions.rst
Normal file
File diff suppressed because it is too large
Load Diff
277
doc/source/netscript/netscriptgangapi.rst
Normal file
277
doc/source/netscript/netscriptgangapi.rst
Normal file
@@ -0,0 +1,277 @@
|
||||
Netscript Gang API
|
||||
==================
|
||||
|
||||
Netscript provides the following API for interacting with the game's Gang mechanic.
|
||||
|
||||
The Gang API is **not** immediately available to the player and must be unlocked
|
||||
later in the game
|
||||
|
||||
**WARNING: This page contains spoilers for the game**
|
||||
|
||||
The Gang API is unlocked in BitNode-2. Currently, BitNode-2 is the only location
|
||||
where the Gang mechanic is accessible. This may change in the future
|
||||
|
||||
**Gang API functions must be accessed through the 'gang' namespace**
|
||||
|
||||
In :ref:`netscript1`::
|
||||
|
||||
gang.getMemberNames();
|
||||
gang.recruitMember("Fry");
|
||||
|
||||
In :ref:`netscriptjs`::
|
||||
|
||||
ns.gang.getMemberNames();
|
||||
ns.gang.recruitMember("Fry");
|
||||
|
||||
getMemberNames
|
||||
--------------
|
||||
|
||||
.. js:function:: getMemberNames()
|
||||
|
||||
Get the names of all Gang members
|
||||
|
||||
:returns: An array of the names of all Gang members as strings
|
||||
|
||||
getGangInformation
|
||||
------------------
|
||||
|
||||
.. js:function:: getGangInformation()
|
||||
|
||||
Get general information about the gang
|
||||
|
||||
:returns: An object with the gang information.
|
||||
|
||||
The object has the following structure::
|
||||
|
||||
{
|
||||
faction: Name of faction that the gang belongs to ("Slum Snakes", etc.)
|
||||
isHacking: Boolean indicating whether or not its a hacking gang
|
||||
moneyGainRate: Money earned per second
|
||||
power: Gang's power for territory warfare
|
||||
respect: Gang's respect
|
||||
respectGainRate: Respect earned per second
|
||||
territory: Amount of territory held. Returned in decimal form, not percentage
|
||||
territoryClashChance: Clash chance. Returned in decimal form, not percentage
|
||||
wantedLevel: Gang's wanted level
|
||||
wantedLevelGainRate: Wanted level gained/lost per second (negative for losses)
|
||||
}
|
||||
|
||||
getOtherGangInformation
|
||||
-----------------------
|
||||
|
||||
.. js:function:: getOtherGangInformation()
|
||||
|
||||
Get territory and power information about all gangs
|
||||
|
||||
:returns: An object with information about all gangs
|
||||
|
||||
The object has the following structure::
|
||||
|
||||
{
|
||||
"Slum Snakes" : {
|
||||
power: Slum Snakes' power
|
||||
territory: Slum Snakes' territory, in decimal form
|
||||
},
|
||||
"Tetrads" : {
|
||||
power: ...
|
||||
territory: ...
|
||||
},
|
||||
"The Syndicate" : {
|
||||
power: ...
|
||||
territory: ...
|
||||
},
|
||||
... (for all six gangs)
|
||||
}
|
||||
|
||||
getMemberInformation
|
||||
--------------------
|
||||
|
||||
.. js:function:: getMemberInformation(name)
|
||||
|
||||
:param string name: Name of member
|
||||
|
||||
Get stat and equipment-related information about a Gang Member
|
||||
|
||||
:returns: An object with the gang member information.
|
||||
|
||||
The object has the following structure::
|
||||
|
||||
{
|
||||
agility: Agility stat
|
||||
agilityEquipMult: Agility multiplier from equipment. Decimal form
|
||||
agilityAscensionMult: Agility multiplier from ascension. Decimal form
|
||||
augmentations: Array of names of all owned Augmentations
|
||||
charisma: Charisma stat
|
||||
charismaEquipMult: Charisma multiplier from equipment. Decimal form
|
||||
charismaAscensionMult: Charisma multiplier from ascension. Decimal form
|
||||
defense: Defense stat
|
||||
defenseEquipMult: Defense multiplier from equipment. Decimal form
|
||||
defenseAscensionMult: Defense multiplier from ascension. Decimal form
|
||||
dexterity: Dexterity stat
|
||||
dexterityEquipMult: Dexterity multiplier from equipment. Decimal form
|
||||
dexterityAscensionMult: Dexterity multiplier from ascension. Decimal form
|
||||
equipment: Array of names of all owned Non-Augmentation Equipment
|
||||
hacking: Hacking stat
|
||||
hackingEquipMult: Hacking multiplier from equipment. Decimal form
|
||||
hackingAscensionMult: Hacking multiplier from ascension. Decimal form
|
||||
strength: Strength stat
|
||||
strengthEquipMult: Strength multiplier from equipment. Decimal form
|
||||
strengthAscensionMult: Strength multiplier from ascension. Decimal form
|
||||
task: Name of currently assigned task
|
||||
}
|
||||
|
||||
canRecruitMember
|
||||
----------------
|
||||
|
||||
.. js:function:: canRecruitMember()
|
||||
|
||||
:returns: Boolean indicating whether a member can currently be recruited
|
||||
|
||||
recruitMember
|
||||
-------------
|
||||
|
||||
.. js:function:: recruitMember(name)
|
||||
|
||||
:param string name: Name of member to recruit
|
||||
|
||||
Attempt to recruit a new gang member.
|
||||
|
||||
Possible reasons for failure:
|
||||
* Cannot currently recruit a new member
|
||||
* There already exists a member with the specified name
|
||||
|
||||
:returns: True if the member was successfully recruited. False otherwise
|
||||
|
||||
getTaskNames
|
||||
------------
|
||||
|
||||
.. js:function:: getTaskNames()
|
||||
|
||||
Get the name of all valid tasks that Gang members can be assigned to
|
||||
|
||||
:returns: Array of strings of all task names
|
||||
|
||||
setMemberTask
|
||||
-------------
|
||||
|
||||
.. js:function:: setMemberTask(memberName, taskName)
|
||||
|
||||
:param string memberName: Name of Gang member to assign
|
||||
:param string taskName: Task to assign
|
||||
|
||||
Attempts to assign the specified Gang Member to the specified task.
|
||||
If an invalid task is specified, the Gang member will be set to idle ("Unassigned")
|
||||
|
||||
:returns: True if the Gang Member was successfully assigned to the task. False otherwise
|
||||
|
||||
getEquipmentNames
|
||||
-----------------
|
||||
|
||||
.. js:function:: getEquipmentNames()
|
||||
|
||||
Get the name of all possible equipment/upgrades you can purchase for your
|
||||
Gang Members. This includes Augmentations.
|
||||
|
||||
:returns: Array of strings of the names of all Equpiment/Augmentations
|
||||
|
||||
getEquipmentCost
|
||||
----------------
|
||||
|
||||
.. js:function:: getEquipmentCost(equipName)
|
||||
|
||||
:param string equipName: Name of equipment
|
||||
|
||||
Get the amount of money it takes to purchase a piece of Equipment or an Augmentation.
|
||||
If an invalid Equipment/Augmentation is specified, this function will return Infinity.
|
||||
|
||||
:returns: Cost to purchase the specified Equipment/Augmentation (number). Infinity
|
||||
for invalid arguments
|
||||
|
||||
getEquipmentType
|
||||
----------------
|
||||
|
||||
.. js:function:: getEquipmentType(equipName)
|
||||
|
||||
:param string equipName: Name of equipment
|
||||
|
||||
Get the specified equipment type, which can be one of the following:
|
||||
|
||||
* Weapon
|
||||
* Armor
|
||||
* Vehicle
|
||||
* Rootkit
|
||||
* Augmentation
|
||||
|
||||
:returns: A string stating the type of the equipment
|
||||
|
||||
purchaseEquipment
|
||||
-----------------
|
||||
|
||||
.. js:function:: purchaseEquipment(memberName, equipName)
|
||||
|
||||
:param string memberName: Name of Gang member to purchase the equipment for
|
||||
:param string equipName: Name of Equipment/Augmentation to purchase
|
||||
|
||||
Attempt to purchase the specified Equipment/Augmentation for the specified
|
||||
Gang member.
|
||||
|
||||
:returns: True if the equipment was successfully purchased. False otherwise
|
||||
|
||||
|
||||
ascendMember
|
||||
------------
|
||||
|
||||
.. js:function:: ascendMember(name)
|
||||
|
||||
:param string name: Name of member to ascend
|
||||
|
||||
Ascend the specified Gang Member.
|
||||
|
||||
:returns: An object with info about the ascension results.
|
||||
|
||||
The object has the following structure::
|
||||
|
||||
{
|
||||
respect: Amount of respect lost from ascending
|
||||
hack: Hacking multiplier gained from ascending. Decimal form
|
||||
str: Strength multiplier gained from ascending. Decimal form
|
||||
def: Defense multiplier gained from ascending. Decimal form
|
||||
dex: Dexterity multiplier gained from ascending. Decimal form
|
||||
agi: Agility multiplier gained from ascending. Decimal form
|
||||
cha: Charisma multiplier gained from ascending. Decimal form
|
||||
}
|
||||
|
||||
|
||||
setTerritoryWarfare
|
||||
-------------------
|
||||
|
||||
.. js:function:: setTerritoryWarfare(engage)
|
||||
|
||||
:param bool engage: Whether or not to engage in territory warfare
|
||||
|
||||
Set whether or not the gang should engage in territory warfare
|
||||
|
||||
getChanceToWinClash
|
||||
-------------------
|
||||
|
||||
.. js:function:: getChanceToWinClash(gangName)
|
||||
|
||||
:param string gangName: Target gang
|
||||
|
||||
Returns the chance you have to win a clash with the specified gang. The chance
|
||||
is returned in decimal form, not percentage
|
||||
|
||||
|
||||
getBonusTime
|
||||
------------
|
||||
|
||||
.. js:function:: getBonusTime()
|
||||
|
||||
Returns the amount of accumulated "bonus time" (seconds) for the Gang mechanic.
|
||||
|
||||
"Bonus time" is accumulated when the game is offline or if the game is
|
||||
inactive in the browser.
|
||||
|
||||
"Bonus time" makes the game progress faster, up to 10x the normal speed.
|
||||
|
||||
:returns: Bonus time for the Gang mechanic in seconds
|
||||
266
doc/source/netscript/netscripthacknetnodeapi.rst
Normal file
266
doc/source/netscript/netscripthacknetnodeapi.rst
Normal file
@@ -0,0 +1,266 @@
|
||||
.. _netscripthacknetnodeapi:
|
||||
|
||||
Netscript Hacknet Node API
|
||||
==========================
|
||||
|
||||
Netscript provides the following API for accessing and upgrading your Hacknet Nodes
|
||||
through scripts.
|
||||
|
||||
Note that none of these functions will write to the script's logs. If you want
|
||||
to see what your script is doing you will have to print to the logs yourself.
|
||||
|
||||
**Hacknet Node API functions must be accessed through the hacknet namespace**
|
||||
|
||||
In Netscript 1.0::
|
||||
|
||||
hacknet.purchaseNode();
|
||||
hacknet.getNodeStats(3).level;
|
||||
|
||||
In :ref:`netscriptjs`::
|
||||
|
||||
ns.hacknet.purchaseNode();
|
||||
ns.hacknet.getNodeStats(3).level;
|
||||
|
||||
Referencing a Hacknet Node
|
||||
--------------------------
|
||||
Most of the functions in the Hacknet Node API perform an operation on a single
|
||||
Node. Therefore, a numeric index is used to identify and specify which Hacknet
|
||||
Node a function should act on. This index number corresponds to the number
|
||||
at the end of the name of the Hacknet Node. For example, the first Hacknet Node you
|
||||
purchase will have the name "hacknet-node-0" and is referenced using index 0.
|
||||
The fifth Hacknet Node you purchase will have the name "hacknet-node-4" and is
|
||||
referenced using index 4.
|
||||
|
||||
numNodes
|
||||
--------
|
||||
.. js:function:: numNodes()
|
||||
|
||||
Returns the number of Hacknet Nodes you own.
|
||||
|
||||
purchaseNode
|
||||
------------
|
||||
.. js:function:: purchaseNode()
|
||||
|
||||
Purchases a new Hacknet Node. Returns a number with the index of the Hacknet Node.
|
||||
This index is equivalent to the number at the end of the Hacknet Node's name
|
||||
(e.g The Hacknet Node named 'hacknet-node-4' will have an index of 4).
|
||||
|
||||
If the player cannot afford to purchase a new Hacknet Node then the function
|
||||
will return -1.
|
||||
|
||||
getPurchaseNodeCost
|
||||
-------------------
|
||||
.. js:function:: getPurchaseNodeCost()
|
||||
|
||||
Returns the cost of purchasing a new Hacknet Node
|
||||
|
||||
getNodeStats
|
||||
------------
|
||||
.. js:function:: getNodeStats(i)
|
||||
|
||||
:param number i: Index/Identifier of Hacknet Node
|
||||
|
||||
Returns an object containing a variety of stats about the specified Hacknet Node::
|
||||
|
||||
{
|
||||
name: Node's name ("hacknet-node-5"),
|
||||
level: Node's level,
|
||||
ram: Node's RAM,
|
||||
cores: Node's number of cores,
|
||||
production: Node's money earned per second,
|
||||
timeOnline: Number of seconds since Node has been purchased,
|
||||
totalProduction: Total number of money Node has produced
|
||||
}
|
||||
|
||||
upgradeLevel
|
||||
------------
|
||||
.. js:function:: upgradeLevel(i, n)
|
||||
|
||||
:param number i: Index/Identifier of Hacknet Node
|
||||
:param number n: Number of levels to purchase. Must be positive. Rounded to nearest integer
|
||||
|
||||
Tries to upgrade the level of the specified Hacknet Node by *n*.
|
||||
|
||||
Returns true if the Hacknet Node's level is successfully upgraded by *n* or
|
||||
if it is upgraded by some positive amount and the Node reaches its max level.
|
||||
|
||||
Returns false otherwise.
|
||||
|
||||
upgradeRam
|
||||
----------
|
||||
.. js:function:: upgradeRam(i, n)
|
||||
|
||||
:param number i: Index/Identifier of Hacknet Node
|
||||
:param number n: Number of times to upgrade RAM. Must be positive. Rounded to nearest integer
|
||||
|
||||
Tries to upgrade the specified Hacknet Node's RAM *n* times. Note that each upgrade
|
||||
doubles the Node's RAM. So this is equivalent to multiplying the Node's RAM by
|
||||
2 :sup:`n`.
|
||||
|
||||
Returns true if the Hacknet Node's RAM is successfully upgraded *n* times or if
|
||||
it is upgraded some positive number of times and the Node reaches it max RAM.
|
||||
|
||||
Returns false otherwise.
|
||||
|
||||
upgradeCore
|
||||
-----------
|
||||
.. js:function:: upgradeCore(i, n)
|
||||
|
||||
:param number i: Index/Identifier of Hacknet Node
|
||||
:param number n: Number of cores to purchase. Must be positive. Rounded to nearest integer
|
||||
|
||||
Tries to purchase *n* cores for the specified Hacknet Node.
|
||||
|
||||
Returns true if it successfully purchases *n* cores for the Hacknet Node or if
|
||||
it purchases some positive amount and the Node reaches its max number of cores.
|
||||
|
||||
Returns false otherwise.
|
||||
|
||||
getLevelUpgradeCost
|
||||
-------------------
|
||||
.. js:function:: getLevelUpgradeCost(i, n)
|
||||
|
||||
:param number i: Index/Identifier of Hacknet Node
|
||||
:param number n: Number of levels to upgrade. Must be positive. Rounded to nearest integer
|
||||
|
||||
Returns the cost of upgrading the specified Hacknet Node by *n* levels.
|
||||
|
||||
If an invalid value for *n* is provided, then this function returns 0. If the
|
||||
specified Hacknet Node is already at max level, then Infinity is returned.
|
||||
|
||||
getRamUpgradeCost
|
||||
-----------------
|
||||
.. js:function:: getRamUpgradeCost(i, n)
|
||||
|
||||
:param number i: Index/Identifier of Hacknet Node
|
||||
:param number n: Number of times to upgrade RAM. Must be positive. Rounded to nearest integer
|
||||
|
||||
Returns the cost of upgrading the RAM of the specified Hacknet Node *n* times.
|
||||
|
||||
If an invalid value for *n* is provided, then this function returns 0. If the
|
||||
specified Hacknet Node is already at max RAM, then Infinity is returned.
|
||||
|
||||
getCoreUpgradeCost
|
||||
------------------
|
||||
.. js:function:: getCoreUpgradeCost(i, n)
|
||||
|
||||
:param number i: Index/Identifier of Hacknet Node
|
||||
:param number n: Number of times to upgrade cores. Must be positive. Rounded to nearest integer
|
||||
|
||||
Returns the cost of upgrading the number of cores of the specified Hacknet Node by *n*.
|
||||
|
||||
If an invalid value for *n* is provided, then this function returns 0. If the
|
||||
specified Hacknet Node is already at the max number of cores, then Infinity is returned.
|
||||
|
||||
Utilities
|
||||
---------
|
||||
The following functions are not officially part of the Hacknet Node API, but they
|
||||
can be useful when writing Hacknet Node-related scripts. Since they are not part
|
||||
of the API, they do not need to be accessed using the *hacknet* namespace.
|
||||
|
||||
.. js:function:: getHacknetMultipliers()
|
||||
|
||||
Returns an object containing the Player's hacknet related multipliers. These multipliers are
|
||||
returned in integer forms, not percentages (e.g. 1.5 instead of 150%). The object has the following structure::
|
||||
|
||||
{
|
||||
production: Player's hacknet production multiplier,
|
||||
purchaseCost: Player's hacknet purchase cost multiplier,
|
||||
ramCost: Player's hacknet ram cost multiplier,
|
||||
coreCost: Player's hacknet core cost multiplier,
|
||||
levelCost: Player's hacknet level cost multiplier
|
||||
}
|
||||
|
||||
Example of how this can be used::
|
||||
|
||||
mults = getHacknetMultipliers();
|
||||
print(mults.production);
|
||||
print(mults.purchaseCost);
|
||||
|
||||
|
||||
Example(s)
|
||||
^^^^^^^^^^
|
||||
|
||||
The following is an example of one way a script can be used to automate the
|
||||
purchasing and upgrading of Hacknet Nodes.
|
||||
|
||||
This script attempts to purchase Hacknet Nodes until the player has a total of 8. Then
|
||||
it gradually upgrades those Node's to a minimum of level 140, 64 GB RAM, and 8 cores::
|
||||
|
||||
function myMoney() {
|
||||
return getServerMoneyAvailable("home");
|
||||
}
|
||||
disableLog("getServerMoneyAvailable");
|
||||
disableLog("sleep");
|
||||
|
||||
cnt = 8;
|
||||
|
||||
while(hacknet.numNodes() < cnt) {
|
||||
res = hacknet.purchaseNode();
|
||||
print("Purchased hacknet Node with index " + res);
|
||||
};
|
||||
|
||||
for (i = 0; i < cnt; i++) {
|
||||
while (hacknet.getNodeStats(i).level <= 80) {
|
||||
var cost = hacknet.getLevelUpgradeCost(i, 10);
|
||||
while (myMoney() < cost) {
|
||||
print("Need $" + cost + " . Have $" + myMoney());
|
||||
sleep(3000);
|
||||
}
|
||||
res = hacknet.upgradeLevel(i, 10);
|
||||
};
|
||||
};
|
||||
|
||||
print("All nodes upgrade to level 80");
|
||||
|
||||
for (i = 0; i < cnt; i++) {
|
||||
while (hacknet.getNodeStats(i).ram < 16) {
|
||||
var cost = hacknet.getRamUpgradeCost(i, 2);
|
||||
while (myMoney() < cost) {
|
||||
print("Need $" + cost + " . Have $" + myMoney());
|
||||
sleep(3000);
|
||||
}
|
||||
res = hacknet.upgradeRam(i, 2);
|
||||
};
|
||||
};
|
||||
|
||||
print("All nodes upgrade to 16GB RAM");
|
||||
|
||||
for (i = 0; i < cnt; i++) {
|
||||
while (hacknet.getNodeStats(i).level <= 140) {
|
||||
var cost = hacknet.getLevelUpgradeCost(i, 5);
|
||||
while (myMoney() < cost) {
|
||||
print("Need $" + cost + " . Have $" + myMoney());
|
||||
sleep(3000);
|
||||
}
|
||||
res = hacknet.upgradeLevel(i, 5);
|
||||
};
|
||||
};
|
||||
|
||||
print("All nodes upgrade to level 140");
|
||||
|
||||
for (i = 0; i < cnt; i++) {
|
||||
while (hacknet.getNodeStats(i).ram < 64) {
|
||||
var cost = hacknet.getRamUpgradeCost(i, 2);
|
||||
while (myMoney() < cost) {
|
||||
print("Need $" + cost + " . Have $" + myMoney());
|
||||
sleep(3000);
|
||||
}
|
||||
res = hacknet.upgradeRam(i, 2);
|
||||
};
|
||||
};
|
||||
|
||||
print("All nodes upgrade to 64GB RAM (MAX)");
|
||||
|
||||
for (i = 0; i < cnt; i++) {
|
||||
while (hacknetnodes.getNodeStatsi(i).cores < 8) {
|
||||
var cost = hacknet.getCoreUpgradeCost(7);
|
||||
while (myMoney() < cost) {
|
||||
print("Need $" + cost + " . Have $" + myMoney());
|
||||
sleep(3000);
|
||||
}
|
||||
res = hacknet.upgradeCore(i, 7);
|
||||
};
|
||||
};
|
||||
|
||||
print("All nodes upgrade to 8 cores");
|
||||
236
doc/source/netscript/netscriptixapi.rst
Normal file
236
doc/source/netscript/netscriptixapi.rst
Normal file
@@ -0,0 +1,236 @@
|
||||
Netscript Trade Information eXchange (TIX) API
|
||||
==============================================
|
||||
|
||||
The Trade Information eXchange (TIX) is the communications protocol supported by the World Stock Exchange (WSE).
|
||||
The WSE provides an API that allows you to automatically communicate with the
|
||||
`Stock Market <http://bitburner.wikia.com/wiki/Stock_Market>`_. This API lets you write code using Netscript
|
||||
to build automated trading systems and create your own algorithmic trading strategies. Access to this
|
||||
TIX API can be purchased by visiting the World Stock Exchange in-game.
|
||||
|
||||
Access to the TIX API currently costs $5 billion. After you purchase it, you will retain this
|
||||
access even after you 'reset' by installing Augmentations
|
||||
|
||||
getStockSymbols
|
||||
---------------
|
||||
|
||||
.. js:function:: getStockSymbols()
|
||||
|
||||
Returns an array of the symbols of the tradable stocks
|
||||
|
||||
getStockPrice
|
||||
-------------
|
||||
|
||||
.. js:function:: getStockPrice(sym)
|
||||
|
||||
:param string sym: Stock symbol
|
||||
|
||||
Returns the price of a stock, given its symbol (NOT the company name). The symbol is a sequence
|
||||
of two to four capital letters.
|
||||
|
||||
Example::
|
||||
|
||||
getStockPrice("FISG");
|
||||
|
||||
getStockPosition
|
||||
----------------
|
||||
|
||||
.. js:function:: getStockPosition(sym)
|
||||
|
||||
:param string sym: Stock symbol
|
||||
|
||||
Returns an array of four elements that represents the player's position in a stock.
|
||||
|
||||
The first element is the returned array is the number of shares the player owns of the stock in the
|
||||
`Long position <http://bitburner.wikia.com/wiki/Stock_Market#Positions:_Long_vs_Short>`_. The second
|
||||
element in the array is the average price of the player's shares in the Long position.
|
||||
|
||||
The third element in the array is the number of shares the player owns of the stock in the
|
||||
`Short position <http://bitburner.wikia.com/wiki/Stock_Market#Positions:_Long_vs_Short>`_. The fourth
|
||||
element in the array is the average price of the player's Short position.
|
||||
|
||||
All elements in the returned array are numeric.
|
||||
|
||||
Example::
|
||||
|
||||
pos = getStockPosition("ECP");
|
||||
shares = pos[0];
|
||||
avgPx = pos[1];
|
||||
sharesShort = pos[2];
|
||||
avgPxShort = pos[3];
|
||||
|
||||
buyStock
|
||||
--------
|
||||
|
||||
.. js:function:: buyStock(sym, shares)
|
||||
|
||||
:param string sym: Symbol of stock to purchase
|
||||
:param number shares: Number of shares to purchased. Must be positive. Will be rounded to nearest integer
|
||||
|
||||
Attempts to purchase shares of a stock using a `Market Order <http://bitburner.wikia.com/wiki/Stock_Market#Order_Types>`_.
|
||||
|
||||
If the player does not have enough money to purchase the specified number of shares, then no shares will be purchased. Remember
|
||||
that every transaction on the stock exchange costs a certain commission fee.
|
||||
|
||||
If this function successfully purchases the shares, it will return the stock price at which each share was purchased. Otherwise,
|
||||
it will return 0.
|
||||
|
||||
sellStock
|
||||
---------
|
||||
|
||||
.. js:function:: sellStock(sym, shares)
|
||||
|
||||
:param string sym: Symbol of stock to sell
|
||||
:param number shares: Number of shares to sell. Must be positive. Will be rounded to nearest integer
|
||||
|
||||
Attempts to sell shares of a stock using a `Market Order <http://bitburner.wikia.com/wiki/Stock_Market#Order_Types>`_.
|
||||
|
||||
If the specified number of shares in the function exceeds the amount that the player actually owns, then this function will
|
||||
sell all owned shares. Remember that every transaction on the stock exchange costs a certain commission fee.
|
||||
|
||||
The net profit made from selling stocks with this function is reflected in the script's statistics.
|
||||
This net profit is calculated as::
|
||||
|
||||
shares * (sell price - average price of purchased shares)
|
||||
|
||||
If the sale is successful, this function will return the stock price at which each share was sold. Otherwise, it will return 0.
|
||||
|
||||
shortStock
|
||||
----------
|
||||
|
||||
.. js:function:: shortStock(sym, shares)
|
||||
|
||||
:param string sym: Symbol of stock to short
|
||||
:param number shares: Number of shares to short. Must be positive. Will be rounded to nearest integer
|
||||
|
||||
Attempts to purchase a `short <http://bitburner.wikia.com/wiki/Stock_Market#Positions:_Long_vs_Short>`_ position of a stock
|
||||
using a `Market Order <http://bitburner.wikia.com/wiki/Stock_Market#Order_Types>`_.
|
||||
|
||||
The ability to short a stock is **not** immediately available to the player and must be unlocked later on in the game.
|
||||
|
||||
If the player does not have enough money to purchase the specified number of shares, then no shares will be purchased.
|
||||
Remember that every transaction on the stock exchange costs a certain commission fee.
|
||||
|
||||
If the purchase is successful, this function will return the stock price at which each share was purchased. Otherwise, it will return 0.
|
||||
|
||||
sellShort
|
||||
---------
|
||||
|
||||
.. js:function:: sellShort(sym, shares)
|
||||
|
||||
:param string sym: Symbol of stock to sell
|
||||
:param number shares: Number of shares to sell. Must be positive. Will be rounded to nearest integer
|
||||
|
||||
Attempts to sell a `short <http://bitburner.wikia.com/wiki/Stock_Market#Positions:_Long_vs_Short>`_ position of a stock
|
||||
using a `Market Order <http://bitburner.wikia.com/wiki/Stock_Market#Order_Types>`_.
|
||||
|
||||
The ability to short a stock is **not** immediately available to the player and must be unlocked later on in the game.
|
||||
|
||||
If the specified number of shares exceeds the amount that the player actually owns, then this function will sell all owned
|
||||
shares. Remember that every transaction on the stock exchange costs a certain commission fee.
|
||||
|
||||
If the sale is successful, this function will return the stock price at which each share was sold. Otherwise it will return 0.
|
||||
|
||||
placeOrder
|
||||
----------
|
||||
|
||||
.. js:function:: placeOrder(sym, shares, price, type, pos)
|
||||
|
||||
:param string sym: Symbol of stock to player order for
|
||||
:param number shares: Number of shares for order. Must be positive. Will be rounded to nearest integer
|
||||
:param number price: Execution price for the order
|
||||
:param string type: Type of order. It must specify "limit" or "stop", and must also specify "buy" or "sell". This is NOT
|
||||
case-sensitive. Here are four examples that will work:
|
||||
|
||||
* limitbuy
|
||||
* limitsell
|
||||
* stopbuy
|
||||
* stopsell
|
||||
|
||||
:param string pos:
|
||||
Specifies whether the order is a "Long" or "Short" position. The Values "L" or "S" can also be used. This is
|
||||
NOT case-sensitive.
|
||||
|
||||
Places an order on the stock market. This function only works for `Limit and Stop Orders <http://bitburner.wikia.com/wiki/Stock_Market#Order_Types>`_.
|
||||
|
||||
The ability to place limit and stop orders is **not** immediately available to the player and must be unlocked later on in the game.
|
||||
|
||||
Returns true if the order is successfully placed, and false otherwise.
|
||||
|
||||
cancelOrder
|
||||
-----------
|
||||
|
||||
.. js:function:: cancelOrder(sym, shares, price, type, pos)
|
||||
|
||||
:param string sym: Symbol of stock to player order for
|
||||
:param number shares: Number of shares for order. Must be positive. Will be rounded to nearest integer
|
||||
:param number price: Execution price for the order
|
||||
:param string type: Type of order. It must specify "limit" or "stop", and must also specify "buy" or "sell". This is NOT
|
||||
case-sensitive. Here are four examples that will work:
|
||||
|
||||
* limitbuy
|
||||
* limitsell
|
||||
* stopbuy
|
||||
* stopsell
|
||||
|
||||
:param string pos:
|
||||
Specifies whether the order is a "Long" or "Short" position. The Values "L" or "S" can also be used. This is
|
||||
NOT case-sensitive.
|
||||
|
||||
Cancels an oustanding Limit or Stop order on the stock market.
|
||||
|
||||
The ability to use limit and stop orders is **not** immediately available to the player and must be unlocked later on in the game.
|
||||
|
||||
getStockVolatility
|
||||
------------------
|
||||
|
||||
.. js:function:: getStockVolatility(sym)
|
||||
|
||||
:param string sym: Symbol of stock
|
||||
|
||||
Returns the volatility of the specified stock.
|
||||
|
||||
Volatility represents the maximum percentage by which a stock's price can
|
||||
change every tick. The volatility is returned as a decimal value, NOT
|
||||
a percentage (e.g. if a stock has a volatility of 3%, then this function will
|
||||
return 0.03, NOT 3).
|
||||
|
||||
In order to use this function, you must first purchase access to the Four Sigma (4S)
|
||||
Market Data TIX API.
|
||||
|
||||
getStockForecast
|
||||
----------------
|
||||
|
||||
.. js:function:: getStockForecast(sym)
|
||||
|
||||
:param string sym: Symbol of stock
|
||||
|
||||
Returns the probability that the specified stock's price will increase
|
||||
(as opposed to decrease) during the next tick.
|
||||
|
||||
The probability is returned as a decimal value, NOT a percentage (e.g. if a
|
||||
stock has a 60% chance of increasing, then this function will return 0.6,
|
||||
NOT 60).
|
||||
|
||||
In other words, if this function returned 0.30 for a stock, then this means
|
||||
that the stock's price has a 30% chance of increasing and a 70% chance of
|
||||
decreasing during the next tick.
|
||||
|
||||
purchase4SMarketData
|
||||
--------------------
|
||||
|
||||
.. js:function:: purchase4SMarketData()
|
||||
|
||||
Purchase 4S Market Data Access.
|
||||
|
||||
Returns true if you successfully purchased it or if you already have access.
|
||||
Returns false otherwise.
|
||||
|
||||
purchase4SMarketDataTixApi
|
||||
--------------------------
|
||||
|
||||
.. js:function:: purchase4SMarketDataTixApi()
|
||||
|
||||
Purchase 4S Market Data TIX API Access.
|
||||
|
||||
Returns true if you successfully purchased it or if you already have access.
|
||||
Returns false otherwise.
|
||||
207
doc/source/netscript/netscriptjs.rst
Normal file
207
doc/source/netscript/netscriptjs.rst
Normal file
@@ -0,0 +1,207 @@
|
||||
.. _netscriptjs:
|
||||
|
||||
NetscriptJS (Netscript 2.0)
|
||||
===========================
|
||||
Netscript 2.0, or Netscript JS, is the new and improved version of Netscript that
|
||||
allows users to write (almost) full-fledged Javascript code in their scripts, while
|
||||
still being able to access the Netscript functions.
|
||||
|
||||
NetscriptJS was developed primarily by `Github user jaguilar <https://github.com/jaguilar>`_
|
||||
|
||||
On top of having almost all of the features and capabilities of JavaScript, NetscriptJS is also
|
||||
significantly faster than Netscript 1.0.
|
||||
|
||||
This documentation will not go over any of the additional features of NetscriptJS, since
|
||||
there is plenty of documentation on Javascript available on the web.
|
||||
|
||||
NetscriptJS in Mozilla Firefox
|
||||
------------------------------
|
||||
As of the time of writing this, the Mozilla Firefox browser does not support
|
||||
dynamic import functionality and therefore cannot run NetscriptJS scripts.
|
||||
|
||||
(This may be some option/method for enabling this in Firefox, but I don't know
|
||||
what is it)
|
||||
|
||||
How to use NetscriptJS
|
||||
----------------------
|
||||
Working with NetscriptJS scripts is the same as Netscript 1.0 scripts. The only difference
|
||||
is that NetscriptJS scripts use the ".ns" or ".js" extension rather than ".script". E.g.::
|
||||
|
||||
$ nano foo.ns
|
||||
$ run foo.ns -t 100 arg1 arg2 arg3
|
||||
exec("foo.ns", "purchasedServer1", "100", "randomArg");
|
||||
|
||||
The caveat when using NetscriptJS to write scripts is that your code must be
|
||||
asynchronous. Furthermore, instead of using the global scope and executing your code
|
||||
sequentially, NetscriptJS uses a :code:`main()` function as an entry point.
|
||||
|
||||
Furthermore, the "Netscript environment" must be passed into a NetscriptJS script through
|
||||
the main function. This environment includes all of the pre-defined Netscript functions
|
||||
(:code:`hack()`, :code:`exec`, etc.) as well as the arguments you pass to the script.
|
||||
|
||||
Therefore, the signature of the :code:`main()` function must be::
|
||||
|
||||
export async function main(ns) {
|
||||
ns.print("Starting script here");
|
||||
await ns.hack("foodnstuff"); //Use Netscript hack function
|
||||
ns.print(ns.args); //The script arguments must be prefaced with ns as well
|
||||
}
|
||||
|
||||
Here is a summary of all rules you need to follow when writing Netscript JS code:
|
||||
|
||||
* Write :code:`await` before any call to the following Netscript functions:
|
||||
|
||||
* hack
|
||||
* grow
|
||||
* weaken
|
||||
* sleep
|
||||
* run
|
||||
* exec
|
||||
* prompt
|
||||
* wget
|
||||
|
||||
* Any function that contains :code:`await` must be declared as :code:`async`
|
||||
|
||||
* Always :code:`await` any function that is marked as :code:`async`
|
||||
|
||||
* Any functions that you want to be visible from other scripts must be marked with :code:`export`.
|
||||
|
||||
* **Do not write any infinite loops without using a** :code:`sleep` **or one of the timed Netscript functions like** :code:`hack`. Doing so will crash your game.
|
||||
|
||||
* Any global variable declared in a NetscriptJS script is shared between all instances of that
|
||||
script. For example, assume you write a script *foo.ns* and declared a global variable like so::
|
||||
|
||||
//foo.ns
|
||||
let globalVariable;
|
||||
|
||||
export async function main(ns) {
|
||||
globalVariable = ns.args.length;
|
||||
while(true) {
|
||||
ns.tprint(globalVariable);
|
||||
await ns.sleep(3000);
|
||||
}
|
||||
}
|
||||
|
||||
Then, you ran multiple instances of *foo.ns*::
|
||||
|
||||
$ run foo.ns 1
|
||||
$ run foo.ns 1 2 3
|
||||
$ run foo.ns 1 2 3 4 5
|
||||
|
||||
Then all three instances of foo.ns will share the same instance of :code:`globalVariable`.
|
||||
(In this example, the value of :code:`globalVariable` will be set to 5 because the
|
||||
last instance of *foo.ns* to run has 5 arguments. This means that all three instances of
|
||||
the script will repeatedly print the value 5).
|
||||
|
||||
These global variables can be thought of as `C++ static class members <https://www.tutorialspoint.com/cplusplus/cpp_static_members.htm>`_,
|
||||
where a NetscriptJS script is a class and a global variable is a static member within that class.
|
||||
|
||||
Warnings
|
||||
--------
|
||||
The NetscriptJS evaluation engine works by converting your code into a blob URL and then
|
||||
using a dynamic import to load your code as a module. Every unique NetscriptJS script
|
||||
is loaded as its own module. This means that
|
||||
making a small edit to a NetscriptJS script results in a new module being generated.
|
||||
|
||||
At this point, we have been unable to find a method for deleting modules from browsers so that
|
||||
they get garbage collected.
|
||||
|
||||
The result is that these modules from NetscriptJS scripts accumulate in your browser,
|
||||
using memory that never gets released. Over time, this results in a memory-leak type
|
||||
situation that can slow down your computer.
|
||||
|
||||
Therefore, there are two recommendations for those who decide to use NetscriptJS:
|
||||
|
||||
1. Every now and then, close and re-open the game. This will clear all of the modules.
|
||||
To be safe, I recommend **completely** closing the game's tab and then re-opening it.
|
||||
Depending on your browser, a refresh or page reload does not always clear the modules.
|
||||
|
||||
2. Only use NetscriptJS scripts when needed. It is very unlikely that NetscriptJS
|
||||
is needed for very simple scripts. By doing this, you will reduce the number of modules
|
||||
that are loaded.
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
**DOM Manipulation (tprintColored.ns)**
|
||||
|
||||
Directly alter the game's terminal and print colored text::
|
||||
|
||||
export function tprintColored(txt, color) {
|
||||
let terminalInput = document.getElementById("terminal-input");
|
||||
let rowElement = document.createElement("tr");
|
||||
let cellElement = document.createElement("td");
|
||||
|
||||
rowElement.classList.add("posted");
|
||||
cellElement.classList.add("terminal-line");
|
||||
cellElement.style.color = color;
|
||||
cellElement.innerText = txt;
|
||||
|
||||
rowElement.appendChild(cellElement);
|
||||
terminalInput.before(rowElement);
|
||||
}
|
||||
|
||||
export async function main(ns) {
|
||||
tprintColored("Red Text!", "red");
|
||||
tprintColored("Blue Text!", "blue");
|
||||
tprintColored("Use Hex Codes!", "#3087E3");
|
||||
}
|
||||
|
||||
**Script Scheduler (scriptScheduler.ns)**
|
||||
|
||||
This script shows some of the new functionality that is available in NetscriptJS,
|
||||
including objects and object constructors, changing an object's prototype, and
|
||||
importing other NetscriptJS scripts::
|
||||
|
||||
import {tprintColored} from "tprintColored.ns"; //Importing from other NetscriptJS scripts works!
|
||||
|
||||
function ScriptJob(params) {
|
||||
if (params.fn == null) {
|
||||
throw new Error("No Filename (fn) passed into ScriptJob ctor");
|
||||
}
|
||||
|
||||
this.fn = params.fn;
|
||||
this.threads = params.threads ? params.threads : 1;
|
||||
this.args = params.args ? params.args : [];
|
||||
}
|
||||
|
||||
ScriptJob.prototype.run = async function(ns) {
|
||||
let runArgs = [this.fn, this.threads].concat(this.args);
|
||||
await ns.run.apply(this, runArgs);
|
||||
tprintColored("Running " + this.fn + " on " + ns.getHostname(), "blue");
|
||||
}
|
||||
|
||||
ScriptJob.prototype.exec = async function(ns, target) {
|
||||
ns.scp(this.fn, target);
|
||||
|
||||
let execArgs = [this.fn, target, this.threads].concat(this.args);
|
||||
await ns.exec.apply(this, execArgs);
|
||||
|
||||
tprintColored("Executing " + this.fn + " on " + target, "blue");
|
||||
}
|
||||
|
||||
export async function main(ns) {
|
||||
tprintColored("Starting scriptScheduler.ns", "red");
|
||||
try {
|
||||
let job = new ScriptJob({
|
||||
fn: "test.js",
|
||||
threads: 1,
|
||||
args: ["foodnstuff"]
|
||||
});
|
||||
await job.run(ns);
|
||||
await job.exec(ns, "foodnstuff");
|
||||
} catch (e) {
|
||||
ns.tprint("Exception thrown in scriptScheduler.ns: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
Final Note
|
||||
----------
|
||||
NetscriptJS opens up a lot of possibilities when scripting. I look forward to seeing
|
||||
the scripts that people come up with. Just remember that the power and capabilities of
|
||||
NetscriptJS come with risks. Please backup your save if you're going to experiment with
|
||||
NetscriptJS and report any serious exploits.
|
||||
|
||||
With great power comes great responsibility
|
||||
|
||||
Happy hacking
|
||||
70
doc/source/netscript/netscriptlearntoprogram.rst
Normal file
70
doc/source/netscript/netscriptlearntoprogram.rst
Normal file
@@ -0,0 +1,70 @@
|
||||
.. _netscriptlearntoprogram:
|
||||
|
||||
Learn to Program in Netscript
|
||||
=============================
|
||||
Netscript is simply a subset of
|
||||
`JavaScript <https://developer.mozilla.org/en-US/docs/Web/JavaScript>`_,
|
||||
with some additional functions added in to allow interaction with the game.
|
||||
|
||||
For Beginner Programmers
|
||||
------------------------
|
||||
If you have little to no programming experience, that's okay! You don't need to be
|
||||
a great programmer in order to enjoy or play this game. In fact, this game could
|
||||
help you learn some basic programming concepts.
|
||||
|
||||
Here are some good tutorials for learning programming/JavaScript as a beginner:
|
||||
|
||||
* `Learn-JS <http://www.learn-js.org/en/Welcome>`_
|
||||
* `Speaking JavaScript <http://speakingjs.com/es5/index.html>`_
|
||||
This is a bit on the longer side. You can skip all of the historical
|
||||
background stuff. Recommended chapters: 1, 7-18
|
||||
|
||||
For Experienced Programmers
|
||||
---------------------------
|
||||
The following section lists several good tutorials/resources for those who have experience
|
||||
programming but who have not worked extensively with JavaScript before.
|
||||
|
||||
Before that, however, it's important to clarify some terminology about the different
|
||||
versions of JavaScript. These are summarized in this article:
|
||||
|
||||
`WTF is ES6, ES8, ES2017, ECMAScript... <https://codeburst.io/javascript-wtf-is-es6-es8-es-2017-ecmascript-dca859e4821c>`_
|
||||
|
||||
An important takeaway from this article is that ES6, also known as ES2015, introduced
|
||||
many major features that are commonly seen in modern JavaScript programming. However, this
|
||||
means that ES5 engines and interpreters will fail if they encounters these ES6 features. You'll see why this
|
||||
is important further down.
|
||||
|
||||
* `MDN Introduction to JS <https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript>`_
|
||||
* `Eloquent JavaScript (ES6+) <http://eloquentjavascript.net/>`_
|
||||
Recommended Chapters: Introduction, 1-6
|
||||
* `Modern Javascript Tutorial (ES6+) <https://javascript.info/>`_
|
||||
Recommended Chapters: 2, 4-6
|
||||
|
||||
Netscript 1.0 vs Netscript 2.0
|
||||
------------------------------
|
||||
There are two versions of Netscript:
|
||||
|
||||
* :doc:`netscript1`
|
||||
* :doc:`netscriptjs`
|
||||
|
||||
Visit the pages above to get more details about each version. If you are new
|
||||
to programming or unfamiliar with JavaScript, I would recommend starting out
|
||||
with :doc:`netscript1`. Experienced web developers can use :doc:`netscriptjs`
|
||||
to take advantage of faster speeds and additional features.
|
||||
|
||||
Here is a short summary of the differences between Netscript 1.0 and Netscript 2.0:
|
||||
|
||||
**Netscript 1.0**
|
||||
|
||||
* ES5
|
||||
* Some ES6 features implemented with polyfills
|
||||
* Slow compared to NetscriptJS (interpreter runs at the "Netscript Exec Time" speed configured in options)
|
||||
* Compatible with all browsers
|
||||
|
||||
**Netscript JS (Netscript 2.0)**
|
||||
|
||||
* Supports (almost) all features of modern JavaScript
|
||||
* Extremely fast - code is executed as an Async Function
|
||||
* Currently only works with Google Chrome browser
|
||||
* Each script becomes a module and therefore all instances of that script can easily
|
||||
share data between each other (essentially global/static variables)
|
||||
222
doc/source/netscript/netscriptmisc.rst
Normal file
222
doc/source/netscript/netscriptmisc.rst
Normal file
@@ -0,0 +1,222 @@
|
||||
.. _netscript_misc:
|
||||
|
||||
Netscript Miscellaneous
|
||||
=======================
|
||||
|
||||
.. _netscript_ports:
|
||||
|
||||
Netscript Ports
|
||||
---------------
|
||||
Netscript Ports are endpoints that can be used to communicate between scripts.
|
||||
A port is implemented as a sort of serialized queue, where you can only write
|
||||
and read one element at a time from the port. When you read data from a port,
|
||||
the element that is read is removed from the port.
|
||||
|
||||
The :js:func:`read`, :js:func:`write`, :js:func:`tryWrite`, :js:func:`clear`, and :js:func:`peek`
|
||||
Netscript functions can be used to interact with ports.
|
||||
|
||||
Right now, there are only 20 ports for Netscript, denoted by the number 1
|
||||
through 20. When using the functions above, the ports are specified
|
||||
by passing the number as the first argument.
|
||||
|
||||
IMPORTANT: The data inside ports are not saved! This means if you close and
|
||||
re-open the game, or reload the page then you will lose all of the data in
|
||||
the ports!
|
||||
|
||||
**Example Usage**
|
||||
|
||||
Here's a brief example of how ports work. For the sake of simplicity we'll only deal with port 1.
|
||||
|
||||
Let's assume Port 1 starts out empty (no data inside). We'll represent the port as such::
|
||||
|
||||
[]
|
||||
|
||||
Now assume we ran the following simple script::
|
||||
|
||||
for (i = 0; i < 10; ++i) {
|
||||
write(1, i); //Writes the value of i to port 1
|
||||
}
|
||||
|
||||
After this script executes, our script will contain every number from 0 through 9, as so::
|
||||
|
||||
[0, 1, 2, 3, 4, 5, 6, 7 , 8, 9]
|
||||
|
||||
Then, assume we run the following script::
|
||||
|
||||
for (i = 0; i < 3; ++i) {
|
||||
print(read(1)); //Reads a value from port 1 and then prints it
|
||||
}
|
||||
|
||||
This script above will read the first three values from port 1 and then print them to the script's log. The log will end up looking like::
|
||||
|
||||
0
|
||||
1
|
||||
2
|
||||
|
||||
And the data in port 1 will look like::
|
||||
|
||||
[3, 4, 5, 6, 7, 8, 9]
|
||||
|
||||
**Port Handles**
|
||||
|
||||
WARNING: Port Handles only work in :ref:`netscriptjs`. They do not work in :ref:`netscript1`
|
||||
|
||||
The :js:func:`getPortHandle` Netscript function can be used to get a handle to a Netscript Port.
|
||||
This handle allows you to access several new port-related functions and the
|
||||
port's underlying data structure, which is just a JavaScript array. The functions are:
|
||||
|
||||
.. js:method:: NetscriptPort.write(data)
|
||||
|
||||
:param data: Data to write to the port
|
||||
:returns: If the port is full, the item that is removed from the port is returned.
|
||||
Otherwise, null is returned.
|
||||
|
||||
Writes `data` to the port. Works the same as the Netscript function `write`.
|
||||
|
||||
.. js:method:: NetscriptPort.tryWrite(data)
|
||||
|
||||
:param data: Data to try to write to the port
|
||||
:returns: True if the data is successfully written to the port, and false otherwise.
|
||||
|
||||
Attempts to write `data` to the Netscript port. If the port is full, the data will
|
||||
not be written. Otherwise, the data will be written normally.
|
||||
|
||||
.. js::method:: NetscriptPort.read()
|
||||
|
||||
:returns: The data read from the port. If the port is empty, "NULL PORT DATA" is returned
|
||||
|
||||
Removes and returns the first element from the port.
|
||||
Works the same as the Netscript function `read`
|
||||
|
||||
.. js::method:: NetscriptPort.peek()
|
||||
|
||||
:returns: The first element in the port, or "NULL PORT DATA" if the port is empty.
|
||||
|
||||
Returns the first element in the port, but does not remove it.
|
||||
Works the same as the Netscript function `peek`
|
||||
|
||||
.. js:method:: NetscriptPort.full()
|
||||
|
||||
:returns: True if the Netscript Port is full, and false otherwise
|
||||
|
||||
.. js:method:: NetscriptPort.empty()
|
||||
|
||||
:returns: True if the Netscript Port is empty, and false otherwise
|
||||
|
||||
.. js:method:: NetscriptPort.clear()
|
||||
|
||||
Clears all data from the port. Works the same as the Netscript function `clear`
|
||||
|
||||
.. js:attribute:: NetscriptPort.data
|
||||
|
||||
The Netscript port underlying data structure, which is just a Javascript array. All
|
||||
valid Javascript Array methods can be called on this.
|
||||
|
||||
Port Handle Example::
|
||||
|
||||
port = getPortHandle(5);
|
||||
back = port.data.pop(); //Get and remove last element in port
|
||||
|
||||
//Remove an element from the port
|
||||
i = port.data.findIndex("foo");
|
||||
if (i != -1) {
|
||||
port.data.slice(i, 1);
|
||||
}
|
||||
|
||||
//Wait for port data before reading
|
||||
while(port.empty()) {
|
||||
sleep(10000);
|
||||
}
|
||||
res = port.read();
|
||||
|
||||
//Wait for there to be room in a port before writing
|
||||
while (!port.tryWrite(5)) {
|
||||
sleep(5000);
|
||||
}
|
||||
|
||||
//Successfully wrote to port!
|
||||
|
||||
|
||||
Comments
|
||||
--------
|
||||
Netscript supports comments using the same syntax as `Javascript comments <https://www.w3schools.com/js/js_comments.asp>`_.
|
||||
Comments are not evaluated as code, and can be used to document and/or explain code::
|
||||
|
||||
//This is a comment and will not get executed even though its in the code
|
||||
/* Multi
|
||||
* line
|
||||
* comment */
|
||||
print("This code will actually get executed");
|
||||
|
||||
.. _netscriptimporting:
|
||||
|
||||
Importing Functions
|
||||
-------------------
|
||||
|
||||
In Netscript you can import functions that are declared in other scripts.
|
||||
The script will incur the RAM usage of all imported functions.
|
||||
There are two ways of doing this::
|
||||
|
||||
import * as namespace from "script filename"; //Import all functions from script
|
||||
import {fn1, fn2, ...} from "script filename"; //Import specific functions from script
|
||||
|
||||
Suppose you have a library script called *testlibrary.script*::
|
||||
|
||||
function foo1(args) {
|
||||
//function definition...
|
||||
}
|
||||
|
||||
function foo2(args) {
|
||||
//function definition...
|
||||
}
|
||||
|
||||
function foo3(args) {
|
||||
//function definition...
|
||||
}
|
||||
|
||||
function foo4(args) {
|
||||
//function definition...
|
||||
}
|
||||
|
||||
Then, if you wanted to use these functions in another script, you can import them like so::
|
||||
|
||||
import * as testlib from "testlibrary.script";
|
||||
|
||||
values = [1,2,3];
|
||||
|
||||
//The imported functions must be specified using the namespace
|
||||
someVal1 = testlib.foo3(values);
|
||||
someVal2 = testlib.foo1(values);
|
||||
if (someVal1 > someVal2) {
|
||||
//...
|
||||
} else {
|
||||
//...
|
||||
}
|
||||
|
||||
If you only wanted to import certain functions, you can do so without needing
|
||||
to specify a namespace for the import::
|
||||
|
||||
import {foo1, foo3} from "testlibrary.script"; //Saves RAM since not all functions are imported!
|
||||
|
||||
values = [1,2,3];
|
||||
|
||||
//No namespace needed
|
||||
someVal1 = foo3(values);
|
||||
someVal2 = foo1(values);
|
||||
if (someVal1 > someVal2) {
|
||||
//...
|
||||
} else {
|
||||
//...
|
||||
}
|
||||
|
||||
Note that exporting functions is not required.
|
||||
|
||||
Standard, Built-In JavaScript Objects
|
||||
-------------------------------------
|
||||
Standard built-in JavaScript objects such as
|
||||
`Math <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math>`_,
|
||||
`Date <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date>`_,
|
||||
`Number <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number>`_,
|
||||
and others are supported as expected based on which version
|
||||
of Netscript you use (i.e. :ref:`netscript1` will support built-in objects that are
|
||||
defined in ES5, and :ref:`netscriptjs` will support whatever your browser supports).
|
||||
26
doc/source/netscript/netscriptscriptarguments.rst
Normal file
26
doc/source/netscript/netscriptscriptarguments.rst
Normal file
@@ -0,0 +1,26 @@
|
||||
.. _netscript_script_arguments:
|
||||
|
||||
Netscript Script Arguments
|
||||
==========================
|
||||
|
||||
Arguments passed into a script can be accessed in Netscript using a
|
||||
special array called *args*. The arguments can be
|
||||
accessed using a normal array using the [] operator
|
||||
(args[0], args[1], etc...).
|
||||
|
||||
For example, let's say we want to make a generic script
|
||||
'generic-run.script' and we plan to pass two arguments into that script.
|
||||
The first argument will be the name of another script, and the second
|
||||
argument will be a number. This generic script will run the
|
||||
script specified in the first argument with the amount of threads
|
||||
specified in the second element. The code would look like::
|
||||
|
||||
run(args[0], args[1]);
|
||||
|
||||
It is also possible to get the number of arguments that was passed
|
||||
into a script using::
|
||||
|
||||
args.length
|
||||
|
||||
**WARNING: Do not try to modify the args array. This will break the game.
|
||||
I will do my best to prevent players from doing this.**
|
||||
601
doc/source/netscript/netscriptsingularityfunctions.rst
Normal file
601
doc/source/netscript/netscriptsingularityfunctions.rst
Normal file
@@ -0,0 +1,601 @@
|
||||
Netscript Singularity Functions
|
||||
===============================
|
||||
|
||||
The Singularity Functions are a special set of Netscript functions. These functions allow you to control
|
||||
many additional aspects of the game through scripts, such as working for factions/companies, purchasing/installing Augmentations,
|
||||
and creating programs.
|
||||
|
||||
The Singularity Functions are **not** immediately available to the player and must be unlocked later in the game.
|
||||
|
||||
**WARNING: This page contains spoilers for the game**.
|
||||
|
||||
The Singularity Functions are unlocked in BitNode-4. If you are in BitNode-4, then you will automatically have access to all of these functions.
|
||||
You can use the Singularity Functions in other BitNodes if and only if you have the Source-File for BitNode-4 (aka Source-File 4). Each level of
|
||||
Source-File 4 will open up additional Singularity Functions that you can use in other BitNodes. If your Source-File 4 is upgraded all the way to
|
||||
level 3, then you will be able to access all of the Singularity Functions.
|
||||
|
||||
Note that Singularity Functions require twice as much RAM outside of BitNode-4
|
||||
|
||||
universityCourse
|
||||
----------------
|
||||
|
||||
.. js:function:: universityCourse(universityName, courseName)
|
||||
|
||||
:param string universityName:
|
||||
Name of university. Not case-sensitive. You must be in the correct city for whatever university you specify.
|
||||
|
||||
* Summit University
|
||||
* Rothman University
|
||||
* ZB Institute Of Technology
|
||||
:param string courseName:
|
||||
Name of course. Not case-sensitive.
|
||||
|
||||
* Study Computer Science
|
||||
* Data Strucures
|
||||
* Networks
|
||||
* Algorithms
|
||||
* Management
|
||||
* Leadership
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 1 of Source-File 4 in order to use this function.
|
||||
|
||||
This function will automatically set you to start taking a course at a university. If you are already in the middle of some
|
||||
"working" action (such as working at a company, for a faction, or on a program), then running this function will automatically
|
||||
cancel that action and give you your earnings.
|
||||
|
||||
The cost and experience gains for all of these universities and classes are the same as if you were to manually visit and take these classes.
|
||||
|
||||
This function will return true if you successfully start taking the course, and false otherwise.
|
||||
|
||||
gymWorkout
|
||||
----------
|
||||
|
||||
.. js:function:: gymWorkout(gymName, stat)
|
||||
|
||||
:param string gymName:
|
||||
Name of gym. Not case-sensitive. You must be in the correct city for whatever gym you specify.
|
||||
|
||||
* Crush Fitness Gym
|
||||
* Snap Fitness Gym
|
||||
* Iron Gym
|
||||
* Powerhouse Gym
|
||||
* Millenium Fitness Gym
|
||||
:param string stat:
|
||||
The stat you want to train. Not case-sensitive.
|
||||
|
||||
* strength OR str
|
||||
* defense OR def
|
||||
* dexterity OR dex
|
||||
* agility OR agi
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 1 of Source-File 4 in order to use this function.
|
||||
|
||||
This function will automatically set you to start working out at a gym to train a particular stat. If you are
|
||||
already in the middle of some "working" action (such as working at a company, for a faction, or on a program),
|
||||
then running this function will automatically cancel that action and give you your earnings.
|
||||
|
||||
The cost and experience gains for all of these gyms are the same as if you were to manually visit these gyms and train
|
||||
|
||||
This function will return true if you successfully start working out at the gym, and false otherwise.
|
||||
|
||||
travelToCity
|
||||
------------
|
||||
|
||||
.. js:function:: travelToCity(cityName)
|
||||
|
||||
:param string cityName:
|
||||
City to travel to. CASE-SENSITIVE.
|
||||
|
||||
* Aevum
|
||||
* Chongqing
|
||||
* Sector-12
|
||||
* New Tokyo
|
||||
* Ishima
|
||||
* Volhaven
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 1 of Source-File 4 in order to use this function.
|
||||
|
||||
This function allows the player to travel to any city. The cost for using this function is the same as the cost for traveling through the Travel Agency.
|
||||
|
||||
This function will return true if you successfully travel to the specified city and false otherwise.
|
||||
|
||||
purchaseTor
|
||||
-----------
|
||||
|
||||
.. js:function:: purchaseTor()
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 1 of Source-File 4 in order to use this function.
|
||||
|
||||
This function allows you to automatically purchase a TOR router. The cost for purchasing a TOR router using this
|
||||
function is the same as if you were to manually purchase one.
|
||||
|
||||
This function will return true if it successfully purchase a TOR router and false otherwise.
|
||||
|
||||
purchaseProgram
|
||||
---------------
|
||||
|
||||
.. js:function:: purchaseProgram(programName)
|
||||
|
||||
:param string programName: Name of program to purchase. Must include '.exe' extension. Not case-sensitive.
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 1 of Source-File 4 in order to use this function.
|
||||
|
||||
This function allows you to automatically purchase programs. You MUST have a TOR router in order to use this function.
|
||||
The cost of purchasing programs using this function is the same as if you were purchasing them through the Dark Web using the
|
||||
Terminal *buy* command.
|
||||
|
||||
Example::
|
||||
|
||||
purchaseProgram("brutessh.exe");
|
||||
|
||||
This function will return true if the specified program is purchased, and false otherwise.
|
||||
|
||||
getStats
|
||||
--------
|
||||
|
||||
.. js:function:: getStats()
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 1 of Source-File 4 in order to run this function.
|
||||
|
||||
Returns an object with the Player's stats. The object has the following properties::
|
||||
|
||||
{
|
||||
hacking
|
||||
strength
|
||||
defense
|
||||
dexterity
|
||||
agility
|
||||
charisma
|
||||
intelligence
|
||||
}
|
||||
|
||||
Example::
|
||||
|
||||
res = getStats();
|
||||
print('My charisma level is: ' + res.charisma);
|
||||
|
||||
getCharacterInformation
|
||||
-----------------------
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 1 of Source-File 4 in order to run this function.
|
||||
|
||||
Returns an object with various information about your character. The object has the following properties::
|
||||
|
||||
{
|
||||
bitnode: Current BitNode number
|
||||
city: Name of city you are currently in
|
||||
company: Name of company
|
||||
factions: Array of factions you are currently a member of
|
||||
jobTitle: Name of job
|
||||
tor: Boolean indicating whether or not you have a tor router
|
||||
|
||||
// The following is an object with many of the player's multipliers from Augmentations/Source Files
|
||||
mult: {
|
||||
agility: Agility stat
|
||||
agilityExp: Agility exp
|
||||
companyRep: Company reputation
|
||||
crimeMoney: Money earned from crimes
|
||||
crimeSuccess: Crime success chance
|
||||
defense: Defense stat
|
||||
defenseExp: Defense exp
|
||||
dexterity: Dexterity stat
|
||||
dexterityExp: Dexterity exp
|
||||
factionRep: Faction reputation
|
||||
hacking: Hacking stat
|
||||
hackingExp: Hacking exp
|
||||
strength: Strength stat
|
||||
strengthExp: Strength exp
|
||||
workMoney: Money earned from jobs
|
||||
},
|
||||
|
||||
// The following apply only to when the character is performing
|
||||
// some type of working action, such as working for a company/faction
|
||||
timeWorked: Timed worked in ms
|
||||
workHackExpGain: Hacking experience earned so far from work
|
||||
workStrExpGain: Str experience earned so far from work
|
||||
workDefExpGain: Def experience earned so far from work
|
||||
workDexExpGain: Dex experience earned so far from work
|
||||
workAgiExpGain: Agi experience earned so far from work
|
||||
workChaExpGain: Cha experience earned so far from work
|
||||
workRepGain: Reputation earned so far from work, if applicable
|
||||
workMoneyGain: Money earned so far from work, if applicable
|
||||
}
|
||||
|
||||
isBusy
|
||||
------
|
||||
|
||||
.. js:function:: isBusy()
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 1 of Source-File 4 in order to run this function.
|
||||
|
||||
Returns a boolean indicating whether or not the player is currently performing an 'action'. These actions include
|
||||
working for a company/faction, studying at a univeristy, working out at a gym, creating a program, or committing a crime.
|
||||
|
||||
stopAction
|
||||
----------
|
||||
|
||||
.. js:function:: stopAction()
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 1 of Source-File 4 in order to run this function.
|
||||
This function is used to end whatever 'action' the player is currently performing. The player
|
||||
will receive whatever money/experience/etc. he has earned from that action.
|
||||
|
||||
The actions that can be stopped with this function are:
|
||||
|
||||
* Studying at a university
|
||||
* Working for a company/faction
|
||||
* Creating a program
|
||||
* Committing a Crime
|
||||
|
||||
This function will return true if the player's action was ended. It will return false if the player was not
|
||||
performing an action when this function was called.
|
||||
|
||||
upgradeHomeRam
|
||||
--------------
|
||||
|
||||
.. js:function:: upgradeHomeRam()
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 2 of Source-File 4 in order to use this function.
|
||||
|
||||
This function will upgrade amount of RAM on the player's home computer. The cost is the same as if you were to do it manually.
|
||||
|
||||
This function will return true if the player's home computer RAM is successfully upgraded, and false otherwise.
|
||||
|
||||
getUpgradeHomeRamCost
|
||||
---------------------
|
||||
|
||||
.. js:function:: getUpgradeHomeRamCost()
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 2 of Source-File 4 in order to use this function.
|
||||
|
||||
Returns the cost of upgrading the player's home computer RAM.
|
||||
|
||||
workForCompany
|
||||
--------------
|
||||
|
||||
.. js:function:: workForCompany()
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 2 of Source-File 4 in order to use this function.
|
||||
|
||||
This function will automatically set you to start working at the company at which you are employed.
|
||||
If you are already in the middle of some "working" action (such as working for a faction, training at
|
||||
a gym, or creating a program), then running this function will automatically cancel that action and give you your earnings.
|
||||
|
||||
This function will return true if the player starts working, and false otherwise.
|
||||
|
||||
Note that when you are working for a company, you will not actually receive your earnings
|
||||
(reputation, money, experience) until you FINISH the action. This can be an issue if, for example,
|
||||
you only want to work until you get 100,000 company reputation. One small hack to get around this is to
|
||||
continuously restart the action to receive your earnings::
|
||||
|
||||
while (getCompanyRep(COMPANY HERE) < VALUE) {
|
||||
workForCompany();
|
||||
sleep(60000);
|
||||
}
|
||||
|
||||
This way, your company reputation will be updated every minute.
|
||||
|
||||
applyToCompany
|
||||
--------------
|
||||
|
||||
.. js:function:: applyToCompany(companyName, field)
|
||||
|
||||
:param string companyName: Name of company to apply to. CASE-SENSITIVE.
|
||||
:param string field:
|
||||
Field to which you want to apply. Not case-sensitive
|
||||
|
||||
* software
|
||||
* software consultant
|
||||
* it
|
||||
* security engineer
|
||||
* network engineer
|
||||
* business
|
||||
* business consultant
|
||||
* security
|
||||
* agent
|
||||
* employee
|
||||
* part-time employee
|
||||
* waiter
|
||||
* part-time waiter
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 2 of Source-File 4 in order to use this function.
|
||||
|
||||
This function will automatically try to apply to the specified company for a position in the specified
|
||||
field. This function can also be used to apply for promotions by specifying the company and field you
|
||||
are already employed at.
|
||||
|
||||
This function will return true if you successfully get a job/promotion, and false otherwise. Note that
|
||||
if you are trying to use this function to apply for a promotion and you don't get one, it will return false.
|
||||
|
||||
getCompanyRep
|
||||
-------------
|
||||
|
||||
.. js:function:: getCompanyRep(companyName)
|
||||
|
||||
:param string companyName: Name of the company. CASE-SENSITIVE
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 2 of Source-File 4 in order to use this function.
|
||||
|
||||
This function will return the amount of reputation you have at the specified company.
|
||||
If the company passed in as an argument is invalid, -1 will be returned.
|
||||
|
||||
getCompanyFavor
|
||||
---------------
|
||||
|
||||
.. js:function:: getCompanyFavor(companyName)
|
||||
|
||||
:param string companyName: Name of the company. CASE-SENSITIVE
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 2 of Source-File 4 in order to use this function.
|
||||
|
||||
This function will return the amount of favor you have at the specified company.
|
||||
If the company passed in as an argument is invalid, -1 will be returned.
|
||||
|
||||
getCompanyFavorGain
|
||||
-------------------
|
||||
|
||||
.. js:function:: getCompanyFavorGain(companyName)
|
||||
|
||||
:param string companyName: Name of the company. CASE-SENSITIVE
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 2 of Source-File 4 in order to use this function.
|
||||
|
||||
This function will return the amount of favor you will gain for the specified company
|
||||
when you reset by installing Augmentations.
|
||||
|
||||
checkFactionInvitations
|
||||
-----------------------
|
||||
|
||||
.. js:function:: checkFactionInvitations()
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 2 of Source-File 4 in order to use this function.
|
||||
|
||||
Returns an array with the name of all Factions you currently have oustanding invitations from.
|
||||
|
||||
joinFaction
|
||||
-----------
|
||||
|
||||
.. js:function:: joinFaction(name)
|
||||
|
||||
:param string name: Name of faction to join. CASE-SENSITIVE
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 2 of Source-File 4 in order to use this function.
|
||||
|
||||
This function will automatically accept an invitation from a faction and join it.
|
||||
|
||||
workForFaction
|
||||
--------------
|
||||
|
||||
.. js:function:: workForFaction(factionName, workType)
|
||||
|
||||
:param string factionName: Name of faction to work for. CASE-SENSITIVE
|
||||
:param string workType:
|
||||
Type of work to perform for the faction
|
||||
|
||||
* hacking/hacking contracts/hackingcontracts
|
||||
* field/fieldwork/field work
|
||||
* security/securitywork/security work
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 2 of Source-File 4 in order to use this function.
|
||||
|
||||
This function will automatically set you to start working for the specified faction.
|
||||
Obviously, you must be a member of the faction or else this function will fail. If you are already in
|
||||
the middle of some "working" action (such as working for a company, training at a gym, or creating a program),
|
||||
then running this function will automatically cancel that action and give you your earnings.
|
||||
|
||||
This function will return true if you successfully start working for the specified faction, and false otherwise.
|
||||
|
||||
Note that when you are working for a faction, you will not actually receive your earnings (reputation, experience)
|
||||
until you FINISH the action. This can be an issue if, for example, you only want to work until you get 100,000 faction
|
||||
reputation. One small hack to get around this is to continuously restart the action to receive your earnings::
|
||||
|
||||
while (getFactionRep(FACTION NAME) < VALUE) {
|
||||
workForFaction(FACNAME, WORKTYPE);
|
||||
sleep(60000);
|
||||
}
|
||||
|
||||
This way, your faction reputation will be updated every minute.
|
||||
|
||||
getFactionRep
|
||||
-------------
|
||||
|
||||
.. js:function:: getFactionRep(factionName)
|
||||
|
||||
:param string factionName: Name of faction. CASE-SENSITIVE
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 2 of Source-File 4 in order to use this function.
|
||||
|
||||
This function returns the amount of reputation you have for the specified faction.
|
||||
|
||||
getFactionFavor
|
||||
---------------
|
||||
|
||||
.. js:function:: getFactionFavor(factionName)
|
||||
|
||||
:param string factionName: Name of faction. CASE-SENSITIVE
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 2 of Source-File 4 in order to use this function.
|
||||
|
||||
This function returns the amount of favor you have for the specified faction.
|
||||
|
||||
getFactionFavorGain
|
||||
-------------------
|
||||
|
||||
.. js:function:: getFactionFavorGain(factionName)
|
||||
|
||||
:param string factionName: Name of faction. CASE-SENSITIVE
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 2 of Source-File 4 in order to use this function.
|
||||
|
||||
This function returns the amount of favor you will gain for the specified faction when you reset by installing Augmentations.
|
||||
|
||||
donateToFaction
|
||||
---------------
|
||||
|
||||
.. js:function:: donateToFaction(factionName, donateAmt)
|
||||
|
||||
:param string factionName: Name of faction to donate to. CASE-SENSITIVE
|
||||
:param number donateAmt: Amount of money to donate
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 3 of Source-File 4 in order to use this function.
|
||||
|
||||
Attempts to donate money to the specified faction in exchange for reputation.
|
||||
Returns true if you successfully donate the money, and false otherwise.
|
||||
|
||||
createProgram
|
||||
-------------
|
||||
|
||||
.. js:function:: createProgram(programName)
|
||||
|
||||
:param string programName: Name of program to create. Not case-sensitive
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 3 of Source-File 4 in order to use this function.
|
||||
|
||||
This function will automatically set you to start working on creating the specified program. If you are
|
||||
already in the middle of some "working" action (such as working for a company, training at a gym, or taking a course),
|
||||
then running this function will automatically cancel that action and give you your earnings.
|
||||
|
||||
Example:
|
||||
|
||||
createProgram("relaysmtp.exe");
|
||||
|
||||
Note that creating a program using this function has the same hacking level requirements as it normally would. These level requirements are:
|
||||
|
||||
* BruteSSH.exe: 50
|
||||
* FTPCrack.exe: 100
|
||||
* relaySMTP.exe: 250
|
||||
* HTTPWorm.exe: 500
|
||||
* SQLInject.exe: 750
|
||||
* DeepscanV1.exe: 75
|
||||
* DeepscanV2.exe: 400
|
||||
* ServerProfiler.exe: 75
|
||||
* AutoLink.exe: 25
|
||||
|
||||
This function returns true if you successfully start working on the specified program, and false otherwise.
|
||||
|
||||
commitCrime
|
||||
-----------
|
||||
|
||||
.. js:function:: commitCrime(crime)
|
||||
|
||||
:param string crime:
|
||||
Name of crime to attempt. Not case-sensitive. This argument is fairly lenient in terms of what inputs it accepts.
|
||||
Here is a list of valid inputs for all of the crimes:
|
||||
|
||||
* shoplift
|
||||
* rob store
|
||||
* mug
|
||||
* larceny
|
||||
* deal drugs
|
||||
* bond forgery
|
||||
* traffick arms
|
||||
* homicide
|
||||
* grand theft auto
|
||||
* kidnap
|
||||
* assassinate
|
||||
* heist
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 3 of Source-File 4 in order to use this function.
|
||||
|
||||
This function is used to automatically attempt to commit crimes. If you are already in the middle of some 'working' action
|
||||
(such as working for a company or training at a gym), then running this function will automatically cancel that action and give you your earnings.
|
||||
|
||||
This function returns the number of seconds it takes to attempt the specified crime (e.g It takes 60 seconds to attempt the 'Rob Store' crime,
|
||||
so running *commitCrime('rob store')* will return 60).
|
||||
|
||||
Warning: I do not recommend using the time returned from this function to try and schedule your crime attempts.
|
||||
Instead, I would use the isBusy() Singularity function to check whether you have finished attempting a crime.
|
||||
This is because although the game sets a certain crime to be X amount of seconds, there is no guarantee that your
|
||||
browser will follow that time limit.
|
||||
|
||||
getCrimeChance
|
||||
--------------
|
||||
|
||||
.. js:function:: getCrimeChance(crime)
|
||||
|
||||
:param string crime:
|
||||
Name of crime. Not case-sensitive. This argument is fairlyn lenient in terms of what inputs it accepts.
|
||||
Check the documentation for the *commitCrime()* function for a list of example inputs.
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 3 of Source-File 4 in order to use this function.
|
||||
|
||||
This function returns your chance of success at commiting the specified crime. The chance is returned as a decimal (i.e. 60% would be returned as 0.6).
|
||||
|
||||
getOwnedAugmentations
|
||||
---------------------
|
||||
|
||||
.. js:function:: getOwnedAugmentations(purchased=false)
|
||||
|
||||
:param boolean purchase:
|
||||
Specifies whether the returned array should include Augmentations you have purchased but not yet installed.
|
||||
By default, this argument is false which means that the return value will NOT have the purchased Augmentations.
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 3 of Source-File 4 in order to use this function.
|
||||
|
||||
This function returns an array containing the names (as strings) of all Augmentations you have.
|
||||
|
||||
getOwnedSourceFiles
|
||||
-------------------
|
||||
|
||||
.. js:function:: getOwnedSourceFiles()
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 3 of Source-File 4 in order to use this function.
|
||||
|
||||
Returns an array of source files
|
||||
[{n: 1, lvl: 3}, {n: 4, lvl: 3}]
|
||||
|
||||
|
||||
getAugmentationsFromFaction
|
||||
---------------------------
|
||||
|
||||
.. js:function:: getAugmentationsFromFaction(facName)
|
||||
|
||||
:param string facName: Name of faction. CASE-SENSITIVE
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 3 of Source-File 4 in order to use this function.
|
||||
|
||||
Returns an array containing the names (as strings) of all Augmentations that are available from the specified faction.
|
||||
|
||||
getAugmentationCost
|
||||
-------------------
|
||||
|
||||
.. js:function:: getAugmentationCost(augName)
|
||||
|
||||
:param string augName: Name of Augmentation. CASE-SENSITIVE
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 3 of Source-File 4 in order to use this function.
|
||||
|
||||
This function returns an array with two elements that gives the cost for the specified Augmentation.
|
||||
The first element in the returned array is the reputation requirement of the Augmentation, and the second element is the money cost.
|
||||
|
||||
If an invalid Augmentation name is passed in for the *augName* argument, this function will return the array [-1, -1].
|
||||
|
||||
purchaseAugmentation
|
||||
--------------------
|
||||
|
||||
.. js:function:: purchaseAugmentation(factionName, augName)
|
||||
|
||||
:param string factionName: Name of faction to purchase Augmentation from. CASE-SENSITIVE
|
||||
:param string augName: Name of Augmentation to purchase. CASE-SENSITIVE
|
||||
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 3 of Source-File 4 in order to use this function.
|
||||
|
||||
This function will try to purchase the specified Augmentation through the given Faction.
|
||||
|
||||
This function will return true if the Augmentation is successfully purchased, and false otherwise.
|
||||
|
||||
installAugmentations
|
||||
--------------------
|
||||
|
||||
.. js:function:: installAugmentations(cbScript)
|
||||
|
||||
:param string cbScript:
|
||||
Optional callback script. This is a script that will automatically be run after Augmentations are installed (after the reset).
|
||||
This script will be run with no arguments and 1 thread. It must be located on your home computer.
|
||||
|
||||
If you are not in BitNode-4, then you must have Level 3 of Source-File 4 in order to use this function.
|
||||
|
||||
This function will automatically install your Augmentations, resetting the game as usual.
|
||||
|
||||
It will return true if successful, and false otherwise.
|
||||
Reference in New Issue
Block a user