Files
Continentis/Assets/Scripts/MainGame/Card/CardData/CardUpgradeNode.cs
SoulliesOfficial 76157e3cb1 继续
2025-10-24 09:11:22 -04:00

87 lines
3.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using NaughtyAttributes;
using SLSFramework.General;
using UnityEngine;
namespace Continentis.MainGame.Card
{
[Serializable]
public class CardUpgradeNode
{
[ReadOnly]
[Tooltip("来源卡牌")]
public CardData sourceCard;
public bool isTerminalNode;
[ShowIf("isTerminalNode")]
public bool isInfiniteUpgrade;
[HideIf("isInfiniteUpgrade")]
public int maxUpgradeLevel;
[HideIf("isTerminalNode")]
[Tooltip("可升级到的卡牌列表")]
public List<CardData> upgradeCards;
[ShowIf("isTerminalNode")]
[Tooltip("默认每次升级时增加的属性,第一栏是属性名,第二栏是增加的数值")]
public Dictionary<string, float> defaultUpgradeAttributes;
[ShowIf("isTerminalNode")]
[Tooltip("设计师设定的卡牌等级升级时增加的属性第一栏是属性名第二栏是增加的数值index=0为第一次升级以此类推优先使用此列表中的属性增量")]
public List<Dictionary<string, float>> customUpgradeAttributes;
[ShowIf("isTerminalNode")]
[Tooltip("设计师设定的卡牌等级升级时替换的描述index=0为第一次升级以此类推优先使用此列表中的描述如果没有则使用原卡牌的描述")]
public List<string> customDescriptions;
public CardUpgradeNode(CardData sourceCard)
{
this.sourceCard = sourceCard;
this.isTerminalNode = true;
this.maxUpgradeLevel = 1;
this.isInfiniteUpgrade = false;
this.upgradeCards = new List<CardData>();
this.defaultUpgradeAttributes = new Dictionary<string, float>();
this.customUpgradeAttributes = new List<Dictionary<string, float>>();
this.customDescriptions = new List<string>();
}
public Dictionary<string, float> GetUpgradeAttributes(int upgradeLevel)
{
Dictionary<string, float> upgradeAttributes = new Dictionary<string, float>();
if (isTerminalNode)
{
int levelCountInCustom = Mathf.Min(customUpgradeAttributes.Count, upgradeLevel);
for (int level = 0; level < levelCountInCustom; level++)
{
Dictionary<string, float> thisLevel = customUpgradeAttributes[level];
foreach (KeyValuePair<string, float> attribute in thisLevel)
{
upgradeAttributes.ModifyOrAdd(attribute.Key, attribute.Value);
}
}
if (upgradeLevel > customUpgradeAttributes.Count)
{
int defaultLevelCount = upgradeLevel - customUpgradeAttributes.Count;
foreach (KeyValuePair<string, float> attribute in defaultUpgradeAttributes)
{
upgradeAttributes.ModifyOrAdd(attribute.Key, attribute.Value * defaultLevelCount);
}
}
}
else
{
Debug.LogError($"[CardUpgradeNode] Attempted to get upgrade attributes for a non-terminal node card {sourceCard.className}.");
}
return upgradeAttributes;
}
}
}