mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-19 14:13:48 +01:00
more work on wrapping formulas
This commit is contained in:
parent
324f752d8a
commit
0da2e74d12
@ -9,11 +9,12 @@ import { Settings } from "../Settings/Settings";
|
|||||||
import { CONSTANTS } from "../Constants";
|
import { CONSTANTS } from "../Constants";
|
||||||
|
|
||||||
type ExternalFunction = (...args: any[]) => any;
|
type ExternalFunction = (...args: any[]) => any;
|
||||||
type ExternalAPI = {
|
export type ExternalAPI = {
|
||||||
[string: string]: ExternalAPI | ExternalFunction;
|
[string: string]: ExternalAPI | ExternalFunction;
|
||||||
};
|
};
|
||||||
|
|
||||||
type InternalFunction<F extends (...args: unknown[]) => unknown> = (ctx: NetscriptContext) => F;
|
type InternalFunction<F extends (...args: unknown[]) => unknown> = (ctx: NetscriptContext) => F;
|
||||||
|
|
||||||
export type InternalAPI<API> = {
|
export type InternalAPI<API> = {
|
||||||
[Property in keyof API]: API[Property] extends ExternalFunction
|
[Property in keyof API]: API[Property] extends ExternalFunction
|
||||||
? InternalFunction<API[Property]>
|
? InternalFunction<API[Property]>
|
||||||
|
@ -443,6 +443,53 @@ export const RamCosts: IMap<any> = {
|
|||||||
// Easter egg function
|
// Easter egg function
|
||||||
break: 0,
|
break: 0,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
formulas: {
|
||||||
|
reputation: {
|
||||||
|
calculateFavorToRep: 0,
|
||||||
|
calculateRepToFavor: 0,
|
||||||
|
repFromDonation: 0,
|
||||||
|
},
|
||||||
|
skills: {
|
||||||
|
calculateSkill: 0,
|
||||||
|
calculateExp: 0,
|
||||||
|
},
|
||||||
|
hacking: {
|
||||||
|
hackChance: 0,
|
||||||
|
hackExp: 0,
|
||||||
|
hackPercent: 0,
|
||||||
|
growPercent: 0,
|
||||||
|
hackTime: 0,
|
||||||
|
growTime: 0,
|
||||||
|
weakenTime: 0,
|
||||||
|
},
|
||||||
|
hacknetNodes: {
|
||||||
|
moneyGainRate: 0,
|
||||||
|
levelUpgradeCost: 0,
|
||||||
|
ramUpgradeCost: 0,
|
||||||
|
coreUpgradeCost: 0,
|
||||||
|
hacknetNodeCost: 0,
|
||||||
|
constants: 0,
|
||||||
|
},
|
||||||
|
hacknetServers: {
|
||||||
|
hashGainRate: 0,
|
||||||
|
levelUpgradeCost: 0,
|
||||||
|
ramUpgradeCost: 0,
|
||||||
|
coreUpgradeCost: 0,
|
||||||
|
cacheUpgradeCost: 0,
|
||||||
|
hashUpgradeCost: 0,
|
||||||
|
hacknetServerCost: 0,
|
||||||
|
constants: 0,
|
||||||
|
},
|
||||||
|
gang: {
|
||||||
|
wantedPenalty: 0,
|
||||||
|
respectGain: 0,
|
||||||
|
wantedLevelGain: 0,
|
||||||
|
moneyGain: 0,
|
||||||
|
ascensionPointsGain: 0,
|
||||||
|
ascensionMultiplier: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getRamCost(player: IPlayer, ...args: string[]): number {
|
export function getRamCost(player: IPlayer, ...args: string[]): number {
|
||||||
|
@ -78,6 +78,7 @@ import { IPort } from "./NetscriptPort";
|
|||||||
import {
|
import {
|
||||||
NS as INS,
|
NS as INS,
|
||||||
Singularity as ISingularity,
|
Singularity as ISingularity,
|
||||||
|
Formulas as IFormulas,
|
||||||
Player as INetscriptPlayer,
|
Player as INetscriptPlayer,
|
||||||
Gang as IGang,
|
Gang as IGang,
|
||||||
Bladeburner as IBladeburner,
|
Bladeburner as IBladeburner,
|
||||||
@ -532,8 +533,9 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const extra = NetscriptExtra(Player, workerScript, helper);
|
const extra = NetscriptExtra(Player, workerScript, helper);
|
||||||
const formulas = NetscriptFormulas(Player, workerScript, helper);
|
|
||||||
|
|
||||||
|
const formulas = wrapAPI(helper, {}, workerScript, NetscriptFormulas(Player, helper), "formulas")
|
||||||
|
.formulas as unknown as IFormulas;
|
||||||
const gang = wrapAPI(helper, {}, workerScript, NetscriptGang(Player, workerScript), "gang").gang as unknown as IGang;
|
const gang = wrapAPI(helper, {}, workerScript, NetscriptGang(Player, workerScript), "gang").gang as unknown as IGang;
|
||||||
const sleeve = wrapAPI(helper, {}, workerScript, NetscriptSleeve(Player), "sleeve").sleeve as unknown as ISleeve;
|
const sleeve = wrapAPI(helper, {}, workerScript, NetscriptSleeve(Player), "sleeve").sleeve as unknown as ISleeve;
|
||||||
const hacknet = wrapAPI(helper, {}, workerScript, NetscriptHacknet(Player, workerScript), "hacknet")
|
const hacknet = wrapAPI(helper, {}, workerScript, NetscriptHacknet(Player, workerScript), "hacknet")
|
||||||
|
@ -41,11 +41,7 @@ import { favorToRep as calculateFavorToRep, repToFavor as calculateRepToFavor }
|
|||||||
import { repFromDonation } from "../Faction/formulas/donation";
|
import { repFromDonation } from "../Faction/formulas/donation";
|
||||||
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
|
||||||
|
|
||||||
export function NetscriptFormulas(
|
export function NetscriptFormulas(player: IPlayer, helper: INetscriptHelper): InternalAPI<IFormulas> {
|
||||||
player: IPlayer,
|
|
||||||
workerScript: WorkerScript,
|
|
||||||
helper: INetscriptHelper,
|
|
||||||
): InternalAPI<IFormulas> {
|
|
||||||
const checkFormulasAccess = function (ctx: NetscriptContext): void {
|
const checkFormulasAccess = function (ctx: NetscriptContext): void {
|
||||||
if (!player.hasProgram(Programs.Formulas.name)) {
|
if (!player.hasProgram(Programs.Formulas.name)) {
|
||||||
throw helper.makeRuntimeErrorMsg(`formulas.${ctx.function}`, `Requires Formulas.exe to run.`);
|
throw helper.makeRuntimeErrorMsg(`formulas.${ctx.function}`, `Requires Formulas.exe to run.`);
|
||||||
|
Loading…
Reference in New Issue
Block a user