most terminal converted to ts

This commit is contained in:
Olivier Gagnon
2021-09-15 19:50:44 -04:00
parent 8097364242
commit 2922e42055
60 changed files with 2998 additions and 2259 deletions
+44
View File
@@ -0,0 +1,44 @@
import { ITerminal } from "../ITerminal";
import { IEngine } from "../../IEngine";
import { IPlayer } from "../../PersonObjects/IPlayer";
import { BaseServer } from "../../Server/BaseServer";
import { Server } from "../../Server/Server";
export function hack(
terminal: ITerminal,
engine: IEngine,
player: IPlayer,
server: BaseServer,
args: (string | number)[],
): void {
if (args.length !== 0) {
terminal.error("Incorrect usage of hack command. Usage: hack");
return;
}
if (!(server instanceof Server)) {
terminal.error(
"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) {
terminal.error(
"Cannot hack your own machines! You are currently connected to your home PC or one of your purchased servers",
);
return;
}
if (!normalServer.hasAdminRights) {
terminal.error("You do not have admin rights for this machine! Cannot hack");
return;
}
if (normalServer.requiredHackingSkill > player.hacking_skill) {
terminal.error(
"Your hacking skill is not high enough to attempt hacking this machine. Try analyzing the machine to determine the required hacking skill",
);
return;
}
terminal.startHack(player);
}