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

436 lines
17 KiB
TypeScript
Raw Normal View History

2021-09-24 00:47:43 +02:00
import * as augmentationMethods from "./PlayerObjectAugmentationMethods";
import * as bladeburnerMethods from "./PlayerObjectBladeburnerMethods";
import * as corporationMethods from "./PlayerObjectCorporationMethods";
import * as gangMethods from "./PlayerObjectGangMethods";
import * as generalMethods from "./PlayerObjectGeneralMethods";
import * as serverMethods from "./PlayerObjectServerMethods";
2022-07-07 08:00:23 +02:00
import * as workMethods from "./PlayerObjectWorkMethods";
2021-09-24 00:47:43 +02:00
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";
2021-10-07 22:04:04 +02:00
import { BaseServer } from "../../Server/BaseServer";
2021-09-24 00:47:43 +02:00
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 { LocationName } from "../../Locations/data/LocationNames";
import { IPlayerOwnedAugmentation } from "../../Augmentation/PlayerOwnedAugmentation";
import { ICorporation } from "../../Corporation/ICorporation";
import { IGang } from "../../Gang/IGang";
import { IBladeburner } from "../../Bladeburner/IBladeburner";
import { HacknetNode } from "../../Hacknet/HacknetNode";
import { HashManager } from "../../Hacknet/HashManager";
import { CityName } from "../../Locations/data/CityNames";
import { MoneySourceTracker } from "../../utils/MoneySourceTracker";
2022-07-15 01:00:10 +02:00
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";
2022-07-07 08:00:23 +02:00
import { Work } from "src/Work/Work";
2022-07-15 00:43:33 +02:00
import { defaultMultipliers, Multipliers } from "../Multipliers";
2021-09-24 00:47:43 +02:00
export class PlayerObject implements IPlayer {
// Class members
augmentations: IPlayerOwnedAugmentation[];
bitNodeN: number;
city: CityName;
companyName: string;
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;
hp: number;
jobs: IMap<string>;
init: () => void;
karma: number;
numPeopleKilled: number;
location: LocationName;
max_hp: number;
2021-11-12 02:42:19 +01:00
money: number;
2021-09-24 00:47:43 +02:00
moneySourceA: MoneySourceTracker;
moneySourceB: MoneySourceTracker;
playtimeSinceLastAug: number;
playtimeSinceLastBitnode: number;
purchasedServers: any[];
queuedAugmentations: IPlayerOwnedAugmentation[];
scriptProdSinceLastAug: number;
sleeves: Sleeve[];
sleevesFromCovenant: number;
sourceFiles: IPlayerOwnedSourceFile[];
exploits: Exploit[];
achievements: PlayerAchievement[];
terminalCommandHistory: string[];
identifier: string;
2021-09-24 00:47:43 +02:00
lastUpdate: number;
lastSave: number;
2021-09-24 00:47:43 +02:00
totalPlaytime: number;
// Stats
2021-11-05 22:12:52 +01:00
hacking: number;
2021-09-24 00:47:43 +02:00
strength: number;
defense: number;
dexterity: number;
agility: number;
charisma: number;
intelligence: number;
// Experience
hacking_exp: number;
strength_exp: number;
defense_exp: number;
dexterity_exp: number;
agility_exp: number;
charisma_exp: number;
intelligence_exp: number;
2022-07-15 00:43:33 +02:00
mults: Multipliers;
2021-09-24 00:47:43 +02:00
2022-07-07 08:00:23 +02:00
currentWork: Work | null;
2021-09-24 00:47:43 +02:00
focus: boolean;
2022-03-29 20:09:17 +02:00
entropy: number;
2022-03-19 19:15:31 +01:00
2021-09-24 00:47:43 +02:00
// Methods
2022-07-14 23:43:08 +02:00
startWork: (w: Work) => void;
processWork: (cycles: number) => void;
finishWork: (cancelled: boolean) => void;
2021-09-24 00:47:43 +02:00
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;
2022-03-19 05:22:21 +01:00
canAccessGrafting: () => boolean;
2021-09-24 00:47:43 +02:00
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;
2021-10-27 20:18:33 +02:00
gainMoney: (money: number, source: string) => void;
2021-10-07 22:04:04 +02:00
getCurrentServer: () => BaseServer;
2021-09-24 00:47:43 +02:00
getGangFaction: () => Faction;
getGangName: () => string;
getHomeComputer: () => Server;
getNextCompanyPosition: (company: Company, entryPosType: CompanyPosition) => CompanyPosition | null;
getUpgradeHomeRamCost: () => number;
getUpgradeHomeCoresCost: () => number;
2021-09-24 00:47:43 +02:00
gotoLocation: (to: LocationName) => boolean;
2021-10-27 03:22:40 +02:00
hasAugmentation: (aug: string | Augmentation, installed?: boolean) => boolean;
2021-09-24 00:47:43 +02:00
hasCorporation: () => boolean;
hasGangWith: (facName: string) => boolean;
hasTorRouter: () => boolean;
hasProgram: (program: string) => boolean;
inBladeburner: () => boolean;
inGang: () => boolean;
2022-04-20 23:03:25 +02:00
isAwareOfGang: () => boolean;
2021-09-24 00:47:43 +02:00
isQualified: (company: Company, position: CompanyPosition) => boolean;
2021-10-27 20:18:33 +02:00
loseMoney: (money: number, source: string) => void;
2021-09-24 22:02:38 +02:00
reapplyAllAugmentations: (resetMultipliers?: boolean) => void;
2021-09-24 00:47:43 +02:00
reapplyAllSourceFiles: () => void;
regenerateHp: (amt: number) => void;
recordMoneySource: (amt: number, source: string) => void;
setMoney: (amt: number) => void;
startBladeburner: (p: any) => 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;
2021-09-24 00:47:43 +02:00
queryStatFromString: (str: string) => number;
getIntelligenceBonus: (weight: number) => number;
getCasinoWinnings: () => number;
quitJob: (company: string, sing?: boolean) => void;
hasJob: () => boolean;
2021-09-24 23:07:53 +02:00
createHacknetServer: () => HacknetServer;
2021-09-24 00:47:43 +02:00
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;
2021-09-24 00:47:43 +02:00
hospitalize: () => void;
2021-09-25 00:29:25 +02:00
checkForFactionInvitations: () => Faction[];
2021-09-24 00:47:43 +02:00
setBitNodeNumber: (n: number) => void;
2021-09-24 22:02:38 +02:00
getMult: (name: string) => number;
setMult: (name: string, mult: number) => void;
2021-09-25 23:21:50 +02:00
canAccessCotMG: () => boolean;
2021-10-08 09:16:51 +02:00
sourceFileLvl: (n: number) => number;
2022-03-19 19:15:31 +01:00
applyEntropy: (stacks?: number) => void;
2022-07-14 23:43:08 +02:00
focusPenalty: () => number;
2021-09-24 00:47:43 +02:00
constructor() {
//Skills and stats
2021-11-05 22:12:52 +01:00
this.hacking = 1;
2021-09-24 00:47:43 +02:00
//Combat stats
this.hp = 10;
this.max_hp = 10;
this.strength = 1;
this.defense = 1;
this.dexterity = 1;
this.agility = 1;
//Labor stats
this.charisma = 1;
//Special stats
this.intelligence = 0;
//Experience and multipliers
this.hacking_exp = 0;
this.strength_exp = 0;
this.defense_exp = 0;
this.dexterity_exp = 0;
this.agility_exp = 0;
this.charisma_exp = 0;
this.intelligence_exp = 0;
2022-07-15 00:43:33 +02:00
this.mults = defaultMultipliers();
2021-09-24 00:47:43 +02:00
//Money
2022-04-14 21:17:46 +02:00
this.money = 1000 + CONSTANTS.Donations;
2021-09-24 00:47:43 +02:00
//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 = {};
// Company at which player is CURRENTLY working (only valid when the player is actively working)
this.companyName = ""; // Name of Company. Must match a key value in Companies ma;
// Servers
2022-03-17 14:50:23 +01:00
this.currentServer = ""; //hostname of Server currently being accessed through termina;
this.purchasedServers = []; //hostnames of purchased server;
2021-09-24 00:47:43 +02:00
// Hacknet Nodes/Servers
2022-03-17 14:50:23 +01:00
this.hacknetNodes = []; // Note= For Hacknet Servers, this array holds the hostnames of the server;
2021-09-24 00:47:43 +02:00
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
2021-09-25 08:36:49 +02:00
//bitnode
this.bitNodeN = 1;
2021-09-24 00:47:43 +02:00
2022-03-29 20:09:17 +02:00
this.entropy = 0;
2022-03-19 19:15:31 +01:00
2021-09-24 00:47:43 +02:00
//Used to store the last update time.
this.lastUpdate = 0;
this.lastSave = 0;
2021-09-24 00:47:43 +02:00
this.totalPlaytime = 0;
2021-09-24 00:47:43 +02:00
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
2021-09-25 08:36:49 +02:00
// Production since last Augmentation installation
this.scriptProdSinceLastAug = 0;
2021-09-24 00:47:43 +02:00
this.exploits = [];
this.achievements = [];
this.terminalCommandHistory = [];
2021-09-24 00:47:43 +02:00
2022-07-15 00:43:33 +02:00
this.focus = false;
2022-07-07 08:00:23 +02:00
this.currentWork = null;
// Let's get a hash of some semi-random stuff so we have something unique.
this.identifier = cyrb53(
"I-" +
2022-03-29 20:09:17 +02:00
new Date().getTime() +
navigator.userAgent +
window.innerWidth +
window.innerHeight +
getRandomInt(100, 999),
);
2021-09-24 00:47:43 +02:00
this.init = generalMethods.init;
this.prestigeAugmentation = generalMethods.prestigeAugmentation;
this.prestigeSourceFile = generalMethods.prestigeSourceFile;
this.receiveInvite = generalMethods.receiveInvite;
this.calculateSkill = generalMethods.calculateSkill;
this.calculateSkillProgress = generalMethods.calculateSkillProgress;
2021-09-24 00:47:43 +02:00
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;
2021-09-24 00:47:43 +02:00
this.queryStatFromString = generalMethods.queryStatFromString;
2022-07-14 23:43:08 +02:00
this.startWork = workMethods.start;
this.processWork = workMethods.process;
this.finishWork = workMethods.finish;
2021-09-24 00:47:43 +02:00
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;
2021-09-24 00:47:43 +02:00
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;
2022-03-19 05:22:21 +01:00
this.canAccessGrafting = generalMethods.canAccessGrafting;
2021-09-24 00:47:43 +02:00
this.giveExploit = generalMethods.giveExploit;
this.giveAchievement = generalMethods.giveAchievement;
2021-09-24 00:47:43 +02:00
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;
2022-04-20 23:03:25 +02:00
this.isAwareOfGang = gangMethods.isAwareOfGang;
2021-09-24 00:47:43 +02:00
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;
2021-09-24 00:47:43 +02:00
this.createHacknetServer = serverMethods.createHacknetServer;
2021-09-24 22:02:38 +02:00
this.getMult = generalMethods.getMult;
this.setMult = generalMethods.setMult;
2021-09-25 23:21:50 +02:00
this.canAccessCotMG = generalMethods.canAccessCotMG;
2021-10-08 09:16:51 +02:00
this.sourceFileLvl = generalMethods.sourceFileLvl;
2022-03-19 19:15:31 +01:00
this.applyEntropy = augmentationMethods.applyEntropy;
2022-07-14 23:43:08 +02:00
this.focusPenalty = generalMethods.focusPenalty;
2021-09-24 00:47:43 +02:00
}
2022-04-14 21:28:13 +02:00
whoAmI(): string {
return "Player";
}
2022-04-14 21:49:21 +02:00
/**
2021-09-24 00:47:43 +02:00
* Serialize the current object to a JSON save state.
*/
2022-07-15 01:00:10 +02:00
toJSON(): IReviverValue {
2021-09-24 00:47:43 +02:00
return Generic_toJSON("PlayerObject", this);
}
/**
* Initiatizes a PlayerObject object from a JSON save state.
*/
2022-07-15 01:00:10 +02:00
static fromJSON(value: IReviverValue): PlayerObject {
2021-09-24 00:47:43 +02:00
return Generic_fromJSON(PlayerObject, value.data);
}
}
Reviver.constructors.PlayerObject = PlayerObject;