mwg API
    Preparing search index...

    Class QuestLog

    Tracks which stage every known quest is on, against GameState's existing switches and variables - not a storage mechanism of its own. A quest's definition (its stages, its prerequisites) is static game content, supplied once, the same way the dungeon example's ITEMS table is; only which stage each quest has reached is what gets saved.

    import { QuestLog, GameState } from '@datamoc/mw_games/rpg';

    const state = new GameState();
    const quests = new QuestLog();
    quests.define({ id: 'rats', stages: [{ counter: { variable: 'ratsKilled', target: 5 } }] });

    quests.track('rats');
    state.setVariable('ratsKilled', 5);
    quests.advanceStage('rats', state); // true - the counter stage is satisfied

    console.log(quests.status('rats')); // 'complete'
    Index
    • Moves a quest on if its current stage's condition or counter is now satisfied.

      A game calls this after anything that might have finished a stage - an event, a kill, picking up an item - the same way EventRunner re-checks activePage rather than being told directly when to move on. A single call advances at most one stage, even if the next one would also already be satisfied; call it again (a fresh turn, a fresh check) to walk through several at once.

      Named advanceStage rather than advance, because everything else called advance in this framework ticks a clock forward by whole turns (TurnClock, Charges, Field, Barrier, AbilityCycle). This advances a quest through its stage list, which is not time passing at all, and sharing the word made both harder to read.

      Parameters

      Returns boolean

      true if a stage (or the whole quest) completed this call

    • whether every prerequisite is already complete, so the quest could be started

      Parameters

      • id: string

      Returns boolean

    • the stage a quest is currently on; null once complete or before it has started

      Parameters

      • id: string

      Returns QuestStage | null

    • Derives what an NPC tied to ids currently has to offer - see QuestMarker. Checking several ids at once covers an NPC that gives one quest and takes in another.

      Parameters

      Returns QuestMarker

    • progress, 0 to 1, towards the current stage's counter; null for a condition stage

      Parameters

      Returns number | null

    • begins a quest; throws if a prerequisite is not yet complete

      Parameters

      • id: string

      Returns void

    • Returns { stageIndex: [string, number][]; tracked: string | null }

    • marks id as the quest a game currently guides the player towards; null to clear it

      Parameters

      • id: string | null

      Returns void

    • where the tracked quest's current stage is satisfied, if it says anywhere at all

      Returns { map?: string; x: number; y: number } | null

    • the currently tracked quest id, or null if none is tracked or it is no longer active

      Returns string | null

    • rebuilds a log from save data - definitions are supplied fresh, the same as ITEMS

      Parameters

      • definitions: QuestDefinition[]
      • data: { stageIndex: [string, number][]; tracked?: string | null }

      Returns QuestLog