Skip to content

Commit

Permalink
prevent sightseeing mission duplication
Browse files Browse the repository at this point in the history
Player cannot accept twice sightseeing mission to a given object
  • Loading branch information
BarthPaleologue committed Sep 15, 2024
1 parent 2f50482 commit 6a4a04a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/ts/missions/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
}
2 changes: 1 addition & 1 deletion src/ts/ui/spaceStation/spaceStationMissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down

0 comments on commit 6a4a04a

Please sign in to comment.