diff --git a/src/ts/missions/mission.ts b/src/ts/missions/mission.ts index 6e2815a2..572e6bbe 100644 --- a/src/ts/missions/mission.ts +++ b/src/ts/missions/mission.ts @@ -20,14 +20,14 @@ export type MissionSerialized = { reward: number; }; -export class Mission implements Mission { - private readonly tree: MissionNode; +export class Mission { + readonly tree: MissionNode; - private readonly reward: number; + readonly reward: number; - private readonly missionGiver: SpaceStationModel; + readonly missionGiver: SpaceStationModel; - private readonly missionType: MissionType; + readonly missionType: MissionType; constructor(tree: MissionNode, reward: number, missionGiver: SpaceStationModel, missionType: MissionType) { this.tree = tree; @@ -41,11 +41,7 @@ export class Mission implements Mission { } equals(other: Mission): boolean { - return false; - } - - getMissionGiver(): SpaceStationModel { - return this.missionGiver; + return this.tree.equals(other.tree); } getReward(): number { diff --git a/src/ts/missions/nodes/actions/sightseeing/missionAsteroidFieldNode.ts b/src/ts/missions/nodes/actions/sightseeing/missionAsteroidFieldNode.ts index bd9c7898..84245353 100644 --- a/src/ts/missions/nodes/actions/sightseeing/missionAsteroidFieldNode.ts +++ b/src/ts/missions/nodes/actions/sightseeing/missionAsteroidFieldNode.ts @@ -1,6 +1,6 @@ import { MissionNode, MissionNodeSerialized, MissionNodeType } from "../../missionNode"; import { MissionContext } from "../../../missionContext"; -import { UniverseObjectId } from "../../../../saveFile/universeCoordinates"; +import { UniverseObjectId, universeObjectIdEquals } from "../../../../saveFile/universeCoordinates"; import { SeededStarSystemModel } from "../../../../starSystem/seededStarSystemModel"; import { SystemSeed } from "../../../../utils/systemSeed"; import { Vector3 } from "@babylonjs/core/Maths/math.vector"; @@ -45,6 +45,11 @@ export class MissionAsteroidFieldNode implements MissionNode { return this.state === AsteroidFieldMissionState.CLOSE_ENOUGH; } + equals(other: MissionNode): boolean { + if (!(other instanceof MissionAsteroidFieldNode)) return false; + return universeObjectIdEquals(this.objectId, other.objectId); + } + updateState(context: MissionContext) { if (this.isCompleted()) return; @@ -103,7 +108,7 @@ export class MissionAsteroidFieldNode implements MissionNode { return i18n.t("missions:sightseeing:describeAsteroidFieldTrek", { objectName: objectModel.name, systemName: systemModel.name, - distance: distance > 0 ? parseDistance(distance * Settings.LIGHT_YEAR): i18n.t("missions:common:here") + distance: distance > 0 ? parseDistance(distance * Settings.LIGHT_YEAR) : i18n.t("missions:common:here") }); } diff --git a/src/ts/missions/nodes/actions/sightseeing/missionFlyByNode.ts b/src/ts/missions/nodes/actions/sightseeing/missionFlyByNode.ts index 5929ff81..716cbf58 100644 --- a/src/ts/missions/nodes/actions/sightseeing/missionFlyByNode.ts +++ b/src/ts/missions/nodes/actions/sightseeing/missionFlyByNode.ts @@ -1,6 +1,6 @@ import { MissionNode, MissionNodeSerialized, MissionNodeType } from "../../missionNode"; import { MissionContext } from "../../../missionContext"; -import { UniverseObjectId } from "../../../../saveFile/universeCoordinates"; +import { UniverseObjectId, universeObjectIdEquals } from "../../../../saveFile/universeCoordinates"; import { SeededStarSystemModel } from "../../../../starSystem/seededStarSystemModel"; import { SystemSeed } from "../../../../utils/systemSeed"; import { Vector3 } from "@babylonjs/core/Maths/math.vector"; @@ -44,6 +44,11 @@ export class MissionFlyByNode implements MissionNode { return this.state === FlyByState.CLOSE_ENOUGH; } + equals(other: MissionNode): boolean { + if (!(other instanceof MissionFlyByNode)) return false; + return universeObjectIdEquals(this.objectId, other.objectId); + } + updateState(context: MissionContext) { if (this.isCompleted()) return; @@ -82,7 +87,7 @@ export class MissionFlyByNode implements MissionNode { return i18n.t("missions:sightseeing:describeFlyBy", { objectType: objectModel.typeName.toLowerCase(), systemName: systemModel.name, - distance: distance > 0 ? parseDistance(distance * Settings.LIGHT_YEAR): i18n.t("missions:common:here") + distance: distance > 0 ? parseDistance(distance * Settings.LIGHT_YEAR) : i18n.t("missions:common:here") }); } diff --git a/src/ts/missions/nodes/actions/sightseeing/missionTerminatorLandingNode.ts b/src/ts/missions/nodes/actions/sightseeing/missionTerminatorLandingNode.ts index 873ad950..e2e488b1 100644 --- a/src/ts/missions/nodes/actions/sightseeing/missionTerminatorLandingNode.ts +++ b/src/ts/missions/nodes/actions/sightseeing/missionTerminatorLandingNode.ts @@ -1,6 +1,6 @@ import { MissionNode, MissionNodeSerialized, MissionNodeType } from "../../missionNode"; import { MissionContext } from "../../../missionContext"; -import { UniverseObjectId } from "../../../../saveFile/universeCoordinates"; +import { UniverseObjectId, universeObjectIdEquals } from "../../../../saveFile/universeCoordinates"; import { SeededStarSystemModel } from "../../../../starSystem/seededStarSystemModel"; import { SystemSeed } from "../../../../utils/systemSeed"; import { Vector3 } from "@babylonjs/core/Maths/math.vector"; @@ -47,6 +47,11 @@ export class MissionTerminatorLandingNode implements MissionNode { return this.state === LandMissionState.LANDED; } + equals(other: MissionNode): boolean { + if (!(other instanceof MissionTerminatorLandingNode)) return false; + return universeObjectIdEquals(this.objectId, other.objectId); + } + updateState(context: MissionContext) { if (this.isCompleted()) return; @@ -111,7 +116,7 @@ export class MissionTerminatorLandingNode implements MissionNode { return i18n.t("missions:sightseeing:describeTerminatorLanding", { objectName: objectModel.name, systemName: systemModel.name, - distance: distance > 0 ? parseDistance(distance * Settings.LIGHT_YEAR): i18n.t("missions:common:here") + distance: distance > 0 ? parseDistance(distance * Settings.LIGHT_YEAR) : i18n.t("missions:common:here") }); } diff --git a/src/ts/missions/nodes/logic/missionAndNode.ts b/src/ts/missions/nodes/logic/missionAndNode.ts index 91deb177..fad63e48 100644 --- a/src/ts/missions/nodes/logic/missionAndNode.ts +++ b/src/ts/missions/nodes/logic/missionAndNode.ts @@ -6,7 +6,7 @@ import i18n from "../../../i18n"; export type MissionAndNodeSerialized = MissionNodeSerialized; export class MissionAndNode implements MissionNode { - public children: MissionNode[]; + readonly children: MissionNode[]; private hasCompletedLock = false; @@ -18,6 +18,15 @@ export class MissionAndNode implements MissionNode { return this.hasCompletedLock; } + equals(other: MissionNode): boolean { + if (!(other instanceof MissionAndNode)) return false; + if (this.children.length !== other.children.length) return false; + for (let i = 0; i < this.children.length; i++) { + if (!this.children[i].equals(other.children[i])) return false; + } + return true; + } + updateState(context: MissionContext) { if (this.hasCompletedLock) return; this.children.forEach((child) => child.updateState(context)); diff --git a/src/ts/missions/nodes/logic/missionOrNode.ts b/src/ts/missions/nodes/logic/missionOrNode.ts index 3f354745..c789cb83 100644 --- a/src/ts/missions/nodes/logic/missionOrNode.ts +++ b/src/ts/missions/nodes/logic/missionOrNode.ts @@ -6,7 +6,7 @@ import { SystemSeed } from "../../../utils/systemSeed"; export type MissionOrNodeSerialized = MissionNodeSerialized; export class MissionOrNode implements MissionNode { - public children: MissionNode[]; + readonly children: MissionNode[]; private hasCompletedLock = false; @@ -18,6 +18,15 @@ export class MissionOrNode implements MissionNode { return this.hasCompletedLock; } + equals(other: MissionNode): boolean { + if (!(other instanceof MissionOrNode)) return false; + if (this.children.length !== other.children.length) return false; + for (let i = 0; i < this.children.length; i++) { + if (!this.children[i].equals(other.children[i])) return false; + } + return true; + } + updateState(context: MissionContext) { if (this.hasCompletedLock) return; this.children.forEach((child) => child.updateState(context)); diff --git a/src/ts/missions/nodes/logic/missionSequenceNode.ts b/src/ts/missions/nodes/logic/missionSequenceNode.ts index 694255ff..c9fa936e 100644 --- a/src/ts/missions/nodes/logic/missionSequenceNode.ts +++ b/src/ts/missions/nodes/logic/missionSequenceNode.ts @@ -21,6 +21,15 @@ export class MissionSequenceNode implements MissionNode { return this.hasCompletedLock; } + equals(other: MissionNode): boolean { + if (!(other instanceof MissionSequenceNode)) return false; + if (this.children.length !== other.children.length) return false; + for (let i = 0; i < this.children.length; i++) { + if (!this.children[i].equals(other.children[i])) return false; + } + return true; + } + updateState(context: MissionContext) { if (this.hasCompletedLock) return; if (this.activeChildIndex >= this.children.length) return; diff --git a/src/ts/missions/nodes/logic/missionXorNode.ts b/src/ts/missions/nodes/logic/missionXorNode.ts index 1fb6b3a7..f6c9a873 100644 --- a/src/ts/missions/nodes/logic/missionXorNode.ts +++ b/src/ts/missions/nodes/logic/missionXorNode.ts @@ -5,7 +5,7 @@ import { SystemSeed } from "../../../utils/systemSeed"; export type MissionXorNodeSerialized = MissionNodeSerialized; export class MissionXorNode implements MissionNode { - public children: MissionNode[]; + readonly children: MissionNode[]; private hasCompletedLock = false; @@ -17,6 +17,15 @@ export class MissionXorNode implements MissionNode { return this.hasCompletedLock; } + equals(other: MissionNode): boolean { + if (!(other instanceof MissionXorNode)) return false; + if (this.children.length !== other.children.length) return false; + for (let i = 0; i < this.children.length; i++) { + if (!this.children[i].equals(other.children[i])) return false; + } + return true; + } + updateState(context: MissionContext) { if (this.hasCompletedLock) return; this.children.forEach((child) => child.updateState(context)); diff --git a/src/ts/missions/nodes/missionNode.ts b/src/ts/missions/nodes/missionNode.ts index b308cbf9..77267283 100644 --- a/src/ts/missions/nodes/missionNode.ts +++ b/src/ts/missions/nodes/missionNode.ts @@ -6,6 +6,8 @@ export interface MissionNode { updateState(context: MissionContext): void; + equals(other: MissionNode): boolean; + describe(originSeed: SystemSeed): string; describeNextTask(context: MissionContext): Promise;