Instakill player when automating infiltration

This commit is contained in:
David Edmondson 2021-08-21 15:00:00 -07:00
parent a564957092
commit 6cd7465b82
12 changed files with 25 additions and 12 deletions

1
.gitignore vendored

@ -1,3 +1,4 @@
.vscode
Changelog.txt Changelog.txt
Netburner.txt Netburner.txt
/doc/build /doc/build

@ -46,7 +46,7 @@ export function BackwardGame(props: IMinigameProps): React.ReactElement {
<GameTimer millis={timer} onExpire={props.onFailure} /> <GameTimer millis={timer} onExpire={props.onFailure} />
<Grid item xs={12}> <Grid item xs={12}>
<h1 className={"noselect"}>Type it backward</h1> <h1 className={"noselect"}>Type it backward</h1>
<KeyHandler onKeyDown={press} /> <KeyHandler onKeyDown={press} onFailure={props.onFailure} />
</Grid> </Grid>
<Grid item xs={6}> <Grid item xs={6}>
<p style={{transform: 'scaleX(-1)'}}>{answer}</p> <p style={{transform: 'scaleX(-1)'}}>{answer}</p>

@ -78,7 +78,7 @@ export function BracketGame(props: IMinigameProps): React.ReactElement {
<Grid item xs={12}> <Grid item xs={12}>
<h1 className={"noselect"}>Close the brackets</h1> <h1 className={"noselect"}>Close the brackets</h1>
<p style={{fontSize: '5em'}}>{`${left}${right}`}<BlinkingCursor /></p> <p style={{fontSize: '5em'}}>{`${left}${right}`}<BlinkingCursor /></p>
<KeyHandler onKeyDown={press} /> <KeyHandler onKeyDown={press} onFailure={props.onFailure} />
</Grid> </Grid>
</Grid>) </Grid>)
} }

@ -51,7 +51,7 @@ export function BribeGame(props: IMinigameProps): React.ReactElement {
<GameTimer millis={timer} onExpire={props.onFailure} /> <GameTimer millis={timer} onExpire={props.onFailure} />
<Grid item xs={12}> <Grid item xs={12}>
<h1>Say something nice about the guard.</h1> <h1>Say something nice about the guard.</h1>
<KeyHandler onKeyDown={press} /> <KeyHandler onKeyDown={press} onFailure={props.onFailure} />
</Grid> </Grid>
<Grid item xs={6}> <Grid item xs={6}>
<h2 style={{fontSize: "2em"}}></h2> <h2 style={{fontSize: "2em"}}></h2>

@ -47,7 +47,7 @@ export function CheatCodeGame(props: IMinigameProps): React.ReactElement {
<Grid item xs={12}> <Grid item xs={12}>
<h1 className={"noselect"}>Enter the Code!</h1> <h1 className={"noselect"}>Enter the Code!</h1>
<p style={{fontSize: '5em'}}>{code[index]}</p> <p style={{fontSize: '5em'}}>{code[index]}</p>
<KeyHandler onKeyDown={press} /> <KeyHandler onKeyDown={press} onFailure={props.onFailure} />
</Grid> </Grid>
</Grid>) </Grid>)
} }

@ -86,7 +86,7 @@ export function Cyberpunk2077Game(props: IMinigameProps): React.ReactElement {
return <span key={`${x}${y}`} style={{fontSize: fontSize, color: 'blue'}}>{cell}&nbsp;</span> return <span key={`${x}${y}`} style={{fontSize: fontSize, color: 'blue'}}>{cell}&nbsp;</span>
return <span key={`${x}${y}`} style={{fontSize: fontSize}}>{cell}&nbsp;</span> return <span key={`${x}${y}`} style={{fontSize: fontSize}}>{cell}&nbsp;</span>
})}</pre><br /></div>)} })}</pre><br /></div>)}
<KeyHandler onKeyDown={press} /> <KeyHandler onKeyDown={press} onFailure={props.onFailure} />
</Grid> </Grid>
</Grid>) </Grid>)
} }

@ -85,10 +85,13 @@ export function Game(props: IProps): React.ReactElement {
}) })
} }
function failure(): void { function failure(options?: { automated: boolean }): void {
setStage(Stage.Countdown); setStage(Stage.Countdown);
pushResult(false); pushResult(false);
if(props.Player.takeDamage(props.StartingDifficulty*3)) { // Kill the player immediately if they use automation, so
// it's clear they're not meant to
const damage = options?.automated ? props.Player.hp : props.StartingDifficulty*3;
if(props.Player.takeDamage(damage)) {
const menu = document.getElementById("mainmenu-container"); const menu = document.getElementById("mainmenu-container");
if(menu === null) throw new Error("mainmenu-container not found"); if(menu === null) throw new Error("mainmenu-container not found");
menu.style.visibility = "visible"; menu.style.visibility = "visible";

@ -1,5 +1,8 @@
export interface IMinigameProps { export interface IMinigameProps {
onSuccess: () => void; onSuccess: () => void;
onFailure: () => void; onFailure: (options?: {
/** Failed due to using untrusted events (automation) */
automated: boolean;
}) => void;
difficulty: number; difficulty: number;
} }

@ -2,6 +2,7 @@ import React, { useEffect } from 'react';
interface IProps { interface IProps {
onKeyDown: (event: React.KeyboardEvent<HTMLElement>) => void; onKeyDown: (event: React.KeyboardEvent<HTMLElement>) => void;
onFailure: (options?: { automated: boolean }) => void;
} }
export function KeyHandler(props: IProps): React.ReactElement { export function KeyHandler(props: IProps): React.ReactElement {
@ -9,7 +10,12 @@ export function KeyHandler(props: IProps): React.ReactElement {
useEffect(() => elem.focus()); useEffect(() => elem.focus());
function onKeyDown(event: React.KeyboardEvent<HTMLElement>): void { function onKeyDown(event: React.KeyboardEvent<HTMLElement>): void {
if(!event.isTrusted) return; console.log("isTrusted?", event.isTrusted)
if(!event.isTrusted) {
console.log("untrusted event!")
props.onFailure({ automated: true });
return;
}
props.onKeyDown(event); props.onKeyDown(event);
} }

@ -94,7 +94,7 @@ export function MinesweeperGame(props: IMinigameProps): React.ReactElement {
return <span key={x}>[&nbsp;]&nbsp;</span> return <span key={x}>[&nbsp;]&nbsp;</span>
} }
})}</pre><br /></div>)} })}</pre><br /></div>)}
<KeyHandler onKeyDown={press} /> <KeyHandler onKeyDown={press} onFailure={props.onFailure} />
</Grid> </Grid>
</Grid>) </Grid>)
} }

@ -54,7 +54,7 @@ export function SlashGame(props: IMinigameProps): React.ReactElement {
<Grid item xs={12}> <Grid item xs={12}>
<h1 className={"noselect"}>Slash when his guard is down!</h1> <h1 className={"noselect"}>Slash when his guard is down!</h1>
<p style={{fontSize: '5em'}}>{guarding ? "!Guarding!" : "!ATTACKING!"}</p> <p style={{fontSize: '5em'}}>{guarding ? "!Guarding!" : "!ATTACKING!"}</p>
<KeyHandler onKeyDown={press} /> <KeyHandler onKeyDown={press} onFailure={props.onFailure} />
</Grid> </Grid>
</Grid>) </Grid>)
} }

@ -111,7 +111,7 @@ export function WireCuttingGame(props: IMinigameProps): React.ReactElement {
})} })}
</pre> </pre>
</div>)} </div>)}
<KeyHandler onKeyDown={press} /> <KeyHandler onKeyDown={press} onFailure={props.onFailure} />
</Grid> </Grid>
</Grid>) </Grid>)
} }