import { NS } from '@ns'; import { kill } from '../kill'; export const serverDeleteAll = (ns: NS) => { // get a list of all the purchased servers const serverNames: string[] = ns.getPurchasedServers(); // initialize a counter for total cost of all the servers let totalCost = 0; // loop through the list of servers and remove each one serverNames.forEach((serverName) => { // get the ram of the server const ram = ns.getServerMaxRam(serverName); // calculate the cost of the server and add it to the total cost const cost = ns.getPurchasedServerCost(ram); totalCost += cost; // kill all the processes running on the server before removing it kill(ns, serverName); // remove the server ns.deleteServer(serverName); }); ns.tprint(`Purchased servers deleted: ${serverNames.length}`); ns.tprint(`Total cost of deleted servers: $${totalCost}`); return serverNames; }; export const main = (ns: NS) => { serverDeleteAll(ns); };