Page 1 of 1
Prevent QuestJournal from adding the same Quest
Posted: Fri Jul 29, 2022 2:46 pm
by keattikorn
How can I prevent quest being added to the QuestJournal that has already contained the quest being added.
Prevent QuestJournal from adding the same Quest
Posted: Fri Jul 29, 2022 3:35 pm
by Tony Li
Hi,
How are you adding the quest?
A Quest Giver's dialogue UI won't offer a quest if either of these are true:
1. The player already has an active hand-written quest with the same ID.
2. Or the player already has a procedurally-generated quest with the same target and action (e.g., "kill" + "orcs").
If you're manually calling QuestGiver.GiveQuestToQuester() in C#, you can do a similar check before calling that method.
Alternatively, if you want to block it on the QuestJournal side, you can make a subclass of QuestJournal that overrides AddQuest(Quest). Something like:
Code: Select all
public class MyQuestJournal : QuestJournal
{
public void AddQuest(Quest quest)
{
if (/* player already has same quest according to your criteria */)
{
Quest.DestroyInstance(quest);
}
else
{
base.AddQuest(quest);
}
}
}
Re: Prevent QuestJournal from adding the same Quest
Posted: Sat Jul 30, 2022 12:07 am
by keattikorn
I do add quest by scripting following your article on add quest by script.
At the moment I check the duplication by checking the quest ID being added.
however, these issues are still have to be addressed.
- the identical 2 quests still can be added if I add a quest as an Action on a successful node "Give Quest to Quester", this action does not check for duplication. Although, the duplication is fine on a QuestJournal component and the journal can be saved to disk successfully with the duplication (I have already inspected the saved JSON content). However, when it is time to load the saved game back, I can see from the load save game mechanic that it uses quest ID as a key in a dictionary, therefore, the result of the duplicated quests in the saved game will not be loaded properly (only one quest will be loaded).
- another issue is that when the quest is completed or abandoned, it is still in the journal database, this can have the issue that the new quest instance cannot be added because the quest with the same ID (although it is completed or abandoned) is being added.
Code: Select all
var questInstance = m_QuestBeingAdded.Clone();
if (!m_QuestJournal.ContainsQuest(questInstance.id))
{
// Add the copy to the quester and activate it:
var questerTextInfo = new QuestParticipantTextInfo(
m_QuestJournal.id, m_QuestJournal.displayName, m_QuestJournal.image, null);
questInstance.AssignQuester(questerTextInfo);
questInstance.timesAccepted = 1;
m_QuestJournal.deletedStaticQuests.Remove(StringField.GetStringValue(questInstance.id));
m_QuestJournal.AddQuest(questInstance);
questInstance.SetState(QuestState.Active);
QuestMachineMessages.RefreshUIs(questInstance);
}
Re: Prevent QuestJournal from adding the same Quest
Posted: Sat Jul 30, 2022 8:42 am
by Tony Li
Hi,
Since you're adding the quest manually (by script and/or by quest action), you'll need to check if the quest is already in the journal. If the quest is in the journal but completed or abandoned, delete it using QuestJournal.DeleteQuest(). If you're using a quest action, you can subclass GiveQuestToQuesterQuestAction and override the Execute() method to check.
If you want the quest journal to always remove quests them when are completed or abandoned, UNtick the Quest Journal component's Save Settings > Remember Completed Quests.
If you only want specific quests to remove themselves from the journal when completed or abandoned, inspect the quest in the Quest Editor window. In the main quest info section, tick Delete When Complete.
Re: Prevent QuestJournal from adding the same Quest
Posted: Sat Jul 30, 2022 11:01 am
by keattikorn
Thanks for your answer. I will try your solution.
Re: Prevent QuestJournal from adding the same Quest
Posted: Sat Jul 30, 2022 2:33 pm
by Tony Li
Glad to help!