some fixed

This commit is contained in:
Olivier Gagnon 2024-06-09 13:52:06 -04:00
parent bdf3a53151
commit e11fa02716
No known key found for this signature in database
GPG Key ID: 0018772EA86FA03F
4 changed files with 44 additions and 36 deletions

@ -16,7 +16,7 @@ export const NewBus = (name: string, x: number, y: number) => {
myrian.devices.push({ myrian.devices.push({
name, name,
type: DeviceType.Bus, type: DeviceType.Bus,
busy: false, isBusy: false,
x, x,
y, y,
content: [], content: [],
@ -34,7 +34,7 @@ export const NewCache = (name: string, x: number, y: number) => {
myrian.devices.push({ myrian.devices.push({
name, name,
type: DeviceType.Cache, type: DeviceType.Cache,
busy: false, isBusy: false,
content: [], content: [],
maxContent: 1, maxContent: 1,
x, x,
@ -46,7 +46,7 @@ export const NewReducer = (name: string, x: number, y: number) => {
myrian.devices.push({ myrian.devices.push({
name, name,
type: DeviceType.Reducer, type: DeviceType.Reducer,
busy: false, isBusy: false,
x, x,
y, y,
content: [], content: [],
@ -59,7 +59,7 @@ export const NewISocket = (name: string, x: number, y: number, dispensing: Compo
myrian.devices.push({ myrian.devices.push({
name, name,
type: DeviceType.ISocket, type: DeviceType.ISocket,
busy: false, isBusy: false,
x, x,
y, y,
emitting: dispensing, emitting: dispensing,
@ -74,7 +74,7 @@ export const NewOSocket = (name: string, x: number, y: number) => {
myrian.devices.push({ myrian.devices.push({
name, name,
type: DeviceType.OSocket, type: DeviceType.OSocket,
busy: false, isBusy: false,
tier: 0, tier: 0,
x, x,
y, y,
@ -88,7 +88,7 @@ export const NewLock = (name: string, x: number, y: number) => {
const lock: Lock = { const lock: Lock = {
name, name,
type: DeviceType.Lock, type: DeviceType.Lock,
busy: false, isBusy: false,
x, x,
y, y,
}; };
@ -107,13 +107,13 @@ export const resetMyrian = () => {
myrian.devices = []; myrian.devices = [];
Object.assign(myrian, defaultMyrian); Object.assign(myrian, defaultMyrian);
NewBus("alice", Math.floor(myrianSize / 2), Math.floor(myrianSize / 2)); NewBus("alice", Math.floor(myrianSize / 2), Math.floor(myrianSize / 2));
NewISocket("disp0", Math.floor(myrianSize / 4), 0, Component.R0); NewISocket("isocket0", Math.floor(myrianSize / 4), 0, Component.R0);
NewISocket("disp1", Math.floor(myrianSize / 2), 0, Component.Y1); NewISocket("isocket1", Math.floor(myrianSize / 2), 0, Component.G0);
NewISocket("disp2", Math.floor((myrianSize * 3) / 4), 0, Component.B0); NewISocket("isocket2", Math.floor((myrianSize * 3) / 4), 0, Component.B0);
NewOSocket("dock0", Math.floor(myrianSize / 4), Math.floor(myrianSize - 1)); NewOSocket("osocket0", Math.floor(myrianSize / 4), Math.floor(myrianSize - 1));
NewOSocket("dock1", Math.floor(myrianSize / 2), Math.floor(myrianSize - 1)); NewOSocket("osocket1", Math.floor(myrianSize / 2), Math.floor(myrianSize - 1));
NewOSocket("dock2", Math.floor((myrianSize * 3) / 4), Math.floor(myrianSize - 1)); NewOSocket("osocket2", Math.floor((myrianSize * 3) / 4), Math.floor(myrianSize - 1));
}; };
resetMyrian(); resetMyrian();

@ -46,6 +46,12 @@ export const getNextISocketRequest = (tier: number) => {
.map(() => potential[Math.floor(Math.random() * potential.length)]); .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> = { export const tierScale: Record<DeviceType, FactoryFormulaParams> = {
[DeviceType.Bus]: [Infinity, Infinity, Infinity, Infinity], [DeviceType.Bus]: [Infinity, Infinity, Infinity, Infinity],
[DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity], [DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity],

@ -40,7 +40,9 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
reset: () => resetMyrian, reset: () => resetMyrian,
getDevice: (ctx) => (_id) => { getDevice: (ctx) => (_id) => {
const id = helpers.deviceID(ctx, "id", _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)), getDevices: (__ctx) => () => JSON.parse(JSON.stringify(myrian.devices)),
getVulns: () => () => myrian.vulns, getVulns: () => () => myrian.vulns,
@ -70,14 +72,14 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
return Promise.resolve(false); return Promise.resolve(false);
} }
if (bus.busy) { if (bus.isBusy) {
helpers.log(ctx, () => `bus ${busID} is busy`); helpers.log(ctx, () => `bus ${busID} is busy`);
return Promise.resolve(false); return Promise.resolve(false);
} }
bus.busy = true; bus.isBusy = true;
return helpers.netscriptDelay(ctx, moveSpeed(bus.moveLvl), true).then(() => { return helpers.netscriptDelay(ctx, moveSpeed(bus.moveLvl), true).then(() => {
bus.busy = false; bus.isBusy = false;
if (findDevice([x, y])) { if (findDevice([x, y])) {
helpers.log(ctx, () => `[${x}, ${y}] is occupied`); helpers.log(ctx, () => `[${x}, ${y}] is occupied`);
return Promise.resolve(false); return Promise.resolve(false);
@ -141,19 +143,19 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
return Promise.resolve(false); return Promise.resolve(false);
} }
if (fromDevice.busy || toDevice.busy) { if (fromDevice.isBusy || toDevice.isBusy) {
helpers.log(ctx, () => "one of the entities is busy"); helpers.log(ctx, () => "one of the entities is busy");
return Promise.resolve(false); return Promise.resolve(false);
} }
const bus = [fromDevice, toDevice].find((e) => e.type === DeviceType.Bus) as Bus; const bus = [fromDevice, toDevice].find((e) => e.type === DeviceType.Bus) as Bus;
const container = [fromDevice, toDevice].find((e) => e.type !== DeviceType.Bus)!; const container = [fromDevice, toDevice].find((e) => e.type !== DeviceType.Bus)!;
fromDevice.busy = true; fromDevice.isBusy = true;
toDevice.busy = true; toDevice.isBusy = true;
return helpers.netscriptDelay(ctx, transferSpeed(bus.transferLvl), true).then(() => { return helpers.netscriptDelay(ctx, transferSpeed(bus.transferLvl), true).then(() => {
fromDevice.busy = false; fromDevice.isBusy = false;
toDevice.busy = false; toDevice.isBusy = false;
toDevice.content = toDevice.content.filter((item) => !input.includes(item)); toDevice.content = toDevice.content.filter((item) => !input.includes(item));
toDevice.content.push(...output); toDevice.content.push(...output);
@ -215,16 +217,16 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
return Promise.resolve(false); return Promise.resolve(false);
} }
if (bus.busy || reducer.busy) { if (bus.isBusy || reducer.isBusy) {
helpers.log(ctx, () => "bus or reducer is busy"); helpers.log(ctx, () => "bus or reducer is busy");
return Promise.resolve(false); return Promise.resolve(false);
} }
bus.busy = true; bus.isBusy = true;
reducer.busy = true; reducer.isBusy = true;
return helpers.netscriptDelay(ctx, reduceSpeed(bus.reduceLvl), true).then(() => { return helpers.netscriptDelay(ctx, reduceSpeed(bus.reduceLvl), true).then(() => {
bus.busy = false; bus.isBusy = false;
reducer.busy = false; reducer.isBusy = false;
reducer.content = [recipe.output]; reducer.content = [recipe.output];
return Promise.resolve(true); return Promise.resolve(true);
}); });
@ -298,7 +300,7 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
return Promise.resolve(false); return Promise.resolve(false);
} }
if (bus.busy) { if (bus.isBusy) {
helpers.log(ctx, () => `bus ${busID} is busy`); helpers.log(ctx, () => `bus ${busID} is busy`);
return Promise.resolve(false); return Promise.resolve(false);
} }
@ -321,12 +323,12 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
return Promise.resolve(false); return Promise.resolve(false);
} }
bus.busy = true; bus.isBusy = true;
const lockName = `lock-${busID}`; const lockName = `lock-${busID}`;
const lock = NewLock(lockName, x, y); const lock = NewLock(lockName, x, y);
lock.busy = true; lock.isBusy = true;
return helpers.netscriptDelay(ctx, installSpeed(bus.installLvl), true).then(() => { return helpers.netscriptDelay(ctx, installSpeed(bus.installLvl), true).then(() => {
bus.busy = false; bus.isBusy = false;
removeDevice(lockName); removeDevice(lockName);
switch (deviceType) { switch (deviceType) {
case DeviceType.Bus: { case DeviceType.Bus: {
@ -368,16 +370,16 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
return Promise.resolve(false); return Promise.resolve(false);
} }
if (bus.busy || placedDevice.busy) { if (bus.isBusy || placedDevice.isBusy) {
helpers.log(ctx, () => `bus or device is busy`); helpers.log(ctx, () => `bus or device is busy`);
return Promise.resolve(false); return Promise.resolve(false);
} }
bus.busy = true; bus.isBusy = true;
placedDevice.busy = true; placedDevice.isBusy = true;
return helpers.netscriptDelay(ctx, installSpeed(bus.installLvl), true).then(() => { return helpers.netscriptDelay(ctx, installSpeed(bus.installLvl), true).then(() => {
bus.busy = false; bus.isBusy = false;
placedDevice.busy = false; placedDevice.isBusy = false;
removeDevice([x, y]); removeDevice([x, y]);
return Promise.resolve(true); return Promise.resolve(true);
}); });

@ -5227,7 +5227,7 @@ export interface BaseDevice {
type: DeviceType; type: DeviceType;
x: number; x: number;
y: number; y: number;
busy: boolean; isBusy: boolean;
} }
export interface Bus extends ContainerDevice { export interface Bus extends ContainerDevice {