198 lines
7.7 KiB
C#
198 lines
7.7 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace GazeLab.Data
|
|
{
|
|
public enum TechNodeCategory
|
|
{
|
|
WeaponUnlock,
|
|
AbilityUnlock,
|
|
StatBuff,
|
|
StationEvolution
|
|
}
|
|
|
|
public enum TechBranchTrack
|
|
{
|
|
Core = 0,
|
|
Defense = 1,
|
|
Ordnance = 2,
|
|
CitadelCommand = 3,
|
|
Logistics = 4
|
|
}
|
|
|
|
public enum TechStatType
|
|
{
|
|
None,
|
|
MaxHull,
|
|
MaxShield,
|
|
ShieldRegen,
|
|
TurretDamage,
|
|
FireRate,
|
|
MagnetRange,
|
|
AsteroidSplit,
|
|
AbilityCooldownReduction,
|
|
ResourceDropBonus
|
|
}
|
|
|
|
public enum TechNodeContainerStyle
|
|
{
|
|
Automatic = 0, // Auto: StatBuff -> Small, Weapon/Ability -> Silver, StationEvolution -> Gold
|
|
Small,
|
|
Silver,
|
|
Gold,
|
|
Custom
|
|
}
|
|
|
|
[Serializable]
|
|
public struct TechNodePrerequisite
|
|
{
|
|
public UpgradeTreeNodeSO parentNode;
|
|
[Tooltip("Minimum rank the parent node must reach before this node unlocks.")]
|
|
[Range(1, 10)] public int minRequiredRank;
|
|
}
|
|
|
|
[CreateAssetMenu(fileName = "TechNode_", menuName = "GazeLab/Upgrades/Tech Tree Node", order = 1)]
|
|
public sealed class UpgradeTreeNodeSO : ScriptableObject
|
|
{
|
|
[Header("Node Identity & Track")]
|
|
public string nodeId = "node_kinetic_boost_1";
|
|
public string displayName = "Reinforced Caliber";
|
|
[TextArea(2, 3)]
|
|
public string shortBenefit = "+6% Global Fire Rate";
|
|
public Sprite icon;
|
|
public TechBranchTrack branchTrack = TechBranchTrack.Ordnance;
|
|
|
|
[Header("Layout Coordinates (Left-to-Right Branching Graph)")]
|
|
[Tooltip("Horizontal tier column (0 = Core Root on left, 1..5 = progressive depth to the right).")]
|
|
[Range(0, 6)] public int treeTier = 1;
|
|
[Tooltip("Vertical lane slot (-2 to +2, or continuous normalized Y via canvasPosition).")]
|
|
[Range(-3, 3)] public int columnSlot = 0;
|
|
[Tooltip("Normalized position (0..1, 0..1) on the constellation canvas. If zero, auto-computed from treeTier & columnSlot.")]
|
|
public Vector2 canvasPosition = Vector2.zero;
|
|
|
|
[Header("Visual Distinction & Container Style")]
|
|
[Tooltip("Major nodes (Weapons, Abilities, Station Evolutions) are visually larger and bolder than Minor stat nodes.")]
|
|
public bool isMajorNode = false;
|
|
[Tooltip("Container style for this node. Automatic selects Small for stats, Silver for rare unlocks (weapons/abilities), and Gold for station evolutions.")]
|
|
public TechNodeContainerStyle containerStyle = TechNodeContainerStyle.Automatic;
|
|
[Tooltip("Optional custom container sprite override. If assigned, this sprite will be used regardless of containerStyle.")]
|
|
public Sprite customContainerSprite;
|
|
|
|
[Header("Multi-Level Node Progression")]
|
|
[Tooltip("Max ranks for this node (e.g. 5 for minor stat buffs, 3 for ability tiers, 2-3 for weapon evolutions).")]
|
|
[Range(1, 10)] public int maxRank = 1;
|
|
[Tooltip("Resource cost for Rank 1")]
|
|
public ResourceCost baseCost = new ResourceCost(10, 0, 0);
|
|
[Tooltip("Additional cost added per rank after Rank 1")]
|
|
public ResourceCost costIncreasePerRank = new ResourceCost(5, 0, 0);
|
|
[Tooltip("Stat increase applied per rank")]
|
|
public float statModifierPerRank = 0.06f;
|
|
|
|
[Header("Upgrade Category & Target Payload")]
|
|
public TechNodeCategory category = TechNodeCategory.StatBuff;
|
|
public WeaponDefinition unlockedWeapon;
|
|
[Tooltip("Optional multi-rank weapon progression (e.g. Rank 1 = Lv1, Rank 2 = Lv3).")]
|
|
public WeaponDefinition[] weaponTiersByRank;
|
|
public StationAbilityDefinition unlockedAbility;
|
|
public TechStatType statType = TechStatType.FireRate;
|
|
public float statModifierValue = 0.06f;
|
|
[Range(1, 8)] public int targetStationLevel = 2;
|
|
|
|
[Header("Prerequisites & Unlock Gates")]
|
|
[Tooltip("Prerequisite nodes with minimum rank requirements (e.g. Attack Speed Rank 2 required).")]
|
|
public TechNodePrerequisite[] prerequisites;
|
|
[Tooltip("Legacy prerequisite nodes without rank requirements.")]
|
|
public UpgradeTreeNodeSO[] prerequisiteNodes;
|
|
[Tooltip("Minimum wave that must be cleared (e.g. Wave 5 Boss cleared).")]
|
|
[Min(0)] public int requiredWaveCleared = 0;
|
|
[Tooltip("Optional per-rank wave requirement for multi-rank Station Evolution nodes.")]
|
|
public int[] requiredWavesByRank;
|
|
public ResourceCost cost = new ResourceCost(10, 0, 0);
|
|
public bool isUnlockedByDefault = false;
|
|
|
|
public Vector2 GetNormalizedCanvasPosition(int maxTier = 5)
|
|
{
|
|
if (canvasPosition.sqrMagnitude > 0.0001f)
|
|
{
|
|
return new Vector2(
|
|
Mathf.Clamp(canvasPosition.x, 0.05f, 0.95f),
|
|
Mathf.Clamp(canvasPosition.y, 0.08f, 0.92f));
|
|
}
|
|
|
|
float normX = Mathf.Lerp(0.08f, 0.92f, Mathf.Clamp01((treeTier - 1f) / Mathf.Max(1f, maxTier - 1f)));
|
|
float normY = Mathf.Lerp(0.14f, 0.86f, Mathf.Clamp01((2f - columnSlot) / 4f));
|
|
return new Vector2(normX, normY);
|
|
}
|
|
|
|
public int GetRequiredWaveForRank(int targetRank)
|
|
{
|
|
if (requiredWavesByRank != null && requiredWavesByRank.Length > 0)
|
|
{
|
|
int idx = Mathf.Clamp(targetRank - 1, 0, requiredWavesByRank.Length - 1);
|
|
return Mathf.Max(0, requiredWavesByRank[idx]);
|
|
}
|
|
return Mathf.Max(0, requiredWaveCleared);
|
|
}
|
|
|
|
public WeaponDefinition GetWeaponForRank(int targetRank)
|
|
{
|
|
if (weaponTiersByRank != null && weaponTiersByRank.Length > 0)
|
|
{
|
|
int idx = Mathf.Clamp(targetRank - 1, 0, weaponTiersByRank.Length - 1);
|
|
if (weaponTiersByRank[idx] != null)
|
|
return weaponTiersByRank[idx];
|
|
}
|
|
return unlockedWeapon;
|
|
}
|
|
|
|
public ResourceCost GetCostForRank(int targetRank)
|
|
{
|
|
ResourceCost start = (baseCost.scrap > 0 || baseCost.gold > 0 || baseCost.uranium > 0) ? baseCost : cost;
|
|
if (targetRank <= 1)
|
|
{
|
|
return start;
|
|
}
|
|
int rankIndex = targetRank - 1;
|
|
return new ResourceCost(
|
|
start.scrap + costIncreasePerRank.scrap * rankIndex,
|
|
start.gold + costIncreasePerRank.gold * rankIndex,
|
|
start.uranium + costIncreasePerRank.uranium * rankIndex
|
|
);
|
|
}
|
|
|
|
public float GetSingleRankStatStep()
|
|
{
|
|
return statModifierPerRank > 0.0001f ? statModifierPerRank : statModifierValue;
|
|
}
|
|
|
|
public float GetStatModifierForRank(int targetRank)
|
|
{
|
|
return GetSingleRankStatStep() * Mathf.Max(0, targetRank);
|
|
}
|
|
|
|
private void OnValidate()
|
|
{
|
|
maxRank = Mathf.Max(1, maxRank);
|
|
if (baseCost.scrap == 0 && baseCost.gold == 0 && baseCost.uranium == 0 &&
|
|
(cost.scrap > 0 || cost.gold > 0 || cost.uranium > 0))
|
|
{
|
|
baseCost = cost;
|
|
}
|
|
else if (cost.scrap == 0 && cost.gold == 0 && cost.uranium == 0 &&
|
|
(baseCost.scrap > 0 || baseCost.gold > 0 || baseCost.uranium > 0))
|
|
{
|
|
cost = baseCost;
|
|
}
|
|
|
|
if (statModifierPerRank <= 0.0001f && statModifierValue > 0.0001f)
|
|
{
|
|
statModifierPerRank = statModifierValue;
|
|
}
|
|
else if (statModifierValue <= 0.0001f && statModifierPerRank > 0.0001f)
|
|
{
|
|
statModifierValue = statModifierPerRank;
|
|
}
|
|
}
|
|
}
|
|
}
|