Address feedback

This commit is contained in:
Olivier Gagnon 2024-06-22 14:57:57 -04:00
parent 300a93f27f
commit 5c2db27f87
No known key found for this signature in database
GPG Key ID: 0018772EA86FA03F
7 changed files with 54 additions and 12 deletions

@ -7,6 +7,7 @@ import { NewBus, NewISocket, NewOSocket } from "./NewDevices";
import { startRoaming } from "./glitches/roaming"; import { startRoaming } from "./glitches/roaming";
import { startRust } from "./glitches/rust"; import { startRust } from "./glitches/rust";
import { startSegmentation } from "./glitches/segmentation"; import { startSegmentation } from "./glitches/segmentation";
import { startBattery } from "./glitches/battery";
export interface Myrian { export interface Myrian {
vulns: number; vulns: number;
@ -33,6 +34,7 @@ export const loadMyrian = (save: string) => {
startRoaming(); startRoaming();
startRust(); startRust();
startSegmentation(); startSegmentation();
startBattery();
if (!save) return; if (!save) return;
const savedMyrian = JSON.parse(save); const savedMyrian = JSON.parse(save);
Object.assign(myrian, savedMyrian); Object.assign(myrian, savedMyrian);

@ -23,7 +23,7 @@ const makeExpFunction = (p: Partial<DeviceScale>) => {
export const upgradeMaxContentCost = makeExpFunction({ export const upgradeMaxContentCost = makeExpFunction({
[DeviceType.Bus]: [8, 0.5, 2, 0], [DeviceType.Bus]: [8, 0.5, 2, 0],
[DeviceType.ISocket]: [4, 1, 5, 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], [DeviceType.Cache]: [1.2, 10, 0, 63],
}); });
@ -53,15 +53,15 @@ export const upgradeInstallLvlCost = makeExpFunction({
}); });
export const upgradeMaxEnergyCost = makeExpFunction({ export const upgradeMaxEnergyCost = makeExpFunction({
[DeviceType.Bus]: [2, 1, 3, 0], [DeviceType.Bus]: [1.1, 1, -8, 16],
[DeviceType.Battery]: [1.1, 1, 3, 8], [DeviceType.Battery]: [1.1, 1, -16, 8],
}); });
export const installDeviceCost = makeExpFunction({ export const installDeviceCost = makeExpFunction({
[DeviceType.Bus]: [4, 0.5, 2, 0], [DeviceType.Bus]: [4, 0.5, 2, 0],
[DeviceType.ISocket]: [2, 1, 4, 0], [DeviceType.ISocket]: [2, 1, 4, 0],
[DeviceType.OSocket]: [4, 1, 3, 0], [DeviceType.OSocket]: [4, 1, 3, 0],
[DeviceType.Reducer]: [1.5, 1, 2, 0], [DeviceType.Reducer]: [5, 0.5, 1, 0],
[DeviceType.Cache]: [1.2, 10, 0, 63], [DeviceType.Cache]: [1.2, 5, 0, 18],
[DeviceType.Battery]: [1.2, 10, 0, 63], [DeviceType.Battery]: [1.2, 10, 0, 63],
}); });

@ -28,16 +28,16 @@ export const giltchMultCoefficients: Record<Glitch, number> = {
export const glitchMult = (glitch: Glitch, lvl: number) => 1 + lvl * giltchMultCoefficients[glitch]; export const glitchMult = (glitch: Glitch, lvl: number) => 1 + lvl * giltchMultCoefficients[glitch];
// move hinderance // 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 // 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 // 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 // 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 // energy loss
export const magnetismLoss = (lvl: number) => lvl; export const magnetismLoss = (lvl: number) => lvl;

@ -5,7 +5,7 @@ export const moveSpeed = (level: number) => 1000 / (level + 10);
export const reduceSpeed = (level: number) => 50000 / (level + 10); export const reduceSpeed = (level: number) => 50000 / (level + 10);
// speed to transfer components between devices // 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 // speed to install / uninstall devices and tweak ISockets
export const installSpeed = (level: number) => 100000 / (level + 10); export const installSpeed = (level: number) => 100000 / (level + 10);

@ -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 adjacent = (a: Device, b: Device) => distance(a, b) === 1;
export const adjacentCoord2D = (a: Device, coord: [number, number]) => distanceCoord2D(a, coord) === 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<Component, number>);
export const inventoryMatches = (a: Component[], b: Component[]) => { export const inventoryMatches = (a: Component[], b: Component[]) => {
if (a.length != b.length) return false; const aMap = makeContentMap(a);
return a.every((i) => b.includes(i)); 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<Component, number> = { const vulnsMap: Record<Component, number> = {

@ -137,6 +137,32 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
bus.isBusy = false; 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: transfer:
(ctx) => (ctx) =>
async (_from, _to, _input, _output): Promise<boolean> => { async (_from, _to, _input, _output): Promise<boolean> => {

@ -5375,6 +5375,12 @@ interface Myrian {
*/ */
moveBus(bus: DeviceID, coord: [number, number]): Promise<boolean>; moveBus(bus: DeviceID, coord: [number, number]): Promise<boolean>;
/**
* 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. * Transfer components between devices, one of them must be a bus.
* @remarks * @remarks