diff --git a/src/Myrian/Myrian.ts b/src/Myrian/Myrian.ts index 63b108ab4..384245f0d 100644 --- a/src/Myrian/Myrian.ts +++ b/src/Myrian/Myrian.ts @@ -7,6 +7,7 @@ import { NewBus, NewISocket, NewOSocket } from "./NewDevices"; import { startRoaming } from "./glitches/roaming"; import { startRust } from "./glitches/rust"; import { startSegmentation } from "./glitches/segmentation"; +import { startBattery } from "./glitches/battery"; export interface Myrian { vulns: number; @@ -33,6 +34,7 @@ export const loadMyrian = (save: string) => { startRoaming(); startRust(); startSegmentation(); + startBattery(); if (!save) return; const savedMyrian = JSON.parse(save); Object.assign(myrian, savedMyrian); diff --git a/src/Myrian/formulas/costs.ts b/src/Myrian/formulas/costs.ts index 92b0dee58..6b0992123 100644 --- a/src/Myrian/formulas/costs.ts +++ b/src/Myrian/formulas/costs.ts @@ -23,7 +23,7 @@ const makeExpFunction = (p: Partial) => { export const upgradeMaxContentCost = makeExpFunction({ [DeviceType.Bus]: [8, 0.5, 2, 0], [DeviceType.ISocket]: [4, 1, 5, 0], - [DeviceType.Reducer]: [Infinity, 1, -1, 4095], + [DeviceType.Reducer]: [256, 1, -3, 512], [DeviceType.Cache]: [1.2, 10, 0, 63], }); @@ -53,15 +53,15 @@ export const upgradeInstallLvlCost = makeExpFunction({ }); export const upgradeMaxEnergyCost = makeExpFunction({ - [DeviceType.Bus]: [2, 1, 3, 0], - [DeviceType.Battery]: [1.1, 1, 3, 8], + [DeviceType.Bus]: [1.1, 1, -8, 16], + [DeviceType.Battery]: [1.1, 1, -16, 8], }); export const installDeviceCost = makeExpFunction({ [DeviceType.Bus]: [4, 0.5, 2, 0], [DeviceType.ISocket]: [2, 1, 4, 0], [DeviceType.OSocket]: [4, 1, 3, 0], - [DeviceType.Reducer]: [1.5, 1, 2, 0], - [DeviceType.Cache]: [1.2, 10, 0, 63], + [DeviceType.Reducer]: [5, 0.5, 1, 0], + [DeviceType.Cache]: [1.2, 5, 0, 18], [DeviceType.Battery]: [1.2, 10, 0, 63], }); diff --git a/src/Myrian/formulas/glitches.ts b/src/Myrian/formulas/glitches.ts index 2023d15db..eadc9907a 100644 --- a/src/Myrian/formulas/glitches.ts +++ b/src/Myrian/formulas/glitches.ts @@ -28,16 +28,16 @@ export const giltchMultCoefficients: Record = { export const glitchMult = (glitch: Glitch, lvl: number) => 1 + lvl * giltchMultCoefficients[glitch]; // move hinderance -export const frictionMult = (lvl: number) => Math.pow(1.25, lvl); +export const frictionMult = (lvl: number) => Math.pow(2.5, lvl); // transfer slow down -export const isolationMult = (lvl: number) => Math.pow(2, lvl); +export const isolationMult = (lvl: number) => Math.pow(8, lvl); // install/uninstall slow down -export const virtualizationMult = (lvl: number) => Math.pow(3, lvl); +export const virtualizationMult = (lvl: number) => Math.pow(5, lvl); // reduce slow down -export const jammingMult = (lvl: number) => Math.pow(1.3, lvl); +export const jammingMult = (lvl: number) => Math.pow(2.5, lvl); // energy loss export const magnetismLoss = (lvl: number) => lvl; diff --git a/src/Myrian/formulas/speed.ts b/src/Myrian/formulas/speed.ts index 94d02f25e..291c4112d 100644 --- a/src/Myrian/formulas/speed.ts +++ b/src/Myrian/formulas/speed.ts @@ -5,7 +5,7 @@ export const moveSpeed = (level: number) => 1000 / (level + 10); export const reduceSpeed = (level: number) => 50000 / (level + 10); // speed to transfer components between devices -export const transferSpeed = (level: number) => 1000 / (level + 10); +export const transferSpeed = (level: number) => 4000 / (level + 10); // speed to install / uninstall devices and tweak ISockets export const installSpeed = (level: number) => 100000 / (level + 10); diff --git a/src/Myrian/utils.ts b/src/Myrian/utils.ts index 4085603ab..c088c1137 100644 --- a/src/Myrian/utils.ts +++ b/src/Myrian/utils.ts @@ -23,9 +23,17 @@ export const distanceCoord2D = (a: Device, coord: [number, number]) => export const adjacent = (a: Device, b: Device) => distance(a, b) === 1; export const adjacentCoord2D = (a: Device, coord: [number, number]) => distanceCoord2D(a, coord) === 1; +export const makeContentMap = (content: Component[]) => + content.reduce((acc, c) => ({ ...acc, [c]: (acc[c] ?? 0) + 1 }), {} as Record); + export const inventoryMatches = (a: Component[], b: Component[]) => { - if (a.length != b.length) return false; - return a.every((i) => b.includes(i)); + const aMap = makeContentMap(a); + const bMap = makeContentMap(b); + + return ( + (Object.keys(aMap) as Component[]).every((k) => aMap[k] === bMap[k]) && + Object.keys(aMap).length === Object.keys(aMap).length + ); }; const vulnsMap: Record = { diff --git a/src/NetscriptFunctions/Myrian.ts b/src/NetscriptFunctions/Myrian.ts index 0c289b382..6e626f086 100644 --- a/src/NetscriptFunctions/Myrian.ts +++ b/src/NetscriptFunctions/Myrian.ts @@ -137,6 +137,32 @@ export function NetscriptMyrian(): InternalAPI { bus.isBusy = false; }); }, + formatContent: (ctx) => (_device) => { + const deviceID = helpers.deviceID(ctx, "device", _device); + + const device = findDevice(deviceID); + if (!device) { + helpers.log(ctx, () => `device ${deviceID} not found`); + return false; + } + + if (!isDeviceContainer(device)) { + helpers.log(ctx, () => `device ${deviceID} is not a container`); + return false; + } + + device.content = []; + + if (isDeviceISocket(device)) { + const cooldown = emissionSpeed(device.emissionLvl); + device.cooldownUntil = Date.now() + cooldown; + setTimeout(() => { + device.content = new Array(device.maxContent).fill(device.emitting); + }, cooldown); + } + + return true; + }, transfer: (ctx) => async (_from, _to, _input, _output): Promise => { diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 16d611d10..a4fc8a56c 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -5375,6 +5375,12 @@ interface Myrian { */ moveBus(bus: DeviceID, coord: [number, number]): Promise; + /** + * Delete the entire content of a device, typically used for debugging. + * @returns true if the formatting succeeded, false otherwise. + */ + formatContent(device: DeviceID): boolean; + /** * Transfer components between devices, one of them must be a bus. * @remarks