mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-25 18:50:56 +02:00
build fix, lint, remove some instanceof checks
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user