mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-25 15:42:28 +01:00
Add tweakISocket
This commit is contained in:
parent
3d87baeb15
commit
e00ea77de8
@ -1,4 +1,4 @@
|
|||||||
import { Bus, Myrian as IMyrian, DeviceType, Component, Reducer, Glitch, Battery } from "@nsdefs";
|
import { Bus, Myrian as IMyrian, DeviceType, Component, Reducer, Glitch, Battery, ISocket } from "@nsdefs";
|
||||||
import { InternalAPI } from "../Netscript/APIWrapper";
|
import { InternalAPI } from "../Netscript/APIWrapper";
|
||||||
import { helpers } from "../Netscript/NetscriptHelpers";
|
import { helpers } from "../Netscript/NetscriptHelpers";
|
||||||
import {
|
import {
|
||||||
@ -279,6 +279,56 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
|
|||||||
reducer.isBusy = false;
|
reducer.isBusy = false;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
tweakISocket: (ctx) => async (_bus, _isocket, _component) => {
|
||||||
|
const busID = helpers.deviceID(ctx, "bus", _bus);
|
||||||
|
const isocketID = helpers.deviceID(ctx, "isocket", _isocket);
|
||||||
|
const component = helpers.string(ctx, "component", _component) as Component;
|
||||||
|
|
||||||
|
if (!componentTiers[0].includes(component)) {
|
||||||
|
helpers.log(ctx, () => `component ${component} is not a valid component`);
|
||||||
|
return Promise.resolve(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
const bus = findDevice(busID, DeviceType.Bus) as Bus;
|
||||||
|
if (!bus) {
|
||||||
|
helpers.log(ctx, () => `bus ${busID} not found`);
|
||||||
|
return Promise.resolve(false);
|
||||||
|
}
|
||||||
|
const isocket = findDevice(isocketID, DeviceType.ISocket) as ISocket;
|
||||||
|
if (!isocket) {
|
||||||
|
helpers.log(ctx, () => `isocket ${isocketID} not found`);
|
||||||
|
return Promise.resolve(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!adjacent(bus, isocket)) {
|
||||||
|
helpers.log(ctx, () => "bus and isocket are not adjacent");
|
||||||
|
return Promise.resolve(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
bus.isBusy = true;
|
||||||
|
isocket.isBusy = true;
|
||||||
|
|
||||||
|
return helpers
|
||||||
|
.netscriptDelay(
|
||||||
|
ctx,
|
||||||
|
installSpeed(bus.installLvl) * virtualizationMult(myrian.glitches[Glitch.Virtualization]),
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
.then(() => {
|
||||||
|
isocket.emitting = component;
|
||||||
|
isocket.content = [];
|
||||||
|
const cooldown = isocketSpeed(isocket.emissionLvl);
|
||||||
|
isocket.cooldownUntil = Date.now() + cooldown;
|
||||||
|
setTimeout(() => {
|
||||||
|
isocket.content = new Array(isocket.maxContent).fill(isocket.emitting);
|
||||||
|
}, cooldown);
|
||||||
|
return Promise.resolve(true);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
bus.isBusy = false;
|
||||||
|
isocket.isBusy = false;
|
||||||
|
});
|
||||||
|
},
|
||||||
energize: (ctx) => async (_bus, _battery) => {
|
energize: (ctx) => async (_bus, _battery) => {
|
||||||
const busID = helpers.deviceID(ctx, "bus", _bus);
|
const busID = helpers.deviceID(ctx, "bus", _bus);
|
||||||
const batteryID = helpers.deviceID(ctx, "battery", _battery);
|
const batteryID = helpers.deviceID(ctx, "battery", _battery);
|
||||||
|
7
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
7
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -5372,6 +5372,13 @@ interface Myrian {
|
|||||||
*/
|
*/
|
||||||
reduce(bus: DeviceID, reducer: DeviceID): Promise<boolean>;
|
reduce(bus: DeviceID, reducer: DeviceID): Promise<boolean>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the component that an isocket emits.
|
||||||
|
* @param component tier 0 component that the isocket should emit
|
||||||
|
* @returns true if the tweak succeeded, false otherwise.
|
||||||
|
*/
|
||||||
|
tweakISocket(bus: DeviceID, isocket: DeviceID, component: Component): Promise<boolean>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Charge a bus with a battery, restoring it's energy.
|
* Charge a bus with a battery, restoring it's energy.
|
||||||
* @returns positive number for the amount of energy transfered, -1 on failure.
|
* @returns positive number for the amount of energy transfered, -1 on failure.
|
||||||
|
Loading…
Reference in New Issue
Block a user