Skip to content

Commit

Permalink
add upgrade tier functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Olivier Gagnon committed Jun 9, 2024
1 parent 46c795c commit ffaa657
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/Myrian/formulas/formulas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export const tierScale: Record<DeviceType, FactoryFormulaParams> = {
[DeviceType.Lock]: [Infinity, Infinity, Infinity, Infinity],
};

export const tierCost = (type: DeviceType, tier: number) => exp(tierScale[type], tier);

/**
glitches:
Expand Down
25 changes: 24 additions & 1 deletion src/NetscriptFunctions/Myrian.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
installSpeed,
moveSpeed,
reduceSpeed,
tierCost,
transferSpeed,
upgradeMaxContentCost,
} from "../Myrian/formulas/formulas";
Expand All @@ -37,7 +38,7 @@ import { componentTiers } from "../Myrian/formulas/components";

export function NetscriptMyrian(): InternalAPI<IMyrian> {
return {
reset: () => resetMyrian,
DEUBG_RESET: () => resetMyrian,
getDevice: (ctx) => (_id) => {
const id = helpers.deviceID(ctx, "id", _id);
const device = findDevice(id);
Expand Down Expand Up @@ -408,5 +409,27 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
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;
},
};
}
23 changes: 22 additions & 1 deletion src/ScriptEditor/NetscriptDefinitions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit ffaa657

Please sign in to comment.