MISC: Cancel infiltration when player is hospitalized (#1579)

This commit is contained in:
catloversg 2024-08-15 12:20:17 +07:00 committed by GitHub
parent 440c074606
commit 9db1084b16
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 24 additions and 2 deletions

@ -1,5 +1,5 @@
import { Button, Container, Paper, Typography } from "@mui/material"; 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 { FactionName, ToastVariant } from "@enums";
import { Router } from "../../ui/GameRoot"; import { Router } from "../../ui/GameRoot";
import { Page } from "../../ui/Router"; import { Page } from "../../ui/Router";
@ -16,6 +16,8 @@ import { Victory } from "./Victory";
import { WireCuttingGame } from "./WireCuttingGame"; import { WireCuttingGame } from "./WireCuttingGame";
import { calculateDamageAfterFailingInfiltration } from "../utils"; import { calculateDamageAfterFailingInfiltration } from "../utils";
import { SnackbarEvents } from "../../ui/React/Snackbar"; import { SnackbarEvents } from "../../ui/React/Snackbar";
import { PlayerEventType, PlayerEvents } from "../../PersonObjects/Player/PlayerEvents";
import { dialogBoxCreate } from "../../ui/React/DialogBox";
type GameProps = { type GameProps = {
StartingDifficulty: number; StartingDifficulty: number;
@ -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 ( return (
<Container> <Container>
<Paper sx={{ p: 1, mb: 1, display: "grid", justifyItems: "center", gap: 1 }}> <Paper sx={{ p: 1, mb: 1, display: "grid", justifyItems: "center", gap: 1 }}>

@ -0,0 +1,7 @@
import { EventEmitter } from "../../utils/EventEmitter";
export enum PlayerEventType {
Hospitalized,
}
export const PlayerEvents = new EventEmitter<[PlayerEventType]>();

@ -52,6 +52,7 @@ import { isMember } from "../../utils/EnumHelper";
import { canAccessBitNodeFeature } from "../../BitNode/BitNodeUtils"; import { canAccessBitNodeFeature } from "../../BitNode/BitNodeUtils";
import { AlertEvents } from "../../ui/React/AlertManager"; import { AlertEvents } from "../../ui/React/AlertManager";
import { Augmentations } from "../../Augmentation/Augmentations"; import { Augmentations } from "../../Augmentation/Augmentations";
import { PlayerEventType, PlayerEvents } from "./PlayerEvents";
export function init(this: PlayerObject): void { export function init(this: PlayerObject): void {
/* Initialize Player's home computer */ /* Initialize Player's home computer */
@ -269,8 +270,9 @@ export function hospitalize(this: PlayerObject, suppressNotification: boolean):
this.loseMoney(cost, "hospitalization"); this.loseMoney(cost, "hospitalization");
this.hp.current = this.hp.max; this.hp.current = this.hp.max;
if (!suppressNotification) { 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; return cost;
} }