using UnityEngine; [CreateAssetMenu(fileName = "EquipmentUpdateSO", menuName = "Equipment/EquipmentUpdateSO")] public class eUpdate_mtrSO : ScriptableObject { [System.Serializable] public class BreakthroughStageCost { [Tooltip("breakthroughMaterial required count")] public int materialRequired; [Tooltip("coin required count")] public int coinRequired; } [Header("Material Definitions")] [Tooltip("Fixed equipment upgrade consumable definition: 78101")] public equipmentConsumableSO upgradeMaterial; [Tooltip("Fixed equipment breakthrough consumable definition: 78111")] public equipmentConsumableSO breakthroughMaterial; [Header("Upgrade Cost")] [Tooltip("Upgrade material required count = base + level * growth")] public int upgradeMaterialBase = 1; public int upgradeMaterialGrowth; [Tooltip("Upgrade coin required count = base + level * growth")] public int upgradeCoinsBase; public int upgradeCoinsGrowth; [Tooltip("Upgrade memory fragment required count = base + level * growth")] public int upgradeMemoryFragmentBase; public int upgradeMemoryFragmentGrowth; [Header("Breakthrough Cost")] [Tooltip("Index 0-3 -> level 4/9/14/19")] public BreakthroughStageCost[] breakthroughStageCosts = new BreakthroughStageCost[4]; public int GetUpgradeMaterialRequired(int level) { return Mathf.Max(0, upgradeMaterialBase + Mathf.Max(0, level) * upgradeMaterialGrowth); } public int GetBreakthroughMaterialRequired(int level) { int stageIndex = GetBreakthroughStageIndex(level); if (stageIndex < 0 || breakthroughStageCosts == null || stageIndex >= breakthroughStageCosts.Length || breakthroughStageCosts[stageIndex] == null) { return 0; } return Mathf.Max(0, breakthroughStageCosts[stageIndex].materialRequired); } public int GetUpgradeCoinsRequired(int level) { return Mathf.Max(0, upgradeCoinsBase + Mathf.Max(0, level) * upgradeCoinsGrowth); } public int GetUpgradeMemoryFragmentRequired(int level) { return Mathf.Max(0, upgradeMemoryFragmentBase + Mathf.Max(0, level) * upgradeMemoryFragmentGrowth); } public int GetBreakthroughCoinsRequired(int level) { int stageIndex = GetBreakthroughStageIndex(level); if (stageIndex < 0 || breakthroughStageCosts == null || stageIndex >= breakthroughStageCosts.Length || breakthroughStageCosts[stageIndex] == null) { return 0; } return Mathf.Max(0, breakthroughStageCosts[stageIndex].coinRequired); } public int GetBreakthroughStageIndex(int level) { switch (level) { case 4: return 0; case 9: return 1; case 14: return 2; case 19: return 3; default: return -1; } } private void OnValidate() { if (breakthroughStageCosts == null || breakthroughStageCosts.Length != 4) { var resized = new BreakthroughStageCost[4]; if (breakthroughStageCosts != null) { for (int i = 0; i < Mathf.Min(breakthroughStageCosts.Length, resized.Length); i++) { resized[i] = breakthroughStageCosts[i]; } } breakthroughStageCosts = resized; } for (int i = 0; i < breakthroughStageCosts.Length; i++) { breakthroughStageCosts[i] ??= new BreakthroughStageCost(); breakthroughStageCosts[i].materialRequired = Mathf.Max(0, breakthroughStageCosts[i].materialRequired); breakthroughStageCosts[i].coinRequired = Mathf.Max(0, breakthroughStageCosts[i].coinRequired); } } }