mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-23 16:13:49 +01:00
add Add several upgrade functions
This commit is contained in:
parent
ffaa657296
commit
863be2abed
@ -22,10 +22,10 @@ export const NewBus = (name: string, x: number, y: number) => {
|
||||
content: [],
|
||||
maxContent: 1,
|
||||
|
||||
moveLvl: 1,
|
||||
transferLvl: 1,
|
||||
reduceLvl: 1,
|
||||
installLvl: 1,
|
||||
moveLvl: 0,
|
||||
transferLvl: 0,
|
||||
reduceLvl: 0,
|
||||
installLvl: 0,
|
||||
// energy: 16,
|
||||
});
|
||||
};
|
||||
@ -63,7 +63,7 @@ export const NewISocket = (name: string, x: number, y: number, dispensing: Compo
|
||||
x,
|
||||
y,
|
||||
emitting: dispensing,
|
||||
cooldown: 10000,
|
||||
emissionLvl: 0,
|
||||
cooldownUntil: 0,
|
||||
content: [dispensing],
|
||||
maxContent: 1,
|
||||
|
@ -20,10 +20,11 @@ export const upgradeMaxContentCost = (type: DeviceType, currentMaxContent: numbe
|
||||
exp(maxContentScale[type], currentMaxContent);
|
||||
|
||||
export const busPrice = (currentBusses: number): number => Math.pow(2, currentBusses + 3);
|
||||
export const moveSpeed = (level: number) => 1000 / (level + 9);
|
||||
export const reduceSpeed = (level: number) => 50000 / (level + 9);
|
||||
export const transferSpeed = (level: number) => 1000 / (level + 9);
|
||||
export const installSpeed = (level: number) => 100000 / (level + 9);
|
||||
export const moveSpeed = (level: number) => 1000 / (level + 10);
|
||||
export const reduceSpeed = (level: number) => 50000 / (level + 10);
|
||||
export const transferSpeed = (level: number) => 1000 / (level + 10);
|
||||
export const installSpeed = (level: number) => 100000 / (level + 10);
|
||||
export const isocketSpeed = (level: number) => 10000 / (level + 10);
|
||||
|
||||
const countDevices = (type: DeviceType) => myrian.devices.reduce((acc, d) => (d.type === type ? acc + 1 : acc), 0);
|
||||
|
||||
@ -46,12 +47,6 @@ export const getNextISocketRequest = (tier: number) => {
|
||||
.map(() => potential[Math.floor(Math.random() * potential.length)]);
|
||||
};
|
||||
|
||||
(() => {
|
||||
for (let i = 0; i < 10; i++) {
|
||||
console.log(getNextISocketRequest(0));
|
||||
}
|
||||
})();
|
||||
|
||||
export const tierScale: Record<DeviceType, FactoryFormulaParams> = {
|
||||
[DeviceType.Bus]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||
@ -63,6 +58,61 @@ export const tierScale: Record<DeviceType, FactoryFormulaParams> = {
|
||||
|
||||
export const tierCost = (type: DeviceType, tier: number) => exp(tierScale[type], tier);
|
||||
|
||||
export const emissionScale: Record<DeviceType, FactoryFormulaParams> = {
|
||||
[DeviceType.Bus]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.ISocket]: [2, 1, 3, 0],
|
||||
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.Reducer]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.Cache]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.Lock]: [Infinity, Infinity, Infinity, Infinity],
|
||||
};
|
||||
|
||||
export const emissionCost = (type: DeviceType, emissionLvl: number) => exp(emissionScale[type], emissionLvl);
|
||||
|
||||
export const moveLvlScale: Record<DeviceType, FactoryFormulaParams> = {
|
||||
[DeviceType.Bus]: [2, 1, 3, 0],
|
||||
[DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.Reducer]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.Cache]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.Lock]: [Infinity, Infinity, Infinity, Infinity],
|
||||
};
|
||||
|
||||
export const moveLvlCost = (type: DeviceType, moveLvl: number) => exp(moveLvlScale[type], moveLvl);
|
||||
|
||||
export const transferLvlScale: Record<DeviceType, FactoryFormulaParams> = {
|
||||
[DeviceType.Bus]: [2, 1, 3, 0],
|
||||
[DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.Reducer]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.Cache]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.Lock]: [Infinity, Infinity, Infinity, Infinity],
|
||||
};
|
||||
|
||||
export const transferLvlCost = (type: DeviceType, transferLvl: number) => exp(transferLvlScale[type], transferLvl);
|
||||
|
||||
export const reduceLvlScale: Record<DeviceType, FactoryFormulaParams> = {
|
||||
[DeviceType.Bus]: [2, 1, 3, 0],
|
||||
[DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.Reducer]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.Cache]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.Lock]: [Infinity, Infinity, Infinity, Infinity],
|
||||
};
|
||||
|
||||
export const reduceLvlCost = (type: DeviceType, reduceLvl: number) => exp(reduceLvlScale[type], reduceLvl);
|
||||
|
||||
export const installLvlScale: Record<DeviceType, FactoryFormulaParams> = {
|
||||
[DeviceType.Bus]: [2, 1, 3, 0],
|
||||
[DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.Reducer]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.Cache]: [Infinity, Infinity, Infinity, Infinity],
|
||||
[DeviceType.Lock]: [Infinity, Infinity, Infinity, Infinity],
|
||||
};
|
||||
|
||||
export const installLvlCost = (type: DeviceType, installLvl: number) => exp(installLvlScale[type], installLvl);
|
||||
|
||||
/**
|
||||
glitches:
|
||||
|
||||
|
@ -25,11 +25,17 @@ import {
|
||||
} from "../Myrian/Myrian";
|
||||
import {
|
||||
deviceCost,
|
||||
emissionCost,
|
||||
getNextISocketRequest,
|
||||
installLvlCost,
|
||||
installSpeed,
|
||||
isocketSpeed,
|
||||
moveLvlCost,
|
||||
moveSpeed,
|
||||
reduceLvlCost,
|
||||
reduceSpeed,
|
||||
tierCost,
|
||||
transferLvlCost,
|
||||
transferSpeed,
|
||||
upgradeMaxContentCost,
|
||||
} from "../Myrian/formulas/formulas";
|
||||
@ -39,6 +45,10 @@ import { componentTiers } from "../Myrian/formulas/components";
|
||||
export function NetscriptMyrian(): InternalAPI<IMyrian> {
|
||||
return {
|
||||
DEUBG_RESET: () => resetMyrian,
|
||||
DEBUG_GIVE_VULNS: (ctx) => (_amount) => {
|
||||
const amount = helpers.number(ctx, "amount", _amount);
|
||||
myrian.vulns += amount;
|
||||
},
|
||||
getDevice: (ctx) => (_id) => {
|
||||
const id = helpers.deviceID(ctx, "id", _id);
|
||||
const device = findDevice(id);
|
||||
@ -170,10 +180,11 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
|
||||
|
||||
switch (container.type) {
|
||||
case DeviceType.ISocket: {
|
||||
container.cooldownUntil = Date.now() + container.cooldown;
|
||||
const cooldown = isocketSpeed(container.emissionLvl);
|
||||
container.cooldownUntil = Date.now() + cooldown;
|
||||
setTimeout(() => {
|
||||
container.content = new Array(container.maxContent).fill(container.emitting);
|
||||
}, container.cooldown);
|
||||
}, cooldown);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -409,6 +420,13 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
|
||||
placedDevice.isBusy = false;
|
||||
});
|
||||
},
|
||||
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);
|
||||
},
|
||||
upgradeTier: (ctx) => (_id) => {
|
||||
const id = helpers.deviceID(ctx, "device", _id);
|
||||
const device = findDevice(id);
|
||||
@ -420,16 +438,95 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
|
||||
device.tier++;
|
||||
return true;
|
||||
},
|
||||
getUpgradeTierCost: (ctx) => (_id) => {
|
||||
getUpgradeEmissionLvlCost: (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);
|
||||
if (!("emissionLvl" in device)) return -1;
|
||||
return emissionCost(device.type, device.emissionLvl);
|
||||
},
|
||||
DEBUG_GIVE_VULNS: (ctx) => (_amount) => {
|
||||
const amount = helpers.number(ctx, "amount", _amount);
|
||||
myrian.vulns += amount;
|
||||
upgradeEmissionLvl: (ctx) => (_id) => {
|
||||
const id = helpers.deviceID(ctx, "device", _id);
|
||||
const device = findDevice(id);
|
||||
if (!device) return false;
|
||||
if (!("emissionLvl" in device)) return false;
|
||||
const cost = emissionCost(device.type, device.emissionLvl);
|
||||
if (myrian.vulns < cost) return false;
|
||||
myrian.vulns -= cost;
|
||||
device.emissionLvl++;
|
||||
return true;
|
||||
},
|
||||
getUpgradeMoveLvlCost: (ctx) => (_id) => {
|
||||
const id = helpers.deviceID(ctx, "device", _id);
|
||||
const device = findDevice(id);
|
||||
if (!device) return -1;
|
||||
if (!("moveLvl" in device)) return -1;
|
||||
return moveLvlCost(device.type, device.moveLvl);
|
||||
},
|
||||
upgradeMoveLvl: (ctx) => (_id) => {
|
||||
const id = helpers.deviceID(ctx, "device", _id);
|
||||
const device = findDevice(id);
|
||||
if (!device) return false;
|
||||
if (!("moveLvl" in device)) return false;
|
||||
const cost = moveLvlCost(device.type, device.moveLvl);
|
||||
if (myrian.vulns < cost) return false;
|
||||
myrian.vulns -= cost;
|
||||
device.moveLvl++;
|
||||
return true;
|
||||
},
|
||||
getUpgradeTransferLvlCost: (ctx) => (_id) => {
|
||||
const id = helpers.deviceID(ctx, "device", _id);
|
||||
const device = findDevice(id);
|
||||
if (!device) return -1;
|
||||
if (!("transferLvl" in device)) return -1;
|
||||
return transferLvlCost(device.type, device.transferLvl);
|
||||
},
|
||||
upgradeTransferLvl: (ctx) => (_id) => {
|
||||
const id = helpers.deviceID(ctx, "device", _id);
|
||||
const device = findDevice(id);
|
||||
if (!device) return false;
|
||||
if (!("transferLvl" in device)) return false;
|
||||
const cost = transferLvlCost(device.type, device.transferLvl);
|
||||
if (myrian.vulns < cost) return false;
|
||||
myrian.vulns -= cost;
|
||||
device.transferLvl++;
|
||||
return true;
|
||||
},
|
||||
getUpgradeReduceLvlCost: (ctx) => (_id) => {
|
||||
const id = helpers.deviceID(ctx, "device", _id);
|
||||
const device = findDevice(id);
|
||||
if (!device) return -1;
|
||||
if (!("reduceLvl" in device)) return -1;
|
||||
return reduceLvlCost(device.type, device.reduceLvl);
|
||||
},
|
||||
upgradeReduceLvl: (ctx) => (_id) => {
|
||||
const id = helpers.deviceID(ctx, "device", _id);
|
||||
const device = findDevice(id);
|
||||
if (!device) return false;
|
||||
if (!("reduceLvl" in device)) return false;
|
||||
const cost = reduceLvlCost(device.type, device.reduceLvl);
|
||||
if (myrian.vulns < cost) return false;
|
||||
myrian.vulns -= cost;
|
||||
device.reduceLvl++;
|
||||
return true;
|
||||
},
|
||||
getUpgradeInstallLvlCost: (ctx) => (_id) => {
|
||||
const id = helpers.deviceID(ctx, "device", _id);
|
||||
const device = findDevice(id);
|
||||
if (!device) return -1;
|
||||
if (!("installLvl" in device)) return -1;
|
||||
return installLvlCost(device.type, device.installLvl);
|
||||
},
|
||||
upgradeInstallLvl: (ctx) => (_id) => {
|
||||
const id = helpers.deviceID(ctx, "device", _id);
|
||||
const device = findDevice(id);
|
||||
if (!device) return false;
|
||||
if (!("installLvl" in device)) return false;
|
||||
const cost = installLvlCost(device.type, device.installLvl);
|
||||
if (myrian.vulns < cost) return false;
|
||||
myrian.vulns -= cost;
|
||||
device.installLvl++;
|
||||
return true;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
82
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
82
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -5248,7 +5248,7 @@ export interface ContainerDevice extends BaseDevice {
|
||||
export interface ISocket extends ContainerDevice {
|
||||
type: DeviceType.ISocket;
|
||||
emitting: Component;
|
||||
cooldown: number;
|
||||
emissionLvl: number;
|
||||
cooldownUntil: number;
|
||||
}
|
||||
|
||||
@ -5396,6 +5396,86 @@ interface Myrian {
|
||||
* @returns cost of upgrading the tier of a device, -1 on failure.
|
||||
*/
|
||||
getUpgradeTierCost(device: DeviceID): number;
|
||||
|
||||
/**
|
||||
* Get the cost of upgrading the emission of a device
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
* @returns cost of upgrading the emission of a device, -1 on failure.
|
||||
*/
|
||||
getUpgradeEmissionLvlCost(device: DeviceID): number;
|
||||
|
||||
/**
|
||||
* Upgrade the emissionLvl of a device
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
* @returns true if the upgrade succeeded, false otherwise.
|
||||
*/
|
||||
upgradeEmissionLvl(device: DeviceID): boolean;
|
||||
|
||||
/**
|
||||
* Get the cost of upgrading the moveLvl of a device
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
* @returns cost of upgrading the moveLvl of a device, -1 on failure.
|
||||
*/
|
||||
getUpgradeMoveLvlCost(device: DeviceID): number;
|
||||
|
||||
/**
|
||||
* Upgrade the moveLvl of a device
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
* @returns true if the upgrade succeeded, false otherwise.
|
||||
*/
|
||||
upgradeMoveLvl(device: DeviceID): boolean;
|
||||
|
||||
/**
|
||||
* Get the cost of upgrading the transferLvl of a device
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
* @returns cost of upgrading the transferLvl of a device, -1 on failure.
|
||||
*/
|
||||
getUpgradeTransferLvlCost(device: DeviceID): number;
|
||||
|
||||
/**
|
||||
* Upgrade the moveLvl of a device
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
* @returns true if the upgrade succeeded, false otherwise.
|
||||
*/
|
||||
upgradeTransferLvl(device: DeviceID): boolean;
|
||||
|
||||
/**
|
||||
* Get the cost of upgrading the reduceLvl of a device
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
* @returns cost of upgrading the reduceLvl of a device, -1 on failure.
|
||||
*/
|
||||
getUpgradeReduceLvlCost(device: DeviceID): number;
|
||||
|
||||
/**
|
||||
* Upgrade the reduceLvl of a device
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
* @returns true if the upgrade succeeded, false otherwise.
|
||||
*/
|
||||
upgradeReduceLvl(device: DeviceID): boolean;
|
||||
|
||||
/**
|
||||
* Get the cost of upgrading the installLvl of a device
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
* @returns cost of upgrading the installLvl of a device, -1 on failure.
|
||||
*/
|
||||
getUpgradeInstallLvlCost(device: DeviceID): number;
|
||||
|
||||
/**
|
||||
* Upgrade the installLvl of a device
|
||||
* @remarks
|
||||
* RAM cost: 0 GB
|
||||
* @returns true if the upgrade succeeded, false otherwise.
|
||||
*/
|
||||
upgradeInstallLvl(device: DeviceID): boolean;
|
||||
}
|
||||
|
||||
/** @public */
|
||||
|
Loading…
Reference in New Issue
Block a user