Define QuestService interface.

interface IQuestService {
    isSystemReady: boolean;
    quests: null | Map<number, IQuest>;
    addQuest(name: string, options?: {
        description?: string;
        onCompleted?: (() => void);
    }): IQuest;
    fire<T>(event: T, ...args?: any[]): EventHandler;
    getQuestById(id: number): null | IQuest;
    getQuestByName(name: string): null | IQuest;
    off<T>(event: T, listener: IQuestServiceEvents[T]): EventHandler;
    on<T>(event: T, listener: IQuestServiceEvents[T]): EventHandle;
    resetAllQuests(): void;
}

Hierarchy

  • EventHandlerMethods
    • IQuestService

Implemented by

Properties

isSystemReady: boolean

Whether the system is ready.

// The quest system might not be ready when the script is loaded.
if(questService.isSystemReady){
console.log('Quest system is ready', questService.quests);
} else {
questService.on('system:ready', () => {
console.log('Quest system is ready', questService.quests);
});
}
quests: null | Map<number, IQuest>

The information of all quests.

Methods

  • Planned

    Add a new quest.

    Parameters

    • name: string

      The name of the quest.

    • Optionaloptions: {
          description?: string;
          onCompleted?: (() => void);
      }

      Optional parameters.

      • Optionaldescription?: string

        The description of the quest.

      • OptionalonCompleted?: (() => void)

        Callback function triggered when the quest is completed.

          • (): void
          • Returns void

    Returns IQuest

    The quest object.

    const quest = questService.addQuest(
    'Quest 1',
    {
    description: 'This is a quest.',
    onCompleted: () => console.log('Quest 1 is completed.')
    }
    );
    quest.addCheckTask('Task 1: Move', {onCompleted: () => console.log('Task 1 is completed.')});
    quest.addProgressBarTask('Task 2: Jump 3 times', 3, {onCompleted: () => console.log('Task 2 is completed.')});
    quest.start();
  • Send a specific event.

    Type Parameters

    Parameters

    • event: T

      Event name

    • Optional Rest...args: any[]

      Event parameters

    Returns EventHandler

  • Planned

    Get a quest by ID.

    Parameters

    • id: number

      Quest ID.

    Returns null | IQuest

    The quest object.

  • Planned

    Get a quest by name. If there are multiple quests with the same name, the first one is returned.

    Parameters

    • name: string

      Quest name.

    Returns null | IQuest

    The quest object.

  • Unsubscribe from a specific event.

    Type Parameters

    Parameters

    Returns EventHandler

  • Subscribe to a specific event.

    Type Parameters

    Parameters

    Returns EventHandle

  • Planned

    Reset all quests.

    Returns void