2017-10-12 22:10:34 +02:00
var sprintf = require ( 'sprintf-js' ) . sprintf ,
vsprintf = require ( 'sprintf-js' ) . vsprintf
2018-06-26 18:34:11 +02:00
import { updateActiveScriptsItems } from "./ActiveScriptsUI" ;
2017-08-30 19:44:29 +02:00
import { Augmentations , Augmentation ,
2017-09-08 21:16:48 +02:00
augmentationExists , installAugmentations ,
2018-06-26 18:34:11 +02:00
AugmentationNames } from "./Augmentations" ;
2018-08-12 03:05:32 +02:00
import { BitNodeMultipliers } from "./BitNodeMultipliers" ;
2018-06-26 18:34:11 +02:00
import { determineCrimeSuccess , findCrime } from "./Crimes" ;
import { Bladeburner } from "./Bladeburner" ;
2017-08-30 19:44:29 +02:00
import { Companies , Company , CompanyPosition ,
2018-06-26 18:34:11 +02:00
CompanyPositions , companyExists } from "./Company" ;
import { CONSTANTS } from "./Constants" ;
import { Programs } from "./CreateProgram" ;
import { DarkWebItems } from "./DarkWeb" ;
2018-08-30 19:00:38 +02:00
import { calculateHackingChance ,
calculateHackingExpGain ,
calculatePercentMoneyHacked ,
calculateHackingTime ,
calculateGrowTime ,
calculateWeakenTime } from "./Hacking" ;
2018-06-26 18:34:11 +02:00
import { AllGangs } from "./Gang" ;
2017-08-30 19:44:29 +02:00
import { Factions , Faction , joinFaction ,
2018-06-26 18:34:11 +02:00
factionExists , purchaseAugmentation } from "./Faction" ;
import { getCostOfNextHacknetNode , purchaseHacknet } from "./HacknetNode" ;
2018-07-21 06:22:04 +02:00
import { Locations } from "./Locations" ;
2018-06-26 18:34:11 +02:00
import { Message , Messages } from "./Message" ;
import { inMission } from "./Missions" ;
import { Player } from "./Player" ;
2018-05-06 00:13:35 +02:00
import { Script , findRunningScript , RunningScript ,
2018-06-26 18:34:11 +02:00
isScriptFilename } from "./Script" ;
2017-08-30 19:44:29 +02:00
import { Server , getServer , AddToAllServers ,
AllServers , processSingleServerGrowth ,
2018-06-26 18:34:11 +02:00
GetServerByHostname } from "./Server" ;
import { Settings } from "./Settings" ;
import { SpecialServerIps } from "./SpecialServerIps" ;
2018-09-06 18:07:59 +02:00
import { Stock } from "./Stock" ;
2018-10-30 22:02:16 +01:00
import { StockMarket , StockSymbols , SymbolToStockMap ,
initStockMarket , initSymbolToStockMap , buyStock ,
sellStock , updateStockPlayerPosition ,
2018-09-06 18:07:59 +02:00
shortStock , sellShort , OrderTypes ,
2018-06-26 18:34:11 +02:00
PositionTypes , placeOrder , cancelOrder } from "./StockMarket" ;
2018-07-18 20:34:18 +02:00
import { post } from "./ui/postToTerminal" ;
2018-06-14 15:11:28 +02:00
import { TextFile , getTextFile , createTextFile } from "./TextFile" ;
2017-08-30 19:44:29 +02:00
2018-07-20 06:06:59 +02:00
import { unknownBladeburnerActionErrorMessage ,
unknownBladeburnerExceptionMessage ,
2018-10-23 20:55:42 +02:00
checkBladeburnerAccess } from "./NetscriptBladeburner" ;
import * as nsGang from "./NetscriptGang" ;
2017-08-30 19:44:29 +02:00
import { WorkerScript , workerScripts ,
2018-06-26 18:34:11 +02:00
killWorkerScript , NetscriptPorts } from "./NetscriptWorker" ;
2018-08-30 19:00:38 +02:00
import { makeRuntimeRejectMsg , netscriptDelay ,
runScriptFromScript } from "./NetscriptEvaluator" ;
2018-06-26 18:34:11 +02:00
import { NetscriptPort } from "./NetscriptPort" ;
2017-08-30 19:44:29 +02:00
2018-05-30 19:41:17 +02:00
import Decimal from "decimal.js" ;
2018-07-20 03:51:18 +02:00
import { Page , routing } from "./ui/navigationTracking" ;
2018-06-26 18:34:11 +02:00
import { dialogBoxCreate } from "../utils/DialogBox" ;
2018-07-05 20:20:21 +02:00
import { isPowerOfTwo } from "../utils/helpers/isPowerOfTwo" ;
2018-07-05 20:12:20 +02:00
import { arrayToString } from "../utils/helpers/arrayToString" ;
2018-06-26 18:34:11 +02:00
import { createRandomIp } from "../utils/IPAddress" ;
2018-07-04 06:33:55 +02:00
import { formatNumber , isHTML } from "../utils/StringHelperFunctions" ;
import { isString } from "../utils/helpers/isString" ;
2017-11-01 23:56:30 +01:00
import { yesNoBoxClose , yesNoBoxGetYesButton ,
yesNoBoxGetNoButton , yesNoBoxCreate ,
2018-06-26 18:34:11 +02:00
yesNoBoxOpen } from "../utils/YesNoBox" ;
2017-08-21 18:59:06 +02:00
2018-05-23 02:09:04 +02:00
var hasCorporationSF = false , //Source-File 3
hasSingularitySF = false , //Source-File 4
hasAISF = false , //Source-File 5
hasBladeburnerSF = false , //Source-File 6
hasBladeburner2079SF = false , //Source-File 7
hasWallStreetSF = false , //Source-File 8
hasBn11SF = false ; //Source-File 11
2018-05-02 19:38:11 +02:00
2018-05-23 02:09:04 +02:00
var singularitySFLvl = 1 , wallStreetSFLvl = 1 ;
2018-05-02 19:38:11 +02:00
2018-05-06 05:59:55 +02:00
var possibleLogs = {
ALL : true ,
scan : true ,
hack : true ,
sleep : true ,
disableLog : true ,
enableLog : true ,
grow : true ,
weaken : true ,
nuke : true ,
brutessh : true ,
ftpcrack : true ,
relaysmtp : true ,
httpworm : true ,
sqlinject : true ,
2018-06-14 21:51:06 +02:00
run : true ,
exec : true ,
2018-05-06 05:59:55 +02:00
spawn : true ,
kill : true ,
killall : true ,
scp : true ,
getHackingLevel : true ,
getServerMoneyAvailable : true ,
getServerSecurityLevel : true ,
getServerBaseSecurityLevel : true ,
getServerMinSecurityLevel : true ,
getServerRequiredHackingLevel : true ,
getServerMaxMoney : true ,
getServerGrowth : true ,
getServerNumPortsRequired : true ,
getServerRam : true ,
2018-11-01 19:18:32 +01:00
2018-10-29 17:08:41 +01:00
// TIX API
2018-05-06 05:59:55 +02:00
buyStock : true ,
sellStock : true ,
2018-10-29 17:08:41 +01:00
shortStock : true ,
sellShort : true ,
2018-11-01 19:18:32 +01:00
purchase4SMarketData : true ,
purchase4SMarketDataTixApi : true ,
2018-10-29 17:08:41 +01:00
// Singularity Functions
2018-05-06 05:59:55 +02:00
purchaseServer : true ,
deleteServer : true ,
universityCourse : true ,
gymWorkout : true ,
travelToCity : true ,
purchaseTor : true ,
purchaseProgram : true ,
stopAction : true ,
upgradeHomeRam : true ,
workForCompany : true ,
applyToCompany : true ,
joinFaction : true ,
workForFaction : true ,
2018-09-11 20:56:23 +02:00
donateToFaction : true ,
2018-05-06 05:59:55 +02:00
createProgram : true ,
commitCrime : true ,
2018-10-29 17:08:41 +01:00
// Bladeburner API
2018-06-08 17:51:48 +02:00
startAction : true ,
upgradeSkill : true ,
setTeamSize : true ,
joinBladeburnerFaction : true ,
2018-10-29 17:08:41 +01:00
// Gang API
recruitMember : true ,
setMemberTask : true ,
purchaseEquipment : true ,
setTerritoryWarfare : true ,
2018-05-06 05:59:55 +02:00
}
2018-01-20 05:47:57 +01:00
2017-10-10 06:56:48 +02:00
//Used to check and set flags for every Source File, despite the name of the function
2017-08-30 19:44:29 +02:00
function initSingularitySFFlags ( ) {
for ( var i = 0 ; i < Player . sourceFiles . length ; ++ i ) {
2018-05-23 02:09:04 +02:00
if ( Player . sourceFiles [ i ] . n === 3 ) { hasCorporationSF = true ; }
2017-08-30 19:44:29 +02:00
if ( Player . sourceFiles [ i ] . n === 4 ) {
hasSingularitySF = true ;
singularitySFLvl = Player . sourceFiles [ i ] . lvl ;
}
2018-05-23 02:09:04 +02:00
if ( Player . sourceFiles [ i ] . n === 5 ) { hasAISF = true ; }
if ( Player . sourceFiles [ i ] . n === 6 ) { hasBladeburnerSF = true ; }
if ( Player . sourceFiles [ i ] . n === 7 ) { hasBladeburner2079SF = true ; }
2017-10-20 23:59:54 +02:00
if ( Player . sourceFiles [ i ] . n === 8 ) {
hasWallStreetSF = true ;
wallStreetSFLvl = Player . sourceFiles [ i ] . lvl ;
}
2018-05-23 02:09:04 +02:00
if ( Player . sourceFiles [ i ] . n === 11 ) { hasBn11SF = true ; }
2017-08-30 19:44:29 +02:00
}
}
2017-06-28 11:47:42 +02:00
function NetscriptFunctions ( workerScript ) {
2018-06-06 18:02:21 +02:00
var updateDynamicRam = function ( fnName , ramCost ) {
if ( workerScript . dynamicLoadedFns [ fnName ] ) { return ; }
workerScript . dynamicLoadedFns [ fnName ] = true ;
2018-10-26 22:51:45 +02:00
const threads = workerScript . scriptRef . threads ;
if ( typeof threads !== 'number' ) {
console . warn ( ` WorkerScript detected NaN for threadcount for ${ workerScript . name } on ${ workerScript . serverIp } ` ) ;
threads = 1 ;
}
workerScript . dynamicRamUsage += ( ramCost * threads ) ;
2018-06-06 18:02:21 +02:00
if ( workerScript . dynamicRamUsage > 1.01 * workerScript . ramUsage ) {
throw makeRuntimeRejectMsg ( workerScript ,
2018-06-25 02:13:50 +02:00
"Dynamic RAM usage calculated to be greater than initial RAM usage on fn: " + fnName +
". This is probably because you somehow circumvented the static RAM " +
2018-07-10 07:11:18 +02:00
"calculation.<br><br>Please don't do that :(<br><br>" +
"Dynamic RAM Usage: " + workerScript . dynamicRamUsage + "<br>" +
"Static RAM Usage: " + workerScript . ramUsage ) ;
2018-06-06 18:02:21 +02:00
}
} ;
var updateStaticRam = function ( fnName , ramCost ) {
if ( workerScript . loadedFns [ fnName ] ) {
return 0 ;
} else {
workerScript . loadedFns [ fnName ] = true ;
return ramCost ;
}
} ;
2018-09-23 02:25:48 +02:00
/ * *
* Gets the Server for a specific hostname / ip , throwing an error
* if the server doesn ' t exist .
* @ param { string } Hostname or IP of the server
* @ returns { Server } The specified Server
* /
var safeGetServer = function ( ip , callingFnName = "" ) {
var server = getServer ( ip ) ;
if ( server == null ) {
throw makeRuntimeRejectMsg ( workerScript , ` Invalid IP or hostname passed into ${ callingFnName } () function ` ) ;
}
return server ;
}
// Utility function to get Hacknet Node object
2018-07-15 02:25:50 +02:00
var getHacknetNode = function ( i ) {
if ( isNaN ( i ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Invalid index specified for Hacknet Node: " + i ) ;
}
if ( i < 0 || i >= Player . hacknetNodes . length ) {
throw makeRuntimeRejectMsg ( workerScript , "Index specified for Hacknet Node is out-of-bounds: " + i ) ;
}
return Player . hacknetNodes [ i ] ;
2018-06-20 18:43:05 +02:00
} ;
2018-09-23 02:25:48 +02:00
var getCodingContract = function ( fn , ip ) {
var server = safeGetServer ( ip , "getCodingContract" ) ;
return server . getContract ( fn ) ;
}
2018-06-20 18:43:05 +02:00
/ * *
* @ param { number } ram The amount of server RAM to calculate cost of .
* @ exception { Error } If the value passed in is not numeric , out of range , or too large of a value .
2018-08-24 22:44:48 +02:00
* @ returns { number } The cost of
2018-06-20 18:43:05 +02:00
* /
const getPurchaseServerRamCostGuard = ( ram ) => {
const guardedRam = Math . round ( ram ) ;
2018-08-05 09:37:28 +02:00
if ( isNaN ( guardedRam ) || ! isPowerOfTwo ( guardedRam ) ) {
2018-06-20 18:43:05 +02:00
throw Error ( "failed due to invalid ram argument. Must be numeric and a power of 2" ) ;
}
if ( guardedRam > CONSTANTS . PurchasedServerMaxRam ) {
throw Error ( "failed because specified RAM was too high. Maximum RAM on a purchased server is " + CONSTANTS . PurchasedServerMaxRam + "GB" ) ;
}
return guardedRam * CONSTANTS . BaseCostFor1GBOfRamServer ;
} ;
2018-07-15 02:25:50 +02:00
2017-06-28 11:47:42 +02:00
return {
2018-07-15 02:25:50 +02:00
hacknet : {
numNodes : function ( ) {
return Player . hacknetNodes . length ;
} ,
purchaseNode : function ( ) {
return purchaseHacknet ( ) ;
} ,
getPurchaseNodeCost : function ( ) {
return getCostOfNextHacknetNode ( ) ;
} ,
getNodeStats : function ( i ) {
var node = getHacknetNode ( i ) ;
return {
name : node . name ,
level : node . level ,
ram : node . ram ,
cores : node . cores ,
production : node . moneyGainRatePerSecond ,
timeOnline : node . onlineTimeSeconds ,
totalProduction : node . totalMoneyGenerated ,
} ;
} ,
upgradeLevel : function ( i , n ) {
var node = getHacknetNode ( i ) ;
return node . purchaseLevelUpgrade ( n ) ;
} ,
upgradeRam : function ( i , n ) {
var node = getHacknetNode ( i ) ;
return node . purchaseRamUpgrade ( n ) ;
} ,
upgradeCore : function ( i , n ) {
var node = getHacknetNode ( i ) ;
return node . purchaseCoreUpgrade ( n ) ;
} ,
getLevelUpgradeCost : function ( i , n ) {
var node = getHacknetNode ( i ) ;
return node . calculateLevelUpgradeCost ( n ) ;
} ,
getRamUpgradeCost : function ( i , n ) {
var node = getHacknetNode ( i ) ;
return node . calculateRamUpgradeCost ( n ) ;
} ,
getCoreUpgradeCost : function ( i , n ) {
var node = getHacknetNode ( i ) ;
return node . calculateCoreUpgradeCost ( n ) ;
}
2018-07-09 01:53:24 +02:00
} ,
2017-10-12 22:10:34 +02:00
sprintf : sprintf ,
vsprintf : vsprintf ,
2017-09-19 20:38:03 +02:00
scan : function ( ip = workerScript . serverIp , hostnames = true ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "scan" , CONSTANTS . ScriptScanRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "scan" , CONSTANTS . ScriptScanRamCost ) ;
2017-06-28 11:47:42 +02:00
var server = getServer ( ip ) ;
if ( server == null ) {
throw makeRuntimeRejectMsg ( workerScript , 'Invalid IP or hostname passed into scan() command' ) ;
}
var out = [ ] ;
for ( var i = 0 ; i < server . serversOnNetwork . length ; i ++ ) {
2017-09-19 20:38:03 +02:00
var entry ;
if ( hostnames ) {
entry = server . getServerOnNetwork ( i ) . hostname ;
} else {
entry = server . getServerOnNetwork ( i ) . ip ;
}
2017-06-28 11:47:42 +02:00
if ( entry == null ) {
continue ;
2017-06-11 08:52:52 +02:00
}
2017-06-28 11:47:42 +02:00
out . push ( entry ) ;
}
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . scan == null ) {
workerScript . scriptRef . log ( 'scan() returned ' + server . serversOnNetwork . length + ' connections for ' + server . hostname ) ;
}
2017-06-28 11:47:42 +02:00
return out ;
} ,
hack : function ( ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "hack" , CONSTANTS . ScriptHackRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "hack" , CONSTANTS . ScriptHackRamCost ) ;
2017-06-28 11:47:42 +02:00
if ( ip === undefined ) {
throw makeRuntimeRejectMsg ( workerScript , "Hack() call has incorrect number of arguments. Takes 1 argument" ) ;
}
var threads = workerScript . scriptRef . threads ;
if ( isNaN ( threads ) || threads < 1 ) { threads = 1 ; }
var server = getServer ( ip ) ;
if ( server == null ) {
2017-07-13 18:54:29 +02:00
workerScript . scriptRef . log ( "hack() error. Invalid IP or hostname passed in: " + ip + ". Stopping..." ) ;
throw makeRuntimeRejectMsg ( workerScript , "hack() error. Invalid IP or hostname passed in: " + ip + ". Stopping..." ) ;
2017-06-05 06:48:37 +02:00
}
2017-07-25 03:06:40 +02:00
//Calculate the hacking time
2018-08-30 19:00:38 +02:00
var hackingTime = calculateHackingTime ( server ) ; //This is in seconds
2017-07-25 03:06:40 +02:00
2017-06-28 11:47:42 +02:00
//No root access or skill level too low
if ( server . hasAdminRights == false ) {
2017-07-13 18:54:29 +02:00
workerScript . scriptRef . log ( "Cannot hack this server (" + server . hostname + ") because user does not have root access" ) ;
throw makeRuntimeRejectMsg ( workerScript , "Cannot hack this server (" + server . hostname + ") because user does not have root access" ) ;
2017-06-28 11:47:42 +02:00
}
2017-07-25 03:06:40 +02:00
2017-06-28 11:47:42 +02:00
if ( server . requiredHackingSkill > Player . hacking _skill ) {
2017-07-13 18:54:29 +02:00
workerScript . scriptRef . log ( "Cannot hack this server (" + server . hostname + ") because user's hacking skill is not high enough" ) ;
throw makeRuntimeRejectMsg ( workerScript , "Cannot hack this server (" + server . hostname + ") because user's hacking skill is not high enough" ) ;
2017-06-28 11:47:42 +02:00
}
2017-07-25 03:06:40 +02:00
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . hack == null ) {
workerScript . scriptRef . log ( "Attempting to hack " + ip + " in " + hackingTime . toFixed ( 3 ) + " seconds (t=" + threads + ")" ) ;
}
2018-08-30 19:00:38 +02:00
return netscriptDelay ( hackingTime * 1000 , workerScript ) . then ( function ( ) {
2017-06-28 11:47:42 +02:00
if ( workerScript . env . stopFlag ) { return Promise . reject ( workerScript ) ; }
2018-08-30 19:00:38 +02:00
var hackChance = calculateHackingChance ( server ) ;
2017-06-28 11:47:42 +02:00
var rand = Math . random ( ) ;
2018-08-30 19:00:38 +02:00
var expGainedOnSuccess = calculateHackingExpGain ( server ) * threads ;
2017-06-28 11:47:42 +02:00
var expGainedOnFailure = ( expGainedOnSuccess / 4 ) ;
2018-05-23 02:09:04 +02:00
if ( rand < hackChance ) { //Success!
2018-08-30 19:00:38 +02:00
const percentHacked = calculatePercentMoneyHacked ( server ) ;
2018-07-25 22:58:36 +02:00
let maxThreadNeeded = Math . ceil ( 1 / percentHacked * ( server . moneyAvailable / server . moneyMax ) ) ;
if ( isNaN ( maxThreadNeeded ) ) {
2018-07-28 02:00:57 +02:00
//Server has a 'max money' of 0 (probably).
//We'll set this to an arbitrarily large value
maxThreadNeeded = 1e6 ;
2018-07-25 22:58:36 +02:00
}
2018-07-13 03:16:24 +02:00
let moneyGained = Math . floor ( server . moneyAvailable * percentHacked ) * threads ;
2017-07-25 03:06:40 +02:00
2017-06-28 11:47:42 +02:00
//Over-the-top safety checks
if ( moneyGained <= 0 ) {
moneyGained = 0 ;
expGainedOnSuccess = expGainedOnFailure ;
2017-06-15 03:19:52 +02:00
}
2017-06-28 11:47:42 +02:00
if ( moneyGained > server . moneyAvailable ) { moneyGained = server . moneyAvailable ; }
server . moneyAvailable -= moneyGained ;
if ( server . moneyAvailable < 0 ) { server . moneyAvailable = 0 ; }
2017-07-25 03:06:40 +02:00
2017-06-28 11:47:42 +02:00
Player . gainMoney ( moneyGained ) ;
workerScript . scriptRef . onlineMoneyMade += moneyGained ;
2017-09-26 04:44:33 +02:00
Player . scriptProdSinceLastAug += moneyGained ;
2017-06-28 11:47:42 +02:00
workerScript . scriptRef . recordHack ( server . ip , moneyGained , threads ) ;
Player . gainHackingExp ( expGainedOnSuccess ) ;
workerScript . scriptRef . onlineExpGained += expGainedOnSuccess ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . hack == null ) {
workerScript . scriptRef . log ( "Script SUCCESSFULLY hacked " + server . hostname + " for $" + formatNumber ( moneyGained , 2 ) + " and " + formatNumber ( expGainedOnSuccess , 4 ) + " exp (t=" + threads + ")" ) ;
}
2018-07-13 03:16:24 +02:00
server . fortify ( CONSTANTS . ServerFortifyAmount * Math . min ( threads , maxThreadNeeded ) ) ;
2018-02-24 23:55:06 +01:00
return Promise . resolve ( moneyGained ) ;
2017-07-25 03:06:40 +02:00
} else {
2018-02-24 23:55:06 +01:00
//Player only gains 25% exp for failure?
2017-06-28 11:47:42 +02:00
Player . gainHackingExp ( expGainedOnFailure ) ;
workerScript . scriptRef . onlineExpGained += expGainedOnFailure ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . hack == null ) {
workerScript . scriptRef . log ( "Script FAILED to hack " + server . hostname + ". Gained " + formatNumber ( expGainedOnFailure , 4 ) + " exp (t=" + threads + ")" ) ;
}
return Promise . resolve ( 0 ) ;
2017-06-15 03:19:52 +02:00
}
2017-06-28 11:47:42 +02:00
} ) ;
} ,
2018-02-24 23:55:06 +01:00
sleep : function ( time ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) { return 0 ; }
2017-06-28 11:47:42 +02:00
if ( time === undefined ) {
throw makeRuntimeRejectMsg ( workerScript , "sleep() call has incorrect number of arguments. Takes 1 argument" ) ;
2017-06-15 03:19:52 +02:00
}
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . sleep == null ) {
2017-07-22 00:54:55 +02:00
workerScript . scriptRef . log ( "Sleeping for " + time + " milliseconds" ) ;
}
2017-09-15 16:06:59 +02:00
return netscriptDelay ( time , workerScript ) . then ( function ( ) {
2017-06-28 11:47:42 +02:00
return Promise . resolve ( true ) ;
} ) ;
} ,
grow : function ( ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "grow" , CONSTANTS . ScriptGrowRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "grow" , CONSTANTS . ScriptGrowRamCost ) ;
2017-06-28 11:47:42 +02:00
var threads = workerScript . scriptRef . threads ;
if ( isNaN ( threads ) || threads < 1 ) { threads = 1 ; }
if ( ip === undefined ) {
throw makeRuntimeRejectMsg ( workerScript , "grow() call has incorrect number of arguments. Takes 1 argument" ) ;
}
var server = getServer ( ip ) ;
if ( server == null ) {
2017-07-13 18:54:29 +02:00
workerScript . scriptRef . log ( "Cannot grow(). Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "Cannot grow(). Invalid IP or hostname passed in: " + ip ) ;
2017-06-28 11:47:42 +02:00
}
2017-07-25 03:06:40 +02:00
2017-06-28 11:47:42 +02:00
//No root access or skill level too low
if ( server . hasAdminRights == false ) {
2017-07-13 18:54:29 +02:00
workerScript . scriptRef . log ( "Cannot grow this server (" + server . hostname + ") because user does not have root access" ) ;
throw makeRuntimeRejectMsg ( workerScript , "Cannot grow this server (" + server . hostname + ") because user does not have root access" ) ;
2017-06-28 11:47:42 +02:00
}
2017-07-25 03:06:40 +02:00
2018-08-30 19:00:38 +02:00
var growTime = calculateGrowTime ( server ) ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . grow == null ) {
2018-08-30 19:00:38 +02:00
workerScript . scriptRef . log ( "Executing grow() on server " + server . hostname + " in " + formatNumber ( growTime , 3 ) + " seconds (t=" + threads + ")" ) ;
2018-02-24 23:55:06 +01:00
}
2018-08-30 19:00:38 +02:00
return netscriptDelay ( growTime * 1000 , workerScript ) . then ( function ( ) {
2017-06-28 11:47:42 +02:00
if ( workerScript . env . stopFlag ) { return Promise . reject ( workerScript ) ; }
2018-09-28 04:09:02 +02:00
const moneyBefore = server . moneyAvailable <= 0 ? 1 : server . moneyAvailable ;
2017-06-28 11:47:42 +02:00
server . moneyAvailable += ( 1 * threads ) ; //It can be grown even if it has no money
var growthPercentage = processSingleServerGrowth ( server , 450 * threads ) ;
2018-06-09 08:58:33 +02:00
const moneyAfter = server . moneyAvailable ;
2017-06-28 11:47:42 +02:00
workerScript . scriptRef . recordGrow ( server . ip , threads ) ;
2018-08-30 19:00:38 +02:00
var expGain = calculateHackingExpGain ( server ) * threads ;
2017-06-28 11:47:42 +02:00
if ( growthPercentage == 1 ) {
expGain = 0 ;
2017-06-11 22:28:20 +02:00
}
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . grow == null ) {
workerScript . scriptRef . log ( "Available money on " + server . hostname + " grown by " +
2018-06-09 08:58:33 +02:00
formatNumber ( ( moneyAfter / moneyBefore ) * 100 - 100 , 6 ) + "%. Gained " +
2018-02-24 23:55:06 +01:00
formatNumber ( expGain , 4 ) + " hacking exp (t=" + threads + ")" ) ;
}
2017-06-28 11:47:42 +02:00
workerScript . scriptRef . onlineExpGained += expGain ;
2017-07-25 03:06:40 +02:00
Player . gainHackingExp ( expGain ) ;
2018-06-14 21:51:06 +02:00
return Promise . resolve ( moneyAfter / moneyBefore ) ;
2017-07-25 03:06:40 +02:00
} ) ;
2017-06-28 11:47:42 +02:00
} ,
weaken : function ( ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "weaken" , CONSTANTS . ScriptWeakenRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "weaken" , CONSTANTS . ScriptWeakenRamCost ) ;
2017-06-28 11:47:42 +02:00
var threads = workerScript . scriptRef . threads ;
if ( isNaN ( threads ) || threads < 1 ) { threads = 1 ; }
if ( ip === undefined ) {
throw makeRuntimeRejectMsg ( workerScript , "weaken() call has incorrect number of arguments. Takes 1 argument" ) ;
}
var server = getServer ( ip ) ;
if ( server == null ) {
2017-07-13 18:54:29 +02:00
workerScript . scriptRef . log ( "Cannot weaken(). Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "Cannot weaken(). Invalid IP or hostname passed in: " + ip ) ;
2017-06-28 11:47:42 +02:00
}
2017-07-25 03:06:40 +02:00
2017-06-28 11:47:42 +02:00
//No root access or skill level too low
if ( server . hasAdminRights == false ) {
2017-07-13 18:54:29 +02:00
workerScript . scriptRef . log ( "Cannot weaken this server (" + server . hostname + ") because user does not have root access" ) ;
throw makeRuntimeRejectMsg ( workerScript , "Cannot weaken this server (" + server . hostname + ") because user does not have root access" ) ;
2017-06-28 11:47:42 +02:00
}
2017-07-25 03:06:40 +02:00
2018-08-30 19:00:38 +02:00
var weakenTime = calculateWeakenTime ( server ) ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . weaken == null ) {
workerScript . scriptRef . log ( "Executing weaken() on server " + server . hostname + " in " +
2018-08-30 19:00:38 +02:00
formatNumber ( weakenTime , 3 ) + " seconds (t=" + threads + ")" ) ;
2018-02-24 23:55:06 +01:00
}
2018-08-30 19:00:38 +02:00
return netscriptDelay ( weakenTime * 1000 , workerScript ) . then ( function ( ) {
2017-06-28 11:47:42 +02:00
if ( workerScript . env . stopFlag ) { return Promise . reject ( workerScript ) ; }
server . weaken ( CONSTANTS . ServerWeakenAmount * threads ) ;
workerScript . scriptRef . recordWeaken ( server . ip , threads ) ;
2018-08-30 19:00:38 +02:00
var expGain = calculateHackingExpGain ( server ) * threads ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . weaken == null ) {
workerScript . scriptRef . log ( "Server security level on " + server . hostname + " weakened to " + server . hackDifficulty +
". Gained " + formatNumber ( expGain , 4 ) + " hacking exp (t=" + threads + ")" ) ;
}
2017-06-28 11:47:42 +02:00
workerScript . scriptRef . onlineExpGained += expGain ;
2017-07-25 03:06:40 +02:00
Player . gainHackingExp ( expGain ) ;
2017-06-28 11:47:42 +02:00
return Promise . resolve ( CONSTANTS . ServerWeakenAmount * threads ) ;
2017-07-25 03:06:40 +02:00
} ) ;
2017-06-28 11:47:42 +02:00
} ,
print : function ( args ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) { return 0 ; }
2017-06-28 11:47:42 +02:00
if ( args === undefined ) {
throw makeRuntimeRejectMsg ( workerScript , "print() call has incorrect number of arguments. Takes 1 argument" ) ;
}
workerScript . scriptRef . log ( args . toString ( ) ) ;
} ,
2017-09-01 16:12:40 +02:00
tprint : function ( args ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) { return 0 ; }
2017-10-26 00:05:12 +02:00
if ( args === undefined || args == null ) {
2017-09-01 16:12:40 +02:00
throw makeRuntimeRejectMsg ( workerScript , "tprint() call has incorrect number of arguments. Takes 1 argument" ) ;
}
2017-09-15 16:06:59 +02:00
var x = args . toString ( ) ;
2017-09-01 16:12:40 +02:00
post ( workerScript . scriptRef . filename + ": " + args . toString ( ) ) ;
} ,
2017-07-22 00:54:55 +02:00
clearLog : function ( ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) { return 0 ; }
2017-07-22 00:54:55 +02:00
workerScript . scriptRef . clearLog ( ) ;
} ,
2018-02-24 23:55:06 +01:00
disableLog : function ( fn ) {
if ( workerScript . checkingRam ) { return 0 ; }
2018-05-06 05:59:55 +02:00
if ( possibleLogs [ fn ] === undefined ) {
throw makeRuntimeRejectMsg ( workerScript , "Invalid argument to disableLog: " + fn ) ;
}
2018-02-24 23:55:06 +01:00
workerScript . disableLogs [ fn ] = true ;
2018-05-06 05:59:55 +02:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . disableLog == null ) {
workerScript . scriptRef . log ( "Disabled logging for " + fn ) ;
}
2018-02-24 23:55:06 +01:00
} ,
enableLog : function ( fn ) {
if ( workerScript . checkingRam ) { return 0 ; }
2018-05-06 05:59:55 +02:00
if ( possibleLogs [ fn ] === undefined ) {
throw makeRuntimeRejectMsg ( workerScript , "Invalid argument to enableLog: " + fn ) ;
}
2018-02-24 23:55:06 +01:00
delete workerScript . disableLogs [ fn ] ;
2018-05-06 05:59:55 +02:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . enableLog == null ) {
workerScript . scriptRef . log ( "Enabled logging for " + fn ) ;
}
2018-02-24 23:55:06 +01:00
} ,
2018-09-11 20:56:23 +02:00
isLogEnabled : function ( fn ) {
if ( workerScript . checkingRam ) { return 0 ; }
if ( possibleLogs [ fn ] === undefined ) {
throw makeRuntimeRejectMsg ( workerScript , "Invalid argument to isLogEnabled: " + fn ) ;
}
return workerScript . disableLogs [ fn ] ? false : true ;
} ,
2018-11-01 19:18:32 +01:00
getScriptLogs : function ( fn , ip ) {
2018-09-11 20:56:23 +02:00
if ( workerScript . checkingRam ) { return 0 ; }
2018-11-01 19:18:32 +01:00
if ( fn != null && typeof fn === 'string' ) {
// Get Logs of another script
if ( ip == null ) { ip = workerScript . serverIp ; }
2018-11-05 00:57:31 +01:00
const server = getServer ( ip ) ;
if ( server == null ) {
workerScript . log ( ` getScriptLogs() failed. Invalid IP or hostname passed in: ${ ip } ` ) ;
throw makeRuntimeRejectMsg ( workerScript , ` getScriptLogs() failed. Invalid IP or hostname passed in: ${ ip } ` ) ;
}
let argsForTarget = [ ] ;
for ( let i = 2 ; i < arguments . length ; ++ i ) {
argsForTarget . push ( arguments [ i ] ) ;
}
const runningScriptObj = findRunningScript ( fn , argsForTarget , server ) ;
if ( runningScriptObj == null ) {
workerScript . scriptRef . log ( ` getScriptLogs() failed. No such script ${ fn } on ${ server . hostname } with args: ${ arrayToString ( argsForTarget ) } ` ) ;
return "" ;
}
return runningScriptObj . logs . slice ( ) ;
2018-11-01 19:18:32 +01:00
}
2018-09-11 20:56:23 +02:00
return workerScript . scriptRef . logs . slice ( ) ;
} ,
2017-06-28 11:47:42 +02:00
nuke : function ( ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "nuke" , CONSTANTS . ScriptPortProgramRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "nuke" , CONSTANTS . ScriptPortProgramRamCost ) ;
2017-06-28 11:47:42 +02:00
if ( ip === undefined ) {
throw makeRuntimeRejectMsg ( workerScript , "Program call has incorrect number of arguments. Takes 1 argument" ) ;
}
var server = getServer ( ip ) ;
if ( server == null ) {
2017-08-01 21:03:45 +02:00
workerScript . scriptRef . log ( "Cannot call nuke(). Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "Cannot call nuke(). Invalid IP or hostname passed in: " + ip ) ;
2017-06-28 11:47:42 +02:00
}
2018-06-02 01:31:34 +02:00
if ( ! Player . hasProgram ( Programs . NukeProgram . name ) ) {
2017-07-22 00:54:55 +02:00
throw makeRuntimeRejectMsg ( workerScript , "You do not have the NUKE.exe virus!" ) ;
}
2017-06-28 11:47:42 +02:00
if ( server . openPortCount < server . numOpenPortsRequired ) {
throw makeRuntimeRejectMsg ( workerScript , "Not enough ports opened to use NUKE.exe virus" ) ;
}
if ( server . hasAdminRights ) {
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . nuke == null ) {
workerScript . scriptRef . log ( "Already have root access to " + server . hostname ) ;
}
2017-06-28 11:47:42 +02:00
} else {
server . hasAdminRights = true ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . nuke == null ) {
workerScript . scriptRef . log ( "Executed NUKE.exe virus on " + server . hostname + " to gain root access" ) ;
}
2017-06-28 11:47:42 +02:00
}
return true ;
} ,
brutessh : function ( ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "brutessh" , CONSTANTS . ScriptPortProgramRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "brutessh" , CONSTANTS . ScriptPortProgramRamCost ) ;
2017-06-28 11:47:42 +02:00
if ( ip === undefined ) {
throw makeRuntimeRejectMsg ( workerScript , "Program call has incorrect number of arguments. Takes 1 argument" ) ;
}
var server = getServer ( ip ) ;
if ( server == null ) {
2017-08-01 21:03:45 +02:00
workerScript . scriptRef . log ( "Cannot call brutessh(). Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "Cannot call brutessh(). Invalid IP or hostname passed in: " + ip ) ;
2017-06-28 11:47:42 +02:00
}
2018-06-02 01:31:34 +02:00
if ( ! Player . hasProgram ( Programs . BruteSSHProgram . name ) ) {
2017-08-30 19:44:29 +02:00
workerScript . scriptRef . log ( "You do not have the BruteSSH.exe program!" ) ;
2017-07-22 00:54:55 +02:00
throw makeRuntimeRejectMsg ( workerScript , "You do not have the BruteSSH.exe program!" ) ;
}
2017-06-28 11:47:42 +02:00
if ( ! server . sshPortOpen ) {
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . brutessh == null ) {
workerScript . scriptRef . log ( "Executed BruteSSH.exe on " + server . hostname + " to open SSH port (22)" ) ;
}
2017-07-25 03:06:40 +02:00
server . sshPortOpen = true ;
2017-06-28 11:47:42 +02:00
++ server . openPortCount ;
} else {
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . brutessh == null ) {
workerScript . scriptRef . log ( "SSH Port (22) already opened on " + server . hostname ) ;
}
2017-06-28 11:47:42 +02:00
}
return true ;
} ,
ftpcrack : function ( ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "ftpcrack" , CONSTANTS . ScriptPortProgramRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "ftpcrack" , CONSTANTS . ScriptPortProgramRamCost ) ;
2017-06-28 11:47:42 +02:00
if ( ip === undefined ) {
throw makeRuntimeRejectMsg ( workerScript , "Program call has incorrect number of arguments. Takes 1 argument" ) ;
}
var server = getServer ( ip ) ;
if ( server == null ) {
2017-08-01 21:03:45 +02:00
workerScript . scriptRef . log ( "Cannot call ftpcrack(). Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "Cannot call ftpcrack(). Invalid IP or hostname passed in: " + ip ) ;
2017-06-28 11:47:42 +02:00
}
2018-06-02 01:31:34 +02:00
if ( ! Player . hasProgram ( Programs . FTPCrackProgram . name ) ) {
2017-07-22 00:54:55 +02:00
throw makeRuntimeRejectMsg ( workerScript , "You do not have the FTPCrack.exe program!" ) ;
}
2017-06-28 11:47:42 +02:00
if ( ! server . ftpPortOpen ) {
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . ftpcrack == null ) {
workerScript . scriptRef . log ( "Executed FTPCrack.exe on " + server . hostname + " to open FTP port (21)" ) ;
}
2017-07-25 03:06:40 +02:00
server . ftpPortOpen = true ;
2017-06-28 11:47:42 +02:00
++ server . openPortCount ;
} else {
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . ftpcrack == null ) {
workerScript . scriptRef . log ( "FTP Port (21) already opened on " + server . hostname ) ;
}
2017-06-28 11:47:42 +02:00
}
return true ;
} ,
relaysmtp : function ( ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "relaysmtp" , CONSTANTS . ScriptPortProgramRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "relaysmtp" , CONSTANTS . ScriptPortProgramRamCost ) ;
2017-06-28 11:47:42 +02:00
if ( ip === undefined ) {
throw makeRuntimeRejectMsg ( workerScript , "Program call has incorrect number of arguments. Takes 1 argument" ) ;
}
var server = getServer ( ip ) ;
if ( server == null ) {
2017-08-01 21:03:45 +02:00
workerScript . scriptRef . log ( "Cannot call relaysmtp(). Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "Cannot call relaysmtp(). Invalid IP or hostname passed in: " + ip ) ;
2017-06-28 11:47:42 +02:00
}
2018-06-02 01:31:34 +02:00
if ( ! Player . hasProgram ( Programs . RelaySMTPProgram . name ) ) {
2017-07-22 00:54:55 +02:00
throw makeRuntimeRejectMsg ( workerScript , "You do not have the relaySMTP.exe program!" ) ;
}
2017-06-28 11:47:42 +02:00
if ( ! server . smtpPortOpen ) {
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . relaysmtp == null ) {
workerScript . scriptRef . log ( "Executed relaySMTP.exe on " + server . hostname + " to open SMTP port (25)" ) ;
}
2017-07-25 03:06:40 +02:00
server . smtpPortOpen = true ;
2017-06-28 11:47:42 +02:00
++ server . openPortCount ;
} else {
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . relaysmtp == null ) {
workerScript . scriptRef . log ( "SMTP Port (25) already opened on " + server . hostname ) ;
}
2017-06-28 11:47:42 +02:00
}
return true ;
} ,
httpworm : function ( ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "httpworm" , CONSTANTS . ScriptPortProgramRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "httpworm" , CONSTANTS . ScriptPortProgramRamCost ) ;
2017-06-28 11:47:42 +02:00
if ( ip === undefined ) {
throw makeRuntimeRejectMsg ( workerScript , "Program call has incorrect number of arguments. Takes 1 argument" ) ;
}
var server = getServer ( ip ) ;
if ( server == null ) {
2017-08-01 21:03:45 +02:00
workerScript . scriptRef . log ( "Cannot call httpworm(). Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "Cannot call httpworm(). Invalid IP or hostname passed in: " + ip ) ;
2017-06-28 11:47:42 +02:00
}
2018-06-02 01:31:34 +02:00
if ( ! Player . hasProgram ( Programs . HTTPWormProgram . name ) ) {
2017-07-22 00:54:55 +02:00
throw makeRuntimeRejectMsg ( workerScript , "You do not have the HTTPWorm.exe program!" ) ;
}
2017-06-28 11:47:42 +02:00
if ( ! server . httpPortOpen ) {
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . httpworm == null ) {
workerScript . scriptRef . log ( "Executed HTTPWorm.exe on " + server . hostname + " to open HTTP port (80)" ) ;
}
2017-07-25 03:06:40 +02:00
server . httpPortOpen = true ;
2017-06-28 11:47:42 +02:00
++ server . openPortCount ;
} else {
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . httpworm == null ) {
workerScript . scriptRef . log ( "HTTP Port (80) already opened on " + server . hostname ) ;
}
2017-06-28 11:47:42 +02:00
}
return true ;
} ,
sqlinject : function ( ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "sqlinject" , CONSTANTS . ScriptPortProgramRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "sqlinject" , CONSTANTS . ScriptPortProgramRamCost ) ;
2017-06-28 11:47:42 +02:00
if ( ip === undefined ) {
throw makeRuntimeRejectMsg ( workerScript , "Program call has incorrect number of arguments. Takes 1 argument" ) ;
}
var server = getServer ( ip ) ;
if ( server == null ) {
2017-08-01 21:03:45 +02:00
workerScript . scriptRef . log ( "Cannot call sqlinject(). Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "Cannot call sqlinject(). Invalid IP or hostname passed in: " + ip ) ;
2017-06-28 11:47:42 +02:00
}
2018-06-02 01:31:34 +02:00
if ( ! Player . hasProgram ( Programs . SQLInjectProgram . name ) ) {
2017-07-22 00:54:55 +02:00
throw makeRuntimeRejectMsg ( workerScript , "You do not have the SQLInject.exe program!" ) ;
}
2017-06-28 11:47:42 +02:00
if ( ! server . sqlPortOpen ) {
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . sqlinject == null ) {
workerScript . scriptRef . log ( "Executed SQLInject.exe on " + server . hostname + " to open SQL port (1433)" ) ;
}
2017-07-25 03:06:40 +02:00
server . sqlPortOpen = true ;
2017-06-28 11:47:42 +02:00
++ server . openPortCount ;
} else {
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . sqlinject == null ) {
workerScript . scriptRef . log ( "SQL Port (1433) already opened on " + server . hostname ) ;
}
2017-06-28 11:47:42 +02:00
}
return true ;
} ,
2017-07-13 18:54:29 +02:00
run : function ( scriptname , threads = 1 ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "run" , CONSTANTS . ScriptRunRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "run" , CONSTANTS . ScriptRunRamCost ) ;
2017-06-28 11:47:42 +02:00
if ( scriptname === undefined ) {
throw makeRuntimeRejectMsg ( workerScript , "run() call has incorrect number of arguments. Usage: run(scriptname, [numThreads], [arg1], [arg2]...)" ) ;
}
if ( isNaN ( threads ) || threads < 1 ) {
throw makeRuntimeRejectMsg ( workerScript , "Invalid argument for thread count passed into run(). Must be numeric and greater than 0" ) ;
}
2017-07-13 18:54:29 +02:00
var argsForNewScript = [ ] ;
for ( var i = 2 ; i < arguments . length ; ++ i ) {
argsForNewScript . push ( arguments [ i ] ) ;
}
2017-06-28 11:47:42 +02:00
var scriptServer = getServer ( workerScript . serverIp ) ;
if ( scriptServer == null ) {
throw makeRuntimeRejectMsg ( workerScript , "Could not find server. This is a bug in the game. Report to game dev" ) ;
}
2017-07-25 03:06:40 +02:00
2017-06-28 11:47:42 +02:00
return runScriptFromScript ( scriptServer , scriptname , argsForNewScript , workerScript , threads ) ;
} ,
2018-01-27 07:52:39 +01:00
exec : function ( scriptname , ip , threads = 1 ) {
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "exec" , CONSTANTS . ScriptExecRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "exec" , CONSTANTS . ScriptExecRamCost ) ;
2017-06-28 11:47:42 +02:00
if ( scriptname === undefined || ip === undefined ) {
throw makeRuntimeRejectMsg ( workerScript , "exec() call has incorrect number of arguments. Usage: exec(scriptname, server, [numThreads], [arg1], [arg2]...)" ) ;
}
if ( isNaN ( threads ) || threads < 1 ) {
throw makeRuntimeRejectMsg ( workerScript , "Invalid argument for thread count passed into exec(). Must be numeric and greater than 0" ) ;
}
2017-07-13 18:54:29 +02:00
var argsForNewScript = [ ] ;
for ( var i = 3 ; i < arguments . length ; ++ i ) {
argsForNewScript . push ( arguments [ i ] ) ;
}
2017-06-28 11:47:42 +02:00
var server = getServer ( ip ) ;
if ( server == null ) {
2017-08-13 07:01:33 +02:00
throw makeRuntimeRejectMsg ( workerScript , "Invalid hostname/ip passed into exec() command: " + ip ) ;
2017-06-28 11:47:42 +02:00
}
return runScriptFromScript ( server , scriptname , argsForNewScript , workerScript , threads ) ;
} ,
2018-02-15 05:26:43 +01:00
spawn : function ( scriptname , threads ) {
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "spawn" , CONSTANTS . ScriptSpawnRamCost ) ;
2018-02-15 05:26:43 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "spawn" , CONSTANTS . ScriptSpawnRamCost ) ;
2018-03-03 22:05:33 +01:00
if ( scriptname == null || threads == null ) {
2018-02-15 05:26:43 +01:00
throw makeRuntimeRejectMsg ( workerScript , "Invalid scriptname or numThreads argument passed to spawn()" ) ;
}
setTimeout ( ( ) => {
2018-06-17 21:19:43 +02:00
if ( scriptname === undefined ) {
throw makeRuntimeRejectMsg ( workerScript , "spawn() call has incorrect number of arguments. Usage: spawn(scriptname, numThreads, [arg1], [arg2]...)" ) ;
}
if ( isNaN ( threads ) || threads < 1 ) {
throw makeRuntimeRejectMsg ( workerScript , "Invalid argument for thread count passed into run(). Must be numeric and greater than 0" ) ;
}
var argsForNewScript = [ ] ;
for ( var i = 2 ; i < arguments . length ; ++ i ) {
argsForNewScript . push ( arguments [ i ] ) ;
}
var scriptServer = getServer ( workerScript . serverIp ) ;
if ( scriptServer == null ) {
throw makeRuntimeRejectMsg ( workerScript , "Could not find server. This is a bug in the game. Report to game dev" ) ;
}
return runScriptFromScript ( scriptServer , scriptname , argsForNewScript , workerScript , threads ) ;
2018-02-15 05:26:43 +01:00
} , 20000 ) ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . spawn == null ) {
workerScript . scriptRef . log ( "spawn() will execute " + scriptname + " in 20 seconds" ) ;
}
2018-02-15 05:26:43 +01:00
NetscriptFunctions ( workerScript ) . exit ( ) ;
} ,
2018-11-05 00:57:31 +01:00
kill : function ( filename , ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "kill" , CONSTANTS . ScriptKillRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "kill" , CONSTANTS . ScriptKillRamCost ) ;
2017-06-28 11:47:42 +02:00
if ( filename === undefined || ip === undefined ) {
2017-07-25 03:06:40 +02:00
throw makeRuntimeRejectMsg ( workerScript , "kill() call has incorrect number of arguments. Usage: kill(scriptname, server, [arg1], [arg2]...)" ) ;
2017-06-28 11:47:42 +02:00
}
var server = getServer ( ip ) ;
if ( server == null ) {
2017-07-13 18:54:29 +02:00
workerScript . scriptRef . log ( "kill() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "kill() failed. Invalid IP or hostname passed in: " + ip ) ;
}
var argsForKillTarget = [ ] ;
for ( var i = 2 ; i < arguments . length ; ++ i ) {
argsForKillTarget . push ( arguments [ i ] ) ;
2017-06-28 11:47:42 +02:00
}
var runningScriptObj = findRunningScript ( filename , argsForKillTarget , server ) ;
if ( runningScriptObj == null ) {
2018-07-05 20:12:20 +02:00
workerScript . scriptRef . log ( "kill() failed. No such script " + filename + " on " + server . hostname + " with args: " + arrayToString ( argsForKillTarget ) ) ;
2017-06-28 11:47:42 +02:00
return false ;
}
var res = killWorkerScript ( runningScriptObj , server . ip ) ;
if ( res ) {
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . kill == null ) {
2018-07-05 20:12:20 +02:00
workerScript . scriptRef . log ( "Killing " + filename + " on " + server . hostname + " with args: " + arrayToString ( argsForKillTarget ) + ". May take up to a few minutes for the scripts to die..." ) ;
2018-02-24 23:55:06 +01:00
}
2017-06-28 11:47:42 +02:00
return true ;
} else {
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . kill == null ) {
2018-07-05 20:12:20 +02:00
workerScript . scriptRef . log ( "kill() failed. No such script " + filename + " on " + server . hostname + " with args: " + arrayToString ( argsForKillTarget ) ) ;
2018-02-24 23:55:06 +01:00
}
2017-06-28 11:47:42 +02:00
return false ;
}
} ,
2018-03-03 22:05:33 +01:00
killall : function ( ip = workerScript . serverIp ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "killall" , CONSTANTS . ScriptKillRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "killall" , CONSTANTS . ScriptKillRamCost ) ;
2017-06-28 11:47:42 +02:00
if ( ip === undefined ) {
throw makeRuntimeRejectMsg ( workerScript , "killall() call has incorrect number of arguments. Takes 1 argument" ) ;
}
var server = getServer ( ip ) ;
if ( server == null ) {
2017-07-13 18:54:29 +02:00
workerScript . scriptRef . log ( "killall() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "killall() failed. Invalid IP or hostname passed in: " + ip ) ;
2017-06-28 11:47:42 +02:00
}
2018-02-24 23:55:06 +01:00
var scriptsRunning = ( server . runningScripts . length > 0 ) ;
2017-06-28 11:47:42 +02:00
for ( var i = server . runningScripts . length - 1 ; i >= 0 ; -- i ) {
killWorkerScript ( server . runningScripts [ i ] , server . ip ) ;
}
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . killall == null ) {
workerScript . scriptRef . log ( "killall(): Killing all scripts on " + server . hostname + ". May take a few minutes for the scripts to die" ) ;
}
return scriptsRunning ;
2017-06-28 11:47:42 +02:00
} ,
2017-12-07 04:45:47 +01:00
exit : function ( ) {
2018-06-17 21:19:43 +02:00
if ( workerScript . checkingRam ) { return 0 ; }
2017-12-07 04:45:47 +01:00
var server = getServer ( workerScript . serverIp ) ;
if ( server == null ) {
throw makeRuntimeRejectMsg ( workerScript , "Error getting Server for this script in exit(). This is a bug please contact game dev" ) ;
}
if ( killWorkerScript ( workerScript . scriptRef , server . ip ) ) {
workerScript . scriptRef . log ( "Exiting..." ) ;
} else {
workerScript . scriptRef . log ( "Exit failed(). This is a bug please contact game developer" ) ;
}
} ,
2018-01-27 07:52:39 +01:00
scp : function ( scriptname , ip1 , ip2 ) {
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "scp" , CONSTANTS . ScriptScpRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "scp" , CONSTANTS . ScriptScpRamCost ) ;
2017-09-19 20:38:03 +02:00
if ( arguments . length !== 2 && arguments . length !== 3 ) {
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "ERROR: scp() call has incorrect number of arguments. Takes 2 or 3 arguments" ) ;
2017-09-07 07:45:14 +02:00
}
2017-09-27 17:13:42 +02:00
if ( scriptname && scriptname . constructor === Array ) {
//Recursively call scp on all elements of array
var res = false ;
scriptname . forEach ( function ( script ) {
if ( NetscriptFunctions ( workerScript ) . scp ( script , ip1 , ip2 ) ) {
res = true ;
} ;
} ) ;
return res ;
}
2018-05-06 00:13:35 +02:00
if ( ! scriptname . endsWith ( ".lit" ) && ! isScriptFilename ( scriptname ) &&
2018-02-24 23:55:06 +01:00
! scriptname . endsWith ( "txt" ) ) {
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "ERROR: scp() does not work with this file type. It only works for .script, .lit, and .txt files" ) ;
2017-06-28 11:47:42 +02:00
}
2017-07-25 03:06:40 +02:00
2017-09-19 20:38:03 +02:00
var destServer , currServ ;
if ( arguments . length === 3 ) { //scriptname, source, destination
if ( scriptname === undefined || ip1 === undefined || ip2 === undefined ) {
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "ERROR: scp() call has incorrect number of arguments. Takes 2 or 3 arguments" ) ;
2017-09-19 20:38:03 +02:00
}
destServer = getServer ( ip2 ) ;
if ( destServer == null ) {
2018-10-23 20:55:42 +02:00
throw makeRuntimeRejectMsg ( workerScript , ` ERROR: Invalid hostname/ip passed into scp() command: ${ ip2 } ` ) ;
2017-09-19 20:38:03 +02:00
}
currServ = getServer ( ip1 ) ;
if ( currServ == null ) {
2018-10-23 20:55:42 +02:00
throw makeRuntimeRejectMsg ( workerScript , ` ERROR: Invalid hostname/ip passed into scp() command: ${ ip1 } ` ) ;
2017-09-19 20:38:03 +02:00
}
} else if ( arguments . length === 2 ) { //scriptname, destination
if ( scriptname === undefined || ip1 === undefined ) {
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "ERROR: scp() call has incorrect number of arguments. Takes 2 or 3 arguments" ) ;
2017-09-19 20:38:03 +02:00
}
destServer = getServer ( ip1 ) ;
if ( destServer == null ) {
2018-10-23 20:55:42 +02:00
throw makeRuntimeRejectMsg ( workerScript , ` ERROR: Invalid hostname/ip passed into scp() command: ${ ip1 } ` ) ;
2017-09-19 20:38:03 +02:00
}
currServ = getServer ( workerScript . serverIp ) ;
if ( currServ == null ) {
throw makeRuntimeRejectMsg ( workerScript , "Could not find server ip for this script. This is a bug please contact game developer" ) ;
}
2017-06-28 11:47:42 +02:00
}
2017-07-25 03:06:40 +02:00
2017-09-07 07:45:14 +02:00
//Scp for lit files
if ( scriptname . endsWith ( ".lit" ) ) {
var found = false ;
for ( var i = 0 ; i < currServ . messages . length ; ++ i ) {
if ( ! ( currServ . messages [ i ] instanceof Message ) && currServ . messages [ i ] == scriptname ) {
found = true ;
2018-02-24 23:55:06 +01:00
break ;
2017-09-07 07:45:14 +02:00
}
}
if ( ! found ) {
workerScript . scriptRef . log ( scriptname + " does not exist. scp() failed" ) ;
return false ;
}
for ( var i = 0 ; i < destServer . messages . length ; ++ i ) {
if ( destServer . messages [ i ] === scriptname ) {
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . scp == null ) {
workerScript . scriptRef . log ( scriptname + " copied over to " + destServer . hostname ) ;
}
2017-09-07 07:45:14 +02:00
return true ; //Already exists
}
}
destServer . messages . push ( scriptname ) ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . scp == null ) {
workerScript . scriptRef . log ( scriptname + " copied over to " + destServer . hostname ) ;
}
return true ;
}
//Scp for text files
if ( scriptname . endsWith ( ".txt" ) ) {
var found = false , txtFile ;
for ( var i = 0 ; i < currServ . textFiles . length ; ++ i ) {
if ( currServ . textFiles [ i ] . fn === scriptname ) {
found = true ;
txtFile = currServ . textFiles [ i ] ;
break ;
}
}
if ( ! found ) {
workerScript . scriptRef . log ( scriptname + " does not exist. scp() failed" ) ;
return false ;
}
for ( var i = 0 ; i < destServer . textFiles . length ; ++ i ) {
if ( destServer . textFiles [ i ] . fn === scriptname ) {
//Overwrite
destServer . textFiles [ i ] . text = txtFile . text ;
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . scp == null ) {
workerScript . scriptRef . log ( scriptname + " copied over to " + destServer . hostname ) ;
}
return true ;
}
}
var newFile = new TextFile ( txtFile . fn , txtFile . text ) ;
destServer . textFiles . push ( newFile ) ;
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . scp == null ) {
workerScript . scriptRef . log ( scriptname + " copied over to " + destServer . hostname ) ;
}
2017-09-07 07:45:14 +02:00
return true ;
}
//Scp for script files
2017-06-28 11:47:42 +02:00
var sourceScript = null ;
for ( var i = 0 ; i < currServ . scripts . length ; ++ i ) {
if ( scriptname == currServ . scripts [ i ] . filename ) {
sourceScript = currServ . scripts [ i ] ;
break ;
2017-06-11 22:28:20 +02:00
}
2017-06-28 11:47:42 +02:00
}
if ( sourceScript == null ) {
workerScript . scriptRef . log ( scriptname + " does not exist. scp() failed" ) ;
return false ;
}
2017-07-25 03:06:40 +02:00
2017-06-28 11:47:42 +02:00
//Overwrite script if it already exists
for ( var i = 0 ; i < destServer . scripts . length ; ++ i ) {
if ( scriptname == destServer . scripts [ i ] . filename ) {
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . scp == null ) {
workerScript . scriptRef . log ( "WARNING: " + scriptname + " already exists on " + destServer . hostname + " and it will be overwritten." ) ;
workerScript . scriptRef . log ( scriptname + " overwritten on " + destServer . hostname ) ;
}
2017-06-28 11:47:42 +02:00
var oldScript = destServer . scripts [ i ] ;
oldScript . code = sourceScript . code ;
oldScript . ramUsage = sourceScript . ramUsage ;
2018-06-29 07:39:05 +02:00
oldScript . module = "" ;
2017-06-28 11:47:42 +02:00
return true ;
2017-06-18 06:36:16 +02:00
}
2017-06-28 11:47:42 +02:00
}
2017-07-25 03:06:40 +02:00
2017-06-28 11:47:42 +02:00
//Create new script if it does not already exist
var newScript = new Script ( ) ;
newScript . filename = scriptname ;
newScript . code = sourceScript . code ;
newScript . ramUsage = sourceScript . ramUsage ;
newScript . server = destServer . ip ;
destServer . scripts . push ( newScript ) ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . scp == null ) {
workerScript . scriptRef . log ( scriptname + " copied over to " + destServer . hostname ) ;
}
2017-06-28 11:47:42 +02:00
return true ;
} ,
2017-09-07 07:45:14 +02:00
ls : function ( ip , grep ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "ls" , CONSTANTS . ScriptScanRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "ls" , CONSTANTS . ScriptScanRamCost ) ;
2017-09-07 07:45:14 +02:00
if ( ip === undefined ) {
throw makeRuntimeRejectMsg ( workerScript , "ls() failed because of invalid arguments. Usage: ls(ip/hostname, [grep filter])" ) ;
}
var server = getServer ( ip ) ;
2017-10-26 00:05:12 +02:00
if ( server == null ) {
2017-09-07 07:45:14 +02:00
workerScript . scriptRef . log ( "ls() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "ls() failed. Invalid IP or hostname passed in: " + ip ) ;
}
//Get the grep filter, if one exists
var filter = false ;
if ( arguments . length >= 2 ) {
filter = grep . toString ( ) ;
}
var allFiles = [ ] ;
for ( var i = 0 ; i < server . programs . length ; i ++ ) {
if ( filter ) {
if ( server . programs [ i ] . includes ( filter ) ) {
allFiles . push ( server . programs [ i ] ) ;
}
} else {
allFiles . push ( server . programs [ i ] ) ;
}
}
for ( var i = 0 ; i < server . scripts . length ; i ++ ) {
if ( filter ) {
if ( server . scripts [ i ] . filename . includes ( filter ) ) {
allFiles . push ( server . scripts [ i ] . filename ) ;
}
} else {
allFiles . push ( server . scripts [ i ] . filename ) ;
}
}
for ( var i = 0 ; i < server . messages . length ; i ++ ) {
if ( filter ) {
if ( server . messages [ i ] instanceof Message ) {
if ( server . messages [ i ] . filename . includes ( filter ) ) {
allFiles . push ( server . messages [ i ] . filename ) ;
}
} else if ( server . messages [ i ] . includes ( filter ) ) {
allFiles . push ( server . messages [ i ] ) ;
}
} else {
if ( server . messages [ i ] instanceof Message ) {
allFiles . push ( server . messages [ i ] . filename ) ;
} else {
allFiles . push ( server . messages [ i ] ) ;
}
}
}
2018-02-18 04:08:54 +01:00
for ( var i = 0 ; i < server . textFiles . length ; i ++ ) {
if ( filter ) {
if ( server . textFiles [ i ] . fn . includes ( filter ) ) {
allFiles . push ( server . textFiles [ i ] . fn ) ;
}
} else {
allFiles . push ( server . textFiles [ i ] . fn ) ;
}
}
2018-09-23 02:25:48 +02:00
for ( var i = 0 ; i < server . contracts . length ; ++ i ) {
if ( filter ) {
if ( server . contracts [ i ] . fn . includes ( filter ) ) {
allFiles . push ( server . contracts [ i ] . fn ) ;
}
} else {
allFiles . push ( server . contracts [ i ] . fn ) ;
}
}
2017-09-07 07:45:14 +02:00
//Sort the files alphabetically then print each
allFiles . sort ( ) ;
return allFiles ;
} ,
2018-06-13 06:03:02 +02:00
ps : function ( ip = workerScript . serverIp ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "ps" , CONSTANTS . ScriptScanRamCost ) ;
}
updateDynamicRam ( "ps" , CONSTANTS . ScriptScanRamCost ) ;
var server = getServer ( ip ) ;
if ( server == null ) {
workerScript . scriptRef . log ( "ps() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "ps() failed. Invalid IP or hostname passed in: " + ip ) ;
}
const processes = [ ] ;
2018-10-23 20:55:42 +02:00
for ( const i in server . runningScripts ) {
2018-06-13 06:03:02 +02:00
const script = server . runningScripts [ i ] ;
processes . push ( { filename : script . filename , threads : script . threads , args : script . args . slice ( ) } )
}
return processes ;
} ,
2018-01-27 07:52:39 +01:00
hasRootAccess : function ( ip ) {
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "hasRootAccess" , CONSTANTS . ScriptHasRootAccessRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "hasRootAccess" , CONSTANTS . ScriptHasRootAccessRamCost ) ;
2017-07-13 18:54:29 +02:00
if ( ip === undefined ) {
2017-06-28 11:47:42 +02:00
throw makeRuntimeRejectMsg ( workerScript , "hasRootAccess() call has incorrect number of arguments. Takes 1 argument" ) ;
}
var server = getServer ( ip ) ;
if ( server == null ) {
2017-07-13 18:54:29 +02:00
workerScript . scriptRef . log ( "hasRootAccess() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "hasRootAccess() failed. Invalid IP or hostname passed in: " + ip ) ;
2017-06-28 11:47:42 +02:00
}
2017-07-13 18:54:29 +02:00
return server . hasAdminRights ;
2017-06-28 11:47:42 +02:00
} ,
2017-09-19 20:38:03 +02:00
getIp : function ( ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getIp" , CONSTANTS . ScriptGetHostnameRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getIp" , CONSTANTS . ScriptGetHostnameRamCost ) ;
2017-09-19 20:38:03 +02:00
var scriptServer = getServer ( workerScript . serverIp ) ;
if ( scriptServer == null ) {
throw makeRuntimeRejectMsg ( workerScript , "Could not find server. This is a bug in the game. Report to game dev" ) ;
}
return scriptServer . ip ;
} ,
2017-06-28 11:47:42 +02:00
getHostname : function ( ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getHostname" , CONSTANTS . ScriptGetHostnameRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getHostname" , CONSTANTS . ScriptGetHostnameRamCost ) ;
2017-06-28 11:47:42 +02:00
var scriptServer = getServer ( workerScript . serverIp ) ;
if ( scriptServer == null ) {
throw makeRuntimeRejectMsg ( workerScript , "Could not find server. This is a bug in the game. Report to game dev" ) ;
}
return scriptServer . hostname ;
} ,
getHackingLevel : function ( ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getHackingLevel" , CONSTANTS . ScriptGetHackingLevelRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getHackingLevel" , CONSTANTS . ScriptGetHackingLevelRamCost ) ;
2017-06-28 11:47:42 +02:00
Player . updateSkillLevels ( ) ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . getHackingLevel == null ) {
workerScript . scriptRef . log ( "getHackingLevel() returned " + Player . hacking _skill ) ;
}
2017-06-28 11:47:42 +02:00
return Player . hacking _skill ;
} ,
2017-09-19 20:38:03 +02:00
getHackingMultipliers : function ( ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getHackingMultipliers" , CONSTANTS . ScriptGetMultipliersRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getHackingMultipliers" , CONSTANTS . ScriptGetMultipliersRamCost ) ;
2017-09-19 20:38:03 +02:00
return {
chance : Player . hacking _chance _mult ,
speed : Player . hacking _speed _mult ,
money : Player . hacking _money _mult ,
growth : Player . hacking _grow _mult ,
} ;
} ,
2018-05-06 20:22:29 +02:00
getHacknetMultipliers : function ( ) {
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getHacknetMultipliers" , CONSTANTS . ScriptGetMultipliersRamCost ) ;
2018-05-06 20:22:29 +02:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getHacknetMultipliers" , CONSTANTS . ScriptGetMultipliersRamCost ) ;
2018-05-06 20:22:29 +02:00
return {
production : Player . hacknet _node _money _mult ,
purchaseCost : Player . hacknet _node _purchase _cost _mult ,
ramCost : Player . hacknet _node _ram _cost _mult ,
coreCost : Player . hacknet _node _core _cost _mult ,
levelCost : Player . hacknet _node _level _cost _mult ,
} ;
} ,
2017-09-19 20:38:03 +02:00
getBitNodeMultipliers : function ( ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getBitNodeMultipliers" , CONSTANTS . ScriptGetMultipliersRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getBitNodeMultipliers" , CONSTANTS . ScriptGetMultipliersRamCost ) ;
2017-09-19 20:38:03 +02:00
if ( ! hasAISF ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run getBitNodeMultipliers(). It requires Source-File 5 to run." ) ;
}
2018-06-03 03:37:56 +02:00
let copy = Object . assign ( { } , BitNodeMultipliers ) ;
return copy ;
2017-09-19 20:38:03 +02:00
} ,
2017-06-28 11:47:42 +02:00
getServerMoneyAvailable : function ( ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getServerMoneyAvailable" , CONSTANTS . ScriptGetServerRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getServerMoneyAvailable" , CONSTANTS . ScriptGetServerRamCost ) ;
2017-06-28 11:47:42 +02:00
var server = getServer ( ip ) ;
if ( server == null ) {
2017-09-07 07:45:14 +02:00
workerScript . scriptRef . log ( "getServerMoneyAvailable() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "getServerMoneyAvailable() failed. Invalid IP or hostname passed in: " + ip ) ;
2017-07-13 18:54:29 +02:00
}
if ( server . hostname == "home" ) {
//Return player's money
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . getServerMoneyAvailable == null ) {
workerScript . scriptRef . log ( "getServerMoneyAvailable('home') returned player's money: $" + formatNumber ( Player . money . toNumber ( ) , 2 ) ) ;
}
2017-07-29 18:25:40 +02:00
return Player . money . toNumber ( ) ;
2017-06-28 11:47:42 +02:00
}
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . getServerMoneyAvailable == null ) {
workerScript . scriptRef . log ( "getServerMoneyAvailable() returned " + formatNumber ( server . moneyAvailable , 2 ) + " for " + server . hostname ) ;
}
2017-06-28 11:47:42 +02:00
return server . moneyAvailable ;
} ,
getServerSecurityLevel : function ( ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getServerSecurityLevel" , CONSTANTS . ScriptGetServerRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getServerSecurityLevel" , CONSTANTS . ScriptGetServerRamCost ) ;
2017-06-28 11:47:42 +02:00
var server = getServer ( ip ) ;
if ( server == null ) {
2017-07-13 18:54:29 +02:00
workerScript . scriptRef . log ( "getServerSecurityLevel() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "getServerSecurityLevel() failed. Invalid IP or hostname passed in: " + ip ) ;
2017-06-28 11:47:42 +02:00
}
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . getServerSecurityLevel == null ) {
workerScript . scriptRef . log ( "getServerSecurityLevel() returned " + formatNumber ( server . hackDifficulty , 3 ) + " for " + server . hostname ) ;
}
2017-06-28 11:47:42 +02:00
return server . hackDifficulty ;
} ,
getServerBaseSecurityLevel : function ( ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getServerBaseSecurityLevel" , CONSTANTS . ScriptGetServerRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getServerBaseSecurityLevel" , CONSTANTS . ScriptGetServerRamCost ) ;
2017-06-28 11:47:42 +02:00
var server = getServer ( ip ) ;
if ( server == null ) {
2017-07-13 18:54:29 +02:00
workerScript . scriptRef . log ( "getServerBaseSecurityLevel() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "getServerBaseSecurityLevel() failed. Invalid IP or hostname passed in: " + ip ) ;
2017-06-28 11:47:42 +02:00
}
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . getServerBaseSecurityLevel == null ) {
workerScript . scriptRef . log ( "getServerBaseSecurityLevel() returned " + formatNumber ( server . baseDifficulty , 3 ) + " for " + server . hostname ) ;
}
2017-06-28 11:47:42 +02:00
return server . baseDifficulty ;
} ,
2017-09-26 04:44:33 +02:00
getServerMinSecurityLevel : function ( ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getServerMinSecurityLevel" , CONSTANTS . ScriptGetServerRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getServerMinSecurityLevel" , CONSTANTS . ScriptGetServerRamCost ) ;
2017-09-26 04:44:33 +02:00
var server = getServer ( ip ) ;
if ( server == null ) {
workerScript . scriptRef . log ( "getServerMinSecurityLevel() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "getServerMinSecurityLevel() failed. Invalid IP or hostname passed in: " + ip ) ;
}
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . getServerMinSecurityLevel == null ) {
workerScript . scriptRef . log ( "getServerMinSecurityLevel() returned " + formatNumber ( server . minDifficulty , 3 ) + " for " + server . hostname ) ;
}
2017-09-26 04:44:33 +02:00
return server . minDifficulty ;
} ,
2018-01-27 07:52:39 +01:00
getServerRequiredHackingLevel : function ( ip ) {
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getServerRequiredHackingLevel" , CONSTANTS . ScriptGetServerRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getServerRequiredHackingLevel" , CONSTANTS . ScriptGetServerRamCost ) ;
2017-06-28 11:47:42 +02:00
var server = getServer ( ip ) ;
if ( server == null ) {
2017-07-13 18:54:29 +02:00
workerScript . scriptRef . log ( "getServerRequiredHackingLevel() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "getServerRequiredHackingLevel() failed. Invalid IP or hostname passed in: " + ip ) ;
2017-06-28 11:47:42 +02:00
}
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . getServerRequiredHackingLevel == null ) {
workerScript . scriptRef . log ( "getServerRequiredHackingLevel returned " + formatNumber ( server . requiredHackingSkill , 0 ) + " for " + server . hostname ) ;
}
2017-06-28 11:47:42 +02:00
return server . requiredHackingSkill ;
} ,
getServerMaxMoney : function ( ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getServerMaxMoney" , CONSTANTS . ScriptGetServerRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getServerMaxMoney" , CONSTANTS . ScriptGetServerRamCost ) ;
2017-06-28 11:47:42 +02:00
var server = getServer ( ip ) ;
if ( server == null ) {
2017-08-18 19:20:51 +02:00
workerScript . scriptRef . log ( "getServerMaxMoney() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "getServerMaxMoney() failed. Invalid IP or hostname passed in: " + ip ) ;
2017-06-28 11:47:42 +02:00
}
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . getServerMaxMoney == null ) {
workerScript . scriptRef . log ( "getServerMaxMoney() returned " + formatNumber ( server . moneyMax , 0 ) + " for " + server . hostname ) ;
}
2017-06-28 11:47:42 +02:00
return server . moneyMax ;
} ,
2017-08-18 19:20:51 +02:00
getServerGrowth : function ( ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getServerGrowth" , CONSTANTS . ScriptGetServerRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getServerGrowth" , CONSTANTS . ScriptGetServerRamCost ) ;
2017-08-18 19:20:51 +02:00
var server = getServer ( ip ) ;
if ( server == null ) {
workerScript . scriptRef . log ( "getServerGrowth() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "getServerGrowth() failed. Invalid IP or hostname passed in: " + ip ) ;
}
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . getServerGrowth == null ) {
workerScript . scriptRef . log ( "getServerGrowth() returned " + formatNumber ( server . serverGrowth , 0 ) + " for " + server . hostname ) ;
}
2017-08-18 19:20:51 +02:00
return server . serverGrowth ;
} ,
2018-01-27 07:52:39 +01:00
getServerNumPortsRequired : function ( ip ) {
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getServerNumPortsRequired" , CONSTANTS . ScriptGetServerRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getServerNumPortsRequired" , CONSTANTS . ScriptGetServerRamCost ) ;
2017-07-13 18:54:29 +02:00
var server = getServer ( ip ) ;
if ( server == null ) {
workerScript . scriptRef . log ( "getServerNumPortsRequired() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "getServerNumPortsRequired() failed. Invalid IP or hostname passed in: " + ip ) ;
}
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . getServerNumPortsRequired == null ) {
workerScript . scriptRef . log ( "getServerNumPortsRequired() returned " + formatNumber ( server . numOpenPortsRequired , 0 ) + " for " + server . hostname ) ;
}
2017-07-13 18:54:29 +02:00
return server . numOpenPortsRequired ;
} ,
2017-07-25 03:06:40 +02:00
getServerRam : function ( ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getServerRam" , CONSTANTS . ScriptGetServerRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getServerRam" , CONSTANTS . ScriptGetServerRamCost ) ;
2017-07-25 03:06:40 +02:00
var server = getServer ( ip ) ;
if ( server == null ) {
workerScript . scriptRef . log ( "getServerRam() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "getServerRam() failed. Invalid IP or hostname passed in: " + ip ) ;
}
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . getServerRam == null ) {
workerScript . scriptRef . log ( "getServerRam() returned [" + formatNumber ( server . maxRam , 2 ) + "GB, " + formatNumber ( server . ramUsed , 2 ) + "GB]" ) ;
}
2017-07-25 03:06:40 +02:00
return [ server . maxRam , server . ramUsed ] ;
} ,
2017-09-15 16:06:59 +02:00
serverExists : function ( ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "serverExists" , CONSTANTS . ScriptGetServerRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "serverExists" , CONSTANTS . ScriptGetServerRamCost ) ;
2017-09-15 16:06:59 +02:00
return ( getServer ( ip ) !== null ) ;
} ,
2018-01-27 07:52:39 +01:00
fileExists : function ( filename , ip = workerScript . serverIp ) {
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "fileExists" , CONSTANTS . ScriptFileExistsRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "fileExists" , CONSTANTS . ScriptFileExistsRamCost ) ;
2017-06-28 11:47:42 +02:00
if ( filename === undefined ) {
2017-07-25 03:06:40 +02:00
throw makeRuntimeRejectMsg ( workerScript , "fileExists() call has incorrect number of arguments. Usage: fileExists(scriptname, [server])" ) ;
2017-06-28 11:47:42 +02:00
}
var server = getServer ( ip ) ;
if ( server == null ) {
2017-07-13 18:54:29 +02:00
workerScript . scriptRef . log ( "fileExists() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "fileExists() failed. Invalid IP or hostname passed in: " + ip ) ;
2017-06-28 11:47:42 +02:00
}
for ( var i = 0 ; i < server . scripts . length ; ++ i ) {
if ( filename == server . scripts [ i ] . filename ) {
return true ;
}
}
2017-07-13 18:54:29 +02:00
for ( var i = 0 ; i < server . programs . length ; ++ i ) {
if ( filename . toLowerCase ( ) == server . programs [ i ] . toLowerCase ( ) ) {
return true ;
}
2017-06-28 11:47:42 +02:00
}
2017-09-21 23:27:31 +02:00
for ( var i = 0 ; i < server . messages . length ; ++ i ) {
if ( ! ( server . messages [ i ] instanceof Message ) &&
filename . toLowerCase ( ) === server . messages [ i ] ) {
return true ;
}
}
2018-01-02 08:12:54 +01:00
var txtFile = getTextFile ( filename , server ) ;
2018-01-21 21:53:16 +01:00
if ( txtFile != null ) {
2018-01-02 08:12:54 +01:00
return true ;
}
2017-06-28 11:47:42 +02:00
return false ;
} ,
2018-01-27 07:52:39 +01:00
isRunning : function ( filename , ip ) {
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "isRunning" , CONSTANTS . ScriptIsRunningRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "isRunning" , CONSTANTS . ScriptIsRunningRamCost ) ;
2017-06-28 11:47:42 +02:00
if ( filename === undefined || ip === undefined ) {
2017-07-25 03:06:40 +02:00
throw makeRuntimeRejectMsg ( workerScript , "isRunning() call has incorrect number of arguments. Usage: isRunning(scriptname, server, [arg1], [arg2]...)" ) ;
2017-06-28 11:47:42 +02:00
}
var server = getServer ( ip ) ;
if ( server == null ) {
2017-07-13 18:54:29 +02:00
workerScript . scriptRef . log ( "isRunning() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "isRunning() failed. Invalid IP or hostname passed in: " + ip ) ;
}
var argsForTargetScript = [ ] ;
for ( var i = 2 ; i < arguments . length ; ++ i ) {
argsForTargetScript . push ( arguments [ i ] ) ;
}
return ( findRunningScript ( filename , argsForTargetScript , server ) != null ) ;
} ,
2018-09-30 03:52:38 +02:00
getStockSymbols : function ( ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getStockSymbols" , CONSTANTS . ScriptGetStockRamCost ) ;
}
updateDynamicRam ( "getStockSymbols" , CONSTANTS . ScriptGetStockRamCost ) ;
if ( ! Player . hasTixApiAccess ) {
throw makeRuntimeRejectMsg ( workerScript , "You don't have TIX API Access! Cannot use getStockSymbols()" ) ;
}
return Object . values ( StockSymbols ) ;
} ,
2017-07-13 18:54:29 +02:00
getStockPrice : function ( symbol ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getStockPrice" , CONSTANTS . ScriptGetStockRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getStockPrice" , CONSTANTS . ScriptGetStockRamCost ) ;
2017-07-13 18:54:29 +02:00
if ( ! Player . hasTixApiAccess ) {
throw makeRuntimeRejectMsg ( workerScript , "You don't have TIX API Access! Cannot use getStockPrice()" ) ;
}
var stock = SymbolToStockMap [ symbol ] ;
if ( stock == null ) {
throw makeRuntimeRejectMsg ( workerScript , "Invalid stock symbol passed into getStockPrice()" ) ;
}
return parseFloat ( stock . price . toFixed ( 3 ) ) ;
} ,
getStockPosition : function ( symbol ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getStockPosition" , CONSTANTS . ScriptGetStockRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getStockPosition" , CONSTANTS . ScriptGetStockRamCost ) ;
2017-07-13 18:54:29 +02:00
if ( ! Player . hasTixApiAccess ) {
throw makeRuntimeRejectMsg ( workerScript , "You don't have TIX API Access! Cannot use getStockPosition()" ) ;
}
var stock = SymbolToStockMap [ symbol ] ;
if ( stock == null ) {
2018-05-13 02:50:13 +02:00
throw makeRuntimeRejectMsg ( workerScript , "Invalid stock symbol passed into getStockPosition()" ) ;
2017-07-13 18:54:29 +02:00
}
2017-10-25 21:47:47 +02:00
return [ stock . playerShares , stock . playerAvgPx , stock . playerShortShares , stock . playerAvgShortPx ] ;
2017-07-13 18:54:29 +02:00
} ,
buyStock : function ( symbol , shares ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "buyStock" , CONSTANTS . ScriptBuySellStockRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "buyStock" , CONSTANTS . ScriptBuySellStockRamCost ) ;
2017-07-13 18:54:29 +02:00
if ( ! Player . hasTixApiAccess ) {
throw makeRuntimeRejectMsg ( workerScript , "You don't have TIX API Access! Cannot use buyStock()" ) ;
}
var stock = SymbolToStockMap [ symbol ] ;
if ( stock == null ) {
2017-10-25 21:47:47 +02:00
throw makeRuntimeRejectMsg ( workerScript , "Invalid stock symbol passed into buyStock()" ) ;
2017-07-13 18:54:29 +02:00
}
2017-10-25 21:47:47 +02:00
if ( shares < 0 || isNaN ( shares ) ) {
2018-06-08 17:51:48 +02:00
workerScript . scriptRef . log ( "ERROR: Invalid 'shares' argument passed to buyStock()" ) ;
2017-12-03 05:19:49 +01:00
return 0 ;
2017-07-13 18:54:29 +02:00
}
shares = Math . round ( shares ) ;
2017-12-03 05:19:49 +01:00
if ( shares === 0 ) { return 0 ; }
2017-07-25 03:06:40 +02:00
2017-07-13 18:54:29 +02:00
var totalPrice = stock . price * shares ;
2017-07-29 18:25:40 +02:00
if ( Player . money . lt ( totalPrice + CONSTANTS . StockMarketCommission ) ) {
2017-07-25 03:06:40 +02:00
workerScript . scriptRef . log ( "Not enough money to purchase " + formatNumber ( shares , 0 ) + " shares of " +
symbol + ". Need $" +
2017-07-13 18:54:29 +02:00
formatNumber ( totalPrice + CONSTANTS . StockMarketCommission , 2 ) . toString ( ) ) ;
2017-12-03 05:19:49 +01:00
return 0 ;
2017-07-13 18:54:29 +02:00
}
2017-07-25 03:06:40 +02:00
2017-07-13 18:54:29 +02:00
var origTotal = stock . playerShares * stock . playerAvgPx ;
Player . loseMoney ( totalPrice + CONSTANTS . StockMarketCommission ) ;
var newTotal = origTotal + totalPrice ;
2017-07-25 03:06:40 +02:00
stock . playerShares += shares ;
2017-07-13 18:54:29 +02:00
stock . playerAvgPx = newTotal / stock . playerShares ;
2018-07-20 03:51:18 +02:00
if ( routing . isOn ( Page . StockMarket ) ) {
2017-07-13 18:54:29 +02:00
updateStockPlayerPosition ( stock ) ;
}
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . buyStock == null ) {
workerScript . scriptRef . log ( "Bought " + formatNumber ( shares , 0 ) + " shares of " + stock . symbol + " at $" +
formatNumber ( stock . price , 2 ) + " per share" ) ;
}
2017-12-03 05:19:49 +01:00
return stock . price ;
2017-07-13 18:54:29 +02:00
} ,
sellStock : function ( symbol , shares ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "sellStock" , CONSTANTS . ScriptBuySellStockRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "sellStock" , CONSTANTS . ScriptBuySellStockRamCost ) ;
2017-07-13 18:54:29 +02:00
if ( ! Player . hasTixApiAccess ) {
throw makeRuntimeRejectMsg ( workerScript , "You don't have TIX API Access! Cannot use sellStock()" ) ;
}
var stock = SymbolToStockMap [ symbol ] ;
if ( stock == null ) {
2017-10-25 21:47:47 +02:00
throw makeRuntimeRejectMsg ( workerScript , "Invalid stock symbol passed into sellStock()" ) ;
2017-07-13 18:54:29 +02:00
}
2017-10-25 21:47:47 +02:00
if ( shares < 0 || isNaN ( shares ) ) {
2018-06-08 17:51:48 +02:00
workerScript . scriptRef . log ( "ERROR: Invalid 'shares' argument passed to sellStock()" ) ;
2017-12-03 05:19:49 +01:00
return 0 ;
2017-06-28 11:47:42 +02:00
}
2017-10-15 03:55:41 +02:00
shares = Math . round ( shares ) ;
2017-07-13 18:54:29 +02:00
if ( shares > stock . playerShares ) { shares = stock . playerShares ; }
2017-12-03 05:19:49 +01:00
if ( shares === 0 ) { return 0 ; }
2017-07-13 18:54:29 +02:00
var gains = stock . price * shares - CONSTANTS . StockMarketCommission ;
Player . gainMoney ( gains ) ;
2017-07-25 03:06:40 +02:00
2017-07-13 18:54:29 +02:00
//Calculate net profit and add to script stats
var netProfit = ( ( stock . price - stock . playerAvgPx ) * shares ) - CONSTANTS . StockMarketCommission ;
if ( isNaN ( netProfit ) ) { netProfit = 0 ; }
workerScript . scriptRef . onlineMoneyMade += netProfit ;
2017-09-26 04:44:33 +02:00
Player . scriptProdSinceLastAug += netProfit ;
2017-07-25 03:06:40 +02:00
2017-07-13 18:54:29 +02:00
stock . playerShares -= shares ;
if ( stock . playerShares == 0 ) {
stock . playerAvgPx = 0 ;
}
2018-07-20 03:51:18 +02:00
if ( routing . isOn ( Page . StockMarket ) ) {
2017-07-13 18:54:29 +02:00
updateStockPlayerPosition ( stock ) ;
}
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . sellStock == null ) {
workerScript . scriptRef . log ( "Sold " + formatNumber ( shares , 0 ) + " shares of " + stock . symbol + " at $" +
formatNumber ( stock . price , 2 ) + " per share. Gained " +
"$" + formatNumber ( gains , 2 ) ) ;
}
2017-12-03 05:19:49 +01:00
return stock . price ;
2017-07-13 18:54:29 +02:00
} ,
2017-10-25 21:47:47 +02:00
shortStock ( symbol , shares ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "shortStock" , CONSTANTS . ScriptBuySellStockRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "shortStock" , CONSTANTS . ScriptBuySellStockRamCost ) ;
2017-10-25 21:47:47 +02:00
if ( ! Player . hasTixApiAccess ) {
throw makeRuntimeRejectMsg ( workerScript , "You don't have TIX API Access! Cannot use shortStock()" ) ;
}
if ( Player . bitNodeN !== 8 ) {
if ( ! ( hasWallStreetSF && wallStreetSFLvl >= 2 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Cannot use shortStock(). You must either be in BitNode-8 or you must have Level 2 of Source-File 8" ) ;
}
}
var stock = SymbolToStockMap [ symbol ] ;
if ( stock == null ) {
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Invalid stock symbol passed into shortStock()" ) ;
}
2017-12-03 05:19:49 +01:00
var res = shortStock ( stock , shares , workerScript ) ;
return res ? stock . price : 0 ;
2017-10-25 21:47:47 +02:00
} ,
sellShort ( symbol , shares ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "sellShort" , CONSTANTS . ScriptBuySellStockRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "sellShort" , CONSTANTS . ScriptBuySellStockRamCost ) ;
2017-10-25 21:47:47 +02:00
if ( ! Player . hasTixApiAccess ) {
throw makeRuntimeRejectMsg ( workerScript , "You don't have TIX API Access! Cannot use sellShort()" ) ;
}
if ( Player . bitNodeN !== 8 ) {
if ( ! ( hasWallStreetSF && wallStreetSFLvl >= 2 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Cannot use sellShort(). You must either be in BitNode-8 or you must have Level 2 of Source-File 8" ) ;
}
}
var stock = SymbolToStockMap [ symbol ] ;
if ( stock == null ) {
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Invalid stock symbol passed into sellShort()" ) ;
}
2017-12-03 05:19:49 +01:00
var res = sellShort ( stock , shares , workerScript ) ;
return res ? stock . price : 0 ;
2017-10-25 21:47:47 +02:00
} ,
placeOrder ( symbol , shares , price , type , pos ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "placeOrder" , CONSTANTS . ScriptBuySellStockRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "placeOrder" , CONSTANTS . ScriptBuySellStockRamCost ) ;
2017-10-25 21:47:47 +02:00
if ( ! Player . hasTixApiAccess ) {
throw makeRuntimeRejectMsg ( workerScript , "You don't have TIX API Access! Cannot use placeOrder()" ) ;
}
if ( Player . bitNodeN !== 8 ) {
if ( ! ( hasWallStreetSF && wallStreetSFLvl >= 3 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Cannot use placeOrder(). You must either be in BitNode-8 or have Level 3 of Source-File 8" ) ;
}
}
var stock = SymbolToStockMap [ symbol ] ;
if ( stock == null ) {
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Invalid stock symbol passed into placeOrder()" ) ;
}
var orderType , orderPos ;
type = type . toLowerCase ( ) ;
if ( type . includes ( "limit" ) && type . includes ( "buy" ) ) {
orderType = OrderTypes . LimitBuy ;
} else if ( type . includes ( "limit" ) && type . includes ( "sell" ) ) {
orderType = OrderTypes . LimitSell ;
} else if ( type . includes ( "stop" ) && type . includes ( "buy" ) ) {
orderType = OrderTypes . StopBuy ;
} else if ( type . includes ( "stop" ) && type . includes ( "sell" ) ) {
orderType = OrderTypes . StopSell ;
} else {
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Invalid Order Type passed into placeOrder()" ) ;
}
pos = pos . toLowerCase ( ) ;
if ( pos . includes ( "l" ) ) {
orderPos = PositionTypes . Long ;
} else if ( pos . includes ( 's' ) ) {
orderPos = PositionTypes . Short ;
} else {
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Invalid Position Type passed into placeOrder()" ) ;
}
return placeOrder ( stock , shares , price , orderType , orderPos , workerScript ) ;
} ,
cancelOrder ( symbol , shares , price , type , pos ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "cancelOrder" , CONSTANTS . ScriptBuySellStockRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "cancelOrder" , CONSTANTS . ScriptBuySellStockRamCost ) ;
2017-10-25 21:47:47 +02:00
if ( ! Player . hasTixApiAccess ) {
throw makeRuntimeRejectMsg ( workerScript , "You don't have TIX API Access! Cannot use cancelOrder()" ) ;
}
if ( Player . bitNodeN !== 8 ) {
if ( ! ( hasWallStreetSF && wallStreetSFLvl >= 3 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Cannot use cancelOrder(). You must either be in BitNode-8 or have Level 3 of Source-File 8" ) ;
}
}
var stock = SymbolToStockMap [ symbol ] ;
if ( stock == null ) {
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Invalid stock symbol passed into cancelOrder()" ) ;
}
if ( isNaN ( shares ) || isNaN ( price ) ) {
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Invalid shares or price argument passed into cancelOrder(). Must be numeric" ) ;
}
var orderType , orderPos ;
type = type . toLowerCase ( ) ;
if ( type . includes ( "limit" ) && type . includes ( "buy" ) ) {
orderType = OrderTypes . LimitBuy ;
} else if ( type . includes ( "limit" ) && type . includes ( "sell" ) ) {
orderType = OrderTypes . LimitSell ;
} else if ( type . includes ( "stop" ) && type . includes ( "buy" ) ) {
orderType = OrderTypes . StopBuy ;
} else if ( type . includes ( "stop" ) && type . includes ( "sell" ) ) {
2017-12-11 06:04:00 +01:00
orderType = OrderTypes . StopSell ;
2017-10-25 21:47:47 +02:00
} else {
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Invalid Order Type passed into placeOrder()" ) ;
}
pos = pos . toLowerCase ( ) ;
if ( pos . includes ( "l" ) ) {
orderPos = PositionTypes . Long ;
} else if ( pos . includes ( 's' ) ) {
orderPos = PositionTypes . Short ;
} else {
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Invalid Position Type passed into placeOrder()" ) ;
}
2017-12-11 06:04:00 +01:00
var params = {
2017-10-25 21:47:47 +02:00
stock : stock ,
shares : shares ,
price : price ,
type : orderType ,
pos : orderPos
} ;
return cancelOrder ( params , workerScript ) ;
} ,
2018-08-24 22:44:48 +02:00
getStockVolatility : function ( symbol ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getStockVolatility" , CONSTANTS . ScriptBuySellStockRamCost ) ;
}
updateDynamicRam ( "getStockVolatility" , CONSTANTS . ScriptBuySellStockRamCost ) ;
if ( ! Player . has4SDataTixApi ) {
throw makeRuntimeRejectMsg ( workerScript , "You don't have 4S Market Data TIX API Access! Cannot use getStockVolatility()" ) ;
}
var stock = SymbolToStockMap [ symbol ] ;
if ( stock == null ) {
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Invalid stock symbol passed into getStockVolatility()" ) ;
}
return stock . mv / 100 ; //Convert from percentage to decimal
} ,
getStockForecast : function ( symbol ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getStockForecast" , CONSTANTS . ScriptBuySellStockRamCost ) ;
}
updateDynamicRam ( "getStockForecast" , CONSTANTS . ScriptBuySellStockRamCost ) ;
if ( ! Player . has4SDataTixApi ) {
throw makeRuntimeRejectMsg ( workerScript , "You don't have 4S Market Data TIX API Access! Cannot use getStockForecast()" ) ;
}
var stock = SymbolToStockMap [ symbol ] ;
if ( stock == null ) {
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Invalid stock symbol passed into getStockForecast()" ) ;
}
var forecast = 50 ;
stock . b ? forecast += stock . otlkMag : forecast -= stock . otlkMag ;
return forecast / 100 ; //Convert from percentage to decimal
} ,
2018-11-01 19:18:32 +01:00
purchase4SMarketData : function ( ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "purchase4SMarketData" , CONSTANTS . ScriptBuySellStockRamCost ) ;
}
updateDynamicRam ( "purchase4SMarketData" , CONSTANTS . ScriptBuySellStockRamCost ) ;
if ( ! Player . hasTixApiAccess ) {
throw makeRuntimeRejectMsg ( workerScript , "You don't have TIX API Access! Cannot use purchase4SMarketData()" ) ;
}
2018-11-04 23:39:30 +01:00
if ( Player . has4SData ) {
2018-11-01 19:18:32 +01:00
if ( workerScript . shouldLog ( "purchase4SMarketData" ) ) {
workerScript . log ( "Already purchased 4S Market Data" ) ;
}
return true ;
}
if ( Player . money . lt ( CONSTANTS . MarketData4SCost ) ) {
if ( workerScript . shouldLog ( "purchase4SMarketData" ) ) {
workerScript . log ( "Failed to purchase 4S Market Data - Not enough money" ) ;
}
return false ;
}
Player . has4SData = true ;
Player . loseMoney ( CONSTANTS . MarketData4SCost ) ;
if ( workerScript . shouldLog ( "purchase4SMarketData" ) ) {
workerScript . log ( "Purchased 4S Market Data" ) ;
}
return true ;
} ,
purchase4SMarketDataTixApi : function ( ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "purchase4SMarketDataTixApi" , CONSTANTS . ScriptBuySellStockRamCost ) ;
}
updateDynamicRam ( "purchase4SMarketDataTixApi" , CONSTANTS . ScriptBuySellStockRamCost ) ;
if ( ! Player . hasTixApiAccess ) {
throw makeRuntimeRejectMsg ( workerScript , "You don't have TIX API Access! Cannot use purchase4SMarketDataTixApi()" ) ;
}
if ( Player . has4SDataTixApi ) {
if ( workerScript . shouldLog ( "purchase4SMarketDataTixApi" ) ) {
workerScript . log ( "Already purchased 4S Market Data TIX API" ) ;
}
return true ;
}
if ( Player . money . lt ( CONSTANTS . MarketDataTixApi4SCost ) ) {
if ( workerScript . shouldLog ( "purchase4SMarketDataTixApi" ) ) {
workerScript . log ( "Failed to purchase 4S Market Data TIX API - Not enough money" ) ;
}
return false ;
}
Player . has4SDataTixApi = true ;
Player . loseMoney ( CONSTANTS . MarketDataTixApi4SCost ) ;
if ( workerScript . shouldLog ( "purchase4SMarketDataTixApi" ) ) {
workerScript . log ( "Purchased 4S Market Data TIX API" ) ;
}
return true ;
} ,
2018-07-20 04:21:11 +02:00
getPurchasedServerLimit : function ( ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getPurchasedServerLimit" , CONSTANTS . ScriptGetPurchasedServerLimit ) ;
}
updateDynamicRam ( "getPurchasedServerLimit" , CONSTANTS . ScriptGetPurchasedServerLimit ) ;
2018-07-20 04:23:43 +02:00
return CONSTANTS . PurchasedServerLimit ;
2018-07-20 04:21:11 +02:00
} ,
getPurchasedServerMaxRam : function ( ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getPurchasedServerMaxRam" , CONSTANTS . ScriptGetPurchasedServerMaxRam ) ;
}
updateDynamicRam ( "getPurchasedServerMaxRam" , CONSTANTS . ScriptGetPurchasedServerMaxRam ) ;
2018-07-20 04:23:43 +02:00
return CONSTANTS . PurchasedServerMaxRam ;
2018-07-20 04:21:11 +02:00
} ,
2018-06-20 18:43:05 +02:00
getPurchasedServerCost : function ( ram ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getPurchasedServerCost" , CONSTANTS . ScriptGetPurchaseServerRamCost ) ;
}
updateDynamicRam ( "getPurchasedServerCost" , CONSTANTS . ScriptGetPurchaseServerRamCost ) ;
let cost = 0 ;
try {
cost = getPurchaseServerRamCostGuard ( ram ) ;
} catch ( e ) {
workerScript . scriptRef . log ( "ERROR: 'getPurchasedServerCost()' " + e . message ) ;
2018-11-04 23:39:30 +01:00
return Infinity ;
2018-06-20 18:43:05 +02:00
}
return cost ;
} ,
2017-07-13 18:54:29 +02:00
purchaseServer : function ( hostname , ram ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "purchaseServer" , CONSTANTS . ScriptPurchaseServerRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "purchaseServer" , CONSTANTS . ScriptPurchaseServerRamCost ) ;
2017-07-13 18:54:29 +02:00
var hostnameStr = String ( hostname ) ;
2018-03-03 22:05:33 +01:00
hostnameStr = hostnameStr . replace ( /\s+/g , '' ) ;
2017-07-13 18:54:29 +02:00
if ( hostnameStr == "" ) {
2018-06-08 17:51:48 +02:00
workerScript . scriptRef . log ( "ERROR: Passed empty string for hostname argument of purchaseServer()" ) ;
2017-07-13 18:54:29 +02:00
return "" ;
}
2017-07-25 03:06:40 +02:00
2017-07-27 04:56:14 +02:00
if ( Player . purchasedServers . length >= CONSTANTS . PurchasedServerLimit ) {
2018-06-08 17:51:48 +02:00
workerScript . scriptRef . log ( "ERROR: You have reached the maximum limit of " + CONSTANTS . PurchasedServerLimit +
2017-07-27 04:56:14 +02:00
" servers. You cannot purchase any more." ) ;
return "" ;
}
2018-06-20 18:43:05 +02:00
let cost = 0 ;
try {
cost = getPurchaseServerRamCostGuard ( ram ) ;
} catch ( e ) {
workerScript . scriptRef . log ( "ERROR: 'purchaseServer()' " + e . message ) ;
2017-07-13 18:54:29 +02:00
return "" ;
}
2017-07-25 03:06:40 +02:00
2017-07-29 18:25:40 +02:00
if ( Player . money . lt ( cost ) ) {
2018-06-08 17:51:48 +02:00
workerScript . scriptRef . log ( "ERROR: Not enough money to purchase server. Need $" + formatNumber ( cost , 2 ) ) ;
2017-07-13 18:54:29 +02:00
return "" ;
}
2018-05-06 15:23:07 +02:00
var newServ = new Server ( {
ip : createRandomIp ( ) ,
hostname : hostnameStr ,
organizationName : "" ,
isConnectedTo : false ,
adminRights : true ,
purchasedByPlayer : true ,
maxRam : ram ,
} ) ;
2017-07-13 18:54:29 +02:00
AddToAllServers ( newServ ) ;
2017-07-25 03:06:40 +02:00
2017-07-13 18:54:29 +02:00
Player . purchasedServers . push ( newServ . ip ) ;
var homeComputer = Player . getHomeComputer ( ) ;
homeComputer . serversOnNetwork . push ( newServ . ip ) ;
newServ . serversOnNetwork . push ( homeComputer . ip ) ;
Player . loseMoney ( cost ) ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . purchaseServer == null ) {
workerScript . scriptRef . log ( "Purchased new server with hostname " + newServ . hostname + " for $" + formatNumber ( cost , 2 ) ) ;
}
2017-07-13 18:54:29 +02:00
return newServ . hostname ;
2017-06-28 11:47:42 +02:00
} ,
2017-07-27 04:56:14 +02:00
deleteServer : function ( hostname ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "deleteServer" , CONSTANTS . ScriptPurchaseServerRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "deleteServer" , CONSTANTS . ScriptPurchaseServerRamCost ) ;
2017-07-27 04:56:14 +02:00
var hostnameStr = String ( hostname ) ;
hostnameStr = hostnameStr . replace ( /\s\s+/g , '' ) ;
var server = GetServerByHostname ( hostnameStr ) ;
if ( server == null ) {
2018-06-08 17:51:48 +02:00
workerScript . scriptRef . log ( "ERROR: Could not find server with hostname " + hostnameStr + ". deleteServer() failed" ) ;
2017-07-27 04:56:14 +02:00
return false ;
}
2018-05-23 02:09:04 +02:00
if ( ! server . purchasedByPlayer || server . hostname === "home" ) {
2018-06-08 17:51:48 +02:00
workerScript . scriptRef . log ( "ERROR: Server " + server . hostname + " is not a purchased server. " +
2018-05-23 02:09:04 +02:00
"Cannot be deleted. deleteServer() failed" ) ;
2017-07-27 04:56:14 +02:00
return false ;
}
2017-08-03 06:21:15 +02:00
2017-07-27 04:56:14 +02:00
var ip = server . ip ;
2018-05-23 02:09:04 +02:00
//Can't delete server you're currently connected to
if ( server . isConnectedTo ) {
2018-06-08 17:51:48 +02:00
workerScript . scriptRef . log ( "ERROR: deleteServer() failed because you are currently connected to the server you are trying to delete" ) ;
2018-05-23 02:09:04 +02:00
return false ;
}
2017-08-13 07:01:33 +02:00
//A server cannot delete itself
2018-05-23 02:09:04 +02:00
if ( ip === workerScript . serverIp ) {
2018-06-08 17:51:48 +02:00
workerScript . scriptRef . log ( "ERROR: Cannot call deleteServer() on self. deleteServer() failed" ) ;
2017-08-13 07:01:33 +02:00
return false ;
2017-08-03 06:21:15 +02:00
}
2017-08-13 07:01:33 +02:00
//Delete all scripts running on server
if ( server . runningScripts . length > 0 ) {
2018-06-08 17:51:48 +02:00
workerScript . scriptRef . log ( "ERROR: Cannot delete server " + server . hostname + " because it still has scripts running." ) ;
2017-08-13 07:01:33 +02:00
return false ;
}
2017-07-27 04:56:14 +02:00
//Delete from player's purchasedServers array
var found = false ;
for ( var i = 0 ; i < Player . purchasedServers . length ; ++ i ) {
if ( ip == Player . purchasedServers [ i ] ) {
found = true ;
Player . purchasedServers . splice ( i , 1 ) ;
break ;
}
}
if ( ! found ) {
2018-06-08 17:51:48 +02:00
workerScript . scriptRef . log ( "ERROR: Could not identify server " + server . hostname +
2017-07-27 04:56:14 +02:00
"as a purchased server. This is likely a bug please contact game dev" ) ;
return false ;
}
2017-08-13 07:01:33 +02:00
//Delete from all servers
delete AllServers [ ip ] ;
2017-07-27 04:56:14 +02:00
//Delete from home computer
found = false ;
var homeComputer = Player . getHomeComputer ( ) ;
for ( var i = 0 ; i < homeComputer . serversOnNetwork . length ; ++ i ) {
if ( ip == homeComputer . serversOnNetwork [ i ] ) {
homeComputer . serversOnNetwork . splice ( i , 1 ) ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . deleteServer == null ) {
workerScript . scriptRef . log ( "Deleted server " + hostnameStr ) ;
}
2017-07-27 04:56:14 +02:00
return true ;
}
}
//Wasn't found on home computer
2018-06-08 17:51:48 +02:00
workerScript . scriptRef . log ( "ERROR: Could not find server " + server . hostname +
2017-07-27 04:56:14 +02:00
"as a purchased server. This is likely a bug please contact game dev" ) ;
return false ;
} ,
2017-09-26 04:44:33 +02:00
getPurchasedServers : function ( hostname = true ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getPurchasedServers" , CONSTANTS . ScriptPurchaseServerRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getPurchasedServers" , CONSTANTS . ScriptPurchaseServerRamCost ) ;
2017-09-26 04:44:33 +02:00
var res = [ ] ;
Player . purchasedServers . forEach ( function ( ip ) {
if ( hostname ) {
var server = getServer ( ip ) ;
if ( server == null ) {
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Could not find server in getPurchasedServers(). This is a bug please report to game dev" ) ;
2017-09-26 04:44:33 +02:00
}
res . push ( server . hostname ) ;
} else {
res . push ( ip ) ;
}
} ) ;
return res ;
} ,
2017-10-12 04:00:22 +02:00
write : function ( port , data = "" , mode = "a" ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "write" , CONSTANTS . ScriptReadWriteRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "write" , CONSTANTS . ScriptReadWriteRamCost ) ;
2017-10-12 04:00:22 +02:00
if ( ! isNaN ( port ) ) { //Write to port
2017-07-22 00:54:55 +02:00
//Port 1-10
2018-03-03 22:05:33 +01:00
port = Math . round ( port ) ;
if ( port < 1 || port > CONSTANTS . NumNetscriptPorts ) {
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Trying to write to invalid port: " + port + ". Only ports 1-" + CONSTANTS . NumNetscriptPorts + " are valid." ) ;
2017-07-22 00:54:55 +02:00
}
2018-03-03 22:05:33 +01:00
var port = NetscriptPorts [ port - 1 ] ;
if ( port == null || ! ( port instanceof NetscriptPort ) ) {
2017-07-22 00:54:55 +02:00
throw makeRuntimeRejectMsg ( workerScript , "Could not find port: " + port + ". This is a bug contact the game developer" ) ;
}
2018-03-03 22:05:33 +01:00
return port . write ( data ) ;
2018-09-14 23:03:31 +02:00
} else if ( isString ( port ) ) { //Write to script or text file
2017-10-12 04:00:22 +02:00
var fn = port ;
2018-09-14 23:03:31 +02:00
var server = workerScript . getServer ( ) ;
2017-10-26 00:05:12 +02:00
if ( server == null ) {
2017-10-12 04:00:22 +02:00
throw makeRuntimeRejectMsg ( workerScript , "Error getting Server for this script in write(). This is a bug please contact game dev" ) ;
}
2018-09-14 23:03:31 +02:00
if ( isScriptFilename ( fn ) ) {
//Write to script
let script = workerScript . getScriptOnServer ( fn ) ;
if ( script == null ) {
//Create a new script
script = new Script ( fn , data , server . ip ) ;
server . scripts . push ( script ) ;
return true ;
}
mode === "w" ? script . code = data : script . code += data ;
script . updateRamUsage ( ) ;
2017-10-12 04:00:22 +02:00
} else {
2018-09-14 23:03:31 +02:00
//Write to text file
let txtFile = getTextFile ( fn , server ) ;
if ( txtFile == null ) {
txtFile = createTextFile ( fn , data , server ) ;
return true ;
}
if ( mode === "w" ) {
txtFile . write ( data ) ;
} else {
txtFile . append ( data ) ;
}
2017-10-12 04:00:22 +02:00
}
return true ;
2017-07-22 00:54:55 +02:00
} else {
2017-12-07 04:45:47 +01:00
throw makeRuntimeRejectMsg ( workerScript , "Invalid argument passed in for write: " + port ) ;
2017-07-22 00:54:55 +02:00
}
} ,
2018-08-30 22:27:47 +02:00
tryWrite : function ( port , data = "" ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "tryWrite" , CONSTANTS . ScriptReadWriteRamCost ) ;
}
updateDynamicRam ( "tryWrite" , CONSTANTS . ScriptReadWriteRamCost ) ;
if ( ! isNaN ( port ) ) {
port = Math . round ( port ) ;
if ( port < 1 || port > CONSTANTS . NumNetscriptPorts ) {
throw makeRuntimeRejectMsg ( workerScript , "ERROR: tryWrite() called on invalid port: " + port + ". Only ports 1-" + CONSTANTS . NumNetscriptPorts + " are valid." ) ;
}
var port = NetscriptPorts [ port - 1 ] ;
if ( port == null || ! ( port instanceof NetscriptPort ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Could not find port: " + port + ". This is a bug contact the game developer" ) ;
}
return port . tryWrite ( data ) ;
} else {
throw makeRuntimeRejectMsg ( workerScript , "Invalid argument passed in for tryWrite: " + port ) ;
}
} ,
2017-07-22 00:54:55 +02:00
read : function ( port ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "read" , CONSTANTS . ScriptReadWriteRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "read" , CONSTANTS . ScriptReadWriteRamCost ) ;
2017-10-12 04:00:22 +02:00
if ( ! isNaN ( port ) ) { //Read from port
2017-07-22 00:54:55 +02:00
//Port 1-10
2018-03-03 22:05:33 +01:00
port = Math . round ( port ) ;
if ( port < 1 || port > CONSTANTS . NumNetscriptPorts ) {
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Trying to read from invalid port: " + port + ". Only ports 1-" + CONSTANTS . NumNetscriptPorts + " are valid." ) ;
2017-07-22 00:54:55 +02:00
}
2018-03-03 22:05:33 +01:00
var port = NetscriptPorts [ port - 1 ] ;
if ( port == null || ! ( port instanceof NetscriptPort ) ) {
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Could not find port: " + port + ". This is a bug contact the game developer" ) ;
2017-07-22 00:54:55 +02:00
}
2018-03-03 22:05:33 +01:00
return port . read ( ) ;
2018-09-14 23:03:31 +02:00
} else if ( isString ( port ) ) { //Read from script or text file
let fn = port ;
let server = getServer ( workerScript . serverIp ) ;
2017-10-26 00:05:12 +02:00
if ( server == null ) {
2017-10-12 04:00:22 +02:00
throw makeRuntimeRejectMsg ( workerScript , "Error getting Server for this script in read(). This is a bug please contact game dev" ) ;
}
2018-09-14 23:03:31 +02:00
if ( isScriptFilename ( fn ) ) {
//Read from script
let script = workerScript . getScriptOnServer ( fn ) ;
if ( script == null ) {
return "" ;
}
return script . code ;
2017-10-12 04:00:22 +02:00
} else {
2018-09-14 23:03:31 +02:00
//Read from text file
let txtFile = getTextFile ( fn , server ) ;
if ( txtFile !== null ) {
return txtFile . text ;
} else {
return "" ;
}
2017-10-12 04:00:22 +02:00
}
2017-07-22 00:54:55 +02:00
} else {
2017-12-07 04:45:47 +01:00
throw makeRuntimeRejectMsg ( workerScript , "Invalid argument passed in for read(): " + port ) ;
}
} ,
2018-02-24 23:55:06 +01:00
peek : function ( port ) {
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "peek" , CONSTANTS . ScriptReadWriteRamCost ) ;
2018-02-24 23:55:06 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "peek" , CONSTANTS . ScriptReadWriteRamCost ) ;
2018-03-03 22:05:33 +01:00
if ( isNaN ( port ) ) {
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "ERROR: peek() called with invalid argument. Must be a port number between 1 and " + CONSTANTS . NumNetscriptPorts ) ;
2018-02-24 23:55:06 +01:00
}
2018-03-03 22:05:33 +01:00
port = Math . round ( port ) ;
if ( port < 1 || port > CONSTANTS . NumNetscriptPorts ) {
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "ERROR: peek() called with invalid argument. Must be a port number between 1 and " + CONSTANTS . NumNetscriptPorts ) ;
2018-02-24 23:55:06 +01:00
}
2018-03-03 22:05:33 +01:00
var port = NetscriptPorts [ port - 1 ] ;
if ( port == null || ! ( port instanceof NetscriptPort ) ) {
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Could not find port: " + port + ". This is a bug contact the game developer" ) ;
2018-02-24 23:55:06 +01:00
}
2018-03-03 22:05:33 +01:00
return port . peek ( ) ;
2018-02-24 23:55:06 +01:00
} ,
2017-12-07 04:45:47 +01:00
clear : function ( port ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "clear" , CONSTANTS . ScriptReadWriteRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "clear" , CONSTANTS . ScriptReadWriteRamCost ) ;
2017-12-07 04:45:47 +01:00
if ( ! isNaN ( port ) ) { //Clear port
2018-03-03 22:05:33 +01:00
port = Math . round ( port ) ;
if ( port < 1 || port > CONSTANTS . NumNetscriptPorts ) {
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Trying to clear invalid port: " + port + ". Only ports 1-" + CONSTANTS . NumNetscriptPorts + " are valid" ) ;
2017-12-07 04:45:47 +01:00
}
2018-03-03 22:05:33 +01:00
var port = NetscriptPorts [ port - 1 ] ;
if ( port == null || ! ( port instanceof NetscriptPort ) ) {
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Could not find port: " + port + ". This is a bug contact the game developer" ) ;
2017-12-07 04:45:47 +01:00
}
2018-03-03 22:05:33 +01:00
return port . clear ( ) ;
2017-12-07 04:45:47 +01:00
} else if ( isString ( port ) ) { //Clear text file
var fn = port ;
var server = getServer ( workerScript . serverIp ) ;
if ( server == null ) {
throw makeRuntimeRejectMsg ( workerScript , "Error getting Server for this script in clear(). This is a bug please contact game dev" ) ;
}
var txtFile = getTextFile ( fn , server ) ;
if ( txtFile != null ) {
txtFile . write ( "" ) ;
}
} else {
throw makeRuntimeRejectMsg ( workerScript , "Invalid argument passed in for clear(): " + port ) ;
2017-07-22 00:54:55 +02:00
}
2017-12-07 04:45:47 +01:00
return 0 ;
2017-08-13 07:01:33 +02:00
} ,
2018-03-03 22:05:33 +01:00
getPortHandle : function ( port ) {
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getPortHandle" , CONSTANTS . ScriptReadWriteRamCost * 10 ) ;
2018-03-03 22:05:33 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getPortHandle" , CONSTANTS . ScriptReadWriteRamCost * 10 ) ;
2018-03-03 22:05:33 +01:00
if ( isNaN ( port ) ) {
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Invalid argument passed into getPortHandle(). Must be an integer between 1 and " + CONSTANTS . NumNetscriptPorts ) ;
2018-03-03 22:05:33 +01:00
}
port = Math . round ( port ) ;
if ( port < 1 || port > CONSTANTS . NumNetscriptPorts ) {
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "ERROR: getPortHandle() called with invalid port number: " + port + ". Only ports 1-" + CONSTANTS . NumNetscriptPorts + " are valid" ) ;
2018-03-03 22:05:33 +01:00
}
var port = NetscriptPorts [ port - 1 ] ;
if ( port == null || ! ( port instanceof NetscriptPort ) ) {
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "ERROR: Could not find port: " + port + ". This is a bug contact the game developer" ) ;
2018-03-03 22:05:33 +01:00
}
return port ;
} ,
2018-01-27 07:52:39 +01:00
rm : function ( fn ) {
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "rm" , CONSTANTS . ScriptReadWriteRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "rm" , CONSTANTS . ScriptReadWriteRamCost ) ;
2018-01-27 07:52:39 +01:00
var s = getServer ( workerScript . serverIp ) ;
if ( s == null ) {
throw makeRuntimeRejectMsg ( workerScript , "Error getting Server for this script in clear(). This is a bug please contact game dev" ) ;
}
if ( fn . includes ( ".exe" ) ) {
for ( var i = 0 ; i < s . programs . length ; ++ i ) {
if ( s . programs [ i ] === fn ) {
s . programs . splice ( i , 1 ) ;
return true ;
}
}
2018-05-06 00:13:35 +02:00
} else if ( isScriptFilename ( fn ) ) {
2018-01-27 07:52:39 +01:00
for ( var i = 0 ; i < s . scripts . length ; ++ i ) {
if ( s . scripts [ i ] . filename === fn ) {
//Check that the script isnt currently running
for ( var j = 0 ; j < s . runningScripts . length ; ++ j ) {
if ( s . runningScripts [ j ] . filename === fn ) {
workerScript . scriptRef . log ( "Cannot delete a script that is currently running!" ) ;
return false ;
}
}
s . scripts . splice ( i , 1 ) ;
return true ;
}
}
} else if ( fn . endsWith ( ".lit" ) ) {
for ( var i = 0 ; i < s . messages . length ; ++ i ) {
var f = s . messages [ i ] ;
if ( ! ( f instanceof Message ) && isString ( f ) && f === fn ) {
s . messages . splice ( i , 1 ) ;
return true ;
}
}
} else if ( fn . endsWith ( ".txt" ) ) {
for ( var i = 0 ; i < s . textFiles . length ; ++ i ) {
if ( s . textFiles [ i ] . fn === fn ) {
s . textFiles . splice ( i , 1 ) ;
return true ;
}
}
2018-09-23 02:25:48 +02:00
} else if ( fn . endsWith ( ".cct" ) ) {
for ( var i = 0 ; i < s . contracts . length ; ++ i ) {
if ( s . contracts [ i ] . fn === fn ) {
s . contracts . splice ( i , 1 ) ;
return true ;
}
}
2018-01-27 07:52:39 +01:00
}
return false ;
} ,
2017-08-13 07:01:33 +02:00
scriptRunning : function ( scriptname , ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "scriptRunning" , CONSTANTS . ScriptArbScriptRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "scriptRunning" , CONSTANTS . ScriptArbScriptRamCost ) ;
2017-08-13 07:01:33 +02:00
var server = getServer ( ip ) ;
if ( server == null ) {
workerScript . scriptRef . log ( "scriptRunning() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "scriptRunning() failed. Invalid IP or hostname passed in: " + ip ) ;
}
for ( var i = 0 ; i < server . runningScripts . length ; ++ i ) {
if ( server . runningScripts [ i ] . filename == scriptname ) {
return true ;
}
}
return false ;
} ,
scriptKill : function ( scriptname , ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "scriptKill" , CONSTANTS . ScriptArbScriptRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "scriptKill" , CONSTANTS . ScriptArbScriptRamCost ) ;
2017-08-13 07:01:33 +02:00
var server = getServer ( ip ) ;
if ( server == null ) {
workerScript . scriptRef . log ( "scriptKill() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "scriptKill() failed. Invalid IP or hostname passed in: " + ip ) ;
}
var suc = false ;
for ( var i = 0 ; i < server . runningScripts . length ; ++ i ) {
if ( server . runningScripts [ i ] . filename == scriptname ) {
killWorkerScript ( server . runningScripts [ i ] , server . ip ) ;
suc = true ;
}
}
return suc ;
} ,
2018-05-06 09:27:16 +02:00
getScriptName : function ( ) {
if ( workerScript . checkingRam ) { return 0 ; }
return workerScript . name ;
} ,
2018-05-09 09:21:47 +02:00
getScriptRam : function ( scriptname , ip = workerScript . serverIp ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getScriptRam" , CONSTANTS . ScriptGetScriptRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getScriptRam" , CONSTANTS . ScriptGetScriptRamCost ) ;
2017-08-13 07:01:33 +02:00
var server = getServer ( ip ) ;
if ( server == null ) {
workerScript . scriptRef . log ( "getScriptRam() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "getScriptRam() failed. Invalid IP or hostname passed in: " + ip ) ;
}
2017-08-18 19:20:51 +02:00
for ( var i = 0 ; i < server . scripts . length ; ++ i ) {
if ( server . scripts [ i ] . filename == scriptname ) {
return server . scripts [ i ] . ramUsage ;
2017-08-13 07:01:33 +02:00
}
}
return 0 ;
} ,
2018-09-11 20:56:23 +02:00
getHackTime : function ( ip , hack , int ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getHackTime" , CONSTANTS . ScriptGetHackTimeRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getHackTime" , CONSTANTS . ScriptGetHackTimeRamCost ) ;
2017-08-20 03:36:19 +02:00
var server = getServer ( ip ) ;
if ( server == null ) {
workerScript . scriptRef . log ( "getHackTime() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "getHackTime() failed. Invalid IP or hostname passed in: " + ip ) ;
}
2018-09-11 20:56:23 +02:00
return calculateHackingTime ( server , hack , int ) ; //Returns seconds
2017-08-20 03:36:19 +02:00
} ,
2018-09-11 20:56:23 +02:00
getGrowTime : function ( ip , hack , int ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getGrowTime" , CONSTANTS . ScriptGetHackTimeRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getGrowTime" , CONSTANTS . ScriptGetHackTimeRamCost ) ;
2017-08-20 03:36:19 +02:00
var server = getServer ( ip ) ;
if ( server == null ) {
workerScript . scriptRef . log ( "getGrowTime() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "getGrowTime() failed. Invalid IP or hostname passed in: " + ip ) ;
}
2018-09-11 20:56:23 +02:00
return calculateGrowTime ( server , hack , int ) ; //Returns seconds
2017-08-20 03:36:19 +02:00
} ,
2018-09-11 20:56:23 +02:00
getWeakenTime : function ( ip , hack , int ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getWeakenTime" , CONSTANTS . ScriptGetHackTimeRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getWeakenTime" , CONSTANTS . ScriptGetHackTimeRamCost ) ;
2017-08-20 03:36:19 +02:00
var server = getServer ( ip ) ;
if ( server == null ) {
workerScript . scriptRef . log ( "getWeakenTime() failed. Invalid IP or hostname passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "getWeakenTime() failed. Invalid IP or hostname passed in: " + ip ) ;
}
2018-09-11 20:56:23 +02:00
return calculateWeakenTime ( server , hack , int ) ; //Returns seconds
2017-08-21 18:59:06 +02:00
} ,
2017-09-12 01:14:51 +02:00
getScriptIncome : function ( scriptname , ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getScriptIncome" , CONSTANTS . ScriptGetScriptRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getScriptIncome" , CONSTANTS . ScriptGetScriptRamCost ) ;
2017-09-12 01:14:51 +02:00
if ( arguments . length === 0 ) {
//Get total script income
2017-09-27 17:13:42 +02:00
var res = [ ] ;
res . push ( updateActiveScriptsItems ( ) ) ;
res . push ( Player . scriptProdSinceLastAug / ( Player . playtimeSinceLastAug / 1000 ) ) ;
return res ;
2017-09-12 01:14:51 +02:00
} else {
//Get income for a particular script
var server = getServer ( ip ) ;
2017-10-26 00:05:12 +02:00
if ( server == null ) {
2017-09-12 01:14:51 +02:00
workerScript . scriptRef . log ( "getScriptIncome() failed. Invalid IP or hostnamed passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "getScriptIncome() failed. Invalid IP or hostnamed passed in: " + ip ) ;
}
var argsForScript = [ ] ;
for ( var i = 2 ; i < arguments . length ; ++ i ) {
argsForScript . push ( arguments [ i ] ) ;
}
var runningScriptObj = findRunningScript ( scriptname , argsForScript , server ) ;
if ( runningScriptObj == null ) {
2018-07-05 20:12:20 +02:00
workerScript . scriptRef . log ( "getScriptIncome() failed. No such script " + scriptname + " on " + server . hostname + " with args: " + arrayToString ( argsForScript ) ) ;
2017-09-12 01:14:51 +02:00
return - 1 ;
}
return runningScriptObj . onlineMoneyMade / runningScriptObj . onlineRunningTime ;
}
} ,
2017-09-15 16:06:59 +02:00
getScriptExpGain : function ( scriptname , ip ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getScriptExpGain" , CONSTANTS . ScriptGetScriptRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getScriptExpGain" , CONSTANTS . ScriptGetScriptRamCost ) ;
2017-09-15 16:06:59 +02:00
if ( arguments . length === 0 ) {
var total = 0 ;
for ( var i = 0 ; i < workerScripts . length ; ++ i ) {
total += ( workerScripts [ i ] . scriptRef . onlineExpGained / workerScripts [ i ] . scriptRef . onlineRunningTime ) ;
}
return total ;
} else {
//Get income for a particular script
var server = getServer ( ip ) ;
2017-10-26 00:05:12 +02:00
if ( server == null ) {
2017-09-15 16:06:59 +02:00
workerScript . scriptRef . log ( "getScriptExpGain() failed. Invalid IP or hostnamed passed in: " + ip ) ;
throw makeRuntimeRejectMsg ( workerScript , "getScriptExpGain() failed. Invalid IP or hostnamed passed in: " + ip ) ;
}
var argsForScript = [ ] ;
for ( var i = 2 ; i < arguments . length ; ++ i ) {
argsForScript . push ( arguments [ i ] ) ;
}
var runningScriptObj = findRunningScript ( scriptname , argsForScript , server ) ;
if ( runningScriptObj == null ) {
2018-07-05 20:12:20 +02:00
workerScript . scriptRef . log ( "getScriptExpGain() failed. No such script " + scriptname + " on " + server . hostname + " with args: " + arrayToString ( argsForScript ) ) ;
2017-09-15 16:06:59 +02:00
return - 1 ;
}
return runningScriptObj . onlineExpGained / runningScriptObj . onlineRunningTime ;
}
} ,
2017-09-27 17:13:42 +02:00
getTimeSinceLastAug : function ( ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getTimeSinceLastAug" , CONSTANTS . ScriptGetHackTimeRamCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getTimeSinceLastAug" , CONSTANTS . ScriptGetHackTimeRamCost ) ;
2017-09-27 17:13:42 +02:00
return Player . playtimeSinceLastAug ;
} ,
2017-11-03 04:11:14 +01:00
prompt : function ( txt ) {
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) { return 0 ; }
2017-11-02 22:47:09 +01:00
if ( yesNoBoxOpen ) {
workerScript . scriptRef . log ( "ERROR: confirm() failed because a pop-up dialog box is already open" ) ;
return false ;
}
if ( ! isString ( txt ) ) { txt = String ( txt ) ; }
var yesBtn = yesNoBoxGetYesButton ( ) , noBtn = yesNoBoxGetNoButton ( ) ;
yesBtn . innerHTML = "Yes" ;
noBtn . innerHTML = "No" ;
return new Promise ( function ( resolve , reject ) {
yesBtn . addEventListener ( "click" , ( ) => {
yesNoBoxClose ( ) ;
resolve ( true ) ;
} ) ;
noBtn . addEventListener ( "click" , ( ) => {
yesNoBoxClose ( ) ;
resolve ( false ) ;
} ) ;
yesNoBoxCreate ( txt ) ;
} ) ;
2017-11-01 23:56:30 +01:00
} ,
2018-09-27 23:49:23 +02:00
wget : async function ( url , target , ip = workerScript . serverIp ) {
2018-09-28 06:19:52 +02:00
if ( workerScript . checkingRam ) { return 0 ; }
2018-09-27 23:49:23 +02:00
if ( ! isScriptFilename ( target ) && ! target . endsWith ( ".txt" ) ) {
workerSript . log ( ` ERROR: wget() failed because of an invalid target file: ${ target } . Target file must be a script or text file ` ) ;
2018-09-28 06:45:13 +02:00
return Promise . resolve ( false ) ;
2018-09-27 23:49:23 +02:00
}
var s = safeGetServer ( ip , "wget" ) ;
2018-09-28 06:19:52 +02:00
return new Promise ( function ( resolve , reject ) {
$ . get ( url , function ( data ) {
let res ;
if ( isScriptFilename ( target ) ) {
res = s . writeToScriptFile ( target , data ) ;
} else {
res = s . writeToTextFile ( target , data ) ;
}
if ( ! res . success ) {
workerScript . log ( "ERROR: wget() failed" ) ;
return resolve ( false ) ;
}
if ( res . overwritten ) {
workerScript . log ( ` wget() successfully retrieved content and overwrote ${ target } on ${ ip } ` ) ;
return resolve ( true ) ;
}
workerScript . log ( ` wget successfully retrieved content to new file ${ target } on ${ ip } ` ) ;
return resolve ( true ) ;
} , 'text' ) . fail ( function ( e ) {
workerScript . log ( ` ERROR: wget() failed: ${ JSON . stringify ( e ) } ` ) ;
return resolve ( false )
} ) ;
2018-09-27 23:49:23 +02:00
} ) ;
} ,
2018-07-28 03:46:37 +02:00
getFavorToDonate : function ( ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getFavorToDonate" , CONSTANTS . ScriptGetFavorToDonate ) ;
}
updateDynamicRam ( "getFavorToDonate" , CONSTANTS . ScriptGetFavorToDonate ) ;
return Math . floor ( CONSTANTS . BaseFavorToDonate * BitNodeMultipliers . RepToDonateToFaction ) ;
} ,
2017-08-21 18:59:06 +02:00
/* Singularity Functions */
2017-11-01 23:56:30 +01:00
universityCourse : function ( universityName , className ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn1RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "universityCourse" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "universityCourse" , ramCost ) ;
2017-08-30 19:44:29 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 1 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run universityCourse(). It is a Singularity Function and requires SourceFile-4 (level 1) to run." ) ;
return false ;
}
}
2017-11-01 23:56:30 +01:00
if ( inMission ) {
workerScript . scriptRef . log ( "ERROR: universityCourse() failed because you are in the middle of a mission." ) ;
return ;
}
2017-08-21 18:59:06 +02:00
if ( Player . isWorking ) {
var txt = Player . singularityStopWork ( ) ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . universityCourse == null ) {
workerScript . scriptRef . log ( txt ) ;
}
2017-08-21 18:59:06 +02:00
}
2017-08-30 19:44:29 +02:00
2017-08-22 20:48:04 +02:00
var costMult , expMult ;
switch ( universityName . toLowerCase ( ) ) {
case Locations . AevumSummitUniversity . toLowerCase ( ) :
2017-08-30 19:44:29 +02:00
if ( Player . city != Locations . Aevum ) {
workerScript . scriptRef . log ( "ERROR: You cannot study at Summit University because you are not in Aevum. universityCourse() failed" ) ;
return false ;
}
2017-09-12 01:14:51 +02:00
Player . location = Locations . AevumSummitUniversity ;
2017-08-22 20:48:04 +02:00
costMult = 4 ;
expMult = 3 ;
break ;
case Locations . Sector12RothmanUniversity . toLowerCase ( ) :
2017-08-30 19:44:29 +02:00
if ( Player . city != Locations . Sector12 ) {
workerScript . scriptRef . log ( "ERROR: You cannot study at Rothman University because you are not in Sector-12. universityCourse() failed" ) ;
return false ;
}
2017-09-12 01:14:51 +02:00
Player . location = Locations . Sector12RothmanUniversity ;
2017-08-22 20:48:04 +02:00
costMult = 3 ;
expMult = 2 ;
break ;
case Locations . VolhavenZBInstituteOfTechnology . toLowerCase ( ) :
2017-08-31 07:04:23 +02:00
if ( Player . city != Locations . Volhaven ) {
2017-08-30 19:44:29 +02:00
workerScript . scriptRef . log ( "ERROR: You cannot study at ZB Institute of Technology because you are not in Volhaven. universityCourse() failed" ) ;
return false ;
}
2017-09-12 01:14:51 +02:00
Player . location = Locations . VolhavenZBInstituteOfTechnology ;
2017-08-22 20:48:04 +02:00
costMult = 5 ;
expMult = 4 ;
break ;
default :
workerScript . scriptRef . log ( "Invalid university name: " + universityName + ". universityCourse() failed" ) ;
return false ;
}
2017-08-30 19:44:29 +02:00
var task ;
2017-08-22 20:48:04 +02:00
switch ( className . toLowerCase ( ) ) {
case "Study Computer Science" . toLowerCase ( ) :
2017-08-30 19:44:29 +02:00
task = CONSTANTS . ClassStudyComputerScience ;
2017-08-22 20:48:04 +02:00
break ;
case "Data Structures" . toLowerCase ( ) :
2017-08-30 19:44:29 +02:00
task = CONSTANTS . ClassDataStructures ;
2017-08-22 20:48:04 +02:00
break ;
case "Networks" . toLowerCase ( ) :
2017-08-30 19:44:29 +02:00
task = CONSTANTS . ClassNetworks ;
2017-08-22 20:48:04 +02:00
break ;
case "Algorithms" . toLowerCase ( ) :
2017-08-30 19:44:29 +02:00
task = CONSTANTS . ClassAlgorithms ;
2017-08-22 20:48:04 +02:00
break ;
case "Management" . toLowerCase ( ) :
2017-08-30 19:44:29 +02:00
task = CONSTANTS . ClassManagement ;
2017-08-22 20:48:04 +02:00
break ;
case "Leadership" . toLowerCase ( ) :
2017-08-30 19:44:29 +02:00
task = CONSTANTS . ClassLeadership ;
2017-08-22 20:48:04 +02:00
break ;
default :
workerScript . scriptRef . log ( "Invalid class name: " + className + ". universityCourse() failed" ) ;
2017-08-30 19:44:29 +02:00
return false ;
}
Player . startClass ( costMult , expMult , task ) ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . universityCourse == null ) {
workerScript . scriptRef . log ( "Started " + task + " at " + universityName ) ;
}
2017-08-30 19:44:29 +02:00
return true ;
} ,
2017-11-01 23:56:30 +01:00
gymWorkout : function ( gymName , stat ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn1RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "gymWorkout" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "gymWorkout" , ramCost ) ;
2017-08-30 19:44:29 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 1 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run gymWorkout(). It is a Singularity Function and requires SourceFile-4 (level 1) to run." ) ;
return false ;
}
}
2017-11-01 23:56:30 +01:00
if ( inMission ) {
2017-11-03 04:32:31 +01:00
workerScript . scriptRef . log ( "ERROR: gymWorkout() failed because you are in the middle of a mission." ) ;
2017-11-01 23:56:30 +01:00
return ;
}
2017-08-30 19:44:29 +02:00
if ( Player . isWorking ) {
var txt = Player . singularityStopWork ( ) ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . gymWorkout == null ) {
workerScript . scriptRef . log ( txt ) ;
}
2017-08-30 19:44:29 +02:00
}
var costMult , expMult ;
switch ( gymName . toLowerCase ( ) ) {
case Locations . AevumCrushFitnessGym . toLowerCase ( ) :
if ( Player . city != Locations . Aevum ) {
workerScript . scriptRef . log ( "ERROR: You cannot workout at Crush Fitness because you are not in Aevum. gymWorkout() failed" ) ;
return false ;
}
2017-09-12 01:14:51 +02:00
Player . location = Locations . AevumCrushFitnessGym ;
2018-05-23 02:09:04 +02:00
costMult = 3 ;
expMult = 2 ;
2017-08-30 19:44:29 +02:00
break ;
case Locations . AevumSnapFitnessGym . toLowerCase ( ) :
if ( Player . city != Locations . Aevum ) {
workerScript . scriptRef . log ( "ERROR: You cannot workout at Snap Fitness because you are not in Aevum. gymWorkout() failed" ) ;
return false ;
}
2017-09-12 01:14:51 +02:00
Player . location = Locations . AevumSnapFitnessGym ;
2018-05-23 02:09:04 +02:00
costMult = 10 ;
expMult = 5 ;
2017-08-30 19:44:29 +02:00
break ;
case Locations . Sector12IronGym . toLowerCase ( ) :
if ( Player . city != Locations . Sector12 ) {
workerScript . scriptRef . log ( "ERROR: You cannot workout at Iron Gym because you are not in Sector-12. gymWorkout() failed" ) ;
return false ;
}
2017-09-12 01:14:51 +02:00
Player . location = Locations . Sector12IronGym ;
2017-08-30 19:44:29 +02:00
costMult = 1 ;
expMult = 1 ;
break ;
case Locations . Sector12PowerhouseGym . toLowerCase ( ) :
if ( Player . city != Locations . Sector12 ) {
workerScript . scriptRef . log ( "ERROR: You cannot workout at Powerhouse Gym because you are not in Sector-12. gymWorkout() failed" ) ;
return false ;
}
2017-09-12 01:14:51 +02:00
Player . location = Locations . Sector12PowerhouseGym ;
2018-05-23 02:09:04 +02:00
costMult = 20 ;
expMult = 10 ;
2017-08-30 19:44:29 +02:00
break ;
2017-08-30 20:36:59 +02:00
case Locations . VolhavenMilleniumFitnessGym :
if ( Player . city != Locations . Volhaven ) {
workerScript . scriptRef . log ( "ERROR: You cannot workout at Millenium Fitness Gym because you are not in Volhaven. gymWorkout() failed" ) ;
return false ;
}
2017-09-12 01:14:51 +02:00
Player . location = Locations . VolhavenMilleniumFitnessGym ;
2018-05-23 02:09:04 +02:00
costMult = 7 ;
expMult = 4 ;
2017-08-30 20:36:59 +02:00
break ;
2017-08-30 19:44:29 +02:00
default :
workerScript . scriptRef . log ( "Invalid gym name: " + gymName + ". gymWorkout() failed" ) ;
return false ;
}
switch ( stat . toLowerCase ( ) ) {
case "strength" . toLowerCase ( ) :
case "str" . toLowerCase ( ) :
Player . startClass ( costMult , expMult , CONSTANTS . ClassGymStrength ) ;
break ;
case "defense" . toLowerCase ( ) :
case "def" . toLowerCase ( ) :
Player . startClass ( costMult , expMult , CONSTANTS . ClassGymDefense ) ;
break ;
case "dexterity" . toLowerCase ( ) :
case "dex" . toLowerCase ( ) :
Player . startClass ( costMult , expMult , CONSTANTS . ClassGymDexterity ) ;
break ;
case "agility" . toLowerCase ( ) :
case "agi" . toLowerCase ( ) :
Player . startClass ( costMult , expMult , CONSTANTS . ClassGymAgility ) ;
break ;
default :
workerScript . scriptRef . log ( "Invalid stat: " + stat + ". gymWorkout() failed" ) ;
return false ;
}
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . gymWorkout == null ) {
workerScript . scriptRef . log ( "Started training " + stat + " at " + gymName ) ;
}
2017-08-30 19:44:29 +02:00
return true ;
} ,
travelToCity ( cityname ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn1RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "travelToCity" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "travelToCity" , ramCost ) ;
2017-08-30 19:44:29 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 1 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run travelToCity(). It is a Singularity Function and requires SourceFile-4 (level 1) to run." ) ;
return false ;
}
}
switch ( cityname ) {
case Locations . Aevum :
case Locations . Chongqing :
case Locations . Sector12 :
case Locations . NewTokyo :
case Locations . Ishima :
case Locations . Volhaven :
2018-06-04 03:09:12 +02:00
if ( Player . money . lt ( CONSTANTS . TravelCost ) ) {
workerScript . scriptRef . log ( "ERROR: not enough money to travel with travelToCity()." ) ;
throw makeRuntimeRejectMsg ( workerScript , "ERROR: not enough money to travel with travelToCity()." ) ;
}
Player . loseMoney ( CONSTANTS . TravelCost ) ;
2017-08-30 19:44:29 +02:00
Player . city = cityname ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . travelToCity == null ) {
workerScript . scriptRef . log ( "Traveled to " + cityname ) ;
}
2017-08-30 19:44:29 +02:00
return true ;
default :
workerScript . scriptRef . log ( "ERROR: Invalid city name passed into travelToCity()." ) ;
return false ;
}
} ,
purchaseTor ( ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn1RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "purchaseTor" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "purchaseTor" , ramCost ) ;
2017-08-30 19:44:29 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 1 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run purchaseTor(). It is a Singularity Function and requires SourceFile-4 (level 1) to run." ) ;
return false ;
}
}
if ( SpecialServerIps [ "Darkweb Server" ] != null ) {
workerScript . scriptRef . log ( "You already have a TOR router! purchaseTor() failed" ) ;
return false ;
}
if ( Player . money . lt ( CONSTANTS . TorRouterCost ) ) {
workerScript . scriptRef . log ( "ERROR: You cannot afford to purchase a Tor router. purchaseTor() failed" ) ;
return false ;
}
Player . loseMoney ( CONSTANTS . TorRouterCost ) ;
2018-05-06 23:20:00 +02:00
var darkweb = new Server ( {
ip : createRandomIp ( ) , hostname : "darkweb" , organizationName : "" ,
isConnectedTo : false , adminRights : false , purchasedByPlayer : false , maxRam : 1
} ) ;
2017-08-30 19:44:29 +02:00
AddToAllServers ( darkweb ) ;
SpecialServerIps . addIp ( "Darkweb Server" , darkweb . ip ) ;
2018-06-14 21:51:06 +02:00
const purchaseTor = document . getElementById ( "location-purchase-tor" ) ;
purchaseTor . setAttribute ( "class" , "a-link-button-bought" ) ;
purchaseTor . innerHTML = "TOR Router - Purchased" ;
2017-08-30 19:44:29 +02:00
Player . getHomeComputer ( ) . serversOnNetwork . push ( darkweb . ip ) ;
darkweb . serversOnNetwork . push ( Player . getHomeComputer ( ) . ip ) ;
2017-09-19 20:38:03 +02:00
Player . gainIntelligenceExp ( CONSTANTS . IntelligenceSingFnBaseExpGain ) ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . purchaseTor == null ) {
workerScript . scriptRef . log ( "You have purchased a Tor router!" ) ;
}
2017-08-30 19:44:29 +02:00
return true ;
} ,
purchaseProgram ( programName ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn1RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "purchaseProgram" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "purchaseProgram" , ramCost ) ;
2017-08-30 19:44:29 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 1 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run purchaseProgram(). It is a Singularity Function and requires SourceFile-4 (level 1) to run." ) ;
return false ;
}
}
if ( SpecialServerIps [ "Darkweb Server" ] == null ) {
2018-06-01 23:05:05 +02:00
workerScript . scriptRef . log ( "ERROR: You do not have the TOR router. purchaseProgram() failed." ) ;
2017-08-30 19:44:29 +02:00
return false ;
}
2018-06-01 23:05:05 +02:00
programName = programName . toLowerCase ( ) ;
let item = null ;
for ( const key in DarkWebItems ) {
const i = DarkWebItems [ key ] ;
if ( i . program . toLowerCase ( ) == programName ) {
item = i ;
}
}
if ( item == null ) {
workerScript . scriptRef . log ( "ERROR: Invalid program name passed into purchaseProgram()." ) ;
return false ;
}
if ( Player . money . lt ( item . price ) ) {
workerScript . scriptRef . log ( "Not enough money to purchase " + item . program ) ;
return false ;
}
if ( Player . hasProgram ( item . program ) ) {
workerScript . scriptRef . log ( 'You already have the ' + item . program + ' program' ) ;
return true ;
}
Player . loseMoney ( item . price ) ;
Player . getHomeComputer ( ) . programs . push ( item . program ) ;
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . purchaseProgram == null ) {
workerScript . scriptRef . log ( "You have purchased the " + item . program + " program. The new program can be found on your home computer." ) ;
2017-08-30 19:44:29 +02:00
}
return true ;
} ,
2017-10-12 04:00:22 +02:00
getStats : function ( ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn1RamCost / 4 ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getStats" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getStats" , ramCost ) ;
2017-10-12 04:00:22 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 1 ) ) {
2017-10-16 04:09:49 +02:00
throw makeRuntimeRejectMsg ( workerScript , "Cannot run getStats(). It is a Singularity Function and requires SourceFile-4 (level 1) to run." ) ;
2017-10-12 04:00:22 +02:00
return { } ;
}
}
return {
hacking : Player . hacking _skill ,
strength : Player . strength ,
defense : Player . defense ,
dexterity : Player . dexterity ,
agility : Player . agility ,
charisma : Player . charisma ,
intelligence : Player . intelligence
}
} ,
2018-03-03 22:05:33 +01:00
getCharacterInformation : function ( ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn1RamCost / 4 ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-03-03 22:05:33 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getCharacterInformation" , ramCost ) ;
2018-03-03 22:05:33 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getCharacterInformation" , ramCost ) ;
2018-03-03 22:05:33 +01:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 1 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run getCharacterInformation(). It is a Singularity Function and requires SourceFile-4 (level 1) to run." ) ;
return { } ;
}
}
var companyPositionTitle = "" ;
if ( Player . companyPosition instanceof CompanyPosition ) {
companyPositionTitle = Player . companyPosition . positionName ;
}
return {
bitnode : Player . bitNodeN ,
city : Player . city ,
2018-10-26 19:37:28 +02:00
company : Player . companyName ,
2018-03-03 22:05:33 +01:00
factions : Player . factions . slice ( ) ,
2018-10-26 19:37:28 +02:00
jobTitle : companyPositionTitle ,
2018-10-26 22:51:45 +02:00
mult : {
2018-10-26 19:37:28 +02:00
agility : Player . agility _mult ,
agilityExp : Player . agility _exp _mult ,
companyRep : Player . company _rep _mult ,
crimeMoney : Player . crime _money _mult ,
crimeSuccess : Player . crime _success _mult ,
defense : Player . defense _mult ,
defenseExp : Player . defense _exp _mult ,
dexterity : Player . dexterity _mult ,
dexterityExp : Player . dexterity _exp _mult ,
factionRep : Player . faction _rep _mult ,
hacking : Player . hacking _mult ,
hackingExp : Player . hacking _exp _mult ,
strength : Player . strength _mult ,
strengthExp : Player . strength _exp _mult ,
workMoney : Player . work _money _mult ,
} ,
2018-03-03 22:05:33 +01:00
timeWorked : Player . timeWorked ,
2018-10-26 19:37:28 +02:00
tor : SpecialServerIps . hasOwnProperty ( "Darkweb Server" ) ,
2018-03-03 22:05:33 +01:00
workHackExpGain : Player . workHackExpGained ,
workStrExpGain : Player . workStrExpGained ,
workDefExpGain : Player . workDefExpGained ,
workDexExpGain : Player . workDexExpGained ,
workAgiExpGain : Player . workAgiExpGained ,
workChaExpGain : Player . workChaExpGained ,
workRepGain : Player . workRepGained ,
workMoneyGain : Player . workMoneyGained ,
} ;
} ,
2017-10-16 04:09:49 +02:00
isBusy : function ( ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn1RamCost / 4 ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "isBusy" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "isBusy" , ramCost ) ;
2017-10-16 04:09:49 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 1 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run isBusy(). It is a Singularity Function and requires SourceFile-4 (level 1) to run." ) ;
return ;
}
}
return Player . isWorking ;
} ,
2018-02-15 05:26:43 +01:00
stopAction : function ( ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn1RamCost / 2 ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-02-15 05:26:43 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "stopAction" , ramCost ) ;
2018-02-15 05:26:43 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "stopAction" , ramCost ) ;
2018-03-03 22:05:33 +01:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 1 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run stopAction(). It is a Singularity Function and requires SourceFile-4 (level 1) to run." ) ;
return false ;
}
}
2018-02-15 05:26:43 +01:00
if ( Player . isWorking ) {
var txt = Player . singularityStopWork ( ) ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . stopAction == null ) {
workerScript . scriptRef . log ( txt ) ;
}
2018-02-15 05:26:43 +01:00
return true ;
}
return false ;
} ,
2018-03-03 22:05:33 +01:00
upgradeHomeRam : function ( ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn2RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "upgradeHomeRam" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "upgradeHomeRam" , ramCost ) ;
2017-08-30 19:44:29 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 2 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run upgradeHomeRam(). It is a Singularity Function and requires SourceFile-4 (level 2) to run." ) ;
return false ;
}
}
2018-06-07 20:54:34 +02:00
const cost = Player . getUpgradeHomeRamCost ( ) ;
2017-08-30 19:44:29 +02:00
if ( Player . money . lt ( cost ) ) {
2017-08-31 07:04:23 +02:00
workerScript . scriptRef . log ( "ERROR: upgradeHomeRam() failed because you don't have enough money" ) ;
2017-08-30 19:44:29 +02:00
return false ;
}
var homeComputer = Player . getHomeComputer ( ) ;
homeComputer . maxRam *= 2 ;
Player . loseMoney ( cost ) ;
2017-09-19 20:38:03 +02:00
Player . gainIntelligenceExp ( CONSTANTS . IntelligenceSingFnBaseExpGain ) ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . upgradeHomeRam == null ) {
workerScript . scriptRef . log ( "Purchased additional RAM for home computer! It now has " + homeComputer . maxRam + "GB of RAM." ) ;
}
2017-08-30 19:44:29 +02:00
return true ;
} ,
2018-03-03 22:05:33 +01:00
getUpgradeHomeRamCost : function ( ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn2RamCost / 2 ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getUpgradeHomeRamCost" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getUpgradeHomeRamCost" , ramCost ) ;
2017-08-30 19:44:29 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 2 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run getUpgradeHomeRamCost(). It is a Singularity Function and requires SourceFile-4 (level 2) to run." ) ;
return false ;
}
}
2018-06-07 20:54:34 +02:00
return Player . getUpgradeHomeRamCost ( ) ;
2017-08-30 19:44:29 +02:00
} ,
2018-03-03 22:05:33 +01:00
workForCompany : function ( ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn2RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "workForCompany" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "workForCompany" , ramCost ) ;
2017-08-30 19:44:29 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 2 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run workForCompany(). It is a Singularity Function and requires SourceFile-4 (level 2) to run." ) ;
return false ;
}
}
2017-11-01 23:56:30 +01:00
if ( inMission ) {
2017-11-03 04:32:31 +01:00
workerScript . scriptRef . log ( "ERROR: workForCompany() failed because you are in the middle of a mission." ) ;
2017-11-01 23:56:30 +01:00
return ;
}
2017-08-30 19:44:29 +02:00
if ( Player . companyPosition == "" || ! ( Player . companyPosition instanceof CompanyPosition ) ) {
workerScript . scriptRef . log ( "ERROR: workForCompany() failed because you do not have a job" ) ;
return false ;
}
if ( Player . isWorking ) {
var txt = Player . singularityStopWork ( ) ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . workForCompany == null ) {
workerScript . scriptRef . log ( txt ) ;
}
2017-08-30 19:44:29 +02:00
}
if ( Player . companyPosition . isPartTimeJob ( ) ) {
Player . startWorkPartTime ( ) ;
} else {
Player . startWork ( ) ;
}
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . workForCompany == null ) {
workerScript . scriptRef . log ( "Began working at " + Player . companyName + " as a " + Player . companyPosition . positionName ) ;
}
2017-08-30 19:44:29 +02:00
return true ;
} ,
2018-03-03 22:05:33 +01:00
applyToCompany : function ( companyName , field ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn2RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "applyToCompany" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "applyToCompany" , ramCost ) ;
2017-08-30 19:44:29 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 2 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run applyToCompany(). It is a Singularity Function and requires SourceFile-4 (level 2) to run." ) ;
return false ;
}
}
2017-08-30 20:36:59 +02:00
if ( ! companyExists ( companyName ) ) {
2017-08-31 07:04:23 +02:00
workerScript . scriptRef . log ( "ERROR: applyToCompany() failed because specified company " + companyName + " does not exist." ) ;
2017-08-30 20:36:59 +02:00
return false ;
}
2017-08-30 19:44:29 +02:00
Player . location = companyName ;
var res ;
switch ( field . toLowerCase ( ) ) {
case "software" :
res = Player . applyForSoftwareJob ( true ) ;
break ;
case "software consultant" :
res = Player . applyForSoftwareConsultantJob ( true ) ;
break ;
case "it" :
res = Player . applyForItJob ( true ) ;
break ;
case "security engineer" :
res = Player . applyForSecurityEngineerJob ( true ) ;
break ;
case "network engineer" :
res = Player . applyForNetworkEngineerJob ( true ) ;
break ;
case "business" :
res = Player . applyForBusinessJob ( true ) ;
2017-08-22 20:48:04 +02:00
break ;
2017-08-30 19:44:29 +02:00
case "business consultant" :
res = Player . applyForBusinessConsultantJob ( true ) ;
break ;
case "security" :
res = Player . applyForSecurityJob ( true ) ;
break ;
case "agent" :
res = Player . applyForAgentJob ( true ) ;
break ;
case "employee" :
res = Player . applyForEmployeeJob ( true ) ;
break ;
case "part-time employee" :
res = Player . applyForPartTimeEmployeeJob ( true ) ;
break ;
case "waiter" :
res = Player . applyForWaiterJob ( true ) ;
break ;
case "part-time waiter" :
res = Player . applyForPartTimeWaiterJob ( true ) ;
break ;
default :
workerScript . scriptRef . log ( "ERROR: Invalid job passed into applyToCompany: " + field + ". applyToCompany() failed" ) ;
return false ;
2017-08-22 20:48:04 +02:00
}
2017-08-30 19:44:29 +02:00
//The Player object's applyForJob function can return string with special error messages
if ( isString ( res ) ) {
workerScript . scriptRef . log ( res ) ;
return false ;
}
if ( res ) {
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . applyToCompany == null ) {
workerScript . scriptRef . log ( "You were offered a new job at " + companyName + " as a " + Player . companyPosition . positionName ) ;
}
2017-08-30 19:44:29 +02:00
} else {
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . applyToCompany == null ) {
workerScript . scriptRef . log ( "You failed to get a new job/promotion at " + companyName + " in the " + field + " field." ) ;
}
2017-08-30 19:44:29 +02:00
}
return res ;
2017-08-21 18:59:06 +02:00
} ,
2018-03-03 22:05:33 +01:00
getCompanyRep : function ( companyName ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn2RamCost / 2 ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getCompanyRep" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getCompanyRep" , ramCost ) ;
2017-08-30 19:44:29 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 2 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run getCompanyRep(). It is a Singularity Function and requires SourceFile-4 (level 2) to run." ) ;
return false ;
}
}
var company = Companies [ companyName ] ;
2017-10-26 00:05:12 +02:00
if ( company == null || ! ( company instanceof Company ) ) {
2017-08-30 19:44:29 +02:00
workerScript . scriptRef . log ( "ERROR: Invalid companyName passed into getCompanyRep(): " + companyName ) ;
return - 1 ;
}
return company . playerReputation ;
} ,
2018-03-03 22:05:33 +01:00
getCompanyFavor : function ( companyName ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn2RamCost / 4 ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-03-03 22:05:33 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getCompanyFavor" , ramCost ) ;
2018-03-03 22:05:33 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getCompanyFavor" , ramCost ) ;
2018-03-03 22:05:33 +01:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 2 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run getCompanyFavor(). It is a Singularity Function and requires SourceFile-4 (level 2) to run." ) ;
return false ;
}
}
var company = Companies [ companyName ] ;
if ( company == null || ! ( company instanceof Company ) ) {
workerScript . scriptRef . log ( "ERROR: Invalid companyName passed into getCompanyFavor(): " + companyName ) ;
return - 1 ;
}
return company . favor ;
} ,
2018-07-28 03:46:37 +02:00
getCompanyFavorGain : function ( companyName ) {
var ramCost = CONSTANTS . ScriptSingularityFn2RamCost / 4 ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-07-28 03:46:37 +02:00
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getCompanyFavorGain" , ramCost ) ;
}
updateDynamicRam ( "getCompanyFavorGain" , ramCost ) ;
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 2 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run getCompanyFavorGain(). It is a Singularity Function and requires SourceFile-4 (level 2) to run." ) ;
return - 1 ;
}
}
var company = Companies [ companyName ] ;
if ( company == null || ! ( company instanceof Company ) ) {
workerScript . scriptRef . log ( "ERROR: Invalid companyName passed into getCompanyFavorGain(): " + companyName ) ;
return - 1 ;
}
return company . getFavorGain ( ) [ 0 ] ;
} ,
2018-03-03 22:05:33 +01:00
checkFactionInvitations : function ( ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn2RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "checkFactionInvitations" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "checkFactionInvitations" , ramCost ) ;
2017-08-30 19:44:29 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 2 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run checkFactionInvitations(). It is a Singularity Function and requires SourceFile-4 (level 2) to run." ) ;
return false ;
}
}
//Make a copy of Player.factionInvitations
return Player . factionInvitations . slice ( ) ;
} ,
2018-03-03 22:05:33 +01:00
joinFaction : function ( name ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn2RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "joinFaction" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "joinFaction" , ramCost ) ;
2017-08-30 19:44:29 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 2 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run joinFaction(). It is a Singularity Function and requires SourceFile-4 (level 2) to run." ) ;
return false ;
}
}
2017-08-21 18:59:06 +02:00
2017-08-30 19:44:29 +02:00
if ( ! factionExists ( name ) ) {
workerScript . scriptRef . log ( "ERROR: Faction specified in joinFaction() does not exist." ) ;
return false ;
}
2017-08-21 18:59:06 +02:00
2017-08-30 19:44:29 +02:00
if ( ! Player . factionInvitations . includes ( name ) ) {
workerScript . scriptRef . log ( "ERROR: Cannot join " + name + " Faction because you have not been invited. joinFaction() failed" ) ;
return false ;
}
var fac = Factions [ name ] ;
joinFaction ( fac ) ;
2018-08-26 06:26:42 +02:00
//Update Faction Invitation list to account for joined + banned factions
for ( var i = 0 ; i < Player . factionInvitations . length ; ++ i ) {
if ( Player . factionInvitations [ i ] == name || Factions [ Player . factionInvitations [ i ] ] . isBanned ) {
Player . factionInvitations . splice ( i , 1 ) ;
i -- ;
}
}
2017-09-19 20:38:03 +02:00
Player . gainIntelligenceExp ( CONSTANTS . IntelligenceSingFnBaseExpGain ) ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . joinFaction == null ) {
workerScript . scriptRef . log ( "Joined the " + name + " faction." ) ;
}
2017-08-30 19:44:29 +02:00
return true ;
} ,
2018-03-03 22:05:33 +01:00
workForFaction : function ( name , type ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn2RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "workForFaction" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "workForFaction" , ramCost ) ;
2017-08-30 19:44:29 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 2 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run workForFaction(). It is a Singularity Function and requires SourceFile-4 (level 2) to run." ) ;
return false ;
}
}
2017-08-21 18:59:06 +02:00
2018-06-10 06:55:25 +02:00
// if the player is in a gang and the target faction is any of the gang faction, fail
2018-06-14 21:51:06 +02:00
if ( Player . inGang ( ) && AllGangs [ name ] !== undefined ) {
2018-06-10 06:55:25 +02:00
workerScript . scriptRef . log ( "ERROR: Faction specified in workForFaction() does not offer work at the moment." ) ;
return ;
}
2017-11-01 23:56:30 +01:00
if ( inMission ) {
2017-11-03 04:32:31 +01:00
workerScript . scriptRef . log ( "ERROR: workForFaction() failed because you are in the middle of a mission." ) ;
2017-11-01 23:56:30 +01:00
return ;
}
2017-08-30 19:44:29 +02:00
if ( ! factionExists ( name ) ) {
workerScript . scriptRef . log ( "ERROR: Faction specified in workForFaction() does not exist." ) ;
return false ;
}
2017-08-21 18:59:06 +02:00
2017-08-30 20:36:59 +02:00
if ( ! Player . factions . includes ( name ) ) {
workerScript . scriptRef . log ( "ERROR: workForFaction() failed because you are not a member of " + name ) ;
return false ;
}
2017-08-30 19:44:29 +02:00
if ( Player . isWorking ) {
var txt = Player . singularityStopWork ( ) ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . workForFaction == null ) {
workerScript . scriptRef . log ( txt ) ;
}
2017-08-30 19:44:29 +02:00
}
2017-08-21 18:59:06 +02:00
2017-08-30 19:44:29 +02:00
var fac = Factions [ name ] ;
//Arrays listing factions that allow each time of work
var hackAvailable = [ "Illuminati" , "Daedalus" , "The Covenant" , "ECorp" , "MegaCorp" ,
"Bachman & Associates" , "Blade Industries" , "NWO" , "Clarke Incorporated" ,
"OmniTek Incorporated" , "Four Sigma" , "KuaiGong International" ,
"Fulcrum Secret Technologies" , "BitRunners" , "The Black Hand" ,
"NiteSec" , "Chongqing" , "Sector-12" , "New Tokyo" , "Aevum" ,
"Ishima" , "Volhaven" , "Speakers for the Dead" , "The Dark Army" ,
"The Syndicate" , "Silhouette" , "Netburners" , "Tian Di Hui" , "CyberSec" ] ;
var fdWkAvailable = [ "Illuminati" , "Daedalus" , "The Covenant" , "ECorp" , "MegaCorp" ,
"Bachman & Associates" , "Blade Industries" , "NWO" , "Clarke Incorporated" ,
"OmniTek Incorporated" , "Four Sigma" , "KuaiGong International" ,
"The Black Hand" , "Chongqing" , "Sector-12" , "New Tokyo" , "Aevum" ,
"Ishima" , "Volhaven" , "Speakers for the Dead" , "The Dark Army" ,
"The Syndicate" , "Silhouette" , "Tetrads" , "Slum Snakes" ] ;
var scWkAvailable = [ "ECorp" , "MegaCorp" ,
"Bachman & Associates" , "Blade Industries" , "NWO" , "Clarke Incorporated" ,
"OmniTek Incorporated" , "Four Sigma" , "KuaiGong International" ,
"Fulcrum Secret Technologies" , "Chongqing" , "Sector-12" , "New Tokyo" , "Aevum" ,
"Ishima" , "Volhaven" , "Speakers for the Dead" ,
"The Syndicate" , "Tetrads" , "Slum Snakes" , "Tian Di Hui" ] ;
2017-08-21 18:59:06 +02:00
2017-08-30 19:44:29 +02:00
switch ( type . toLowerCase ( ) ) {
case "hacking" :
case "hacking contracts" :
case "hackingcontracts" :
if ( ! hackAvailable . includes ( fac . name ) ) {
workerScript . scriptRef . log ( "ERROR: Cannot carry out hacking contracts for " + fac . name + ". workForFaction() failed" ) ;
return false ;
}
Player . startFactionHackWork ( fac ) ;
workerScript . scriptRef . log ( "Started carrying out hacking contracts for " + fac . name ) ;
return true ;
case "field" :
case "fieldwork" :
case "field work" :
if ( ! fdWkAvailable . includes ( fac . name ) ) {
workerScript . scriptRef . log ( "ERROR: Cannot carry out field missions for " + fac . name + ". workForFaction() failed" ) ;
return false ;
}
Player . startFactionFieldWork ( fac ) ;
workerScript . scriptRef . log ( "Started carrying out field missions for " + fac . name ) ;
return true ;
case "security" :
case "securitywork" :
case "security work" :
if ( ! scWkAvailable . includes ( fac . name ) ) {
workerScript . scriptRef . log ( "ERROR: Cannot serve as security detail for " + fac . name + ". workForFaction() failed" ) ;
return false ;
}
Player . startFactionSecurityWork ( fac ) ;
workerScript . scriptRef . log ( "Started serving as security details for " + fac . name ) ;
return true ;
default :
workerScript . scriptRef . log ( "ERROR: Invalid work type passed into workForFaction(): " + type ) ;
}
2017-08-30 20:36:59 +02:00
return true ;
2017-08-30 19:44:29 +02:00
} ,
2018-03-03 22:05:33 +01:00
getFactionRep : function ( name ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn2RamCost / 4 ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getFactionRep" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getFactionRep" , ramCost ) ;
2017-08-30 19:44:29 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 2 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run getFactionRep(). It is a Singularity Function and requires SourceFile-4 (level 2) to run." ) ;
return - 1 ;
}
}
if ( ! factionExists ( name ) ) {
workerScript . scriptRef . log ( "ERROR: Faction specified in getFactionRep() does not exist." ) ;
return - 1 ;
}
2017-08-21 18:59:06 +02:00
2017-08-30 19:44:29 +02:00
return Factions [ name ] . playerReputation ;
} ,
2018-03-03 22:05:33 +01:00
getFactionFavor : function ( name ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn2RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-03-03 22:05:33 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getFactionFavor" , ramCost ) ;
2018-03-03 22:05:33 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getFactionFavor" , ramCost ) ;
2018-03-03 22:05:33 +01:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 2 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run getFactionFavor(). It is a Singularity Function and requires SourceFile-4 (level 2) to run." ) ;
return - 1 ;
}
}
if ( ! factionExists ( name ) ) {
workerScript . scriptRef . log ( "ERROR: Faction specified in getFactionFavor() does not exist." ) ;
return - 1 ;
}
return Factions [ name ] . favor ;
} ,
2018-09-11 20:56:23 +02:00
getFactionFavorGain : function ( name ) {
2018-07-28 03:46:37 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn2RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-07-28 03:46:37 +02:00
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getFactionFavorGain" , ramCost ) ;
}
updateDynamicRam ( "getFactionFavorGain" , ramCost ) ;
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 2 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run getFactionFavorGain(). It is a Singularity Function and requires SourceFile-4 (level 2) to run." ) ;
return - 1 ;
}
}
if ( ! factionExists ( name ) ) {
workerScript . scriptRef . log ( "ERROR: Faction specified in getFactionFavorGain() does not exist." ) ;
return - 1 ;
}
return Factions [ name ] . getFavorGain ( ) [ 0 ] ;
} ,
2018-09-11 20:56:23 +02:00
donateToFaction : function ( name , amt ) {
var ramCost = CONSTANTS . ScriptSingularityFn3RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-09-11 20:56:23 +02:00
if ( workerScript . checkingRam ) {
return updateStaticRam ( "donateToFaction" , ramCost ) ;
}
updateDynamicRam ( "donateToFaction" , ramCost ) ;
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 3 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run donateToFaction(). It is a Singularity Function and requires SourceFile-4 (level 3) to run." ) ;
return ;
}
}
if ( ! factionExists ( name ) ) {
workerScript . log ( ` ERROR: Faction specified in donateToFaction() does not exist: ${ name } ` ) ;
return false ;
}
if ( typeof amt !== 'number' || amt <= 0 ) {
workerScript . log ( ` ERROR: Invalid donation amount specified in donateToFaction(): ${ amt } . Must be numeric and positive ` ) ;
return false ;
}
if ( Player . money . lt ( amt ) ) {
workerScript . log ( ` ERROR: You do not have enough money to donate $ ${ amt } to ${ name } ` ) ;
return false ;
}
var repNeededToDonate = Math . round ( CONSTANTS . BaseFavorToDonate * BitNodeMultipliers . RepToDonateToFaction ) ;
if ( Factions [ name ] . favor < repNeededToDonate ) {
workerScript . log ( ` ERROR: You do not have enough favor to donate to this faction. Have ${ Factions [ name ] . favor } , need ${ repNeededToDonate } ` ) ;
return false ;
}
var repGain = amt / CONSTANTS . DonateMoneyToRepDivisor * Player . faction _rep _mult ;
Factions [ name ] . playerReputation += repGain ;
Player . loseMoney ( amt ) ;
if ( workerScript . shouldLog ( "donateToFaction" ) ) {
workerScript . log ( ` $ ${ amt } donated to ${ name } for ${ repGain } reputation ` ) ;
}
return true ;
} ,
2018-03-03 22:05:33 +01:00
createProgram : function ( name ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn3RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "createProgram" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "createProgram" , ramCost ) ;
2017-08-30 19:44:29 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 3 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run createProgram(). It is a Singularity Function and requires SourceFile-4 (level 3) to run." ) ;
return false ;
}
}
2017-11-01 23:56:30 +01:00
if ( inMission ) {
2017-11-03 04:32:31 +01:00
workerScript . scriptRef . log ( "ERROR: createProgram() failed because you are in the middle of a mission." ) ;
2017-11-01 23:56:30 +01:00
return ;
}
2017-08-30 19:44:29 +02:00
if ( Player . isWorking ) {
var txt = Player . singularityStopWork ( ) ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . createProgram == null ) {
workerScript . scriptRef . log ( txt ) ;
}
2017-08-30 19:44:29 +02:00
}
2018-06-02 01:31:34 +02:00
name = name . toLowerCase ( ) ;
let p = null ;
for ( const key in Programs ) {
if ( Programs [ key ] . name . toLowerCase ( ) == name ) {
p = Programs [ key ] ;
}
}
2018-06-26 16:49:28 +02:00
if ( p == null ) {
2018-06-02 01:31:34 +02:00
workerScript . scriptRef . log ( "ERROR: createProgram() failed because the specified program does not exist: " + name ) ;
return false ;
}
2018-06-26 16:49:28 +02:00
if ( Player . hasProgram ( p . name ) ) {
2018-06-02 01:31:34 +02:00
workerScript . scriptRef . log ( 'ERROR: createProgram() failed because you already have the ' + p . name + ' program' ) ;
return false ;
}
2018-06-26 16:49:28 +02:00
if ( ! p . create . req ( ) ) {
2018-06-02 01:31:34 +02:00
workerScript . scriptRef . log ( "ERROR: createProgram() failed because hacking level is too low to create " + p . name + " (level " + p . create . level + " req)" ) ;
return false
}
Player . startCreateProgramWork ( p . name , p . create . time , p . create . level ) ;
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . createProgram == null ) {
workerScript . scriptRef . log ( "Began creating program: " + name ) ;
2017-08-30 19:44:29 +02:00
}
return true ;
} ,
2018-05-29 22:36:52 +02:00
commitCrime : function ( crimeRoughName ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn3RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "commitCrime" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "commitCrime" , ramCost ) ;
2017-10-12 04:00:22 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 3 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run commitCrime(). It is a Singularity Function and requires SourceFile-4 (level 3) to run." ) ;
return ;
}
}
2017-11-01 23:56:30 +01:00
if ( inMission ) {
2017-11-03 04:32:31 +01:00
workerScript . scriptRef . log ( "ERROR: commitCrime() failed because you are in the middle of a mission." ) ;
2017-11-01 23:56:30 +01:00
return ;
}
2017-10-12 04:00:22 +02:00
if ( Player . isWorking ) {
var txt = Player . singularityStopWork ( ) ;
2018-02-24 23:55:06 +01:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . commitCrime == null ) {
workerScript . scriptRef . log ( txt ) ;
}
2017-10-12 04:00:22 +02:00
}
2017-10-20 23:59:54 +02:00
//Set Location to slums
switch ( Player . city ) {
case Locations . Aevum :
Player . location = Locations . AevumSlums ;
break ;
case Locations . Chongqing :
Player . location = Locations . ChongqingSlums ;
break ;
case Locations . Sector12 :
Player . location = Locations . Sector12Slums ;
break ;
case Locations . NewTokyo :
Player . location = Locations . NewTokyoSlums ;
break ;
case Locations . Ishima :
Player . location = Locations . IshimaSlums ;
break ;
case Locations . Volhaven :
Player . location = Locations . VolhavenSlums ;
break ;
default :
console . log ( "Invalid Player.city value" ) ;
}
2018-05-29 22:36:52 +02:00
const crime = findCrime ( crimeRoughName . toLowerCase ( ) ) ;
if ( crime == null ) { // couldn't find crime
2018-07-28 02:00:57 +02:00
throw makeRuntimeRejectMsg ( workerScript , "Invalid crime passed into commitCrime(): " + crimeRoughName ) ;
2017-10-12 04:00:22 +02:00
}
2018-05-29 22:36:52 +02:00
if ( workerScript . disableLogs . ALL == null && workerScript . disableLogs . commitCrime == null ) {
workerScript . scriptRef . log ( "Attempting to commit crime: " + crime . name + "..." ) ;
}
2018-10-24 20:20:51 +02:00
return crime . commit ( 1 , { workerscript : workerScript } ) ;
2017-10-12 04:00:22 +02:00
} ,
2018-05-29 22:36:52 +02:00
getCrimeChance : function ( crimeRoughName ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn3RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getCrimeChance" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getCrimeChance" , ramCost ) ;
2017-10-15 03:55:41 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 3 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run getCrimeChance(). It is a Singularity Function and requires SourceFile-4 (level 3) to run." ) ;
return ;
}
}
2018-05-29 22:36:52 +02:00
const crime = findCrime ( crimeRoughName . toLowerCase ( ) ) ;
if ( crime == null ) {
2017-10-15 03:55:41 +02:00
throw makeRuntimeRejectMsg ( workerScript , "Invalid crime passed into getCrimeChance(): " + crime ) ;
}
2018-05-29 22:36:52 +02:00
return crime . successRate ( ) ;
2017-10-15 03:55:41 +02:00
} ,
2018-03-03 22:05:33 +01:00
getOwnedAugmentations : function ( purchased = false ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn3RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getOwnedAugmentations" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getOwnedAugmentations" , ramCost ) ;
2017-10-10 06:56:48 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 3 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run getOwnedAugmentations(). It is a Singularity Function and requires SourceFile-4 (level 3) to run." ) ;
return [ ] ;
}
}
var res = [ ] ;
for ( var i = 0 ; i < Player . augmentations . length ; ++ i ) {
res . push ( Player . augmentations [ i ] . name ) ;
}
if ( purchased ) {
for ( var i = 0 ; i < Player . queuedAugmentations . length ; ++ i ) {
res . push ( Player . queuedAugmentations [ i ] . name ) ;
}
}
return res ;
} ,
2018-07-25 06:31:17 +02:00
getOwnedSourceFiles : function ( ) {
let ramCost = CONSTANTS . ScriptSingularityFn3RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-07-25 06:31:17 +02:00
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getOwnedSourceFiles" , ramCost ) ;
}
updateDynamicRam ( "getOwnedSourceFiles" , ramCost ) ;
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 3 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run getOwnedSourceFiles(). It is a Singularity Function and requires SourceFile-4 (level 3) to run." ) ;
return [ ] ;
}
}
let res = [ ] ;
for ( let i = 0 ; i < Player . sourceFiles . length ; ++ i ) {
res . push ( { n : Player . sourceFiles [ i ] . n , lvl : Player . sourceFiles [ i ] . lvl } ) ;
}
return res ;
} ,
2018-03-03 22:05:33 +01:00
getAugmentationsFromFaction : function ( facname ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn3RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getAugmentationsFromFaction" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getAugmentationsFromFaction" , ramCost ) ;
2017-10-10 06:56:48 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 3 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run getAugmentationsFromFaction(). It is a Singularity Function and requires SourceFile-4 (level 3) to run." ) ;
return [ ] ;
}
}
if ( ! factionExists ( facname ) ) {
workerScript . scriptRef . log ( "ERROR: getAugmentationsFromFaction() failed. Invalid faction name passed in (this is case-sensitive): " + facname ) ;
return [ ] ;
}
var fac = Factions [ facname ] ;
var res = [ ] ;
for ( var i = 0 ; i < fac . augmentations . length ; ++ i ) {
res . push ( fac . augmentations [ i ] ) ;
}
return res ;
} ,
2018-03-03 22:05:33 +01:00
getAugmentationCost : function ( name ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn3RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "getAugmentationCost" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "getAugmentationCost" , ramCost ) ;
2017-08-30 19:44:29 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 3 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run getAugmentationCost(). It is a Singularity Function and requires SourceFile-4 (level 3) to run." ) ;
return false ;
}
}
if ( ! augmentationExists ( name ) ) {
workerScript . scriptRef . log ( "ERROR: getAugmentationCost() failed. Invalid Augmentation name passed in (note: this is case-sensitive): " + name ) ;
return [ - 1 , - 1 ] ;
}
var aug = Augmentations [ name ] ;
return [ aug . baseRepRequirement , aug . baseCost ] ;
} ,
2018-03-03 22:05:33 +01:00
purchaseAugmentation : function ( faction , name ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn3RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "purchaseAugmentation" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "purchaseAugmentation" , ramCost ) ;
2017-08-30 19:44:29 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 3 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run purchaseAugmentation(). It is a Singularity Function and requires SourceFile-4 (level 3) to run." ) ;
return false ;
}
}
var fac = Factions [ faction ] ;
2017-10-26 00:05:12 +02:00
if ( fac == null || ! ( fac instanceof Faction ) ) {
2017-08-30 19:44:29 +02:00
workerScript . scriptRef . log ( "ERROR: purchaseAugmentation() failed because of invalid faction name: " + faction ) ;
return false ;
}
if ( ! fac . augmentations . includes ( name ) ) {
workerScript . scriptRef . log ( "ERROR: purchaseAugmentation() failed because the faction " + faction + " does not contain the " + name + " augmentation" ) ;
return false ;
}
var aug = Augmentations [ name ] ;
2017-10-26 00:05:12 +02:00
if ( aug == null || ! ( aug instanceof Augmentation ) ) {
2017-08-30 19:44:29 +02:00
workerScript . scriptRef . log ( "ERROR: purchaseAugmentation() failed because of invalid augmentation name: " + name ) ;
return false ;
}
2017-09-08 21:16:48 +02:00
var isNeuroflux = false ;
if ( aug . name === AugmentationNames . NeuroFluxGovernor ) {
isNeuroflux = true ;
2017-08-30 19:44:29 +02:00
}
2017-09-08 21:16:48 +02:00
if ( ! isNeuroflux ) {
for ( var j = 0 ; j < Player . queuedAugmentations . length ; ++ j ) {
if ( Player . queuedAugmentations [ j ] . name === aug . name ) {
workerScript . scriptRef . log ( "ERROR: purchaseAugmentation() failed because you already have " + name ) ;
return false ;
}
}
for ( var j = 0 ; j < Player . augmentations . length ; ++ j ) {
if ( Player . augmentations [ j ] . name === aug . name ) {
workerScript . scriptRef . log ( "ERROR: purchaseAugmentation() failed because you already have " + name ) ;
return false ;
}
2017-08-30 19:44:29 +02:00
}
}
2017-08-30 20:36:59 +02:00
if ( fac . playerReputation < aug . baseRepRequirement ) {
workerScript . scriptRef . log ( "ERROR: purchaseAugmentation() failed because you do not have enough reputation with " + fac . name ) ;
return false ;
}
2017-08-30 19:44:29 +02:00
var res = purchaseAugmentation ( aug , fac , true ) ;
workerScript . scriptRef . log ( res ) ;
if ( isString ( res ) && res . startsWith ( "You purchased" ) ) {
2017-09-19 20:38:03 +02:00
Player . gainIntelligenceExp ( CONSTANTS . IntelligenceSingFnBaseExpGain ) ;
2017-08-30 19:44:29 +02:00
return true ;
} else {
return false ;
}
} ,
2018-03-03 22:05:33 +01:00
installAugmentations : function ( cbScript ) {
2018-06-06 18:02:21 +02:00
var ramCost = CONSTANTS . ScriptSingularityFn3RamCost ;
2018-10-23 20:55:42 +02:00
if ( Player . bitNodeN !== 4 ) { ramCost *= CONSTANTS . ScriptSingularityFnRamMult ; }
2018-01-27 07:52:39 +01:00
if ( workerScript . checkingRam ) {
2018-06-06 18:02:21 +02:00
return updateStaticRam ( "installAugmentations" , ramCost ) ;
2018-01-27 07:52:39 +01:00
}
2018-06-06 18:02:21 +02:00
updateDynamicRam ( "installAugmentations" , ramCost ) ;
2017-08-30 19:44:29 +02:00
if ( Player . bitNodeN != 4 ) {
if ( ! ( hasSingularitySF && singularitySFLvl >= 3 ) ) {
throw makeRuntimeRejectMsg ( workerScript , "Cannot run installAugmentations(). It is a Singularity Function and requires SourceFile-4 (level 3) to run." ) ;
return false ;
}
}
if ( Player . queuedAugmentations . length === 0 ) {
workerScript . scriptRef . log ( "ERROR: installAugmentations() failed because you do not have any Augmentations to be installed" ) ;
return false ;
}
2017-09-19 20:38:03 +02:00
Player . gainIntelligenceExp ( CONSTANTS . IntelligenceSingFnBaseExpGain ) ;
2017-08-30 19:44:29 +02:00
workerScript . scriptRef . log ( "Installing Augmentations. This will cause this script to be killed" ) ;
2017-10-02 04:35:22 +02:00
installAugmentations ( cbScript ) ;
2017-08-30 19:44:29 +02:00
return true ;
2018-05-23 02:09:04 +02:00
} ,
2018-10-23 20:55:42 +02:00
// Gang API
gang : {
getMemberNames : function ( ) {
if ( workerScript . checkingRam ) {
2018-10-24 20:20:51 +02:00
return updateStaticRam ( "getMemberNames" , CONSTANTS . ScriptGangApiBaseRamCost / 4 ) ;
2018-10-23 20:55:42 +02:00
}
2018-10-24 20:20:51 +02:00
updateDynamicRam ( "getMemberNames" , CONSTANTS . ScriptGangApiBaseRamCost / 4 ) ;
2018-10-23 20:55:42 +02:00
nsGang . checkGangApiAccess ( workerScript , "getMemberNames" ) ;
try {
const names = [ ] ;
for ( const member of Player . gang . members ) {
names . push ( member . name ) ;
}
return names ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , nsGang . unknownGangApiExceptionMessage ( "getMemberNames" , e ) ) ;
}
} ,
getGangInformation : function ( ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getGangInformation" , CONSTANTS . ScriptGangApiBaseRamCost / 2 ) ;
}
updateDynamicRam ( "getGangInformation" , CONSTANTS . ScriptGangApiBaseRamCost / 2 ) ;
nsGang . checkGangApiAccess ( workerScript , "getGangInformation" ) ;
try {
return {
faction : Player . gang . facName ,
isHacking : Player . gang . isHackingGang ,
moneyGainRate : Player . gang . moneyGainRate ,
power : Player . gang . getPower ( ) ,
respect : Player . gang . respect ,
respectGainRate : Player . gang . respectGainRate ,
territory : Player . gang . getTerritory ( ) ,
territoryClashChance : Player . gang . territoryClashChance ,
territoryWarfareEngaged : Player . gang . territoryWarfareEngaged ,
wantedLevel : Player . gang . wanted ,
wantedLevelGainRate : Player . gang . wantedGainRate ,
}
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , nsGang . unknownGangApiExceptionMessage ( "getGangInformation" , e ) ) ;
}
} ,
2018-10-25 03:26:53 +02:00
getOtherGangInformation : function ( ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getOtherGangInformation" , CONSTANTS . ScriptGangApiBaseRamCost / 2 ) ;
}
updateDynamicRam ( "getOtherGangInformation" , CONSTANTS . ScriptGangApiBaseRamCost / 2 ) ;
nsGang . checkGangApiAccess ( workerScript , "getOtherGangInformation" ) ;
try {
return Object . assign ( AllGangs ) ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , nsGang . unknownGangApiExceptionMessage ( "getOtherGangInformation" , e ) ) ;
}
} ,
2018-10-23 20:55:42 +02:00
getMemberInformation : function ( name ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getMemberInformation" , CONSTANTS . ScriptGangApiBaseRamCost / 2 ) ;
}
updateDynamicRam ( "getMemberInformation" , CONSTANTS . ScriptGangApiBaseRamCost / 2 ) ;
nsGang . checkGangApiAccess ( workerScript , "getMemberInformation" ) ;
try {
for ( const member of Player . gang . members ) {
if ( member . name === name ) {
return {
agility : member . agi ,
agilityEquipMult : member . agi _mult ,
agilityAscensionMult : member . agi _asc _mult ,
augmentations : member . augmentations . slice ( ) ,
charisma : member . cha ,
charismaEquipMult : member . cha _mult ,
charismaAscensionMult : member . cha _asc _mult ,
defense : member . def ,
defenseEquipMult : member . def _mult ,
defenseAscensionMult : member . def _asc _mult ,
dexterity : member . dex ,
dexterityEquipMult : member . dex _mult ,
dexterityAscensionMult : member . dex _asc _mult ,
equipment : member . upgrades . slice ( ) ,
hacking : member . hack ,
hackingEquipMult : member . hack _mult ,
hackingAscensionMult : member . hack _asc _mult ,
strength : member . str ,
strengthEquipMult : member . str _mult ,
strengthAscensionMult : member . str _asc _mult ,
2018-10-29 17:08:41 +01:00
task : member . task ,
2018-10-23 20:55:42 +02:00
}
}
}
workerScript . log ( ` Invalid argument passed to gang.getMemberInformation(). No gang member could be found with name ${ name } ` ) ;
return { } ; // Member could not be found
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , nsGang . unknownGangApiExceptionMessage ( "getMemberInformation" , e ) ) ;
}
} ,
canRecruitMember : function ( ) {
if ( workerScript . checkingRam ) {
2018-10-24 20:20:51 +02:00
return updateStaticRam ( "canRecruitMember" , CONSTANTS . ScriptGangApiBaseRamCost / 4 ) ;
2018-10-23 20:55:42 +02:00
}
2018-10-24 20:20:51 +02:00
updateDynamicRam ( "canRecruitMember" , CONSTANTS . ScriptGangApiBaseRamCost / 4 ) ;
2018-10-23 20:55:42 +02:00
nsGang . checkGangApiAccess ( workerScript , "canRecruitMember" ) ;
try {
return Player . gang . canRecruitMember ( ) ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , nsGang . unknownGangApiExceptionMessage ( "canRecruitMember" , e ) ) ;
}
} ,
recruitMember : function ( name ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "recruitMember" , CONSTANTS . ScriptGangApiBaseRamCost / 2 ) ;
}
updateDynamicRam ( "recruitMember" , CONSTANTS . ScriptGangApiBaseRamCost / 2 ) ;
nsGang . checkGangApiAccess ( workerScript , "recruitMember" ) ;
try {
2018-10-29 17:08:41 +01:00
const res = Player . gang . recruitMember ( name ) ;
if ( workerScript . shouldLog ( "recruitMember" ) ) {
if ( res ) {
workerScript . log ( ` Successfully recruited Gang Member ${ name } ` ) ;
} else {
workerScript . log ( ` Failed to recruit Gang Member ${ name } ` ) ;
}
}
return res ;
2018-10-23 20:55:42 +02:00
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , nsGang . unknownGangApiExceptionMessage ( "recruitMember" , e ) ) ;
}
} ,
getTaskNames : function ( ) {
if ( workerScript . checkingRam ) {
2018-10-24 20:20:51 +02:00
return updateStaticRam ( "getTaskNames" , CONSTANTS . ScriptGangApiBaseRamCost / 4 ) ;
2018-10-23 20:55:42 +02:00
}
2018-10-24 20:20:51 +02:00
updateDynamicRam ( "getTaskNames" , CONSTANTS . ScriptGangApiBaseRamCost / 4 ) ;
2018-10-23 20:55:42 +02:00
nsGang . checkGangApiAccess ( workerScript , "getTaskNames" ) ;
try {
const tasks = Player . gang . getAllTaskNames ( ) ;
tasks . unshift ( "Unassigned" ) ;
return tasks ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , nsGang . unknownGangApiExceptionMessage ( "getTaskNames" , e ) ) ;
}
} ,
setMemberTask : function ( memberName , taskName ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "setMemberTask" , CONSTANTS . ScriptGangApiBaseRamCost / 2 ) ;
}
updateDynamicRam ( "setMemberTask" , CONSTANTS . ScriptGangApiBaseRamCost / 2 ) ;
nsGang . checkGangApiAccess ( workerScript , "setMemberTask" ) ;
try {
for ( const member of Player . gang . members ) {
if ( member . name === memberName ) {
2018-10-29 17:08:41 +01:00
const res = member . assignToTask ( taskName ) ;
if ( workerScript . shouldLog ( "setMemberTask" ) ) {
if ( res ) {
workerScript . log ( ` Successfully assigned Gang Member ${ memberName } to ${ taskName } task ` ) ;
} else {
workerScript . log ( ` Failed to assign Gang Member ${ memberName } to ${ taskName } task. ${ memberName } is now Unassigned ` ) ;
}
}
return res ;
2018-10-23 20:55:42 +02:00
}
}
workerScript . log ( ` Invalid argument passed to gang.setMemberTask(). No gang member could be found with name ${ memberName } ` ) ;
return false ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , nsGang . unknownGangApiExceptionMessage ( "setMemberTask" , e ) ) ;
}
} ,
getEquipmentNames : function ( ) {
if ( workerScript . checkingRam ) {
2018-10-24 20:20:51 +02:00
return updateStaticRam ( "getEquipmentNames" , CONSTANTS . ScriptGangApiBaseRamCost / 4 ) ;
2018-10-23 20:55:42 +02:00
}
2018-10-24 20:20:51 +02:00
updateDynamicRam ( "getEquipmentNames" , CONSTANTS . ScriptGangApiBaseRamCost / 4 ) ;
2018-10-23 20:55:42 +02:00
nsGang . checkGangApiAccess ( workerScript , "getEquipmentNames" ) ;
try {
return Player . gang . getAllUpgradeNames ( ) ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , nsGang . unknownGangApiExceptionMessage ( "getEquipmentNames" , e ) ) ;
}
} ,
getEquipmentCost : function ( equipName ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getEquipmentCost" , CONSTANTS . ScriptGangApiBaseRamCost / 2 ) ;
}
updateDynamicRam ( "getEquipmentCost" , CONSTANTS . ScriptGangApiBaseRamCost / 2 ) ;
nsGang . checkGangApiAccess ( workerScript , "getEquipmentCost" ) ;
try {
return Player . gang . getUpgradeCost ( equipName ) ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , nsGang . unknownGangApiExceptionMessage ( "getEquipmentCost" , e ) ) ;
}
} ,
purchaseEquipment : function ( memberName , equipName ) {
if ( workerScript . checkingRam ) {
2018-10-24 20:20:51 +02:00
return updateStaticRam ( "purchaseEquipment" , CONSTANTS . ScriptGangApiBaseRamCost ) ;
2018-10-23 20:55:42 +02:00
}
2018-10-24 20:20:51 +02:00
updateDynamicRam ( "purchaseEquipment" , CONSTANTS . ScriptGangApiBaseRamCost ) ;
2018-10-23 20:55:42 +02:00
nsGang . checkGangApiAccess ( workerScript , "purchaseEquipment" ) ;
try {
2018-11-13 23:42:15 +01:00
for ( const member of Player . gang . members ) {
2018-10-23 20:55:42 +02:00
if ( member . name === memberName ) {
2018-10-29 17:08:41 +01:00
const res = member . buyUpgrade ( equipName , Player , Player . gang ) ;
if ( workerScript . shouldLog ( "purchaseEquipment" ) ) {
if ( res ) {
workerScript . log ( ` Purchased ${ equipName } for Gang member ${ memberName } ` ) ;
} else {
workerScript . log ( ` Failed to purchase ${ equipName } for Gang member ${ memberName } ` ) ;
}
}
return res ;
2018-10-23 20:55:42 +02:00
}
}
workerScript . log ( ` Invalid argument passed to gang.purchaseEquipment(). No gang member could be found with name ${ memberName } ` ) ;
return false ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , nsGang . unknownGangApiExceptionMessage ( "purchaseEquipment" , e ) ) ;
}
} ,
ascendMember : function ( name ) {
if ( workerScript . checkingRam ) {
2018-10-24 20:20:51 +02:00
return updateStaticRam ( "ascendMember" , CONSTANTS . ScriptGangApiBaseRamCost ) ;
2018-10-23 20:55:42 +02:00
}
2018-10-24 20:20:51 +02:00
updateDynamicRam ( "ascendMember" , CONSTANTS . ScriptGangApiBaseRamCost ) ;
2018-10-23 20:55:42 +02:00
nsGang . checkGangApiAccess ( workerScript , "ascendMember" ) ;
try {
2018-11-13 23:42:15 +01:00
for ( const member of Player . gang . members ) {
2018-10-23 20:55:42 +02:00
if ( member . name === name ) {
return Player . gang . ascendMember ( member , workerScript ) ;
}
}
2018-11-06 01:16:53 +01:00
workerScript . log ( ` Invalid argument passed to gang.ascendMember(). No gang member could be found with name ${ name } ` ) ;
2018-10-23 20:55:42 +02:00
return false ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , nsGang . unknownGangApiExceptionMessage ( "ascendMember" , e ) ) ;
}
} ,
setTerritoryWarfare : function ( engage ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "setTerritoryWarfare" , CONSTANTS . ScriptGangApiBaseRamCost / 2 ) ;
}
updateDynamicRam ( "setTerritoryWarfare" , CONSTANTS . ScriptGangApiBaseRamCost / 2 ) ;
nsGang . checkGangApiAccess ( workerScript , "setTerritoryWarfare" ) ;
try {
if ( engage ) {
Player . gang . territoryWarfareEngaged = true ;
2018-10-29 17:08:41 +01:00
if ( workerScript . shouldLog ( "setTerritoryWarfare" ) ) {
workerScript . log ( "Engaging in Gang Territory Warfare" ) ;
}
2018-10-23 20:55:42 +02:00
} else {
Player . gang . territoryWarfareEngaged = false ;
2018-10-29 17:08:41 +01:00
if ( workerScript . shouldLog ( "setTerritoryWarfare" ) ) {
workerScript . log ( "Disengaging in Gang Territory Warfare" ) ;
}
2018-10-23 20:55:42 +02:00
}
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , nsGang . unknownGangApiExceptionMessage ( "setTerritoryWarfare" , e ) ) ;
}
} ,
getBonusTime : function ( ) {
if ( workerScript . checkingRam ) { return 0 ; }
nsGang . checkGangApiAccess ( workerScript , "getBonusTime" ) ;
try {
return Math . round ( Player . gang . storedCycles / 5 ) ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , nsGang . unknownGangApiExceptionMessage ( "getBonusTime" , e ) ) ;
}
} ,
} , // end gang namespace
// Bladeburner API
2018-05-23 02:09:04 +02:00
bladeburner : {
2018-06-25 21:07:03 +02:00
getContractNames : function ( ) {
2018-06-08 17:51:48 +02:00
if ( workerScript . checkingRam ) {
2018-06-25 02:13:50 +02:00
return updateStaticRam ( "getContractNames" , CONSTANTS . ScriptBladeburnerApiBaseRamCost / 10 ) ;
2018-06-08 17:51:48 +02:00
}
2018-06-25 02:13:50 +02:00
updateDynamicRam ( "getContractNames" , CONSTANTS . ScriptBladeburnerApiBaseRamCost / 10 ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-25 21:07:03 +02:00
return Player . bladeburner . getContractNamesNetscriptFn ( ) ;
2018-05-23 02:09:04 +02:00
}
2018-06-25 02:13:50 +02:00
throw makeRuntimeRejectMsg ( workerScript , "getContractNames() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
2018-06-25 21:07:03 +02:00
getOperationNames : function ( ) {
2018-06-08 17:51:48 +02:00
if ( workerScript . checkingRam ) {
2018-06-25 02:13:50 +02:00
return updateStaticRam ( "getOperationNames" , CONSTANTS . ScriptBladeburnerApiBaseRamCost / 10 ) ;
2018-06-08 17:51:48 +02:00
}
2018-06-25 02:13:50 +02:00
updateDynamicRam ( "getOperationNames" , CONSTANTS . ScriptBladeburnerApiBaseRamCost / 10 ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-25 21:07:03 +02:00
return Player . bladeburner . getOperationNamesNetscriptFn ( ) ;
2018-05-23 02:09:04 +02:00
}
2018-06-25 02:13:50 +02:00
throw makeRuntimeRejectMsg ( workerScript , "getOperationNames() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
2018-06-25 21:07:03 +02:00
getBlackOpNames : function ( ) {
2018-06-08 17:51:48 +02:00
if ( workerScript . checkingRam ) {
2018-06-25 02:13:50 +02:00
return updateStaticRam ( "getBlackOpNames" , CONSTANTS . ScriptBladeburnerApiBaseRamCost / 10 ) ;
2018-06-08 17:51:48 +02:00
}
2018-06-25 02:13:50 +02:00
updateDynamicRam ( "getBlackOpNames" , CONSTANTS . ScriptBladeburnerApiBaseRamCost / 10 ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-25 21:07:03 +02:00
return Player . bladeburner . getBlackOpNamesNetscriptFn ( ) ;
2018-05-23 02:09:04 +02:00
}
2018-06-25 02:13:50 +02:00
throw makeRuntimeRejectMsg ( workerScript , "getBlackOpNames() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
2018-06-25 21:07:03 +02:00
getGeneralActionNames : function ( ) {
2018-06-08 17:51:48 +02:00
if ( workerScript . checkingRam ) {
2018-06-25 02:13:50 +02:00
return updateStaticRam ( "getGeneralActionNames" , CONSTANTS . ScriptBladeburnerApiBaseRamCost / 10 ) ;
2018-06-08 17:51:48 +02:00
}
2018-06-25 02:13:50 +02:00
updateDynamicRam ( "getGeneralActionNames" , CONSTANTS . ScriptBladeburnerApiBaseRamCost / 10 ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-25 21:07:03 +02:00
return Player . bladeburner . getGeneralActionNamesNetscriptFn ( ) ;
2018-05-23 02:09:04 +02:00
}
2018-06-25 02:13:50 +02:00
throw makeRuntimeRejectMsg ( workerScript , "getGeneralActionNames() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
2018-06-25 21:07:03 +02:00
getSkillNames : function ( ) {
2018-06-08 17:51:48 +02:00
if ( workerScript . checkingRam ) {
2018-06-25 02:13:50 +02:00
return updateStaticRam ( "getSkillNames" , CONSTANTS . ScriptBladeburnerApiBaseRamCost / 10 ) ;
2018-06-08 17:51:48 +02:00
}
2018-06-25 02:13:50 +02:00
updateDynamicRam ( "getSkillNames" , CONSTANTS . ScriptBladeburnerApiBaseRamCost / 10 ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-25 21:07:03 +02:00
return Player . bladeburner . getSkillNamesNetscriptFn ( ) ;
2018-05-23 02:09:04 +02:00
}
2018-06-25 02:13:50 +02:00
throw makeRuntimeRejectMsg ( workerScript , "getSkillNames() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
2018-06-08 17:51:48 +02:00
startAction : function ( type = "" , name = "" ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "startAction" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "startAction" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-08 17:51:48 +02:00
try {
return Player . bladeburner . startActionNetscriptFn ( type , name , workerScript ) ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , "Bladeburner.startAction() failed with exception: " + e ) ;
}
2018-05-23 02:09:04 +02:00
}
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "startAction() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
2018-06-25 02:13:50 +02:00
stopBladeburnerAction : function ( ) {
2018-06-08 17:51:48 +02:00
if ( workerScript . checkingRam ) {
2018-06-25 02:13:50 +02:00
return updateStaticRam ( "stopBladeburnerAction" , CONSTANTS . ScriptBladeburnerApiBaseRamCost / 2 ) ;
2018-06-08 17:51:48 +02:00
}
2018-06-25 02:13:50 +02:00
updateDynamicRam ( "stopBladeburnerAction" , CONSTANTS . ScriptBladeburnerApiBaseRamCost / 2 ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-08 17:51:48 +02:00
return Player . bladeburner . resetAction ( ) ;
2018-05-23 02:09:04 +02:00
}
2018-06-25 02:13:50 +02:00
throw makeRuntimeRejectMsg ( workerScript , "stopBladeburnerAction() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
2018-07-11 06:41:26 +02:00
getCurrentAction : function ( ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getCurrentAction" , CONSTANTS . ScriptBladeburnerApiBaseRamCost / 4 ) ;
}
2018-07-12 07:01:52 +02:00
updateDynamicRam ( "getCurrentAction" , CONSTANTS . ScriptBladeburnerApiBaseRamCost / 4 ) ;
2018-07-11 06:41:26 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-08-04 23:52:45 +02:00
return Player . bladeburner . getTypeAndNameFromActionId ( Player . bladeburner . action ) ;
2018-07-11 06:41:26 +02:00
}
throw makeRuntimeRejectMsg ( workerScript , "getCurrentAction() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
2018-05-23 02:09:04 +02:00
getActionTime : function ( type = "" , name = "" ) {
2018-06-08 17:51:48 +02:00
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getActionTime" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "getActionTime" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-08 17:51:48 +02:00
try {
return Player . bladeburner . getActionTimeNetscriptFn ( type , name , workerScript ) ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , "Bladeburner.getActionTime() failed with exception: " + e ) ;
}
2018-05-23 02:09:04 +02:00
}
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "getActionTime() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
getActionEstimatedSuccessChance : function ( type = "" , name = "" ) {
2018-06-08 17:51:48 +02:00
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getActionEstimatedSuccessChance" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "getActionEstimatedSuccessChance" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-08 17:51:48 +02:00
try {
return Player . bladeburner . getActionEstimatedSuccessChanceNetscriptFn ( type , name , workerScript ) ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , "Bladeburner.getActionEstimatedSuccessChance() failed with exception: " + e ) ;
}
2018-05-23 02:09:04 +02:00
}
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "getActionEstimatedSuccessChance() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
2018-09-24 06:27:31 +02:00
getActionRepGain : function ( type = "" , name = "" , level ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getActionRepGain" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "getActionRepGain" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
checkBladeburnerAccess ( workerScript , "getActionRepGain" ) ;
try {
var errorLogText = unknownBladeburnerActionErrorMessage ( "getActionAutolevel" , type , name ) ;
const actionId = Player . bladeburner . getActionIdFromTypeAndName ( type , name ) ;
if ( actionId == null ) {
workerScript . log ( errorLogText ) ;
return - 1 ;
}
const actionObj = Player . bladeburner . getActionObject ( actionId ) ;
if ( actionObj == null ) {
workerScript . log ( errorLogText ) ;
return - 1 ;
}
var rewardMultiplier ;
if ( level == null || isNaN ( level ) ) {
rewardMultiplier = Math . pow ( actionObj . rewardFac , actionObj . level - 1 ) ;
} else {
rewardMultiplier = Math . pow ( actionObj . rewardFac , level - 1 ) ;
}
return actionObj . rankGain * rewardMultiplier * BitNodeMultipliers . BladeburnerRank ;
} catch ( err ) {
throw makeRuntimeRejectMsg ( workerScript , unknownBladeburnerExceptionMessage ( "getActionAutolevel" , err ) ) ;
}
} ,
2018-05-23 02:09:04 +02:00
getActionCountRemaining : function ( type = "" , name = "" ) {
2018-06-08 17:51:48 +02:00
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getActionCountRemaining" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "getActionCountRemaining" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-08 17:51:48 +02:00
try {
return Player . bladeburner . getActionCountRemainingNetscriptFn ( type , name , workerScript ) ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , "Bladeburner.getActionCountRemaining() failed with exception: " + e ) ;
}
2018-05-23 02:09:04 +02:00
}
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "getActionCountRemaining() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
2018-07-20 06:06:59 +02:00
getActionMaxLevel : function ( type = "" , name = "" ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getActionMaxLevel" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "getActionMaxLevel" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
checkBladeburnerAccess ( workerScript , "getActionMaxLevel" ) ;
try {
var errorLogText = unknownBladeburnerActionErrorMessage ( "getActionMaxLevel" , type , name ) ;
const actionId = Player . bladeburner . getActionIdFromTypeAndName ( type , name ) ;
if ( actionId == null ) {
workerScript . log ( errorLogText ) ;
return - 1 ;
}
const actionObj = Player . bladeburner . getActionObject ( actionId ) ;
if ( actionObj == null ) {
workerScript . log ( errorLogText ) ;
return - 1 ;
}
return actionObj . maxLevel ;
} catch ( err ) {
throw makeRuntimeRejectMsg ( workerScript , unknownBladeburnerExceptionMessage ( "getActionMaxLevel" , err ) ) ;
}
} ,
getActionCurrentLevel : function ( type = "" , name = "" ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getActionCurrentLevel" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "getActionCurrentLevel" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
checkBladeburnerAccess ( workerScript , "getActionCurrentLevel" ) ;
try {
var errorLogText = unknownBladeburnerActionErrorMessage ( "getActionCurrentLevel" , type , name ) ;
const actionId = Player . bladeburner . getActionIdFromTypeAndName ( type , name ) ;
if ( actionId == null ) {
workerScript . log ( errorLogText ) ;
return - 1 ;
}
const actionObj = Player . bladeburner . getActionObject ( actionId ) ;
if ( actionObj == null ) {
workerScript . log ( errorLogText ) ;
return - 1 ;
}
return actionObj . level ;
} catch ( err ) {
throw makeRuntimeRejectMsg ( workerScript , unknownBladeburnerExceptionMessage ( "getActionCurrentLevel" , err ) ) ;
}
} ,
getActionAutolevel : function ( type = "" , name = "" ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getActionAutolevel" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "getActionAutolevel" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
checkBladeburnerAccess ( workerScript , "getActionAutolevel" ) ;
try {
var errorLogText = unknownBladeburnerActionErrorMessage ( "getActionAutolevel" , type , name ) ;
const actionId = Player . bladeburner . getActionIdFromTypeAndName ( type , name ) ;
if ( actionId == null ) {
workerScript . log ( errorLogText ) ;
return false ;
}
const actionObj = Player . bladeburner . getActionObject ( actionId ) ;
if ( actionObj == null ) {
workerScript . log ( errorLogText ) ;
return false ;
}
return actionObj . autoLevel ;
} catch ( err ) {
throw makeRuntimeRejectMsg ( workerScript , unknownBladeburnerExceptionMessage ( "getActionAutolevel" , err ) ) ;
}
} ,
setActionAutolevel : function ( type = "" , name = "" , autoLevel = true ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "setActionAutolevel" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "setActionAutolevel" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
checkBladeburnerAccess ( workerScript , "setActionAutolevel" ) ;
try {
var errorLogText = unknownBladeburnerActionErrorMessage ( "setActionAutolevel" , type , name ) ;
const actionId = Player . bladeburner . getActionIdFromTypeAndName ( type , name ) ;
if ( actionId == null ) {
workerScript . log ( errorLogText ) ;
return ;
}
const actionObj = Player . bladeburner . getActionObject ( actionId ) ;
if ( actionObj == null ) {
workerScript . log ( errorLogText ) ;
return ;
}
actionObj . autoLevel = autoLevel ;
} catch ( err ) {
throw makeRuntimeRejectMsg ( workerScript , unknownBladeburnerExceptionMessage ( "setActionAutolevel" , err ) ) ;
}
} ,
setActionLevel : function ( type = "" , name = "" , level = 1 ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "setActionLevel" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "setActionLevel" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
checkBladeburnerAccess ( workerScript , "setActionLevel" ) ;
try {
var errorLogText = unknownBladeburnerActionErrorMessage ( "setActionLevel" , type , name ) ;
const actionId = Player . bladeburner . getActionIdFromTypeAndName ( type , name ) ;
if ( actionId == null ) {
workerScript . log ( errorLogText ) ;
return ;
}
const actionObj = Player . bladeburner . getActionObject ( actionId ) ;
if ( actionObj == null ) {
workerScript . log ( errorLogText ) ;
return ;
}
if ( level > actionObj . maxLevel ) {
workerScript . log ( ` ERROR: bladeburner. ${ setActionLevel } () failed because level exceeds max level for given action. ` ) ;
return ;
}
if ( level < 1 ) {
workerScript . log ( ` ERROR: bladeburner. ${ setActionLevel } () failed because level is below 1. ` ) ;
return ;
}
actionObj . level = level ;
} catch ( err ) {
throw makeRuntimeRejectMsg ( workerScript , unknownBladeburnerExceptionMessage ( "setActionLevel" , err ) ) ;
}
} ,
2018-05-23 02:09:04 +02:00
getRank : function ( ) {
2018-06-08 17:51:48 +02:00
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getRank" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "getRank" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-08 17:51:48 +02:00
return Player . bladeburner . rank ;
2018-05-23 02:09:04 +02:00
}
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "getRank() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
getSkillPoints : function ( ) {
2018-06-08 17:51:48 +02:00
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getSkillPoints" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "getSkillPoints" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-08 17:51:48 +02:00
return Player . bladeburner . skillPoints ;
2018-05-23 02:09:04 +02:00
}
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "getSkillPoints() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
getSkillLevel : function ( skillName = "" ) {
2018-06-08 17:51:48 +02:00
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getSkillLevel" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "getSkillLevel" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-08 17:51:48 +02:00
try {
return Player . bladeburner . getSkillLevelNetscriptFn ( skillName , workerScript ) ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , "Bladeburner.getSkillLevel() failed with exception: " + e ) ;
}
2018-05-23 02:09:04 +02:00
}
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "getSkillLevel() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
2018-08-12 03:05:32 +02:00
getSkillUpgradeCost : function ( skillName = "" ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getSkillUpgradeCost" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "getSkillUpgradeCost" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
try {
return Player . bladeburner . getSkillUpgradeCostNetscriptFn ( skillName , workerScript ) ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , "Bladeburner.getSkillUpgradeCost() failed with exception: " + e ) ;
}
}
throw makeRuntimeRejectMsg ( workerScript , "getSkillUpgradeCost() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
2018-05-23 02:09:04 +02:00
upgradeSkill : function ( skillName ) {
2018-06-08 17:51:48 +02:00
if ( workerScript . checkingRam ) {
return updateStaticRam ( "upgradeSkill" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "upgradeSkill" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-08 17:51:48 +02:00
try {
return Player . bladeburner . upgradeSkillNetscriptFn ( skillName , workerScript ) ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , "Bladeburner.upgradeSkill() failed with exception: " + e ) ;
}
2018-05-23 02:09:04 +02:00
}
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "upgradeSkill() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
2018-06-08 17:51:48 +02:00
getTeamSize : function ( type = "" , name = "" ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getTeamSize" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "getTeamSize" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-08 17:51:48 +02:00
try {
return Player . bladeburner . getTeamSizeNetscriptFn ( type , name , workerScript ) ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , "Bladeburner.getTeamSize() failed with exception: " + e ) ;
}
2018-05-23 02:09:04 +02:00
}
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "getTeamSize() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
setTeamSize : function ( type = "" , name = "" , size ) {
2018-06-08 17:51:48 +02:00
if ( workerScript . checkingRam ) {
return updateStaticRam ( "setTeamSize" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "setTeamSize" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-08 17:51:48 +02:00
try {
return Player . bladeburner . setTeamSizeNetscriptFn ( type , name , size , workerScript ) ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , "Bladeburner.setTeamSize() failed with exception: " + e ) ;
}
2018-05-23 02:09:04 +02:00
}
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "setTeamSize() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
getCityEstimatedPopulation : function ( cityName ) {
2018-06-08 17:51:48 +02:00
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getCityEstimatedPopulation" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "getCityEstimatedPopulation" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-08 17:51:48 +02:00
try {
return Player . bladeburner . getCityEstimatedPopulationNetscriptFn ( cityName , workerScript ) ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , "Bladeburner.getCityEstimatedPopulation() failed with exception: " + e ) ;
}
2018-05-23 02:09:04 +02:00
}
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "getCityEstimatedPopulation() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
getCityEstimatedCommunities : function ( cityName ) {
2018-06-08 17:51:48 +02:00
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getCityEstimatedCommunities" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "getCityEstimatedCommunities" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-08 17:51:48 +02:00
try {
return Player . bladeburner . getCityEstimatedCommunitiesNetscriptFn ( cityName , workerScript ) ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , "Bladeburner.getCityEstimatedCommunities() failed with exception: " + e ) ;
}
2018-05-23 02:09:04 +02:00
}
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "getCityEstimatedCommunities() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
getCityChaos : function ( cityName ) {
2018-06-08 17:51:48 +02:00
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getCityChaos" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "getCityChaos" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-08 17:51:48 +02:00
try {
return Player . bladeburner . getCityChaosNetscriptFn ( cityName , workerScript ) ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , "Bladeburner.getCityChaos() failed with exception: " + e ) ;
}
2018-05-23 02:09:04 +02:00
}
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "getCityChaos() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
2018-08-24 22:44:48 +02:00
getCity : function ( ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getCity" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "getCity" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
try {
return Player . bladeburner . city ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , "Bladeburner.getCity() failed with exception: " + e ) ;
}
}
throw makeRuntimeRejectMsg ( workerScript , "getCity() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
2018-05-23 02:09:04 +02:00
switchCity : function ( cityName ) {
2018-06-08 17:51:48 +02:00
if ( workerScript . checkingRam ) {
return updateStaticRam ( "switchCity" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "switchCity" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-08 17:51:48 +02:00
try {
return Player . bladeburner . switchCityNetscriptFn ( cityName , workerScript ) ;
} catch ( e ) {
throw makeRuntimeRejectMsg ( workerScript , "Bladeburner.switchCity() failed with exception: " + e ) ;
}
2018-05-23 02:09:04 +02:00
}
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "switchCity() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
getStamina : function ( ) {
2018-06-08 17:51:48 +02:00
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getStamina" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "getStamina" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-08 17:51:48 +02:00
return [ Player . bladeburner . stamina , Player . bladeburner . maxStamina ] ;
2018-05-23 02:09:04 +02:00
}
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "getStamina() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
} ,
2018-06-08 17:51:48 +02:00
joinBladeburnerFaction : function ( ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "joinBladeburnerFaction" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "joinBladeburnerFaction" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
2018-05-23 02:09:04 +02:00
if ( Player . bladeburner instanceof Bladeburner && ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
2018-06-08 17:51:48 +02:00
return Player . bladeburner . joinBladeburnerFactionNetscriptFn ( workerScript ) ;
2018-05-23 02:09:04 +02:00
}
2018-06-08 17:51:48 +02:00
throw makeRuntimeRejectMsg ( workerScript , "joinBladeburnerFaction() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
2018-05-23 02:09:04 +02:00
"at the Bladeburner division or because you do not have Source-File 7" ) ;
2018-06-25 02:13:50 +02:00
} ,
2018-07-03 05:35:12 +02:00
joinBladeburnerDivision : function ( ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "joinBladeburnerDivision" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
}
updateDynamicRam ( "joinBladeburnerDivision" , CONSTANTS . ScriptBladeburnerApiBaseRamCost ) ;
if ( ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
if ( Player . bladeburner instanceof Bladeburner ) {
return true ; //Already member
} else if ( Player . strength >= 100 && Player . defense >= 100 &&
Player . dexterity >= 100 && Player . agility >= 100 ) {
Player . bladeburner = new Bladeburner ( { new : true } ) ;
workerScript . log ( "You have been accepted into the Bladeburner division" ) ;
return true ;
} else {
workerScript . log ( "You do not meet the requirements for joining the Bladeburner division" ) ;
return false ;
}
}
throw makeRuntimeRejectMsg ( workerScript , "joinBladeburnerDivision() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
"at the Bladeburner division or because you do not have Source-File 7" ) ;
2018-08-12 03:05:32 +02:00
} ,
getBonusTime : function ( ) {
if ( workerScript . checkingRam ) { return 0 ; }
if ( ( Player . bitNodeN === 7 || hasBladeburner2079SF ) ) {
return Math . round ( Player . bladeburner . storedCycles / 5 ) ;
}
throw makeRuntimeRejectMsg ( workerScript , "getBonusTime() failed because you do not currently have access to the Bladeburner API. This is either because you are not currently employed " +
"at the Bladeburner division or because you do not have Source-File 7" ) ;
2018-07-03 05:35:12 +02:00
}
2018-09-23 02:25:48 +02:00
} , // End Bladeburner
codingcontract : {
attempt : function ( answer , fn , ip = workerScript . serverIp ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "attempt" , CONSTANTS . ScriptCodingContractBaseRamCost ) ;
}
updateDynamicRam ( "attempt" , CONSTANTS . ScriptCodingContractBaseRamCost ) ;
const contract = getCodingContract ( fn , ip ) ;
if ( contract == null ) {
workerScript . log ( ` ERROR: codingcontract.getData() failed because it could find the specified contract ${ fn } on server ${ ip } ` ) ;
return false ;
}
answer = String ( answer ) ;
const serv = safeGetServer ( ip , "codingcontract.attempt()" ) ;
if ( contract . isSolution ( answer ) ) {
const reward = Player . gainCodingContractReward ( contract . reward , contract . getDifficulty ( ) ) ;
workerScript . log ( ` Successfully completed Coding Contract ${ fn } . Reward: ${ reward } ` ) ;
serv . removeContract ( fn ) ;
return true ;
} else {
++ contract . tries ;
if ( contract . tries >= contract . getMaxNumTries ( ) ) {
workerScript . log ( ` Coding Contract ${ fn } failed. Contract is now self-destructing ` ) ;
serv . removeContract ( fn ) ;
} else {
workerScript . log ( ` Coding Contract ${ fn } failed. ${ contract . getMaxNumTries ( ) - contract . tries } attempts remaining ` ) ;
}
return false ;
}
} ,
2018-10-09 02:26:24 +02:00
getContractType : function ( fn , ip = workerScript . serverIp ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getContractType" , CONSTANTS . ScriptCodingContractBaseRamCost / 2 ) ;
}
updateDynamicRam ( "getContractType" , CONSTANTS . ScriptCodingContractBaseRamCost / 2 ) ;
let contract = getCodingContract ( fn , ip ) ;
if ( contract == null ) {
workerScript . log ( ` ERROR: codingcontract.getData() failed because it could find the specified contract ${ fn } on server ${ ip } ` ) ;
return null ;
}
return contract . getType ( ) ;
} ,
2018-09-23 02:25:48 +02:00
getData : function ( fn , ip = workerScript . serverIp ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getData" , CONSTANTS . ScriptCodingContractBaseRamCost / 2 ) ;
}
updateDynamicRam ( "getData" , CONSTANTS . ScriptCodingContractBaseRamCost / 2 ) ;
2018-10-09 02:26:24 +02:00
let contract = getCodingContract ( fn , ip ) ;
2018-09-23 02:25:48 +02:00
if ( contract == null ) {
workerScript . log ( ` ERROR: codingcontract.getData() failed because it could find the specified contract ${ fn } on server ${ ip } ` ) ;
return null ;
}
2018-10-09 02:26:24 +02:00
let data = contract . getData ( ) ;
2018-10-09 02:33:07 +02:00
if ( data . constructor === Array ) {
2018-10-09 02:26:24 +02:00
// Pass a copy
return data . slice ( ) ;
} else {
return data ;
}
2018-09-23 02:25:48 +02:00
} ,
getDescription : function ( fn , ip = workerScript . serverIp ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getDescription" , CONSTANTS . ScriptCodingContractBaseRamCost / 2 ) ;
}
updateDynamicRam ( "getDescription" , CONSTANTS . ScriptCodingContractBaseRamCost / 2 ) ;
var contract = getCodingContract ( fn , ip ) ;
if ( contract == null ) {
workerScript . log ( ` ERROR: codingcontract.getDescription() failed because it could find the specified contract ${ fn } on server ${ ip } ` ) ;
return "" ;
}
return contract . getDescription ( ) ;
} ,
getNumTriesRemaining : function ( fn , ip = workerScript . serverIp ) {
if ( workerScript . checkingRam ) {
return updateStaticRam ( "getNumTriesRemaining" , CONSTANTS . ScriptCodingContractBaseRamCost / 2 ) ;
}
updateDynamicRam ( "getNumTriesRemaining" , CONSTANTS . ScriptCodingContractBaseRamCost / 2 ) ;
var contract = getCodingContract ( fn , ip ) ;
if ( contract == null ) {
workerScript . log ( ` ERROR: codingcontract.getNumTriesRemaining() failed because it could find the specified contract ${ fn } on server ${ ip } ` ) ;
return - 1 ;
}
return contract . getMaxNumTries ( ) - contract . tries ;
} ,
2017-08-30 19:44:29 +02:00
}
2018-05-23 02:09:04 +02:00
} //End return
} //End NetscriptFunction()
2017-08-30 19:44:29 +02:00
2018-05-02 19:38:11 +02:00
export { NetscriptFunctions , initSingularitySFFlags , hasSingularitySF , hasBn11SF ,
hasWallStreetSF , wallStreetSFLvl , hasCorporationSF , hasAISF , hasBladeburnerSF } ;