mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-09 17:23:53 +01:00
MISC: Cancel infiltration when player is hospitalized (#1579)
This commit is contained in:
parent
440c074606
commit
9db1084b16
@ -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 }}>
|
||||||
|
7
src/PersonObjects/Player/PlayerEvents.ts
Normal file
7
src/PersonObjects/Player/PlayerEvents.ts
Normal file
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user