2022-09-20 07:57:46 +02:00
|
|
|
import { Person } from "./Person";
|
|
|
|
import { calculateSkill } from "./formulas/skill";
|
2023-06-16 23:52:42 +02:00
|
|
|
import { currentNodeMults } from "../BitNode/BitNodeMultipliers";
|
2022-10-10 00:42:14 +02:00
|
|
|
import { Player } from "@player";
|
2022-12-30 02:28:53 +01:00
|
|
|
import { WorkStats } from "@nsdefs";
|
2022-09-20 07:57:46 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-06-16 23:52:42 +02:00
|
|
|
this.skills.hacking = calculateSkill(this.exp.hacking, this.mults.hacking * currentNodeMults.HackingLevelMultiplier);
|
2022-09-20 07:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2023-06-16 23:52:42 +02:00
|
|
|
this.mults.strength * currentNodeMults.StrengthLevelMultiplier,
|
2022-09-20 07:57:46 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-06-16 23:52:42 +02:00
|
|
|
this.skills.defense = calculateSkill(this.exp.defense, this.mults.defense * currentNodeMults.DefenseLevelMultiplier);
|
2022-09-20 07:57:46 +02:00
|
|
|
const ratio = this.hp.current / this.hp.max;
|
2022-11-10 04:06:27 +01:00
|
|
|
this.hp.max = Math.floor(10 + this.skills.defense / 10);
|
|
|
|
this.hp.current = Math.round(this.hp.max * ratio);
|
2022-09-20 07:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2023-06-16 23:52:42 +02:00
|
|
|
this.mults.dexterity * currentNodeMults.DexterityLevelMultiplier,
|
2022-09-20 07:57:46 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-06-16 23:52:42 +02:00
|
|
|
this.skills.agility = calculateSkill(this.exp.agility, this.mults.agility * currentNodeMults.AgilityLevelMultiplier);
|
2022-09-20 07:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2023-06-16 23:52:42 +02:00
|
|
|
this.mults.charisma * currentNodeMults.CharismaLevelMultiplier,
|
2022-09-20 07:57:46 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
2022-10-11 14:25:16 +02:00
|
|
|
export function gainStats(this: Person, retValue: WorkStats): void {
|
|
|
|
this.gainHackingExp(retValue.hackExp * this.mults.hacking_exp);
|
|
|
|
this.gainStrengthExp(retValue.strExp * this.mults.strength_exp);
|
|
|
|
this.gainDefenseExp(retValue.defExp * this.mults.defense_exp);
|
|
|
|
this.gainDexterityExp(retValue.dexExp * this.mults.dexterity_exp);
|
|
|
|
this.gainAgilityExp(retValue.agiExp * this.mults.agility_exp);
|
|
|
|
this.gainCharismaExp(retValue.chaExp * this.mults.charisma_exp);
|
|
|
|
this.gainIntelligenceExp(retValue.intExp);
|
2022-09-20 07:57:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//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,
|
2023-06-16 23:52:42 +02:00
|
|
|
Math.floor(this.calculateSkill(this.exp.hacking, this.mults.hacking * currentNodeMults.HackingLevelMultiplier)),
|
2022-09-20 07:57:46 +02:00
|
|
|
);
|
|
|
|
this.skills.strength = Math.max(
|
|
|
|
1,
|
2023-06-16 23:52:42 +02:00
|
|
|
Math.floor(this.calculateSkill(this.exp.strength, this.mults.strength * currentNodeMults.StrengthLevelMultiplier)),
|
2022-09-20 07:57:46 +02:00
|
|
|
);
|
|
|
|
this.skills.defense = Math.max(
|
|
|
|
1,
|
2023-06-16 23:52:42 +02:00
|
|
|
Math.floor(this.calculateSkill(this.exp.defense, this.mults.defense * currentNodeMults.DefenseLevelMultiplier)),
|
2022-09-20 07:57:46 +02:00
|
|
|
);
|
|
|
|
this.skills.dexterity = Math.max(
|
|
|
|
1,
|
|
|
|
Math.floor(
|
2023-06-16 23:52:42 +02:00
|
|
|
this.calculateSkill(this.exp.dexterity, this.mults.dexterity * currentNodeMults.DexterityLevelMultiplier),
|
2022-09-20 07:57:46 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
this.skills.agility = Math.max(
|
|
|
|
1,
|
2023-06-16 23:52:42 +02:00
|
|
|
Math.floor(this.calculateSkill(this.exp.agility, this.mults.agility * currentNodeMults.AgilityLevelMultiplier)),
|
2022-09-20 07:57:46 +02:00
|
|
|
);
|
|
|
|
this.skills.charisma = Math.max(
|
|
|
|
1,
|
2023-06-16 23:52:42 +02:00
|
|
|
Math.floor(this.calculateSkill(this.exp.charisma, this.mults.charisma * currentNodeMults.CharismaLevelMultiplier)),
|
2022-09-20 07:57:46 +02:00
|
|
|
);
|
|
|
|
|
2023-01-03 08:13:01 +01:00
|
|
|
const ratio: number = Math.min(this.hp.current / this.hp.max, 1);
|
|
|
|
this.hp.max = Math.floor(10 + this.skills.defense / 10);
|
|
|
|
this.hp.current = Math.round(this.hp.max * ratio);
|
2022-09-20 07:57:46 +02:00
|
|
|
}
|
2022-09-27 19:20:42 +02:00
|
|
|
|
2022-09-27 21:14:34 +02:00
|
|
|
export function hasAugmentation(this: Person, augName: string, ignoreQueued = false) {
|
2022-10-04 23:55:35 +02:00
|
|
|
if (this.augmentations.some((a) => a.name === augName)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (!ignoreQueued && this.queuedAugmentations.some((a) => a.name === augName)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2022-09-27 19:20:42 +02:00
|
|
|
}
|