Merge pull request #3421 from Undeemiss/message-refactor

Removed redpillFlag and refactored MessageHelpers.ts
This commit is contained in:
hydroflame 2022-04-13 00:27:14 -04:00 committed by GitHub
commit 16dd31331d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 46 deletions

@ -2,7 +2,7 @@ import React, { useState } from "react";
import { SourceFileFlags } from "../../SourceFile/SourceFileFlags"; import { SourceFileFlags } from "../../SourceFile/SourceFileFlags";
import { IRouter } from "../../ui/Router"; import { IRouter } from "../../ui/Router";
import { BitNodes } from "../BitNode"; import { BitNodes } from "../BitNode";
import { enterBitNode, setRedPillFlag } from "../../RedPill"; import { enterBitNode } from "../../RedPill";
import { PortalModal } from "./PortalModal"; import { PortalModal } from "./PortalModal";
import { CinematicText } from "../../ui/React/CinematicText"; import { CinematicText } from "../../ui/React/CinematicText";
import { use } from "../../ui/Context"; import { use } from "../../ui/Context";
@ -123,7 +123,6 @@ interface IProps {
} }
export function BitverseRoot(props: IProps): React.ReactElement { export function BitverseRoot(props: IProps): React.ReactElement {
setRedPillFlag(true);
const player = use.Player(); const player = use.Player();
const enter = enterBitNode; const enter = enterBitNode;
const destroyed = player.bitNodeN; const destroyed = player.bitNodeN;

@ -1,9 +1,9 @@
import { Message } from "./Message"; import { Message } from "./Message";
import { Augmentations } from "../Augmentation/Augmentations";
import { AugmentationNames } from "../Augmentation/data/AugmentationNames"; import { AugmentationNames } from "../Augmentation/data/AugmentationNames";
import { Router } from "../ui/GameRoot";
import { Programs } from "../Programs/Programs"; import { Programs } from "../Programs/Programs";
import { Player } from "../Player"; import { Player } from "../Player";
import { redPillFlag } from "../RedPill"; import { Page } from "../ui/Router";
import { GetServer } from "../Server/AllServers"; import { GetServer } from "../Server/AllServers";
import { Settings } from "../Settings/Settings"; import { Settings } from "../Settings/Settings";
import { dialogBoxCreate } from "../ui/React/DialogBox"; import { dialogBoxCreate } from "../ui/React/DialogBox";
@ -51,7 +51,7 @@ function addMessageToServer(msg: Message, serverHostname: string): void {
//Checks if any of the 'timed' messages should be sent //Checks if any of the 'timed' messages should be sent
function checkForMessagesToSend(): void { function checkForMessagesToSend(): void {
if (redPillFlag) return; if (Router.page() === Page.BitVerse) return;
const jumper0 = Messages[MessageFilenames.Jumper0]; const jumper0 = Messages[MessageFilenames.Jumper0];
const jumper1 = Messages[MessageFilenames.Jumper1]; const jumper1 = Messages[MessageFilenames.Jumper1];
const jumper2 = Messages[MessageFilenames.Jumper2]; const jumper2 = Messages[MessageFilenames.Jumper2];
@ -62,38 +62,29 @@ function checkForMessagesToSend(): void {
const bitrunnersTest = Messages[MessageFilenames.BitRunnersTest]; const bitrunnersTest = Messages[MessageFilenames.BitRunnersTest];
const redpill = Messages[MessageFilenames.RedPill]; const redpill = Messages[MessageFilenames.RedPill];
let redpillOwned = false; if (Player.hasAugmentation(AugmentationNames.TheRedPill)) {
if (Augmentations[AugmentationNames.TheRedPill].owned) { //Force the message if the player has never destroyed a BitNode
redpillOwned = true; sendMessage(redpill, Player.sourceFiles.length === 0);
} } else if (!jumper0.recvd && Player.hacking >= 25) {
if (redpill && redpillOwned && Player.sourceFiles.length === 0 && !redPillFlag) {
sendMessage(redpill, true);
} else if (redpill && redpillOwned) {
//If player has already destroyed a BitNode, message is not forced
if (!redPillFlag) {
sendMessage(redpill);
}
} else if (jumper0 && !jumper0.recvd && Player.hacking >= 25) {
sendMessage(jumper0); sendMessage(jumper0);
const flightName = Programs.Flight.name; const flightName = Programs.Flight.name;
const homeComp = Player.getHomeComputer(); const homeComp = Player.getHomeComputer();
if (!homeComp.programs.includes(flightName)) { if (!homeComp.programs.includes(flightName)) {
homeComp.programs.push(flightName); homeComp.programs.push(flightName);
} }
} else if (jumper1 && !jumper1.recvd && Player.hacking >= 40) { } else if (!jumper1.recvd && Player.hacking >= 40) {
sendMessage(jumper1); sendMessage(jumper1);
} else if (cybersecTest && !cybersecTest.recvd && Player.hacking >= 50) { } else if (!cybersecTest.recvd && Player.hacking >= 50) {
sendMessage(cybersecTest); sendMessage(cybersecTest);
} else if (jumper2 && !jumper2.recvd && Player.hacking >= 175) { } else if (!jumper2.recvd && Player.hacking >= 175) {
sendMessage(jumper2); sendMessage(jumper2);
} else if (nitesecTest && !nitesecTest.recvd && Player.hacking >= 200) { } else if (!nitesecTest.recvd && Player.hacking >= 200) {
sendMessage(nitesecTest); sendMessage(nitesecTest);
} else if (jumper3 && !jumper3.recvd && Player.hacking >= 350) { } else if (!jumper3.recvd && Player.hacking >= 350) {
sendMessage(jumper3); sendMessage(jumper3);
} else if (jumper4 && !jumper4.recvd && Player.hacking >= 490) { } else if (!jumper4.recvd && Player.hacking >= 490) {
sendMessage(jumper4); sendMessage(jumper4);
} else if (bitrunnersTest && !bitrunnersTest.recvd && Player.hacking >= 500) { } else if (!bitrunnersTest.recvd && Player.hacking >= 500) {
sendMessage(bitrunnersTest); sendMessage(bitrunnersTest);
} }
} }
@ -102,23 +93,23 @@ function AddToAllMessages(msg: Message): void {
Messages[msg.filename] = msg; Messages[msg.filename] = msg;
} }
let Messages: { [key: string]: Message | undefined } = {}; let Messages: { [key: string]: Message } = {};
function loadMessages(saveString: string): void { function loadMessages(saveString: string): void {
Messages = JSON.parse(saveString, Reviver); Messages = JSON.parse(saveString, Reviver);
} }
const MessageFilenames = { enum MessageFilenames {
Jumper0: "j0.msg", Jumper0 = "j0.msg",
Jumper1: "j1.msg", Jumper1 = "j1.msg",
Jumper2: "j2.msg", Jumper2 = "j2.msg",
Jumper3: "j3.msg", Jumper3 = "j3.msg",
Jumper4: "j4.msg", Jumper4 = "j4.msg",
CyberSecTest: "csec-test.msg", CyberSecTest = "csec-test.msg",
NiteSecTest: "nitesec-test.msg", NiteSecTest = "nitesec-test.msg",
BitRunnersTest: "19dfj3l1nd.msg", BitRunnersTest = "19dfj3l1nd.msg",
RedPill: "icarus.msg", RedPill = "icarus.msg",
}; }
function initMessages(): void { function initMessages(): void {
//Reset //Reset

@ -11,12 +11,6 @@ import { SourceFiles } from "./SourceFile/SourceFiles";
import { dialogBoxCreate } from "./ui/React/DialogBox"; import { dialogBoxCreate } from "./ui/React/DialogBox";
import { IRouter } from "./ui/Router"; import { IRouter } from "./ui/Router";
export let redPillFlag = false;
export function setRedPillFlag(b: boolean): void {
redPillFlag = b;
}
function giveSourceFile(bitNodeNumber: number): void { function giveSourceFile(bitNodeNumber: number): void {
const sourceFileKey = "SourceFile" + bitNodeNumber.toString(); const sourceFileKey = "SourceFile" + bitNodeNumber.toString();
const sourceFile = SourceFiles[sourceFileKey]; const sourceFile = SourceFiles[sourceFileKey];
@ -82,7 +76,6 @@ export function enterBitNode(router: IRouter, flume: boolean, destroyedBitNode:
if (newBitNode === 5 && Player.intelligence === 0) { if (newBitNode === 5 && Player.intelligence === 0) {
Player.intelligence = 1; Player.intelligence = 1;
} }
redPillFlag = false;
// Set new Bit Node // Set new Bit Node
Player.bitNodeN = newBitNode; Player.bitNodeN = newBitNode;

@ -51,7 +51,6 @@ import { CONSTANTS } from "../../Constants";
import { iTutorialSteps, iTutorialNextStep, ITutorial } from "../../InteractiveTutorial"; import { iTutorialSteps, iTutorialNextStep, ITutorial } from "../../InteractiveTutorial";
import { getAvailableCreatePrograms } from "../../Programs/ProgramHelpers"; import { getAvailableCreatePrograms } from "../../Programs/ProgramHelpers";
import { Settings } from "../../Settings/Settings"; import { Settings } from "../../Settings/Settings";
import { redPillFlag } from "../../RedPill";
import { AugmentationNames } from "../../Augmentation/data/AugmentationNames"; import { AugmentationNames } from "../../Augmentation/data/AugmentationNames";
import { ProgramsSeen } from "../../Programs/ui/ProgramsRoot"; import { ProgramsSeen } from "../../Programs/ui/ProgramsRoot";
@ -275,7 +274,7 @@ export function SidebarRoot(props: IProps): React.ReactElement {
// Alt-o - Options // Alt-o - Options
function handleShortcuts(this: Document, event: KeyboardEvent): any { function handleShortcuts(this: Document, event: KeyboardEvent): any {
if (Settings.DisableHotkeys) return; if (Settings.DisableHotkeys) return;
if ((props.player.isWorking && props.player.focus) || redPillFlag) return; if ((props.player.isWorking && props.player.focus) || props.router.page() === Page.BitVerse) return;
if (event.key === KEY.T && event.altKey) { if (event.key === KEY.T && event.altKey) {
event.preventDefault(); event.preventDefault();
clickTerminal(); clickTerminal();