diff --git a/src/Infiltration/ui/Victory.tsx b/src/Infiltration/ui/Victory.tsx index 7e0a9041e..4e2389905 100644 --- a/src/Infiltration/ui/Victory.tsx +++ b/src/Infiltration/ui/Victory.tsx @@ -26,9 +26,19 @@ interface IProps { MaxLevel: number; } +// Use a module-scope variable to save the faction choice. +let defaultFactionChoice: FactionName | "none" = "none"; + export function Victory(props: IProps): React.ReactElement { - const defaultFaction = isFactionWork(Player.currentWork) ? Player.currentWork.factionName : "none"; - const [factionName, setFactionName] = useState(defaultFaction); + /** + * Use the working faction as the default choice in 2 cases: + * - The player has not chosen a faction. + * - The current default choice is not in the faction list. It may happen after the player "prestiges". + */ + if (defaultFactionChoice === "none" || !Player.factions.includes(defaultFactionChoice)) { + defaultFactionChoice = isFactionWork(Player.currentWork) ? Player.currentWork.factionName : "none"; + } + const [factionName, setFactionName] = useState(defaultFactionChoice); function quitInfiltration(): void { handleInfiltrators(); @@ -48,8 +58,11 @@ export function Victory(props: IProps): React.ReactElement { } function trade(): void { - if (!getEnumHelper("FactionName").isMember(factionName)) return; + if (!getEnumHelper("FactionName").isMember(factionName)) { + return; + } Factions[factionName].playerReputation += repGain; + defaultFactionChoice = factionName; quitInfiltration(); } @@ -81,7 +94,7 @@ export function Victory(props: IProps): React.ReactElement { -