convert more netscript functions to use common error message

This commit is contained in:
Olivier Gagnon
2021-03-16 06:01:15 -04:00
parent c9fe8d9b65
commit 4c30f107e3
2 changed files with 21 additions and 20 deletions

View File

@ -329,10 +329,10 @@ function NetscriptFunctions(workerScript) {
*/ */
const checkTixApiAccess = function(callingFn="") { const checkTixApiAccess = function(callingFn="") {
if (!Player.hasWseAccount) { if (!Player.hasWseAccount) {
throw makeRuntimeRejectMsg(workerScript, `You don't have WSE Access! Cannot use ${callingFn}()`); throw makeRuntimeErrorMsg(callingFn, `You don't have WSE Access! Cannot use ${callingFn}()`);
} }
if (!Player.hasTixApiAccess) { if (!Player.hasTixApiAccess) {
throw makeRuntimeRejectMsg(workerScript, `You don't have TIX API Access! Cannot use ${callingFn}()`); throw makeRuntimeErrorMsg(callingFn, `You don't have TIX API Access! Cannot use ${callingFn}()`);
} }
} }
@ -344,7 +344,7 @@ function NetscriptFunctions(workerScript) {
const getStockFromSymbol = function(symbol, callingFn="") { const getStockFromSymbol = function(symbol, callingFn="") {
const stock = SymbolToStockMap[symbol]; const stock = SymbolToStockMap[symbol];
if (stock == null) { if (stock == null) {
throw makeRuntimeRejectMsg(workerScript, `Invalid stock symbol passed into ${callingFn}()`); throw makeRuntimeErrorMsg(callingFn, `Invalid stock symbol: '${symbol}'`);
} }
return stock; return stock;
@ -367,18 +367,18 @@ function NetscriptFunctions(workerScript) {
} }
// Utility function to get Hacknet Node object // Utility function to get Hacknet Node object
const getHacknetNode = function(i) { const getHacknetNode = function(i, callingFn="") {
if (isNaN(i)) { if (isNaN(i)) {
throw makeRuntimeRejectMsg(workerScript, "Invalid index specified for Hacknet Node: " + i); throw makeRuntimeErrorMsg(callingFn, "Invalid index specified for Hacknet Node: " + i);
} }
if (i < 0 || i >= Player.hacknetNodes.length) { if (i < 0 || i >= Player.hacknetNodes.length) {
throw makeRuntimeRejectMsg(workerScript, "Index specified for Hacknet Node is out-of-bounds: " + i); throw makeRuntimeErrorMsg(callingFn, "Index specified for Hacknet Node is out-of-bounds: " + i);
} }
if (hasHacknetServers()) { if (hasHacknetServers()) {
const hserver = AllServers[Player.hacknetNodes[i]]; const hserver = AllServers[Player.hacknetNodes[i]];
if (hserver == null) { if (hserver == null) {
throw makeRuntimeRejectMsg(workerScript, `Could not get Hacknet Server for index ${i}. This is probably a bug, please report to game dev`); throw makeRuntimeErrorMsg(callingFn, `Could not get Hacknet Server for index ${i}. This is probably a bug, please report to game dev`);
} }
return hserver; return hserver;
@ -579,7 +579,7 @@ function NetscriptFunctions(workerScript) {
} }
}, },
getNodeStats : function(i) { getNodeStats : function(i) {
const node = getHacknetNode(i); const node = getHacknetNode(i, "getNodeStats");
const hasUpgraded = hasHacknetServers(); const hasUpgraded = hasHacknetServers();
const res = { const res = {
name: hasUpgraded ? node.hostname : node.name, name: hasUpgraded ? node.hostname : node.name,
@ -599,20 +599,20 @@ function NetscriptFunctions(workerScript) {
return res; return res;
}, },
upgradeLevel : function(i, n) { upgradeLevel : function(i, n) {
const node = getHacknetNode(i); const node = getHacknetNode(i, "upgradeLevel");
return purchaseLevelUpgrade(node, n); return purchaseLevelUpgrade(node, n);
}, },
upgradeRam : function(i, n) { upgradeRam : function(i, n) {
const node = getHacknetNode(i); const node = getHacknetNode(i, "upgradeRam");
return purchaseRamUpgrade(node, n); return purchaseRamUpgrade(node, n);
}, },
upgradeCore : function(i, n) { upgradeCore : function(i, n) {
const node = getHacknetNode(i); const node = getHacknetNode(i, "upgradeCore");
return purchaseCoreUpgrade(node, n); return purchaseCoreUpgrade(node, n);
}, },
upgradeCache : function(i, n) { upgradeCache : function(i, n) {
if (!hasHacknetServers()) { return false; } if (!hasHacknetServers()) { return false; }
const node = getHacknetNode(i); const node = getHacknetNode(i, "upgradeCache");
const res = purchaseCacheUpgrade(node, n); const res = purchaseCacheUpgrade(node, n);
if (res) { if (res) {
updateHashManagerCapacity(); updateHashManagerCapacity();
@ -620,20 +620,20 @@ function NetscriptFunctions(workerScript) {
return res; return res;
}, },
getLevelUpgradeCost : function(i, n) { getLevelUpgradeCost : function(i, n) {
const node = getHacknetNode(i); const node = getHacknetNode(i, "upgradeLevel");
return node.calculateLevelUpgradeCost(n, Player.hacknet_node_level_cost_mult); return node.calculateLevelUpgradeCost(n, Player.hacknet_node_level_cost_mult);
}, },
getRamUpgradeCost : function(i, n) { getRamUpgradeCost : function(i, n) {
const node = getHacknetNode(i); const node = getHacknetNode(i, "upgradeRam");
return node.calculateRamUpgradeCost(n, Player.hacknet_node_ram_cost_mult); return node.calculateRamUpgradeCost(n, Player.hacknet_node_ram_cost_mult);
}, },
getCoreUpgradeCost : function(i, n) { getCoreUpgradeCost : function(i, n) {
const node = getHacknetNode(i); const node = getHacknetNode(i, "upgradeCore");
return node.calculateCoreUpgradeCost(n, Player.hacknet_node_core_cost_mult); return node.calculateCoreUpgradeCost(n, Player.hacknet_node_core_cost_mult);
}, },
getCacheUpgradeCost : function(i, n) { getCacheUpgradeCost : function(i, n) {
if (!hasHacknetServers()) { return Infinity; } if (!hasHacknetServers()) { return Infinity; }
const node = getHacknetNode(i); const node = getHacknetNode(i, "upgradeCache");
return node.calculateCacheUpgradeCost(n); return node.calculateCacheUpgradeCost(n);
}, },
numHashes : function() { numHashes : function() {

View File

@ -1149,10 +1149,11 @@ const Engine = {
Engine.start(); // Run main game loop and Scripts loop Engine.start(); // Run main game loop and Scripts loop
removeLoadingScreen(); removeLoadingScreen();
const timeOfflineString = convertTimeMsToTimeElapsedString(time); const timeOfflineString = convertTimeMsToTimeElapsedString(time);
dialogBoxCreate(`Offline for ${timeOfflineString}. While you were offline, your scripts ` + dialogBoxCreate(<>
"generated <span class='money-gold'>" + Offline for {timeOfflineString}. While you were offline, your scripts generated
numeralWrapper.formatMoney(offlineProductionFromScripts) + "</span> " + <span class='money-gold'> {numeralWrapper.formatMoney(offlineProductionFromScripts)} </span>
"and your Hacknet Nodes generated <span class='money-gold'>" + hacknetProdInfo + "</span>"); and your Hacknet Nodes generated <span class='money-gold'>{hacknetProdInfo}</span>.
</>);
// Close main menu accordions for loaded game // Close main menu accordions for loaded game
var visibleMenuTabs = [terminal, createScript, activeScripts, stats, var visibleMenuTabs = [terminal, createScript, activeScripts, stats,
hacknetnodes, city, tutorial, options, dev]; hacknetnodes, city, tutorial, options, dev];