Added Quest field

This commit is contained in:
jonathan
2025-08-11 19:15:12 +02:00
parent 6aa7530502
commit c96be7467e
12 changed files with 89 additions and 9 deletions
@@ -0,0 +1,37 @@
using Godot;
using System;
using Babushka.scripts.CSharp.Common.Farming;
using Babushka.scripts.CSharp.Common.Quest;
public partial class DetectFieldWork : QuestFulfillmentBase
{
private int wateredCounter = 0;
[Export] private int _wateringNeeded = 5;
public override void _EnterTree()
{
WateringCanState.OnWater += CountWater;
QuestManager.Instance!.QuestsChanged += CheckFieldWork;
}
public override void _ExitTree()
{
WateringCanState.OnWater -= CountWater;
QuestManager.Instance!.QuestsChanged -= CheckFieldWork;
}
public void CountWater()
{
wateredCounter++;
CheckFieldWork();
}
public void CheckFieldWork()
{
if (IsQuestActive() && wateredCounter >= _wateringNeeded)
{
Fulfill();
}
}
}
@@ -0,0 +1 @@
uid://bhbldab74vmhy
@@ -1,6 +0,0 @@
using Godot;
using System;
public partial class DetectToolCollection : Node
{
}
@@ -1 +0,0 @@
uid://caohn76m3n3nm
@@ -3,6 +3,12 @@ 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;
@@ -12,6 +18,8 @@ public abstract partial class QuestFulfillmentBase : Node
[Export] private bool _whenFulfilledSetNextQuestToActive = true;
[Export] private bool _whenFulfilledSetNextQuestToFollow = true;
[Signal] private delegate void OnFulfilledEventHandler();
protected void Fulfill()
{
if (_whenFulfilledSetActiveQuestToDone)
@@ -26,6 +34,8 @@ public abstract partial class QuestFulfillmentBase : Node
{
QuestManager.Instance!.SetFollowQuest(_toNextQuest);
}
EmitSignalOnFulfilled();
}
protected bool IsQuestActive()