Refactor for ... in loops

This commit is contained in:
nickofolas 2022-01-15 18:45:03 -06:00
parent d5c3d89613
commit ab841f7530
54 changed files with 128 additions and 130 deletions

@ -22,12 +22,12 @@ export function loadGlobalAliases(saveString: string): void {
// Prints all aliases to terminal
export function printAliases(): void {
for (const name in Aliases) {
for (const name of Object.keys(Aliases)) {
if (Aliases.hasOwnProperty(name)) {
Terminal.print("alias " + name + "=" + Aliases[name]);
}
}
for (const name in GlobalAliases) {
for (const name of Object.keys(GlobalAliases)) {
if (GlobalAliases.hasOwnProperty(name)) {
Terminal.print("global alias " + name + "=" + GlobalAliases[name]);
}

@ -526,7 +526,7 @@ export class Augmentation {
// Adds this Augmentation to all Factions
addToAllFactions(): void {
for (const fac in Factions) {
for (const fac of Object.keys(Factions)) {
if (Factions.hasOwnProperty(fac)) {
const facObj: Faction | null = Factions[fac];
if (facObj == null) {

@ -112,7 +112,7 @@ function getRandomBonus(): any {
}
function initAugmentations(): void {
for (const name in Factions) {
for (const name of Object.keys(Factions)) {
if (Factions.hasOwnProperty(name)) {
Factions[name].augmentations = [];
}
@ -2498,7 +2498,7 @@ function initAugmentations(): void {
CONSTANTS.MultipleAugMultiplier * [1, 0.96, 0.94, 0.93][SourceFileFlags[11]],
Player.queuedAugmentations.length,
);
for (const name in Augmentations) {
for (const name of Object.keys(Augmentations)) {
if (Augmentations.hasOwnProperty(name)) {
Augmentations[name].baseCost *= mult;
}
@ -2525,7 +2525,7 @@ function applyAugmentation(aug: IPlayerOwnedAugmentation, reapply = false): void
const augObj = Augmentations[aug.name];
// Apply multipliers
for (const mult in augObj.mults) {
for (const mult of Object.keys(augObj.mults)) {
const v = Player.getMult(mult) * augObj.mults[mult];
Player.setMult(mult, v);
}

@ -17,7 +17,7 @@ function calculateAugmentedStats(): any {
const augP: any = {};
for (const aug of Player.queuedAugmentations) {
const augObj = Augmentations[aug.name];
for (const mult in augObj.mults) {
for (const mult of Object.keys(augObj.mults)) {
const v = augP[mult] ? augP[mult] : 1;
augP[mult] = v * augObj.mults[mult];
}

@ -578,7 +578,7 @@ export function initBitNodeMultipliers(p: IPlayer): void {
if (p.bitNodeN == null) {
p.bitNodeN = 1;
}
for (const mult in BitNodeMultipliers) {
for (const mult of Object.keys(BitNodeMultipliers)) {
if (BitNodeMultipliers.hasOwnProperty(mult)) {
BitNodeMultipliers[mult] = 1;
}

@ -117,7 +117,7 @@ export class Action implements IAction {
// Check to make sure weights are summed properly
let sum = 0;
for (const weight in this.weights) {
for (const weight of Object.keys(this.weights)) {
if (this.weights.hasOwnProperty(weight)) {
sum += this.weights[weight];
}
@ -131,7 +131,7 @@ export class Action implements IAction {
);
}
for (const decay in this.decays) {
for (const decay of Object.keys(this.decays)) {
if (this.decays.hasOwnProperty(decay)) {
if (this.decays[decay] > 1) {
throw new Error(
@ -240,7 +240,7 @@ export class Action implements IAction {
}
let difficulty = this.getDifficulty();
let competence = 0;
for (const stat in this.weights) {
for (const stat of Object.keys(this.weights)) {
if (this.weights.hasOwnProperty(stat)) {
const playerStatLvl = Player.queryStatFromString(stat);
const key = "eff" + stat.charAt(0).toUpperCase() + stat.slice(1);

@ -135,7 +135,7 @@ export class Bladeburner implements IBladeburner {
// Can't start a BlackOp if you haven't done the one before it
const blackops = [];
for (const nm in BlackOperations) {
for (const nm of Object.keys(BlackOperations)) {
if (BlackOperations.hasOwnProperty(nm)) {
blackops.push(nm);
}
@ -1074,7 +1074,7 @@ export class Bladeburner implements IBladeburner {
updateSkillMultipliers(): void {
this.resetSkillMultipliers();
for (const skillName in this.skills) {
for (const skillName of Object.keys(this.skills)) {
if (this.skills.hasOwnProperty(skillName)) {
const skill = Skills[skillName];
if (skill == null) {

@ -12,7 +12,7 @@ interface IProps {
export function BlackOpList(props: IProps): React.ReactElement {
let blackops: BlackOperation[] = [];
for (const blackopName in BlackOperations) {
for (const blackopName of Object.keys(BlackOperations)) {
if (BlackOperations.hasOwnProperty(blackopName)) {
blackops.push(BlackOperations[blackopName]);
}

@ -12,7 +12,7 @@ interface IProps {
export function GeneralActionList(props: IProps): React.ReactElement {
const actions: Action[] = [];
for (const name in GeneralActions) {
for (const name of Object.keys(GeneralActions)) {
if (GeneralActions.hasOwnProperty(name)) {
actions.push(GeneralActions[name]);
}

@ -157,7 +157,7 @@ export function SlotMachine(props: IProps): React.ReactElement {
function step(): void {
let stoppedOne = false;
const copy = index.slice();
for (const i in copy) {
for (let i = 0; i < copy.length; i++) {
if (copy[i] === locks[i] && !stoppedOne) continue;
copy[i] = (copy[i] + 1) % symbols.length;
stoppedOne = true;

@ -26,7 +26,7 @@ export function initCompanies(): void {
});
// Reset data
for (const companyName in Companies) {
for (const companyName of Object.keys(Companies)) {
const company = Companies[companyName];
const oldCompany = oldCompanies[companyName];
if (!(oldCompany instanceof Company)) {

@ -307,7 +307,7 @@ export class Corporation {
if (upgN === 1) {
for (let i = 0; i < this.divisions.length; ++i) {
const industry = this.divisions[i];
for (const city in industry.warehouses) {
for (const city of Object.keys(industry.warehouses)) {
const warehouse = industry.warehouses[city];
if (warehouse === 0) continue;
if (industry.warehouses.hasOwnProperty(city) && warehouse instanceof Warehouse) {

@ -378,7 +378,7 @@ export class Industry implements IIndustry {
updateWarehouseSizeUsed(warehouse: Warehouse): void {
warehouse.updateMaterialSizeUsed();
for (const prodName in this.products) {
for (const prodName of Object.keys(this.products)) {
if (this.products.hasOwnProperty(prodName)) {
const prod = this.products[prodName];
if (prod === undefined) continue;
@ -414,7 +414,7 @@ export class Industry implements IIndustry {
// Process offices (and the employees in them)
let employeeSalary = 0;
for (const officeLoc in this.offices) {
for (const officeLoc of Object.keys(this.offices)) {
const office = this.offices[officeLoc];
if (office === 0) continue;
if (office instanceof OfficeSpace) {
@ -470,7 +470,7 @@ export class Industry implements IIndustry {
if (this.warehouses[CorporationConstants.Cities[i]] instanceof Warehouse) {
const wh = this.warehouses[CorporationConstants.Cities[i]];
if (wh === 0) continue;
for (const name in reqMats) {
for (const name of Object.keys(reqMats)) {
if (reqMats.hasOwnProperty(name)) {
wh.materials[name].processMarket();
}
@ -493,7 +493,7 @@ export class Industry implements IIndustry {
// Process change in demand and competition for this industry's products
processProductMarket(marketCycles = 1): void {
// Demand gradually decreases, and competition gradually increases
for (const name in this.products) {
for (const name of Object.keys(this.products)) {
if (this.products.hasOwnProperty(name)) {
const product = this.products[name];
if (product === undefined) continue;
@ -531,7 +531,7 @@ export class Industry implements IIndustry {
}
const warehouse = this.warehouses[city];
if (warehouse === 0) continue;
for (const matName in warehouse.materials) {
for (const matName of Object.keys(warehouse.materials)) {
if (warehouse.materials.hasOwnProperty(matName)) {
const mat = warehouse.materials[matName];
mat.imp = 0;
@ -552,7 +552,7 @@ export class Industry implements IIndustry {
switch (this.state) {
case "PURCHASE": {
/* Process purchase of materials */
for (const matName in warehouse.materials) {
for (const matName of Object.keys(warehouse.materials)) {
if (!warehouse.materials.hasOwnProperty(matName)) continue;
const mat = warehouse.materials[matName];
let buyAmt = 0;
@ -574,7 +574,7 @@ export class Industry implements IIndustry {
// smart supply
const smartBuy: { [key: string]: number | undefined } = {};
for (const matName in warehouse.materials) {
for (const matName of Object.keys(warehouse.materials)) {
if (!warehouse.materials.hasOwnProperty(matName)) continue;
if (!warehouse.smartSupplyEnabled || !Object.keys(this.reqMats).includes(matName)) continue;
const mat = warehouse.materials[matName];
@ -591,7 +591,7 @@ export class Industry implements IIndustry {
// Find which material were trying to create the least amount of product with.
let worseAmt = 1e99;
for (const matName in smartBuy) {
for (const matName of Object.keys(smartBuy)) {
const buyAmt = smartBuy[matName];
if (buyAmt === undefined) throw new Error(`Somehow smartbuy matname is undefined`);
const reqMat = this.reqMats[matName];
@ -601,7 +601,7 @@ export class Industry implements IIndustry {
}
// Align all the materials to the smallest amount.
for (const matName in smartBuy) {
for (const matName of Object.keys(smartBuy)) {
const reqMat = this.reqMats[matName];
if (reqMat === undefined) throw new Error(`reqMat "${matName}" is undefined`);
smartBuy[matName] = worseAmt * reqMat;
@ -609,7 +609,7 @@ export class Industry implements IIndustry {
// Calculate the total size of all things were trying to buy
let totalSize = 0;
for (const matName in smartBuy) {
for (const matName of Object.keys(smartBuy)) {
const buyAmt = smartBuy[matName];
if (buyAmt === undefined) throw new Error(`Somehow smartbuy matname is undefined`);
totalSize += buyAmt * MaterialSizes[matName];
@ -618,7 +618,7 @@ export class Industry implements IIndustry {
// Shrink to the size of available space.
const freeSpace = warehouse.size - warehouse.sizeUsed;
if (totalSize > freeSpace) {
for (const matName in smartBuy) {
for (const matName of Object.keys(smartBuy)) {
const buyAmt = smartBuy[matName];
if (buyAmt === undefined) throw new Error(`Somehow smartbuy matname is undefined`);
smartBuy[matName] = Math.floor((buyAmt * freeSpace) / totalSize);
@ -626,7 +626,7 @@ export class Industry implements IIndustry {
}
// Use the materials already in the warehouse if the option is on.
for (const matName in smartBuy) {
for (const matName of Object.keys(smartBuy)) {
if (!warehouse.smartSupplyUseLeftovers[matName]) continue;
const mat = warehouse.materials[matName];
const buyAmt = smartBuy[matName];
@ -635,7 +635,7 @@ export class Industry implements IIndustry {
}
// buy them
for (const matName in smartBuy) {
for (const matName of Object.keys(smartBuy)) {
const mat = warehouse.materials[matName];
const buyAmt = smartBuy[matName];
if (buyAmt === undefined) throw new Error(`Somehow smartbuy matname is undefined`);
@ -672,7 +672,7 @@ export class Industry implements IIndustry {
for (let tmp = 0; tmp < this.prodMats.length; ++tmp) {
totalMatSize += MaterialSizes[this.prodMats[tmp]];
}
for (const reqMatName in this.reqMats) {
for (const reqMatName of Object.keys(this.reqMats)) {
const normQty = this.reqMats[reqMatName];
if (normQty === undefined) continue;
totalMatSize -= MaterialSizes[reqMatName] * normQty;
@ -692,7 +692,7 @@ export class Industry implements IIndustry {
// Make sure we have enough resource to make our materials
let producableFrac = 1;
for (const reqMatName in this.reqMats) {
for (const reqMatName of Object.keys(this.reqMats)) {
if (this.reqMats.hasOwnProperty(reqMatName)) {
const reqMat = this.reqMats[reqMatName];
if (reqMat === undefined) continue;
@ -709,7 +709,7 @@ export class Industry implements IIndustry {
// Make our materials if they are producable
if (producableFrac > 0 && prod > 0) {
for (const reqMatName in this.reqMats) {
for (const reqMatName of Object.keys(this.reqMats)) {
const reqMat = this.reqMats[reqMatName];
if (reqMat === undefined) continue;
const reqMatQtyNeeded = reqMat * prod * producableFrac;
@ -726,7 +726,7 @@ export class Industry implements IIndustry {
Math.pow(warehouse.materials["AICores"].qty, this.aiFac) / 10e3;
}
} else {
for (const reqMatName in this.reqMats) {
for (const reqMatName of Object.keys(this.reqMats)) {
if (this.reqMats.hasOwnProperty(reqMatName)) {
warehouse.materials[reqMatName].prd = 0;
}
@ -742,7 +742,7 @@ export class Industry implements IIndustry {
//If this doesn't produce any materials, then it only creates
//Products. Creating products will consume materials. The
//Production of all consumed materials must be set to 0
for (const reqMatName in this.reqMats) {
for (const reqMatName of Object.keys(this.reqMats)) {
warehouse.materials[reqMatName].prd = 0;
}
}
@ -750,7 +750,7 @@ export class Industry implements IIndustry {
case "SALE":
/* Process sale of materials */
for (const matName in warehouse.materials) {
for (const matName of Object.keys(warehouse.materials)) {
if (warehouse.materials.hasOwnProperty(matName)) {
const mat = warehouse.materials[matName];
if (mat.sCost < 0 || mat.sllman[0] === false) {
@ -881,7 +881,7 @@ export class Industry implements IIndustry {
break;
case "EXPORT":
for (const matName in warehouse.materials) {
for (const matName of Object.keys(warehouse.materials)) {
if (warehouse.materials.hasOwnProperty(matName)) {
const mat = warehouse.materials[matName];
mat.totalExp = 0; //Reset export
@ -993,7 +993,7 @@ export class Industry implements IIndustry {
//Create products
if (this.state === "PRODUCTION") {
for (const prodName in this.products) {
for (const prodName of Object.keys(this.products)) {
const prod = this.products[prodName];
if (prod === undefined) continue;
if (!prod.fin) {
@ -1025,7 +1025,7 @@ export class Industry implements IIndustry {
}
//Produce Products
for (const prodName in this.products) {
for (const prodName of Object.keys(this.products)) {
if (this.products.hasOwnProperty(prodName)) {
const prod = this.products[prodName];
if (prod instanceof Product && prod.fin) {
@ -1067,7 +1067,7 @@ export class Industry implements IIndustry {
//Calculate net change in warehouse storage making the Products will cost
let netStorageSize = product.siz;
for (const reqMatName in product.reqMats) {
for (const reqMatName of Object.keys(product.reqMats)) {
if (product.reqMats.hasOwnProperty(reqMatName)) {
const normQty = product.reqMats[reqMatName];
netStorageSize -= MaterialSizes[reqMatName] * normQty;
@ -1084,7 +1084,7 @@ export class Industry implements IIndustry {
//Make sure we have enough resources to make our Products
let producableFrac = 1;
for (const reqMatName in product.reqMats) {
for (const reqMatName of Object.keys(product.reqMats)) {
if (product.reqMats.hasOwnProperty(reqMatName)) {
const req = product.reqMats[reqMatName] * prod;
if (warehouse.materials[reqMatName].qty < req) {
@ -1095,7 +1095,7 @@ export class Industry implements IIndustry {
//Make our Products if they are producable
if (producableFrac > 0 && prod > 0) {
for (const reqMatName in product.reqMats) {
for (const reqMatName of Object.keys(product.reqMats)) {
if (product.reqMats.hasOwnProperty(reqMatName)) {
const reqMatQtyNeeded = product.reqMats[reqMatName] * prod * producableFrac;
warehouse.materials[reqMatName].qty -= reqMatQtyNeeded;
@ -1114,7 +1114,7 @@ export class Industry implements IIndustry {
case "SALE": {
//Process sale of Products
product.pCost = 0; //Estimated production cost
for (const reqMatName in product.reqMats) {
for (const reqMatName of Object.keys(product.reqMats)) {
if (product.reqMats.hasOwnProperty(reqMatName)) {
product.pCost += product.reqMats[reqMatName] * warehouse.materials[reqMatName].bCost;
}
@ -1250,7 +1250,7 @@ export class Industry implements IIndustry {
}
discontinueProduct(product: Product): void {
for (const productName in this.products) {
for (const productName of Object.keys(this.products)) {
if (this.products.hasOwnProperty(productName)) {
if (product === this.products[productName]) {
delete this.products[productName];
@ -1354,7 +1354,7 @@ export class Industry implements IIndustry {
// Since ResearchTree data isnt saved, we'll update the Research Tree data
// based on the stored 'researched' property in the Industry object
if (Object.keys(researchTree.researched).length !== Object.keys(this.researched).length) {
for (const research in this.researched) {
for (const research of Object.keys(this.researched)) {
researchTree.research(research);
}
}

@ -103,7 +103,7 @@ export class OfficeSpace {
calculateEmployeeProductivity(corporation: ICorporation, industry: IIndustry): void {
//Reset
for (const name in this.employeeProd) {
for (const name of Object.keys(this.employeeProd)) {
this.employeeProd[name] = 0;
}

@ -198,7 +198,7 @@ export class Product {
//Calculate the product's required materials
//For now, just set it to be the same as the requirements to make materials
for (const matName in industry.reqMats) {
for (const matName of Object.keys(industry.reqMats)) {
if (industry.reqMats.hasOwnProperty(matName)) {
const reqMat = industry.reqMats[matName];
if (reqMat === undefined) continue;
@ -209,7 +209,7 @@ export class Product {
//Calculate the product's size
//For now, just set it to be the same size as the requirements to make materials
this.siz = 0;
for (const matName in industry.reqMats) {
for (const matName of Object.keys(industry.reqMats)) {
const reqMat = industry.reqMats[matName];
if (reqMat === undefined) continue;
this.siz += MaterialSizes[matName] * reqMat;

@ -85,7 +85,7 @@ export class Warehouse {
// Re-calculate how much space is being used by this Warehouse
updateMaterialSizeUsed(): void {
this.sizeUsed = 0;
for (const matName in this.materials) {
for (const matName of Object.keys(this.materials)) {
const mat = this.materials[matName];
if (MaterialSizes.hasOwnProperty(matName)) {
this.sizeUsed += mat.qty * MaterialSizes[matName];

@ -215,7 +215,7 @@ function Upgrades(props: { office: OfficeSpace; rerender: () => void }): React.R
const corp = useCorporation();
const division = useDivision();
const upgrades = [];
for (const index in IndustryUpgrades) {
for (const index of Object.keys(IndustryUpgrades)) {
const upgrade = IndustryUpgrades[index];
// AutoBrew research disables the Coffee upgrade

@ -81,7 +81,7 @@ function WarehouseRoot(props: IProps): React.ReactElement {
// Create React components for materials
const mats = [];
for (const matName in props.warehouse.materials) {
for (const matName of Object.keys(props.warehouse.materials)) {
if (!(props.warehouse.materials[matName] instanceof Material)) continue;
// Only create UI for materials that are relevant for the industry
if (!isRelevantMaterial(matName, division)) continue;
@ -99,7 +99,7 @@ function WarehouseRoot(props: IProps): React.ReactElement {
// Create React components for products
const products = [];
if (division.makesProducts && Object.keys(division.products).length > 0) {
for (const productName in division.products) {
for (const productName of Object.keys(division.products)) {
const product = division.products[productName];
if (!(product instanceof Product)) continue;
products.push(
@ -109,14 +109,14 @@ function WarehouseRoot(props: IProps): React.ReactElement {
}
const breakdownItems: JSX.Element[] = [];
for (const matName in props.warehouse.materials) {
for (const matName of Object.keys(props.warehouse.materials)) {
const mat = props.warehouse.materials[matName];
if (!MaterialSizes.hasOwnProperty(matName)) continue;
if (mat.qty === 0) continue;
breakdownItems.push(<>{matName}: {numeralWrapper.format(mat.qty * MaterialSizes[matName], "0,0.0")}</>);
}
for (const prodName in division.products) {
for (const prodName of Object.keys(division.products)) {
const prod = division.products[prodName];
if (prod === undefined) continue;
breakdownItems.push(<>{prodName}: {numeralWrapper.format(prod.data[props.warehouse.loc][0] * prod.siz, "0,0.0")}</>);

@ -60,7 +60,7 @@ export function SmartSupplyModal(props: IProps): React.ReactElement {
// Create React components for materials
const mats = [];
for (const matName in props.warehouse.materials) {
for (const matName of Object.keys(props.warehouse.materials)) {
if (!(props.warehouse.materials[matName] instanceof Material)) continue;
if (!Object.keys(division.reqMats).includes(matName)) continue;
mats.push(<Leftover key={matName} warehouse={props.warehouse} matName={matName} />);

@ -7,7 +7,7 @@ import { dialogBoxCreate } from "../ui/React/DialogBox";
export function determineCrimeSuccess(p: IPlayer, type: string): boolean {
let chance = 0;
let found = false;
for (const i in Crimes) {
for (const i of Object.keys(Crimes)) {
const crime = Crimes[i];
if (crime.type == type) {
chance = crime.successRate(p);

@ -21,7 +21,7 @@ export function checkIfConnectedToDarkweb(): void {
}
export function listAllDarkwebItems(): void {
for (const key in DarkWebItems) {
for (const key of Object.keys(DarkWebItems)) {
const item = DarkWebItems[key];
const cost = Player.getHomeComputer().programs.includes(item.program) ? (
@ -44,7 +44,7 @@ export function buyDarkwebItem(itemName: string): void {
// find the program that matches, if any
let item: DarkWebItem | null = null;
for (const key in DarkWebItems) {
for (const key of Object.keys(DarkWebItems)) {
const i = DarkWebItems[key];
if (i.program.toLowerCase() == itemName) {
item = i;
@ -93,7 +93,7 @@ export function buyAllDarkwebItems(): void {
const itemsToBuy: DarkWebItem[] = [];
let cost = 0;
for (const key in DarkWebItems) {
for (const key of Object.keys(DarkWebItems)) {
const item = DarkWebItems[key];
if (!Player.hasProgram(item.program)) {
itemsToBuy.push(item);

@ -46,25 +46,25 @@ export function Companies(): React.ReactElement {
}
function tonsOfRepCompanies(): void {
for (const c in AllCompanies) {
for (const c of Object.keys(AllCompanies)) {
AllCompanies[c].playerReputation = bigNumber;
}
}
function resetAllRepCompanies(): void {
for (const c in AllCompanies) {
for (const c of Object.keys(AllCompanies)) {
AllCompanies[c].playerReputation = 0;
}
}
function tonsOfFavorCompanies(): void {
for (const c in AllCompanies) {
for (const c of Object.keys(AllCompanies)) {
AllCompanies[c].favor = bigNumber;
}
}
function resetAllFavorCompanies(): void {
for (const c in AllCompanies) {
for (const c of Object.keys(AllCompanies)) {
AllCompanies[c].favor = 0;
}
}

@ -36,7 +36,7 @@ export function Factions(props: IProps): React.ReactElement {
}
function receiveAllInvites(): void {
for (const i in AllFaction) {
for (const i of Object.keys(AllFaction)) {
props.player.receiveInvite(AllFaction[i].name);
}
}
@ -74,25 +74,25 @@ export function Factions(props: IProps): React.ReactElement {
}
function tonsOfRep(): void {
for (const i in AllFaction) {
for (const i of Object.keys(AllFaction)) {
AllFaction[i].playerReputation = bigNumber;
}
}
function resetAllRep(): void {
for (const i in AllFaction) {
for (const i of Object.keys(AllFaction)) {
AllFaction[i].playerReputation = 0;
}
}
function tonsOfFactionFavor(): void {
for (const i in AllFaction) {
for (const i of Object.keys(AllFaction)) {
AllFaction[i].favor = bigNumber;
}
}
function resetAllFactionFavor(): void {
for (const i in AllFaction) {
for (const i of Object.keys(AllFaction)) {
AllFaction[i].favor = 0;
}
}

@ -28,7 +28,7 @@ export function Programs(props: IProps): React.ReactElement {
}
function addAllPrograms(): void {
for (const i in AllPrograms) {
for (const i of Object.keys(AllPrograms)) {
if (!props.player.hasProgram(AllPrograms[i].name)) {
props.player.getHomeComputer().programs.push(AllPrograms[i].name);
}

@ -38,7 +38,7 @@ export function StockMarket(): React.ReactElement {
};
}
for (const name in SM) {
for (const name of Object.keys(SM)) {
if (SM.hasOwnProperty(name)) {
const stock = SM[name];
if (stock instanceof Stock && match(stock.symbol)) {

@ -34,8 +34,7 @@ export function joinFaction(faction: Faction): void {
const factionInfo = faction.getInfo();
//Determine what factions you are banned from now that you have joined this faction
for (const i in factionInfo.enemies) {
const enemy = factionInfo.enemies[i];
for (const enemy of factionInfo.enemies) {
if (Factions[enemy] instanceof Faction) {
Factions[enemy].isBanned = true;
}
@ -121,7 +120,7 @@ export function purchaseAugmentation(aug: Augmentation, fac: Faction, sing = fal
}
}
for (const name in Augmentations) {
for (const name of Object.keys(Augmentations)) {
if (Augmentations.hasOwnProperty(name)) {
Augmentations[name].baseCost *= CONSTANTS.MultipleAugMultiplier * [1, 0.96, 0.94, 0.93][SourceFileFlags[11]];
}
@ -170,7 +169,7 @@ export function getNextNeurofluxLevel(): number {
}
export function processPassiveFactionRepGain(numCycles: number): void {
for (const name in Factions) {
for (const name of Object.keys(Factions)) {
if (name === Player.currentWorkFactionName) continue;
if (!Factions.hasOwnProperty(name)) continue;
const faction = Factions[name];

@ -34,7 +34,7 @@ export function factionExists(name: string): boolean {
}
export function initFactions(): void {
for (const name in FactionInfos) {
for (const name of Object.keys(FactionInfos)) {
resetFaction(new Faction(name));
}
}

@ -44,7 +44,7 @@ export function AugmentationsPage(props: IProps): React.ReactElement {
function getAugs(): string[] {
if (isPlayersGang) {
const augs: string[] = [];
for (const augName in Augmentations) {
for (const augName of Object.keys(Augmentations)) {
if (augName === AugmentationNames.NeuroFluxGovernor) continue;
if (augName === AugmentationNames.TheRedPill && player.bitNodeN !== 2) continue;
const aug = Augmentations[augName];

@ -158,7 +158,7 @@ export class Gang implements IGang {
// Process power first
const gangName = this.facName;
for (const name in AllGangs) {
for (const name of Object.keys(AllGangs)) {
if (AllGangs.hasOwnProperty(name)) {
if (name == gangName) {
AllGangs[name].power += this.calculatePower();

@ -24,7 +24,7 @@ export class HashManager {
upgrades: IMap<number> = {};
constructor() {
for (const name in HashUpgrades) {
for (const name of Object.keys(HashUpgrades)) {
this.upgrades[name] = 0;
}
}
@ -85,7 +85,7 @@ export class HashManager {
}
prestige(): void {
for (const name in HashUpgrades) {
for (const name of Object.keys(HashUpgrades)) {
this.upgrades[name] = 0;
}
this.hashes = 0;

@ -220,7 +220,7 @@ for (const metadata of LocationsMetadata) {
const cityName = loc.city;
if (cityName === null) {
// Generic location, add to all cities
for (const city in Cities) {
for (const city of Object.keys(Cities)) {
Cities[city].addLocation(loc.name);
}
} else {

@ -132,10 +132,10 @@ function ASCIICity(props: IProps): React.ReactElement {
const elems: JSX.Element[] = [];
const lines = props.city.asciiArt.split("\n");
for (const i in lines) {
for (const line of lines) {
elems.push(
<Typography key={i} sx={{ lineHeight: "1em", whiteSpace: "pre" }}>
{lineElems(lines[i])}
<Typography key={line} sx={{ lineHeight: "1em", whiteSpace: "pre" }}>
{lineElems(line)}
</Typography>,
);
}

@ -762,7 +762,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
},
disableLog: function (fn: any): any {
if (fn === "ALL") {
for (fn in possibleLogs) {
for (fn of Object.keys(possibleLogs)) {
workerScript.disableLogs[fn] = true;
}
workerScript.log("disableLog", () => `Disabled logging for all functions`);
@ -775,7 +775,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
},
enableLog: function (fn: any): any {
if (fn === "ALL") {
for (fn in possibleLogs) {
for (fn of Object.keys(possibleLogs)) {
delete workerScript.disableLogs[fn];
}
workerScript.log("enableLog", () => `Enabled logging for all functions`);
@ -1302,8 +1302,7 @@ export function NetscriptFunctions(workerScript: WorkerScript): NS {
updateDynamicRam("ps", getRamCost(Player, "ps"));
const server = safeGetServer(hostname, "ps");
const processes = [];
for (const i in server.runningScripts) {
const script = server.runningScripts[i];
for (const script of server.runningScripts) {
processes.push({
filename: script.filename,
threads: script.threads,

@ -101,7 +101,7 @@ export function NetscriptGang(player: IPlayer, workerScript: WorkerScript, helpe
helper.updateDynamicRam("getOtherGangInformation", getRamCost(player, "gang", "getOtherGangInformation"));
checkGangApiAccess("getOtherGangInformation");
const cpy: any = {};
for (const gang in AllGangs) {
for (const gang of Object.keys(AllGangs)) {
cpy[gang] = Object.assign({}, AllGangs[gang]);
}

@ -113,7 +113,7 @@ export function NetscriptSingularity(
// If player has a gang with this faction, return all augmentations.
if (player.hasGangWith(facname)) {
const res = [];
for (const augName in Augmentations) {
for (const augName of Object.keys(Augmentations)) {
if (augName === AugmentationNames.NeuroFluxGovernor) continue;
if (augName === AugmentationNames.TheRedPill && player.bitNodeN !== 2) continue;
const aug = Augmentations[augName];
@ -165,7 +165,7 @@ export function NetscriptSingularity(
let augs = [];
if (player.hasGangWith(faction)) {
for (const augName in Augmentations) {
for (const augName of Object.keys(Augmentations)) {
if (augName === AugmentationNames.NeuroFluxGovernor) continue;
if (augName === AugmentationNames.TheRedPill && player.bitNodeN !== 2) continue;
const tempAug = Augmentations[augName];

@ -273,7 +273,7 @@ export function NetscriptStockMarket(player: IPlayer, workerScript: WorkerScript
const orders: any = {};
const stockMarketOrders = StockMarket["Orders"];
for (const symbol in stockMarketOrders) {
for (const symbol of Object.keys(stockMarketOrders)) {
const orderBook = stockMarketOrders[symbol];
if (orderBook.constructor === Array && orderBook.length > 0) {
orders[symbol] = [];

@ -28,7 +28,7 @@ export function toNative(pseudoObj: any): any {
} else {
// Object.
nativeObj = {};
for (const key in pseudoObj.properties) {
for (const key of Object.keys(pseudoObj.properties)) {
const val = pseudoObj.properties[key];
nativeObj[key] = toNative(val);
}

@ -221,7 +221,7 @@ function _getScriptUrls(script: Script, scripts: Script[], seen: Script[]): Scri
return urlStack;
} catch (err) {
// If there is an error, we need to clean up the URLs.
for (const url in urlStack) URL.revokeObjectURL(url);
for (const url of urlStack) URL.revokeObjectURL(url.url);
throw err;
} finally {
seen.pop();

@ -116,7 +116,7 @@ function startNetscript2Script(player: IPlayer, workerScript: WorkerScript): Pro
};
}
for (const prop in workerScript.env.vars) {
for (const prop of Object.keys(workerScript.env.vars)) {
if (typeof workerScript.env.vars[prop] !== "function") continue;
workerScript.env.vars[prop] = wrap(prop, workerScript.env.vars[prop]);
}
@ -175,7 +175,7 @@ function startNetscript1Script(workerScript: WorkerScript): Promise<WorkerScript
const interpreterInitialization = function (int: any, scope: any): void {
//Add the Netscript environment
const ns = NetscriptFunctions(workerScript);
for (const name in ns) {
for (const name of Object.keys(ns)) {
const entry = ns[name];
if (typeof entry === "function") {
//Async functions need to be wrapped. See JS-Interpreter documentation

@ -112,7 +112,7 @@ export abstract class Person {
* Updates this object's multipliers for the given augmentation
*/
applyAugmentation(aug: Augmentation): void {
for (const mult in aug.mults) {
for (const mult of Object.keys(aug.mults)) {
if ((this as any)[mult] == null) {
console.warn(`Augmentation has unrecognized multiplier property: ${mult}`);
} else {

@ -1484,7 +1484,7 @@ export function finishCrime(this: IPlayer, cancelled: boolean): string {
if (determineCrimeSuccess(this, this.crimeType)) {
//Handle Karma and crime statistics
let crime = null;
for (const i in Crimes) {
for (const i of Object.keys(Crimes)) {
if (Crimes[i].type == this.crimeType) {
crime = Crimes[i];
break;
@ -2556,15 +2556,15 @@ export function setBitNodeNumber(this: IPlayer, n: number): void {
}
export function queueAugmentation(this: IPlayer, name: string): void {
for (const i in this.queuedAugmentations) {
if (this.queuedAugmentations[i].name == name) {
for (const aug of this.queuedAugmentations) {
if (aug.name == name) {
console.warn(`tried to queue ${name} twice, this may be a bug`);
return;
}
}
for (const i in this.augmentations) {
if (this.augmentations[i].name == name) {
for (const aug of this.augmentations) {
if (aug.name == name) {
console.warn(`tried to queue ${name} twice, this may be a bug`);
return;
}

@ -37,7 +37,7 @@ export function purchaseResleeve(r: Resleeve, p: IPlayer): boolean {
p.charisma_exp = r.charisma_exp;
// Reset Augmentation "owned" data
for (const augKey in Augmentations) {
for (const augKey of Object.keys(Augmentations)) {
Augmentations[augKey].owned = false;
}

@ -42,7 +42,7 @@ export function findSleevePurchasableAugs(sleeve: Sleeve, p: IPlayer): Augmentat
if (p.inGang()) {
const fac = p.getGangFaction();
for (const augName in Augmentations) {
for (const augName of Object.keys(Augmentations)) {
const aug = Augmentations[augName];
if (!isAvailableForSleeve(aug)) {
continue;

@ -75,14 +75,14 @@ export function prestigeAugmentation(): void {
initForeignServers(Player.getHomeComputer());
// Gain favor for Companies
for (const member in Companies) {
for (const member of Object.keys(Companies)) {
if (Companies.hasOwnProperty(member)) {
Companies[member].gainFavor();
}
}
// Gain favor for factions
for (const member in Factions) {
for (const member of Object.keys(Factions)) {
if (Factions.hasOwnProperty(member)) {
Factions[member].gainFavor();
}
@ -200,14 +200,14 @@ export function prestigeSourceFile(flume: boolean): void {
homeComp.cpuCores = 1;
// Reset favor for Companies
for (const member in Companies) {
for (const member of Object.keys(Companies)) {
if (Companies.hasOwnProperty(member)) {
Companies[member].favor = 0;
}
}
// Reset favor for factions
for (const member in Factions) {
for (const member of Object.keys(Factions)) {
if (Factions.hasOwnProperty(member)) {
Factions[member].favor = 0;
}
@ -219,7 +219,7 @@ export function prestigeSourceFile(flume: boolean): void {
}
// Delete all Augmentations
for (const name in Augmentations) {
for (const name of Object.keys(Augmentations)) {
if (Augmentations.hasOwnProperty(name)) {
delete Augmentations[name];
}

@ -6,7 +6,7 @@ import { IPlayer } from "../PersonObjects/IPlayer";
//Returns the programs this player can create.
export function getAvailableCreatePrograms(player: IPlayer): Program[] {
const programs: Program[] = [];
for (const key in Programs) {
for (const key of Object.keys(Programs)) {
// Non-creatable program
const create = Programs[key].create;
if (create == null) continue;

@ -115,7 +115,7 @@ function evaluateVersionCompatibility(ver: string | number): void {
}
// The "companyName" property of all Companies is renamed to "name"
for (const companyName in Companies) {
for (const companyName of Object.keys(Companies)) {
const company: any = Companies[companyName];
if (company.name == 0 && company.companyName != null) {
company.name = company.companyName;

@ -27,7 +27,7 @@ export function scriptCalculateOfflineProduction(runningScript: RunningScript):
//Data map: [MoneyStolen, NumTimesHacked, NumTimesGrown, NumTimesWeaken]
// Grow
for (const hostname in runningScript.dataMap) {
for (const hostname of Object.keys(runningScript.dataMap)) {
if (runningScript.dataMap.hasOwnProperty(hostname)) {
if (runningScript.dataMap[hostname][2] == 0 || runningScript.dataMap[hostname][2] == null) {
continue;
@ -60,7 +60,7 @@ export function scriptCalculateOfflineProduction(runningScript: RunningScript):
runningScript.offlineExpGained += expGain;
// Weaken
for (const hostname in runningScript.dataMap) {
for (const hostname of Object.keys(runningScript.dataMap)) {
if (runningScript.dataMap.hasOwnProperty(hostname)) {
if (runningScript.dataMap[hostname][3] == 0 || runningScript.dataMap[hostname][3] == null) {
continue;

@ -20,7 +20,7 @@ import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
let AllServers: IMap<Server | HacknetServer> = {};
function GetServerByIP(ip: string): BaseServer | undefined {
for (const key in AllServers) {
for (const key of Object.keys(AllServers)) {
const server = AllServers[key];
if (server.ip !== ip) continue;
return server;
@ -30,7 +30,7 @@ function GetServerByIP(ip: string): BaseServer | undefined {
//Returns server object with corresponding hostname
// Relatively slow, would rather not use this a lot
function GetServerByHostname(hostname: string): BaseServer | null {
for (const key in AllServers) {
for (const key of Object.keys(AllServers)) {
const server = AllServers[key];
if (server.hostname == hostname) {
return server;
@ -58,14 +58,14 @@ export function GetServer(s: string): BaseServer | null {
export function GetAllServers(): BaseServer[] {
const servers: BaseServer[] = [];
for (const key in AllServers) {
for (const key of Object.keys(AllServers)) {
servers.push(AllServers[key]);
}
return servers;
}
export function DeleteServer(serverkey: string): void {
for (const key in AllServers) {
for (const key of Object.keys(AllServers)) {
const server = AllServers[key];
if (server.ip !== serverkey && server.hostname !== serverkey) continue;
delete AllServers[key];
@ -194,7 +194,7 @@ export function initForeignServers(homeComputer: Server): void {
}
export function prestigeAllServers(): void {
for (const member in AllServers) {
for (const member of Object.keys(AllServers)) {
delete AllServers[member];
}
AllServers = {};
@ -206,7 +206,7 @@ export function loadAllServers(saveString: string): void {
export function saveAllServers(excludeRunningScripts = false): string {
const TempAllServers = JSON.parse(JSON.stringify(AllServers), Reviver);
for (const key in TempAllServers) {
for (const key of Object.keys(TempAllServers)) {
const server = TempAllServers[key];
if (excludeRunningScripts) {
server.runningScripts = [];

@ -42,7 +42,7 @@ export function processOrders(
const orderBook = refs.stockMarket["Orders"];
if (orderBook == null) {
const orders: IOrderBook = {};
for (const name in refs.stockMarket) {
for (const name of Object.keys(refs.stockMarket)) {
const stock = refs.stockMarket[name];
if (!(stock instanceof Stock)) {
continue;

@ -55,7 +55,7 @@ export function placeOrder(
const order = new Order(stock.symbol, shares, price, type, position);
if (StockMarket["Orders"] == null) {
const orders: IOrderBook = {};
for (const name in StockMarket) {
for (const name of Object.keys(StockMarket)) {
const stk = StockMarket[name];
if (!(stk instanceof Stock)) {
continue;
@ -157,7 +157,7 @@ export function deleteStockMarket(): void {
}
export function initStockMarket(): void {
for (const stk in StockMarket) {
for (const stk of Object.keys(StockMarket)) {
if (StockMarket.hasOwnProperty(stk)) {
delete StockMarket[stk];
}
@ -169,7 +169,7 @@ export function initStockMarket(): void {
}
const orders: IOrderBook = {};
for (const name in StockMarket) {
for (const name of Object.keys(StockMarket)) {
const stock = StockMarket[name];
if (!(stock instanceof Stock)) {
continue;
@ -184,7 +184,7 @@ export function initStockMarket(): void {
}
export function initSymbolToStockMap(): void {
for (const name in StockSymbols) {
for (const name of Object.keys(StockSymbols)) {
if (StockSymbols.hasOwnProperty(name)) {
const stock = StockMarket[name];
if (stock == null) {
@ -198,7 +198,7 @@ export function initSymbolToStockMap(): void {
}
function stockMarketCycle(): void {
for (const name in StockMarket) {
for (const name of Object.keys(StockMarket)) {
const stock = StockMarket[name];
if (!(stock instanceof Stock)) {
continue;
@ -247,7 +247,7 @@ export function processStockPrices(numCycles = 1): void {
}
const v = Math.random();
for (const name in StockMarket) {
for (const name of Object.keys(StockMarket)) {
const stock = StockMarket[name];
if (!(stock instanceof Stock)) {
continue;

@ -5,7 +5,7 @@ export const TickerHeaderFormatData = {
longestSymbol: 0,
};
for (const key in StockSymbols) {
for (const key of Object.keys(StockSymbols)) {
TickerHeaderFormatData.longestName = Math.max(key.length, TickerHeaderFormatData.longestName);
TickerHeaderFormatData.longestSymbol = Math.max(StockSymbols[key].length, TickerHeaderFormatData.longestSymbol);
}

@ -66,7 +66,7 @@ export function StockTickers(props: IProps): React.ReactElement {
}
const tickers: React.ReactElement[] = [];
for (const stockMarketProp in props.stockMarket) {
for (const stockMarketProp of Object.keys(props.stockMarket)) {
const val = props.stockMarket[stockMarketProp];
if (val instanceof Stock) {
// Skip if there's a filter and the stock isnt in that filter

@ -204,7 +204,7 @@ export async function determineAllPossibilitiesForTabCompletion(
if (isCommand("buy")) {
const options = [];
for (const i in DarkWebItems) {
for (const i of Object.keys(DarkWebItems)) {
const item = DarkWebItems[i];
options.push(item.program);
}

@ -169,7 +169,7 @@ const Engine: {
},
decrementAllCounters: function (numCycles = 1) {
for (const counterName in Engine.Counters) {
for (const counterName of Object.keys(Engine.Counters)) {
const counter = Engine.Counters[counterName];
if (counter === undefined) throw new Error("counter should not be undefined");
Engine.Counters[counterName] = counter - numCycles;