68 lines
2.2 KiB
C#
68 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace GazeLab.Data
|
|
{
|
|
[CreateAssetMenu(fileName = "MetaTreeDefinition", menuName = "GazeLab/Meta/Meta Tree Definition", order = 2)]
|
|
public sealed class MetaTreeDefinitionSO : ScriptableObject
|
|
{
|
|
public string treeTitle = "Legacy Mastery Matrix // Permanent Rogue-Lite Upgrades";
|
|
public MetaUpgradeNodeSO[] allNodes;
|
|
|
|
public int CalculateTotalTreeCost()
|
|
{
|
|
if (allNodes == null) return 0;
|
|
int total = 0;
|
|
for (int i = 0; i < allNodes.Length; i++)
|
|
{
|
|
if (allNodes[i] != null)
|
|
{
|
|
total += allNodes[i].TotalPointCost;
|
|
}
|
|
}
|
|
return total;
|
|
}
|
|
|
|
public MetaUpgradeNodeSO GetNodeById(string nodeId)
|
|
{
|
|
if (string.IsNullOrEmpty(nodeId) || allNodes == null) return null;
|
|
for (int i = 0; i < allNodes.Length; i++)
|
|
{
|
|
if (allNodes[i] != null && allNodes[i].nodeId == nodeId)
|
|
return allNodes[i];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public HashSet<MetaUpgradeNodeSO> GetAncestorSet(MetaUpgradeNodeSO targetNode)
|
|
{
|
|
HashSet<MetaUpgradeNodeSO> visited = new HashSet<MetaUpgradeNodeSO>();
|
|
if (targetNode == null) return visited;
|
|
|
|
Queue<MetaUpgradeNodeSO> queue = new Queue<MetaUpgradeNodeSO>();
|
|
queue.Enqueue(targetNode);
|
|
|
|
while (queue.Count > 0)
|
|
{
|
|
MetaUpgradeNodeSO current = queue.Dequeue();
|
|
if (current == null) continue;
|
|
|
|
if (current.prerequisites != null && current.prerequisites.Length > 0)
|
|
{
|
|
for (int i = 0; i < current.prerequisites.Length; i++)
|
|
{
|
|
MetaUpgradeNodeSO parent = current.prerequisites[i].parentNode;
|
|
if (parent != null && visited.Add(parent))
|
|
{
|
|
queue.Enqueue(parent);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return visited;
|
|
}
|
|
}
|
|
}
|
|
|