From 1baa615def7ecd3c20c33c99e2996f67a4d4849d Mon Sep 17 00:00:00 2001 From: Mughur Date: Mon, 2 Jan 2023 20:51:59 +0200 Subject: [PATCH] MISC: small fixes (#270) * infiltration gain bug fix * fix corp division description * avoid some issues with Infinity at super high NFG levels Co-authored-by: Daniel Perez Alvarez --- .../guidesandtips/recommendedbitnodeorder.rst | 7 ++++--- src/Faction/FactionHelpers.tsx | 1 + src/Gang/formulas/formulas.ts | 2 +- src/Infiltration/ui/Victory.tsx | 2 -- src/ScriptEditor/NetscriptDefinitions.d.ts | 13 ++++++++----- src/Server/ServerHelpers.ts | 7 ++++--- src/engine.tsx | 2 +- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/doc/source/guidesandtips/recommendedbitnodeorder.rst b/doc/source/guidesandtips/recommendedbitnodeorder.rst index 217ce21a7..2513541df 100644 --- a/doc/source/guidesandtips/recommendedbitnodeorder.rst +++ b/doc/source/guidesandtips/recommendedbitnodeorder.rst @@ -466,11 +466,12 @@ Path 1 (new): is extremely powerful, as it raises all multipliers by a significant amount. This also a let's you get used to augments and other features resetting. -2. Do **BitNode-3: Corporatocracy** once to unlock the Corporation mechanic. This mechanic - has highest profit potential in the game. +2. Do **BitNode-3: Corporatocracy** at least once to unlock the Corporation mechanic, finishing all + 3 levels unlocks the full API for free allowing fully scripted corp. This mechanic has highest + profit potential in the game. 3. Do **BitNode-10: Digital Carbon** once to unlock sleeves and grafting. Sleeves are useful in all nodes - and grafting can be useful in future BitNodes (especially 8). It's recommended to buy all sleeves and + and grafting can be useful in future BitNodes (especially 8). It's recommended to buy all purchasable sleeves and their memory during the first run. The ordering of the next three is dependant on playing style and wants/needs. diff --git a/src/Faction/FactionHelpers.tsx b/src/Faction/FactionHelpers.tsx index 5e51d20aa..a45f87111 100644 --- a/src/Faction/FactionHelpers.tsx +++ b/src/Faction/FactionHelpers.tsx @@ -107,6 +107,7 @@ export function purchaseAugmentation(aug: Augmentation, fac: Faction, sing = fal } export function processPassiveFactionRepGain(numCycles: number): void { + if (Player.bitNodeN === 2) return; for (const name of Object.keys(Factions)) { if (isFactionWork(Player.currentWork) && name === Player.currentWork.factionName) continue; if (!Factions.hasOwnProperty(name)) continue; diff --git a/src/Gang/formulas/formulas.ts b/src/Gang/formulas/formulas.ts index 8d05b9247..566863348 100644 --- a/src/Gang/formulas/formulas.ts +++ b/src/Gang/formulas/formulas.ts @@ -9,7 +9,7 @@ export interface FormulaGang { } export function calculateWantedPenalty(gang: FormulaGang): number { - return gang.respect / (gang.respect + gang.wantedLevel); + return Math.max(gang.respect + 0.0001) / (gang.respect + gang.wantedLevel); } export function calculateRespectGain(gang: FormulaGang, member: GangMember, task: GangMemberTask): number { diff --git a/src/Infiltration/ui/Victory.tsx b/src/Infiltration/ui/Victory.tsx index 7fb7a9609..6fc7ced06 100644 --- a/src/Infiltration/ui/Victory.tsx +++ b/src/Infiltration/ui/Victory.tsx @@ -38,14 +38,12 @@ export function Victory(props: IProps): React.ReactElement { const isMemberOfInfiltrators = Player.factions.includes(FactionNames.ShadowsOfAnarchy); function sell(): void { - handleInfiltrators(); Player.gainMoney(moneyGain, "infiltration"); quitInfiltration(); } function trade(): void { if (faction === "none") return; - handleInfiltrators(); Factions[faction].playerReputation += repGain; quitInfiltration(); } diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 3a1a99a36..0e1b20f55 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -3938,6 +3938,7 @@ interface HackingFormulas { hackPercent(server: Server, player: Person): number; /** * Calculate the percent a server would grow to. + * Not exact due to limitations of mathematics. * (Ex: 3.0 would would grow the server to 300% of its current value.) * @param server - Server info from {@link NS.getServer | getServer} * @param threads - Amount of thread. @@ -4615,11 +4616,11 @@ export interface NS { * * Use your hacking skills to increase the amount of money available on a server. * The runtime for this command depends on your hacking level and the target server’s - * security level. When `grow` completes, the money available on a target server will - * be increased by a certain, fixed percentage. This percentage is determined by the - * target server’s growth rate (which varies between servers) and security level. Generally, - * higher-level servers have higher growth rates. The {@link NS.getServerGrowth | getServerGrowth} function can be used - * to obtain a server’s growth rate. + * security level. When `grow` completes, the money available on a target server will be increased + * by amount equal to the number of threads used and a certain, fixed percentage of current money on + * the server. This percentage is determined by the target server’s growth rate (which varies between servers) + * and security level. Generally, higher-level servers have higher growth rates. + * The {@link NS.getServerGrowth | getServerGrowth} function can be used to obtain a server’s growth rate. * * Like {@link NS.hack | hack}, `grow` can be called on any server, regardless of where the script is running. * The grow() command requires root access to the target server, but there is no required hacking @@ -4773,6 +4774,8 @@ export interface NS { * the amount of money available on the specified server by the specified amount. * The specified amount is multiplicative and is in decimal form, not percentage. * + * Due to limitations of mathematics, this function won't be the true value, but an approximation. + * * Warning: The value returned by this function isn’t necessarily a whole number. * * @example diff --git a/src/Server/ServerHelpers.ts b/src/Server/ServerHelpers.ts index 489c59df8..3db62bbe2 100644 --- a/src/Server/ServerHelpers.ts +++ b/src/Server/ServerHelpers.ts @@ -183,14 +183,15 @@ export function numCycleForGrowthCorrected(server: Server, targetMoney: number, */ let bt = exponentialBase ** threadMultiplier; if (bt == Infinity) bt = 1e300; - let corr = Infinity; // Two sided error because we do not want to get stuck if the error stays on the wrong side do { // c should be above 0 so Halley's method can't be used, we have to stick to Newton-Raphson - const bct = bt ** cycles; + let bct = bt ** cycles; + if (bct == Infinity) bct = 1e300; const opc = startMoney + cycles; - const diff = opc * bct - targetMoney; + let diff = opc * bct - targetMoney; + if (diff == Infinity) diff = 1e300; corr = diff / (opc * x + 1.0) / bct; cycles -= corr; } while (Math.abs(corr) >= 1); diff --git a/src/engine.tsx b/src/engine.tsx index f3780988f..87bea912d 100644 --- a/src/engine.tsx +++ b/src/engine.tsx @@ -275,7 +275,7 @@ const Engine: { if (Player.currentWork !== null) { Player.focus = true; Player.processWork(numCyclesOffline); - } else { + } else if (Player.bitNodeN !== 2) { for (let i = 0; i < Player.factions.length; i++) { const facName = Player.factions[i]; if (!Factions.hasOwnProperty(facName)) continue;