organized files

This commit is contained in:
Vomitblood 2026-05-04 00:39:11 +08:00
parent 1533cc0e5f
commit fbe84d3c25
21 changed files with 69 additions and 90 deletions

View file

@ -4,7 +4,7 @@ NOTE: All user scripts to be synced with the game is found under `src/`.
## TODO ## TODO
- Fix the fucking ezgame.formulas.hacking.growTime(). calculateIntelligenceBonus() is throwing errors when calculating intelligence. Clearly my intelligence value is 0. - `ezgame.analyze`
This is a template for a viteburner project. It is a simple example of how to use Viteburner. This is a template for a viteburner project. It is a simple example of how to use Viteburner.

View file

@ -1,5 +0,0 @@
import { formulas } from "./ezgame/formulas";
export const ezgame = {
formulas,
};

View file

@ -1,5 +1,6 @@
import { NS, Server } from "@ns"; import { NS, Server } from "@ns";
// TODO: incomplete
// define a new interface for the new analysis results // define a new interface for the new analysis results
interface ServerAnalysis { interface ServerAnalysis {
hostname: string; hostname: string;

View file

@ -1,15 +0,0 @@
import { gang } from "./formulas/gang";
import { hacking } from "./formulas/hacking";
import { hacknetNodes } from "./formulas/hacknet-nodes";
import { hacknetServers } from "./formulas/hacknet-servers";
import { reputation } from "./formulas/reputation";
import { skills } from "./formulas/skills";
export const formulas = {
gang,
hacking,
hacknetNodes,
hacknetServers,
reputation,
skills,
};

View file

@ -0,0 +1,15 @@
import { gang } from "./gang";
import { hacking } from "./hacking";
import { hacknetNodes } from "./hacknet-nodes";
import { hacknetServers } from "./hacknet-servers";
import { reputation } from "./reputation";
import { skills } from "./skills";
export const formulas = {
gang,
hacking,
hacknetNodes,
hacknetServers,
reputation,
skills,
};

View file

@ -1,5 +1,5 @@
import { ezgame } from "@/ezgame"; import { ezgame } from "@/ezgame";
import { getNormalServer } from "@/utils/get-normal-server"; import { getNormalServer } from "@/ezgame/get-normal-server";
import { utils } from "@/utils/utils"; import { utils } from "@/utils/utils";
import { NS } from "@ns"; import { NS } from "@ns";

5
src/ezgame/index.ts Normal file
View file

@ -0,0 +1,5 @@
import { formulas } from "./formulas";
export const ezgame = {
formulas,
};

View file

@ -1,5 +1,5 @@
import { NS } from "@ns"; import { NS } from "@ns";
import { scan } from "./scan"; import { scan } from "../ezgame/scan";
export const killall = (ns: NS): void => { export const killall = (ns: NS): void => {
const allHosts = scan(ns); const allHosts = scan(ns);

View file

@ -1,5 +1,5 @@
import { NS } from "@ns"; import { NS } from "@ns";
import { scan } from "./scan"; import { scan } from "../ezgame/scan";
// get root access to all the servers that we can // get root access to all the servers that we can
// then return a list of all the servers we have root access to // then return a list of all the servers we have root access to

View file

@ -1,5 +1,5 @@
import { NS } from "@ns"; import { NS } from "@ns";
import { scan } from "./scan"; import { scan } from "../ezgame/scan";
export const scriptCleanup = (ns: NS) => { export const scriptCleanup = (ns: NS) => {
// get all hosts with root access // get all hosts with root access

View file

@ -1,5 +1,5 @@
import { NS } from "@ns"; import { NS } from "@ns";
import { scan } from "./scan"; import { scan } from "../ezgame/scan";
export const scriptPropagator = (ns: NS) => { export const scriptPropagator = (ns: NS) => {
// get all hosts with root access // get all hosts with root access

View file

@ -1,6 +1,6 @@
import { NS } from "@ns"; import { NS } from "@ns";
export const serverBuyMax = (ns: NS, serverNamePrefix: string) => { export const buyMax = (ns: NS, serverNamePrefix: string) => {
// get the maximum number of servers that can be purchased // get the maximum number of servers that can be purchased
const maxServers = ns.cloud.getServerLimit(); const maxServers = ns.cloud.getServerLimit();
@ -64,5 +64,5 @@ export const serverBuyMax = (ns: NS, serverNamePrefix: string) => {
export const main = (ns: NS) => { export const main = (ns: NS) => {
const serverNamePrefix = "worker"; const serverNamePrefix = "worker";
serverBuyMax(ns, serverNamePrefix); buyMax(ns, serverNamePrefix);
}; };

View file

@ -1,7 +1,7 @@
import { NS } from "@ns"; import { NS } from "@ns";
import { kill } from "../kill"; import { kill } from "../kill";
export const serverDeleteAll = (ns: NS) => { export const deleteAll = (ns: NS) => {
// get a list of all the purchased servers // get a list of all the purchased servers
const serverNames: string[] = ns.cloud.getServerNames(); const serverNames: string[] = ns.cloud.getServerNames();
@ -31,5 +31,5 @@ export const serverDeleteAll = (ns: NS) => {
}; };
export const main = (ns: NS) => { export const main = (ns: NS) => {
serverDeleteAll(ns); deleteAll(ns);
}; };

View file

@ -1,5 +1,5 @@
import { NS } from "@ns"; import { NS } from "@ns";
import { scan } from "./scan"; import { scan } from "../ezgame/scan";
interface StartOptions { interface StartOptions {
threads?: number; // explicit thread count threads?: number; // explicit thread count

View file

@ -1,7 +1,10 @@
import { NS } from "@ns"; import { NS } from "@ns";
import { format } from "./utils/format-number"; import { ezgame } from "./ezgame";
import { getNormalServer } from "./ezgame/get-normal-server";
import { utils } from "./utils";
export const main = (ns: NS) => { export const main = (ns: NS) => {
// console.log(ns.formulas.hacking.growTime(getNormalServer(ns, "n00dles"), ns.getPlayer())); // console.log(ns.formulas.hacking.growTime(getNormalServer(ns, "n00dles"), ns.getPlayer()));
console.log(format.number(ns.cloud.getServerCost(2048))); console.log(utils.format.number(ns.cloud.getServerCost(2048)));
console.log(utils.format.date(ezgame.formulas.hacking.growTime(getNormalServer(ns, "n00dles"), ns.getPlayer())));
}; };

View file

@ -268,6 +268,32 @@ function parseBigNumber(str: string): number {
return parseFloat(str.substring(0, str.length - 1) + "e" + suffixIndex * 3); return parseFloat(str.substring(0, str.length - 1) + "e" + suffixIndex * 3);
} }
/**
* Format the date/time.
* If the date is today, show the time. Otherwise, show the date in "day month year" format.
* @param dateString The date string to format
* @returns Formatted date/time string
*/
function formatDate(dateString: string): string {
const date = new Date(dateString);
const today = new Date();
// save today date at midnight for comparison
const todayMidnight = new Date(today.getFullYear(), today.getMonth(), today.getDate());
// check if the date is today
if (
date >= todayMidnight &&
date < new Date(todayMidnight.getTime() + 86400000 /* milliseconds in a day sheeesh */)
) {
// show time if today
return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
} else {
// "day month year" format
return date.toLocaleDateString(undefined, { day: "numeric", month: "long", year: "numeric" });
}
}
/** Namespace for all number formatting functions */ /** Namespace for all number formatting functions */
export const format = { export const format = {
bytes: formatBytes, bytes: formatBytes,
@ -304,4 +330,5 @@ export const format = {
sleeveSynchro: formatSleeveSynchro, sleeveSynchro: formatSleeveSynchro,
corpStat: formatCorpStat, corpStat: formatCorpStat,
parseBigNumber: parseBigNumber, parseBigNumber: parseBigNumber,
formatDate,
}; };

5
src/utils/index.ts Normal file
View file

@ -0,0 +1,5 @@
import { format } from "./format";
export const utils = {
format,
};

View file

@ -1,9 +1,6 @@
import { Server } from "@ns"; import { Server } from "@ns";
export const utils = { export const utils = {
utilityFormatDate: formatDate,
utilityFormatSize: formatSize,
utilityUnformatSize: unformatSize,
utilityExtractFilename: extractFilename, utilityExtractFilename: extractFilename,
clampNumber, clampNumber,
clampInteger, clampInteger,
@ -13,60 +10,6 @@ export const utils = {
isDarknetServer, isDarknetServer,
}; };
/**
* Format the date/time.
* If the date is today, show the time. Otherwise, show the date in "day month year" format.
* @param dateString The date string to format
* @returns Formatted date/time string
*/
function formatDate(dateString: string): string {
const date = new Date(dateString);
const today = new Date();
// save today date at midnight for comparison
const todayMidnight = new Date(today.getFullYear(), today.getMonth(), today.getDate());
// check if the date is today
if (
date >= todayMidnight &&
date < new Date(todayMidnight.getTime() + 86400000 /* milliseconds in a day sheeesh */)
) {
// show time if today
return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
} else {
// "day month year" format
return date.toLocaleDateString(undefined, { day: "numeric", month: "long", year: "numeric" });
}
}
/**
* Format bytes into human-readable size
* @param bytes Number of bytes to format
* @returns Formatted size string
*/
function formatSize(bytes: number): string {
if (bytes === 0) return "0 Bytes";
const k = 1024;
const sizes = ["Bytes", "KB", "MB", "GB"];
const i = Math.floor(Math.log(bytes) / Math.log(k));
// tf is pow
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
}
/**
* Convert a formatted size string back to bytes
* @param formattedSize Formatted size string (must be in the same format produced by `utilityFormatSize()`)
* @returns Number of bytes
*/
function unformatSize(formattedSize: string): number {
const sizes = ["Bytes", "KB", "MB", "GB"];
const [value, unit] = formattedSize.split(" ");
const index = sizes.indexOf(unit);
return parseFloat(value) * Math.pow(1024, index);
}
/** /**
* Extract filename stem and extension from a file path * Extract filename stem and extension from a file path
* @param filePath The file path to parse * @param filePath The file path to parse