mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-23 17:53:00 +02:00
Player is now a Person
Use correct class inheritance, use class as type and remove IPlayer
This commit is contained in:
@@ -11,7 +11,6 @@ import { Sleeve } from "../Sleeve/Sleeve";
|
||||
import { IPlayerOwnedSourceFile } from "../../SourceFile/PlayerOwnedSourceFile";
|
||||
import { Exploit } from "../../Exploits/Exploit";
|
||||
|
||||
import { IPerson } from "../IPerson";
|
||||
import { LocationName } from "../../Locations/data/LocationNames";
|
||||
import { IPlayerOwnedAugmentation } from "../../Augmentation/PlayerOwnedAugmentation";
|
||||
import { ICorporation } from "../../Corporation/ICorporation";
|
||||
@@ -20,7 +19,6 @@ 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";
|
||||
import { Reviver, Generic_toJSON, Generic_fromJSON, IReviverValue } from "../../utils/JSONReviver";
|
||||
@@ -29,15 +27,11 @@ import { cyrb53 } from "../../utils/StringHelperFunctions";
|
||||
import { getRandomInt } from "../../utils/helpers/getRandomInt";
|
||||
import { CONSTANTS } from "../../Constants";
|
||||
import { Work } from "src/Work/Work";
|
||||
import { defaultMultipliers } from "../Multipliers";
|
||||
import { HP } from "../HP";
|
||||
import { Skills } from "../Skills";
|
||||
import { Person } from "../Person";
|
||||
|
||||
export class PlayerObject implements IPerson {
|
||||
// Class members
|
||||
augmentations: IPlayerOwnedAugmentation[] = [];
|
||||
export class PlayerObject extends Person {
|
||||
// Player-specific properties
|
||||
bitNodeN = 1; //current bitnode
|
||||
city = CityName.Sector12;
|
||||
corporation: ICorporation | null = null;
|
||||
gang: IGang | null = null;
|
||||
bladeburner: IBladeburner | null = null;
|
||||
@@ -73,34 +67,12 @@ export class PlayerObject implements IPerson {
|
||||
lastSave = 0;
|
||||
totalPlaytime = 0;
|
||||
|
||||
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 = defaultMultipliers();
|
||||
|
||||
currentWork: Work | null = null;
|
||||
focus = false;
|
||||
|
||||
entropy = 0;
|
||||
|
||||
// Methods
|
||||
// Player-specific methods
|
||||
init = generalMethods.init;
|
||||
startWork = workMethods.startWork;
|
||||
processWork = workMethods.processWork;
|
||||
@@ -124,14 +96,6 @@ export class PlayerObject implements IPerson {
|
||||
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;
|
||||
@@ -153,7 +117,6 @@ export class PlayerObject implements IPerson {
|
||||
loseMoney = generalMethods.loseMoney;
|
||||
reapplyAllAugmentations = generalMethods.reapplyAllAugmentations;
|
||||
reapplyAllSourceFiles = generalMethods.reapplyAllSourceFiles;
|
||||
regenerateHp = generalMethods.regenerateHp;
|
||||
recordMoneySource = generalMethods.recordMoneySource;
|
||||
setMoney = generalMethods.setMoney;
|
||||
startBladeburner = bladeburnerMethods.startBladeburner;
|
||||
@@ -164,21 +127,16 @@ export class PlayerObject implements IPerson {
|
||||
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;
|
||||
@@ -189,6 +147,7 @@ export class PlayerObject implements IPerson {
|
||||
focusPenalty = generalMethods.focusPenalty;
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
// Let's get a hash of some semi-random stuff so we have something unique.
|
||||
this.identifier = cyrb53(
|
||||
"I-" +
|
||||
@@ -219,4 +178,4 @@ export class PlayerObject implements IPerson {
|
||||
}
|
||||
}
|
||||
|
||||
Reviver.constructors.PlayerObject = PlayerObject;
|
||||
Reviver.constructors.PlayerObject = PlayerObject;
|
||||
@@ -24,11 +24,9 @@ import { LocationName } from "../../Locations/data/LocationNames";
|
||||
import { Sleeve } from "../Sleeve/Sleeve";
|
||||
import { isSleeveCompanyWork } from "../Sleeve/Work/SleeveCompanyWork";
|
||||
import {
|
||||
calculateSkill as calculateSkillF,
|
||||
calculateSkillProgress as calculateSkillProgressF,
|
||||
ISkillProgress,
|
||||
} from "../formulas/skill";
|
||||
import { calculateIntelligenceBonus } from "../formulas/intelligence";
|
||||
import { GetServer, AddToAllServers, createUniqueRandomIp } from "../../Server/AllServers";
|
||||
import { Server } from "../../Server/Server";
|
||||
import { safetlyCreateUniqueServer } from "../../Server/ServerHelpers";
|
||||
@@ -47,12 +45,8 @@ import { dialogBoxCreate } from "../../ui/React/DialogBox";
|
||||
import { SnackbarEvents, ToastVariant } from "../../ui/React/Snackbar";
|
||||
import { achievements } from "../../Achievements/Achievements";
|
||||
import { FactionNames } from "../../Faction/data/FactionNames";
|
||||
import { ITaskTracker } from "../ITaskTracker";
|
||||
import { IPerson } from "../IPerson";
|
||||
import { Player } from "../../Player";
|
||||
|
||||
import { isCompanyWork } from "../../Work/CompanyWork";
|
||||
import { defaultMultipliers } from "../Multipliers";
|
||||
import { serverMetadata } from "../../Server/data/servers";
|
||||
|
||||
export function init(this: PlayerObject): void {
|
||||
@@ -186,63 +180,11 @@ export function receiveInvite(this: PlayerObject, factionName: string): void {
|
||||
this.factionInvitations.push(factionName);
|
||||
}
|
||||
|
||||
//Calculates skill level based on experience. The same formula will be used for every skill
|
||||
export function calculateSkill(this: IPerson, exp: number, mult = 1): number {
|
||||
return calculateSkillF(exp, mult);
|
||||
}
|
||||
|
||||
//Calculates skill level progress based on experience. The same formula will be used for every skill
|
||||
export function calculateSkillProgress(this: PlayerObject, exp: number, mult = 1): ISkillProgress {
|
||||
return calculateSkillProgressF(exp, mult);
|
||||
}
|
||||
|
||||
export function updateSkillLevels(this: PlayerObject): void {
|
||||
this.skills.hacking = Math.max(
|
||||
1,
|
||||
Math.floor(this.calculateSkill(this.exp.hacking, this.mults.hacking * BitNodeMultipliers.HackingLevelMultiplier)),
|
||||
);
|
||||
this.skills.strength = Math.max(
|
||||
1,
|
||||
Math.floor(
|
||||
this.calculateSkill(this.exp.strength, this.mults.strength * BitNodeMultipliers.StrengthLevelMultiplier),
|
||||
),
|
||||
);
|
||||
this.skills.defense = Math.max(
|
||||
1,
|
||||
Math.floor(this.calculateSkill(this.exp.defense, this.mults.defense * BitNodeMultipliers.DefenseLevelMultiplier)),
|
||||
);
|
||||
this.skills.dexterity = Math.max(
|
||||
1,
|
||||
Math.floor(
|
||||
this.calculateSkill(this.exp.dexterity, this.mults.dexterity * BitNodeMultipliers.DexterityLevelMultiplier),
|
||||
),
|
||||
);
|
||||
this.skills.agility = Math.max(
|
||||
1,
|
||||
Math.floor(this.calculateSkill(this.exp.agility, this.mults.agility * BitNodeMultipliers.AgilityLevelMultiplier)),
|
||||
);
|
||||
this.skills.charisma = Math.max(
|
||||
1,
|
||||
Math.floor(
|
||||
this.calculateSkill(this.exp.charisma, this.mults.charisma * BitNodeMultipliers.CharismaLevelMultiplier),
|
||||
),
|
||||
);
|
||||
|
||||
if (this.skills.intelligence > 0) {
|
||||
this.skills.intelligence = Math.floor(this.calculateSkill(this.exp.intelligence));
|
||||
} else {
|
||||
this.skills.intelligence = 0;
|
||||
}
|
||||
|
||||
const ratio = this.hp.current / this.hp.max;
|
||||
this.hp.max = Math.floor(10 + this.skills.defense / 10);
|
||||
this.hp.current = Math.round(this.hp.max * ratio);
|
||||
}
|
||||
|
||||
export function resetMultipliers(this: PlayerObject): void {
|
||||
this.mults = defaultMultipliers();
|
||||
}
|
||||
|
||||
export function hasProgram(this: PlayerObject, programName: string): boolean {
|
||||
const home = this.getHomeComputer();
|
||||
if (home == null) {
|
||||
@@ -306,153 +248,6 @@ export function recordMoneySource(this: PlayerObject, amt: number, source: strin
|
||||
this.moneySourceB.record(amt, source);
|
||||
}
|
||||
|
||||
export function gainHackingExp(this: IPerson, exp: number): void {
|
||||
if (isNaN(exp)) {
|
||||
console.error("ERR: NaN passed into Player.gainHackingExp()");
|
||||
return;
|
||||
}
|
||||
this.exp.hacking += exp;
|
||||
if (this.exp.hacking < 0) {
|
||||
this.exp.hacking = 0;
|
||||
}
|
||||
|
||||
this.skills.hacking = calculateSkillF(
|
||||
this.exp.hacking,
|
||||
this.mults.hacking * BitNodeMultipliers.HackingLevelMultiplier,
|
||||
);
|
||||
}
|
||||
|
||||
export function gainStrengthExp(this: IPerson, exp: number): void {
|
||||
if (isNaN(exp)) {
|
||||
console.error("ERR: NaN passed into Player.gainStrengthExp()");
|
||||
return;
|
||||
}
|
||||
this.exp.strength += exp;
|
||||
if (this.exp.strength < 0) {
|
||||
this.exp.strength = 0;
|
||||
}
|
||||
|
||||
this.skills.strength = calculateSkillF(
|
||||
this.exp.strength,
|
||||
this.mults.strength * BitNodeMultipliers.StrengthLevelMultiplier,
|
||||
);
|
||||
}
|
||||
|
||||
export function gainDefenseExp(this: IPerson, exp: number): void {
|
||||
if (isNaN(exp)) {
|
||||
console.error("ERR: NaN passed into player.gainDefenseExp()");
|
||||
return;
|
||||
}
|
||||
this.exp.defense += exp;
|
||||
if (this.exp.defense < 0) {
|
||||
this.exp.defense = 0;
|
||||
}
|
||||
|
||||
this.skills.defense = calculateSkillF(
|
||||
this.exp.defense,
|
||||
this.mults.defense * BitNodeMultipliers.DefenseLevelMultiplier,
|
||||
);
|
||||
const ratio = this.hp.current / this.hp.max;
|
||||
this.hp.max = Math.floor(10 + this.skills.defense / 10);
|
||||
this.hp.current = Math.round(this.hp.max * ratio);
|
||||
}
|
||||
|
||||
export function gainDexterityExp(this: IPerson, exp: number): void {
|
||||
if (isNaN(exp)) {
|
||||
console.error("ERR: NaN passed into Player.gainDexterityExp()");
|
||||
return;
|
||||
}
|
||||
this.exp.dexterity += exp;
|
||||
if (this.exp.dexterity < 0) {
|
||||
this.exp.dexterity = 0;
|
||||
}
|
||||
|
||||
this.skills.dexterity = calculateSkillF(
|
||||
this.exp.dexterity,
|
||||
this.mults.dexterity * BitNodeMultipliers.DexterityLevelMultiplier,
|
||||
);
|
||||
}
|
||||
|
||||
export function gainAgilityExp(this: IPerson, exp: number): void {
|
||||
if (isNaN(exp)) {
|
||||
console.error("ERR: NaN passed into Player.gainAgilityExp()");
|
||||
return;
|
||||
}
|
||||
this.exp.agility += exp;
|
||||
if (this.exp.agility < 0) {
|
||||
this.exp.agility = 0;
|
||||
}
|
||||
|
||||
this.skills.agility = calculateSkillF(
|
||||
this.exp.agility,
|
||||
this.mults.agility * BitNodeMultipliers.AgilityLevelMultiplier,
|
||||
);
|
||||
}
|
||||
|
||||
export function gainCharismaExp(this: IPerson, exp: number): void {
|
||||
if (isNaN(exp)) {
|
||||
console.error("ERR: NaN passed into Player.gainCharismaExp()");
|
||||
return;
|
||||
}
|
||||
this.exp.charisma += exp;
|
||||
if (this.exp.charisma < 0) {
|
||||
this.exp.charisma = 0;
|
||||
}
|
||||
|
||||
this.skills.charisma = calculateSkillF(
|
||||
this.exp.charisma,
|
||||
this.mults.charisma * BitNodeMultipliers.CharismaLevelMultiplier,
|
||||
);
|
||||
}
|
||||
|
||||
export function gainIntelligenceExp(this: IPerson, exp: number): void {
|
||||
if (isNaN(exp)) {
|
||||
console.error("ERROR: NaN passed into Player.gainIntelligenceExp()");
|
||||
return;
|
||||
}
|
||||
if (Player.sourceFileLvl(5) > 0 || this.skills.intelligence > 0 || Player.bitNodeN === 5) {
|
||||
this.exp.intelligence += exp;
|
||||
this.skills.intelligence = Math.floor(this.calculateSkill(this.exp.intelligence, 1));
|
||||
}
|
||||
}
|
||||
|
||||
export function gainStats(this: IPerson, retValue: ITaskTracker): void {
|
||||
this.gainHackingExp(retValue.hack * this.mults.hacking_exp);
|
||||
this.gainStrengthExp(retValue.str * this.mults.strength_exp);
|
||||
this.gainDefenseExp(retValue.def * this.mults.defense_exp);
|
||||
this.gainDexterityExp(retValue.dex * this.mults.dexterity_exp);
|
||||
this.gainAgilityExp(retValue.agi * this.mults.agility_exp);
|
||||
this.gainCharismaExp(retValue.cha * this.mults.charisma_exp);
|
||||
this.gainIntelligenceExp(retValue.int);
|
||||
}
|
||||
|
||||
//Given a string expression like "str" or "strength", returns the given stat
|
||||
export function queryStatFromString(this: PlayerObject, str: string): number {
|
||||
const tempStr = str.toLowerCase();
|
||||
if (tempStr.includes("hack")) {
|
||||
return this.skills.hacking;
|
||||
}
|
||||
if (tempStr.includes("str")) {
|
||||
return this.skills.strength;
|
||||
}
|
||||
if (tempStr.includes("def")) {
|
||||
return this.skills.defense;
|
||||
}
|
||||
if (tempStr.includes("dex")) {
|
||||
return this.skills.dexterity;
|
||||
}
|
||||
if (tempStr.includes("agi")) {
|
||||
return this.skills.agility;
|
||||
}
|
||||
if (tempStr.includes("cha")) {
|
||||
return this.skills.charisma;
|
||||
}
|
||||
if (tempStr.includes("int")) {
|
||||
return this.skills.intelligence;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function startFocusing(this: PlayerObject): void {
|
||||
this.focus = true;
|
||||
}
|
||||
@@ -477,17 +272,6 @@ export function takeDamage(this: PlayerObject, amt: number): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
export function regenerateHp(this: IPerson, amt: number): void {
|
||||
if (typeof amt !== "number") {
|
||||
console.warn(`Player.regenerateHp() called without a numeric argument: ${amt}`);
|
||||
return;
|
||||
}
|
||||
this.hp.current += amt;
|
||||
if (this.hp.current > this.hp.max) {
|
||||
this.hp.current = this.hp.max;
|
||||
}
|
||||
}
|
||||
|
||||
export function hospitalize(this: PlayerObject): number {
|
||||
const cost = getHospitalizationCost();
|
||||
SnackbarEvents.emit(`You've been Hospitalized for ${numeralWrapper.formatMoney(cost)}`, ToastVariant.WARNING, 2000);
|
||||
@@ -1441,10 +1225,6 @@ export function giveAchievement(this: PlayerObject, achievementId: string): void
|
||||
}
|
||||
}
|
||||
|
||||
export function getIntelligenceBonus(this: PlayerObject, weight: number): number {
|
||||
return calculateIntelligenceBonus(this.skills.intelligence, weight);
|
||||
}
|
||||
|
||||
export function getCasinoWinnings(this: PlayerObject): number {
|
||||
return this.moneySourceA.casino;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user