From 02b07bb33215b2eb5f3ee2bc406112a460682383 Mon Sep 17 00:00:00 2001 From: Staszek Welsh Date: Thu, 2 Jun 2022 22:51:36 +0100 Subject: [PATCH] Fix relevant linter errors and run formatter --- src/Corporation/Actions.ts | 21 +++++++++----- src/Corporation/Employee.ts | 3 +- src/Corporation/OfficeSpace.ts | 20 +++++++------ src/Corporation/Product.ts | 36 ++++++++++++++---------- src/Corporation/ui/Industry.tsx | 2 +- src/Corporation/ui/IndustryOffice.tsx | 37 +++++++++++++------------ src/Corporation/ui/IndustryOverview.tsx | 23 ++++++++------- src/NetscriptFunctions.ts | 2 +- src/NetscriptFunctions/Corporation.ts | 9 ++---- 9 files changed, 84 insertions(+), 69 deletions(-) diff --git a/src/Corporation/Actions.ts b/src/Corporation/Actions.ts index 2492ac999..22eccc181 100644 --- a/src/Corporation/Actions.ts +++ b/src/Corporation/Actions.ts @@ -13,7 +13,6 @@ import { CorporationUnlockUpgrade } from "./data/CorporationUnlockUpgrades"; import { CorporationUpgrade } from "./data/CorporationUpgrades"; import { Cities } from "../Locations/Cities"; import { EmployeePositions } from "./EmployeePositions"; -import { Employee } from "./Employee"; import { ResearchMap } from "./ResearchMap"; import { isRelevantMaterial } from "./ui/Helpers"; @@ -304,7 +303,7 @@ export function BuyBackShares(corporation: ICorporation, player: IPlayer, numSha } export function AssignJob(office: OfficeSpace, employeeName: string, job: string): void { - const employee = office.employees.find(e => e.name === employeeName); + const employee = office.employees.find((e) => e.name === employeeName); if (!employee) throw new Error(`Could not find employee '${name}'.`); if (!Object.values(EmployeePositions).includes(job)) throw new Error(`'${job}' is not a valid job.`); @@ -314,7 +313,7 @@ export function AssignJob(office: OfficeSpace, employeeName: string, job: string export function AutoAssignJob(office: OfficeSpace, job: string, count: number): boolean { if (!Object.values(EmployeePositions).includes(job)) throw new Error(`'${job}' is not a valid job.`); - + return office.autoAssignJob(job, count); } @@ -334,9 +333,13 @@ export function UpgradeOfficeSize(corp: ICorporation, office: OfficeSpace, size: export function BuyCoffee(corp: ICorporation, office: OfficeSpace): boolean { const cost = office.getCoffeeCost(); - if (corp.funds < cost) { return false; } + if (corp.funds < cost) { + return false; + } - if (!office.setCoffee()) { return false; } + if (!office.setCoffee()) { + return false; + } corp.funds -= cost; return true; @@ -345,9 +348,13 @@ export function BuyCoffee(corp: ICorporation, office: OfficeSpace): boolean { export function ThrowParty(corp: ICorporation, office: OfficeSpace, costPerEmployee: number): number { const mult = 1 + costPerEmployee / 10e6; const cost = costPerEmployee * office.employees.length; - if (corp.funds < cost) { return 0; } + if (corp.funds < cost) { + return 0; + } - if (!office.setParty(mult)) { return 0; } + if (!office.setParty(mult)) { + return 0; + } corp.funds -= cost; return mult; diff --git a/src/Corporation/Employee.ts b/src/Corporation/Employee.ts index 3d7db353d..bed72a99c 100644 --- a/src/Corporation/Employee.ts +++ b/src/Corporation/Employee.ts @@ -3,7 +3,6 @@ import { getRandomInt } from "../utils/helpers/getRandomInt"; import { Generic_fromJSON, Generic_toJSON, Reviver } from "../utils/JSONReviver"; import { EmployeePositions } from "./EmployeePositions"; import { ICorporation } from "./ICorporation"; -import { OfficeSpace } from "./OfficeSpace"; import { IIndustry } from "./IIndustry"; interface IParams { @@ -57,7 +56,7 @@ export class Employee { } //Returns the amount the employee needs to be paid - process(marketCycles = 1, office: OfficeSpace): number { + process(marketCycles = 1): number { const gain = 0.003 * marketCycles; const det = gain * Math.random(); this.exp += gain; diff --git a/src/Corporation/OfficeSpace.ts b/src/Corporation/OfficeSpace.ts index 7f662a769..63412ee61 100644 --- a/src/Corporation/OfficeSpace.ts +++ b/src/Corporation/OfficeSpace.ts @@ -25,11 +25,11 @@ export class OfficeSpace { maxMor = 100; autoCoffee = false; - autoParty = false; + autoParty = false; coffeeMult = 0; - partyMult = 0; + partyMult = 0; coffeeEmployees = 0; - partyEmployees = 0; + partyEmployees = 0; employees: Employee[] = []; employeeProd: { [key: string]: number } = { @@ -78,7 +78,9 @@ export class OfficeSpace { } // Update employee jobs and job counts - for (const employee of this.employees) { employee.pos = employee.nextPos; } + for (const employee of this.employees) { + employee.pos = employee.nextPos; + } this.calculateTotalEmployees(); this.calculateNextEmployees(); @@ -113,13 +115,13 @@ export class OfficeSpace { let totalSalary = 0; for (const employee of this.employees) { - const salary = employee.process(marketCycles, this); + const salary = employee.process(marketCycles); totalSalary += salary; if (this.autoCoffee) { employee.ene = this.maxEne; } else if (this.coffeeMult > 1) { - const mult = 1 + (this.coffeeMult - 1) * this.employees.length / this.coffeeEmployees; + const mult = 1 + ((this.coffeeMult - 1) * this.employees.length) / this.coffeeEmployees; employee.ene *= mult; } else { employee.ene *= perfMult; @@ -129,7 +131,7 @@ export class OfficeSpace { employee.mor = this.maxMor; employee.hap = this.maxHap; } else if (this.partyMult > 1) { - const mult = 1 + (this.partyMult - 1) * this.employees.length / this.partyEmployees; + const mult = 1 + ((this.partyMult - 1) * this.employees.length) / this.partyEmployees; employee.mor *= mult; employee.hap *= mult; } else { @@ -143,9 +145,9 @@ export class OfficeSpace { } this.coffeeMult = 0; - this.partyMult = 0; + this.partyMult = 0; this.coffeeEmployees = 0; - this.partyEmployees = 0; + this.partyEmployees = 0; this.calculateEmployeeProductivity(corporation, industry); return totalSalary; diff --git a/src/Corporation/Product.ts b/src/Corporation/Product.ts index b674dba77..9917a276a 100644 --- a/src/Corporation/Product.ts +++ b/src/Corporation/Product.ts @@ -128,24 +128,30 @@ export class Product { // Make progress on this product based on current employee productivity createProduct(marketCycles: number, employeeProd: typeof this["creationProd"]): void { - if (this.fin) { return; } + if (this.fin) { + return; + } // Designing/Creating a Product is based mostly off Engineers - const opProd = employeeProd[EmployeePositions.Operations]; + const opProd = employeeProd[EmployeePositions.Operations]; const engrProd = employeeProd[EmployeePositions.Engineer]; const mgmtProd = employeeProd[EmployeePositions.Management]; - const total = opProd + engrProd + mgmtProd; - if (total <= 0) { return; } + const total = opProd + engrProd + mgmtProd; + if (total <= 0) { + return; + } // Management is a multiplier for the production from Engineers const mgmtFactor = 1 + mgmtProd / (1.2 * total); - const prodMult = (Math.pow(engrProd, 0.34) + Math.pow(opProd, 0.2)) * mgmtFactor; - const progress = Math.min(marketCycles * 0.01 * prodMult, 100 - this.prog); - if (progress <= 0) { return; } + const prodMult = (Math.pow(engrProd, 0.34) + Math.pow(opProd, 0.2)) * mgmtFactor; + const progress = Math.min(marketCycles * 0.01 * prodMult, 100 - this.prog); + if (progress <= 0) { + return; + } this.prog += progress; for (const pos of Object.keys(employeeProd)) { - this.creationProd[pos] += employeeProd[pos] * progress / 100; + this.creationProd[pos] += (employeeProd[pos] * progress) / 100; } } @@ -155,16 +161,16 @@ export class Product { // Calculate properties const totalProd = Object.values(this.creationProd).reduce((p, q) => p + q); - const engrRatio = this.creationProd[EmployeePositions.Engineer] / totalProd; + const engrRatio = this.creationProd[EmployeePositions.Engineer] / totalProd; const mgmtRatio = this.creationProd[EmployeePositions.Management] / totalProd; - const rndRatio = this.creationProd[EmployeePositions.RandD] / totalProd; - const opsRatio = this.creationProd[EmployeePositions.Operations] / totalProd; - const busRatio = this.creationProd[EmployeePositions.Business] / totalProd; + const rndRatio = this.creationProd[EmployeePositions.RandD] / totalProd; + const opsRatio = this.creationProd[EmployeePositions.Operations] / totalProd; + const busRatio = this.creationProd[EmployeePositions.Business] / totalProd; - const designMult = 1 + Math.pow(this.designCost, 0.1) / 100; + const designMult = 1 + Math.pow(this.designCost, 0.1) / 100; const balanceMult = 1.2 * engrRatio + 0.9 * mgmtRatio + 1.3 * rndRatio + 1.5 * opsRatio + busRatio; - const sciMult = 1 + Math.pow(industry.sciResearch.qty, industry.sciFac) / 800; - const totalMult = balanceMult * designMult * sciMult; + const sciMult = 1 + Math.pow(industry.sciResearch.qty, industry.sciFac) / 800; + const totalMult = balanceMult * designMult * sciMult; this.qlt = totalMult * diff --git a/src/Corporation/ui/Industry.tsx b/src/Corporation/ui/Industry.tsx index 9a5f65eb1..9c1fafadf 100644 --- a/src/Corporation/ui/Industry.tsx +++ b/src/Corporation/ui/Industry.tsx @@ -25,7 +25,7 @@ export function Industry(props: IProps): React.ReactElement { return ( - + diff --git a/src/Corporation/ui/IndustryOffice.tsx b/src/Corporation/ui/IndustryOffice.tsx index ae29985bb..f7b28d114 100644 --- a/src/Corporation/ui/IndustryOffice.tsx +++ b/src/Corporation/ui/IndustryOffice.tsx @@ -36,14 +36,6 @@ interface IProps { rerender: () => void; } -function countEmployee(employees: Employee[], job: string): number { - let n = 0; - for (let i = 0; i < employees.length; ++i) { - if (employees[i].pos === job) n++; - } - return n; -} - interface ISwitchProps { manualMode: boolean; switchMode: (f: (b: boolean) => boolean) => void; @@ -181,7 +173,7 @@ interface IAutoAssignProps { rerender: () => void; } -function EmployeeCount(props: { num: number, next: number }): React.ReactElement { +function EmployeeCount(props: { num: number; next: number }): React.ReactElement { return ( {props.num === props.next ? null : props.num} @@ -192,9 +184,6 @@ function EmployeeCount(props: { num: number, next: number }): React.ReactElement } function AutoAssignJob(props: IAutoAssignProps): React.ReactElement { - const corp = useCorporation(); - const division = useDivision(); - const currJob = props.office.employeeJobs[props.job]; const nextJob = props.office.employeeNextJobs[props.job]; const nextUna = props.office.employeeNextJobs[EmployeePositions.Unassigned]; @@ -319,9 +308,9 @@ function AutoManagement(props: IProps): React.ReactElement { - The base amount of material this office can produce. Does not include production multipliers - from upgrades and materials. This value is based off the productivity of your Operations, - Engineering, and Management employees + The base amount of material this office can produce. Does not include production multipliers from + upgrades and materials. This value is based off the productivity of your Operations, Engineering, + and Management employees } > @@ -473,8 +462,17 @@ export function IndustryOffice(props: IProps): React.ReactElement { title={Throw an office party to increase your employee's morale and happiness} > - @@ -487,7 +485,10 @@ export function IndustryOffice(props: IProps): React.ReactElement { title={Throw an office party to increase your employee's morale and happiness} > - diff --git a/src/Corporation/ui/IndustryOverview.tsx b/src/Corporation/ui/IndustryOverview.tsx index 4682097c3..337e52d5b 100644 --- a/src/Corporation/ui/IndustryOverview.tsx +++ b/src/Corporation/ui/IndustryOverview.tsx @@ -2,7 +2,6 @@ // (top-left panel in the Industry UI) import React, { useState } from "react"; -import { OfficeSpace } from "../OfficeSpace"; import { Industries } from "../IndustryData"; import { HireAdVert } from "../Actions"; import { numeralWrapper } from "../../ui/numeralFormat"; @@ -89,8 +88,6 @@ function MakeProductButton(): React.ReactElement { } interface IProps { - currentCity: string; - office: OfficeSpace; rerender: () => void; } @@ -218,14 +215,20 @@ export function IndustryOverview(props: IProps): React.ReactElement { - Hire AdVert.Inc to advertise your company. Each level of - this upgrade grants your company a static increase of 3 and 1 to its awareness and - popularity, respectively. It will then increase your company's awareness by 1%, and its popularity - by a random percentage between 1% and 3%. These effects are increased by other upgrades - that increase the power of your advertising. + Hire AdVert.Inc to advertise your company. Each level of this upgrade grants your company a static + increase of 3 and 1 to its awareness and popularity, respectively. It will then increase your company's + awareness by 1%, and its popularity by a random percentage between 1% and 3%. These effects are increased + by other upgrades that increase the power of your advertising. - }> - diff --git a/src/NetscriptFunctions.ts b/src/NetscriptFunctions.ts index 02d3a74ba..e4ced14c8 100644 --- a/src/NetscriptFunctions.ts +++ b/src/NetscriptFunctions.ts @@ -531,7 +531,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS { bladeburner: NetscriptBladeburner(Player, workerScript), codingcontract: NetscriptCodingContract(Player, workerScript), sleeve: NetscriptSleeve(Player), - corporation: NetscriptCorporation(Player, workerScript), + corporation: NetscriptCorporation(Player), stanek: NetscriptStanek(Player, workerScript, helper), infiltration: NetscriptInfiltration(Player), ui: NetscriptUserInterface(), diff --git a/src/NetscriptFunctions/Corporation.ts b/src/NetscriptFunctions/Corporation.ts index 212b7a3ff..fb34437f4 100644 --- a/src/NetscriptFunctions/Corporation.ts +++ b/src/NetscriptFunctions/Corporation.ts @@ -1,6 +1,4 @@ -import { WorkerScript } from "../Netscript/WorkerScript"; import { IPlayer } from "../PersonObjects/IPlayer"; -import { netscriptDelay } from "../NetscriptEvaluator"; import { OfficeSpace } from "../Corporation/OfficeSpace"; import { Employee } from "../Corporation/Employee"; @@ -60,7 +58,6 @@ import { import { CorporationUnlockUpgrades } from "../Corporation/data/CorporationUnlockUpgrades"; import { CorporationUpgrades } from "../Corporation/data/CorporationUpgrades"; import { EmployeePositions } from "../Corporation/EmployeePositions"; -import { calculateIntelligenceBonus } from "../PersonObjects/formulas/intelligence"; import { Industry } from "../Corporation/Industry"; import { IndustryResearchTrees, IndustryStartingCosts } from "../Corporation/IndustryData"; import { CorporationConstants } from "../Corporation/data/Constants"; @@ -69,7 +66,7 @@ import { Factions } from "../Faction/Factions"; import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers"; import { InternalAPI, NetscriptContext } from "src/Netscript/APIWrapper"; -export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript): InternalAPI { +export function NetscriptCorporation(player: IPlayer): InternalAPI { function createCorporation(corporationName: string, selfFund = true): boolean { if (!player.canAccessCorporation() || player.hasCorporation()) return false; if (!corporationName) return false; @@ -257,7 +254,7 @@ export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript function getMaterial(divisionName: string, cityName: string, materialName: string): Material { const warehouse = getWarehouse(divisionName, cityName); - const matName = (materialName ).replace(/ /g, ""); + const matName = materialName.replace(/ /g, ""); const material = warehouse.materials[matName]; if (material === undefined) throw new Error(`Invalid material name: '${materialName}'`); return material; @@ -780,7 +777,7 @@ export function NetscriptCorporation(player: IPlayer, workerScript: WorkerScript const corporation = getCorporation(); const office = getOffice(divisionName, cityName); - return ThrowParty(corporation, office, costPerEmployee) + return ThrowParty(corporation, office, costPerEmployee); }, buyCoffee: (ctx: NetscriptContext) =>