bitburner-src/src/Terminal/commands/hack.ts

38 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-09-06 15:07:12 +02:00
import { Terminal } from "../../Terminal";
import { Player } from "@player";
2021-09-16 01:50:44 +02:00
import { BaseServer } from "../../Server/BaseServer";
import { Server } from "../../Server/Server";
2022-09-13 18:37:24 +02:00
export function hack(args: (string | number | boolean)[], server: BaseServer): void {
2021-09-16 01:50:44 +02:00
if (args.length !== 0) {
2022-09-06 15:07:12 +02:00
Terminal.error("Incorrect usage of hack command. Usage: hack");
2021-09-16 01:50:44 +02:00
return;
}
if (!(server instanceof Server)) {
2022-09-06 15:07:12 +02:00
Terminal.error(
2021-09-16 01:50:44 +02:00
"Cannot hack your own machines! You are currently connected to your home PC or one of your purchased servers",
);
}
const normalServer = server as Server;
// Hack the current PC (usually for money)
// You can't hack your home pc or servers you purchased
if (normalServer.purchasedByPlayer) {
2022-09-06 15:07:12 +02:00
Terminal.error(
2021-09-16 01:50:44 +02:00
"Cannot hack your own machines! You are currently connected to your home PC or one of your purchased servers",
);
return;
}
if (!normalServer.hasAdminRights) {
2022-09-06 15:07:12 +02:00
Terminal.error("You do not have admin rights for this machine! Cannot hack");
2021-09-16 01:50:44 +02:00
return;
}
2022-09-06 15:07:12 +02:00
if (normalServer.requiredHackingSkill > Player.skills.hacking) {
Terminal.error(
2021-09-16 01:50:44 +02:00
"Your hacking skill is not high enough to attempt hacking this machine. Try analyzing the machine to determine the required hacking skill",
);
return;
}
2022-09-06 15:07:12 +02:00
Terminal.startHack();
2021-09-16 01:50:44 +02:00
}