using System; using System.Collections.Generic; using Adventurer.Runtime; using Core.Runtime; using Item.Runtime; using Newtonsoft.Json; using UnityEngine; namespace Quests.Runtime { [Serializable] public class QuestClass { #region Getters and Setters public Guid ID { get { return _id; } } public string Name { get { return _name; } set { _name = value; } } [JsonIgnore] public string Description { get { return _description; } set { _description = value; } } [JsonIgnore] public string Objective { get { return _objective; } set { _objective = value; } } [JsonIgnore] public int Duration { get { return _duration; } set { _duration = value; } } [JsonIgnore] public QuestDifficultyEnum Difficulty { get { return _difficulty; } set { _difficulty = value; } } [JsonIgnore] public List Rewards { get { return _rewards; } set { _rewards = value ?? new List(); } } public QuestStateEnum State { get { return _state; } set { _state = value; } } [JsonIgnore] public int MinLevel { get { return _minLevel; } set { _minLevel = value; } } public List AssignedAdventurersID { get { return _assignedAdventurersID; } set { _assignedAdventurersID = value; } } public int StartSeconds { get { return _StartSeconds; } set { _StartSeconds = value; } } public int EndSeconds { get { return _endSeconds; } set { _endSeconds = value; } } [JsonIgnore] public QuestEventPackSO EventPack { get { return _eventPack; } set { _eventPack = value; } } [JsonIgnore] public List ActiveEvents => _activeEvents; [JsonIgnore] public List TriggeredEventsDescriptionKeys = new List(); #endregion #region Parameters [SerializeField] string _name; [SerializeField] string _description; [SerializeField] string _objective; [SerializeField] int _duration; [SerializeField] QuestDifficultyEnum _difficulty; [SerializeField] List _rewards; [SerializeField] int _minLevel; [SerializeField] QuestEventPackSO _eventPack; Guid _id; QuestStateEnum _state; int _StartSeconds; int _endSeconds; List _assignedAdventurersID = new List(); List _activeEvents = new List(); #endregion #region Constructor public QuestClass(Guid id, string name, string description, string objective, int duration, QuestDifficultyEnum difficulty, List reward, int minLevel = 1) { _id = id; _name = name; _description = description; _objective = objective; _duration = duration; _difficulty = difficulty; _rewards = reward; _minLevel = minLevel; _state = QuestStateEnum.Disponible; } #endregion #region Methods public void InitializeEvents(QuestEventPackSO pack) { ActiveEvents.Clear(); if (pack == null || pack.availableEvents == null || pack.availableEvents.Count == 0) { return; } var pool = new List(pack.availableEvents); int toPick = Mathf.Min(pack.maxEventsToPick, pool.Count); int currentTime = 0; if (QuestManager.Instance != null) { currentTime = QuestManager.Instance.currentTimeInQuest; } for (int i = 0; i < toPick; i++) { int index = UnityEngine.Random.Range(0, pool.Count); var pickedSO = pool[index]; pool.RemoveAt(index); if (pickedSO != null) { ActiveEvents.Add(pickedSO.ToQuestEventClass(currentTime)); } } } public static List GetAdventurersFromId(List adventurersId) { var adventurers = new List(); if (adventurersId == null || GameManager.Instance == null || GameManager.Instance.Fact == null) return adventurers; foreach (var adventurerId in adventurersId) { var adventurer = GetOneAdventurerFromId(adventurerId); if (adventurer != null) adventurers.Add(adventurer); } return adventurers; } public static AdventurerClass GetOneAdventurerFromId(Guid adventurerId) { // Guard against GameManager or Fact system not ready Debug.Log($"ID recherché : {adventurerId}"); if (GameManager.Instance == null) { Debug.Log("GameManager introuvable ou pas initialisé"); return null; } if (GameManager.Instance.Fact == null) { Debug.Log("Fact introuvable ou null"); return null; } var list = GameManager.Instance.Fact.GetFact>("my_adventurers"); if (list == null) { Debug.Log("Liste des aventuriers est null"); return null; } else { Debug.Log($"Nombre d'Aventuriers : {list.Count}"); } var adventurer = list.Find(adventurer => adventurer != null && adventurer.ID == adventurerId); Debug.Log($"retourne : {adventurer}"); return list.Find(adventurer => adventurer != null && adventurer.ID == adventurerId); } public static List GetIdFromAdventurers(List adventurers) { List adventurersId = new List(); foreach (var adventurer in adventurers) { adventurersId.Add(adventurer.ID); } return adventurersId; } public static Guid GetOneIdFromAdventurer(AdventurerClass adventurer) { if (adventurer == null || GameManager.Instance == null || GameManager.Instance.Fact == null) { return Guid.Empty; } var currentAdventurers = GameManager.Instance.Fact.GetFact>("my_adventurers"); var adv = currentAdventurers?.Find(a => a != null && a.ID == adventurer.ID); return adv != null ? adv.ID : Guid.Empty; } #endregion } }