You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.5 KiB
46 lines
1.5 KiB
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 _onAvailableQuest = null!;
|
|
[Export] private QuestResource _toNextQuest = null!;
|
|
|
|
[Export] private bool _whenFulfilledSetAvailableQuestToDone = true;
|
|
[Export] private bool _whenFulfilledSetNextQuestToAvailable = true;
|
|
[Export] private bool _whenFulfilledSetNextQuestToActive = true;
|
|
|
|
[Signal] private delegate void OnFulfilledEventHandler();
|
|
|
|
protected void Fulfill()
|
|
{
|
|
if (_whenFulfilledSetAvailableQuestToDone)
|
|
{
|
|
QuestManager.Instance!.ChangeQuestStatus(_onAvailableQuest, QuestStatus.Status.Done);
|
|
}
|
|
if (_whenFulfilledSetNextQuestToAvailable)
|
|
{
|
|
QuestManager.Instance!.ChangeQuestStatus(_toNextQuest, QuestStatus.Status.Available);
|
|
}
|
|
if (_whenFulfilledSetNextQuestToActive)
|
|
{
|
|
QuestManager.Instance!.SetActiveQuest(_toNextQuest);
|
|
}
|
|
|
|
EmitSignalOnFulfilled();
|
|
}
|
|
|
|
protected bool IsQuestActive()
|
|
{
|
|
return QuestManager.Instance!.GetAvailableQuests().Any(q => q.Key == _onAvailableQuest);
|
|
}
|
|
}
|