diff --git a/markdown/bitburner.gang.getotherganginformation.md b/markdown/bitburner.gang.getallganginformation.md similarity index 71% rename from markdown/bitburner.gang.getotherganginformation.md rename to markdown/bitburner.gang.getallganginformation.md index 281bbdd7d..f41282659 100644 --- a/markdown/bitburner.gang.getotherganginformation.md +++ b/markdown/bitburner.gang.getallganginformation.md @@ -1,15 +1,15 @@ -[Home](./index.md) > [bitburner](./bitburner.md) > [Gang](./bitburner.gang.md) > [getOtherGangInformation](./bitburner.gang.getotherganginformation.md) +[Home](./index.md) > [bitburner](./bitburner.md) > [Gang](./bitburner.gang.md) > [getAllGangInformation](./bitburner.gang.getallganginformation.md) -## Gang.getOtherGangInformation() method +## Gang.getAllGangInformation() method Get information about all gangs. **Signature:** ```typescript -getOtherGangInformation(): Record; +getAllGangInformation(): Record; ``` **Returns:** diff --git a/markdown/bitburner.gang.md b/markdown/bitburner.gang.md index 2145895fa..242d9882b 100644 --- a/markdown/bitburner.gang.md +++ b/markdown/bitburner.gang.md @@ -61,6 +61,17 @@ Check if you can recruit a new gang member. Create a gang. + + + +[getAllGangInformation()](./bitburner.gang.getallganginformation.md) + + + + +Get information about all gangs. + + @@ -182,17 +193,6 @@ Get information about a specific gang member. List all gang members. - - - -[getOtherGangInformation()](./bitburner.gang.getotherganginformation.md) - - - - -Get information about all gangs. - - diff --git a/src/Documentation/pages.ts b/src/Documentation/pages.ts index 8d1ce9335..69d7a8d26 100644 --- a/src/Documentation/pages.ts +++ b/src/Documentation/pages.ts @@ -561,6 +561,7 @@ import nsDoc_bitburner_gameinfo_versionnumber_md from "../../markdown/bitburner. import nsDoc_bitburner_gang_ascendmember_md from "../../markdown/bitburner.gang.ascendmember.md?raw"; import nsDoc_bitburner_gang_canrecruitmember_md from "../../markdown/bitburner.gang.canrecruitmember.md?raw"; import nsDoc_bitburner_gang_creategang_md from "../../markdown/bitburner.gang.creategang.md?raw"; +import nsDoc_bitburner_gang_getallganginformation_md from "../../markdown/bitburner.gang.getallganginformation.md?raw"; import nsDoc_bitburner_gang_getascensionresult_md from "../../markdown/bitburner.gang.getascensionresult.md?raw"; import nsDoc_bitburner_gang_getbonustime_md from "../../markdown/bitburner.gang.getbonustime.md?raw"; import nsDoc_bitburner_gang_getchancetowinclash_md from "../../markdown/bitburner.gang.getchancetowinclash.md?raw"; @@ -572,7 +573,6 @@ import nsDoc_bitburner_gang_getganginformation_md from "../../markdown/bitburner import nsDoc_bitburner_gang_getinstallresult_md from "../../markdown/bitburner.gang.getinstallresult.md?raw"; import nsDoc_bitburner_gang_getmemberinformation_md from "../../markdown/bitburner.gang.getmemberinformation.md?raw"; import nsDoc_bitburner_gang_getmembernames_md from "../../markdown/bitburner.gang.getmembernames.md?raw"; -import nsDoc_bitburner_gang_getotherganginformation_md from "../../markdown/bitburner.gang.getotherganginformation.md?raw"; import nsDoc_bitburner_gang_getrecruitsavailable_md from "../../markdown/bitburner.gang.getrecruitsavailable.md?raw"; import nsDoc_bitburner_gang_gettasknames_md from "../../markdown/bitburner.gang.gettasknames.md?raw"; import nsDoc_bitburner_gang_gettaskstats_md from "../../markdown/bitburner.gang.gettaskstats.md?raw"; @@ -2157,6 +2157,7 @@ AllPages["nsDoc/bitburner.gameinfo.versionnumber.md"] = nsDoc_bitburner_gameinfo AllPages["nsDoc/bitburner.gang.ascendmember.md"] = nsDoc_bitburner_gang_ascendmember_md; AllPages["nsDoc/bitburner.gang.canrecruitmember.md"] = nsDoc_bitburner_gang_canrecruitmember_md; AllPages["nsDoc/bitburner.gang.creategang.md"] = nsDoc_bitburner_gang_creategang_md; +AllPages["nsDoc/bitburner.gang.getallganginformation.md"] = nsDoc_bitburner_gang_getallganginformation_md; AllPages["nsDoc/bitburner.gang.getascensionresult.md"] = nsDoc_bitburner_gang_getascensionresult_md; AllPages["nsDoc/bitburner.gang.getbonustime.md"] = nsDoc_bitburner_gang_getbonustime_md; AllPages["nsDoc/bitburner.gang.getchancetowinclash.md"] = nsDoc_bitburner_gang_getchancetowinclash_md; @@ -2168,7 +2169,6 @@ AllPages["nsDoc/bitburner.gang.getganginformation.md"] = nsDoc_bitburner_gang_ge AllPages["nsDoc/bitburner.gang.getinstallresult.md"] = nsDoc_bitburner_gang_getinstallresult_md; AllPages["nsDoc/bitburner.gang.getmemberinformation.md"] = nsDoc_bitburner_gang_getmemberinformation_md; AllPages["nsDoc/bitburner.gang.getmembernames.md"] = nsDoc_bitburner_gang_getmembernames_md; -AllPages["nsDoc/bitburner.gang.getotherganginformation.md"] = nsDoc_bitburner_gang_getotherganginformation_md; AllPages["nsDoc/bitburner.gang.getrecruitsavailable.md"] = nsDoc_bitburner_gang_getrecruitsavailable_md; AllPages["nsDoc/bitburner.gang.gettasknames.md"] = nsDoc_bitburner_gang_gettasknames_md; AllPages["nsDoc/bitburner.gang.gettaskstats.md"] = nsDoc_bitburner_gang_gettaskstats_md; diff --git a/src/Netscript/RamCostGenerator.ts b/src/Netscript/RamCostGenerator.ts index 5d0d8ed32..b6a71c37f 100644 --- a/src/Netscript/RamCostGenerator.ts +++ b/src/Netscript/RamCostGenerator.ts @@ -275,7 +275,7 @@ const gang = { getMemberNames: RamCostConstants.GangApiBase / 4, renameMember: 0, getGangInformation: RamCostConstants.GangApiBase / 2, - getOtherGangInformation: RamCostConstants.GangApiBase / 2, + getAllGangInformation: RamCostConstants.GangApiBase / 2, getMemberInformation: RamCostConstants.GangApiBase / 2, canRecruitMember: RamCostConstants.GangApiBase / 4, getRecruitsAvailable: RamCostConstants.GangApiBase / 4, diff --git a/src/NetscriptFunctions/Gang.ts b/src/NetscriptFunctions/Gang.ts index adeba6025..935a498eb 100644 --- a/src/NetscriptFunctions/Gang.ts +++ b/src/NetscriptFunctions/Gang.ts @@ -2,7 +2,7 @@ import type { Gang as IGang, EquipmentStats, GangOtherInfoObject } from "@nsdefs import type { Gang } from "../Gang/Gang"; import type { GangMember } from "../Gang/GangMember"; import type { GangMemberTask } from "../Gang/GangMemberTask"; -import type { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper"; +import { type InternalAPI, type NetscriptContext, setRemovedFunctions } from "../Netscript/APIWrapper"; import { GangPromise, RecruitmentResult } from "../Gang/Gang"; import { Player } from "@player"; @@ -37,7 +37,7 @@ export function NetscriptGang(): InternalAPI { return task; }; - return { + const gangFunctions: InternalAPI = { createGang: (ctx) => (_faction) => { const faction = getEnumHelper("FactionName").nsGetMember(ctx, _faction); if (Player.gang) { @@ -117,7 +117,7 @@ export function NetscriptGang(): InternalAPI { equipmentCostMult: 1 / gang.getDiscount(), }; }, - getOtherGangInformation: (ctx) => () => { + getAllGangInformation: (ctx) => () => { getGang(ctx); const cpy: Record = {}; for (const gang of Object.keys(AllGangs)) { @@ -362,4 +362,10 @@ export function NetscriptGang(): InternalAPI { return GangPromise.promise; }, }; + + // Removed functions + setRemovedFunctions(gangFunctions, { + getOtherGangInformation: { version: "3.0.0", replacement: "gang.getAllGangInformation" }, + }); + return gangFunctions; } diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index eb4046ee2..87b392a3c 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -4879,7 +4879,7 @@ export interface Gang { * * @returns Object containing territory and power information about all gangs, including the player's gang, if any. */ - getOtherGangInformation(): Record; + getAllGangInformation(): Record; /** * Get information about a specific gang member. diff --git a/src/utils/APIBreaks/3.0.0.ts b/src/utils/APIBreaks/3.0.0.ts index bf4508c11..1c06e6437 100644 --- a/src/utils/APIBreaks/3.0.0.ts +++ b/src/utils/APIBreaks/3.0.0.ts @@ -384,6 +384,21 @@ export const breakingChanges300: VersionBreakingChange = { `- "White Ferrari" was renamed to "${convertV2GangEquipmentNames("White Ferrari")}".\n`, showWarning: false, }, + { + brokenAPIs: [ + { + name: "ns.gang.getOtherGangInformation", + migration: { + searchValue: "getOtherGangInformation", + replaceValue: "getAllGangInformation", + }, + }, + ], + info: + "ns.gang.getOtherGangInformation() was renamed to ns.gang.getAllGangInformation().\n" + + "The function was renamed because it returns information about all gangs, including the player's own gang.", + showWarning: false, + }, { brokenAPIs: [{ name: "purchase4SMarketData" }], info: diff --git a/test/jest/Netscript/Gang.test.ts b/test/jest/Netscript/Gang.test.ts new file mode 100644 index 000000000..667bdf362 --- /dev/null +++ b/test/jest/Netscript/Gang.test.ts @@ -0,0 +1,46 @@ +import { FactionName } from "@enums"; +import { Player } from "@player"; +import { Gang } from "../../../src/Gang/Gang"; +import { AllGangs } from "../../../src/Gang/AllGangs"; +import { getNS, initGameEnvironment, setupBasicTestingEnvironment } from "../Utilities"; + +beforeAll(() => { + initGameEnvironment(); +}); + +beforeEach(() => { + setupBasicTestingEnvironment(); + // Give the player a gang so gang API is accessible + Player.gang = new Gang(FactionName.SlumSnakes, false); +}); + +describe("ns.gang.getAllGangInformation", () => { + it("should return territory and power info for all gangs including the player's", () => { + const ns = getNS(); + const info = ns.gang.getAllGangInformation(); + const gangNames = Object.keys(info); + + // Should include all 7 gangs + expect(gangNames).toHaveLength(Object.keys(AllGangs).length); + + // Should include the player's own gang + expect(info[FactionName.SlumSnakes]).toBeDefined(); + + // Each entry should have power and territory + for (const name of gangNames) { + expect(info[name]).toHaveProperty("power"); + expect(info[name]).toHaveProperty("territory"); + expect(typeof info[name].power).toBe("number"); + expect(typeof info[name].territory).toBe("number"); + } + }); + + it("should return copies, not references to the original AllGangs data", () => { + const ns = getNS(); + const info = ns.gang.getAllGangInformation(); + + // Mutating the returned data should not affect AllGangs + info[FactionName.SlumSnakes].power = 999999; + expect(AllGangs[FactionName.SlumSnakes].power).not.toBe(999999); + }); +});