bitburner-src/src/Message/MessageHelpers.ts

221 lines
7.7 KiB
TypeScript
Raw Normal View History

import { Message } from "./Message";
import { Augmentations } from "../Augmentation/Augmentations";
import { AugmentationNames } from "../Augmentation/data/AugmentationNames";
import { Programs } from "../Programs/Programs";
import { Player } from "../Player";
import { redPillFlag } from "../RedPill";
2021-10-07 22:56:01 +02:00
import { GetServer } from "../Server/AllServers";
import { Settings } from "../Settings/Settings";
2021-09-25 20:42:57 +02:00
import { dialogBoxCreate } from "../ui/React/DialogBox";
import { Reviver } from "../utils/JSONReviver";
//Sends message to player, including a pop up
2021-09-24 22:02:38 +02:00
function sendMessage(msg: Message, forced = false): void {
2021-09-05 01:09:30 +02:00
msg.recvd = true;
if (forced || !Settings.SuppressMessages) {
2021-10-14 08:07:05 +02:00
showMessage(msg.filename);
2021-09-05 01:09:30 +02:00
}
addMessageToServer(msg, "home");
}
2021-10-14 08:07:05 +02:00
function showMessage(name: string): void {
const msg = Messages[name];
if (!msg) throw new Error("trying to display unexistent message");
2021-09-25 07:26:03 +02:00
const txt =
2021-09-05 01:09:30 +02:00
"Message received from unknown sender: <br><br>" +
"<i>" +
msg.msg +
"</i><br><br>" +
"This message was saved as " +
msg.filename +
" onto your home computer.";
dialogBoxCreate(txt);
}
//Adds a message to a server
2021-09-24 22:02:38 +02:00
function addMessageToServer(msg: Message, serverHostname: string): void {
2021-10-07 22:56:01 +02:00
const server = GetServer(serverHostname);
2021-09-05 01:09:30 +02:00
if (server == null) {
console.warn(`Could not find server ${serverHostname}`);
return;
}
2021-09-25 07:26:03 +02:00
for (let i = 0; i < server.messages.length; ++i) {
2021-09-25 08:36:49 +02:00
const other = server.messages[i];
2021-10-14 08:07:05 +02:00
if (msg.filename === other) {
2021-09-05 01:09:30 +02:00
return; //Already exists
2017-09-19 20:38:03 +02:00
}
2021-09-05 01:09:30 +02:00
}
2021-10-14 08:07:05 +02:00
server.messages.push(msg.filename);
}
//Checks if any of the 'timed' messages should be sent
2021-09-25 08:36:49 +02:00
function checkForMessagesToSend(): void {
2021-09-22 07:36:17 +02:00
if (redPillFlag) return;
const jumper0 = Messages[MessageFilenames.Jumper0];
const jumper1 = Messages[MessageFilenames.Jumper1];
const jumper2 = Messages[MessageFilenames.Jumper2];
const jumper3 = Messages[MessageFilenames.Jumper3];
const jumper4 = Messages[MessageFilenames.Jumper4];
const cybersecTest = Messages[MessageFilenames.CyberSecTest];
const nitesecTest = Messages[MessageFilenames.NiteSecTest];
const bitrunnersTest = Messages[MessageFilenames.BitRunnersTest];
const redpill = Messages[MessageFilenames.RedPill];
2021-09-22 18:38:13 +02:00
let redpillOwned = false;
2021-09-05 01:09:30 +02:00
if (Augmentations[AugmentationNames.TheRedPill].owned) {
redpillOwned = true;
}
2021-10-01 21:26:12 +02:00
if (redpill && redpillOwned && Player.sourceFiles.length === 0 && !redPillFlag) {
2021-09-05 01:09:30 +02:00
sendMessage(redpill, true);
} else if (redpill && redpillOwned) {
//If player has already destroyed a BitNode, message is not forced
2021-10-01 21:26:12 +02:00
if (!redPillFlag) {
2021-09-05 01:09:30 +02:00
sendMessage(redpill);
}
2021-09-05 01:09:30 +02:00
} else if (jumper0 && !jumper0.recvd && Player.hacking_skill >= 25) {
sendMessage(jumper0);
const flightName = Programs.Flight.name;
const homeComp = Player.getHomeComputer();
if (!homeComp.programs.includes(flightName)) {
homeComp.programs.push(flightName);
}
} else if (jumper1 && !jumper1.recvd && Player.hacking_skill >= 40) {
sendMessage(jumper1);
2021-09-09 05:47:34 +02:00
} else if (cybersecTest && !cybersecTest.recvd && Player.hacking_skill >= 50) {
2021-09-05 01:09:30 +02:00
sendMessage(cybersecTest);
} else if (jumper2 && !jumper2.recvd && Player.hacking_skill >= 175) {
sendMessage(jumper2);
} else if (nitesecTest && !nitesecTest.recvd && Player.hacking_skill >= 200) {
sendMessage(nitesecTest);
} else if (jumper3 && !jumper3.recvd && Player.hacking_skill >= 350) {
sendMessage(jumper3);
} else if (jumper4 && !jumper4.recvd && Player.hacking_skill >= 490) {
sendMessage(jumper4);
2021-09-09 05:47:34 +02:00
} else if (bitrunnersTest && !bitrunnersTest.recvd && Player.hacking_skill >= 500) {
2021-09-05 01:09:30 +02:00
sendMessage(bitrunnersTest);
}
}
2021-09-24 22:02:38 +02:00
function AddToAllMessages(msg: Message): void {
2021-09-05 01:09:30 +02:00
Messages[msg.filename] = msg;
}
2021-09-24 22:02:38 +02:00
let Messages: { [key: string]: Message | undefined } = {};
2021-09-24 22:02:38 +02:00
function loadMessages(saveString: string): void {
2021-09-05 01:09:30 +02:00
Messages = JSON.parse(saveString, Reviver);
}
2021-09-25 07:26:03 +02:00
const MessageFilenames = {
2021-09-05 01:09:30 +02:00
Jumper0: "j0.msg",
Jumper1: "j1.msg",
Jumper2: "j2.msg",
Jumper3: "j3.msg",
Jumper4: "j4.msg",
CyberSecTest: "csec-test.msg",
NiteSecTest: "nitesec-test.msg",
BitRunnersTest: "19dfj3l1nd.msg",
RedPill: "icarus.msg",
};
2021-09-25 08:36:49 +02:00
function initMessages(): void {
2021-09-05 01:09:30 +02:00
//Reset
Messages = {};
2021-09-05 01:09:30 +02:00
//jump3R Messages
AddToAllMessages(
new Message(
MessageFilenames.Jumper0,
"I know you can sense it. I know you're searching for it. " +
"It's why you spend night after " +
"night at your computer. <br><br>It's real, I've seen it. And I can " +
"help you find it. But not right now. You're not ready yet.<br><br>" +
"Use this program to track your progress<br><br>" +
"The fl1ght.exe program was added to your home computer<br><br>" +
"-jump3R",
),
);
AddToAllMessages(
new Message(
MessageFilenames.Jumper1,
"Soon you will be contacted by a hacking group known as CyberSec. " +
"They can help you with your search. <br><br>" +
"You should join them, garner their favor, and " +
"exploit them for their Augmentations. But do not trust them. " +
"They are not what they seem. No one is.<br><br>" +
"-jump3R",
),
);
AddToAllMessages(
new Message(
MessageFilenames.Jumper2,
"Do not try to save the world. There is no world to save. If " +
"you want to find the truth, worry only about yourself. Ethics and " +
"morals will get you killed. <br><br>Watch out for a hacking group known as NiteSec." +
"<br><br>-jump3R",
),
);
AddToAllMessages(
new Message(
MessageFilenames.Jumper3,
"You must learn to walk before you can run. And you must " +
"run before you can fly. Look for the black hand. <br><br>" +
"I.I.I.I <br><br>-jump3R",
),
);
AddToAllMessages(
new Message(
MessageFilenames.Jumper4,
"To find what you are searching for, you must understand the bits. " +
"The bits are all around us. The runners will help you.<br><br>" +
"-jump3R",
),
);
2021-09-05 01:09:30 +02:00
//Messages from hacking factions
AddToAllMessages(
new Message(
MessageFilenames.CyberSecTest,
"We've been watching you. Your skills are very impressive. But you're wasting " +
"your talents. If you join us, you can put your skills to good use and change " +
"the world for the better. If you join us, we can unlock your full potential. <br><br>" +
"But first, you must pass our test. Find and install the backdoor on our server. <br><br>" +
"-CyberSec",
),
);
AddToAllMessages(
new Message(
MessageFilenames.NiteSecTest,
"People say that the corrupted governments and corporations rule the world. " +
"Yes, maybe they do. But do you know who everyone really fears? People " +
"like us. Because they can't hide from us. Because they can't fight shadows " +
"and ideas with bullets. <br><br>" +
"Join us, and people will fear you, too. <br><br>" +
"Find and install the backdoor on our server. Then, we will contact you again." +
"<br><br>-NiteSec",
),
);
AddToAllMessages(
new Message(
MessageFilenames.BitRunnersTest,
"We know what you are doing. We know what drives you. We know " +
"what you are looking for. <br><br> " +
"We can help you find the answers.<br><br>" +
"run4theh111z",
),
);
2021-09-05 01:09:30 +02:00
AddToAllMessages(
new Message(
MessageFilenames.RedPill,
"@)(#V%*N)@(#*)*C)@#%*)*V)@#(*%V@)(#VN%*)@#(*%<br>" +
")@B(*#%)@)M#B*%V)____FIND___#$@)#%(B*)@#(*%B)<br>" +
"@_#(%_@#M(BDSPOMB__THE-CAVE_#)$(*@#$)@#BNBEGB<br>" +
"DFLSMFVMV)#@($*)@#*$MV)@#(*$V)M#(*$)M@(#*VM$)",
),
);
}
2021-09-09 05:47:34 +02:00
export { Messages, checkForMessagesToSend, sendMessage, showMessage, loadMessages, initMessages, Message };