mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2025-03-07 19:14:37 +01:00
INFILTRATION: Handle automated infiltration (#1414)
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { Button, Container, Paper, Typography } from "@mui/material";
|
||||
import React, { useCallback, useState } from "react";
|
||||
import { FactionName } from "@enums";
|
||||
import { FactionName, ToastVariant } from "@enums";
|
||||
import { Router } from "../../ui/GameRoot";
|
||||
import { Page } from "../../ui/Router";
|
||||
import { Player } from "@player";
|
||||
@ -15,6 +15,7 @@ import { SlashGame } from "./SlashGame";
|
||||
import { Victory } from "./Victory";
|
||||
import { WireCuttingGame } from "./WireCuttingGame";
|
||||
import { calculateDamageAfterFailingInfiltration } from "../utils";
|
||||
import { SnackbarEvents } from "../../ui/React/Snackbar";
|
||||
|
||||
type GameProps = {
|
||||
StartingDifficulty: number;
|
||||
@ -91,11 +92,18 @@ export function Game(props: GameProps): React.ReactElement {
|
||||
setStage(Stage.Countdown);
|
||||
pushResult(false);
|
||||
Player.receiveRumor(FactionName.ShadowsOfAnarchy);
|
||||
// Kill the player immediately if they use automation, so
|
||||
// it's clear they're not meant to
|
||||
const damage = options?.automated
|
||||
? Player.hp.current
|
||||
: calculateDamageAfterFailingInfiltration(props.StartingDifficulty);
|
||||
let damage = calculateDamageAfterFailingInfiltration(props.StartingDifficulty);
|
||||
// Kill the player immediately if they use automation, so it's clear they're not meant to
|
||||
if (options?.automated) {
|
||||
damage = Player.hp.current;
|
||||
setTimeout(() => {
|
||||
SnackbarEvents.emit(
|
||||
"You were hospitalized. Do not try to automate infiltration!",
|
||||
ToastVariant.WARNING,
|
||||
5000,
|
||||
);
|
||||
}, 500);
|
||||
}
|
||||
if (Player.takeDamage(damage)) {
|
||||
Router.toPage(Page.City);
|
||||
return;
|
||||
|
@ -1,16 +1,18 @@
|
||||
import React, { useEffect } from "react";
|
||||
|
||||
interface IProps {
|
||||
onKeyDown: (this: Document, event: KeyboardEvent) => void;
|
||||
onKeyDown: (event: KeyboardEvent) => void;
|
||||
onFailure: (options?: { automated: boolean }) => void;
|
||||
}
|
||||
|
||||
export function KeyHandler(props: IProps): React.ReactElement {
|
||||
useEffect(() => {
|
||||
function press(this: Document, event: KeyboardEvent): void {
|
||||
if (!event.isTrusted) return;
|
||||
const f = props.onKeyDown.bind(this);
|
||||
f(event);
|
||||
function press(event: KeyboardEvent): void {
|
||||
if (!event.isTrusted || !(event instanceof KeyboardEvent)) {
|
||||
props.onFailure({ automated: true });
|
||||
return;
|
||||
}
|
||||
props.onKeyDown(event);
|
||||
}
|
||||
document.addEventListener("keydown", press);
|
||||
return () => document.removeEventListener("keydown", press);
|
||||
|
Reference in New Issue
Block a user