diff --git a/src/Enums.ts b/src/Enums.ts index e8064f4f7..07984ef4f 100644 --- a/src/Enums.ts +++ b/src/Enums.ts @@ -14,3 +14,4 @@ export * from "./Programs/Enums"; export * from "./StockMarket/Enums"; export * from "./ui/Enums"; export * from "./Work/Enums"; +export * from "./Myrian/Enums"; diff --git a/src/Myrian/Enums.ts b/src/Myrian/Enums.ts new file mode 100644 index 000000000..af693cf55 --- /dev/null +++ b/src/Myrian/Enums.ts @@ -0,0 +1,100 @@ +export enum DeviceType { + Bus = "bus", + ISocket = "isocket", + OSocket = "osocket", + Reducer = "reducer", + Cache = "cache", + Lock = "lock", + Battery = "battery", +} + +export enum Component { + // tier 0 + R0 = "r0", + G0 = "g0", + B0 = "b0", + + // tier 1 + R1 = "r1", + G1 = "g1", + B1 = "b1", + + Y1 = "y1", + C1 = "c1", + M1 = "m1", + + // tier 2 + R2 = "r2", + G2 = "g2", + B2 = "b2", + + Y2 = "y2", + C2 = "c2", + M2 = "m2", + + W2 = "w2", + + // tier 3 + R3 = "r3", + G3 = "g3", + B3 = "b3", + + Y3 = "y3", + C3 = "c3", + M3 = "m3", + + W3 = "w3", + + // tier 4 + R4 = "r4", + G4 = "g4", + B4 = "b4", + + Y4 = "y4", + C4 = "c4", + M4 = "m4", + + W4 = "w4", + + // tier 5 + R5 = "r5", + G5 = "g5", + B5 = "b5", + + Y5 = "y5", + C5 = "c5", + M5 = "m5", + + W5 = "w5", + + // tier 6 + Y6 = "y6", + C6 = "c6", + M6 = "m6", + + W6 = "w6", + + // tier 7 + W7 = "w7", +} + +export enum Glitch { + // Locks spawn at random + Segmentation = "segmentation", + // ISockets and OSockets move around on their own + Roaming = "roaming", + // OSocket ask for more complicated components + Encryption = "encryption", + // Energy starts being consumed (level 0 is no consumption) + Magnetism = "magnetism", + // Hidden tiles on the board, when stepped on the bus loses upgrades + Rust = "rust", + // Move slows down + Friction = "friction", + // Transfer components and charging slows down + Isolation = "isolation", + // Install/Uninstall slows down + Virtualization = "virtualization", + // Reduce slows down + Jamming = "jamming", +} diff --git a/src/Myrian/Myrian.ts b/src/Myrian/Myrian.ts index 761179ccf..63b108ab4 100644 --- a/src/Myrian/Myrian.ts +++ b/src/Myrian/Myrian.ts @@ -1,4 +1,5 @@ -import { Device, DeviceType, Component, DeviceID, Glitch } from "@nsdefs"; +import { Device, DeviceID } from "@nsdefs"; +import { DeviceType, Component, Glitch } from "@enums"; import { glitchMult } from "./formulas/glitches"; import { isDeviceISocket, pickOne } from "./utils"; import { componentTiers } from "./formulas/components"; diff --git a/src/Myrian/NewDevices.ts b/src/Myrian/NewDevices.ts index 9fe3ecb77..ee0559bdf 100644 --- a/src/Myrian/NewDevices.ts +++ b/src/Myrian/NewDevices.ts @@ -1,4 +1,5 @@ -import { Battery, Bus, Cache, Component, DeviceType, ISocket, Lock, OSocket, Reducer } from "@nsdefs"; +import { Battery, Bus, Cache, ISocket, Lock, OSocket, Reducer } from "@nsdefs"; +import { Component, DeviceType } from "@enums"; import { myrian } from "./Myrian"; import { getNextOSocketRequest } from "./Myrian"; diff --git a/src/Myrian/formulas/components.ts b/src/Myrian/formulas/components.ts index e8671b04c..8d23be532 100644 --- a/src/Myrian/formulas/components.ts +++ b/src/Myrian/formulas/components.ts @@ -1,4 +1,4 @@ -import { Component } from "@nsdefs"; +import { Component } from "@enums"; export const componentTiers = [ [Component.R0, Component.G0, Component.B0], diff --git a/src/Myrian/formulas/costs.ts b/src/Myrian/formulas/costs.ts index 8b0a9f200..92b0dee58 100644 --- a/src/Myrian/formulas/costs.ts +++ b/src/Myrian/formulas/costs.ts @@ -1,4 +1,4 @@ -import { DeviceType } from "@nsdefs"; +import { DeviceType } from "@enums"; // parameters for a exponential formula, a^(b*X+c)+d type ExponentialFormulaParams = [number, number, number, number]; diff --git a/src/Myrian/formulas/glitches.ts b/src/Myrian/formulas/glitches.ts index 8de383c65..2023d15db 100644 --- a/src/Myrian/formulas/glitches.ts +++ b/src/Myrian/formulas/glitches.ts @@ -1,4 +1,4 @@ -import { Glitch } from "@nsdefs"; +import { Glitch } from "@enums"; export const glitchMaxLvl: Record = { [Glitch.Segmentation]: 10, diff --git a/src/Myrian/formulas/recipes.ts b/src/Myrian/formulas/recipes.ts index 76ac3beff..f6911a2f8 100644 --- a/src/Myrian/formulas/recipes.ts +++ b/src/Myrian/formulas/recipes.ts @@ -1,4 +1,5 @@ -import { Component, Recipe } from "@nsdefs"; +import { Recipe } from "@nsdefs"; +import { Component } from "@enums"; const make = (input: Component[], output: Component): Recipe => ({ input, output }); diff --git a/src/Myrian/glitches/battery.ts b/src/Myrian/glitches/battery.ts index 49912eb48..d065dcebc 100644 --- a/src/Myrian/glitches/battery.ts +++ b/src/Myrian/glitches/battery.ts @@ -1,9 +1,9 @@ -import { DeviceType } from "@nsdefs"; import { myrian } from "../Myrian"; +import { isDeviceBattery } from "../utils"; const applyBattery = () => { myrian.devices.forEach((device) => { - if (device.type !== DeviceType.Battery) return; + if (!isDeviceBattery(device)) return; const up = Math.pow(2, device.tier + 1); device.energy = Math.min(device.energy + up, device.maxEnergy); }); diff --git a/src/Myrian/glitches/roaming.ts b/src/Myrian/glitches/roaming.ts index 962a07838..5d95b10a6 100644 --- a/src/Myrian/glitches/roaming.ts +++ b/src/Myrian/glitches/roaming.ts @@ -1,4 +1,4 @@ -import { DeviceType, Glitch } from "@nsdefs"; +import { DeviceType, Glitch } from "@enums"; import { myrian, myrianSize } from "../Myrian"; import { findDevice, inMyrianBounds } from "../Myrian"; import { roamingTime } from "../formulas/glitches"; diff --git a/src/Myrian/glitches/rust.ts b/src/Myrian/glitches/rust.ts index af1c6aa29..385e7ee4c 100644 --- a/src/Myrian/glitches/rust.ts +++ b/src/Myrian/glitches/rust.ts @@ -1,4 +1,5 @@ -import { Bus, Glitch } from "@nsdefs"; +import { Bus } from "@nsdefs"; +import { Glitch } from "@enums"; import { myrian, myrianSize } from "../Myrian"; import { pickOne } from "../utils"; diff --git a/src/Myrian/glitches/segmentation.ts b/src/Myrian/glitches/segmentation.ts index 63c7b101a..64fa8a789 100644 --- a/src/Myrian/glitches/segmentation.ts +++ b/src/Myrian/glitches/segmentation.ts @@ -1,4 +1,4 @@ -import { Glitch } from "@nsdefs"; +import { Glitch } from "@enums"; import { myrian, myrianSize } from "../Myrian"; import { findDevice } from "../Myrian"; import { NewLock } from "../NewDevices"; diff --git a/src/Myrian/ui/ComponentText.tsx b/src/Myrian/ui/ComponentText.tsx index 8955f5b78..a3829b320 100644 --- a/src/Myrian/ui/ComponentText.tsx +++ b/src/Myrian/ui/ComponentText.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { Component } from "@nsdefs"; +import { Component } from "@enums"; import { getComponentColor } from "./common"; interface IComponent { diff --git a/src/Myrian/ui/DeviceIcon.tsx b/src/Myrian/ui/DeviceIcon.tsx index 188884e12..54c2e9538 100644 --- a/src/Myrian/ui/DeviceIcon.tsx +++ b/src/Myrian/ui/DeviceIcon.tsx @@ -1,5 +1,6 @@ import React from "react"; -import { Device, DeviceType } from "@nsdefs"; +import { Device } from "@nsdefs"; +import { DeviceType } from "@enums"; import { BusIcon } from "./BusIcon"; import { ReducerIcon } from "./Reducer"; @@ -8,26 +9,27 @@ import { CacheIcon } from "./CacheIcon"; import { BatteryIcon } from "./BatteryIcon"; import { OSocketIcon } from "./OSocketIcon"; import { ISocketIcon } from "./ISocketIcon"; +import { + isDeviceBattery, + isDeviceBus, + isDeviceCache, + isDeviceISocket, + isDeviceLock, + isDeviceOSocket, + isDeviceReducer, +} from "../utils"; interface IDeviceIconProps { device: Device; } export const DeviceIcon = ({ device }: IDeviceIconProps): React.ReactElement => { - switch (device.type) { - case DeviceType.ISocket: - return ; - case DeviceType.OSocket: - return ; - case DeviceType.Bus: - return ; - case DeviceType.Reducer: - return ; - case DeviceType.Lock: - return ; - case DeviceType.Cache: - return ; - case DeviceType.Battery: - return ; - } + if (isDeviceISocket(device)) return ; + if (isDeviceOSocket(device)) return ; + if (isDeviceBus(device)) return ; + if (isDeviceReducer(device)) return ; + if (isDeviceLock(device)) return ; + if (isDeviceCache(device)) return ; + if (isDeviceBattery(device)) return ; + return <>; }; diff --git a/src/Myrian/ui/common.ts b/src/Myrian/ui/common.ts index 663a7bd28..a1aff6298 100644 --- a/src/Myrian/ui/common.ts +++ b/src/Myrian/ui/common.ts @@ -1,4 +1,4 @@ -import { Component } from "@nsdefs"; +import { Component } from "@enums"; export const cellSize = 48; diff --git a/src/Myrian/utils.ts b/src/Myrian/utils.ts index c527fe1de..4085603ab 100644 --- a/src/Myrian/utils.ts +++ b/src/Myrian/utils.ts @@ -1,10 +1,8 @@ import { - Component, BaseDevice, ContainerDevice, Device, Bus, - DeviceType, ISocket, OSocket, Reducer, @@ -14,6 +12,7 @@ import { TieredDevice, EnergyDevice, } from "@nsdefs"; +import { Component, DeviceType } from "@enums"; export const pickOne = (arr: T[]): T => arr[Math.floor(Math.random() * arr.length)]; diff --git a/src/NetscriptFunctions/Myrian.ts b/src/NetscriptFunctions/Myrian.ts index 764fff85a..50a483ef8 100644 --- a/src/NetscriptFunctions/Myrian.ts +++ b/src/NetscriptFunctions/Myrian.ts @@ -40,6 +40,8 @@ import { inventoryMatches, isDeviceBus, isDeviceContainer, + isDeviceISocket, + isDeviceOSocket, isDeviceTiered, isEmittingDevice, isEnergyDevice, @@ -52,7 +54,8 @@ import { import { installSpeed, emissionSpeed, moveSpeed, reduceSpeed, transferSpeed } from "../Myrian/formulas/speed"; import { NewBattery, NewBus, NewCache, NewISocket, NewLock, NewOSocket, NewReducer } from "../Myrian/NewDevices"; import { rustBus } from "../Myrian/glitches/rust"; -import { Bus, Myrian as IMyrian, DeviceType, Component, Reducer, Glitch, Battery, ISocket } from "@nsdefs"; +import { Bus, Myrian as IMyrian, Reducer, Battery, ISocket } from "@nsdefs"; +import { DeviceType, Component, Glitch } from "@enums"; export function NetscriptMyrian(): InternalAPI { return { @@ -109,7 +112,7 @@ export function NetscriptMyrian(): InternalAPI { return Promise.resolve(false); } - const outOfEnergy = bus.energy === 0 ? 0.1 : 1; + const outOfEnergy = bus.energy === 0 ? 10 : 1; bus.isBusy = true; return helpers @@ -208,28 +211,21 @@ export function NetscriptMyrian(): InternalAPI { fromDevice.content = fromDevice.content.filter((item) => !input.includes(item)); fromDevice.content.push(...output); - switch (container.type) { - case DeviceType.ISocket: { - if (previousSize <= container.content.length) break; - const cooldown = emissionSpeed(container.emissionLvl); - container.cooldownUntil = Date.now() + cooldown; - setTimeout(() => { - container.content = new Array(container.maxContent).fill(container.emitting); - }, cooldown); - break; - } - - case DeviceType.OSocket: { - if (!inventoryMatches(container.currentRequest, container.content)) break; - const gain = contentVulnsValue(container.content) * getTotalGlitchMult(); - myrian.vulns += gain; - myrian.totalVulns += gain; - container.content = []; - const request = getNextOSocketRequest(myrian.glitches[Glitch.Encryption]); - container.currentRequest = request; - container.maxContent = request.length; - break; - } + if (isDeviceISocket(container) && previousSize > container.content.length) { + const cooldown = emissionSpeed(container.emissionLvl); + container.cooldownUntil = Date.now() + cooldown; + setTimeout(() => { + container.content = new Array(container.maxContent).fill(container.emitting); + }, cooldown); + } + if (isDeviceOSocket(container) && inventoryMatches(container.currentRequest, container.content)) { + const gain = contentVulnsValue(container.content) * getTotalGlitchMult(); + myrian.vulns += gain; + myrian.totalVulns += gain; + container.content = []; + const request = getNextOSocketRequest(myrian.glitches[Glitch.Encryption]); + container.currentRequest = request; + container.maxContent = request.length; } return Promise.resolve(true); }) diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 1b22eb6b8..16d611d10 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -5162,106 +5162,106 @@ interface Stanek { acceptGift(): boolean; } -export enum DeviceType { - Bus = "bus", - ISocket = "isocket", - OSocket = "osocket", - Reducer = "reducer", - Cache = "cache", - Lock = "lock", - Battery = "battery", -} +// declare enum DeviceType { +// Bus = "bus", +// ISocket = "isocket", +// OSocket = "osocket", +// Reducer = "reducer", +// Cache = "cache", +// Lock = "lock", +// Battery = "battery", +// } -export enum Component { - // tier 0 - R0 = "r0", - G0 = "g0", - B0 = "b0", +// declare enum Component { +// // tier 0 +// R0 = "r0", +// G0 = "g0", +// B0 = "b0", - // tier 1 - R1 = "r1", - G1 = "g1", - B1 = "b1", +// // tier 1 +// R1 = "r1", +// G1 = "g1", +// B1 = "b1", - Y1 = "y1", - C1 = "c1", - M1 = "m1", +// Y1 = "y1", +// C1 = "c1", +// M1 = "m1", - // tier 2 - R2 = "r2", - G2 = "g2", - B2 = "b2", +// // tier 2 +// R2 = "r2", +// G2 = "g2", +// B2 = "b2", - Y2 = "y2", - C2 = "c2", - M2 = "m2", +// Y2 = "y2", +// C2 = "c2", +// M2 = "m2", - W2 = "w2", +// W2 = "w2", - // tier 3 - R3 = "r3", - G3 = "g3", - B3 = "b3", +// // tier 3 +// R3 = "r3", +// G3 = "g3", +// B3 = "b3", - Y3 = "y3", - C3 = "c3", - M3 = "m3", +// Y3 = "y3", +// C3 = "c3", +// M3 = "m3", - W3 = "w3", +// W3 = "w3", - // tier 4 - R4 = "r4", - G4 = "g4", - B4 = "b4", +// // tier 4 +// R4 = "r4", +// G4 = "g4", +// B4 = "b4", - Y4 = "y4", - C4 = "c4", - M4 = "m4", +// Y4 = "y4", +// C4 = "c4", +// M4 = "m4", - W4 = "w4", +// W4 = "w4", - // tier 5 - R5 = "r5", - G5 = "g5", - B5 = "b5", +// // tier 5 +// R5 = "r5", +// G5 = "g5", +// B5 = "b5", - Y5 = "y5", - C5 = "c5", - M5 = "m5", +// Y5 = "y5", +// C5 = "c5", +// M5 = "m5", - W5 = "w5", +// W5 = "w5", - // tier 6 - Y6 = "y6", - C6 = "c6", - M6 = "m6", +// // tier 6 +// Y6 = "y6", +// C6 = "c6", +// M6 = "m6", - W6 = "w6", +// W6 = "w6", - // tier 7 - W7 = "w7", -} +// // tier 7 +// W7 = "w7", +// } -export enum Glitch { - // Locks spawn at random - Segmentation = "segmentation", - // ISockets and OSockets move around on their own - Roaming = "roaming", - // OSocket ask for more complicated components - Encryption = "encryption", - // Energy starts being consumed (level 0 is no consumption) - Magnetism = "magnetism", - // Hidden tiles on the board, when stepped on the bus loses upgrades - Rust = "rust", - // Move slows down - Friction = "friction", - // Transfer components and charging slows down - Isolation = "isolation", - // Install/Uninstall slows down - Virtualization = "virtualization", - // Reduce slows down - Jamming = "jamming", -} +// declare enum Glitch { +// // Locks spawn at random +// Segmentation = "segmentation", +// // ISockets and OSockets move around on their own +// Roaming = "roaming", +// // OSocket ask for more complicated components +// Encryption = "encryption", +// // Energy starts being consumed (level 0 is no consumption) +// Magnetism = "magnetism", +// // Hidden tiles on the board, when stepped on the bus loses upgrades +// Rust = "rust", +// // Move slows down +// Friction = "friction", +// // Transfer components and charging slows down +// Isolation = "isolation", +// // Install/Uninstall slows down +// Virtualization = "virtualization", +// // Reduce slows down +// Jamming = "jamming", +// } export interface BaseDevice { name: string;