mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-27 18:13:52 +01:00
add upgrade tier functions
This commit is contained in:
parent
46c795c1a9
commit
ffaa657296
@ -61,6 +61,8 @@ export const tierScale: Record<DeviceType, FactoryFormulaParams> = {
|
|||||||
[DeviceType.Lock]: [Infinity, Infinity, Infinity, Infinity],
|
[DeviceType.Lock]: [Infinity, Infinity, Infinity, Infinity],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const tierCost = (type: DeviceType, tier: number) => exp(tierScale[type], tier);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
glitches:
|
glitches:
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ import {
|
|||||||
installSpeed,
|
installSpeed,
|
||||||
moveSpeed,
|
moveSpeed,
|
||||||
reduceSpeed,
|
reduceSpeed,
|
||||||
|
tierCost,
|
||||||
transferSpeed,
|
transferSpeed,
|
||||||
upgradeMaxContentCost,
|
upgradeMaxContentCost,
|
||||||
} from "../Myrian/formulas/formulas";
|
} from "../Myrian/formulas/formulas";
|
||||||
@ -37,7 +38,7 @@ import { componentTiers } from "../Myrian/formulas/components";
|
|||||||
|
|
||||||
export function NetscriptMyrian(): InternalAPI<IMyrian> {
|
export function NetscriptMyrian(): InternalAPI<IMyrian> {
|
||||||
return {
|
return {
|
||||||
reset: () => resetMyrian,
|
DEUBG_RESET: () => resetMyrian,
|
||||||
getDevice: (ctx) => (_id) => {
|
getDevice: (ctx) => (_id) => {
|
||||||
const id = helpers.deviceID(ctx, "id", _id);
|
const id = helpers.deviceID(ctx, "id", _id);
|
||||||
const device = findDevice(id);
|
const device = findDevice(id);
|
||||||
@ -408,5 +409,27 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
|
|||||||
placedDevice.isBusy = false;
|
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
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
23
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -5281,12 +5281,17 @@ export type DeviceID = string | [number, number];
|
|||||||
export type Device = Bus | ISocket | OSocket | Reducer | Cache | Lock;
|
export type Device = Bus | ISocket | OSocket | Reducer | Cache | Lock;
|
||||||
|
|
||||||
interface Myrian {
|
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
|
* Completely reset the myrian kernel, for debug purposes
|
||||||
* @remarks
|
* @remarks
|
||||||
* RAM cost: 0 GB
|
* RAM cost: 0 GB
|
||||||
*/
|
*/
|
||||||
reset(): void;
|
DEUBG_RESET(): void;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get device
|
* Get device
|
||||||
@ -5375,6 +5380,22 @@ interface Myrian {
|
|||||||
* @returns cost of upgrading the content of a device, -1 on failure.
|
* @returns cost of upgrading the content of a device, -1 on failure.
|
||||||
*/
|
*/
|
||||||
getUpgradeMaxContentCost(device: DeviceID): number;
|
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 */
|
/** @public */
|
||||||
|
Loading…
Reference in New Issue
Block a user