organized files
This commit is contained in:
parent
1533cc0e5f
commit
fbe84d3c25
|
|
@ -4,7 +4,7 @@ NOTE: All user scripts to be synced with the game is found under `src/`.
|
|||
|
||||
## 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.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
import { formulas } from "./ezgame/formulas";
|
||||
|
||||
export const ezgame = {
|
||||
formulas,
|
||||
};
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import { NS, Server } from "@ns";
|
||||
|
||||
// TODO: incomplete
|
||||
// define a new interface for the new analysis results
|
||||
interface ServerAnalysis {
|
||||
hostname: string;
|
||||
|
|
@ -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,
|
||||
};
|
||||
15
src/ezgame/formulas/index.ts
Normal file
15
src/ezgame/formulas/index.ts
Normal 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,
|
||||
};
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { ezgame } from "@/ezgame";
|
||||
import { getNormalServer } from "@/utils/get-normal-server";
|
||||
import { getNormalServer } from "@/ezgame/get-normal-server";
|
||||
import { utils } from "@/utils/utils";
|
||||
import { NS } from "@ns";
|
||||
|
||||
|
|
|
|||
5
src/ezgame/index.ts
Normal file
5
src/ezgame/index.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { formulas } from "./formulas";
|
||||
|
||||
export const ezgame = {
|
||||
formulas,
|
||||
};
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { NS } from "@ns";
|
||||
import { scan } from "./scan";
|
||||
import { scan } from "../ezgame/scan";
|
||||
|
||||
export const killall = (ns: NS): void => {
|
||||
const allHosts = scan(ns);
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { NS } from "@ns";
|
||||
import { scan } from "./scan";
|
||||
import { scan } from "../ezgame/scan";
|
||||
|
||||
// get root access to all the servers that we can
|
||||
// then return a list of all the servers we have root access to
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { NS } from "@ns";
|
||||
import { scan } from "./scan";
|
||||
import { scan } from "../ezgame/scan";
|
||||
|
||||
export const scriptCleanup = (ns: NS) => {
|
||||
// get all hosts with root access
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { NS } from "@ns";
|
||||
import { scan } from "./scan";
|
||||
import { scan } from "../ezgame/scan";
|
||||
|
||||
export const scriptPropagator = (ns: NS) => {
|
||||
// get all hosts with root access
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
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
|
||||
const maxServers = ns.cloud.getServerLimit();
|
||||
|
||||
|
|
@ -64,5 +64,5 @@ export const serverBuyMax = (ns: NS, serverNamePrefix: string) => {
|
|||
|
||||
export const main = (ns: NS) => {
|
||||
const serverNamePrefix = "worker";
|
||||
serverBuyMax(ns, serverNamePrefix);
|
||||
buyMax(ns, serverNamePrefix);
|
||||
};
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import { NS } from "@ns";
|
||||
import { kill } from "../kill";
|
||||
|
||||
export const serverDeleteAll = (ns: NS) => {
|
||||
export const deleteAll = (ns: NS) => {
|
||||
// get a list of all the purchased servers
|
||||
const serverNames: string[] = ns.cloud.getServerNames();
|
||||
|
||||
|
|
@ -31,5 +31,5 @@ export const serverDeleteAll = (ns: NS) => {
|
|||
};
|
||||
|
||||
export const main = (ns: NS) => {
|
||||
serverDeleteAll(ns);
|
||||
deleteAll(ns);
|
||||
};
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { NS } from "@ns";
|
||||
import { scan } from "./scan";
|
||||
import { scan } from "../ezgame/scan";
|
||||
|
||||
interface StartOptions {
|
||||
threads?: number; // explicit thread count
|
||||
|
|
@ -1,7 +1,10 @@
|
|||
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) => {
|
||||
// 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())));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -268,6 +268,32 @@ function parseBigNumber(str: string): number {
|
|||
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 */
|
||||
export const format = {
|
||||
bytes: formatBytes,
|
||||
|
|
@ -304,4 +330,5 @@ export const format = {
|
|||
sleeveSynchro: formatSleeveSynchro,
|
||||
corpStat: formatCorpStat,
|
||||
parseBigNumber: parseBigNumber,
|
||||
formatDate,
|
||||
};
|
||||
5
src/utils/index.ts
Normal file
5
src/utils/index.ts
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import { format } from "./format";
|
||||
|
||||
export const utils = {
|
||||
format,
|
||||
};
|
||||
|
|
@ -1,9 +1,6 @@
|
|||
import { Server } from "@ns";
|
||||
|
||||
export const utils = {
|
||||
utilityFormatDate: formatDate,
|
||||
utilityFormatSize: formatSize,
|
||||
utilityUnformatSize: unformatSize,
|
||||
utilityExtractFilename: extractFilename,
|
||||
clampNumber,
|
||||
clampInteger,
|
||||
|
|
@ -13,60 +10,6 @@ export const utils = {
|
|||
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
|
||||
* @param filePath The file path to parse
|
||||
|
|
|
|||
Loading…
Reference in a new issue