more work on wrapping formulas

This commit is contained in:
Olivier Gagnon 2022-05-24 17:51:48 -04:00
parent 324f752d8a
commit 0da2e74d12
4 changed files with 53 additions and 7 deletions

@ -9,11 +9,12 @@ import { Settings } from "../Settings/Settings";
import { CONSTANTS } from "../Constants";
type ExternalFunction = (...args: any[]) => any;
type ExternalAPI = {
export type ExternalAPI = {
[string: string]: ExternalAPI | ExternalFunction;
};
type InternalFunction<F extends (...args: unknown[]) => unknown> = (ctx: NetscriptContext) => F;
export type InternalAPI<API> = {
[Property in keyof API]: API[Property] extends ExternalFunction
? InternalFunction<API[Property]>

@ -443,6 +443,53 @@ export const RamCosts: IMap<any> = {
// Easter egg function
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 {

@ -78,6 +78,7 @@ import { IPort } from "./NetscriptPort";
import {
NS as INS,
Singularity as ISingularity,
Formulas as IFormulas,
Player as INetscriptPlayer,
Gang as IGang,
Bladeburner as IBladeburner,
@ -532,8 +533,9 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
};
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 sleeve = wrapAPI(helper, {}, workerScript, NetscriptSleeve(Player), "sleeve").sleeve as unknown as ISleeve;
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 { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
export function NetscriptFormulas(
player: IPlayer,
workerScript: WorkerScript,
helper: INetscriptHelper,
): InternalAPI<IFormulas> {
export function NetscriptFormulas(player: IPlayer, helper: INetscriptHelper): InternalAPI<IFormulas> {
const checkFormulasAccess = function (ctx: NetscriptContext): void {
if (!player.hasProgram(Programs.Formulas.name)) {
throw helper.makeRuntimeErrorMsg(`formulas.${ctx.function}`, `Requires Formulas.exe to run.`);