bitburner-src/src/PersonObjects/Person.ts

173 lines
5.0 KiB
TypeScript
Raw Normal View History

import * as generalMethods from "./Player/PlayerObjectGeneralMethods";
import { Augmentation } from "../Augmentation/Augmentation";
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";
2022-07-18 09:31:17 +02:00
import { defaultMultipliers, mergeMultipliers } from "./Multipliers";
// Base class representing a person-like object
export abstract class Person implements IPerson {
2021-09-05 01:09:30 +02:00
/**
* Stats
*/
2022-05-21 00:18:42 +02:00
hacking = 1;
strength = 1;
defense = 1;
dexterity = 1;
agility = 1;
charisma = 1;
intelligence = 0;
hp = 10;
max_hp = 10;
2021-09-05 01:09:30 +02:00
/**
* Experience
*/
2022-05-21 00:18:42 +02:00
hacking_exp = 0;
strength_exp = 0;
defense_exp = 0;
dexterity_exp = 0;
agility_exp = 0;
charisma_exp = 0;
intelligence_exp = 0;
2022-07-15 00:43:33 +02:00
mults = defaultMultipliers();
2021-09-05 01:09:30 +02:00
/**
* Augmentations
*/
2022-05-21 00:18:42 +02:00
augmentations: IPlayerOwnedAugmentation[] = [];
2021-09-05 01:09:30 +02:00
/**
* City that the person is in
*/
city: CityName = CityName.Sector12;
2022-05-21 00:18:42 +02:00
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;
2022-04-14 21:28:13 +02:00
2021-09-05 01:09:30 +02:00
/**
* Updates this object's multipliers for the given augmentation
*/
applyAugmentation(aug: Augmentation): void {
2022-07-15 00:43:33 +02:00
this.mults = mergeMultipliers(this.mults, aug.mults);
2021-09-05 01:09:30 +02:00
}
2021-09-05 01:09:30 +02:00
/**
* 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);
}
2021-09-05 01:09:30 +02:00
/**
* Calculate and return the amount of faction reputation earned per cycle
* when doing Field Work for a faction
*/
getFactionFieldWorkRepGain(): number {
const t =
(0.9 *
2021-11-05 22:12:52 +01:00
(this.hacking / CONSTANTS.MaxSkillLevel +
2021-09-05 01:09:30 +02:00
this.strength / CONSTANTS.MaxSkillLevel +
this.defense / CONSTANTS.MaxSkillLevel +
this.dexterity / CONSTANTS.MaxSkillLevel +
this.agility / CONSTANTS.MaxSkillLevel +
this.charisma / CONSTANTS.MaxSkillLevel)) /
5.5;
2022-07-15 00:43:33 +02:00
return t * this.mults.faction_rep;
2021-09-05 01:09:30 +02:00
}
/**
* Calculate and return the amount of faction reputation earned per cycle
* when doing Hacking Work for a faction
*/
getFactionHackingWorkRepGain(): number {
2022-07-15 00:43:33 +02:00
return (this.hacking / CONSTANTS.MaxSkillLevel) * this.mults.faction_rep;
2021-09-05 01:09:30 +02:00
}
/**
* Calculate and return the amount of faction reputation earned per cycle
* when doing Security Work for a faction
*/
getFactionSecurityWorkRepGain(): number {
const t =
(0.9 *
2021-11-05 22:12:52 +01:00
(this.hacking / CONSTANTS.MaxSkillLevel +
2021-09-05 01:09:30 +02:00
this.strength / CONSTANTS.MaxSkillLevel +
this.defense / CONSTANTS.MaxSkillLevel +
this.dexterity / CONSTANTS.MaxSkillLevel +
this.agility / CONSTANTS.MaxSkillLevel)) /
4.5;
2022-07-15 00:43:33 +02:00
return t * this.mults.faction_rep;
2021-09-05 01:09:30 +02:00
}
/**
* Reset all multipliers to 1
*/
resetMultipliers(): void {
2022-07-15 00:43:33 +02:00
this.mults = defaultMultipliers();
2021-09-05 01:09:30 +02:00
}
/**
* Update all stat levels
*/
updateStatLevels(): void {
2021-11-05 22:12:52 +01:00
this.hacking = Math.max(
2021-09-05 01:09:30 +02:00
1,
2022-07-15 00:43:33 +02:00
Math.floor(this.calculateStat(this.hacking_exp, this.mults.hacking * BitNodeMultipliers.HackingLevelMultiplier)),
2021-09-05 01:09:30 +02:00
);
this.strength = Math.max(
1,
Math.floor(
2022-07-15 00:43:33 +02:00
this.calculateStat(this.strength_exp, this.mults.strength * BitNodeMultipliers.StrengthLevelMultiplier),
2021-09-05 01:09:30 +02:00
),
);
this.defense = Math.max(
1,
2022-07-15 00:43:33 +02:00
Math.floor(this.calculateStat(this.defense_exp, this.mults.defense * BitNodeMultipliers.DefenseLevelMultiplier)),
2021-09-05 01:09:30 +02:00
);
this.dexterity = Math.max(
1,
Math.floor(
2022-07-15 00:43:33 +02:00
this.calculateStat(this.dexterity_exp, this.mults.dexterity * BitNodeMultipliers.DexterityLevelMultiplier),
2021-09-05 01:09:30 +02:00
),
);
this.agility = Math.max(
1,
2022-07-15 00:43:33 +02:00
Math.floor(this.calculateStat(this.agility_exp, this.mults.agility * BitNodeMultipliers.AgilityLevelMultiplier)),
2021-09-05 01:09:30 +02:00
);
this.charisma = Math.max(
1,
Math.floor(
2022-07-15 00:43:33 +02:00
this.calculateStat(this.charisma_exp, this.mults.charisma * BitNodeMultipliers.CharismaLevelMultiplier),
2021-09-05 01:09:30 +02:00
),
);
const ratio: number = this.hp / this.max_hp;
this.max_hp = Math.floor(10 + this.defense / 10);
this.hp = Math.round(this.max_hp * ratio);
}
getIntelligenceBonus(weight: number): number {
return calculateIntelligenceBonus(this.intelligence, weight);
}
abstract takeDamage(amt: number): boolean;
abstract whoAmI(): string;
}