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
3 changed files with 24 additions and 2 deletions
+14 -1
View File
@@ -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";
@@ -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;
@@ -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 }}>