gdquest-demos/godot-open-rpg

Quest system

guilhermehto opened this issue ยท 5 comments

This issue's objective is to create a system that allows:

  • Creation of quests by designers
  • Quest assignment to the player
  • Finishing quests

They should as of now, support two types of objectives for them:

  • Slaying monsters
  • Talking with NPC's

There can be N number of objectives per quests.

@nhydock if you have already implemented a quest system in your game, input would be appreciated ๐Ÿ˜ƒ

I've taken the "what works" vs the "best practices" approach in my game and just have a global event bus (autoload/singleton) associated with Quest progress. So things like NPCs can trigger quest processors within their execute script by doing something like

Quest.handle('npc.boss_character.defeated')

And then it just loops through all the quests in the game that are marked as active and incompleted. Each quest is just its own script/node with an on_event handler and they keep track of their own state and emit changes in their state and completion. Resetting and saving progress isn't bad, you can just define how each node serializes its state and loads it.

Agreed that you'll likely need something that's globally accessible so that NPCs can update this or that specific quest. Imagine NPCs that exist just for specific quest objectives, that appear in the game and disappear once the quest is over or after talking to them: you'd want all the quest related code to sit there, all in one place.

For achievements-like quests (looting X items, killing X enemies) though I'd rather stick to signals, otherwise you're going to end up with calls to QuestSystem everywhere in the codebase, making it likely to break everything if you want to change how the quest system works - and I'd bet that the system's design will evolve moving forward.

Thanks for the input!

And I'd bet that the system's design will evolve moving forward.

I'll leave the approach as is for now, when we run into these kinds of situation that you stated we can improve the system. I thought of having the QuestSystem as a singleton but for now it's sitting in the Game scene. If need be we can later autoload it without much effort. Though, having it as a singleton means that we'll have to access it through these NPCs to complete objectives, I'd rather have a system that works "alone", without needing to add more code to actors.

Though, having it as a singleton means that we'll have to access it through these NPCs to complete objectives

That's exactly the point, having all the quest-specific code from quest-specific NPCs all in one place. And still having more general quest update code use signals so you don't couple the quest system to the rest of the game. Anyway we can see if that's required later