more updates

* added more keycodes constant support
* implemented new faction mechanics for mini games
* more small refactors
This commit is contained in:
phyzical
2022-03-23 22:31:56 +08:00
parent 4e73e489ed
commit 0b171822df
16 changed files with 236 additions and 97 deletions
+14 -3
View File
@@ -3,9 +3,19 @@ import Grid from "@mui/material/Grid";
import { IMinigameProps } from "./IMinigameProps";
import { KeyHandler } from "./KeyHandler";
import { GameTimer } from "./GameTimer";
import { random, getArrow } from "../utils";
import {
random,
getArrow,
getInverseArrow,
leftArrowSymbol,
rightArrowSymbol,
upArrowSymbol,
downArrowSymbol,
} from "../utils";
import { interpolate } from "./Difficulty";
import Typography from "@mui/material/Typography";
import { AugmentationNames } from "../../Augmentation/data/AugmentationNames";
import { Player } from "../../Player";
interface Difficulty {
[key: string]: number;
@@ -32,10 +42,11 @@ export function CheatCodeGame(props: IMinigameProps): React.ReactElement {
const timer = difficulty.timer;
const [code] = useState(generateCode(difficulty));
const [index, setIndex] = useState(0);
const hasAugment = Player.hasAugmentation(AugmentationNames.LameSharkRepository, true);
function press(this: Document, event: KeyboardEvent): void {
event.preventDefault();
if (code[index] !== getArrow(event)) {
if (code[index] !== getArrow(event) || (hasAugment && getInverseArrow(event))) {
props.onFailure();
return;
}
@@ -56,7 +67,7 @@ export function CheatCodeGame(props: IMinigameProps): React.ReactElement {
}
function generateCode(difficulty: Difficulty): string {
const arrows = ["←", "→", "↑", "↓"];
const arrows = [leftArrowSymbol, rightArrowSymbol, upArrowSymbol, downArrowSymbol];
let code = "";
for (let i = 0; i < random(difficulty.min, difficulty.max); i++) {
let arrow = arrows[Math.floor(4 * Math.random())];