Le quêtes sont désormais bien retirés quand choisis.
This commit is contained in:
parent
9f2e4c1063
commit
838f91ede7
7 changed files with 107 additions and 24 deletions
|
|
@ -1,8 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 44cc5e4b4ce644394a7b14151c11fee3
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -150,6 +150,11 @@ namespace Core.Runtime
|
|||
Debug.Log("Chemin des sauvegardes : " + Application.persistentDataPath);
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
Destroy(Instance);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -24,12 +24,14 @@ namespace Decor.Runtime
|
|||
|
||||
void Awake()
|
||||
{
|
||||
_player = GetFact<PlayerClass>(GameManager.Instance.Profile);
|
||||
//
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
// Trigger an initial refresh
|
||||
_player = GetFact<PlayerClass>(GameManager.Instance.Profile);
|
||||
Info($"Player : {_player.GuildName}");
|
||||
|
||||
QuestManager.Instance.NotifyAvailableQuestsUpdated(_player.GuildLevel);
|
||||
UpdateParchmentState();
|
||||
}
|
||||
|
|
@ -72,8 +74,8 @@ namespace Decor.Runtime
|
|||
var allPossibleQuests = QuestManager.Instance.GetAvailableQuests(_player.GuildLevel);
|
||||
|
||||
// 2. Quêtes déjà démarrées (actives OU complétées)
|
||||
var startedQuests = QuestManager.Instance.ActiveQuests
|
||||
.Concat(QuestManager.Instance.CompletedQuests)
|
||||
var startedQuests = (QuestManager.Instance.ActiveQuests ?? new List<QuestClass>())
|
||||
.Concat(QuestManager.Instance.CompletedQuests ?? Enumerable.Empty<QuestClass>())
|
||||
.ToList();
|
||||
|
||||
// 3. Quêtes vraiment disponibles = possibles - déjà démarrées
|
||||
|
|
|
|||
|
|
@ -169,16 +169,30 @@ namespace Quests.Runtime
|
|||
{
|
||||
ActiveEvents.Clear();
|
||||
|
||||
if (pack == null || pack.availableEvents == null || pack.availableEvents.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var pool = new List<QuestEventSO>(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);
|
||||
|
||||
ActiveEvents.Add(pickedSO.ToQuestEventClass(QuestManager.Instance.currentTimeInQuest));
|
||||
if (pickedSO != null)
|
||||
{
|
||||
ActiveEvents.Add(pickedSO.ToQuestEventClass(currentTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Adventurer.Runtime;
|
||||
|
|
@ -13,8 +14,15 @@ namespace Quests.Runtime
|
|||
{
|
||||
#region Singleton
|
||||
|
||||
static QuestManager _instance;
|
||||
public static QuestManager Instance => _instance ??= new QuestManager();
|
||||
public static QuestManager Instance { get; set; }
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if (Instance == this)
|
||||
{
|
||||
Instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
|
@ -27,23 +35,55 @@ namespace Quests.Runtime
|
|||
|
||||
#endregion
|
||||
|
||||
#region Unity API
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (Instance != null && Instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
_disponibleQuests = _questDatabase.GetAll().SelectMany(f => f.questTemplates).Select(t => t.ToQuestClass(QuestStateEnum.Disponible)).ToList();
|
||||
|
||||
// Ensure quest lists are initialized to avoid null issues in consumers
|
||||
if (_activeQuests == null) _activeQuests = new List<QuestClass>();
|
||||
if (_completedQuests == null) _completedQuests = new List<QuestClass>();
|
||||
if (_disponibleQuests == null) _disponibleQuests = new List<QuestClass>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
List<QuestClass> _activeQuests;
|
||||
List<QuestClass> _disponibleQuests;
|
||||
List<QuestClass> _completedQuests;
|
||||
QuestClass _currentQuest;
|
||||
|
||||
public QuestClass CurrentQuest
|
||||
{
|
||||
get => _currentQuest;
|
||||
set => _currentQuest = value;
|
||||
}
|
||||
|
||||
List<QuestClass> _activeQuests;
|
||||
public List<QuestClass> DisponibleQuests
|
||||
{
|
||||
get => _disponibleQuests;
|
||||
set => _disponibleQuests = value;
|
||||
}
|
||||
|
||||
public List<QuestClass> ActiveQuests
|
||||
{
|
||||
get => _activeQuests;
|
||||
set => _activeQuests = value;
|
||||
}
|
||||
|
||||
List<QuestClass> _completedQuests;
|
||||
public List<QuestClass> CompletedQuests
|
||||
{
|
||||
get => _completedQuests;
|
||||
|
|
@ -183,7 +223,7 @@ namespace Quests.Runtime
|
|||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
#region Utils
|
||||
|
||||
/// <summary>
|
||||
/// Assigne des aventuriers à une quête
|
||||
|
|
|
|||
|
|
@ -83,6 +83,7 @@ namespace GameUI.Runtime
|
|||
QuestManager.Instance.NotifyAvailableQuestsUpdated(player.GuildLevel);
|
||||
|
||||
// Remove the accepted card from the board
|
||||
Info($"<color=green>Quest accepted?: {_quest.Name} : {_quest.State}</color>");
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -65,20 +65,49 @@ namespace GameUI.Runtime
|
|||
|
||||
void DisplayAvailableQuests(List<QuestTemplate> availableTemplates, List<QuestClass> acceptedQuests)
|
||||
{
|
||||
// Build a set of started quest IDs (Accepted/Active + Completed)
|
||||
// Build a set of started/accepted quest IDs to filter out from the board
|
||||
var startedIds = new HashSet<System.Guid>();
|
||||
// Active (in progress)
|
||||
foreach (var q in QuestManager.Instance.ActiveQuests ?? new List<QuestClass>())
|
||||
{
|
||||
if (q.ID != System.Guid.Empty) startedIds.Add(q.ID);
|
||||
if (q != null && q.ID != System.Guid.Empty) startedIds.Add(q.ID);
|
||||
}
|
||||
// Completed
|
||||
foreach (var q in QuestManager.Instance.CompletedQuests ?? new List<QuestClass>())
|
||||
{
|
||||
if (q.ID != System.Guid.Empty) startedIds.Add(q.ID);
|
||||
if (q != null && q.ID != System.Guid.Empty) startedIds.Add(q.ID);
|
||||
}
|
||||
// Accepted but not yet started (persisted list)
|
||||
try
|
||||
{
|
||||
if (FactExists<List<QuestClass>>("accepted_quests", out var accepted) && accepted != null)
|
||||
{
|
||||
foreach (var q in accepted)
|
||||
{
|
||||
if (q != null && q.ID != System.Guid.Empty) startedIds.Add(q.ID);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Try to read anyway (some implementations auto-initialize facts)
|
||||
var fallbackAccepted = GetFact<List<QuestClass>>("accepted_quests");
|
||||
if (fallbackAccepted != null)
|
||||
{
|
||||
foreach (var q in fallbackAccepted)
|
||||
{
|
||||
if (q != null && q.ID != System.Guid.Empty) startedIds.Add(q.ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// If facts system isn't ready, just skip; board will refresh later
|
||||
}
|
||||
|
||||
foreach (var template in availableTemplates)
|
||||
{
|
||||
// Skip if this template already started (by GUID)
|
||||
// Skip if this template already started/accepted (by GUID)
|
||||
if (System.Guid.TryParse(template.m_assetGuid, out var guid) && startedIds.Contains(guid))
|
||||
{
|
||||
continue;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue