Skip to content

Commit

Permalink
Add Segmentation and Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Gagnon committed Jun 9, 2024
1 parent e2e7150 commit e9edcd2
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
24 changes: 23 additions & 1 deletion src/Myrian/Helper.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DeviceType, Component, Lock, Glitch } from "@nsdefs";
import { Myrian } from "./Myrian";
import { Myrian, findDevice } from "./Myrian";
import { getNextISocketRequest } from "./formulas/formulas";

export const myrianSize = 12;
Expand All @@ -21,6 +21,7 @@ const defaultMyrian: Myrian = {
totalVulns: 0,
devices: [],
glitches: { ...defaultGlitches },
rust: {},
};

export const myrian: Myrian = defaultMyrian;
Expand Down Expand Up @@ -134,6 +135,7 @@ export const resetMyrian = () => {
myrian.totalVulns = 0;
myrian.devices = [];
myrian.glitches = { ...defaultGlitches };
myrian.rust = {};

Object.assign(myrian, defaultMyrian);

Expand All @@ -156,4 +158,24 @@ setInterval(() => {
});
}, 1000);

setInterval(() => {
const segmentation = myrian.glitches[Glitch.Segmentation];
for (let i = 0; i < segmentation; i++) {
const x = Math.floor(Math.random() * myrianSize);
const y = Math.floor(Math.random() * myrianSize);
if (findDevice([x, y])) continue;
NewLock(`lock-${x}-${y}`, x, y);
}
}, 30000);

setInterval(() => {
myrian.rust = {};
const rust = myrian.glitches[Glitch.Rust];
for (let i = 0; i < rust * 3; i++) {
const x = Math.floor(Math.random() * myrianSize);
const y = Math.floor(Math.random() * myrianSize);
myrian.rust[`${x}:${y}`] = true;
}
}, 30000);

resetMyrian();
13 changes: 13 additions & 0 deletions src/Myrian/Myrian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface Myrian {
totalVulns: number;
devices: Device[];
glitches: Record<Glitch, number>;
rust: Record<string, boolean>;
}

export const distance = (a: Device, b: Device) => Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
Expand Down Expand Up @@ -133,3 +134,15 @@ export const getTotalGlitchMult = () =>
Object.entries(myrian.glitches).reduce((acc, [glitch, lvl]) => {
return acc * glitchMult(glitch as Glitch, lvl);
}, 1);

const rustStats: (keyof Bus)[] = ["moveLvl", "transferLvl", "reduceLvl", "installLvl", "maxEnergy"];

export const rustBus = (bus: Bus, rust: number) => {
const potential = rustStats.filter((stat) => {
const value = bus[stat];
if (typeof value !== "number") return false;
return value > 0;
});
const chosen = potential[Math.floor(Math.random() * potential.length)];
(bus[chosen] as any) = Math.max(0, (bus[chosen] as any) - rust * 0.1) as any;
};
4 changes: 2 additions & 2 deletions src/Myrian/formulas/glitches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export const glitchMaxLvl: Record<Glitch, number> = {
};

export const giltchMultCoefficients: Record<Glitch, number> = {
[Glitch.Segmentation]: 0, // 1,
[Glitch.Segmentation]: 1,
[Glitch.Roaming]: 0, // 1,
[Glitch.Encryption]: 0, // 0.1,
[Glitch.Magnetism]: 0.2,
[Glitch.Rust]: 0, // 1,
[Glitch.Rust]: 1,
[Glitch.Friction]: 0.2,
[Glitch.Isolation]: 0.2,
[Glitch.Virtualization]: 0.2,
Expand Down
8 changes: 8 additions & 0 deletions src/Myrian/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,18 @@ By default bus lose 0 energy when moving. But when this glitch is active they st

When Friction is active busses move more slowly.

## Rust

When rust is active, hidden tiles are set on the Myrian. When a bus steps on one of these hidden tiles one of their upgrade lowers. Higher Rust level means lowers by a larger amount and more rust tiles are set.

### Isolation

When Isolation is active busses transfer and charge more slowly.

## Segmentation

When Segmentation is active random Locks will spawn on the Myrian. You have to remove these locks or the bord will be overrun with Locks and you won't be able to move.

### Virtualization

When Virtualization is active busses install and uninstall devices more slowly.
Expand Down
2 changes: 2 additions & 0 deletions src/NetscriptFunctions/Myrian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
isDeviceBus,
removeDevice,
getTotalGlitchMult,
rustBus,
} from "../Myrian/Myrian";
import {
deviceCost,
Expand Down Expand Up @@ -118,6 +119,7 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
}
bus.x = x;
bus.y = y;
if (myrian.rust[`${x}:${y}`]) rustBus(bus, myrian.glitches[Glitch.Rust]);
return Promise.resolve(true);
})
.finally(() => {
Expand Down

0 comments on commit e9edcd2

Please sign in to comment.