Merge pull request #1814 from danielyxie/dev

many bugfix
This commit is contained in:
hydroflame 2021-12-03 15:31:41 -05:00 committed by GitHub
commit 043aaeab8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 124 additions and 84 deletions

24
dist/vendor.bundle.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -16,6 +16,7 @@ import Typography from "@mui/material/Typography";
interface IProps {
StartingDifficulty: number;
Difficulty: number;
Reward: number;
MaxLevel: number;
}
@ -112,6 +113,7 @@ export function Game(props: IProps): React.ReactElement {
<Victory
StartingDifficulty={props.StartingDifficulty}
Difficulty={props.Difficulty}
Reward={props.Reward}
MaxLevel={props.MaxLevel}
/>
);

@ -4,18 +4,35 @@ import { Intro } from "./Intro";
import { Game } from "./Game";
import { Location } from "../../Locations/Location";
import { use } from "../../ui/Context";
import { calculateSkill } from "../../PersonObjects/formulas/skill";
interface IProps {
location: Location;
}
function calcDifficulty(player: IPlayer, startingDifficulty: number): number {
const totalStats = player.strength + player.defense + player.dexterity + player.agility + player.charisma;
const difficulty = startingDifficulty - Math.pow(totalStats, 0.9) / 250 - player.intelligence / 1600;
function calcRawDiff(player: IPlayer, stats: number, startingDifficulty: number): number {
const difficulty = startingDifficulty - Math.pow(stats, 0.9) / 250 - player.intelligence / 1600;
if (difficulty < 0) return 0;
if (difficulty > 3) return 3;
return difficulty;
}
function calcDifficulty(player: IPlayer, startingDifficulty: number): number {
const totalStats = player.strength + player.defense + player.dexterity + player.agility + player.charisma;
return calcRawDiff(player, totalStats, startingDifficulty);
}
function calcReward(player: IPlayer, startingDifficulty: number): number {
const xpMult = 10 * 60 * 15;
const total =
calculateSkill(player.strength_exp_mult * xpMult, player.strength_mult) +
calculateSkill(player.defense_exp_mult * xpMult, player.defense_mult) +
calculateSkill(player.agility_exp_mult * xpMult, player.agility_mult) +
calculateSkill(player.dexterity_exp_mult * xpMult, player.dexterity_mult) +
calculateSkill(player.charisma_exp_mult * xpMult, player.charisma_mult);
return calcRawDiff(player, total, startingDifficulty);
}
export function InfiltrationRoot(props: IProps): React.ReactElement {
const player = use.Player();
const router = use.Router();
@ -24,6 +41,8 @@ export function InfiltrationRoot(props: IProps): React.ReactElement {
if (props.location.infiltrationData === undefined) throw new Error("Trying to do infiltration on invalid location.");
const startingDifficulty = props.location.infiltrationData.startingSecurityLevel;
const difficulty = calcDifficulty(player, startingDifficulty);
const reward = calcReward(player, startingDifficulty);
console.log(`${difficulty} ${reward}`);
function cancel(): void {
router.toCity();
@ -45,6 +64,7 @@ export function InfiltrationRoot(props: IProps): React.ReactElement {
<Game
StartingDifficulty={startingDifficulty}
Difficulty={difficulty}
Reward={reward}
MaxLevel={props.location.infiltrationData.maxClearanceLevel}
/>
);

@ -13,6 +13,7 @@ import Select, { SelectChangeEvent } from "@mui/material/Select";
interface IProps {
StartingDifficulty: number;
Difficulty: number;
Reward: number;
MaxLevel: number;
}
@ -28,14 +29,14 @@ export function Victory(props: IProps): React.ReactElement {
const levelBonus = props.MaxLevel * Math.pow(1.01, props.MaxLevel);
const repGain =
Math.pow(props.Difficulty + 1, 1.1) *
Math.pow(props.Reward + 1, 1.1) *
Math.pow(props.StartingDifficulty, 1.2) *
30 *
levelBonus *
BitNodeMultipliers.InfiltrationRep;
const moneyGain =
Math.pow(props.Difficulty + 1, 2) *
Math.pow(props.Reward + 1, 2) *
Math.pow(props.StartingDifficulty, 3) *
3e3 *
levelBonus *

@ -14,7 +14,7 @@ import { calculateHackingTime, calculateGrowTime, calculateWeakenTime } from "..
function requireHackingLevel(lvl: number) {
return function (p: IPlayer) {
return p.hacking >= lvl;
return p.hacking + p.intelligence / 2 >= lvl;
};
}

@ -87,7 +87,7 @@ export function scriptCalculateOfflineProduction(runningScript: RunningScript):
//designated server, and false otherwise
export function findRunningScript(
filename: string,
args: (string | number)[],
args: (string | number | boolean)[],
server: BaseServer,
): RunningScript | null {
for (let i = 0; i < server.runningScripts.length; ++i) {

@ -31,7 +31,7 @@ export function ParseCommands(commands: string): string[] {
return out;
}
export function ParseCommand(command: string): (string | number)[] {
export function ParseCommand(command: string): (string | number | boolean)[] {
// This will be used to keep track of whether we're in a quote. This is for situations
// like the alias command:
// alias run="run NUKE.exe"
@ -101,6 +101,10 @@ export function ParseCommand(command: string): (string | number)[] {
// If this is a number, convert it from a string to number
if (isNumber(arg)) {
args.push(parseFloat(arg));
} else if (arg === "true") {
args.push(true);
} else if (arg === "false") {
args.push(false);
} else {
args.push(arg);
}
@ -117,6 +121,10 @@ export function ParseCommand(command: string): (string | number)[] {
// If this is a number, convert it from string to number
if (isNumber(arg)) {
args.push(parseFloat(arg));
} else if (arg === "true") {
args.push(true);
} else if (arg === "false") {
args.push(false);
} else {
args.push(arg);
}

@ -507,14 +507,16 @@ export class Terminal implements ITerminal {
if (s.hasAdminRights) {
c = "YES";
}
this.print(
`${dashes}Root Access: ${c}${!isHacknet ? ", Required hacking skill: " + (s as any).requiredHackingSkill : ""}`,
);
let out = `${dashes}Root Access: ${c}${
!isHacknet ? ", Required hacking skill: " + (s as any).requiredHackingSkill : ""
}`;
if (s.hasOwnProperty("numOpenPortsRequired")) {
this.print(dashes + "Number of open ports required to NUKE: " + (s as any).numOpenPortsRequired);
out += "\n" + dashes + "Number of open ports required to NUKE: " + (s as any).numOpenPortsRequired;
}
this.print(dashes + "RAM: " + numeralWrapper.formatRAM(s.maxRam));
this.print(" ");
out += "\n" + dashes + "RAM: " + numeralWrapper.formatRAM(s.maxRam);
out += "\n" + " ";
this.print(out);
}
}
@ -716,7 +718,7 @@ export class Terminal implements ITerminal {
/****************** END INTERACTIVE TUTORIAL ******************/
/* Command parser */
const commandName = commandArray[0];
if (typeof commandName === "number") {
if (typeof commandName === "number" || typeof commandName === "boolean") {
this.error(`Command ${commandArray[0]} not found`);
return;
}
@ -727,7 +729,7 @@ export class Terminal implements ITerminal {
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
) => void;
} = {
"scan-analyze": scananalyze,

@ -9,7 +9,7 @@ export function alias(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length === 0) {
printAliases();

@ -8,7 +8,7 @@ export function analyze(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length !== 0) {
terminal.error("Incorrect usage of analyze command. Usage: analyze");

@ -10,7 +10,7 @@ export function backdoor(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length !== 0) {
terminal.error("Incorrect usage of backdoor command. Usage: backdoor");

@ -11,7 +11,7 @@ export function buy(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (!GetServer(SpecialServers.DarkWeb)) {
terminal.error(

@ -10,7 +10,7 @@ export function cat(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length !== 1) {
terminal.error("Incorrect usage of cat command. Usage: cat [file]");

@ -10,7 +10,7 @@ export function cd(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length > 1) {
terminal.error("Incorrect number of arguments. Usage: cd [dir]");

@ -10,7 +10,7 @@ export function check(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length < 1) {
terminal.error("Incorrect number of arguments. Usage: check [script] [arg1] [arg2]...");

@ -9,7 +9,7 @@ export function connect(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
// Disconnect from current server in terminal and connect to new one
if (args.length !== 1) {

@ -9,7 +9,7 @@ export function cp(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
try {
if (args.length !== 2) {

@ -11,7 +11,7 @@ export function download(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
try {
if (args.length !== 1) {
@ -24,7 +24,7 @@ export function download(
const matchEnding = fn.length == 1 || fn === "*.*" ? null : fn.slice(1); // Treat *.* the same as *
const zip = new JSZip();
// Helper function to zip any file contents whose name matches the pattern
let zipFiles = (fileNames: string[], fileContents: string[]) => {
const zipFiles = (fileNames: string[], fileContents: string[]) => {
for (let i = 0; i < fileContents.length; ++i) {
let name = fileNames[i];
if (name.startsWith("/")) name = name.slice(1);
@ -34,13 +34,18 @@ export function download(
};
// In the case of script files, we pull from the server.scripts array
if (!matchEnding || isScriptFilename(matchEnding))
zipFiles(server.scripts.map(s => s.filename), server.scripts.map(s => s.code));
zipFiles(
server.scripts.map((s) => s.filename),
server.scripts.map((s) => s.code),
);
// In the case of text files, we pull from the server.scripts array
if (!matchEnding || matchEnding.endsWith(".txt"))
zipFiles(server.textFiles.map(s => s.fn), server.textFiles.map(s => s.text));
zipFiles(
server.textFiles.map((s) => s.fn),
server.textFiles.map((s) => s.text),
);
// Return an error if no files matched, rather than an empty zip folder
if (Object.keys(zip.files).length == 0)
return terminal.error(`No files match the pattern ${fn}`);
if (Object.keys(zip.files).length == 0) return terminal.error(`No files match the pattern ${fn}`);
const zipFn = `bitburner${isScriptFilename(fn) ? "Scripts" : fn === "*.txt" ? "Texts" : "Files"}.zip`;
zip.generateAsync({ type: "blob" }).then((content: any) => FileSaver.saveAs(content, zipFn));
return;

@ -8,7 +8,7 @@ export function expr(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length === 0) {
terminal.error("Incorrect usage of expr command. Usage: expr [math expression]");

@ -9,7 +9,7 @@ export function free(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length !== 0) {
terminal.error("Incorrect usage of free command. Usage: free");

@ -9,7 +9,7 @@ export function grow(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length !== 0) {
terminal.error("Incorrect usage of grow command. Usage: grow");

@ -9,7 +9,7 @@ export function hack(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length !== 0) {
terminal.error("Incorrect usage of hack command. Usage: hack");

@ -9,7 +9,7 @@ export function help(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length !== 0 && args.length !== 1) {
terminal.error("Incorrect usage of help command. Usage: help");
@ -18,7 +18,7 @@ export function help(
if (args.length === 0) {
TerminalHelpText.forEach((line) => terminal.print(line));
} else {
const cmd = args[0];
const cmd = args[0] + "";
const txt = HelpTexts[cmd];
if (txt == null) {
terminal.error("No help topics match '" + cmd + "'");

@ -8,7 +8,7 @@ export function home(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length !== 0) {
terminal.error("Incorrect usage of home command. Usage: home");

@ -8,7 +8,7 @@ export function hostname(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length !== 0) {
terminal.error("Incorrect usage of hostname command. Usage: hostname");

@ -9,13 +9,16 @@ export function kill(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
try {
if (args.length < 1) {
terminal.error("Incorrect usage of kill command. Usage: kill [scriptname] [arg1] [arg2]...");
return;
}
if (typeof args[0] === "boolean") {
return;
}
// Kill by PID
if (typeof args[0] === "number") {

@ -10,7 +10,7 @@ export function ls(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
const numArgs = args.length;
function incorrectUsage(): void {

@ -9,7 +9,7 @@ export function mem(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
try {
if (args.length !== 1 && args.length !== 3) {

@ -11,7 +11,7 @@ export function mv(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length !== 2) {
terminal.error(`Incorrect number of arguments. Usage: mv [src] [dest]`);

@ -10,7 +10,7 @@ export function nano(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length !== 1) {
terminal.error("Incorrect usage of nano command. Usage: nano [scriptname]");

@ -8,7 +8,7 @@ export function ps(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length !== 0) {
terminal.error("Incorrect usage of ps command. Usage: ps");

@ -9,7 +9,7 @@ export function rm(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length !== 1) {
terminal.error("Incorrect number of arguments. Usage: rm [program/script]");

@ -11,7 +11,7 @@ export function run(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
// Run a program or a script
if (args.length < 1) {

@ -9,7 +9,7 @@ export function runProgram(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length < 1) {
return;

@ -14,7 +14,7 @@ export function runScript(
router: IRouter,
player: IPlayer,
server: BaseServer,
commandArgs: (string | number)[],
commandArgs: (string | number | boolean)[],
): void {
if (commandArgs.length < 1) {
terminal.error(

@ -9,7 +9,7 @@ export function scan(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length !== 0) {
terminal.error("Incorrect usage of netstat/scan command. Usage: netstat/scan");

@ -9,7 +9,7 @@ export function scananalyze(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length === 0) {
terminal.executeScanAnalyzeCommand(player, 1);

@ -10,7 +10,7 @@ export function scp(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
try {
if (args.length !== 2) {

@ -8,7 +8,7 @@ export function sudov(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length !== 0) {
terminal.error("Incorrect number of arguments. Usage: sudov");

@ -12,7 +12,7 @@ export function tail(
router: IRouter,
player: IPlayer,
server: BaseServer,
commandArray: (string | number)[],
commandArray: (string | number | boolean)[],
): void {
try {
if (commandArray.length < 1) {
@ -67,7 +67,7 @@ export function tail(
// if there's no candidate then we just don't know.
terminal.error("No such script exists.");
} else {
} else if (typeof commandArray[0] === "number") {
const runningScript = findRunningScriptByPid(commandArray[0], server);
if (runningScript == null) {
terminal.error("No such script exists");

@ -10,7 +10,7 @@ export function top(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length !== 0) {
terminal.error("Incorrect usage of top command. Usage: top");

@ -9,7 +9,7 @@ export function unalias(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length !== 1) {
terminal.error("Incorrect usage of unalias name. Usage: unalias [alias]");

@ -9,7 +9,7 @@ export function weaken(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length !== 0) {
terminal.error("Incorrect usage of weaken command. Usage: weaken");

@ -9,7 +9,7 @@ export function wget(
router: IRouter,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
args: (string | number | boolean)[],
): void {
if (args.length !== 2) {
terminal.error("Incorrect usage of wget command. Usage: wget [url] [target file]");

@ -265,13 +265,6 @@ export async function determineAllPossibilitiesForTabCompletion(
return allPos;
}
if (isCommand("kill") || isCommand("tail") || isCommand("mem") || isCommand("check")) {
addAllScripts();
addAllDirectories();
return allPos;
}
if (isCommand("nano")) {
addAllScripts();
addAllTextFiles();
@ -292,7 +285,7 @@ export async function determineAllPossibilitiesForTabCompletion(
}
async function scriptAutocomplete(): Promise<string[] | undefined> {
if (!isCommand("run")) return;
if (!isCommand("run") && !isCommand("tail") && !isCommand("kill")) return;
const commands = ParseCommands(input);
if (commands.length === 0) return;
const command = ParseCommand(commands[commands.length - 1]);
@ -348,6 +341,13 @@ export async function determineAllPossibilitiesForTabCompletion(
addAllDirectories();
}
if (isCommand("kill") || isCommand("tail") || isCommand("mem") || isCommand("check")) {
addAllScripts();
addAllDirectories();
return allPos;
}
if (isCommand("cat")) {
addAllMessages();
addAllLitFiles();

@ -159,7 +159,7 @@ function LogWindow(props: IProps): React.ReactElement {
}
return (
<Draggable handle=".drag">
<Draggable bounds="body" handle=".drag">
<Paper
style={{
display: "flex",

@ -4,7 +4,6 @@ export function formatTime(fmt: string): string {
try {
return format(new Date(), fmt);
} catch (err: any) {
console.error(err);
return "format error";
}
}