fix augmentation side effect for bribe game

fix double tick for wire cutting game
This commit is contained in:
phyzical 2022-03-26 10:50:28 +08:00
parent a0d845ffae
commit d94f391dc6
2 changed files with 33 additions and 17 deletions

@ -50,9 +50,23 @@ export function BribeGame(props: IMinigameProps): React.ReactElement {
const hasAugment = Player.hasAugmentation(AugmentationNames.AmuletOfPersuasion, true);
if (hasAugment) {
upColor = correctIndex < index ? upColor : disabledColor;
downColor = correctIndex > index ? upColor : disabledColor;
choiceColor = correctIndex == index ? Settings.theme.success : disabledColor;
const upIndex = index + 1 >= choices.length ? 0 : index + 1;
let upDistance = correctIndex - upIndex;
if (upIndex > correctIndex) {
upDistance = choices.length - 1 - upIndex + correctIndex;
}
const downIndex = index - 1 < 0 ? choices.length - 1 : index - 1;
let downDistance = downIndex - correctIndex;
if (downIndex < correctIndex) {
downDistance = downIndex + choices.length - 1 - correctIndex;
}
const onCorrectIndex = correctIndex == index;
upColor = upDistance <= downDistance && !onCorrectIndex ? upColor : disabledColor;
downColor = upDistance >= downDistance && !onCorrectIndex ? downColor : disabledColor;
choiceColor = onCorrectIndex ? defaultColor : disabledColor;
}
function press(this: Document, event: KeyboardEvent): void {

@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useEffect, useState } from "react";
import Grid from "@mui/material/Grid";
import Typography from "@mui/material/Typography";
import { IMinigameProps } from "./IMinigameProps";
@ -70,6 +70,21 @@ export function WireCuttingGame(props: IMinigameProps): React.ReactElement {
return questions.some((q) => q.shouldCut(wires[wireNum - 1], wireNum - 1));
}
useEffect(() => {
// check if we won
const wiresToBeCut = [];
for (let j = 0; j < wires.length; j++) {
let shouldBeCut = false;
for (let i = 0; i < questions.length; i++) {
shouldBeCut = shouldBeCut || questions[i].shouldCut(wires[j], j);
}
wiresToBeCut.push(shouldBeCut);
}
if (wiresToBeCut.every((b, i) => b === cutWires[i])) {
props.onSuccess();
}
}, [cutWires]);
function press(this: Document, event: KeyboardEvent): void {
event.preventDefault();
const wireNum = parseInt(event.key);
@ -82,19 +97,6 @@ export function WireCuttingGame(props: IMinigameProps): React.ReactElement {
props.onFailure();
}
// check if we won
const wiresToBeCut = [];
for (let j = 0; j < wires.length; j++) {
let shouldBeCut = false;
for (let i = 0; i < questions.length; i++) {
shouldBeCut = shouldBeCut || questions[i].shouldCut(wires[j], j);
}
wiresToBeCut.push(shouldBeCut);
}
if (wiresToBeCut.every((b, i) => b === next[i])) {
props.onSuccess();
}
return next;
});
}