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:
Snarling
2022-11-09 07:26:26 -05:00
committed by GitHub
parent 6f08aee8f6
commit 8e0e0eaa88
31 changed files with 251 additions and 337 deletions
+6 -6
View File
@@ -1,7 +1,7 @@
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
import { Crime } from "../Crime/Crime";
import { newWorkStats, scaleWorkStats, WorkStats, multWorkStats } from "./WorkStats";
import { Person } from "../PersonObjects/Person";
import { Person as IPerson } from "../ScriptEditor/NetscriptDefinitions";
import { CONSTANTS } from "../Constants";
import { FactionWorkType } from "./data/FactionWorkType";
import {
@@ -40,7 +40,7 @@ export const FactionWorkStats: Record<FactionWorkType, WorkStats> = {
}),
};
export function calculateCrimeWorkStats(person: Person, crime: Crime): WorkStats {
export function calculateCrimeWorkStats(person: IPerson, crime: Crime): WorkStats {
const gains = scaleWorkStats(
multWorkStats(
//Todo: rework crime and workstats interfaces to use the same naming convention for exp values, then we can just make a workStats directly from a crime.
@@ -63,7 +63,7 @@ export function calculateCrimeWorkStats(person: Person, crime: Crime): WorkStats
return gains;
}
export const calculateFactionRep = (person: Person, type: FactionWorkType, favor: number): number => {
export const calculateFactionRep = (person: IPerson, type: FactionWorkType, favor: number): number => {
const repFormulas = {
[FactionWorkType.HACKING]: getHackingWorkRepGain,
[FactionWorkType.FIELD]: getFactionFieldWorkRepGain,
@@ -72,7 +72,7 @@ export const calculateFactionRep = (person: Person, type: FactionWorkType, favor
return repFormulas[type](person, favor);
};
export function calculateFactionExp(person: Person, type: FactionWorkType): WorkStats {
export function calculateFactionExp(person: IPerson, type: FactionWorkType): WorkStats {
return scaleWorkStats(
multWorkStats(FactionWorkStats[type], person.mults),
BitNodeMultipliers.FactionWorkExpGain / gameCPS,
@@ -87,7 +87,7 @@ export function calculateCost(classs: Class, location: Location): number {
return classs.earnings.money * location.costMult * discount;
}
export function calculateClassEarnings(person: Person, type: ClassType, locationName: LocationName): WorkStats {
export function calculateClassEarnings(person: IPerson, type: ClassType, locationName: LocationName): WorkStats {
const hashManager = Player.hashManager;
const classs = Classes[type];
const location = Locations[locationName];
@@ -107,7 +107,7 @@ export function calculateClassEarnings(person: Person, type: ClassType, location
}
export const calculateCompanyWorkStats = (
worker: Person,
worker: IPerson,
company: Company,
companyPosition: CompanyPosition,
favor: number,