112 lines
3.0 KiB
C#
112 lines
3.0 KiB
C#
using UnityEngine;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using EasyTalk.Nodes;
|
|
|
|
[CreateAssetMenu(fileName = "New Quest", menuName = "RPG/Quest")]
|
|
public class Quest : ScriptableObject
|
|
{
|
|
[Header("Basic Info")]
|
|
public string questId;
|
|
public string questName;
|
|
[TextArea(3, 5)]
|
|
public string description;
|
|
[TextArea(2, 4)]
|
|
public string summary;
|
|
|
|
[Header("Quest Properties")]
|
|
public int level = 1;
|
|
public bool isMainQuest = false;
|
|
public bool isRepeatable = false;
|
|
public Quest[] prerequisites;
|
|
|
|
[Header("Objectives")]
|
|
public List<QuestObjective> objectives = new List<QuestObjective>();
|
|
public string currentObjective; [Header("Rewards")]
|
|
public int experienceReward = 100;
|
|
public int goldReward = 50;
|
|
public string[] itemRewards;
|
|
|
|
// Runtime data (not serialized)
|
|
[System.NonSerialized]
|
|
public QuestStatus status = QuestStatus.NotStarted;
|
|
|
|
/// <summary>
|
|
/// Check if all required objectives are completed
|
|
/// </summary>
|
|
public bool AreRequiredObjectivesCompleted()
|
|
{
|
|
return objectives.Where(obj => !obj.isOptional).All(obj => obj.isCompleted);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Check if all objectives (including optional) are completed
|
|
/// </summary>
|
|
public bool AreAllObjectivesCompleted()
|
|
{
|
|
return objectives.All(obj => obj.isCompleted);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get overall quest progress percentage (0-1)
|
|
/// </summary>
|
|
public float GetProgressPercentage()
|
|
{
|
|
if (objectives.Count == 0) return 0f;
|
|
|
|
float totalProgress = objectives.Sum(obj => obj.GetProgressPercentage());
|
|
return totalProgress / objectives.Count;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get specific objective by ID
|
|
/// </summary>
|
|
public QuestObjective GetObjective(string objectiveId)
|
|
{
|
|
return objectives.FirstOrDefault(obj => obj.objectiveId == objectiveId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reset all objectives
|
|
/// </summary>
|
|
public void ResetObjectives()
|
|
{
|
|
foreach (var objective in objectives)
|
|
{
|
|
objective.Reset();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Validate quest data
|
|
/// </summary>
|
|
public bool IsValid()
|
|
{
|
|
if (string.IsNullOrEmpty(questId) || string.IsNullOrEmpty(questName))
|
|
return false;
|
|
|
|
if (objectives.Count == 0)
|
|
return false;
|
|
|
|
// Check for duplicate objective IDs
|
|
var objectiveIds = objectives.Select(obj => obj.objectiveId).ToList();
|
|
return objectiveIds.Count == objectiveIds.Distinct().Count();
|
|
}
|
|
|
|
public void GetCurrentObjective(out QuestObjective currentObjective, out int currentIndex)
|
|
{
|
|
currentObjective = null;
|
|
currentIndex = -1;
|
|
|
|
for (int i = 0; i < objectives.Count; i++)
|
|
{
|
|
if (!objectives[i].isCompleted)
|
|
{
|
|
currentObjective = objectives[i];
|
|
currentIndex = i;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|