From 23f193c8eb433a8ea29b15dfc006be6c31afcaaf Mon Sep 17 00:00:00 2001 From: catloversg <152669316+catloversg@users.noreply.github.com> Date: Sun, 4 Aug 2024 14:04:06 +0700 Subject: [PATCH] MISC: Remove unnecessary dependency in Person class (#1534) --- src/PersonObjects/Person.ts | 19 ++++++++++--------- src/PersonObjects/Player/PlayerObject.ts | 6 +++++- src/PersonObjects/Sleeve/Sleeve.ts | 5 +++++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/PersonObjects/Person.ts b/src/PersonObjects/Person.ts index 37852bd6a..7abe6df02 100644 --- a/src/PersonObjects/Person.ts +++ b/src/PersonObjects/Person.ts @@ -1,16 +1,16 @@ -import type { Skills } from "./Skills"; -import type { HP } from "./HP"; import type { Person as IPerson, WorkStats } from "@nsdefs"; +import type { PlayerOwnedAugmentation } from "../Augmentation/PlayerOwnedAugmentation"; +import type { IReviverValue } from "../utils/JSONReviver"; +import type { MoneySource } from "../utils/MoneySourceTracker"; +import type { HP } from "./HP"; +import type { Skills } from "./Skills"; import { CityName } from "@enums"; -import { PlayerOwnedAugmentation } from "../Augmentation/PlayerOwnedAugmentation"; -import { calculateSkill } from "./formulas/skill"; -import { defaultMultipliers } from "./Multipliers"; -import { IReviverValue } from "../utils/JSONReviver"; import { currentNodeMults } from "../BitNode/BitNodeMultipliers"; -import { Player } from "../Player"; import { CONSTANTS } from "../Constants"; -import { PlayerObject } from "./Player/PlayerObject"; +import { Player } from "../Player"; +import { defaultMultipliers } from "./Multipliers"; +import { calculateSkill } from "./formulas/skill"; // Base class representing a person-like object export abstract class Person implements IPerson { @@ -226,7 +226,7 @@ export abstract class Person implements IPerson { return false; } - Player.loseMoney(CONSTANTS.TravelCost, this instanceof PlayerObject ? "other" : "sleeves"); + Player.loseMoney(CONSTANTS.TravelCost, this.travelCostMoneySource()); this.city = cityName; return true; @@ -239,6 +239,7 @@ export abstract class Person implements IPerson { this.mults = defaultMultipliers(); } + abstract travelCostMoneySource(): MoneySource; abstract takeDamage(amt: number): boolean; abstract whoAmI(): string; abstract toJSON(): IReviverValue; diff --git a/src/PersonObjects/Player/PlayerObject.ts b/src/PersonObjects/Player/PlayerObject.ts index df8cf8970..5e1eb07c4 100644 --- a/src/PersonObjects/Player/PlayerObject.ts +++ b/src/PersonObjects/Player/PlayerObject.ts @@ -19,7 +19,7 @@ import * as workMethods from "./PlayerObjectWorkMethods"; import { setPlayer } from "@player"; import { CompanyName, FactionName, JobName, LocationName } from "@enums"; import { HashManager } from "../../Hacknet/HashManager"; -import { MoneySourceTracker } from "../../utils/MoneySourceTracker"; +import { type MoneySource, MoneySourceTracker } from "../../utils/MoneySourceTracker"; import { constructorsForReviver, Generic_toJSON, Generic_fromJSON, IReviverValue } from "../../utils/JSONReviver"; import { JSONMap, JSONSet } from "../../Types/Jsonable"; import { cyrb53 } from "../../utils/StringHelperFunctions"; @@ -163,6 +163,10 @@ export class PlayerObject extends Person implements IPlayer { this.lastAugReset = this.lastNodeReset = Date.now(); } + travelCostMoneySource(): MoneySource { + return "other"; + } + whoAmI(): string { return "Player"; } diff --git a/src/PersonObjects/Sleeve/Sleeve.ts b/src/PersonObjects/Sleeve/Sleeve.ts index bc4d5e07a..0f56f63df 100644 --- a/src/PersonObjects/Sleeve/Sleeve.ts +++ b/src/PersonObjects/Sleeve/Sleeve.ts @@ -48,6 +48,7 @@ import { Multipliers, mergeMultipliers } from "../Multipliers"; import { getFactionAugmentationsFiltered } from "../../Faction/FactionHelpers"; import { Augmentations } from "../../Augmentation/Augmentations"; import { getAugCost } from "../../Augmentation/AugmentationHelpers"; +import type { MoneySource } from "../../utils/MoneySourceTracker"; export class Sleeve extends Person implements SleevePerson { currentWork: SleeveWork | null = null; @@ -529,6 +530,10 @@ export class Sleeve extends Person implements SleevePerson { return false; } + travelCostMoneySource(): MoneySource { + return "sleeves"; + } + takeDamage(amt: number): boolean { if (typeof amt !== "number") { console.warn(`Player.takeDamage() called without a numeric argument: ${amt}`);