2023-06-05 19:57:17 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Events;
|
|
|
|
namespace BITKit.SubSystems.Quest
|
|
|
|
{
|
2023-06-29 14:57:11 +08:00
|
|
|
public class QuestSystem
|
2023-06-05 19:57:17 +08:00
|
|
|
{
|
|
|
|
public enum State
|
|
|
|
{
|
|
|
|
None,
|
|
|
|
InProcess,
|
|
|
|
Complete,
|
|
|
|
Canceled,
|
|
|
|
}
|
|
|
|
public class Info
|
|
|
|
{
|
|
|
|
public static implicit operator Guid(Info self)
|
|
|
|
{
|
|
|
|
return self.id;
|
|
|
|
}
|
|
|
|
public static implicit operator string(Info self)
|
|
|
|
{
|
|
|
|
return self.name;
|
|
|
|
}
|
|
|
|
internal Info(string name, string description)
|
|
|
|
{
|
|
|
|
id = Guid.NewGuid();
|
|
|
|
this.name = name;
|
|
|
|
this.description = description;
|
|
|
|
}
|
|
|
|
public readonly Guid id;
|
|
|
|
public State state { get; internal set; }
|
|
|
|
public string name { get; internal set; }
|
|
|
|
public string description { get; internal set; }
|
|
|
|
//public List<Func<bool>> condition = new();
|
|
|
|
}
|
|
|
|
public static Dictionary<Guid, Info> quests { get; private set; } = new();
|
|
|
|
public static event Action<Info> OnQuestCreated;
|
|
|
|
public static event Action<Info> OnQuestCompleted;
|
|
|
|
public static event Action<Info> OnQuestCanceled;
|
|
|
|
public static Info Create(string name = "New Quest", string description = "Quest in progress")
|
|
|
|
{
|
|
|
|
Info info = new(name, description);
|
|
|
|
info.state = State.InProcess;
|
|
|
|
quests.Add(info, info);
|
|
|
|
OnQuestCreated?.Invoke(info);
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
public static void Complete(Info quest)
|
|
|
|
{
|
|
|
|
quest.state = State.Complete;
|
|
|
|
OnQuestCompleted?.Invoke(quest);
|
|
|
|
}
|
|
|
|
public static void Cancel(Info quest)
|
|
|
|
{
|
|
|
|
if (quests.ContainsKey(quest.id))
|
|
|
|
{
|
|
|
|
quests.Remove(quest.id);
|
|
|
|
quest.state = State.Canceled;
|
|
|
|
OnQuestCanceled?.Invoke(quest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
|
|
|
static void Reload()
|
|
|
|
{
|
|
|
|
quests.Clear();
|
|
|
|
OnQuestCreated = null;
|
|
|
|
OnQuestCompleted = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|