Player is now a Person

Use correct class inheritance, use class as type and remove IPlayer
This commit is contained in:
Snarling
2022-09-20 01:57:46 -04:00
parent 475a8812bb
commit c510e47885
24 changed files with 297 additions and 518 deletions
-33
View File
@@ -1,33 +0,0 @@
// Interface that represents either the player (PlayerObject) or
// a Sleeve. Used for functions that need to take in both.
import { IPlayerOwnedAugmentation } from "../Augmentation/PlayerOwnedAugmentation";
import { HP } from "./HP";
import { ITaskTracker } from "./ITaskTracker";
import { Multipliers } from "./Multipliers";
import { Skills } from "./Skills";
export interface IPerson {
hp: HP;
skills: Skills;
exp: Skills;
mults: Multipliers;
augmentations: IPlayerOwnedAugmentation[];
getIntelligenceBonus(weight: number): number;
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;
calculateSkill(exp: number, mult?: number): number;
takeDamage(amt: number): boolean;
regenerateHp: (amt: number) => void;
queryStatFromString: (str: string) => number;
whoAmI: () => string;
}
+18 -116
View File
@@ -1,18 +1,15 @@
import * as generalMethods from "./Player/PlayerObjectGeneralMethods";
import { Augmentation } from "../Augmentation/Augmentation";
import * as personMethods from "./PersonMethods";
import { IPlayerOwnedAugmentation } from "../Augmentation/PlayerOwnedAugmentation";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
import { CityName } from "../Locations/data/CityNames";
import { CONSTANTS } from "../Constants";
import { calculateSkill } from "./formulas/skill";
import { calculateIntelligenceBonus } from "./formulas/intelligence";
import { IPerson } from "./IPerson";
import { defaultMultipliers, mergeAugmentation } from "./Multipliers";
import { defaultMultipliers } from "./Multipliers";
import { Skills } from "./Skills";
import { HP } from "./HP";
import { IReviverValue } from "../utils/JSONReviver";
// Base class representing a person-like object
export abstract class Person implements IPerson {
export abstract class Person {
hp: HP = { current: 10, max: 10 };
skills: Skills = {
hacking: 1,
@@ -45,126 +42,31 @@ export abstract class Person implements IPerson {
*/
city: CityName = CityName.Sector12;
gainHackingExp = generalMethods.gainHackingExp;
gainStrengthExp = generalMethods.gainStrengthExp;
gainDefenseExp = generalMethods.gainDefenseExp;
gainDexterityExp = generalMethods.gainDexterityExp;
gainAgilityExp = generalMethods.gainAgilityExp;
gainCharismaExp = generalMethods.gainCharismaExp;
gainIntelligenceExp = generalMethods.gainIntelligenceExp;
gainStats = generalMethods.gainStats;
calculateSkill = generalMethods.calculateSkill;
regenerateHp = generalMethods.regenerateHp;
queryStatFromString = generalMethods.queryStatFromString;
/**
* Updates this object's multipliers for the given augmentation
*/
applyAugmentation(aug: Augmentation): void {
this.mults = mergeAugmentation(this.mults, aug.mults);
}
/**
* Given an experience amount and stat multiplier, calculates the
* stat level. Stat-agnostic (same formula for every stat)
*/
calculateStat(exp: number, mult = 1): number {
return calculateSkill(exp, mult);
}
/**
* Calculate and return the amount of faction reputation earned per cycle
* when doing Field Work for a faction
*/
getFactionFieldWorkRepGain(): number {
const t =
(0.9 *
(this.skills.hacking / CONSTANTS.MaxSkillLevel +
this.skills.strength / CONSTANTS.MaxSkillLevel +
this.skills.defense / CONSTANTS.MaxSkillLevel +
this.skills.dexterity / CONSTANTS.MaxSkillLevel +
this.skills.agility / CONSTANTS.MaxSkillLevel +
this.skills.charisma / CONSTANTS.MaxSkillLevel)) /
5.5;
return t * this.mults.faction_rep;
}
/**
* Calculate and return the amount of faction reputation earned per cycle
* when doing Hacking Work for a faction
*/
getFactionHackingWorkRepGain(): number {
return (this.skills.hacking / CONSTANTS.MaxSkillLevel) * this.mults.faction_rep;
}
/**
* Calculate and return the amount of faction reputation earned per cycle
* when doing Security Work for a faction
*/
getFactionSecurityWorkRepGain(): number {
const t =
(0.9 *
(this.skills.hacking / CONSTANTS.MaxSkillLevel +
this.skills.strength / CONSTANTS.MaxSkillLevel +
this.skills.defense / CONSTANTS.MaxSkillLevel +
this.skills.dexterity / CONSTANTS.MaxSkillLevel +
this.skills.agility / CONSTANTS.MaxSkillLevel)) /
4.5;
return t * this.mults.faction_rep;
}
gainHackingExp = personMethods.gainHackingExp;
gainStrengthExp = personMethods.gainStrengthExp;
gainDefenseExp = personMethods.gainDefenseExp;
gainDexterityExp = personMethods.gainDexterityExp;
gainAgilityExp = personMethods.gainAgilityExp;
gainCharismaExp = personMethods.gainCharismaExp;
gainIntelligenceExp = personMethods.gainIntelligenceExp;
gainStats = personMethods.gainStats;
regenerateHp = personMethods.regenerateHp;
queryStatFromString = personMethods.queryStatFromString;
updateSkillLevels = personMethods.updateSkillLevels;
calculateSkill = calculateSkill; //Class version is equal to imported version
/**
* Reset all multipliers to 1
*/
resetMultipliers(): void {
resetMultipliers() {
this.mults = defaultMultipliers();
}
/**
* Update all stat levels
*/
updateStatLevels(): void {
this.skills.hacking = Math.max(
1,
Math.floor(this.calculateStat(this.exp.hacking, this.mults.hacking * BitNodeMultipliers.HackingLevelMultiplier)),
);
this.skills.strength = Math.max(
1,
Math.floor(
this.calculateStat(this.exp.strength, this.mults.strength * BitNodeMultipliers.StrengthLevelMultiplier),
),
);
this.skills.defense = Math.max(
1,
Math.floor(this.calculateStat(this.exp.defense, this.mults.defense * BitNodeMultipliers.DefenseLevelMultiplier)),
);
this.skills.dexterity = Math.max(
1,
Math.floor(
this.calculateStat(this.exp.dexterity, this.mults.dexterity * BitNodeMultipliers.DexterityLevelMultiplier),
),
);
this.skills.agility = Math.max(
1,
Math.floor(this.calculateStat(this.exp.agility, this.mults.agility * BitNodeMultipliers.AgilityLevelMultiplier)),
);
this.skills.charisma = Math.max(
1,
Math.floor(
this.calculateStat(this.exp.charisma, this.mults.charisma * BitNodeMultipliers.CharismaLevelMultiplier),
),
);
const ratio: number = 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);
}
getIntelligenceBonus(weight: number): number {
return calculateIntelligenceBonus(this.skills.intelligence, weight);
}
abstract takeDamage(amt: number): boolean;
abstract whoAmI(): string;
abstract toJSON(): IReviverValue;
}
+199
View File
@@ -0,0 +1,199 @@
import { Person } from "./Person";
import { calculateSkill } from "./formulas/skill";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
import { Player } from "../Player";
import { ITaskTracker } from "./ITaskTracker";
export function gainHackingExp(this: Person, 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 = calculateSkill(
this.exp.hacking,
this.mults.hacking * BitNodeMultipliers.HackingLevelMultiplier,
);
}
export function gainStrengthExp(this: Person, 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 = calculateSkill(
this.exp.strength,
this.mults.strength * BitNodeMultipliers.StrengthLevelMultiplier,
);
}
export function gainDefenseExp(this: Person, 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 = calculateSkill(
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: Person, 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 = calculateSkill(
this.exp.dexterity,
this.mults.dexterity * BitNodeMultipliers.DexterityLevelMultiplier,
);
}
export function gainAgilityExp(this: Person, 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 = calculateSkill(
this.exp.agility,
this.mults.agility * BitNodeMultipliers.AgilityLevelMultiplier,
);
}
export function gainCharismaExp(this: Person, 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 = calculateSkill(
this.exp.charisma,
this.mults.charisma * BitNodeMultipliers.CharismaLevelMultiplier,
);
}
export function gainIntelligenceExp(this: Person, 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: Person, 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: Person, 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 regenerateHp(this: Person, 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 updateSkillLevels(this: Person): 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),
),
);
const ratio: number = 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);
}
+6 -47
View File
@@ -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;
}
+3 -2
View File
@@ -80,6 +80,7 @@ export class Sleeve extends Person {
this.shockRecovery();
}
applyAugmentation = sleeveMethods.applyAugmentation;
findPurchasableAugs = sleeveMethods.findPurchasableAugs;
shockBonus(): number {
@@ -147,7 +148,7 @@ export class Sleeve extends Person {
this.exp.charisma = 0;
this.applyAugmentation(aug);
this.augmentations.push({ name: aug.name, level: 1 });
this.updateStatLevels();
this.updateSkillLevels();
}
/**
@@ -161,7 +162,7 @@ export class Sleeve extends Person {
this.exp.dexterity = 0;
this.exp.agility = 0;
this.exp.charisma = 0;
this.updateStatLevels();
this.updateSkillLevels();
this.hp.current = this.hp.max;
// Reset task-related stuff
+8 -1
View File
@@ -6,10 +6,17 @@ import { Player } from "../../Player";
import { Augmentation } from "../../Augmentation/Augmentation";
import { StaticAugmentations } from "../../Augmentation/StaticAugmentations";
import { Factions } from "../../Faction/Factions";
import { Multipliers } from "../Multipliers";
import { mergeMultipliers, Multipliers } from "../Multipliers";
import { AugmentationNames } from "../../Augmentation/data/AugmentationNames";
import { getFactionAugmentationsFiltered } from "../../Faction/FactionHelpers";
/**
* Updates this object's multipliers for the given augmentation
*/
export function applyAugmentation(this: Sleeve, aug: Augmentation): void {
this.mults = mergeMultipliers(this.mults, aug.mults);
}
export function findPurchasableAugs(this: Sleeve): Augmentation[] {
// You can only purchase Augmentations that are actually available from
// your factions. I.e. you must be in a faction that has the Augmentation
+4 -4
View File
@@ -1,7 +1,7 @@
import { CONSTANTS } from "../../Constants";
import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
import { CalculateShareMult } from "../../NetworkShare/Share";
import { IPerson } from "../IPerson";
import { Person } from "../Person";
import { calculateIntelligenceBonus } from "./intelligence";
function mult(favor: number): number {
@@ -12,7 +12,7 @@ function mult(favor: number): number {
return favorMult * BitNodeMultipliers.FactionWorkRepGain;
}
export function getHackingWorkRepGain(p: IPerson, favor: number): number {
export function getHackingWorkRepGain(p: Person, favor: number): number {
return (
((p.skills.hacking + p.skills.intelligence / 3) / CONSTANTS.MaxSkillLevel) *
p.mults.faction_rep *
@@ -22,7 +22,7 @@ export function getHackingWorkRepGain(p: IPerson, favor: number): number {
);
}
export function getFactionSecurityWorkRepGain(p: IPerson, favor: number): number {
export function getFactionSecurityWorkRepGain(p: Person, favor: number): number {
const t =
(0.9 *
(p.skills.strength +
@@ -35,7 +35,7 @@ export function getFactionSecurityWorkRepGain(p: IPerson, favor: number): number
return t * p.mults.faction_rep * mult(favor) * calculateIntelligenceBonus(p.skills.intelligence, 1);
}
export function getFactionFieldWorkRepGain(p: IPerson, favor: number): number {
export function getFactionFieldWorkRepGain(p: Person, favor: number): number {
const t =
(0.9 *
(p.skills.strength +
+4
View File
@@ -1,3 +1,7 @@
/**
* Given an experience amount and stat multiplier, calculates the
* stat level. Stat-agnostic (same formula for every stat)
*/
export function calculateSkill(exp: number, mult = 1): number {
return Math.max(Math.floor(mult * (32 * Math.log(exp + 534.5) - 200)), 1);
}