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
+7 -7
View File
@@ -1,10 +1,10 @@
import { BitNodeMultipliers } from "./BitNode/BitNodeMultipliers";
import { Person } from "./PersonObjects/Person";
import { Person as IPerson } from "./ScriptEditor/NetscriptDefinitions";
import { calculateIntelligenceBonus } from "./PersonObjects/formulas/intelligence";
import { Server } from "./Server/Server";
/** Returns the chance the person has to successfully hack a server */
export function calculateHackingChance(server: Server, person: Person): number {
export function calculateHackingChance(server: Server, person: IPerson): number {
const hackFactor = 1.75;
const difficultyMult = (100 - server.hackDifficulty) / 100;
const skillMult = hackFactor * person.skills.hacking;
@@ -28,7 +28,7 @@ export function calculateHackingChance(server: Server, person: Person): number {
* Returns the amount of hacking experience the person will gain upon
* successfully hacking a server
*/
export function calculateHackingExpGain(server: Server, person: Person): number {
export function calculateHackingExpGain(server: Server, person: IPerson): number {
const baseExpGain = 3;
const diffFactor = 0.3;
if (server.baseDifficulty == null) {
@@ -44,7 +44,7 @@ export function calculateHackingExpGain(server: Server, person: Person): number
* Returns the percentage of money that will be stolen from a server if
* it is successfully hacked (returns the decimal form, not the actual percent value)
*/
export function calculatePercentMoneyHacked(server: Server, person: Person): number {
export function calculatePercentMoneyHacked(server: Server, person: IPerson): number {
// Adjust if needed for balancing. This is the divisor for the final calculation
const balanceFactor = 240;
@@ -63,7 +63,7 @@ export function calculatePercentMoneyHacked(server: Server, person: Person): num
}
/** Returns time it takes to complete a hack on a server, in seconds */
export function calculateHackingTime(server: Server, person: Person): number {
export function calculateHackingTime(server: Server, person: IPerson): number {
const difficultyMult = server.requiredHackingSkill * server.hackDifficulty;
const baseDiff = 500;
@@ -82,14 +82,14 @@ export function calculateHackingTime(server: Server, person: Person): number {
}
/** Returns time it takes to complete a grow operation on a server, in seconds */
export function calculateGrowTime(server: Server, person: Person): number {
export function calculateGrowTime(server: Server, person: IPerson): number {
const growTimeMultiplier = 3.2; // Relative to hacking time. 16/5 = 3.2
return growTimeMultiplier * calculateHackingTime(server, person);
}
/** Returns time it takes to complete a weaken operation on a server, in seconds */
export function calculateWeakenTime(server: Server, person: Person): number {
export function calculateWeakenTime(server: Server, person: IPerson): number {
const weakenTimeMultiplier = 4; // Relative to hacking time
return weakenTimeMultiplier * calculateHackingTime(server, person);