Skip to content

Commit

Permalink
MISC: Cancel infiltration when player is hospitalized (bitburner-offi…
Browse files Browse the repository at this point in the history
  • Loading branch information
catloversg authored Aug 15, 2024
1 parent 440c074 commit 9db1084
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/Infiltration/ui/Game.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, Container, Paper, Typography } from "@mui/material";
import React, { useCallback, useState } from "react";
import React, { useCallback, useEffect, useState } from "react";
import { FactionName, ToastVariant } from "@enums";
import { Router } from "../../ui/GameRoot";
import { Page } from "../../ui/Router";
Expand All @@ -16,6 +16,8 @@ import { Victory } from "./Victory";
import { WireCuttingGame } from "./WireCuttingGame";
import { calculateDamageAfterFailingInfiltration } from "../utils";
import { SnackbarEvents } from "../../ui/React/Snackbar";
import { PlayerEventType, PlayerEvents } from "../../PersonObjects/Player/PlayerEvents";
import { dialogBoxCreate } from "../../ui/React/DialogBox";

type GameProps = {
StartingDifficulty: number;
Expand Down Expand Up @@ -151,6 +153,17 @@ export function Game(props: GameProps): React.ReactElement {
);
}

useEffect(() => {
const clearSubscription = PlayerEvents.subscribe((eventType) => {
if (eventType !== PlayerEventType.Hospitalized) {
return;
}
cancel();
dialogBoxCreate("Infiltration was cancelled because you were hospitalized");
});
return clearSubscription;
}, []);

return (
<Container>
<Paper sx={{ p: 1, mb: 1, display: "grid", justifyItems: "center", gap: 1 }}>
Expand Down
7 changes: 7 additions & 0 deletions src/PersonObjects/Player/PlayerEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { EventEmitter } from "../../utils/EventEmitter";

export enum PlayerEventType {
Hospitalized,
}

export const PlayerEvents = new EventEmitter<[PlayerEventType]>();
4 changes: 3 additions & 1 deletion src/PersonObjects/Player/PlayerObjectGeneralMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { isMember } from "../../utils/EnumHelper";
import { canAccessBitNodeFeature } from "../../BitNode/BitNodeUtils";
import { AlertEvents } from "../../ui/React/AlertManager";
import { Augmentations } from "../../Augmentation/Augmentations";
import { PlayerEventType, PlayerEvents } from "./PlayerEvents";

export function init(this: PlayerObject): void {
/* Initialize Player's home computer */
Expand Down Expand Up @@ -269,8 +270,9 @@ export function hospitalize(this: PlayerObject, suppressNotification: boolean):
this.loseMoney(cost, "hospitalization");
this.hp.current = this.hp.max;
if (!suppressNotification) {
SnackbarEvents.emit(`You've been Hospitalized for ${formatMoney(cost)}`, ToastVariant.SUCCESS, 2000);
SnackbarEvents.emit(`You've been hospitalized for ${formatMoney(cost)}`, ToastVariant.SUCCESS, 2000);
}
PlayerEvents.emit(PlayerEventType.Hospitalized);
return cost;
}

Expand Down

0 comments on commit 9db1084

Please sign in to comment.