mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2025-01-20 13:01:27 +01:00
Add renameDevice and modify Rust
This commit is contained in:
parent
e00ea77de8
commit
3f95518891
@ -16,6 +16,7 @@ import {
|
|||||||
} from "@nsdefs";
|
} from "@nsdefs";
|
||||||
import { myrian, myrianSize } from "./Helper";
|
import { myrian, myrianSize } from "./Helper";
|
||||||
import { glitchMult } from "./formulas/glitches";
|
import { glitchMult } from "./formulas/glitches";
|
||||||
|
import { pickOne } from "./utils";
|
||||||
|
|
||||||
export interface Myrian {
|
export interface Myrian {
|
||||||
vulns: number;
|
vulns: number;
|
||||||
@ -135,14 +136,16 @@ export const getTotalGlitchMult = () =>
|
|||||||
return acc * glitchMult(glitch as Glitch, lvl);
|
return acc * glitchMult(glitch as Glitch, lvl);
|
||||||
}, 1);
|
}, 1);
|
||||||
|
|
||||||
const rustStats: (keyof Bus)[] = ["moveLvl", "transferLvl", "reduceLvl", "installLvl", "maxEnergy"];
|
// DO NOT use `Object.keys` on a Rustable because it will return way more than just the rustable stats.
|
||||||
|
const rustStats: (keyof Rustable)[] = ["moveLvl", "transferLvl", "reduceLvl", "installLvl", "maxEnergy"];
|
||||||
|
type Rustable = Pick<Bus, "moveLvl" | "transferLvl" | "reduceLvl" | "installLvl" | "maxEnergy">;
|
||||||
|
|
||||||
export const rustBus = (bus: Bus, rust: number) => {
|
export const rustBus = (bus: Bus, rust: number) => {
|
||||||
const potential = rustStats.filter((stat) => {
|
const rustable = bus as Rustable;
|
||||||
const value = bus[stat];
|
const nonZero = rustStats.filter((stat) => rustable[stat] > 0);
|
||||||
if (typeof value !== "number") return false;
|
const chosen = pickOne(nonZero);
|
||||||
return value > 0;
|
rustable[chosen] = Math.max(0, rustable[chosen] - rust * 0.1);
|
||||||
});
|
|
||||||
const chosen = potential[Math.floor(Math.random() * potential.length)];
|
// cap energy when maxEnergy is reduced
|
||||||
(bus[chosen] as any) = Math.max(0, (bus[chosen] as any) - rust * 0.1) as any;
|
bus.energy = Math.min(bus.energy, bus.maxEnergy);
|
||||||
};
|
};
|
||||||
|
0
src/Myrian/formulas/cost.ts
Normal file
0
src/Myrian/formulas/cost.ts
Normal file
@ -1,10 +1,11 @@
|
|||||||
import { DeviceType } from "@nsdefs";
|
import { DeviceType } from "@nsdefs";
|
||||||
import { myrian } from "../Helper";
|
import { myrian } from "../Helper";
|
||||||
import { componentTiers } from "./components";
|
import { componentTiers } from "./components";
|
||||||
|
import { pickOne } from "../utils";
|
||||||
|
|
||||||
export type FactoryFormulaParams = [number, number, number, number];
|
type FactoryFormulaParams = [number, number, number, number];
|
||||||
|
|
||||||
export const maxContentScale: Record<DeviceType, FactoryFormulaParams> = {
|
const maxContentScale: Record<DeviceType, FactoryFormulaParams> = {
|
||||||
[DeviceType.Bus]: [8, 0.5, 2, 0],
|
[DeviceType.Bus]: [8, 0.5, 2, 0],
|
||||||
[DeviceType.ISocket]: [4, 1, 5, 0],
|
[DeviceType.ISocket]: [4, 1, 5, 0],
|
||||||
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
|
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||||
@ -20,16 +21,9 @@ const exp = (p: FactoryFormulaParams, x: number): number => Math.pow(p[0], p[1]
|
|||||||
export const upgradeMaxContentCost = (type: DeviceType, currentMaxContent: number): number =>
|
export const upgradeMaxContentCost = (type: DeviceType, currentMaxContent: number): number =>
|
||||||
exp(maxContentScale[type], currentMaxContent);
|
exp(maxContentScale[type], currentMaxContent);
|
||||||
|
|
||||||
export const busPrice = (currentBusses: number): number => Math.pow(2, currentBusses + 3);
|
|
||||||
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) => 100000 / (level + 10);
|
|
||||||
|
|
||||||
const countDevices = (type: DeviceType) => myrian.devices.reduce((acc, d) => (d.type === type ? acc + 1 : acc), 0);
|
const countDevices = (type: DeviceType) => myrian.devices.reduce((acc, d) => (d.type === type ? acc + 1 : acc), 0);
|
||||||
|
|
||||||
export const deviceScale: Record<DeviceType, FactoryFormulaParams> = {
|
const deviceScale: Record<DeviceType, FactoryFormulaParams> = {
|
||||||
[DeviceType.Bus]: [4, 0.5, 2, 0],
|
[DeviceType.Bus]: [4, 0.5, 2, 0],
|
||||||
[DeviceType.ISocket]: [2, 1, 4, 0],
|
[DeviceType.ISocket]: [2, 1, 4, 0],
|
||||||
[DeviceType.OSocket]: [4, 1, 3, 0],
|
[DeviceType.OSocket]: [4, 1, 3, 0],
|
||||||
@ -44,12 +38,10 @@ export const deviceCost = (type: DeviceType, count?: number) =>
|
|||||||
|
|
||||||
export const getNextISocketRequest = (tier: number) => {
|
export const getNextISocketRequest = (tier: number) => {
|
||||||
const potential = componentTiers.slice(0, tier + 1).flat();
|
const potential = componentTiers.slice(0, tier + 1).flat();
|
||||||
return new Array(Math.floor(Math.pow(Math.random() * tier, 0.75) + 1))
|
return new Array(Math.floor(Math.pow(Math.random() * tier, 0.75) + 1)).fill(null).map(() => pickOne(potential));
|
||||||
.fill(null)
|
|
||||||
.map(() => potential[Math.floor(Math.random() * potential.length)]);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const tierScale: Record<DeviceType, FactoryFormulaParams> = {
|
const tierScale: Record<DeviceType, FactoryFormulaParams> = {
|
||||||
[DeviceType.Bus]: [Infinity, Infinity, Infinity, Infinity],
|
[DeviceType.Bus]: [Infinity, Infinity, Infinity, Infinity],
|
||||||
[DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity],
|
[DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||||
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
|
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||||
@ -61,7 +53,7 @@ export const tierScale: Record<DeviceType, FactoryFormulaParams> = {
|
|||||||
|
|
||||||
export const tierCost = (type: DeviceType, tier: number) => exp(tierScale[type], tier);
|
export const tierCost = (type: DeviceType, tier: number) => exp(tierScale[type], tier);
|
||||||
|
|
||||||
export const emissionScale: Record<DeviceType, FactoryFormulaParams> = {
|
const emissionScale: Record<DeviceType, FactoryFormulaParams> = {
|
||||||
[DeviceType.Bus]: [Infinity, Infinity, Infinity, Infinity],
|
[DeviceType.Bus]: [Infinity, Infinity, Infinity, Infinity],
|
||||||
[DeviceType.ISocket]: [2, 1, 3, 0],
|
[DeviceType.ISocket]: [2, 1, 3, 0],
|
||||||
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
|
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||||
@ -73,7 +65,7 @@ export const emissionScale: Record<DeviceType, FactoryFormulaParams> = {
|
|||||||
|
|
||||||
export const emissionCost = (type: DeviceType, emissionLvl: number) => exp(emissionScale[type], emissionLvl);
|
export const emissionCost = (type: DeviceType, emissionLvl: number) => exp(emissionScale[type], emissionLvl);
|
||||||
|
|
||||||
export const moveLvlScale: Record<DeviceType, FactoryFormulaParams> = {
|
const moveLvlScale: Record<DeviceType, FactoryFormulaParams> = {
|
||||||
[DeviceType.Bus]: [2, 1, 3, 0],
|
[DeviceType.Bus]: [2, 1, 3, 0],
|
||||||
[DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity],
|
[DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||||
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
|
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||||
@ -85,7 +77,7 @@ export const moveLvlScale: Record<DeviceType, FactoryFormulaParams> = {
|
|||||||
|
|
||||||
export const moveLvlCost = (type: DeviceType, moveLvl: number) => exp(moveLvlScale[type], moveLvl);
|
export const moveLvlCost = (type: DeviceType, moveLvl: number) => exp(moveLvlScale[type], moveLvl);
|
||||||
|
|
||||||
export const transferLvlScale: Record<DeviceType, FactoryFormulaParams> = {
|
const transferLvlScale: Record<DeviceType, FactoryFormulaParams> = {
|
||||||
[DeviceType.Bus]: [2, 1, 3, 0],
|
[DeviceType.Bus]: [2, 1, 3, 0],
|
||||||
[DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity],
|
[DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||||
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
|
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||||
@ -97,7 +89,7 @@ export const transferLvlScale: Record<DeviceType, FactoryFormulaParams> = {
|
|||||||
|
|
||||||
export const transferLvlCost = (type: DeviceType, transferLvl: number) => exp(transferLvlScale[type], transferLvl);
|
export const transferLvlCost = (type: DeviceType, transferLvl: number) => exp(transferLvlScale[type], transferLvl);
|
||||||
|
|
||||||
export const reduceLvlScale: Record<DeviceType, FactoryFormulaParams> = {
|
const reduceLvlScale: Record<DeviceType, FactoryFormulaParams> = {
|
||||||
[DeviceType.Bus]: [2, 1, 3, 0],
|
[DeviceType.Bus]: [2, 1, 3, 0],
|
||||||
[DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity],
|
[DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||||
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
|
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||||
@ -109,7 +101,7 @@ export const reduceLvlScale: Record<DeviceType, FactoryFormulaParams> = {
|
|||||||
|
|
||||||
export const reduceLvlCost = (type: DeviceType, reduceLvl: number) => exp(reduceLvlScale[type], reduceLvl);
|
export const reduceLvlCost = (type: DeviceType, reduceLvl: number) => exp(reduceLvlScale[type], reduceLvl);
|
||||||
|
|
||||||
export const installLvlScale: Record<DeviceType, FactoryFormulaParams> = {
|
const installLvlScale: Record<DeviceType, FactoryFormulaParams> = {
|
||||||
[DeviceType.Bus]: [2, 1, 3, 0],
|
[DeviceType.Bus]: [2, 1, 3, 0],
|
||||||
[DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity],
|
[DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||||
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
|
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||||
@ -121,7 +113,7 @@ export const installLvlScale: Record<DeviceType, FactoryFormulaParams> = {
|
|||||||
|
|
||||||
export const installLvlCost = (type: DeviceType, installLvl: number) => exp(installLvlScale[type], installLvl);
|
export const installLvlCost = (type: DeviceType, installLvl: number) => exp(installLvlScale[type], installLvl);
|
||||||
|
|
||||||
export const maxEnergyScale: Record<DeviceType, FactoryFormulaParams> = {
|
const maxEnergyScale: Record<DeviceType, FactoryFormulaParams> = {
|
||||||
[DeviceType.Bus]: [2, 1, 3, 0],
|
[DeviceType.Bus]: [2, 1, 3, 0],
|
||||||
[DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity],
|
[DeviceType.ISocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||||
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
|
[DeviceType.OSocket]: [Infinity, Infinity, Infinity, Infinity],
|
||||||
@ -132,19 +124,3 @@ export const maxEnergyScale: Record<DeviceType, FactoryFormulaParams> = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const maxEnergyCost = (type: DeviceType, maxEnergy: number) => exp(maxEnergyScale[type], maxEnergy);
|
export const maxEnergyCost = (type: DeviceType, maxEnergy: number) => exp(maxEnergyScale[type], maxEnergy);
|
||||||
|
|
||||||
/**
|
|
||||||
glitches:
|
|
||||||
|
|
||||||
- random walls (higher level more randomly spawning walls, level 0 is no walls)
|
|
||||||
- moving dock & dispensers (higher level move faster, level 0 does not move)
|
|
||||||
- dock complexity (higher level more complex, level 0 is repeating request)
|
|
||||||
- energy consumption (higher level consume more, level 0 is no consumption)
|
|
||||||
- ugrade degradation (hidden tile degrade upgrades, level 0 does not degrade)
|
|
||||||
- move hinderance (speed) (higher level slower, level 0 is no hinderance)
|
|
||||||
- connection hinderance (transfer / charge) (higher level slower, level 0 is immediate transfer speed and charge)
|
|
||||||
- allocation hinderance (craft & build) (higher level slower, level 0 is no hinderance)
|
|
||||||
|
|
||||||
|
|
||||||
special requests like "has red" that increases the reward
|
|
||||||
*/
|
|
||||||
|
5
src/Myrian/formulas/speed.ts
Normal file
5
src/Myrian/formulas/speed.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
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) => 100000 / (level + 10);
|
1
src/Myrian/ideas.txt
Normal file
1
src/Myrian/ideas.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
New device that makes special requests like "has red" | "at least tier 3" | "does not contain blue" that increases the reward.
|
1
src/Myrian/utils.ts
Normal file
1
src/Myrian/utils.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export const pickOne = <T>(arr: T[]): T => arr[Math.floor(Math.random() * arr.length)];
|
@ -31,16 +31,11 @@ import {
|
|||||||
emissionCost,
|
emissionCost,
|
||||||
getNextISocketRequest,
|
getNextISocketRequest,
|
||||||
installLvlCost,
|
installLvlCost,
|
||||||
installSpeed,
|
|
||||||
isocketSpeed,
|
|
||||||
maxEnergyCost,
|
maxEnergyCost,
|
||||||
moveLvlCost,
|
moveLvlCost,
|
||||||
moveSpeed,
|
|
||||||
reduceLvlCost,
|
reduceLvlCost,
|
||||||
reduceSpeed,
|
|
||||||
tierCost,
|
tierCost,
|
||||||
transferLvlCost,
|
transferLvlCost,
|
||||||
transferSpeed,
|
|
||||||
upgradeMaxContentCost,
|
upgradeMaxContentCost,
|
||||||
} from "../Myrian/formulas/formulas";
|
} from "../Myrian/formulas/formulas";
|
||||||
import { recipes } from "../Myrian/formulas/recipes";
|
import { recipes } from "../Myrian/formulas/recipes";
|
||||||
@ -54,6 +49,8 @@ import {
|
|||||||
magnetismLoss,
|
magnetismLoss,
|
||||||
virtualizationMult,
|
virtualizationMult,
|
||||||
} from "../Myrian/formulas/glitches";
|
} from "../Myrian/formulas/glitches";
|
||||||
|
import { pickOne } from "../Myrian/utils";
|
||||||
|
import { installSpeed, isocketSpeed, moveSpeed, reduceSpeed, transferSpeed } from "../Myrian/formulas/speed";
|
||||||
|
|
||||||
export function NetscriptMyrian(): InternalAPI<IMyrian> {
|
export function NetscriptMyrian(): InternalAPI<IMyrian> {
|
||||||
return {
|
return {
|
||||||
@ -70,6 +67,15 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
|
|||||||
},
|
},
|
||||||
getDevices: (__ctx) => () => JSON.parse(JSON.stringify(myrian.devices)),
|
getDevices: (__ctx) => () => JSON.parse(JSON.stringify(myrian.devices)),
|
||||||
getVulns: () => () => myrian.vulns,
|
getVulns: () => () => myrian.vulns,
|
||||||
|
renameDevice: (ctx) => (_id, _name) => {
|
||||||
|
const id = helpers.deviceID(ctx, "id", _id);
|
||||||
|
const name = helpers.string(ctx, "name", _name);
|
||||||
|
const device = findDevice(id);
|
||||||
|
if (!device) return false;
|
||||||
|
if (findDevice(name)) return false;
|
||||||
|
device.name = name;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
moveBus:
|
moveBus:
|
||||||
(ctx) =>
|
(ctx) =>
|
||||||
async (_bus, _coord): Promise<boolean> => {
|
async (_bus, _coord): Promise<boolean> => {
|
||||||
@ -101,7 +107,7 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
|
|||||||
return Promise.resolve(false);
|
return Promise.resolve(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const outOfEnergy = bus.energy === 0 ? 0.5 : 1;
|
const outOfEnergy = bus.energy === 0 ? 0.1 : 1;
|
||||||
|
|
||||||
bus.isBusy = true;
|
bus.isBusy = true;
|
||||||
return helpers
|
return helpers
|
||||||
@ -472,7 +478,7 @@ export function NetscriptMyrian(): InternalAPI<IMyrian> {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DeviceType.ISocket: {
|
case DeviceType.ISocket: {
|
||||||
NewISocket(name, x, y, componentTiers[0][Math.floor(Math.random() * componentTiers[0].length)]);
|
NewISocket(name, x, y, pickOne(componentTiers[0]));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DeviceType.OSocket: {
|
case DeviceType.OSocket: {
|
||||||
|
6
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
6
src/ScriptEditor/NetscriptDefinitions.d.ts
vendored
@ -5409,6 +5409,12 @@ interface Myrian {
|
|||||||
*/
|
*/
|
||||||
uninstallDevice(bus: DeviceID, coord: [number, number]): Promise<boolean>;
|
uninstallDevice(bus: DeviceID, coord: [number, number]): Promise<boolean>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rename a device, no 2 entity can have the same name
|
||||||
|
* @returns true if the rename succeeded, false otherwise.
|
||||||
|
*/
|
||||||
|
renameDevice(device: DeviceID, name: string): boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upgrade the max content of a device
|
* Upgrade the max content of a device
|
||||||
* @remarks
|
* @remarks
|
||||||
|
Loading…
Reference in New Issue
Block a user