INFILTRATION: Improve accuracy of slash game UI (#1422)

This commit is contained in:
catloversg 2024-06-28 16:09:18 +07:00 committed by GitHub
parent 031b8b9cbb
commit f162faf60a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 49 additions and 22 deletions

@ -1013,9 +1013,9 @@ export const Augmentations: Record<AugmentationName, Augmentation> = (() => {
moneyCost: 1e6,
info:
"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:
"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,
factions: [FactionName.ShadowsOfAnarchy],
},

@ -1,5 +1,5 @@
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 { Player } from "@player";
import { KEY } from "../../utils/helpers/keyCodes";
@ -27,34 +27,53 @@ const difficulties: {
export function SlashGame({ difficulty, onSuccess, onFailure }: IMinigameProps): React.ReactElement {
const [phase, setPhase] = useState(0);
const [hasAugment, setHasAugment] = useState(false);
const [guardingTime, setGuardingTime] = useState(0);
const timeOutId = useRef<number | ReturnType<typeof setTimeout>>(-1);
const hasWKSharmonizer = Player.hasAugmentation(AugmentationName.WKSharmonizer, true);
const hasMightOfAres = Player.hasAugmentation(AugmentationName.MightOfAres, true);
useEffect(() => {
// Determine timeframes for game phase changes
const data = useMemo(() => {
// Determine time window of phases
const newDifficulty: Difficulty = { window: 0 };
interpolate(difficulties, difficulty, newDifficulty);
const distractedTime =
newDifficulty.window * (Player.hasAugmentation(AugmentationName.WKSharmonizer, true) ? 1.3 : 1);
const distractedTime = newDifficulty.window * (hasWKSharmonizer ? 1.3 : 1);
const alertedTime = 250;
const guardingTime = Math.random() * 3250 + 1500 - (distractedTime + alertedTime);
// Set initial game state
setPhase(0);
setGuardingTime(guardingTime);
setHasAugment(Player.hasAugmentation(AugmentationName.MightOfAres, true));
return {
hasAugment: hasMightOfAres,
guardingTime,
distractedTime,
alertedTime,
};
}, [difficulty, hasWKSharmonizer, hasMightOfAres]);
// Setup timer for game phases
let id = setTimeout(() => {
useEffect(() => {
return () => {
if (timeOutId.current !== -1) {
clearTimeout(timeOutId.current);
}
};
}, []);
const startPhase1 = useCallback(
(alertedTime: number, distractedTime: number) => {
setPhase(1);
id = setTimeout(() => {
timeOutId.current = setTimeout(() => {
setPhase(2);
id = setTimeout(() => onFailure(), alertedTime);
timeOutId.current = setTimeout(() => onFailure(), alertedTime);
}, distractedTime);
}, guardingTime);
},
[onFailure],
);
return () => clearTimeout(id);
}, [difficulty, onSuccess, onFailure]);
useEffect(() => {
// 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 {
event.preventDefault();
@ -76,10 +95,18 @@ export function SlashGame({ difficulty, onSuccess, onFailure }: IMinigameProps):
Do not alert him!
</Typography>
<br />
{hasAugment && (
{phase === 0 && data.hasAugment && (
<Box sx={{ my: 1 }}>
<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 />
</Box>
)}