mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-27 10:03:48 +01:00
lint, tests, enums, and fix out of energy speeding up instead of slowing down
This commit is contained in:
parent
6f27643977
commit
c459586df7
@ -14,3 +14,4 @@ export * from "./Programs/Enums";
|
||||
export * from "./StockMarket/Enums";
|
||||
export * from "./ui/Enums";
|
||||
export * from "./Work/Enums";
|
||||
export * from "./Myrian/Enums";
|
||||
|
100
src/Myrian/Enums.ts
Normal file
100
src/Myrian/Enums.ts
Normal file
@ -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",
|
||||
}
|
@ -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";
|
||||
|
@ -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";
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Component } from "@nsdefs";
|
||||
import { Component } from "@enums";
|
||||
|
||||
export const componentTiers = [
|
||||
[Component.R0, Component.G0, Component.B0],
|
||||
|
@ -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];
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Glitch } from "@nsdefs";
|
||||
import { Glitch } from "@enums";
|
||||
|
||||
export const glitchMaxLvl: Record<Glitch, number> = {
|
||||
[Glitch.Segmentation]: 10,
|
||||
|
@ -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 });
|
||||
|
||||
|
@ -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);
|
||||
});
|
||||
|
@ -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";
|
||||
|
@ -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";
|
||||
|
||||
|
@ -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";
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React from "react";
|
||||
import { Component } from "@nsdefs";
|
||||
import { Component } from "@enums";
|
||||
import { getComponentColor } from "./common";
|
||||
|
||||
interface IComponent {
|
||||
|
@ -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 <ISocketIcon socket={device} />;
|
||||
case DeviceType.OSocket:
|
||||
return <OSocketIcon socket={device} />;
|
||||
case DeviceType.Bus:
|
||||
return <BusIcon bus={device} />;
|
||||
case DeviceType.Reducer:
|
||||
return <ReducerIcon reducer={device} />;
|
||||
case DeviceType.Lock:
|
||||
return <LockIcon lock={device} />;
|
||||
case DeviceType.Cache:
|
||||
return <CacheIcon cache={device} />;
|
||||
case DeviceType.Battery:
|
||||
return <BatteryIcon battery={device} />;
|
||||
}
|
||||
if (isDeviceISocket(device)) return <ISocketIcon socket={device} />;
|
||||
if (isDeviceOSocket(device)) return <OSocketIcon socket={device} />;
|
||||
if (isDeviceBus(device)) return <BusIcon bus={device} />;
|
||||
if (isDeviceReducer(device)) return <ReducerIcon reducer={device} />;
|
||||
if (isDeviceLock(device)) return <LockIcon lock={device} />;
|
||||
if (isDeviceCache(device)) return <CacheIcon cache={device} />;
|
||||
if (isDeviceBattery(device)) return <BatteryIcon battery={device} />;
|
||||
return <></>;
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Component } from "@nsdefs";
|
||||
import { Component } from "@enums";
|
||||
|
||||
export const cellSize = 48;
|
||||
|
||||
|
@ -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 = <T>(arr: T[]): T => arr[Math.floor(Math.random() * arr.length)];
|
||||
|
||||
|
@ -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<IMyrian> {
|
||||
return {
|
||||
@ -109,7 +112,7 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
|
||||
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<IMyrian> {
|
||||
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);
|
||||
})
|
||||
|
162
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
162
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user