110 lines
3.1 KiB
C#
110 lines
3.1 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Core.Runtime;
|
|
using EventSystem.Runtime;
|
|
using Item.Runtime;
|
|
using Quests.Runtime;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
namespace GameUI.Runtime
|
|
{
|
|
public class QuestCardUI : BaseMonobehaviour
|
|
{
|
|
|
|
#region Publics
|
|
|
|
[Header("UI References")]
|
|
public TMPro.TextMeshProUGUI m_title;
|
|
public TMPro.TextMeshProUGUI m_description;
|
|
public TMPro.TextMeshProUGUI m_objective;
|
|
public TMPro.TextMeshProUGUI m_duration;
|
|
public TMPro.TextMeshProUGUI m_difficulty;
|
|
public TMPro.TextMeshProUGUI m_reward;
|
|
public TMPro.TextMeshProUGUI m_minLevel;
|
|
|
|
public QuestClass Quest => _quest;
|
|
|
|
#endregion
|
|
|
|
|
|
#region Unity API
|
|
|
|
void Start()
|
|
{
|
|
foreach (var txt in GetComponentsInChildren<TMP_Text>())
|
|
{
|
|
txt.text = LocalizationSystem.Instance.GetLocalizedText(txt.text);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
#region Main Methods
|
|
|
|
public void Setup(QuestClass quest)
|
|
{
|
|
_quest = quest;
|
|
m_title.text = quest.Name;
|
|
m_description.text = quest.Description;
|
|
m_objective.text = quest.Objective;
|
|
//m_duration.text = quest.Duration.ToString();
|
|
m_difficulty.text = quest.Difficulty.ToString();
|
|
m_reward.text = RewardsListJoined(quest.Rewards);
|
|
m_minLevel.text = quest.MinLevel.ToString();
|
|
}
|
|
|
|
public void AcceptQuest()
|
|
{
|
|
// Ensure state order: Disponible -> Accepted
|
|
_quest.State = QuestStateEnum.Accepted;
|
|
|
|
// Persist in saved quests list
|
|
List<QuestClass> savedQuests = GetFact<List<QuestClass>>("accepted_quests");
|
|
savedQuests.Add(_quest);
|
|
|
|
// Also add to runtime active quests list so other systems can find it
|
|
if (FactExists<List<QuestClass>>("accepted_quests", out _))
|
|
{
|
|
var acceptedQuests = GetFact<List<QuestClass>>("accepted_quests");
|
|
// Avoid duplicates by GUID
|
|
if (!acceptedQuests.Any(q => q.ID == _quest.ID))
|
|
{
|
|
acceptedQuests.Add(_quest);
|
|
}
|
|
}
|
|
|
|
SaveFacts();
|
|
|
|
// Refresh quest UIs and availability board
|
|
QuestSignals.RaiseRefreshQuests();
|
|
var player = GetFact<Player.Runtime.PlayerClass>(GameManager.Instance.Profile);
|
|
QuestManager.Instance.NotifyAvailableQuestsUpdated(player.GuildLevel);
|
|
|
|
// Remove the accepted card from the board
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
#region Utils
|
|
|
|
string RewardsListJoined(List<ItemReward> rewards)
|
|
{
|
|
return string.Join(", ", rewards.Select(r => r.m_itemDefinition.DisplayNameKey != null
|
|
? LocalizationSystem.Instance.GetLocalizedText(r.m_itemDefinition.DisplayNameKey)
|
|
: "???"));
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
#region Privates and Protected
|
|
|
|
QuestClass _quest;
|
|
|
|
#endregion
|
|
}
|
|
}
|