Files
Babushka/scripts/CSharp/Common/QuestBehaviour/QuestFulfillmentBase.cs
T
2025-08-11 19:15:12 +02:00

46 lines
1.4 KiB
C#

using Godot;
using System;
using System.Linq;
using Babushka.scripts.CSharp.Common.Quest;
/// <summary>
/// Acts as a base for scripts to check for conditions to complete quests.
///
/// The derived Class is responsible for triggering the Check.
/// It is recommended to always check on QuestManager.Instance!.QuestsChanged
/// </summary>
public abstract partial class QuestFulfillmentBase : Node
{
[Export] private QuestResource _onActiveQuest;
[Export] private QuestResource _toNextQuest;
[Export] private bool _whenFulfilledSetActiveQuestToDone = true;
[Export] private bool _whenFulfilledSetNextQuestToActive = true;
[Export] private bool _whenFulfilledSetNextQuestToFollow = true;
[Signal] private delegate void OnFulfilledEventHandler();
protected void Fulfill()
{
if (_whenFulfilledSetActiveQuestToDone)
{
QuestManager.Instance!.ChangeQuestStatus(_onActiveQuest, QuestStatus.Status.Done);
}
if (_whenFulfilledSetNextQuestToActive)
{
QuestManager.Instance!.ChangeQuestStatus(_toNextQuest, QuestStatus.Status.Active);
}
if (_whenFulfilledSetNextQuestToFollow)
{
QuestManager.Instance!.SetFollowQuest(_toNextQuest);
}
EmitSignalOnFulfilled();
}
protected bool IsQuestActive()
{
return QuestManager.Instance!.GetActiveQuests().Any(q => q.Key == _onActiveQuest);
}
}