mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-18 20:25:45 +01:00
INFILTRATION: Improve accuracy of slash game UI (#1422)
This commit is contained in:
parent
031b8b9cbb
commit
f162faf60a
@ -1013,9 +1013,9 @@ export const Augmentations: Record<AugmentationName, Augmentation> = (() => {
|
|||||||
moneyCost: 1e6,
|
moneyCost: 1e6,
|
||||||
info:
|
info:
|
||||||
"Extra-ocular neurons taken from old martial art master. Injecting them gives the user the ability to " +
|
"Extra-ocular neurons taken from old martial art master. Injecting them gives the user the ability to " +
|
||||||
"predict the enemy's attack before they even know it themselves.",
|
"predict the enemy's movement.",
|
||||||
stats:
|
stats:
|
||||||
"This augmentation makes the Slash minigame easier by showing you via an indicator when the slash is coming.",
|
"This augmentation makes the Slash minigame easier by showing you via an indicator when the sentinel is distracted.",
|
||||||
isSpecial: true,
|
isSpecial: true,
|
||||||
factions: [FactionName.ShadowsOfAnarchy],
|
factions: [FactionName.ShadowsOfAnarchy],
|
||||||
},
|
},
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Box, Paper, Typography } from "@mui/material";
|
import { Box, Paper, Typography } from "@mui/material";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { AugmentationName } from "@enums";
|
import { AugmentationName } from "@enums";
|
||||||
import { Player } from "@player";
|
import { Player } from "@player";
|
||||||
import { KEY } from "../../utils/helpers/keyCodes";
|
import { KEY } from "../../utils/helpers/keyCodes";
|
||||||
@ -27,34 +27,53 @@ const difficulties: {
|
|||||||
|
|
||||||
export function SlashGame({ difficulty, onSuccess, onFailure }: IMinigameProps): React.ReactElement {
|
export function SlashGame({ difficulty, onSuccess, onFailure }: IMinigameProps): React.ReactElement {
|
||||||
const [phase, setPhase] = useState(0);
|
const [phase, setPhase] = useState(0);
|
||||||
const [hasAugment, setHasAugment] = useState(false);
|
const timeOutId = useRef<number | ReturnType<typeof setTimeout>>(-1);
|
||||||
const [guardingTime, setGuardingTime] = useState(0);
|
const hasWKSharmonizer = Player.hasAugmentation(AugmentationName.WKSharmonizer, true);
|
||||||
|
const hasMightOfAres = Player.hasAugmentation(AugmentationName.MightOfAres, true);
|
||||||
|
|
||||||
useEffect(() => {
|
const data = useMemo(() => {
|
||||||
// Determine timeframes for game phase changes
|
// Determine time window of phases
|
||||||
const newDifficulty: Difficulty = { window: 0 };
|
const newDifficulty: Difficulty = { window: 0 };
|
||||||
interpolate(difficulties, difficulty, newDifficulty);
|
interpolate(difficulties, difficulty, newDifficulty);
|
||||||
const distractedTime =
|
const distractedTime = newDifficulty.window * (hasWKSharmonizer ? 1.3 : 1);
|
||||||
newDifficulty.window * (Player.hasAugmentation(AugmentationName.WKSharmonizer, true) ? 1.3 : 1);
|
|
||||||
const alertedTime = 250;
|
const alertedTime = 250;
|
||||||
const guardingTime = Math.random() * 3250 + 1500 - (distractedTime + alertedTime);
|
const guardingTime = Math.random() * 3250 + 1500 - (distractedTime + alertedTime);
|
||||||
|
|
||||||
// Set initial game state
|
return {
|
||||||
setPhase(0);
|
hasAugment: hasMightOfAres,
|
||||||
setGuardingTime(guardingTime);
|
guardingTime,
|
||||||
setHasAugment(Player.hasAugmentation(AugmentationName.MightOfAres, true));
|
distractedTime,
|
||||||
|
alertedTime,
|
||||||
|
};
|
||||||
|
}, [difficulty, hasWKSharmonizer, hasMightOfAres]);
|
||||||
|
|
||||||
// Setup timer for game phases
|
useEffect(() => {
|
||||||
let id = setTimeout(() => {
|
return () => {
|
||||||
|
if (timeOutId.current !== -1) {
|
||||||
|
clearTimeout(timeOutId.current);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const startPhase1 = useCallback(
|
||||||
|
(alertedTime: number, distractedTime: number) => {
|
||||||
setPhase(1);
|
setPhase(1);
|
||||||
id = setTimeout(() => {
|
timeOutId.current = setTimeout(() => {
|
||||||
setPhase(2);
|
setPhase(2);
|
||||||
id = setTimeout(() => onFailure(), alertedTime);
|
timeOutId.current = setTimeout(() => onFailure(), alertedTime);
|
||||||
}, distractedTime);
|
}, distractedTime);
|
||||||
}, guardingTime);
|
},
|
||||||
|
[onFailure],
|
||||||
|
);
|
||||||
|
|
||||||
return () => clearTimeout(id);
|
useEffect(() => {
|
||||||
}, [difficulty, onSuccess, onFailure]);
|
// Start the timer if the player does not have MightOfAres augmentation.
|
||||||
|
if (phase === 0 && !data.hasAugment) {
|
||||||
|
timeOutId.current = setTimeout(() => {
|
||||||
|
startPhase1(data.alertedTime, data.distractedTime);
|
||||||
|
}, data.guardingTime);
|
||||||
|
}
|
||||||
|
}, [phase, data, startPhase1]);
|
||||||
|
|
||||||
function press(this: Document, event: KeyboardEvent): void {
|
function press(this: Document, event: KeyboardEvent): void {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@ -76,10 +95,18 @@ export function SlashGame({ difficulty, onSuccess, onFailure }: IMinigameProps):
|
|||||||
Do not alert him!
|
Do not alert him!
|
||||||
</Typography>
|
</Typography>
|
||||||
<br />
|
<br />
|
||||||
{hasAugment && (
|
{phase === 0 && data.hasAugment && (
|
||||||
<Box sx={{ my: 1 }}>
|
<Box sx={{ my: 1 }}>
|
||||||
<Typography variant="h5">The sentinel will drop his guard and be distracted in ...</Typography>
|
<Typography variant="h5">The sentinel will drop his guard and be distracted in ...</Typography>
|
||||||
<GameTimer millis={guardingTime} onExpire={() => null} ignoreAugment_WKSharmonizer noPaper tick={20} />
|
<GameTimer
|
||||||
|
millis={data.guardingTime}
|
||||||
|
onExpire={() => {
|
||||||
|
startPhase1(data.alertedTime, data.distractedTime);
|
||||||
|
}}
|
||||||
|
ignoreAugment_WKSharmonizer
|
||||||
|
noPaper
|
||||||
|
tick={20}
|
||||||
|
/>
|
||||||
<br />
|
<br />
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
|
Loading…
Reference in New Issue
Block a user