mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-23 01:32:55 +02:00
prettify, sorry for the big ass commit
This commit is contained in:
+18
-16
@@ -1,26 +1,28 @@
|
||||
export interface IPlayer {
|
||||
hacking_skill: number;
|
||||
sourceFiles: any[];
|
||||
hacking_skill: number;
|
||||
sourceFiles: any[];
|
||||
}
|
||||
|
||||
export interface IProgramCreate {
|
||||
level: number;
|
||||
req(p: IPlayer): boolean; // Function that indicates whether player meets requirements
|
||||
time: number;
|
||||
tooltip: string;
|
||||
level: number;
|
||||
req(p: IPlayer): boolean; // Function that indicates whether player meets requirements
|
||||
time: number;
|
||||
tooltip: string;
|
||||
}
|
||||
|
||||
export class Program {
|
||||
name = "";
|
||||
create: IProgramCreate | null;
|
||||
name = "";
|
||||
create: IProgramCreate | null;
|
||||
|
||||
constructor(name: string, create: IProgramCreate | null) {
|
||||
this.name = name;
|
||||
this.create = create;
|
||||
}
|
||||
constructor(name: string, create: IProgramCreate | null) {
|
||||
this.name = name;
|
||||
this.create = create;
|
||||
}
|
||||
|
||||
htmlID(): string {
|
||||
const name = this.name.endsWith('.exe') ? this.name.slice(0, -('.exe'.length)) : this.name;
|
||||
return "create-program-" + name;
|
||||
}
|
||||
htmlID(): string {
|
||||
const name = this.name.endsWith(".exe")
|
||||
? this.name.slice(0, -".exe".length)
|
||||
: this.name;
|
||||
return "create-program-" + name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,73 +1,78 @@
|
||||
import { Programs } from "./Programs";
|
||||
import { Programs } from "./Programs";
|
||||
|
||||
import { Player } from "../Player";
|
||||
import { createElement } from "../../utils/uiHelpers/createElement";
|
||||
import { Player } from "../Player";
|
||||
import { createElement } from "../../utils/uiHelpers/createElement";
|
||||
|
||||
// this has the same key as 'Programs', not program names
|
||||
const aLinks = {};
|
||||
|
||||
function displayCreateProgramContent() {
|
||||
for(const key in aLinks) {
|
||||
const p = Programs[key]
|
||||
aLinks[key].style.display = "none";
|
||||
if(!Player.hasProgram(p.name) && p.create.req(Player)){
|
||||
aLinks[key].style.display = "inline-block";
|
||||
}
|
||||
for (const key in aLinks) {
|
||||
const p = Programs[key];
|
||||
aLinks[key].style.display = "none";
|
||||
if (!Player.hasProgram(p.name) && p.create.req(Player)) {
|
||||
aLinks[key].style.display = "inline-block";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Returns the number of programs that are currently available to be created
|
||||
function getNumAvailableCreateProgram() {
|
||||
var count = 0;
|
||||
for (const key in Programs) {
|
||||
// Non-creatable program
|
||||
if (Programs[key].create == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Already has program
|
||||
if (Player.hasProgram(Programs[key].name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Does not meet requirements
|
||||
if (!Programs[key].create.req(Player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
count++;
|
||||
var count = 0;
|
||||
for (const key in Programs) {
|
||||
// Non-creatable program
|
||||
if (Programs[key].create == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Player.firstProgramAvailable === false && count > 0) {
|
||||
Player.firstProgramAvailable = true;
|
||||
document.getElementById("hacking-menu-header").click();
|
||||
document.getElementById("hacking-menu-header").click();
|
||||
// Already has program
|
||||
if (Player.hasProgram(Programs[key].name)) {
|
||||
continue;
|
||||
}
|
||||
return count;
|
||||
|
||||
// Does not meet requirements
|
||||
if (!Programs[key].create.req(Player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
if (Player.firstProgramAvailable === false && count > 0) {
|
||||
Player.firstProgramAvailable = true;
|
||||
document.getElementById("hacking-menu-header").click();
|
||||
document.getElementById("hacking-menu-header").click();
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
function initCreateProgramButtons() {
|
||||
const createProgramList = document.getElementById("create-program-list");
|
||||
for (const key in Programs) {
|
||||
if(Programs[key].create === null) {
|
||||
continue;
|
||||
}
|
||||
const elem = createElement("a", {
|
||||
class: "a-link-button", id: Programs[key].htmlID(), innerText: Programs[key].name,
|
||||
tooltip: Programs[key].create.tooltip,
|
||||
});
|
||||
aLinks[key] = elem;
|
||||
createProgramList.appendChild(elem);
|
||||
const createProgramList = document.getElementById("create-program-list");
|
||||
for (const key in Programs) {
|
||||
if (Programs[key].create === null) {
|
||||
continue;
|
||||
}
|
||||
const elem = createElement("a", {
|
||||
class: "a-link-button",
|
||||
id: Programs[key].htmlID(),
|
||||
innerText: Programs[key].name,
|
||||
tooltip: Programs[key].create.tooltip,
|
||||
});
|
||||
aLinks[key] = elem;
|
||||
createProgramList.appendChild(elem);
|
||||
}
|
||||
|
||||
for (const key in aLinks) {
|
||||
const p = Programs[key]
|
||||
aLinks[key].addEventListener("click", function() {
|
||||
Player.startCreateProgramWork(p.name, p.create.time, p.create.level);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
for (const key in aLinks) {
|
||||
const p = Programs[key];
|
||||
aLinks[key].addEventListener("click", function () {
|
||||
Player.startCreateProgramWork(p.name, p.create.time, p.create.level);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export {displayCreateProgramContent, getNumAvailableCreateProgram,
|
||||
initCreateProgramButtons};
|
||||
export {
|
||||
displayCreateProgramContent,
|
||||
getNumAvailableCreateProgram,
|
||||
initCreateProgramButtons,
|
||||
};
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Program } from "./Program";
|
||||
import { programsMetadata } from "./data/ProgramsMetadata";
|
||||
import { IMap } from "../types";
|
||||
import { Program } from "./Program";
|
||||
import { programsMetadata } from "./data/ProgramsMetadata";
|
||||
import { IMap } from "../types";
|
||||
|
||||
export const Programs: IMap<Program> = {};
|
||||
|
||||
for (const params of programsMetadata) {
|
||||
Programs[params.key] = new Program(params.name, params.create);
|
||||
Programs[params.key] = new Program(params.name, params.create);
|
||||
}
|
||||
|
||||
@@ -1,139 +1,145 @@
|
||||
import { IPlayer,
|
||||
IProgramCreate } from "../Program";
|
||||
import { IPlayer, IProgramCreate } from "../Program";
|
||||
import { CONSTANTS } from "../../Constants";
|
||||
|
||||
function requireHackingLevel(lvl: number) {
|
||||
return function(p: IPlayer) {
|
||||
return p.hacking_skill >= lvl;
|
||||
}
|
||||
return function (p: IPlayer) {
|
||||
return p.hacking_skill >= lvl;
|
||||
};
|
||||
}
|
||||
|
||||
function bitFlumeRequirements() {
|
||||
return function(p: IPlayer) {
|
||||
return p.sourceFiles.length > 0 && p.hacking_skill >= 1;
|
||||
}
|
||||
return function (p: IPlayer) {
|
||||
return p.sourceFiles.length > 0 && p.hacking_skill >= 1;
|
||||
};
|
||||
}
|
||||
|
||||
export interface IProgramCreationParams {
|
||||
key: string;
|
||||
name: string;
|
||||
create: IProgramCreate | null;
|
||||
key: string;
|
||||
name: string;
|
||||
create: IProgramCreate | null;
|
||||
}
|
||||
|
||||
export const programsMetadata: IProgramCreationParams[] = [
|
||||
{
|
||||
key: "NukeProgram",
|
||||
name: "NUKE.exe",
|
||||
create: {
|
||||
level: 1,
|
||||
tooltip: "This virus is used to gain root access to a machine if enough ports are opened.",
|
||||
req: requireHackingLevel(1),
|
||||
time: CONSTANTS.MillisecondsPerFiveMinutes,
|
||||
},
|
||||
{
|
||||
key: "NukeProgram",
|
||||
name: "NUKE.exe",
|
||||
create: {
|
||||
level: 1,
|
||||
tooltip:
|
||||
"This virus is used to gain root access to a machine if enough ports are opened.",
|
||||
req: requireHackingLevel(1),
|
||||
time: CONSTANTS.MillisecondsPerFiveMinutes,
|
||||
},
|
||||
{
|
||||
key: "BruteSSHProgram",
|
||||
name: "BruteSSH.exe",
|
||||
create: {
|
||||
level: 50,
|
||||
tooltip: "This program executes a brute force attack that opens SSH ports",
|
||||
req: requireHackingLevel(50),
|
||||
time: CONSTANTS.MillisecondsPerFiveMinutes * 2,
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "BruteSSHProgram",
|
||||
name: "BruteSSH.exe",
|
||||
create: {
|
||||
level: 50,
|
||||
tooltip:
|
||||
"This program executes a brute force attack that opens SSH ports",
|
||||
req: requireHackingLevel(50),
|
||||
time: CONSTANTS.MillisecondsPerFiveMinutes * 2,
|
||||
},
|
||||
{
|
||||
key: "FTPCrackProgram",
|
||||
name: "FTPCrack.exe",
|
||||
create: {
|
||||
level: 100,
|
||||
tooltip: "This program cracks open FTP ports",
|
||||
req: requireHackingLevel(100),
|
||||
time: CONSTANTS.MillisecondsPerHalfHour,
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "FTPCrackProgram",
|
||||
name: "FTPCrack.exe",
|
||||
create: {
|
||||
level: 100,
|
||||
tooltip: "This program cracks open FTP ports",
|
||||
req: requireHackingLevel(100),
|
||||
time: CONSTANTS.MillisecondsPerHalfHour,
|
||||
},
|
||||
{
|
||||
key: "RelaySMTPProgram",
|
||||
name: "relaySMTP.exe",
|
||||
create: {
|
||||
level: 250,
|
||||
tooltip: "This program opens SMTP ports by redirecting data",
|
||||
req: requireHackingLevel(250),
|
||||
time: CONSTANTS.MillisecondsPer2Hours,
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "RelaySMTPProgram",
|
||||
name: "relaySMTP.exe",
|
||||
create: {
|
||||
level: 250,
|
||||
tooltip: "This program opens SMTP ports by redirecting data",
|
||||
req: requireHackingLevel(250),
|
||||
time: CONSTANTS.MillisecondsPer2Hours,
|
||||
},
|
||||
{
|
||||
key: "HTTPWormProgram",
|
||||
name: "HTTPWorm.exe",
|
||||
create: {
|
||||
level: 500,
|
||||
tooltip: "This virus opens up HTTP ports",
|
||||
req: requireHackingLevel(500),
|
||||
time: CONSTANTS.MillisecondsPer4Hours,
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "HTTPWormProgram",
|
||||
name: "HTTPWorm.exe",
|
||||
create: {
|
||||
level: 500,
|
||||
tooltip: "This virus opens up HTTP ports",
|
||||
req: requireHackingLevel(500),
|
||||
time: CONSTANTS.MillisecondsPer4Hours,
|
||||
},
|
||||
{
|
||||
key: "SQLInjectProgram",
|
||||
name: "SQLInject.exe",
|
||||
create: {
|
||||
level: 750,
|
||||
tooltip: "This virus opens SQL ports",
|
||||
req: requireHackingLevel(750),
|
||||
time: CONSTANTS.MillisecondsPer8Hours,
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "SQLInjectProgram",
|
||||
name: "SQLInject.exe",
|
||||
create: {
|
||||
level: 750,
|
||||
tooltip: "This virus opens SQL ports",
|
||||
req: requireHackingLevel(750),
|
||||
time: CONSTANTS.MillisecondsPer8Hours,
|
||||
},
|
||||
{
|
||||
key: "DeepscanV1",
|
||||
name: "DeepscanV1.exe",
|
||||
create: {
|
||||
level: 75,
|
||||
tooltip: "This program allows you to use the scan-analyze command with a depth up to 5",
|
||||
req: requireHackingLevel(75),
|
||||
time: CONSTANTS.MillisecondsPerQuarterHour,
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "DeepscanV1",
|
||||
name: "DeepscanV1.exe",
|
||||
create: {
|
||||
level: 75,
|
||||
tooltip:
|
||||
"This program allows you to use the scan-analyze command with a depth up to 5",
|
||||
req: requireHackingLevel(75),
|
||||
time: CONSTANTS.MillisecondsPerQuarterHour,
|
||||
},
|
||||
{
|
||||
key: "DeepscanV2",
|
||||
name: "DeepscanV2.exe",
|
||||
create: {
|
||||
level: 400,
|
||||
tooltip: "This program allows you to use the scan-analyze command with a depth up to 10",
|
||||
req: requireHackingLevel(400),
|
||||
time: CONSTANTS.MillisecondsPer2Hours,
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "DeepscanV2",
|
||||
name: "DeepscanV2.exe",
|
||||
create: {
|
||||
level: 400,
|
||||
tooltip:
|
||||
"This program allows you to use the scan-analyze command with a depth up to 10",
|
||||
req: requireHackingLevel(400),
|
||||
time: CONSTANTS.MillisecondsPer2Hours,
|
||||
},
|
||||
{
|
||||
key: "ServerProfiler",
|
||||
name: "ServerProfiler.exe",
|
||||
create: {
|
||||
level: 75,
|
||||
tooltip: "This program is used to display hacking and Netscript-related information about servers",
|
||||
req: requireHackingLevel(75),
|
||||
time: CONSTANTS.MillisecondsPerHalfHour,
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "ServerProfiler",
|
||||
name: "ServerProfiler.exe",
|
||||
create: {
|
||||
level: 75,
|
||||
tooltip:
|
||||
"This program is used to display hacking and Netscript-related information about servers",
|
||||
req: requireHackingLevel(75),
|
||||
time: CONSTANTS.MillisecondsPerHalfHour,
|
||||
},
|
||||
{
|
||||
key: "AutoLink",
|
||||
name: "AutoLink.exe",
|
||||
create: {
|
||||
level: 25,
|
||||
tooltip: "This program allows you to directly connect to other servers through the 'scan-analyze' command",
|
||||
req: requireHackingLevel(25),
|
||||
time: CONSTANTS.MillisecondsPerQuarterHour,
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "AutoLink",
|
||||
name: "AutoLink.exe",
|
||||
create: {
|
||||
level: 25,
|
||||
tooltip:
|
||||
"This program allows you to directly connect to other servers through the 'scan-analyze' command",
|
||||
req: requireHackingLevel(25),
|
||||
time: CONSTANTS.MillisecondsPerQuarterHour,
|
||||
},
|
||||
{
|
||||
key: "BitFlume",
|
||||
name: "b1t_flum3.exe",
|
||||
create: {
|
||||
level: 1,
|
||||
tooltip: "This program creates a portal to the BitNode Nexus (allows you to restart and switch BitNodes)",
|
||||
req: bitFlumeRequirements(),
|
||||
time: CONSTANTS.MillisecondsPerFiveMinutes / 20,
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "Flight",
|
||||
name: "fl1ght.exe",
|
||||
create: null,
|
||||
},
|
||||
{
|
||||
key: "BitFlume",
|
||||
name: "b1t_flum3.exe",
|
||||
create: {
|
||||
level: 1,
|
||||
tooltip:
|
||||
"This program creates a portal to the BitNode Nexus (allows you to restart and switch BitNodes)",
|
||||
req: bitFlumeRequirements(),
|
||||
time: CONSTANTS.MillisecondsPerFiveMinutes / 20,
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "Flight",
|
||||
name: "fl1ght.exe",
|
||||
create: null,
|
||||
},
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user