build fix, lint, remove some instanceof checks

This commit is contained in:
Snarling
2022-09-27 15:14:34 -04:00
parent 81412db02e
commit 38063f62a7
38 changed files with 131 additions and 282 deletions
+3 -3
View File
@@ -1,5 +1,5 @@
import * as personMethods from "./PersonMethods";
import { IPlayerOwnedAugmentation } from "../Augmentation/PlayerOwnedAugmentation";
import { PlayerOwnedAugmentation } from "../Augmentation/PlayerOwnedAugmentation";
import { CityName } from "../Locations/data/CityNames";
import { calculateSkill } from "./formulas/skill";
import { calculateIntelligenceBonus } from "./formulas/intelligence";
@@ -33,8 +33,8 @@ export abstract class Person {
mults = defaultMultipliers();
/** Augmentations */
augmentations: IPlayerOwnedAugmentation[] = [];
queuedAugmentations: IPlayerOwnedAugmentation[] = [];
augmentations: PlayerOwnedAugmentation[] = [];
queuedAugmentations: PlayerOwnedAugmentation[] = [];
/** City that the person is in */
city: CityName = CityName.Sector12;
+1 -1
View File
@@ -198,6 +198,6 @@ export function updateSkillLevels(this: Person): void {
this.hp.current = Math.round(this.hp.max * ratio);
}
export function hasAugmentation(this: Person, augName: string, ignoreQueued: boolean = false) {
export function hasAugmentation(this: Person, augName: string, ignoreQueued = false) {
return this.augmentations.some((a) => a.name === augName && (ignoreQueued || !this.queuedAugmentations.includes(a)));
}
-1
View File
@@ -12,7 +12,6 @@ import { PlayerOwnedSourceFile } from "../../SourceFile/PlayerOwnedSourceFile";
import { Exploit } from "../../Exploits/Exploit";
import { LocationName } from "../../Locations/data/LocationNames";
import { IPlayerOwnedAugmentation } from "../../Augmentation/PlayerOwnedAugmentation";
import { Corporation } from "../../Corporation/Corporation";
import { Gang } from "../../Gang/Gang";
import { Bladeburner } from "../../Bladeburner/Bladeburner";
@@ -6,10 +6,7 @@ export function canAccessBladeburner(this: PlayerObject): boolean {
}
export function inBladeburner(this: PlayerObject): boolean {
if (this.bladeburner == null) {
return false;
}
return this.bladeburner instanceof Bladeburner;
return Boolean(this.bladeburner);
}
export function startBladeburner(this: PlayerObject): void {
@@ -10,10 +10,7 @@ export function canAccessCorporation(this: PlayerObject): boolean {
}
export function hasCorporation(this: PlayerObject): boolean {
if (this.corporation == null) {
return false;
}
return this.corporation instanceof Corporation;
return Boolean(this.corporation);
}
export function startCorporation(this: PlayerObject, corpName: string, additionalShares = 0): void {
@@ -21,41 +21,22 @@ export function isAwareOfGang(this: PlayerObject): boolean {
export function getGangFaction(this: PlayerObject): Faction {
const gang = this.gang;
if (gang === null) {
throw new Error("Cannot get gang faction because player is not in a gang.");
}
if (gang === null) throw new Error("Cannot get gang faction because player is not in a gang.");
const fac = Factions[gang.facName];
if (fac == null) {
throw new Error(`Gang has invalid faction name: ${gang.facName}`);
}
if (fac == null) throw new Error(`Gang has invalid faction name: ${gang.facName}`);
return fac;
}
export function getGangName(this: PlayerObject): string {
if (!this.inGang()) return "";
const gang = this.gang;
if (gang === null) {
throw new Error("Cannot get gang faction because player is not in a gang.");
}
return gang.facName;
return gang ? gang.facName : "";
}
export function hasGangWith(this: PlayerObject, facName: string): boolean {
if (!this.inGang()) return false;
const gang = this.gang;
if (gang === null) {
throw new Error("Cannot get gang faction because player is not in a gang.");
}
return gang.facName === facName;
}
export function inGang(this: PlayerObject): boolean {
if (this.gang == null || this.gang == undefined) {
return false;
}
return this.gang instanceof Gang;
return gang ? gang.facName === facName : false;
}
export function startGang(this: PlayerObject, factionName: string, hacking: boolean): void {
@@ -67,3 +48,7 @@ export function startGang(this: PlayerObject, factionName: string, hacking: bool
}
fac.playerReputation = 0;
}
export function inGang(this: PlayerObject) {
return Boolean(this.gang);
}
@@ -105,15 +105,7 @@ export function prestigeAugmentation(this: PlayerObject): void {
this.sleeves.push(new Sleeve());
}
for (let i = 0; i < this.sleeves.length; ++i) {
if (this.sleeves[i] instanceof Sleeve) {
if (this.sleeves[i].shock >= 100) {
this.sleeves[i].synchronize();
} else {
this.sleeves[i].shockRecovery();
}
}
}
this.sleeves.forEach((sleeve) => (sleeve.shock >= 100 ? sleeve.synchronize() : sleeve.shockRecovery()));
this.lastUpdate = new Date().getTime();
@@ -137,13 +129,7 @@ export function prestigeSourceFile(this: PlayerObject): void {
this.prestigeAugmentation();
this.karma = 0;
// Duplicate sleeves are reset to level 1 every Bit Node (but the number of sleeves you have persists)
for (let i = 0; i < this.sleeves.length; ++i) {
if (this.sleeves[i] instanceof Sleeve) {
this.sleeves[i].prestige();
} else {
this.sleeves[i] = new Sleeve();
}
}
this.sleeves.forEach((sleeve) => sleeve.prestige());
if (this.bitNodeN === 10) {
for (let i = 0; i < this.sleeves.length; i++) {
@@ -284,7 +270,7 @@ export function hospitalize(this: PlayerObject): number {
//the applyToCompany() Netscript Singularity function
export function applyForJob(this: PlayerObject, entryPosType: CompanyPosition, sing = false): boolean {
const company = Companies[this.location]; //Company being applied to
if (!(company instanceof Company)) {
if (!company) {
console.error(`Could not find company that matches the location: ${this.location}. Player.applyToCompany() failed`);
return false;
}
@@ -1131,7 +1117,7 @@ export function gainCodingContractReward(this: PlayerObject, reward: ICodingCont
/* eslint-disable no-case-declarations */
switch (reward.type) {
case CodingContractRewardType.FactionReputation:
if (reward.name == null || !(Factions[reward.name] instanceof Faction)) {
if (reward.name == null || !Factions[reward.name]) {
// If no/invalid faction was designated, just give rewards to all factions
reward.type = CodingContractRewardType.FactionReputationAll;
return this.gainCodingContractReward(reward);
@@ -1156,14 +1142,12 @@ export function gainCodingContractReward(this: PlayerObject, reward: ICodingCont
const gainPerFaction = Math.floor(totalGain / factions.length);
for (const facName of factions) {
if (!(Factions[facName] instanceof Faction)) {
continue;
}
if (!Factions[facName]) continue;
Factions[facName].playerReputation += gainPerFaction;
}
return `Gained ${gainPerFaction} reputation for each of the following factions: ${factions.toString()}`;
case CodingContractRewardType.CompanyReputation: {
if (reward.name == null || !(Companies[reward.name] instanceof Company)) {
if (reward.name == null || !Companies[reward.name]) {
//If no/invalid company was designated, just give rewards to all factions
reward.type = CodingContractRewardType.FactionReputationAll;
return this.gainCodingContractReward(reward);
+2 -3
View File
@@ -24,7 +24,6 @@ import { Contracts } from "../../Bladeburner/data/Contracts";
import { CONSTANTS } from "../../Constants";
import { Faction } from "../../Faction/Faction";
import { Factions } from "../../Faction/Factions";
import { CityName } from "../../Locations/data/CityNames";
@@ -307,7 +306,7 @@ export class Sleeve extends Person {
* Returns boolean indicating success
*/
workForCompany(companyName: string): boolean {
if (!(Companies[companyName] instanceof Company) || Player.jobs[companyName] == null) {
if (!Companies[companyName] || Player.jobs[companyName] == null) {
return false;
}
@@ -327,7 +326,7 @@ export class Sleeve extends Person {
*/
workForFaction(factionName: string, workType: string): boolean {
const faction = Factions[factionName];
if (factionName === "" || !faction || !(faction instanceof Faction) || !Player.factions.includes(factionName)) {
if (factionName === "" || !faction || !Player.factions.includes(factionName)) {
return false;
}
+1 -1
View File
@@ -61,7 +61,7 @@ export function findPurchasableAugs(this: Sleeve): Augmentation[] {
// If player is in a gang, then we return all augs that the player
// has enough reputation for (since that gang offers all augs)
if (Player.inGang()) {
if (Player.gang) {
const fac = Player.getGangFaction();
const gangAugs = getFactionAugmentationsFiltered(fac);