QuestManager
This commit is contained in:
parent
89dbf9f8ff
commit
00fc43a564
|
|
@ -104,3 +104,33 @@ export class QuestEngine {
|
||||||
return this._status;
|
return this._status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class QuestManager {
|
||||||
|
private readonly engines: Map<string, QuestEngine>;
|
||||||
|
|
||||||
|
constructor(quests: Quest[], options: QuestRuntimeOptions) {
|
||||||
|
this.engines = new Map(quests.map(q => [q.id, new QuestEngine(q, options)]));
|
||||||
|
}
|
||||||
|
|
||||||
|
start(questId: string): void {
|
||||||
|
this.engines.get(questId)?.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
async checkAndAdvance(): Promise<void> {
|
||||||
|
for (const engine of this.engines.values()) {
|
||||||
|
await engine.checkAndAdvance();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getVariables(): RPGVariables {
|
||||||
|
const result: RPGVariables = {};
|
||||||
|
for (const engine of this.engines.values()) {
|
||||||
|
Object.assign(result, engine.getVariables());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
getEngine(questId: string): QuestEngine | undefined {
|
||||||
|
return this.engines.get(questId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue