TRAVEL: Unify implementation for Player and Sleeves (and some followup for #1365) (#1439)

This commit is contained in:
Snarling 2024-06-26 16:46:50 -08:00 committed by GitHub
parent abdf5f52cd
commit b597746343
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 21 additions and 43 deletions

@ -51,6 +51,7 @@ export abstract class Person implements IPerson {
regenerateHp = personMethods.regenerateHp;
updateSkillLevels = personMethods.updateSkillLevels;
hasAugmentation = personMethods.hasAugmentation;
travel = personMethods.travel;
calculateSkill = calculateSkill; //Class version is equal to imported version
/** Reset all multipliers to 1 */

@ -1,8 +1,10 @@
import type { CityName } from "@enums";
import { Person } from "./Person";
import { calculateSkill } from "./formulas/skill";
import { currentNodeMults } from "../BitNode/BitNodeMultipliers";
import { Player } from "@player";
import { WorkStats } from "@nsdefs";
import { CONSTANTS } from "../Constants";
export function gainHackingExp(this: Person, exp: number): void {
if (isNaN(exp)) {
@ -167,3 +169,15 @@ export function hasAugmentation(this: Person, augName: string, ignoreQueued = fa
}
return false;
}
/** Travel to another City. Costs money from player regardless of which person is traveling */
export function travel(this: Person, cityName: CityName): boolean {
if (!Player.canAfford(CONSTANTS.TravelCost)) {
return false;
}
Player.loseMoney(CONSTANTS.TravelCost, "sleeves");
this.city = cityName;
return true;
}

@ -110,7 +110,6 @@ export class PlayerObject extends Person implements IPlayer {
startFocusing = generalMethods.startFocusing;
startGang = gangMethods.startGang;
takeDamage = generalMethods.takeDamage;
travel = generalMethods.travel;
giveExploit = generalMethods.giveExploit;
giveAchievement = generalMethods.giveAchievement;
getCasinoWinnings = generalMethods.getCasinoWinnings;

@ -28,8 +28,6 @@ import { Faction } from "../../Faction/Faction";
import { Factions } from "../../Faction/Factions";
import { FactionInvitationEvents } from "../../Faction/ui/FactionInvitationManager";
import { resetGangs } from "../../Gang/AllGangs";
import { Cities } from "../../Locations/Cities";
import { Locations } from "../../Locations/Locations";
import { Sleeve } from "../Sleeve/Sleeve";
import { SleeveWorkType } from "../Sleeve/Work/Work";
import { calculateSkillProgress as calculateSkillProgressF, ISkillProgress } from "../formulas/skill";
@ -532,26 +530,8 @@ export function gainCodingContractReward(
}
}
export function travel(this: PlayerObject, cityName: CityName): boolean {
if (Cities[cityName] == null) {
throw new Error(`Player.travel() was called with an invalid city: ${cityName}`);
}
if (!this.canAfford(CONSTANTS.TravelCost)) {
return false;
}
this.loseMoney(CONSTANTS.TravelCost, "other");
this.city = cityName;
return true;
}
export function gotoLocation(this: PlayerObject, to: LocationName): boolean {
if (Locations[to] == null) {
throw new Error(`Player.gotoLocation() was called with an invalid location: ${to}`);
}
this.location = to;
return true;
}

@ -44,7 +44,6 @@ import { SleeveCrimeWork } from "./Work/SleeveCrimeWork";
import * as sleeveMethods from "./SleeveMethods";
import { calculateIntelligenceBonus } from "../formulas/intelligence";
import { getEnumHelper } from "../../utils/EnumHelper";
import { Cities } from "../../Locations/Cities";
export class Sleeve extends Person implements SleevePerson {
currentWork: SleeveWork | null = null;
@ -255,21 +254,6 @@ export class Sleeve extends Person implements SleevePerson {
return true;
}
/** Travel to another City. Costs money from player */
travel(cityName: CityName): boolean {
if (Cities[cityName] == null) {
throw new Error(`Sleeve.travel() was called with an invalid city: ${cityName}`);
}
if (!Player.canAfford(CONSTANTS.TravelCost)) {
return false;
}
Player.loseMoney(CONSTANTS.TravelCost, "sleeves");
this.city = cityName;
return true;
}
tryBuyAugmentation(aug: Augmentation): boolean {
if (!Player.canAfford(aug.baseCost)) {
return false;

@ -9,16 +9,16 @@ import { Settings } from "../../../Settings/Settings";
import { dialogBoxCreate } from "../../../ui/React/DialogBox";
import { Modal } from "../../../ui/React/Modal";
interface IProps {
interface TravelModalProps {
open: boolean;
onClose: () => void;
sleeve: Sleeve;
rerender: () => void;
}
export function TravelModal(props: IProps): React.ReactElement {
function travel(city: string): void {
if (!props.sleeve.travel(city as CityName)) {
export function TravelModal(props: TravelModalProps): React.ReactElement {
function travel(city: CityName): void {
if (!props.sleeve.travel(city)) {
dialogBoxCreate("You cannot afford to have this sleeve travel to another city");
return;
}
@ -36,13 +36,13 @@ export function TravelModal(props: IProps): React.ReactElement {
also set your current sleeve task to idle.
</Typography>
{Settings.DisableASCIIArt ? (
Object.values(CityName).map((city: CityName) => (
Object.values(CityName).map((city) => (
<Button key={city} onClick={() => travel(city)}>
{city}
</Button>
))
) : (
<WorldMap currentCity={props.sleeve.city} onTravel={(city: CityName) => travel(city)} />
<WorldMap currentCity={props.sleeve.city} onTravel={travel} />
)}
</>
</Modal>