From 6a4a04aec768c6dccbd16b79902d9f543c1dc0f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9lemy?= <31370477+BarthPaleologue@users.noreply.github.com> Date: Sun, 15 Sep 2024 14:43:52 +0200 Subject: [PATCH] prevent sightseeing mission duplication Player cannot accept twice sightseeing mission to a given object --- src/ts/missions/generator.ts | 8 ++++++-- src/ts/ui/spaceStation/spaceStationMissions.ts | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ts/missions/generator.ts b/src/ts/missions/generator.ts index d47cec793..763769683 100644 --- a/src/ts/missions/generator.ts +++ b/src/ts/missions/generator.ts @@ -5,8 +5,9 @@ import { SightSeeingMission, SightSeeingType } from "./sightSeeingMission"; import { uniformRandBool } from "extended-random"; import { BodyType } from "../architecture/bodyType"; import { SystemObjectType } from "../saveFile/universeCoordinates"; +import { Player } from "../player/player"; -export function generateSightseeingMissions(spaceStationModel: SpaceStationModel, timestampMillis: number): SightSeeingMission[] { +export function generateSightseeingMissions(spaceStationModel: SpaceStationModel, player: Player, timestampMillis: number): SightSeeingMission[] { const hours = Math.floor(timestampMillis / 1000 / 60 / 60); const starSystem = spaceStationModel.starSystem; @@ -63,5 +64,8 @@ export function generateSightseeingMissions(spaceStationModel: SpaceStationModel }); }); - return blackHoleFlyByMissions.concat(neutronStarFlyByMissions, anomalyFlyByMissions); + const allMissions = blackHoleFlyByMissions.concat(neutronStarFlyByMissions, anomalyFlyByMissions); + + // filter missions to avoid duplicates with already accepted missions of the player + return allMissions.filter((mission) => player.currentMissions.every((currentMission) => !mission.equals(currentMission))); } diff --git a/src/ts/ui/spaceStation/spaceStationMissions.ts b/src/ts/ui/spaceStation/spaceStationMissions.ts index 5eec24294..182a72d26 100644 --- a/src/ts/ui/spaceStation/spaceStationMissions.ts +++ b/src/ts/ui/spaceStation/spaceStationMissions.ts @@ -11,7 +11,7 @@ import { Player } from "../../player/player"; import { MissionContainer } from "./missionContainer"; export function generateMissionsDom(stationModel: SpaceStationModel, player: Player): HTMLDivElement { - const sightSeeingMissions = generateSightseeingMissions(stationModel, Date.now()); + const sightSeeingMissions = generateSightseeingMissions(stationModel, player, Date.now()); const starSystem = stationModel.starSystem; if (!(starSystem instanceof SeededStarSystemModel)) {