From e9edcd2008522a4d08ebe32b62b8fc05c541ba35 Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Sun, 9 Jun 2024 19:04:23 -0400 Subject: [PATCH] Add Segmentation and Rust --- src/Myrian/Helper.tsx | 24 +++++++++++++++++++++++- src/Myrian/Myrian.ts | 13 +++++++++++++ src/Myrian/formulas/glitches.ts | 4 ++-- src/Myrian/tutorial.md | 8 ++++++++ src/NetscriptFunctions/Myrian.ts | 2 ++ 5 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/Myrian/Helper.tsx b/src/Myrian/Helper.tsx index fba99d7cb..9665d5175 100644 --- a/src/Myrian/Helper.tsx +++ b/src/Myrian/Helper.tsx @@ -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; @@ -21,6 +21,7 @@ const defaultMyrian: Myrian = { totalVulns: 0, devices: [], glitches: { ...defaultGlitches }, + rust: {}, }; export const myrian: Myrian = defaultMyrian; @@ -134,6 +135,7 @@ export const resetMyrian = () => { myrian.totalVulns = 0; myrian.devices = []; myrian.glitches = { ...defaultGlitches }; + myrian.rust = {}; Object.assign(myrian, defaultMyrian); @@ -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(); diff --git a/src/Myrian/Myrian.ts b/src/Myrian/Myrian.ts index cd4dcbbc6..eb446d0d1 100644 --- a/src/Myrian/Myrian.ts +++ b/src/Myrian/Myrian.ts @@ -22,6 +22,7 @@ export interface Myrian { totalVulns: number; devices: Device[]; glitches: Record; + rust: Record; } export const distance = (a: Device, b: Device) => Math.abs(a.x - b.x) + Math.abs(a.y - b.y); @@ -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; +}; diff --git a/src/Myrian/formulas/glitches.ts b/src/Myrian/formulas/glitches.ts index 493813077..a71b8d5d9 100644 --- a/src/Myrian/formulas/glitches.ts +++ b/src/Myrian/formulas/glitches.ts @@ -13,11 +13,11 @@ export const glitchMaxLvl: Record = { }; export const giltchMultCoefficients: Record = { - [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, diff --git a/src/Myrian/tutorial.md b/src/Myrian/tutorial.md index 8d34bd924..37349d1ad 100644 --- a/src/Myrian/tutorial.md +++ b/src/Myrian/tutorial.md @@ -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. diff --git a/src/NetscriptFunctions/Myrian.ts b/src/NetscriptFunctions/Myrian.ts index 1f3925710..95671a48f 100644 --- a/src/NetscriptFunctions/Myrian.ts +++ b/src/NetscriptFunctions/Myrian.ts @@ -24,6 +24,7 @@ import { isDeviceBus, removeDevice, getTotalGlitchMult, + rustBus, } from "../Myrian/Myrian"; import { deviceCost, @@ -118,6 +119,7 @@ export function NetscriptMyrian(): InternalAPI { } bus.x = x; bus.y = y; + if (myrian.rust[`${x}:${y}`]) rustBus(bus, myrian.glitches[Glitch.Rust]); return Promise.resolve(true); }) .finally(() => {