bitburner-src/src/PersonObjects/Player/PlayerObjectGangMethods.ts

70 lines
2.0 KiB
TypeScript
Raw Normal View History

2019-04-14 11:08:10 +02:00
import { Factions } from "../../Faction/Factions";
2021-09-23 19:30:13 +02:00
import { Faction } from "../../Faction/Faction";
2021-06-17 00:38:29 +02:00
import { Gang } from "../../Gang/Gang";
2019-04-14 11:08:10 +02:00
import { SourceFileFlags } from "../../SourceFile/SourceFileFlags";
import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
2021-09-23 19:30:13 +02:00
import { IPlayer } from "../IPlayer";
2019-04-14 11:08:10 +02:00
// Amount of negative karma needed to manage a gang in BitNodes other than 2
const GangKarmaRequirement = -54000;
2021-09-23 19:30:13 +02:00
export function canAccessGang(this: IPlayer): boolean {
2021-09-05 01:09:30 +02:00
if (this.bitNodeN === 2) {
return true;
}
if (SourceFileFlags[2] <= 0) {
return false;
}
2021-09-09 05:47:34 +02:00
return this.karma <= BitNodeMultipliers.GangKarmaRequirement * GangKarmaRequirement;
2019-04-14 11:08:10 +02:00
}
2021-09-23 19:30:13 +02:00
export function getGangFaction(this: IPlayer): Faction {
2021-09-24 00:47:43 +02:00
const gang = this.gang;
if (gang === null) {
throw new Error("Cannot get gang faction because player is not in a gang.");
}
const fac = Factions[gang.facName];
2021-09-05 01:09:30 +02:00
if (fac == null) {
2021-09-24 00:47:43 +02:00
throw new Error(`Gang has invalid faction name: ${gang.facName}`);
2021-09-05 01:09:30 +02:00
}
2021-09-05 01:09:30 +02:00
return fac;
}
2021-09-23 19:30:13 +02:00
export function getGangName(this: IPlayer): string {
2021-09-24 00:47:43 +02:00
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;
}
2021-09-23 19:30:13 +02:00
export function hasGangWith(this: IPlayer, facName: string): boolean {
2021-09-24 00:47:43 +02:00
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;
2019-04-14 11:08:10 +02:00
}
2021-09-23 19:30:13 +02:00
export function inGang(this: IPlayer): boolean {
2021-09-05 01:09:30 +02:00
if (this.gang == null || this.gang == undefined) {
return false;
}
2019-04-14 11:08:10 +02:00
2021-09-05 01:09:30 +02:00
return this.gang instanceof Gang;
2019-04-14 11:08:10 +02:00
}
2021-09-23 19:30:13 +02:00
export function startGang(this: IPlayer, factionName: string, hacking: boolean): void {
2021-09-05 01:09:30 +02:00
this.gang = new Gang(factionName, hacking);
2019-04-14 11:08:10 +02:00
2021-09-05 01:09:30 +02:00
const fac = Factions[factionName];
if (fac == null) {
throw new Error(`Invalid faction name when creating gang: ${factionName}`);
}
fac.playerReputation = 0;
2019-04-14 11:08:10 +02:00
}