Les pénalités ne se suivent pas d'une tentative à une autre
This commit is contained in:
parent
979362d012
commit
cb1222d9cf
@ -101,7 +101,7 @@ export default function GameProvider({ children }: { children: ReactNode }) {
|
||||
const activeChallenge: ChallengeAction | undefined = challengeActions
|
||||
.find(challengeAction => challengeAction.penaltyStart && challengeAction.penaltyEnd
|
||||
&& challengeAction.penaltyStart <= now && now <= challengeAction.penaltyEnd)
|
||||
if (!activeChallenge || !game.currentRunner)
|
||||
if (!activeChallenge || !game.currentRunner || game.runId !== activeChallenge.runId)
|
||||
updatePenalty({ penaltyStart: null, penaltyEnd: null })
|
||||
else if (activeChallenge && (activeChallenge.penaltyStart !== game.penaltyStart || activeChallenge.penaltyEnd)) {
|
||||
updatePenalty({ penaltyStart: activeChallenge.penaltyStart, penaltyEnd: activeChallenge.penaltyEnd })
|
||||
|
@ -9,6 +9,7 @@ export interface ChallengeAction {
|
||||
end: number | null, // date
|
||||
penaltyStart: number | null, // date
|
||||
penaltyEnd: number | null, // date
|
||||
runId: number,
|
||||
}
|
||||
|
||||
export interface ActionsState {
|
||||
@ -28,6 +29,7 @@ export interface ChallengeActionPayload {
|
||||
end: string | null,
|
||||
penaltyStart: string | null,
|
||||
penaltyEnd: string | null,
|
||||
runId: number,
|
||||
}
|
||||
|
||||
export interface ChallengeActionsPayload {
|
||||
@ -51,6 +53,7 @@ export const challengeActionsSlice = createSlice({
|
||||
end: dlChallenge.action.end ? new Date(dlChallenge.action.end).getTime() : null,
|
||||
penaltyStart: dlChallenge.action.penaltyStart ? new Date(dlChallenge.action.penaltyStart).getTime() : null,
|
||||
penaltyEnd: dlChallenge.action.penaltyEnd ? new Date(dlChallenge.action.penaltyEnd).getTime() : null,
|
||||
runId: dlChallenge.action.runId,
|
||||
})
|
||||
}
|
||||
state.challengeActions.sort((c1, c2) => c2.id - c1.id)
|
||||
|
@ -22,6 +22,7 @@ export interface PenaltyPayload {
|
||||
|
||||
export interface GameState {
|
||||
playerId: number | null
|
||||
runId: number | null
|
||||
gameStarted: boolean
|
||||
money: number
|
||||
currentRunner: boolean
|
||||
@ -33,6 +34,7 @@ export interface GameState {
|
||||
|
||||
const initialState: GameState = {
|
||||
playerId: null,
|
||||
runId: null,
|
||||
gameStarted: false,
|
||||
money: 0,
|
||||
currentRunner: false,
|
||||
@ -58,6 +60,7 @@ export const gameSlice = createSlice({
|
||||
updateGameState: (state, action: PayloadAction<GamePayload>) => {
|
||||
const game: GamePayload = action.payload
|
||||
state.gameStarted = game.started
|
||||
state.runId = game.currentRunId
|
||||
state.currentRunner = state.playerId === game.currentRun?.runnerId
|
||||
if (state.currentRunner)
|
||||
state.chaseFreeTime = null
|
||||
|
Loading…
Reference in New Issue
Block a user