LogoPixi’VN

Quests

The quest system is a way to create and manage quests in your game. Quests can have multiple stages, and players can complete them to earn rewards or progress in the story.

Initialize

To initialize a quest, create a new instance of the QuestBaseModel class (or your custom class) and add it to the game quest dictionary when the game is initialized.

It is recommended to import the instances at project startup, see the src/main.ts file.

To create a new instance of QuestBaseModel, you need the following parameters:

import { QuestBaseModel, RegisteredQuests, StageBaseModel } from "@drincs/nqtr";
import { orderProduct, takeProduct } from "../quests";
import { mcRoom, terrace } from "../rooms";

export const aliceQuest = new QuestBaseModel(
    "aliceQuest",
    [
        // stages
        new StageBaseModel("talk_alice1", {
            name: "Talk to Alice",
            description: "Talk to Alice on the terrace",
        }),
        new StageBaseModel("order_products", {
            onStart: () => {
                mcRoom.addActivity(orderProduct);
            },
            name: "Order products",
            description: "Order the products with your PC",
        }),
        new StageBaseModel("take_products", {
            onStart: (_, { notify }) => {
                terrace.addActivity(takeProduct);
                notify("You can take the products on the Terrace");
            },
            name: "Take products",
            description: "Take products on the Terrace",
            requestDescriptionToStart: "Wait for the products you ordered to arrive (2 day)",
            deltaDateRequired: 2,
        }),
        new StageBaseModel("talk_alice2", {
            name: "Talk to Alice",
            description: "Talk to Alice on the terrace",
        }),
    ],
    {
        // props
        name: "Help Alice",
        description:
            'To learn more about how the repo works, Talk to Alice. \nGoing when she is there will automatically start an "Event" (see aliceQuest.tsx to learn more). \nAfter that an action will be added to open the pc, in MC room. \n\n(during the quest you can talk to Alice and you will see her talking during the quests of the same Quest)',
        image: "alice_terrace0A",
        onStart: (quest, { notify, uiTransition }) => {
            notify(uiTransition("notify_quest_is_started", { quest: quest.name }));
        },
        onNextStage: (stage, { notify, uiTransition }) => {
            notify(uiTransition("notify_quest_is_updated", { quest: stage.name }));
        },
    }
);

RegisteredQuests.add(aliceQuest);

RegisteredQuests.add is required to save the quests in the game.

You can also create a function to load quests. The important thing is that it is called at least once before the quests are used in the game, otherwise they will not be available.

Start

To start a quest, you can use the start method of the Quest class. This method will set the current stage to the first stage of the quest and trigger the onStart action defined in the quest. This function has the following parameters:

  • props: the properties that will be passed to onStart. Its interface corresponds to OnRunProps.
import { newLabel } from "@drincs/pixi-vn";
import { aliceQuest } from "../values/quests";

const startLabel = newLabel("start", [
    async (props) => {
        await aliceQuest.start(props); 
    },
]);
export default startLabel;

Go next

To go to the next stage of a quest, you can use the goNext method of the Quest class. This method will set the current stage to the next stage of the quest and trigger the onNextStage action defined in the quest. This function has the following parameters:

  • props: the properties that will be passed to onNextStage. Its interface corresponds to OnRunProps.
import { newLabel } from "@drincs/pixi-vn";
import { aliceQuest } from "../values/quests";

const startLabel = newLabel("start", [
    async (props) => {
        await aliceQuest.goNext(props); 
    },
]);
export default startLabel;

Get

To get a quest by its id, use the RegisteredQuests.get function.

import { RegisteredQuests } from "@drincs/nqtr";

const aliceQuest = RegisteredQuests.get('aliceQuest');

Get all

To get all quests, use the RegisteredQuests.values function.

import { RegisteredQuests } from "@drincs/nqtr";

const quests = RegisteredQuests.values();

Custom class

Templates

In all templates, the Quest class is already defined in the file models/nqtr/Quest.ts. You can use it directly or modify it to suit your needs.

It is recommended to create your own class Quest that extends QuestStoredClass and "override" the interface QuestInterface to add, edit, or remove properties or methods.

For example, if you want to create a class Quest, you must "override" the interface QuestInterface to use your properties or methods. (See the file nqtr.d.ts)

Now you can create a class Quest that extends QuestStoredClass and implements the QuestInterface. (For more information on how to create a class in TypeScript, read the official documentation)

To create a property that stores its value in the game storage, you can create Getters/Setters and use the this.getStorageProperty() / this.setStorageProperty() methods. (See the file Quest.ts)

import { QuestInterface, QuestStoredClass, QuestStoredClassProps, StageInterface } from "@drincs/nqtr";

export default class Quest extends QuestStoredClass implements QuestInterface {
    constructor(
        id: string,
        _stages: StageInterface[],
        props: {
            name?: string;
            description?: string;
            image?: string;
            inDevelopment?: boolean;
        } & QuestStoredClassProps
    ) {
        super(id, _stages, props);
        this.name = props.name || "";
        this.description = props.description || "";
        this.image = props.image;
        this.inDevelopment = props.inDevelopment || false;
    }
    readonly name: string;
    readonly description: string;
    readonly image?: string;
    readonly inDevelopment: boolean;
}

FAQ