From ffaa65729626d6056b7ba91410fc5bd4202e2cdd Mon Sep 17 00:00:00 2001 From: Olivier Gagnon Date: Sun, 9 Jun 2024 14:16:55 -0400 Subject: [PATCH] add upgrade tier functions --- src/Myrian/formulas/formulas.ts | 2 ++ src/NetscriptFunctions/Myrian.ts | 25 +++++++++++++++++++++- src/ScriptEditor/NetscriptDefinitions.d.ts | 23 +++++++++++++++++++- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/Myrian/formulas/formulas.ts b/src/Myrian/formulas/formulas.ts index c808fee43..28d9706c7 100644 --- a/src/Myrian/formulas/formulas.ts +++ b/src/Myrian/formulas/formulas.ts @@ -61,6 +61,8 @@ export const tierScale: Record = { [DeviceType.Lock]: [Infinity, Infinity, Infinity, Infinity], }; +export const tierCost = (type: DeviceType, tier: number) => exp(tierScale[type], tier); + /** glitches: diff --git a/src/NetscriptFunctions/Myrian.ts b/src/NetscriptFunctions/Myrian.ts index af72a82af..653d04d2d 100644 --- a/src/NetscriptFunctions/Myrian.ts +++ b/src/NetscriptFunctions/Myrian.ts @@ -29,6 +29,7 @@ import { installSpeed, moveSpeed, reduceSpeed, + tierCost, transferSpeed, upgradeMaxContentCost, } from "../Myrian/formulas/formulas"; @@ -37,7 +38,7 @@ import { componentTiers } from "../Myrian/formulas/components"; export function NetscriptMyrian(): InternalAPI { return { - reset: () => resetMyrian, + DEUBG_RESET: () => resetMyrian, getDevice: (ctx) => (_id) => { const id = helpers.deviceID(ctx, "id", _id); const device = findDevice(id); @@ -408,5 +409,27 @@ export function NetscriptMyrian(): InternalAPI { placedDevice.isBusy = false; }); }, + upgradeTier: (ctx) => (_id) => { + const id = helpers.deviceID(ctx, "device", _id); + const device = findDevice(id); + if (!device) return false; + if (!("tier" in device)) return false; + const cost = tierCost(device.type, device.tier); + if (myrian.vulns < cost) return false; + myrian.vulns -= cost; + device.tier++; + return true; + }, + getUpgradeTierCost: (ctx) => (_id) => { + const id = helpers.deviceID(ctx, "device", _id); + const device = findDevice(id); + if (!device) return -1; + if (!("tier" in device)) return -1; + return tierCost(device.type, device.tier); + }, + DEBUG_GIVE_VULNS: (ctx) => (_amount) => { + const amount = helpers.number(ctx, "amount", _amount); + myrian.vulns += amount; + }, }; } diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index 76f6119d2..e99703809 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -5281,12 +5281,17 @@ export type DeviceID = string | [number, number]; export type Device = Bus | ISocket | OSocket | Reducer | Cache | Lock; interface Myrian { + /** + * Give yourself some vulns, for testing. + * @param n amount of vulns to give + */ + DEBUG_GIVE_VULNS(n: number): void; /** * Completely reset the myrian kernel, for debug purposes * @remarks * RAM cost: 0 GB */ - reset(): void; + DEUBG_RESET(): void; /** * Get device @@ -5375,6 +5380,22 @@ interface Myrian { * @returns cost of upgrading the content of a device, -1 on failure. */ getUpgradeMaxContentCost(device: DeviceID): number; + + /** + * Upgrade the tier of a device + * @remarks + * RAM cost: 0 GB + * @returns true if the upgrade succeeded, false otherwise. + */ + upgradeTier(device: DeviceID): boolean; + + /** + * Get the cost of upgrading the tier of a device + * @remarks + * RAM cost: 0 GB + * @returns cost of upgrading the tier of a device, -1 on failure. + */ + getUpgradeTierCost(device: DeviceID): number; } /** @public */