73 lines
1.9 KiB
C#
73 lines
1.9 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Quests
|
|
{
|
|
public enum QuestState
|
|
{
|
|
NotStarted,
|
|
InProgress,
|
|
Completed,
|
|
HandedIn
|
|
}
|
|
|
|
[System.Serializable]
|
|
public class Quest
|
|
{
|
|
public QuestData data;
|
|
public QuestState state;
|
|
public List<QuestObjective> objectives;
|
|
|
|
public bool IsAllObjectivesComplete
|
|
{
|
|
get
|
|
{
|
|
foreach (var obj in objectives)
|
|
{
|
|
if (!obj.IsComplete) return false;
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public Quest(QuestData data)
|
|
{
|
|
this.data = data;
|
|
this.state = QuestState.NotStarted;
|
|
this.objectives = new List<QuestObjective>();
|
|
|
|
if (data != null && data.objectives != null)
|
|
{
|
|
foreach (var objData in data.objectives)
|
|
{
|
|
objectives.Add(new QuestObjective(objData));
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool ProgressObjective(ObjectiveType type, string targetID, int amount = 1)
|
|
{
|
|
if (state != QuestState.InProgress) return false;
|
|
|
|
bool updatedAny = false;
|
|
foreach (var obj in objectives)
|
|
{
|
|
if (!obj.IsComplete && obj.data.objectiveType == type && obj.data.targetID == targetID)
|
|
{
|
|
obj.AddProgress(amount);
|
|
updatedAny = true;
|
|
Debug.Log($"[QuestSystem] Progress updated for '{data.title}': {obj.data.description} ({obj.currentAmount}/{obj.data.requiredAmount})");
|
|
}
|
|
}
|
|
|
|
if (updatedAny && IsAllObjectivesComplete)
|
|
{
|
|
state = QuestState.Completed;
|
|
Debug.Log($"[QuestSystem] Quest Completed: '{data.title}'!");
|
|
}
|
|
|
|
return updatedAny;
|
|
}
|
|
}
|
|
}
|