Remove IPlayer interface

Use PlayerObject instead when referring to the type of "The Player."
This commit is contained in:
Snarling 2022-09-20 00:14:17 -04:00
parent 21a2d49de7
commit e578bd7681
9 changed files with 225 additions and 567 deletions

@ -1,157 +0,0 @@
/**
* Interface for an object that represents the player (PlayerObject)
* Used because at the time of implementation, the PlayerObject
* cant be converted to TypeScript.
*/
import { Sleeve } from "./Sleeve/Sleeve";
import { IMap } from "../types";
import { IPlayerOwnedAugmentation } from "../Augmentation/PlayerOwnedAugmentation";
import { Augmentation } from "../Augmentation/Augmentation";
import { Company } from "../Company/Company";
import { CompanyPosition } from "../Company/CompanyPosition";
import { CityName } from "../Locations/data/CityNames";
import { Faction } from "../Faction/Faction";
import { HashManager } from "../Hacknet/HashManager";
import { HacknetNode } from "../Hacknet/HacknetNode";
import { LocationName } from "../Locations/data/LocationNames";
import { Server } from "../Server/Server";
import { BaseServer } from "../Server/BaseServer";
import { IPlayerOwnedSourceFile } from "../SourceFile/PlayerOwnedSourceFile";
import { MoneySourceTracker } from "../utils/MoneySourceTracker";
import { Exploit } from "../Exploits/Exploit";
import { ICorporation } from "../Corporation/ICorporation";
import { IGang } from "../Gang/IGang";
import { IBladeburner } from "../Bladeburner/IBladeburner";
import { ICodingContractReward } from "../CodingContracts";
import { HacknetServer } from "../Hacknet/HacknetServer";
import { ISkillProgress } from "./formulas/skill";
import { PlayerAchievement } from "../Achievements/Achievements";
import { IPerson } from "./IPerson";
import { Work } from "../Work/Work";
import { Multipliers } from "./Multipliers";
import { Skills } from "./Skills";
import { HP } from "./HP";
export interface IPlayer extends IPerson {
bitNodeN: number;
city: CityName;
corporation: ICorporation | null;
gang: IGang | null;
bladeburner: IBladeburner | null;
currentServer: string;
factions: string[];
factionInvitations: string[];
hacknetNodes: (HacknetNode | string)[]; // HacknetNode object or IP of Hacknet Server
has4SData: boolean;
has4SDataTixApi: boolean;
hashManager: HashManager;
hasTixApiAccess: boolean;
hasWseAccount: boolean;
jobs: IMap<string>;
karma: number;
numPeopleKilled: number;
location: LocationName;
readonly money: number;
moneySourceA: MoneySourceTracker;
moneySourceB: MoneySourceTracker;
playtimeSinceLastAug: number;
playtimeSinceLastBitnode: number;
purchasedServers: string[];
queuedAugmentations: IPlayerOwnedAugmentation[];
scriptProdSinceLastAug: number;
sleeves: Sleeve[];
sleevesFromCovenant: number;
sourceFiles: IPlayerOwnedSourceFile[];
exploits: Exploit[];
achievements: PlayerAchievement[];
terminalCommandHistory: string[];
lastUpdate: number;
totalPlaytime: number;
hp: HP;
skills: Skills;
exp: Skills;
mults: Multipliers;
currentWork: Work | null;
focus: boolean;
entropy: number;
// Methods
init: () => void;
startWork(w: Work): void;
processWork(cycles: number): void;
finishWork(cancelled: boolean): void;
applyForAgentJob(sing?: boolean): boolean;
applyForBusinessConsultantJob(sing?: boolean): boolean;
applyForBusinessJob(sing?: boolean): boolean;
applyForEmployeeJob(sing?: boolean): boolean;
applyForItJob(sing?: boolean): boolean;
applyForJob(entryPosType: CompanyPosition, sing?: boolean): boolean;
applyForNetworkEngineerJob(sing?: boolean): boolean;
applyForPartTimeEmployeeJob(sing?: boolean): boolean;
applyForPartTimeWaiterJob(sing?: boolean): boolean;
applyForSecurityEngineerJob(sing?: boolean): boolean;
applyForSecurityJob(sing?: boolean): boolean;
applyForSoftwareConsultantJob(sing?: boolean): boolean;
applyForSoftwareJob(sing?: boolean): boolean;
applyForWaiterJob(sing?: boolean): boolean;
canAccessBladeburner(): boolean;
canAccessCorporation(): boolean;
canAccessGang(): boolean;
canAccessGrafting(): boolean;
canAfford(cost: number): boolean;
gainMoney(money: number, source: string): void;
getCurrentServer(): BaseServer;
getGangFaction(): Faction;
getGangName(): string;
getHomeComputer(): Server;
getNextCompanyPosition(company: Company, entryPosType: CompanyPosition): CompanyPosition | null;
getUpgradeHomeRamCost(): number;
getUpgradeHomeCoresCost(): number;
gotoLocation(to: LocationName): boolean;
hasAugmentation(aug: string | Augmentation, installed?: boolean): boolean;
hasCorporation(): boolean;
hasGangWith(facName: string): boolean;
hasTorRouter(): boolean;
hasProgram(program: string): boolean;
inBladeburner(): boolean;
inGang(): boolean;
isAwareOfGang(): boolean;
isQualified(company: Company, position: CompanyPosition): boolean;
loseMoney(money: number, source: string): void;
reapplyAllAugmentations(resetMultipliers?: boolean): void;
reapplyAllSourceFiles(): void;
setMoney(amt: number): void;
startBladeburner(): void;
startCorporation(corpName: string, additionalShares?: number): void;
startFocusing(): void;
startGang(facName: string, isHacking: boolean): void;
travel(to: CityName): boolean;
giveExploit(exploit: Exploit): void;
giveAchievement(achievementId: string): void;
getCasinoWinnings(): number;
quitJob(company: string, sing?: boolean): void;
hasJob(): boolean;
createHacknetServer(): HacknetServer;
queueAugmentation(augmentationName: string): void;
receiveInvite(factionName: string): void;
updateSkillLevels(): void;
gainCodingContractReward(reward: ICodingContractReward, difficulty?: number): string;
stopFocusing(): void;
resetMultipliers(): void;
prestigeAugmentation(): void;
prestigeSourceFile(): void;
calculateSkillProgress(exp: number, mult?: number): ISkillProgress;
hospitalize(): void;
checkForFactionInvitations(): Faction[];
setBitNodeNumber(n: number): void;
canAccessCotMG(): boolean;
sourceFileLvl(n: number): number;
applyEntropy(stacks?: number): void;
focusPenalty(): number;
}

@ -10,16 +10,8 @@ import { IMap } from "../../types";
import { Sleeve } from "../Sleeve/Sleeve";
import { IPlayerOwnedSourceFile } from "../../SourceFile/PlayerOwnedSourceFile";
import { Exploit } from "../../Exploits/Exploit";
import { CompanyPosition } from "../../Company/CompanyPosition";
import { Server } from "../../Server/Server";
import { BaseServer } from "../../Server/BaseServer";
import { HacknetServer } from "../../Hacknet/HacknetServer";
import { Faction } from "../../Faction/Faction";
import { Company } from "../../Company/Company";
import { Augmentation } from "../../Augmentation/Augmentation";
import { ICodingContractReward } from "../../CodingContracts";
import { IPlayer } from "../IPlayer";
import { IPerson } from "../IPerson";
import { LocationName } from "../../Locations/data/LocationNames";
import { IPlayerOwnedAugmentation } from "../../Augmentation/PlayerOwnedAugmentation";
import { ICorporation } from "../../Corporation/ICorporation";
@ -32,257 +24,171 @@ import { CityName } from "../../Locations/data/CityNames";
import { MoneySourceTracker } from "../../utils/MoneySourceTracker";
import { Reviver, Generic_toJSON, Generic_fromJSON, IReviverValue } from "../../utils/JSONReviver";
import { ISkillProgress } from "../formulas/skill";
import { PlayerAchievement } from "../../Achievements/Achievements";
import { cyrb53 } from "../../utils/StringHelperFunctions";
import { getRandomInt } from "../../utils/helpers/getRandomInt";
import { ITaskTracker } from "../ITaskTracker";
import { CONSTANTS } from "../../Constants";
import { Work } from "src/Work/Work";
import { defaultMultipliers, Multipliers } from "../Multipliers";
import { defaultMultipliers } from "../Multipliers";
import { HP } from "../HP";
import { Skills } from "../Skills";
export class PlayerObject implements IPlayer {
export class PlayerObject implements IPerson {
// Class members
augmentations: IPlayerOwnedAugmentation[];
bitNodeN: number;
city: CityName;
corporation: ICorporation | null;
gang: IGang | null;
bladeburner: IBladeburner | null;
currentServer: string;
factions: string[];
factionInvitations: string[];
hacknetNodes: (HacknetNode | string)[]; // HacknetNode object or IP of Hacknet Server
has4SData: boolean;
has4SDataTixApi: boolean;
hashManager: HashManager;
hasTixApiAccess: boolean;
hasWseAccount: boolean;
jobs: IMap<string>;
init: () => void;
karma: number;
numPeopleKilled: number;
location: LocationName;
money: number;
moneySourceA: MoneySourceTracker;
moneySourceB: MoneySourceTracker;
playtimeSinceLastAug: number;
playtimeSinceLastBitnode: number;
purchasedServers: string[];
queuedAugmentations: IPlayerOwnedAugmentation[];
scriptProdSinceLastAug: number;
sleeves: Sleeve[];
sleevesFromCovenant: number;
sourceFiles: IPlayerOwnedSourceFile[];
exploits: Exploit[];
achievements: PlayerAchievement[];
terminalCommandHistory: string[];
augmentations: IPlayerOwnedAugmentation[] = [];
bitNodeN = 1; //current bitnode
city = CityName.Sector12;
corporation: ICorporation | null = null;
gang: IGang | null = null;
bladeburner: IBladeburner | null = null;
currentServer = "";
factions: string[] = [];
factionInvitations: string[] = [];
hacknetNodes: (HacknetNode | string)[] = []; // HacknetNode object or hostname of Hacknet Server
has4SData = false;
has4SDataTixApi = false;
hashManager = new HashManager();
hasTixApiAccess = false;
hasWseAccount = false;
jobs: IMap<string> = {};
karma = 0;
numPeopleKilled = 0;
location = LocationName.TravelAgency;
money = 1000 + CONSTANTS.Donations;
moneySourceA = new MoneySourceTracker();
moneySourceB = new MoneySourceTracker();
playtimeSinceLastAug = 0;
playtimeSinceLastBitnode = 0;
purchasedServers: string[] = [];
queuedAugmentations: IPlayerOwnedAugmentation[] = [];
scriptProdSinceLastAug = 0;
sleeves: Sleeve[] = [];
sleevesFromCovenant = 0;
sourceFiles: IPlayerOwnedSourceFile[] = [];
exploits: Exploit[] = [];
achievements: PlayerAchievement[] = [];
terminalCommandHistory: string[] = [];
identifier: string;
lastUpdate: number;
lastSave: number;
totalPlaytime: number;
lastUpdate = 0;
lastSave = 0;
totalPlaytime = 0;
hp: HP;
skills: Skills;
exp: Skills;
hp: HP = { current: 10, max: 10 };
skills: Skills = {
hacking: 1,
strength: 1,
defense: 1,
dexterity: 1,
agility: 1,
charisma: 1,
intelligence: 0,
};
exp: Skills = {
hacking: 0,
strength: 0,
defense: 0,
dexterity: 0,
agility: 0,
charisma: 0,
intelligence: 0,
};
mults: Multipliers;
mults = defaultMultipliers();
currentWork: Work | null;
focus: boolean;
currentWork: Work | null = null;
focus = false;
entropy: number;
entropy = 0;
// Methods
startWork: (w: Work) => void;
processWork: (cycles: number) => void;
finishWork: (cancelled: boolean) => void;
applyForAgentJob: (sing?: boolean) => boolean;
applyForBusinessConsultantJob: (sing?: boolean) => boolean;
applyForBusinessJob: (sing?: boolean) => boolean;
applyForEmployeeJob: (sing?: boolean) => boolean;
applyForItJob: (sing?: boolean) => boolean;
applyForJob: (entryPosType: CompanyPosition, sing?: boolean) => boolean;
applyForNetworkEngineerJob: (sing?: boolean) => boolean;
applyForPartTimeEmployeeJob: (sing?: boolean) => boolean;
applyForPartTimeWaiterJob: (sing?: boolean) => boolean;
applyForSecurityEngineerJob: (sing?: boolean) => boolean;
applyForSecurityJob: (sing?: boolean) => boolean;
applyForSoftwareConsultantJob: (sing?: boolean) => boolean;
applyForSoftwareJob: (sing?: boolean) => boolean;
applyForWaiterJob: (sing?: boolean) => boolean;
canAccessBladeburner: () => boolean;
canAccessCorporation: () => boolean;
canAccessGang: () => boolean;
canAccessGrafting: () => boolean;
canAfford: (cost: number) => boolean;
gainHackingExp: (exp: number) => void;
gainStrengthExp: (exp: number) => void;
gainDefenseExp: (exp: number) => void;
gainDexterityExp: (exp: number) => void;
gainAgilityExp: (exp: number) => void;
gainCharismaExp: (exp: number) => void;
gainIntelligenceExp: (exp: number) => void;
gainStats: (retValue: ITaskTracker) => void;
gainMoney: (money: number, source: string) => void;
getCurrentServer: () => BaseServer;
getGangFaction: () => Faction;
getGangName: () => string;
getHomeComputer: () => Server;
getNextCompanyPosition: (company: Company, entryPosType: CompanyPosition) => CompanyPosition | null;
getUpgradeHomeRamCost: () => number;
getUpgradeHomeCoresCost: () => number;
gotoLocation: (to: LocationName) => boolean;
hasAugmentation: (aug: string | Augmentation, installed?: boolean) => boolean;
hasCorporation: () => boolean;
hasGangWith: (facName: string) => boolean;
hasTorRouter: () => boolean;
hasProgram: (program: string) => boolean;
inBladeburner: () => boolean;
inGang: () => boolean;
isAwareOfGang: () => boolean;
isQualified: (company: Company, position: CompanyPosition) => boolean;
loseMoney: (money: number, source: string) => void;
reapplyAllAugmentations: (resetMultipliers?: boolean) => void;
reapplyAllSourceFiles: () => void;
regenerateHp: (amt: number) => void;
recordMoneySource: (amt: number, source: string) => void;
setMoney: (amt: number) => void;
startBladeburner: () => void;
startCorporation: (corpName: string, additionalShares?: number) => void;
startFocusing: () => void;
startGang: (facName: string, isHacking: boolean) => void;
takeDamage: (amt: number) => boolean;
travel: (to: CityName) => boolean;
giveExploit: (exploit: Exploit) => void;
giveAchievement: (achievementId: string) => void;
queryStatFromString: (str: string) => number;
getIntelligenceBonus: (weight: number) => number;
getCasinoWinnings: () => number;
quitJob: (company: string, sing?: boolean) => void;
hasJob: () => boolean;
createHacknetServer: () => HacknetServer;
queueAugmentation: (augmentationName: string) => void;
receiveInvite: (factionName: string) => void;
updateSkillLevels: () => void;
gainCodingContractReward: (reward: ICodingContractReward, difficulty?: number) => string;
stopFocusing: () => void;
resetMultipliers: () => void;
prestigeAugmentation: () => void;
prestigeSourceFile: () => void;
calculateSkill: (exp: number, mult?: number) => number;
calculateSkillProgress: (exp: number, mult?: number) => ISkillProgress;
hospitalize: () => void;
checkForFactionInvitations: () => Faction[];
setBitNodeNumber: (n: number) => void;
canAccessCotMG: () => boolean;
sourceFileLvl: (n: number) => number;
applyEntropy: (stacks?: number) => void;
focusPenalty: () => number;
init = generalMethods.init;
startWork = workMethods.startWork;
processWork = workMethods.processWork;
finishWork = workMethods.finishWork;
applyForSoftwareJob = generalMethods.applyForSoftwareJob;
applyForSoftwareConsultantJob = generalMethods.applyForSoftwareConsultantJob;
applyForItJob = generalMethods.applyForItJob;
applyForSecurityEngineerJob = generalMethods.applyForSecurityEngineerJob;
applyForNetworkEngineerJob = generalMethods.applyForNetworkEngineerJob;
applyForBusinessJob = generalMethods.applyForBusinessJob;
applyForBusinessConsultantJob = generalMethods.applyForBusinessConsultantJob;
applyForSecurityJob = generalMethods.applyForSecurityJob;
applyForAgentJob = generalMethods.applyForAgentJob;
applyForEmployeeJob = generalMethods.applyForEmployeeJob;
applyForPartTimeEmployeeJob = generalMethods.applyForPartTimeEmployeeJob;
applyForWaiterJob = generalMethods.applyForWaiterJob;
applyForPartTimeWaiterJob = generalMethods.applyForPartTimeWaiterJob;
applyForJob = generalMethods.applyForJob;
canAccessBladeburner = bladeburnerMethods.canAccessBladeburner;
canAccessCorporation = corporationMethods.canAccessCorporation;
canAccessGang = gangMethods.canAccessGang;
canAccessGrafting = generalMethods.canAccessGrafting;
canAfford = generalMethods.canAfford;
gainHackingExp = generalMethods.gainHackingExp;
gainStrengthExp = generalMethods.gainStrengthExp;
gainDefenseExp = generalMethods.gainDefenseExp;
gainDexterityExp = generalMethods.gainDexterityExp;
gainAgilityExp = generalMethods.gainAgilityExp;
gainCharismaExp = generalMethods.gainCharismaExp;
gainIntelligenceExp = generalMethods.gainIntelligenceExp;
gainStats = generalMethods.gainStats;
gainMoney = generalMethods.gainMoney;
getCurrentServer = serverMethods.getCurrentServer;
getGangFaction = gangMethods.getGangFaction;
getGangName = gangMethods.getGangName;
getHomeComputer = serverMethods.getHomeComputer;
getNextCompanyPosition = generalMethods.getNextCompanyPosition;
getUpgradeHomeRamCost = serverMethods.getUpgradeHomeRamCost;
getUpgradeHomeCoresCost = serverMethods.getUpgradeHomeCoresCost;
gotoLocation = generalMethods.gotoLocation;
hasAugmentation = augmentationMethods.hasAugmentation;
hasCorporation = corporationMethods.hasCorporation;
hasGangWith = gangMethods.hasGangWith;
hasTorRouter = serverMethods.hasTorRouter;
hasProgram = generalMethods.hasProgram;
inBladeburner = bladeburnerMethods.inBladeburner;
inGang = gangMethods.inGang;
isAwareOfGang = gangMethods.isAwareOfGang;
isQualified = generalMethods.isQualified;
loseMoney = generalMethods.loseMoney;
reapplyAllAugmentations = generalMethods.reapplyAllAugmentations;
reapplyAllSourceFiles = generalMethods.reapplyAllSourceFiles;
regenerateHp = generalMethods.regenerateHp;
recordMoneySource = generalMethods.recordMoneySource;
setMoney = generalMethods.setMoney;
startBladeburner = bladeburnerMethods.startBladeburner;
startCorporation = corporationMethods.startCorporation;
startFocusing = generalMethods.startFocusing;
startGang = gangMethods.startGang;
takeDamage = generalMethods.takeDamage;
travel = generalMethods.travel;
giveExploit = generalMethods.giveExploit;
giveAchievement = generalMethods.giveAchievement;
queryStatFromString = generalMethods.queryStatFromString;
getIntelligenceBonus = generalMethods.getIntelligenceBonus;
getCasinoWinnings = generalMethods.getCasinoWinnings;
quitJob = generalMethods.quitJob;
hasJob = generalMethods.hasJob;
createHacknetServer = serverMethods.createHacknetServer;
queueAugmentation = generalMethods.queueAugmentation;
receiveInvite = generalMethods.receiveInvite;
updateSkillLevels = generalMethods.updateSkillLevels;
gainCodingContractReward = generalMethods.gainCodingContractReward;
stopFocusing = generalMethods.stopFocusing;
resetMultipliers = generalMethods.resetMultipliers;
prestigeAugmentation = generalMethods.prestigeAugmentation;
prestigeSourceFile = generalMethods.prestigeSourceFile;
calculateSkill = generalMethods.calculateSkill;
calculateSkillProgress = generalMethods.calculateSkillProgress;
hospitalize = generalMethods.hospitalize;
checkForFactionInvitations = generalMethods.checkForFactionInvitations;
setBitNodeNumber = generalMethods.setBitNodeNumber;
canAccessCotMG = generalMethods.canAccessCotMG;
sourceFileLvl = generalMethods.sourceFileLvl;
applyEntropy = augmentationMethods.applyEntropy;
focusPenalty = generalMethods.focusPenalty;
constructor() {
this.hp = { current: 10, max: 10 };
this.skills = {
hacking: 1,
strength: 1,
defense: 1,
dexterity: 1,
agility: 1,
charisma: 1,
intelligence: 0,
};
this.exp = {
hacking: 0,
strength: 0,
defense: 0,
dexterity: 0,
agility: 0,
charisma: 0,
intelligence: 0,
};
this.mults = defaultMultipliers();
//Money
this.money = 1000 + CONSTANTS.Donations;
//Location information
this.city = CityName.Sector12;
this.location = LocationName.TravelAgency;
// Jobs that the player holds
// Map of company name (key) -> name of company position (value. Just the name, not the CompanyPosition object)
// The CompanyPosition name must match a key value in CompanyPositions
this.jobs = {};
// Servers
this.currentServer = ""; //hostname of Server currently being accessed through termina;
this.purchasedServers = []; //hostnames of purchased server;
// Hacknet Nodes/Servers
this.hacknetNodes = []; // Note= For Hacknet Servers, this array holds the hostnames of the server;
this.hashManager = new HashManager();
//Factions
this.factions = []; //Names of all factions player has joine;
this.factionInvitations = []; //Outstanding faction invitation;
//Augmentations
this.queuedAugmentations = [];
this.augmentations = [];
this.sourceFiles = [];
//Crime statistics
this.numPeopleKilled = 0;
this.karma = 0;
//Stock Market
this.hasWseAccount = false;
this.hasTixApiAccess = false;
this.has4SData = false;
this.has4SDataTixApi = false;
//Gang
this.gang = null;
//Corporation
this.corporation = null;
//Bladeburner
this.bladeburner = null;
// Sleeves & Re-sleeving
this.sleeves = [];
this.sleevesFromCovenant = 0; // # of Duplicate sleeves purchased from the covenant
//bitnode
this.bitNodeN = 1;
this.entropy = 0;
//Used to store the last update time.
this.lastUpdate = 0;
this.lastSave = 0;
this.totalPlaytime = 0;
this.playtimeSinceLastAug = 0;
this.playtimeSinceLastBitnode = 0;
// Keep track of where money comes from
this.moneySourceA = new MoneySourceTracker(); // Where money comes from since last-installed Augmentation
this.moneySourceB = new MoneySourceTracker(); // Where money comes from for this entire BitNode run
// Production since last Augmentation installation
this.scriptProdSinceLastAug = 0;
this.exploits = [];
this.achievements = [];
this.terminalCommandHistory = [];
this.focus = false;
this.currentWork = null;
// Let's get a hash of some semi-random stuff so we have something unique.
this.identifier = cyrb53(
"I-" +
@ -292,96 +198,6 @@ export class PlayerObject implements IPlayer {
window.innerHeight +
getRandomInt(100, 999),
);
this.init = generalMethods.init;
this.prestigeAugmentation = generalMethods.prestigeAugmentation;
this.prestigeSourceFile = generalMethods.prestigeSourceFile;
this.receiveInvite = generalMethods.receiveInvite;
this.calculateSkill = generalMethods.calculateSkill;
this.calculateSkillProgress = generalMethods.calculateSkillProgress;
this.updateSkillLevels = generalMethods.updateSkillLevels;
this.resetMultipliers = generalMethods.resetMultipliers;
this.hasProgram = generalMethods.hasProgram;
this.setMoney = generalMethods.setMoney;
this.gainMoney = generalMethods.gainMoney;
this.loseMoney = generalMethods.loseMoney;
this.canAfford = generalMethods.canAfford;
this.recordMoneySource = generalMethods.recordMoneySource;
this.gainHackingExp = generalMethods.gainHackingExp;
this.gainStrengthExp = generalMethods.gainStrengthExp;
this.gainDefenseExp = generalMethods.gainDefenseExp;
this.gainDexterityExp = generalMethods.gainDexterityExp;
this.gainAgilityExp = generalMethods.gainAgilityExp;
this.gainCharismaExp = generalMethods.gainCharismaExp;
this.gainIntelligenceExp = generalMethods.gainIntelligenceExp;
this.gainStats = generalMethods.gainStats;
this.queryStatFromString = generalMethods.queryStatFromString;
this.startWork = workMethods.start;
this.processWork = workMethods.process;
this.finishWork = workMethods.finish;
this.startFocusing = generalMethods.startFocusing;
this.stopFocusing = generalMethods.stopFocusing;
this.takeDamage = generalMethods.takeDamage;
this.regenerateHp = generalMethods.regenerateHp;
this.hospitalize = generalMethods.hospitalize;
this.applyForJob = generalMethods.applyForJob;
this.getNextCompanyPosition = generalMethods.getNextCompanyPosition;
this.quitJob = generalMethods.quitJob;
this.hasJob = generalMethods.hasJob;
this.applyForSoftwareJob = generalMethods.applyForSoftwareJob;
this.applyForSoftwareConsultantJob = generalMethods.applyForSoftwareConsultantJob;
this.applyForItJob = generalMethods.applyForItJob;
this.applyForSecurityEngineerJob = generalMethods.applyForSecurityEngineerJob;
this.applyForNetworkEngineerJob = generalMethods.applyForNetworkEngineerJob;
this.applyForBusinessJob = generalMethods.applyForBusinessJob;
this.applyForBusinessConsultantJob = generalMethods.applyForBusinessConsultantJob;
this.applyForSecurityJob = generalMethods.applyForSecurityJob;
this.applyForAgentJob = generalMethods.applyForAgentJob;
this.applyForEmployeeJob = generalMethods.applyForEmployeeJob;
this.applyForPartTimeEmployeeJob = generalMethods.applyForPartTimeEmployeeJob;
this.applyForWaiterJob = generalMethods.applyForWaiterJob;
this.applyForPartTimeWaiterJob = generalMethods.applyForPartTimeWaiterJob;
this.isQualified = generalMethods.isQualified;
this.reapplyAllAugmentations = generalMethods.reapplyAllAugmentations;
this.reapplyAllSourceFiles = generalMethods.reapplyAllSourceFiles;
this.checkForFactionInvitations = generalMethods.checkForFactionInvitations;
this.setBitNodeNumber = generalMethods.setBitNodeNumber;
this.queueAugmentation = generalMethods.queueAugmentation;
this.gainCodingContractReward = generalMethods.gainCodingContractReward;
this.travel = generalMethods.travel;
this.gotoLocation = generalMethods.gotoLocation;
this.canAccessGrafting = generalMethods.canAccessGrafting;
this.giveExploit = generalMethods.giveExploit;
this.giveAchievement = generalMethods.giveAchievement;
this.getIntelligenceBonus = generalMethods.getIntelligenceBonus;
this.getCasinoWinnings = generalMethods.getCasinoWinnings;
this.hasAugmentation = augmentationMethods.hasAugmentation;
this.canAccessBladeburner = bladeburnerMethods.canAccessBladeburner;
this.inBladeburner = bladeburnerMethods.inBladeburner;
this.startBladeburner = bladeburnerMethods.startBladeburner;
this.canAccessCorporation = corporationMethods.canAccessCorporation;
this.hasCorporation = corporationMethods.hasCorporation;
this.startCorporation = corporationMethods.startCorporation;
this.canAccessGang = gangMethods.canAccessGang;
this.isAwareOfGang = gangMethods.isAwareOfGang;
this.getGangFaction = gangMethods.getGangFaction;
this.getGangName = gangMethods.getGangName;
this.hasGangWith = gangMethods.hasGangWith;
this.inGang = gangMethods.inGang;
this.startGang = gangMethods.startGang;
this.hasTorRouter = serverMethods.hasTorRouter;
this.getCurrentServer = serverMethods.getCurrentServer;
this.getHomeComputer = serverMethods.getHomeComputer;
this.getUpgradeHomeRamCost = serverMethods.getUpgradeHomeRamCost;
this.getUpgradeHomeCoresCost = serverMethods.getUpgradeHomeCoresCost;
this.createHacknetServer = serverMethods.createHacknetServer;
this.canAccessCotMG = generalMethods.canAccessCotMG;
this.sourceFileLvl = generalMethods.sourceFileLvl;
this.applyEntropy = augmentationMethods.applyEntropy;
this.focusPenalty = generalMethods.focusPenalty;
}
whoAmI(): string {

@ -1,13 +1,13 @@
/**
* Augmentation-related methods for the Player class (PlayerObject)
*/
import { IPlayer } from "../IPlayer";
import { PlayerObject } from "./PlayerObject";
import { Augmentation } from "../../Augmentation/Augmentation";
import { calculateEntropy } from "../Grafting/EntropyAccumulation";
export function hasAugmentation(this: IPlayer, aug: string | Augmentation, ignoreQueued = false): boolean {
export function hasAugmentation(this: PlayerObject, aug: string | Augmentation, ignoreQueued = false): boolean {
const augName: string = aug instanceof Augmentation ? aug.name : aug;
for (const owned of this.augmentations) {
@ -27,7 +27,7 @@ export function hasAugmentation(this: IPlayer, aug: string | Augmentation, ignor
return false;
}
export function applyEntropy(this: IPlayer, stacks = 1): void {
export function applyEntropy(this: PlayerObject, stacks = 1): void {
// Re-apply all multipliers
this.reapplyAllAugmentations();
this.reapplyAllSourceFiles();

@ -1,17 +1,17 @@
import { Bladeburner } from "../../Bladeburner/Bladeburner";
import { IPlayer } from "../IPlayer";
import { PlayerObject } from "./PlayerObject";
export function canAccessBladeburner(this: IPlayer): boolean {
export function canAccessBladeburner(this: PlayerObject): boolean {
return this.bitNodeN === 6 || this.bitNodeN === 7 || this.sourceFileLvl(6) > 0 || this.sourceFileLvl(7) > 0;
}
export function inBladeburner(this: IPlayer): boolean {
export function inBladeburner(this: PlayerObject): boolean {
if (this.bladeburner == null) {
return false;
}
return this.bladeburner instanceof Bladeburner;
}
export function startBladeburner(this: IPlayer): void {
export function startBladeburner(this: PlayerObject): void {
this.bladeburner = new Bladeburner();
}

@ -3,20 +3,20 @@ import {
CorporationUnlockUpgradeIndex,
CorporationUnlockUpgrades,
} from "../../Corporation/data/CorporationUnlockUpgrades";
import { IPlayer } from "../IPlayer";
import { PlayerObject } from "./PlayerObject";
export function canAccessCorporation(this: IPlayer): boolean {
export function canAccessCorporation(this: PlayerObject): boolean {
return this.bitNodeN === 3 || this.sourceFileLvl(3) > 0;
}
export function hasCorporation(this: IPlayer): boolean {
export function hasCorporation(this: PlayerObject): boolean {
if (this.corporation == null) {
return false;
}
return this.corporation instanceof Corporation;
}
export function startCorporation(this: IPlayer, corpName: string, additionalShares = 0): void {
export function startCorporation(this: PlayerObject, corpName: string, additionalShares = 0): void {
this.corporation = new Corporation({
name: corpName,
});

@ -1,10 +1,10 @@
import { Factions } from "../../Faction/Factions";
import { Faction } from "../../Faction/Faction";
import { Gang } from "../../Gang/Gang";
import { IPlayer } from "../IPlayer";
import { PlayerObject } from "./PlayerObject";
import { GangConstants } from "../../Gang/data/Constants";
export function canAccessGang(this: IPlayer): boolean {
export function canAccessGang(this: PlayerObject): boolean {
if (this.bitNodeN === 2) {
return true;
}
@ -15,11 +15,11 @@ export function canAccessGang(this: IPlayer): boolean {
return this.karma <= GangConstants.GangKarmaRequirement;
}
export function isAwareOfGang(this: IPlayer): boolean {
export function isAwareOfGang(this: PlayerObject): boolean {
return this.bitNodeN === 2 || this.sourceFileLvl(2) >= 1;
}
export function getGangFaction(this: IPlayer): Faction {
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.");
@ -32,7 +32,7 @@ export function getGangFaction(this: IPlayer): Faction {
return fac;
}
export function getGangName(this: IPlayer): string {
export function getGangName(this: PlayerObject): string {
if (!this.inGang()) return "";
const gang = this.gang;
if (gang === null) {
@ -41,7 +41,7 @@ export function getGangName(this: IPlayer): string {
return gang.facName;
}
export function hasGangWith(this: IPlayer, facName: string): boolean {
export function hasGangWith(this: PlayerObject, facName: string): boolean {
if (!this.inGang()) return false;
const gang = this.gang;
if (gang === null) {
@ -50,7 +50,7 @@ export function hasGangWith(this: IPlayer, facName: string): boolean {
return gang.facName === facName;
}
export function inGang(this: IPlayer): boolean {
export function inGang(this: PlayerObject): boolean {
if (this.gang == null || this.gang == undefined) {
return false;
}
@ -58,7 +58,7 @@ export function inGang(this: IPlayer): boolean {
return this.gang instanceof Gang;
}
export function startGang(this: IPlayer, factionName: string, hacking: boolean): void {
export function startGang(this: PlayerObject, factionName: string, hacking: boolean): void {
this.gang = new Gang(factionName, hacking);
const fac = Factions[factionName];

@ -1,4 +1,3 @@
import { IPlayer } from "../IPlayer";
import { PlayerObject } from "./PlayerObject";
import { applyAugmentation } from "../../Augmentation/AugmentationHelpers";
import { PlayerOwnedAugmentation } from "../../Augmentation/PlayerOwnedAugmentation";
@ -56,7 +55,7 @@ import { isCompanyWork } from "../../Work/CompanyWork";
import { defaultMultipliers } from "../Multipliers";
import { serverMetadata } from "../../Server/data/servers";
export function init(this: IPlayer): void {
export function init(this: PlayerObject): void {
/* Initialize Player's home computer */
const t_homeComp = safetlyCreateUniqueServer({
adminRights: true,
@ -142,7 +141,7 @@ export function prestigeAugmentation(this: PlayerObject): void {
this.finishWork(true);
}
export function prestigeSourceFile(this: IPlayer): void {
export function prestigeSourceFile(this: PlayerObject): void {
this.entropy = 0;
this.prestigeAugmentation();
this.karma = 0;
@ -180,7 +179,7 @@ export function prestigeSourceFile(this: IPlayer): void {
this.augmentations = [];
}
export function receiveInvite(this: IPlayer, factionName: string): void {
export function receiveInvite(this: PlayerObject, factionName: string): void {
if (this.factionInvitations.includes(factionName) || this.factions.includes(factionName)) {
return;
}
@ -193,11 +192,11 @@ export function calculateSkill(this: IPerson, exp: number, mult = 1): number {
}
//Calculates skill level progress based on experience. The same formula will be used for every skill
export function calculateSkillProgress(this: IPlayer, exp: number, mult = 1): ISkillProgress {
export function calculateSkillProgress(this: PlayerObject, exp: number, mult = 1): ISkillProgress {
return calculateSkillProgressF(exp, mult);
}
export function updateSkillLevels(this: IPlayer): void {
export function updateSkillLevels(this: PlayerObject): void {
this.skills.hacking = Math.max(
1,
Math.floor(this.calculateSkill(this.exp.hacking, this.mults.hacking * BitNodeMultipliers.HackingLevelMultiplier)),
@ -240,11 +239,11 @@ export function updateSkillLevels(this: IPlayer): void {
this.hp.current = Math.round(this.hp.max * ratio);
}
export function resetMultipliers(this: IPlayer): void {
export function resetMultipliers(this: PlayerObject): void {
this.mults = defaultMultipliers();
}
export function hasProgram(this: IPlayer, programName: string): boolean {
export function hasProgram(this: PlayerObject, programName: string): boolean {
const home = this.getHomeComputer();
if (home == null) {
return false;
@ -286,7 +285,7 @@ export function loseMoney(this: PlayerObject, money: number, source: string): vo
this.recordMoneySource(-1 * money, source);
}
export function canAfford(this: IPlayer, cost: number): boolean {
export function canAfford(this: PlayerObject, cost: number): boolean {
if (isNaN(cost)) {
console.error(`NaN passed into Player.canAfford()`);
return false;
@ -428,7 +427,7 @@ export function gainStats(this: IPerson, retValue: ITaskTracker): void {
}
//Given a string expression like "str" or "strength", returns the given stat
export function queryStatFromString(this: IPlayer, str: string): number {
export function queryStatFromString(this: PlayerObject, str: string): number {
const tempStr = str.toLowerCase();
if (tempStr.includes("hack")) {
return this.skills.hacking;
@ -454,16 +453,16 @@ export function queryStatFromString(this: IPlayer, str: string): number {
return 0;
}
export function startFocusing(this: IPlayer): void {
export function startFocusing(this: PlayerObject): void {
this.focus = true;
}
export function stopFocusing(this: IPlayer): void {
export function stopFocusing(this: PlayerObject): void {
this.focus = false;
}
// Returns true if hospitalized, false otherwise
export function takeDamage(this: IPlayer, amt: number): boolean {
export function takeDamage(this: PlayerObject, amt: number): boolean {
if (typeof amt !== "number") {
console.warn(`Player.takeDamage() called without a numeric argument: ${amt}`);
return false;
@ -489,7 +488,7 @@ export function regenerateHp(this: IPerson, amt: number): void {
}
}
export function hospitalize(this: IPlayer): number {
export function hospitalize(this: PlayerObject): number {
const cost = getHospitalizationCost();
SnackbarEvents.emit(`You've been Hospitalized for ${numeralWrapper.formatMoney(cost)}`, ToastVariant.WARNING, 2000);
@ -502,7 +501,7 @@ export function hospitalize(this: IPlayer): number {
//Determines the job that the Player should get (if any) at the current company
//The 'sing' argument designates whether or not this is being called from
//the applyToCompany() Netscript Singularity function
export function applyForJob(this: IPlayer, entryPosType: CompanyPosition, sing = false): boolean {
export function applyForJob(this: PlayerObject, entryPosType: CompanyPosition, sing = false): boolean {
const company = Companies[this.location]; //Company being applied to
if (!(company instanceof Company)) {
console.error(`Could not find company that matches the location: ${this.location}. Player.applyToCompany() failed`);
@ -555,7 +554,7 @@ export function applyForJob(this: IPlayer, entryPosType: CompanyPosition, sing =
//Returns your next position at a company given the field (software, business, etc.)
export function getNextCompanyPosition(
this: IPlayer,
this: PlayerObject,
company: Company,
entryPosType: CompanyPosition,
): CompanyPosition | null {
@ -590,7 +589,7 @@ export function getNextCompanyPosition(
return entryPosType;
}
export function quitJob(this: IPlayer, company: string): void {
export function quitJob(this: PlayerObject, company: string): void {
if (isCompanyWork(this.currentWork) && this.currentWork.companyName === company) {
this.finishWork(true);
}
@ -608,23 +607,23 @@ export function quitJob(this: IPlayer, company: string): void {
* @param this The player instance
* @returns Whether the user has at least one job
*/
export function hasJob(this: IPlayer): boolean {
export function hasJob(this: PlayerObject): boolean {
return Boolean(Object.keys(this.jobs).length);
}
export function applyForSoftwareJob(this: IPlayer, sing = false): boolean {
export function applyForSoftwareJob(this: PlayerObject, sing = false): boolean {
return this.applyForJob(CompanyPositions[posNames.SoftwareCompanyPositions[0]], sing);
}
export function applyForSoftwareConsultantJob(this: IPlayer, sing = false): boolean {
export function applyForSoftwareConsultantJob(this: PlayerObject, sing = false): boolean {
return this.applyForJob(CompanyPositions[posNames.SoftwareConsultantCompanyPositions[0]], sing);
}
export function applyForItJob(this: IPlayer, sing = false): boolean {
export function applyForItJob(this: PlayerObject, sing = false): boolean {
return this.applyForJob(CompanyPositions[posNames.ITCompanyPositions[0]], sing);
}
export function applyForSecurityEngineerJob(this: IPlayer, sing = false): boolean {
export function applyForSecurityEngineerJob(this: PlayerObject, sing = false): boolean {
const company = Companies[this.location]; //Company being applied to
if (this.isQualified(company, CompanyPositions[posNames.SecurityEngineerCompanyPositions[0]])) {
return this.applyForJob(CompanyPositions[posNames.SecurityEngineerCompanyPositions[0]], sing);
@ -636,7 +635,7 @@ export function applyForSecurityEngineerJob(this: IPlayer, sing = false): boolea
}
}
export function applyForNetworkEngineerJob(this: IPlayer, sing = false): boolean {
export function applyForNetworkEngineerJob(this: PlayerObject, sing = false): boolean {
const company = Companies[this.location]; //Company being applied to
if (this.isQualified(company, CompanyPositions[posNames.NetworkEngineerCompanyPositions[0]])) {
const pos = CompanyPositions[posNames.NetworkEngineerCompanyPositions[0]];
@ -649,21 +648,21 @@ export function applyForNetworkEngineerJob(this: IPlayer, sing = false): boolean
}
}
export function applyForBusinessJob(this: IPlayer, sing = false): boolean {
export function applyForBusinessJob(this: PlayerObject, sing = false): boolean {
return this.applyForJob(CompanyPositions[posNames.BusinessCompanyPositions[0]], sing);
}
export function applyForBusinessConsultantJob(this: IPlayer, sing = false): boolean {
export function applyForBusinessConsultantJob(this: PlayerObject, sing = false): boolean {
return this.applyForJob(CompanyPositions[posNames.BusinessConsultantCompanyPositions[0]], sing);
}
export function applyForSecurityJob(this: IPlayer, sing = false): boolean {
export function applyForSecurityJob(this: PlayerObject, sing = false): boolean {
// TODO Police Jobs
// Indexing starts at 2 because 0 is for police officer
return this.applyForJob(CompanyPositions[posNames.SecurityCompanyPositions[2]], sing);
}
export function applyForAgentJob(this: IPlayer, sing = false): boolean {
export function applyForAgentJob(this: PlayerObject, sing = false): boolean {
const company = Companies[this.location]; //Company being applied to
if (this.isQualified(company, CompanyPositions[posNames.AgentCompanyPositions[0]])) {
const pos = CompanyPositions[posNames.AgentCompanyPositions[0]];
@ -676,7 +675,7 @@ export function applyForAgentJob(this: IPlayer, sing = false): boolean {
}
}
export function applyForEmployeeJob(this: IPlayer, sing = false): boolean {
export function applyForEmployeeJob(this: PlayerObject, sing = false): boolean {
const company = Companies[this.location]; //Company being applied to
const position = posNames.MiscCompanyPositions[1];
// Check if this company has the position
@ -700,7 +699,7 @@ export function applyForEmployeeJob(this: IPlayer, sing = false): boolean {
}
}
export function applyForPartTimeEmployeeJob(this: IPlayer, sing = false): boolean {
export function applyForPartTimeEmployeeJob(this: PlayerObject, sing = false): boolean {
const company = Companies[this.location]; //Company being applied to
const position = posNames.PartTimeCompanyPositions[1];
// Check if this company has the position
@ -723,7 +722,7 @@ export function applyForPartTimeEmployeeJob(this: IPlayer, sing = false): boolea
}
}
export function applyForWaiterJob(this: IPlayer, sing = false): boolean {
export function applyForWaiterJob(this: PlayerObject, sing = false): boolean {
const company = Companies[this.location]; //Company being applied to
const position = posNames.MiscCompanyPositions[0];
// Check if this company has the position
@ -744,7 +743,7 @@ export function applyForWaiterJob(this: IPlayer, sing = false): boolean {
}
}
export function applyForPartTimeWaiterJob(this: IPlayer, sing = false): boolean {
export function applyForPartTimeWaiterJob(this: PlayerObject, sing = false): boolean {
const company = Companies[this.location]; //Company being applied to
const position = posNames.PartTimeCompanyPositions[0];
// Check if this company has the position
@ -766,7 +765,7 @@ export function applyForPartTimeWaiterJob(this: IPlayer, sing = false): boolean
}
//Checks if the Player is qualified for a certain position
export function isQualified(this: IPlayer, company: Company, position: CompanyPosition): boolean {
export function isQualified(this: PlayerObject, company: Company, position: CompanyPosition): boolean {
const offset = company.jobStatReqOffset;
const reqHacking = position.requiredHacking > 0 ? position.requiredHacking + offset : 0;
const reqStrength = position.requiredStrength > 0 ? position.requiredStrength + offset : 0;
@ -787,7 +786,7 @@ export function isQualified(this: IPlayer, company: Company, position: CompanyPo
}
/********** Reapplying Augmentations and Source File ***********/
export function reapplyAllAugmentations(this: IPlayer, resetMultipliers = true): void {
export function reapplyAllAugmentations(this: PlayerObject, resetMultipliers = true): void {
if (resetMultipliers) {
this.resetMultipliers();
}
@ -813,7 +812,7 @@ export function reapplyAllAugmentations(this: IPlayer, resetMultipliers = true):
this.updateSkillLevels();
}
export function reapplyAllSourceFiles(this: IPlayer): void {
export function reapplyAllSourceFiles(this: PlayerObject): void {
//Will always be called after reapplyAllAugmentations() so multipliers do not have to be reset
//this.resetMultipliers();
@ -834,7 +833,7 @@ export function reapplyAllSourceFiles(this: IPlayer): void {
//This function sets the requirements to join a Faction. It checks whether the Player meets
//those requirements and will return an array of all factions that the Player should
//receive an invitation to
export function checkForFactionInvitations(this: IPlayer): Faction[] {
export function checkForFactionInvitations(this: PlayerObject): Faction[] {
const invitedFactions: Faction[] = []; //Array which will hold all Factions the player should be invited to
const numAugmentations = this.augmentations.length;
@ -1320,11 +1319,11 @@ export function checkForFactionInvitations(this: IPlayer): Faction[] {
}
/************* BitNodes **************/
export function setBitNodeNumber(this: IPlayer, n: number): void {
export function setBitNodeNumber(this: PlayerObject, n: number): void {
this.bitNodeN = n;
}
export function queueAugmentation(this: IPlayer, name: string): void {
export function queueAugmentation(this: PlayerObject, name: string): void {
for (const aug of this.queuedAugmentations) {
if (aug.name == name) {
console.warn(`tried to queue ${name} twice, this may be a bug`);
@ -1343,7 +1342,7 @@ export function queueAugmentation(this: IPlayer, name: string): void {
}
/************* Coding Contracts **************/
export function gainCodingContractReward(this: IPlayer, reward: ICodingContractReward, difficulty = 1): string {
export function gainCodingContractReward(this: PlayerObject, reward: ICodingContractReward, difficulty = 1): string {
if (reward == null || reward.type == null) {
return `No reward for this contract`;
}
@ -1402,7 +1401,7 @@ export function gainCodingContractReward(this: IPlayer, reward: ICodingContractR
/* eslint-enable no-case-declarations */
}
export function travel(this: IPlayer, to: CityName): boolean {
export function travel(this: PlayerObject, to: CityName): boolean {
if (Cities[to] == null) {
console.warn(`Player.travel() called with invalid city: ${to}`);
return false;
@ -1412,7 +1411,7 @@ export function travel(this: IPlayer, to: CityName): boolean {
return true;
}
export function gotoLocation(this: IPlayer, to: LocationName): boolean {
export function gotoLocation(this: PlayerObject, to: LocationName): boolean {
if (Locations[to] == null) {
console.warn(`Player.gotoLocation() called with invalid location: ${to}`);
return false;
@ -1422,18 +1421,18 @@ export function gotoLocation(this: IPlayer, to: LocationName): boolean {
return true;
}
export function canAccessGrafting(this: IPlayer): boolean {
export function canAccessGrafting(this: PlayerObject): boolean {
return this.bitNodeN === 10 || this.sourceFileLvl(10) > 0;
}
export function giveExploit(this: IPlayer, exploit: Exploit): void {
export function giveExploit(this: PlayerObject, exploit: Exploit): void {
if (!this.exploits.includes(exploit)) {
this.exploits.push(exploit);
SnackbarEvents.emit("SF -1 acquired!", ToastVariant.SUCCESS, 2000);
}
}
export function giveAchievement(this: IPlayer, achievementId: string): void {
export function giveAchievement(this: PlayerObject, achievementId: string): void {
const achievement = achievements[achievementId];
if (!achievement) return;
if (!this.achievements.map((a) => a.ID).includes(achievementId)) {
@ -1442,25 +1441,25 @@ export function giveAchievement(this: IPlayer, achievementId: string): void {
}
}
export function getIntelligenceBonus(this: IPlayer, weight: number): number {
export function getIntelligenceBonus(this: PlayerObject, weight: number): number {
return calculateIntelligenceBonus(this.skills.intelligence, weight);
}
export function getCasinoWinnings(this: IPlayer): number {
export function getCasinoWinnings(this: PlayerObject): number {
return this.moneySourceA.casino;
}
export function canAccessCotMG(this: IPlayer): boolean {
export function canAccessCotMG(this: PlayerObject): boolean {
return this.bitNodeN === 13 || this.sourceFileLvl(13) > 0;
}
export function sourceFileLvl(this: IPlayer, n: number): number {
export function sourceFileLvl(this: PlayerObject, n: number): number {
const sf = this.sourceFiles.find((sf) => sf.n === n);
if (!sf) return 0;
return sf.lvl;
}
export function focusPenalty(this: IPlayer): number {
export function focusPenalty(this: PlayerObject): number {
let focus = 1;
if (!this.hasAugmentation(AugmentationNames.NeuroreceptorManager, true)) {
focus = this.focus ? 1 : CONSTANTS.BaseFocusBonus;

@ -1,7 +1,7 @@
/**
* Server and HacknetServer-related methods for the Player class (PlayerObject)
*/
import { IPlayer } from "../IPlayer";
import { PlayerObject } from "./PlayerObject";
import { CONSTANTS } from "../../Constants";
@ -12,23 +12,23 @@ import { HacknetServer } from "../../Hacknet/HacknetServer";
import { GetServer, AddToAllServers, createUniqueRandomIp } from "../../Server/AllServers";
import { SpecialServers } from "../../Server/data/SpecialServers";
export function hasTorRouter(this: IPlayer): boolean {
export function hasTorRouter(this: PlayerObject): boolean {
return this.getHomeComputer().serversOnNetwork.includes(SpecialServers.DarkWeb);
}
export function getCurrentServer(this: IPlayer): BaseServer {
export function getCurrentServer(this: PlayerObject): BaseServer {
const server = GetServer(this.currentServer);
if (server === null) throw new Error(`somehow connected to a server that does not exist. ${this.currentServer}`);
return server;
}
export function getHomeComputer(this: IPlayer): Server {
export function getHomeComputer(this: PlayerObject): Server {
const home = GetServer("home");
if (home instanceof Server) return home;
throw new Error("home computer was not a normal server");
}
export function getUpgradeHomeRamCost(this: IPlayer): number {
export function getUpgradeHomeRamCost(this: PlayerObject): number {
//Calculate how many times ram has been upgraded (doubled)
const currentRam = this.getHomeComputer().maxRam;
const numUpgrades = Math.log2(currentRam);
@ -40,11 +40,11 @@ export function getUpgradeHomeRamCost(this: IPlayer): number {
return cost;
}
export function getUpgradeHomeCoresCost(this: IPlayer): number {
export function getUpgradeHomeCoresCost(this: PlayerObject): number {
return 1e9 * Math.pow(7.5, this.getHomeComputer().cpuCores);
}
export function createHacknetServer(this: IPlayer): HacknetServer {
export function createHacknetServer(this: PlayerObject): HacknetServer {
const numOwned = this.hacknetNodes.length;
const name = `hacknet-node-${numOwned}`;
const server = new HacknetServer({

@ -1,20 +1,20 @@
import { Work } from "../../Work/Work";
import { IPlayer } from "../IPlayer";
import { PlayerObject } from "./PlayerObject";
export function start(this: IPlayer, w: Work): void {
export function startWork(this: PlayerObject, w: Work): void {
if (this.currentWork !== null) {
this.currentWork.finish(true);
}
this.currentWork = w;
}
export function process(this: IPlayer, cycles = 1): void {
export function processWork(this: PlayerObject, cycles = 1): void {
if (this.currentWork === null) return;
const finished = this.currentWork.process(cycles);
if (finished) {
this.finishWork(false);
}
}
export function finish(this: IPlayer, cancelled: boolean): void {
export function finishWork(this: PlayerObject, cancelled: boolean): void {
if (this.currentWork === null) return;
this.currentWork.finish(cancelled);
this.currentWork = null;