convert some files to ts

This commit is contained in:
Olivier Gagnon
2021-09-23 13:30:13 -04:00
parent cdd9c174e7
commit 8fd6b2e7da
3 changed files with 16 additions and 12 deletions

View File

@@ -0,0 +1,55 @@
import { Factions } from "../../Faction/Factions";
import { Faction } from "../../Faction/Faction";
import { Gang } from "../../Gang/Gang";
import { SourceFileFlags } from "../../SourceFile/SourceFileFlags";
import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
import { IPlayer } from "../IPlayer";
// Amount of negative karma needed to manage a gang in BitNodes other than 2
const GangKarmaRequirement = -54000;
export function canAccessGang(this: IPlayer): boolean {
if (this.bitNodeN === 2) {
return true;
}
if (SourceFileFlags[2] <= 0) {
return false;
}
return this.karma <= BitNodeMultipliers.GangKarmaRequirement * GangKarmaRequirement;
}
export function getGangFaction(this: IPlayer): Faction {
const fac = Factions[this.gang.facName];
if (fac == null) {
throw new Error(`Gang has invalid faction name: ${this.gang.facName}`);
}
return fac;
}
export function getGangName(this: IPlayer): string {
return this.inGang() ? this.gang.facName : "";
}
export function hasGangWith(this: IPlayer, facName: string): boolean {
return this.inGang() && this.gang.facName === facName;
}
export function inGang(this: IPlayer): boolean {
if (this.gang == null || this.gang == undefined) {
return false;
}
return this.gang instanceof Gang;
}
export function startGang(this: IPlayer, factionName: string, hacking: boolean): void {
this.gang = new Gang(factionName, hacking);
const fac = Factions[factionName];
if (fac == null) {
throw new Error(`Invalid faction name when creating gang: ${factionName}`);
}
fac.playerReputation = 0;
}