UI: Show hints of Gang mechanic in pre-endgame (#2723)

This commit is contained in:
catloversg
2026-05-07 05:22:43 +07:00
committed by GitHub
parent 2ab144cff2
commit eb431145ee
9 changed files with 216 additions and 106 deletions
+64 -6
View File
@@ -1,8 +1,10 @@
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";
import { getNS, getWorkerScriptAndNS, initGameEnvironment, setupBasicTestingEnvironment } from "../Utilities";
import { GangConstants } from "../../../src/Gang/data/Constants";
import { joinFaction } from "../../../src/Faction/FactionHelpers";
import { Factions } from "../../../src/Faction/Factions";
beforeAll(() => {
initGameEnvironment();
@@ -10,12 +12,16 @@ beforeAll(() => {
beforeEach(() => {
setupBasicTestingEnvironment();
// Give the player a gang so gang API is accessible
Player.gang = new Gang(FactionName.SlumSnakes, false);
Player.sourceFiles.set(2, 3);
});
describe("ns.gang.getAllGangInformation", () => {
it("should return territory and power info for all gangs including the player's", () => {
beforeEach(() => {
// Give the player a gang so gang API is accessible
Player.startGang(FactionName.SlumSnakes, false);
});
test("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);
@@ -35,7 +41,7 @@ describe("ns.gang.getAllGangInformation", () => {
}
});
it("should return copies, not references to the original AllGangs data", () => {
test("should return copies, not references to the original AllGangs data", () => {
const ns = getNS();
const info = ns.gang.getAllGangInformation();
@@ -44,3 +50,55 @@ describe("ns.gang.getAllGangInformation", () => {
expect(AllGangs[FactionName.SlumSnakes].power).not.toBe(999999);
});
});
describe("createGang", () => {
test("Success", () => {
const ns = getNS();
Player.karma = GangConstants.GangKarmaRequirement;
joinFaction(Factions[FactionName.SlumSnakes]);
expect(ns.gang.createGang(FactionName.SlumSnakes)).toBe(true);
});
describe("Failure", () => {
test("Already have a gang", () => {
const { ws, ns } = getWorkerScriptAndNS();
Player.karma = GangConstants.GangKarmaRequirement;
joinFaction(Factions[FactionName.SlumSnakes]);
expect(ns.gang.createGang(FactionName.SlumSnakes)).toBe(true);
expect(ns.gang.createGang(FactionName.SlumSnakes)).toBe(false);
expect(ws.scriptRef.logs[0]).toMatch("You already have a gang");
expect(ns.gang.createGang(FactionName.Tetrads)).toBe(false);
expect(ws.scriptRef.logs[1]).toMatch("You already have a gang");
});
test("Disabled by advanced options", () => {
const { ws, ns } = getWorkerScriptAndNS();
Player.bitNodeOptions.disableGang = true;
expect(ns.gang.createGang(FactionName.SlumSnakes)).toBe(false);
expect(ws.scriptRef.logs[0]).toMatch("Gang is disabled by advanced options");
});
test("Not have Source-File 2", () => {
const { ws, ns } = getWorkerScriptAndNS();
Player.sourceFiles.set(2, 0);
expect(ns.gang.createGang(FactionName.SlumSnakes)).toBe(false);
expect(ws.scriptRef.logs[0]).toMatch("You do not have Source-File 2");
});
test("Not enough karma", () => {
const { ws, ns } = getWorkerScriptAndNS();
expect(ns.gang.createGang(FactionName.SlumSnakes)).toBe(false);
expect(ws.scriptRef.logs[0]).toMatch("Your karma must be less than or equal to");
});
test("Invalid gang faction", () => {
const { ws, ns } = getWorkerScriptAndNS();
Player.karma = GangConstants.GangKarmaRequirement;
joinFaction(Factions[FactionName.SlumSnakes]);
expect(ns.gang.createGang(FactionName.Illuminati)).toBe(false);
expect(ws.scriptRef.logs[0]).toMatch("does not allow creating a gang");
});
test("Not a faction member", () => {
const { ws, ns } = getWorkerScriptAndNS();
Player.karma = GangConstants.GangKarmaRequirement;
expect(ns.gang.createGang(FactionName.SlumSnakes)).toBe(false);
expect(ws.scriptRef.logs[0]).toMatch("You are not a member of");
});
});
});