mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-24 00:23:49 +01:00
Add the Roaming Glitch
This commit is contained in:
parent
e9edcd2008
commit
e0cd360d4c
@ -1,6 +1,8 @@
|
|||||||
import { DeviceType, Component, Lock, Glitch } from "@nsdefs";
|
import { DeviceType, Component, Lock, Glitch } from "@nsdefs";
|
||||||
import { Myrian, findDevice } from "./Myrian";
|
import { Myrian, findDevice, inMyrianBounds } from "./Myrian";
|
||||||
import { getNextISocketRequest } from "./formulas/formulas";
|
import { getNextISocketRequest } from "./formulas/formulas";
|
||||||
|
import { decodeBase64 } from "bcryptjs";
|
||||||
|
import { roamingTime } from "./formulas/glitches";
|
||||||
|
|
||||||
export const myrianSize = 12;
|
export const myrianSize = 12;
|
||||||
|
|
||||||
@ -178,4 +180,72 @@ setInterval(() => {
|
|||||||
}
|
}
|
||||||
}, 30000);
|
}, 30000);
|
||||||
|
|
||||||
|
const clamp = (min: number, v: number, max: number) => Math.min(Math.max(v, min), max);
|
||||||
|
let globalOffset = 0;
|
||||||
|
const dirDiff = (v: number): number => {
|
||||||
|
globalOffset++;
|
||||||
|
const r = Math.random();
|
||||||
|
const d = v - (myrianSize - 1) / 2;
|
||||||
|
const h = d > 0 ? -1 : 1;
|
||||||
|
|
||||||
|
const dv = Math.floor(r * 3 + h * Math.random() * Math.sin(globalOffset * 0.05) * Math.abs(d)) - 1;
|
||||||
|
return clamp(-1, dv, 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
const isEmpty = (x: number, y: number) => {
|
||||||
|
if (!inMyrianBounds(x, y)) return false;
|
||||||
|
return !findDevice([x, y]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const dirs = [
|
||||||
|
[0, 1],
|
||||||
|
[0, -1],
|
||||||
|
[1, 0],
|
||||||
|
[-1, 0],
|
||||||
|
];
|
||||||
|
|
||||||
|
const applyRoaming = () => {
|
||||||
|
const roaming = myrian.glitches[Glitch.Roaming];
|
||||||
|
setTimeout(applyRoaming, roamingTime(roaming));
|
||||||
|
if (roaming === 0) return;
|
||||||
|
myrian.devices.forEach((device) => {
|
||||||
|
if (device.type !== DeviceType.OSocket && device.type !== DeviceType.ISocket) return;
|
||||||
|
if (device.isBusy) return;
|
||||||
|
let canMove = false;
|
||||||
|
for (const dir of dirs) {
|
||||||
|
const [dx, dy] = dir;
|
||||||
|
if (isEmpty(device.x + dx, device.y + dy)) {
|
||||||
|
canMove = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let x = -1;
|
||||||
|
let y = -1;
|
||||||
|
if (canMove) {
|
||||||
|
let dx = dirDiff(device.x);
|
||||||
|
let dy = dirDiff(device.y);
|
||||||
|
|
||||||
|
if (dx !== 0 && dy !== 0) {
|
||||||
|
if (Math.random() > 0.5) {
|
||||||
|
dx = 0;
|
||||||
|
} else {
|
||||||
|
dy = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x = device.x + dx;
|
||||||
|
y = device.y + dy;
|
||||||
|
} else {
|
||||||
|
x = Math.floor(Math.random() * myrianSize);
|
||||||
|
y = Math.floor(Math.random() * myrianSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (findDevice([x, y])) return;
|
||||||
|
if (!inMyrianBounds(x, y)) return;
|
||||||
|
device.x = x;
|
||||||
|
device.y = y;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
setTimeout(applyRoaming, 0);
|
||||||
|
|
||||||
resetMyrian();
|
resetMyrian();
|
||||||
|
@ -40,3 +40,5 @@ export const jammingMult = (lvl: number) => Math.pow(1.3, lvl);
|
|||||||
|
|
||||||
// energy loss
|
// energy loss
|
||||||
export const magnetismLoss = (lvl: number) => lvl;
|
export const magnetismLoss = (lvl: number) => lvl;
|
||||||
|
|
||||||
|
export const roamingTime = (lvl: number) => 30000 * Math.pow(0.7, lvl);
|
||||||
|
@ -79,7 +79,7 @@ const YHeader = () => {
|
|||||||
interface IProps {}
|
interface IProps {}
|
||||||
|
|
||||||
export const MyrianRoot = (__props: IProps): React.ReactElement => {
|
export const MyrianRoot = (__props: IProps): React.ReactElement => {
|
||||||
useRerender(200);
|
useRerender(50);
|
||||||
return (
|
return (
|
||||||
<Container maxWidth="lg" disableGutters sx={{ mx: 0 }}>
|
<Container maxWidth="lg" disableGutters sx={{ mx: 0 }}>
|
||||||
<Typography variant="h4">Myrian OS</Typography>
|
<Typography variant="h4">Myrian OS</Typography>
|
||||||
|
Loading…
Reference in New Issue
Block a user