MESSAGES: Re-implement limit on Icarus messages after a bitnode is completed (#742)

This commit is contained in:
Michael Ficocelli 2023-08-28 14:38:15 -04:00 committed by GitHub
parent 93235570d0
commit 79b677973b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 66 additions and 1 deletions

@ -58,7 +58,10 @@ function checkForMessagesToSend(): void {
throw new Error("The world daemon is not a server???? Please un-break reality");
}
//If the daemon can be hacked, send the player icarus.msg
if (Player.skills.hacking >= worldDaemon.requiredHackingSkill) {
if (
Player.skills.hacking >= worldDaemon.requiredHackingSkill &&
(Player.sourceFiles.size === 0 || !recvd(MessageFilename.RedPill))
) {
sendMessage(MessageFilename.RedPill, Player.sourceFiles.size === 0);
}
//If the daemon cannot be hacked, send the player truthgazer.msg a single time.

@ -0,0 +1,62 @@
import { checkForMessagesToSend } from "../../../src/Message/MessageHelpers";
import * as dialogBoxCreate from "../../../src/ui/React/DialogBox";
import { Player } from "@player";
import "../../../src/ui/GameRoot";
import { AugmentationName } from "@enums";
import { AddToAllServers } from "../../../src/Server/AllServers";
import { Server } from "../../../src/Server/Server";
import { installAugmentations } from "../../../src/Augmentation/AugmentationHelpers";
import { initSourceFiles } from "../../../src/SourceFile/SourceFiles";
jest.mock("../../../src/ui/GameRoot", () => ({
Router: {
page: () => ({}),
toPage: () => ({}),
},
}));
jest.mock("../../../src/ui/React/DialogBox", () => ({
dialogBoxCreate: jest.fn(),
}));
AddToAllServers(new Server({ hostname: "home" }));
describe("MessageHelpers tests", () => {
afterEach(() => {
jest.clearAllMocks();
});
it("Should repeatedly send the Icarus message on the player's first bitnode", () => {
Player.queueAugmentation(AugmentationName.TheRedPill);
installAugmentations();
Player.gainHackingExp(2 ** 200);
const showMessageSpy = jest.spyOn(dialogBoxCreate, "dialogBoxCreate");
checkForMessagesToSend();
checkForMessagesToSend();
// Called once for installing augmentations, and once for each
// checkForMessagesToSend() sending an Icarus message
expect(showMessageSpy).toHaveBeenCalledTimes(3);
});
it("Should not repeatedly send the Icarus message after the player's first bitnode completion", () => {
initSourceFiles();
Player.sourceFiles.set(1, 1);
Player.queueAugmentation(AugmentationName.TheRedPill);
installAugmentations();
Player.gainHackingExp(2 ** 200);
const showMessageSpy = jest.spyOn(dialogBoxCreate, "dialogBoxCreate");
checkForMessagesToSend();
checkForMessagesToSend();
checkForMessagesToSend();
checkForMessagesToSend();
// Called once for installing augmentations, and only once for any number of
// checkForMessagesToSend() ( sending an Icarus message only the first time)
expect(showMessageSpy).toHaveBeenCalledTimes(2);
});
});