mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-23 16:13:49 +01:00
some fixed
This commit is contained in:
parent
bdf3a53151
commit
e11fa02716
@ -16,7 +16,7 @@ export const NewBus = (name: string, x: number, y: number) => {
|
||||
myrian.devices.push({
|
||||
name,
|
||||
type: DeviceType.Bus,
|
||||
busy: false,
|
||||
isBusy: false,
|
||||
x,
|
||||
y,
|
||||
content: [],
|
||||
@ -34,7 +34,7 @@ export const NewCache = (name: string, x: number, y: number) => {
|
||||
myrian.devices.push({
|
||||
name,
|
||||
type: DeviceType.Cache,
|
||||
busy: false,
|
||||
isBusy: false,
|
||||
content: [],
|
||||
maxContent: 1,
|
||||
x,
|
||||
@ -46,7 +46,7 @@ export const NewReducer = (name: string, x: number, y: number) => {
|
||||
myrian.devices.push({
|
||||
name,
|
||||
type: DeviceType.Reducer,
|
||||
busy: false,
|
||||
isBusy: false,
|
||||
x,
|
||||
y,
|
||||
content: [],
|
||||
@ -59,7 +59,7 @@ export const NewISocket = (name: string, x: number, y: number, dispensing: Compo
|
||||
myrian.devices.push({
|
||||
name,
|
||||
type: DeviceType.ISocket,
|
||||
busy: false,
|
||||
isBusy: false,
|
||||
x,
|
||||
y,
|
||||
emitting: dispensing,
|
||||
@ -74,7 +74,7 @@ export const NewOSocket = (name: string, x: number, y: number) => {
|
||||
myrian.devices.push({
|
||||
name,
|
||||
type: DeviceType.OSocket,
|
||||
busy: false,
|
||||
isBusy: false,
|
||||
tier: 0,
|
||||
x,
|
||||
y,
|
||||
@ -88,7 +88,7 @@ export const NewLock = (name: string, x: number, y: number) => {
|
||||
const lock: Lock = {
|
||||
name,
|
||||
type: DeviceType.Lock,
|
||||
busy: false,
|
||||
isBusy: false,
|
||||
x,
|
||||
y,
|
||||
};
|
||||
@ -107,13 +107,13 @@ export const resetMyrian = () => {
|
||||
myrian.devices = [];
|
||||
Object.assign(myrian, defaultMyrian);
|
||||
NewBus("alice", Math.floor(myrianSize / 2), Math.floor(myrianSize / 2));
|
||||
NewISocket("disp0", Math.floor(myrianSize / 4), 0, Component.R0);
|
||||
NewISocket("disp1", Math.floor(myrianSize / 2), 0, Component.Y1);
|
||||
NewISocket("disp2", Math.floor((myrianSize * 3) / 4), 0, Component.B0);
|
||||
NewISocket("isocket0", Math.floor(myrianSize / 4), 0, Component.R0);
|
||||
NewISocket("isocket1", Math.floor(myrianSize / 2), 0, Component.G0);
|
||||
NewISocket("isocket2", Math.floor((myrianSize * 3) / 4), 0, Component.B0);
|
||||
|
||||
NewOSocket("dock0", Math.floor(myrianSize / 4), Math.floor(myrianSize - 1));
|
||||
NewOSocket("dock1", Math.floor(myrianSize / 2), Math.floor(myrianSize - 1));
|
||||
NewOSocket("dock2", Math.floor((myrianSize * 3) / 4), Math.floor(myrianSize - 1));
|
||||
NewOSocket("osocket0", Math.floor(myrianSize / 4), Math.floor(myrianSize - 1));
|
||||
NewOSocket("osocket1", Math.floor(myrianSize / 2), Math.floor(myrianSize - 1));
|
||||
NewOSocket("osocket2", Math.floor((myrianSize * 3) / 4), Math.floor(myrianSize - 1));
|
||||
};
|
||||
|
||||
resetMyrian();
|
||||
|
@ -46,6 +46,12 @@ export const getNextISocketRequest = (tier: number) => {
|
||||
.map(() => potential[Math.floor(Math.random() * potential.length)]);
|
||||
};
|
||||
|
||||
(() => {
|
||||
for (let i = 0; i < 10; i++) {
|
||||
console.log(getNextISocketRequest(0));
|
||||
}
|
||||
})();
|
||||
|
||||
export const tierScale: Record<DeviceType, FactoryFormulaParams> = {
|
||||
[DeviceType.Bus]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||
|
@ -40,7 +40,9 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
|
||||
reset: () => resetMyrian,
|
||||
getDevice: (ctx) => (_id) => {
|
||||
const id = helpers.deviceID(ctx, "id", _id);
|
||||
return JSON.parse(JSON.stringify(findDevice(id)));
|
||||
const device = findDevice(id);
|
||||
if (!device) return;
|
||||
return JSON.parse(JSON.stringify(device));
|
||||
},
|
||||
getDevices: (__ctx) => () => JSON.parse(JSON.stringify(myrian.devices)),
|
||||
getVulns: () => () => myrian.vulns,
|
||||
@ -70,14 +72,14 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
if (bus.busy) {
|
||||
if (bus.isBusy) {
|
||||
helpers.log(ctx, () => `bus ${busID} is busy`);
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
bus.busy = true;
|
||||
bus.isBusy = true;
|
||||
return helpers.netscriptDelay(ctx, moveSpeed(bus.moveLvl), true).then(() => {
|
||||
bus.busy = false;
|
||||
bus.isBusy = false;
|
||||
if (findDevice([x, y])) {
|
||||
helpers.log(ctx, () => `[${x}, ${y}] is occupied`);
|
||||
return Promise.resolve(false);
|
||||
@ -141,19 +143,19 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
if (fromDevice.busy || toDevice.busy) {
|
||||
if (fromDevice.isBusy || toDevice.isBusy) {
|
||||
helpers.log(ctx, () => "one of the entities is busy");
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
const bus = [fromDevice, toDevice].find((e) => e.type === DeviceType.Bus) as Bus;
|
||||
const container = [fromDevice, toDevice].find((e) => e.type !== DeviceType.Bus)!;
|
||||
fromDevice.busy = true;
|
||||
toDevice.busy = true;
|
||||
fromDevice.isBusy = true;
|
||||
toDevice.isBusy = true;
|
||||
|
||||
return helpers.netscriptDelay(ctx, transferSpeed(bus.transferLvl), true).then(() => {
|
||||
fromDevice.busy = false;
|
||||
toDevice.busy = false;
|
||||
fromDevice.isBusy = false;
|
||||
toDevice.isBusy = false;
|
||||
toDevice.content = toDevice.content.filter((item) => !input.includes(item));
|
||||
toDevice.content.push(...output);
|
||||
|
||||
@ -215,16 +217,16 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
if (bus.busy || reducer.busy) {
|
||||
if (bus.isBusy || reducer.isBusy) {
|
||||
helpers.log(ctx, () => "bus or reducer is busy");
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
bus.busy = true;
|
||||
reducer.busy = true;
|
||||
bus.isBusy = true;
|
||||
reducer.isBusy = true;
|
||||
return helpers.netscriptDelay(ctx, reduceSpeed(bus.reduceLvl), true).then(() => {
|
||||
bus.busy = false;
|
||||
reducer.busy = false;
|
||||
bus.isBusy = false;
|
||||
reducer.isBusy = false;
|
||||
reducer.content = [recipe.output];
|
||||
return Promise.resolve(true);
|
||||
});
|
||||
@ -298,7 +300,7 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
if (bus.busy) {
|
||||
if (bus.isBusy) {
|
||||
helpers.log(ctx, () => `bus ${busID} is busy`);
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
@ -321,12 +323,12 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
bus.busy = true;
|
||||
bus.isBusy = true;
|
||||
const lockName = `lock-${busID}`;
|
||||
const lock = NewLock(lockName, x, y);
|
||||
lock.busy = true;
|
||||
lock.isBusy = true;
|
||||
return helpers.netscriptDelay(ctx, installSpeed(bus.installLvl), true).then(() => {
|
||||
bus.busy = false;
|
||||
bus.isBusy = false;
|
||||
removeDevice(lockName);
|
||||
switch (deviceType) {
|
||||
case DeviceType.Bus: {
|
||||
@ -368,16 +370,16 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
if (bus.busy || placedDevice.busy) {
|
||||
if (bus.isBusy || placedDevice.isBusy) {
|
||||
helpers.log(ctx, () => `bus or device is busy`);
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
bus.busy = true;
|
||||
placedDevice.busy = true;
|
||||
bus.isBusy = true;
|
||||
placedDevice.isBusy = true;
|
||||
return helpers.netscriptDelay(ctx, installSpeed(bus.installLvl), true).then(() => {
|
||||
bus.busy = false;
|
||||
placedDevice.busy = false;
|
||||
bus.isBusy = false;
|
||||
placedDevice.isBusy = false;
|
||||
removeDevice([x, y]);
|
||||
return Promise.resolve(true);
|
||||
});
|
||||
|
2
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
2
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -5227,7 +5227,7 @@ export interface BaseDevice {
|
||||
type: DeviceType;
|
||||
x: number;
|
||||
y: number;
|
||||
busy: boolean;
|
||||
isBusy: boolean;
|
||||
}
|
||||
|
||||
export interface Bus extends ContainerDevice {
|
||||
|
Loading…
Reference in New Issue
Block a user