NETSCRIPT: Add ns.formulas.work.companyGains function (#195)

* added ns.formulas.work.companyGains.
* Removed Work/Formulas folder, added Work/Formulas.ts
* CompanyPosition.calculateJobPerformance now takes in a Person instead of taking in a full set of stats, and it takes INT into account.
* formulas.crimeGains takes in a person object.
* Renamed ns Player type to Person.
* added multWorkStats, which multiplies a WorkStats object with a multipliers object.
* Remove unused types in NetscriptDefinitons.d.ts
* reuse formulas code in other parts of game
* getSleeveInformation also returns skills

Co-authored-by: Alexey <alexey.kozhemiakin@gmail.com>
This commit is contained in:
Snarling
2022-11-06 17:27:04 -05:00
committed by GitHub
parent 5205ff2837
commit 9e869bc876
22 changed files with 241 additions and 350 deletions
@@ -2,7 +2,7 @@ import { Generic_fromJSON, Generic_toJSON, IReviverValue, Reviver } from "../../
import { applySleeveGains, Work, WorkType } from "./Work";
import { ClassType } from "../../../Work/ClassWork";
import { LocationName } from "../../../Locations/data/LocationNames";
import { calculateClassEarnings } from "../../../Work/formulas/Class";
import { calculateClassEarnings } from "../../../Work/Formulas";
import { Sleeve } from "../Sleeve";
import { scaleWorkStats, WorkStats } from "../../../Work/WorkStats";
@@ -4,9 +4,11 @@ import { applySleeveGains, Work, WorkType } from "./Work";
import { LocationName } from "../../../Locations/data/LocationNames";
import { Companies } from "../../../Company/Companies";
import { Company } from "../../../Company/Company";
import { calculateCompanyWorkStats } from "../../../Work/formulas/Company";
import { calculateCompanyWorkStats } from "../../../Work/Formulas";
import { WorkStats } from "../../../Work/WorkStats";
import { influenceStockThroughCompanyWork } from "../../../StockMarket/PlayerInfluencing";
import { Player } from "@player";
import { CompanyPositions } from "../../../Company/CompanyPositions";
interface SleeveCompanyWorkParams {
companyName: string;
@@ -30,7 +32,8 @@ export class SleeveCompanyWork extends Work {
}
getGainRates(sleeve: Sleeve): WorkStats {
return calculateCompanyWorkStats(sleeve, this.getCompany());
const company = this.getCompany();
return calculateCompanyWorkStats(sleeve, company, CompanyPositions[Player.jobs[company.name]], company.favor);
}
process(sleeve: Sleeve, cycles: number): number {
@@ -5,10 +5,10 @@ import { applySleeveGains, Work, WorkType } from "./Work";
import { CrimeType } from "../../../utils/WorkType";
import { Crimes } from "../../../Crime/Crimes";
import { Crime } from "../../../Crime/Crime";
import { newWorkStats, scaleWorkStats, WorkStats } from "../../../Work/WorkStats";
import { scaleWorkStats, WorkStats } from "../../../Work/WorkStats";
import { CONSTANTS } from "../../../Constants";
import { BitNodeMultipliers } from "../../../BitNode/BitNodeMultipliers";
import { checkEnum } from "../../../utils/helpers/checkEnum";
import { calculateCrimeWorkStats } from "../../../Work/Formulas";
export const isSleeveCrimeWork = (w: Work | null): w is SleeveCrimeWork => w !== null && w.type === WorkType.CRIME;
@@ -26,17 +26,7 @@ export class SleeveCrimeWork extends Work {
}
getExp(sleeve: Sleeve): WorkStats {
const crime = this.getCrime();
return newWorkStats({
money: crime.money * BitNodeMultipliers.CrimeMoney * sleeve.mults.crime_money,
hackExp: crime.hacking_exp * BitNodeMultipliers.CrimeExpGain * sleeve.mults.hacking_exp,
strExp: crime.strength_exp * BitNodeMultipliers.CrimeExpGain * sleeve.mults.strength_exp,
defExp: crime.defense_exp * BitNodeMultipliers.CrimeExpGain * sleeve.mults.defense_exp,
dexExp: crime.dexterity_exp * BitNodeMultipliers.CrimeExpGain * sleeve.mults.dexterity_exp,
agiExp: crime.agility_exp * BitNodeMultipliers.CrimeExpGain * sleeve.mults.agility_exp,
chaExp: crime.charisma_exp * BitNodeMultipliers.CrimeExpGain * sleeve.mults.charisma_exp,
intExp: crime.intelligence_exp * BitNodeMultipliers.CrimeExpGain,
});
return calculateCrimeWorkStats(sleeve, this.getCrime());
}
cyclesNeeded(): number {
@@ -5,15 +5,9 @@ import { applySleeveGains, Work, WorkType } from "./Work";
import { FactionWorkType } from "../../../Work/data/FactionWorkType";
import { FactionNames } from "../../../Faction/data/FactionNames";
import { Factions } from "../../../Faction/Factions";
import { calculateFactionExp } from "../../../Work/formulas/Faction";
import { calculateFactionExp, calculateFactionRep } from "../../../Work/Formulas";
import { Faction } from "../../../Faction/Faction";
import {
getFactionFieldWorkRepGain,
getFactionSecurityWorkRepGain,
getHackingWorkRepGain,
} from "../../../PersonObjects/formulas/reputation";
import { scaleWorkStats, WorkStats } from "../../../Work/WorkStats";
import { BitNodeMultipliers } from "../../../BitNode/BitNodeMultipliers";
interface SleeveFactionWorkParams {
factionWorkType: FactionWorkType;
@@ -38,17 +32,7 @@ export class SleeveFactionWork extends Work {
}
getReputationRate(sleeve: Sleeve): number {
const faction = this.getFaction();
const repFormulas = {
[FactionWorkType.HACKING]: getHackingWorkRepGain,
[FactionWorkType.FIELD]: getFactionFieldWorkRepGain,
[FactionWorkType.SECURITY]: getFactionSecurityWorkRepGain,
};
return (
repFormulas[this.factionWorkType](sleeve, faction.favor) *
sleeve.shockBonus() *
BitNodeMultipliers.FactionWorkRepGain
);
return calculateFactionRep(sleeve, this.factionWorkType, this.getFaction().favor) * sleeve.shockBonus();
}
getFaction(): Faction {