mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-26 19:14:32 +02:00
NETSCRIPT: ns.sleeve.getSleeve added. getPlayer and getSleeve can both be used for formulas. (#200)
* BREAKING CHANGE: Removed getSleeveStats and getSleeveInformation because this info is provided by getSleeve in a more usable form. * BREAKING CHANGE: Removed tor, inBladeburner, and hasCorporation fields from ns.getPlayer. Functionality still exists via added functions ns.hasTorRouter, ns.corporation.hasCorporation, and ns.bladeburner.inBladeburner. * Separated ns definitions for Person, Sleeve, and Player interfaces with both Player and Sleeve just extending Person. Added getSleeve, which provides a Sleeve object similar to getPlayer. * Renamed the sleeve ns layer's interface as sleeve lowercase because of name conflict. todo: May move all the ns layers interface names to lowercase for consistency * Added ns.formulas.work.crimeSuccessChance and reworked to allow both sleeve and player calculations. * Removed internal Person.getIntelligenceBonus function which was just a wrapper for calculateIntelligenceBonus. Any use of the former in formulas creates a conflict where ns-provided Person objects throw an error. * Renamed helpers.player to helpers.person for netscript person validation. Reduced number of fields validated due to Person being a smaller interface. * Fixed bug in bladeburner where Player multipliers and int were being used no matter which person was performing the task * Fixed leak of Player.jobs at ns.getPlayer * Person / Player / Sleeve classes now implement the netscript equivalent interfaces. Netscript helper for person no longer asserts that it's a real Person class member, only that it's a Person interface. Functions that use netscript persons have been changed to expect just a person interface to prevent needing this incorrect type assertion.
This commit is contained in:
@@ -21,7 +21,6 @@ import { CONSTANTS } from "../Constants";
|
||||
import { influenceStockThroughServerHack } from "../StockMarket/PlayerInfluencing";
|
||||
import { IPort, NetscriptPort } from "../NetscriptPort";
|
||||
import { NetscriptPorts } from "../NetscriptWorker";
|
||||
import { Person } from "../PersonObjects/Person";
|
||||
import { FormulaGang } from "../Gang/formulas/formulas";
|
||||
import { GangMember } from "../Gang/GangMember";
|
||||
import { GangMemberTask } from "../Gang/GangMemberTask";
|
||||
@@ -29,7 +28,7 @@ import { RunningScript } from "../Script/RunningScript";
|
||||
import { toNative } from "../NetscriptFunctions/toNative";
|
||||
import { ScriptIdentifier } from "./ScriptIdentifier";
|
||||
import { findRunningScript, findRunningScriptByPid } from "../Script/ScriptHelpers";
|
||||
import { RunningScript as IRunningScript } from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { RunningScript as IRunningScript, Person as IPerson } from "../ScriptEditor/NetscriptDefinitions";
|
||||
import { arrayToString } from "../utils/helpers/arrayToString";
|
||||
import { HacknetServer } from "../Hacknet/HacknetServer";
|
||||
import { BaseServer } from "../Server/BaseServer";
|
||||
@@ -53,7 +52,7 @@ export const helpers = {
|
||||
scriptIdentifier,
|
||||
hack,
|
||||
getValidPort,
|
||||
player,
|
||||
person,
|
||||
server,
|
||||
gang,
|
||||
gangMember,
|
||||
@@ -546,27 +545,15 @@ function getValidPort(ctx: NetscriptContext, port: number): IPort {
|
||||
return iport;
|
||||
}
|
||||
|
||||
function player(ctx: NetscriptContext, p: unknown): Person {
|
||||
const fakePlayer = {
|
||||
function person(ctx: NetscriptContext, p: unknown): IPerson {
|
||||
const fakePerson = {
|
||||
hp: undefined,
|
||||
exp: undefined,
|
||||
mults: undefined,
|
||||
numPeopleKilled: undefined,
|
||||
money: undefined,
|
||||
city: undefined,
|
||||
location: undefined,
|
||||
bitNodeN: undefined,
|
||||
totalPlaytime: undefined,
|
||||
playtimeSinceLastAug: undefined,
|
||||
playtimeSinceLastBitnode: undefined,
|
||||
jobs: undefined,
|
||||
factions: undefined,
|
||||
tor: undefined,
|
||||
inBladeburner: undefined,
|
||||
hasCorporation: undefined,
|
||||
entropy: undefined,
|
||||
};
|
||||
if (!roughlyIs(fakePlayer, p)) throw makeRuntimeErrorMsg(ctx, `player should be a Player.`, "TYPE");
|
||||
return p as Person;
|
||||
if (!roughlyIs(fakePerson, p)) throw makeRuntimeErrorMsg(ctx, `person should be a Person.`, "TYPE");
|
||||
return p as IPerson;
|
||||
}
|
||||
|
||||
function server(ctx: NetscriptContext, s: unknown): Server {
|
||||
|
||||
@@ -231,6 +231,7 @@ const gang = {
|
||||
|
||||
// Bladeburner API
|
||||
const bladeburner = {
|
||||
inBladeburner: RamCostConstants.ScriptBladeburnerApiBaseRamCost / 4,
|
||||
getContractNames: RamCostConstants.ScriptBladeburnerApiBaseRamCost / 10,
|
||||
getOperationNames: RamCostConstants.ScriptBladeburnerApiBaseRamCost / 10,
|
||||
getBlackOpNames: RamCostConstants.ScriptBladeburnerApiBaseRamCost / 10,
|
||||
@@ -295,9 +296,8 @@ const sleeve = {
|
||||
setToCompanyWork: RamCostConstants.ScriptSleeveBaseRamCost,
|
||||
setToFactionWork: RamCostConstants.ScriptSleeveBaseRamCost,
|
||||
setToGymWorkout: RamCostConstants.ScriptSleeveBaseRamCost,
|
||||
getSleeveStats: RamCostConstants.ScriptSleeveBaseRamCost,
|
||||
getTask: RamCostConstants.ScriptSleeveBaseRamCost,
|
||||
getInformation: RamCostConstants.ScriptSleeveBaseRamCost,
|
||||
getSleeve: RamCostConstants.ScriptSleeveBaseRamCost,
|
||||
getSleeveAugmentations: RamCostConstants.ScriptSleeveBaseRamCost,
|
||||
getSleevePurchasableAugs: RamCostConstants.ScriptSleeveBaseRamCost,
|
||||
purchaseSleeveAug: RamCostConstants.ScriptSleeveBaseRamCost,
|
||||
@@ -343,6 +343,7 @@ const grafting = {
|
||||
} as const;
|
||||
|
||||
const corporation = {
|
||||
hasCorporation: 0,
|
||||
getMaterialNames: 0,
|
||||
getIndustryTypes: 0,
|
||||
getEmployeePositions: 0,
|
||||
@@ -453,6 +454,7 @@ export const RamCosts: RamCostTree<Omit<NSFull, "args" | "enums">> = {
|
||||
enableLog: 0,
|
||||
isLogEnabled: 0,
|
||||
getScriptLogs: 0,
|
||||
hasTorRouter: 0.05,
|
||||
nuke: RamCostConstants.ScriptPortProgramRamCost,
|
||||
brutessh: RamCostConstants.ScriptPortProgramRamCost,
|
||||
ftpcrack: RamCostConstants.ScriptPortProgramRamCost,
|
||||
@@ -543,15 +545,13 @@ export const RamCosts: RamCostTree<Omit<NSFull, "args" | "enums">> = {
|
||||
bypass: 0,
|
||||
alterReality: 0,
|
||||
rainbow: 0,
|
||||
heart: {
|
||||
// Easter egg function
|
||||
break: 0,
|
||||
},
|
||||
heart: { break: 0 },
|
||||
iKnowWhatImDoing: 0,
|
||||
|
||||
formulas: {
|
||||
mockServer: 0,
|
||||
mockPlayer: 0,
|
||||
mockPerson: 0,
|
||||
reputation: {
|
||||
calculateFavorToRep: 0,
|
||||
calculateRepToFavor: 0,
|
||||
@@ -597,6 +597,7 @@ export const RamCosts: RamCostTree<Omit<NSFull, "args" | "enums">> = {
|
||||
ascensionMultiplier: 0,
|
||||
},
|
||||
work: {
|
||||
crimeSuccessChance: 0,
|
||||
crimeGains: 0,
|
||||
classGains: 0,
|
||||
factionGains: 0,
|
||||
|
||||
Reference in New Issue
Block a user