From 46a90e6271e0a60229bcc8a3cdda9b2194899011 Mon Sep 17 00:00:00 2001 From: Undeemiss Date: Tue, 19 Apr 2022 12:00:24 -0500 Subject: [PATCH 1/7] Added ns function stanek.acceptGift Added a new ns function stanek.acceptGift to the game, with a ram cost of 2gb. The function attempts to join the CotMG and install the gift, then returns true iff the player is in the CotMG and has the gift installed. --- src/Netscript/RamCostGenerator.ts | 2 ++ src/NetscriptFunctions/Stanek.ts | 27 ++++++++++++++++++++++ src/ScriptEditor/NetscriptDefinitions.d.ts | 10 ++++++++ 3 files changed, 39 insertions(+) diff --git a/src/Netscript/RamCostGenerator.ts b/src/Netscript/RamCostGenerator.ts index b7f8b704e..a74f248a4 100644 --- a/src/Netscript/RamCostGenerator.ts +++ b/src/Netscript/RamCostGenerator.ts @@ -70,6 +70,7 @@ export const RamCostConstants: IMap = { ScriptStanekPlace: 5, ScriptStanekFragmentAt: 2, ScriptStanekDeleteAt: 0.15, + ScriptStanekAcceptGift: 2, }; function SF4Cost(cost: number): (player: IPlayer) => number { @@ -284,6 +285,7 @@ const stanek: IMap = { placeFragment: RamCostConstants.ScriptStanekPlace, getFragment: RamCostConstants.ScriptStanekFragmentAt, removeFragment: RamCostConstants.ScriptStanekDeleteAt, + acceptGift: RamCostConstants.ScriptStanekAcceptGift, }; // UI API diff --git a/src/NetscriptFunctions/Stanek.ts b/src/NetscriptFunctions/Stanek.ts index 0b2010f6c..07a271a37 100644 --- a/src/NetscriptFunctions/Stanek.ts +++ b/src/NetscriptFunctions/Stanek.ts @@ -13,6 +13,10 @@ import { } from "../ScriptEditor/NetscriptDefinitions"; import { AugmentationNames } from "../Augmentation/data/AugmentationNames"; import { NetscriptContext, InternalAPI } from "../Netscript/APIWrapper"; +import { applyAugmentation } from "../Augmentation/AugmentationHelpers"; +import { FactionNames } from "../Faction/data/FactionNames"; +import { joinFaction } from "../Faction/FactionHelpers"; +import { Factions } from "../Faction/Factions"; export function NetscriptStanek( player: IPlayer, @@ -109,5 +113,28 @@ export function NetscriptStanek( checkStanekAPIAccess("removeFragment"); return staneksGift.delete(rootX, rootY); }, + acceptGift: (_ctx: NetscriptContext) => + function (): boolean { + //Check if the player has access to the church + if (player.canAccessCotMG()) { + //Attempt to join CotMG + const faction = Factions[FactionNames.ChurchOfTheMachineGod]; + if (!player.factions.includes(FactionNames.ChurchOfTheMachineGod)) { + joinFaction(faction); + } + //Attempt to install the first Stanek aug + if ( + !player.hasAugmentation(AugmentationNames.StaneksGift1) && + !player.queuedAugmentations.some((a) => a.name === AugmentationNames.StaneksGift1) + ) { + applyAugmentation({ name: AugmentationNames.StaneksGift1, level: 1 }); + } + } + //Return true iff the player is in CotMG and has the first Stanek aug installed + return ( + player.factions.includes(FactionNames.ChurchOfTheMachineGod) && + player.hasAugmentation(AugmentationNames.StaneksGift1) + ); + }, }; } diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index ba24d768b..b14c35af8 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -4261,6 +4261,16 @@ interface Stanek { * @returns The fragment at [rootX, rootY], if any. */ removeFragment(rootX: number, rootY: number): boolean; + + /** + * Accept Stanek's Gift by joining the Church of the Machine God + * @remarks + * RAM cost: 2 GB + * + * @returns true if the player is a member of the church and has the gift installed, + * false otherwise. + */ + acceptGift(): boolean; } /** From b3e83dd9760c1da451a2bc41bb8bff63b759ddc1 Mon Sep 17 00:00:00 2001 From: Undeemiss Date: Tue, 19 Apr 2022 13:33:07 -0500 Subject: [PATCH 2/7] Added check for aug status to stanek.acceptGift Added a check to stanek.acceptGift for aug status. It's not particularly elegant, but I copied the checks from the ui. Also changed the way CotMG status is checked to be more robust. --- src/NetscriptFunctions/Stanek.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/NetscriptFunctions/Stanek.ts b/src/NetscriptFunctions/Stanek.ts index 07a271a37..afd50f2bc 100644 --- a/src/NetscriptFunctions/Stanek.ts +++ b/src/NetscriptFunctions/Stanek.ts @@ -115,11 +115,15 @@ export function NetscriptStanek( }, acceptGift: (_ctx: NetscriptContext) => function (): boolean { - //Check if the player has access to the church - if (player.canAccessCotMG()) { + //Check if the player is eligible to join the church + if ( + player.canAccessCotMG() && + player.augmentations.filter((a) => a.name !== AugmentationNames.NeuroFluxGovernor).length == 0 && + player.queuedAugmentations.filter((a) => a.name !== AugmentationNames.NeuroFluxGovernor).length == 0 + ) { //Attempt to join CotMG const faction = Factions[FactionNames.ChurchOfTheMachineGod]; - if (!player.factions.includes(FactionNames.ChurchOfTheMachineGod)) { + if (!faction.isMember) { joinFaction(faction); } //Attempt to install the first Stanek aug @@ -132,7 +136,7 @@ export function NetscriptStanek( } //Return true iff the player is in CotMG and has the first Stanek aug installed return ( - player.factions.includes(FactionNames.ChurchOfTheMachineGod) && + Factions[FactionNames.ChurchOfTheMachineGod].isMember && player.hasAugmentation(AugmentationNames.StaneksGift1) ); }, From 6d55bfe79504b779baf137b79df1d6aaaaffa77e Mon Sep 17 00:00:00 2001 From: Undeemiss Date: Tue, 19 Apr 2022 13:39:56 -0500 Subject: [PATCH 3/7] Removed redundant check for whether the player is in CotMG --- src/NetscriptFunctions/Stanek.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/NetscriptFunctions/Stanek.ts b/src/NetscriptFunctions/Stanek.ts index afd50f2bc..e80e2f6f3 100644 --- a/src/NetscriptFunctions/Stanek.ts +++ b/src/NetscriptFunctions/Stanek.ts @@ -122,10 +122,7 @@ export function NetscriptStanek( player.queuedAugmentations.filter((a) => a.name !== AugmentationNames.NeuroFluxGovernor).length == 0 ) { //Attempt to join CotMG - const faction = Factions[FactionNames.ChurchOfTheMachineGod]; - if (!faction.isMember) { - joinFaction(faction); - } + joinFaction(Factions[FactionNames.ChurchOfTheMachineGod]); //Attempt to install the first Stanek aug if ( !player.hasAugmentation(AugmentationNames.StaneksGift1) && From 01d7ac6967781154506cd158cbafc38b9023b2d4 Mon Sep 17 00:00:00 2001 From: JP Sugarbroad Date: Sat, 16 Apr 2022 17:29:20 -0700 Subject: [PATCH 4/7] make jQuery use explicit --- jest.config.js | 1 - jest.setup.js | 2 -- package.json | 2 +- src/NetscriptFunctions.ts | 1 + src/Terminal/commands/wget.ts | 2 ++ webpack.config.js | 9 --------- 6 files changed, 4 insertions(+), 13 deletions(-) delete mode 100644 jest.setup.js diff --git a/jest.config.js b/jest.config.js index 12e22e92d..22f371dcd 100644 --- a/jest.config.js +++ b/jest.config.js @@ -1,5 +1,4 @@ module.exports = { - setupFiles: ["./jest.setup.js"], moduleFileExtensions: ["ts", "tsx", "js", "jsx"], transform: { "^.+\\.(js|jsx|ts|tsx)$": "babel-jest", diff --git a/jest.setup.js b/jest.setup.js deleted file mode 100644 index a10911aae..000000000 --- a/jest.setup.js +++ /dev/null @@ -1,2 +0,0 @@ -import "regenerator-runtime/runtime"; -global.$ = require("jquery"); diff --git a/package.json b/package.json index a5778a54b..2ce83ca4c 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ "@types/acorn": "^4.0.6", "@types/escodegen": "^0.0.7", "@types/file-saver": "^2.0.3", + "@types/jquery": "^3.5.14", "@types/lodash": "^4.14.168", "@types/numeral": "0.0.25", "@types/react": "^17.0.21", @@ -84,7 +85,6 @@ "prettier": "^2.3.2", "raw-loader": "^4.0.2", "react-refresh": "^0.10.0", - "regenerator-runtime": "^0.13.9", "source-map": "^0.7.3", "start-server-and-test": "^1.14.0", "typescript": "^4.2.4", diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index e0e1da770..f662f7543 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -1,3 +1,4 @@ +import $ from "jquery"; import { vsprintf, sprintf } from "sprintf-js"; import { getRamCost } from "./Netscript/RamCostGenerator"; diff --git a/src/Terminal/commands/wget.ts b/src/Terminal/commands/wget.ts index 72832c56e..8717ffcc2 100644 --- a/src/Terminal/commands/wget.ts +++ b/src/Terminal/commands/wget.ts @@ -1,3 +1,5 @@ +import $ from "jquery"; + import { ITerminal } from "../ITerminal"; import { IRouter } from "../../ui/Router"; import { IPlayer } from "../../PersonObjects/IPlayer"; diff --git a/webpack.config.js b/webpack.config.js index fa6b96960..5aa0b34e2 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -93,15 +93,6 @@ module.exports = (env, argv) => { new webpack.DefinePlugin({ "process.env.NODE_ENV": isDevelopment ? '"development"' : '"production"', }), - // http://stackoverflow.com/questions/29080148/expose-jquery-to-real-window-object-with-webpack - new webpack.ProvidePlugin({ - // Automtically detect jQuery and $ as free var in modules - // and inject the jquery library - // This is required by many jquery plugins - jquery: "jquery", - jQuery: "jquery", - $: "jquery", - }), new HtmlWebpackPlugin(htmlConfig), new MiniCssExtractPlugin({ filename: "[name].css", From d5be70e8861e39381ee3f42208deffdbbc52478a Mon Sep 17 00:00:00 2001 From: JP Sugarbroad Date: Tue, 19 Apr 2022 17:06:36 -0700 Subject: [PATCH 5/7] update @types/numeral and fix type errors --- package.json | 2 +- src/ui/numeralFormat.ts | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index a5778a54b..28f0c6559 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "@types/escodegen": "^0.0.7", "@types/file-saver": "^2.0.3", "@types/lodash": "^4.14.168", - "@types/numeral": "0.0.25", + "@types/numeral": "^2.0.2", "@types/react": "^17.0.21", "@types/react-beautiful-dnd": "^13.1.2", "@types/react-dom": "^17.0.9", diff --git a/src/ui/numeralFormat.ts b/src/ui/numeralFormat.ts index 170e9a466..6a7325e04 100644 --- a/src/ui/numeralFormat.ts +++ b/src/ui/numeralFormat.ts @@ -223,19 +223,21 @@ class NumeralFormatter { const parsed = parseFloat(s); const selfParsed = this.parseCustomLargeNumber(s); // Check for one or more NaN values - if (isNaN(parsed) && numeralValue === null && isNaN(selfParsed)) { - // 3x NaN - return NaN; - } else if (isNaN(parsed) && isNaN(selfParsed)) { + if (isNaN(parsed) && isNaN(selfParsed)) { + if (numeralValue === null) { + // 3x NaN + return NaN; + } // 2x NaN return numeralValue; } else if (numeralValue === null && isNaN(selfParsed)) { // 2x NaN return parsed; - } else if (isNaN(parsed) && numeralValue === null) { - // 2x NaN - return selfParsed; } else if (isNaN(parsed)) { + if (numeralValue === null) { + // 2x NaN + return selfParsed; + } // 1x NaN return this.largestAbsoluteNumber(numeralValue, selfParsed); } else if (numeralValue === null) { From 16e507127ac892ddac9616eb92a864cf1e3d4706 Mon Sep 17 00:00:00 2001 From: Snarling <84951833+Snarling@users.noreply.github.com> Date: Wed, 20 Apr 2022 10:03:51 -0400 Subject: [PATCH 6/7] Allow cd .. into empty directories --- src/Terminal/commands/cd.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Terminal/commands/cd.ts b/src/Terminal/commands/cd.ts index ac1c63fa3..7fb9d2c7b 100644 --- a/src/Terminal/commands/cd.ts +++ b/src/Terminal/commands/cd.ts @@ -30,7 +30,11 @@ export function cd( terminal.error("Invalid path. Failed to change directories"); return; } - + if (terminal.cwd().length>1 && dir === ".."){ + terminal.setcwd(evaledDir); + return; + } + const server = player.getCurrentServer(); if (!containsFiles(server, evaledDir)) { terminal.error("Invalid path. Failed to change directories"); From 3f53a1f090d5960b595faa0e2f29b08b144533e1 Mon Sep 17 00:00:00 2001 From: Snarling <84951833+Snarling@users.noreply.github.com> Date: Wed, 20 Apr 2022 10:05:55 -0400 Subject: [PATCH 7/7] Format+lint --- src/Terminal/commands/cd.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Terminal/commands/cd.ts b/src/Terminal/commands/cd.ts index 7fb9d2c7b..174f557bd 100644 --- a/src/Terminal/commands/cd.ts +++ b/src/Terminal/commands/cd.ts @@ -30,11 +30,11 @@ export function cd( terminal.error("Invalid path. Failed to change directories"); return; } - if (terminal.cwd().length>1 && dir === ".."){ + if (terminal.cwd().length > 1 && dir === "..") { terminal.setcwd(evaledDir); return; } - + const server = player.getCurrentServer(); if (!containsFiles(server, evaledDir)) { terminal.error("Invalid path. Failed to change directories");