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 = 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(); var pool = new List(pack.availableEvents); int toPick = Mathf.Min(pack.maxEventsToPick, pool.Count); for (int i = 0; i < toPick; i++) { int index = UnityEngine.Random.Range(0, pool.Count); var pickedSO = pool[index]; pool.RemoveAt(index); ActiveEvents.Add(pickedSO.ToQuestEventClass(QuestManager.Instance.currentTimeInQuest)); } } 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) { if (GameManager.Instance.Fact.GetFact>("my_adventurers") == null) { return null; } List currentAdventurers = GameManager.Instance.Fact.GetFact>("my_adventurers"); return currentAdventurers.Find(adventurer => 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) { List currentAdventurers = GameManager.Instance.Fact.GetFact>("my_adventurers"); return currentAdventurers.Find(adv => adv.ID == adventurer.ID).ID; } #endregion } }