MOD!
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SoulliesFramework.General;
|
||||
using SLSFramework.General;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -18,9 +18,9 @@ namespace Continentis.MainGame.Card
|
||||
private void Initialize(CardData cardData)
|
||||
{
|
||||
Dictionary<string, float> originalAttributes = new Dictionary<string, float>(cardData.originalAttributes);
|
||||
Dictionary<string, string> endowingAttributes = new Dictionary<string, string>(cardData.endowingCurrentAttributes);
|
||||
Dictionary<string, string> endowingAttributes = new Dictionary<string, string>(cardData.runtimeCurrentAttributes);
|
||||
|
||||
if (cardData.upgradeNode.isInfiniteUpgrade)
|
||||
if (cardData.upgradeNode is { isInfiniteUpgrade: true })
|
||||
{
|
||||
foreach (KeyValuePair<string, float> upgrade in cardData.upgradeNode.GetUpgradeAttributes(owner.upgradeLevel))
|
||||
{
|
||||
|
||||
@@ -1,249 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using DynamicExpresso;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Continentis.MainGame.Card
|
||||
{
|
||||
public static partial class CardDescriptionInterpreter
|
||||
{
|
||||
public static Interpreter DescriptionInterpreter;
|
||||
|
||||
static CardDescriptionInterpreter()
|
||||
{
|
||||
DescriptionInterpreter = new Interpreter();
|
||||
DescriptionInterpreter.SetFunction("GetDynamicValue", new Func<float, float, bool, string>(GetDynamicValue));
|
||||
DescriptionInterpreter.SetFunction("GetDynamicValue", new Func<float, string>(GetDynamicValue));
|
||||
DescriptionInterpreter.SetFunction("AttributeCheck", new Func<string, float, float, string>(AttributeCheck));
|
||||
|
||||
foreach (KeyValuePair<string,string> keyword in CombatMainManager.Instance.keywordCollection.keywords)
|
||||
{
|
||||
DescriptionInterpreter.SetVariable(keyword.Key, keyword.Key);
|
||||
}
|
||||
|
||||
foreach (KeyValuePair<string, InterpretedKeyword> keyword in CombatMainManager.Instance.keywordCollection.interpretedKeywords)
|
||||
{
|
||||
DescriptionInterpreter.SetVariable(keyword.Key, keyword.Value.name);
|
||||
}
|
||||
}
|
||||
|
||||
public static string InterpretDescription(CardLogicBase card)
|
||||
{
|
||||
card.contentSubmodule.keywords.Clear();
|
||||
|
||||
foreach (KeyValuePair<string, float> attribute in card.attributeSubmodule.attributeGroup.current)
|
||||
{
|
||||
DescriptionInterpreter.SetVariable(attribute.Key, attribute.Value);
|
||||
}
|
||||
|
||||
DescriptionInterpreter.SetFunction("RemoveWhenSelecting", new Func<string, string>((toRemove) => RemoveWhenSelecting(card, toRemove)));
|
||||
|
||||
string result = ParseKeywords(card.cardData.cardDescription, card.contentSubmodule.keywords);
|
||||
|
||||
card.contentSubmodule.cardDescription = result;
|
||||
|
||||
Debug.Log($"Interpreted Description: {result}");
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class CardDescriptionInterpreter
|
||||
{
|
||||
public static List<string> GetKeywords(string template)
|
||||
{
|
||||
List<string> keywords = new List<string>();
|
||||
|
||||
DescriptionInterpreter.UnsetExpression("Keyword");
|
||||
DescriptionInterpreter.SetFunction("Keyword", new Action<string>((keywordName) =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(keywordName) && !keywords.Contains(keywordName))
|
||||
{
|
||||
keywords.Add(keywordName);
|
||||
}
|
||||
}));
|
||||
|
||||
try
|
||||
{
|
||||
//提取所有$Keyword(...)的关键词
|
||||
//其它的表达式直接跳过
|
||||
while (template.Contains("$"))
|
||||
{
|
||||
int startIndex = template.LastIndexOf('$');
|
||||
int endIndex = FindMatchingClosingParenthesis(template, startIndex);
|
||||
|
||||
if (endIndex == -1)
|
||||
{
|
||||
Debug.LogError($"解析错误: 在 '{template}' 中找不到与 '{template.Substring(startIndex)}' 匹配的闭合括号。");
|
||||
break; // 中断以防止死循环
|
||||
}
|
||||
|
||||
string expressionToEvaluate = template.Substring(startIndex, endIndex - startIndex + 1);
|
||||
string cleanExpression = expressionToEvaluate.Substring(1);
|
||||
|
||||
// 仅处理 Keyword 函数,跳过其他表达式
|
||||
if (cleanExpression.StartsWith("Keyword"))
|
||||
{
|
||||
DescriptionInterpreter.Eval(cleanExpression);
|
||||
}
|
||||
|
||||
// 移除已处理的表达式,继续查找下一个
|
||||
template = template.Substring(0, startIndex) + template.Substring(endIndex + 1);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"解析模板时发生严重错误: {ex.Message}\nStackTrace: {ex.StackTrace}");
|
||||
}
|
||||
|
||||
return keywords;
|
||||
}
|
||||
|
||||
public static string ParseKeywords(string template, List<string> keywords)
|
||||
{
|
||||
DescriptionInterpreter.UnsetExpression("Keyword");
|
||||
DescriptionInterpreter.SetFunction("Keyword", new Func<string, string>((keywordName) =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(keywordName) && !keywords.Contains(keywordName))
|
||||
{
|
||||
keywords.Add(keywordName);
|
||||
}
|
||||
|
||||
return Keyword(keywordName);
|
||||
}));
|
||||
|
||||
try
|
||||
{
|
||||
while (template.Contains("$"))
|
||||
{
|
||||
int startIndex = template.LastIndexOf('$');
|
||||
int endIndex = FindMatchingClosingParenthesis(template, startIndex);
|
||||
|
||||
if (endIndex == -1)
|
||||
{
|
||||
Debug.LogError($"解析错误: 在 '{template}' 中找不到与 '{template.Substring(startIndex)}' 匹配的闭合括号。");
|
||||
return template; // 中断以防止死循环
|
||||
}
|
||||
|
||||
string expressionToEvaluate = template.Substring(startIndex, endIndex - startIndex + 1);
|
||||
string cleanExpression = expressionToEvaluate.Substring(1);
|
||||
|
||||
object result = DescriptionInterpreter.Eval(cleanExpression);
|
||||
|
||||
string resultAsLiteral = result.ToString();
|
||||
template = template.Substring(0, startIndex) + resultAsLiteral + template.Substring(endIndex + 1);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"解析模板时发生严重错误: {ex.Message}\nStackTrace: {ex.StackTrace}");
|
||||
}
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
private static int FindMatchingClosingParenthesis(string text, int startIndex)
|
||||
{
|
||||
int openParenIndex = text.IndexOf('(', startIndex);
|
||||
if (openParenIndex == -1) return -1;
|
||||
|
||||
int parenthesisCounter = 1;
|
||||
bool isInString = false;
|
||||
|
||||
for (int i = openParenIndex + 1; i < text.Length; i++)
|
||||
{
|
||||
char c = text[i];
|
||||
char prevC = i > 0 ? text[i - 1] : '\0';
|
||||
|
||||
// 检查是否进入或退出字符串(忽略转义的引号 \")
|
||||
if (c == '"' && prevC != '\\')
|
||||
{
|
||||
isInString = !isInString;
|
||||
}
|
||||
|
||||
// 如果在字符串中,则跳过对括号的计数
|
||||
if (isInString)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (c == '(')
|
||||
{
|
||||
parenthesisCounter++;
|
||||
}
|
||||
else if (c == ')')
|
||||
{
|
||||
parenthesisCounter--;
|
||||
}
|
||||
|
||||
if (parenthesisCounter == 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1; // 没有找到匹配的闭合括号
|
||||
}
|
||||
}
|
||||
|
||||
public partial class CardDescriptionInterpreter
|
||||
{
|
||||
private static string GetDynamicValue(float current, float baseValue, bool normalMode)
|
||||
{
|
||||
string color;
|
||||
if (current > baseValue)
|
||||
color = normalMode ? "green" : "red";
|
||||
else if (current < baseValue)
|
||||
color = normalMode ? "red" : "green";
|
||||
else
|
||||
color = "white";
|
||||
|
||||
//Debug.Log($"GetDynamicValue: current={current}, baseValue={baseValue}, normalMode={normalMode}, color={color}");
|
||||
|
||||
return $"<color={color}>{current}</color>";
|
||||
}
|
||||
|
||||
private static string GetDynamicValue(float current)
|
||||
{
|
||||
return current.ToString(CultureInfo.CurrentCulture);
|
||||
}
|
||||
|
||||
private static string Keyword(string keyword)
|
||||
{
|
||||
string color = "orange";
|
||||
return $"<color={color}>{keyword}</color>";
|
||||
}
|
||||
|
||||
private static string RemoveWhenSelecting(CardLogicBase card, string toRemove)
|
||||
{
|
||||
return card.handCardView != null && card.handCardView.isSelecting ? "" : toRemove;
|
||||
}
|
||||
|
||||
private static string AttributeCheck(string attributeName, float requirement, float probability)
|
||||
{
|
||||
if (probability < 0)
|
||||
{
|
||||
return "{" + attributeName + " check: " + requirement + "}";
|
||||
}
|
||||
|
||||
int percent = Mathf.RoundToInt(probability * 100);
|
||||
|
||||
string result = percent + "%";
|
||||
|
||||
if (percent == 0)
|
||||
{
|
||||
result = "<color=red>" + result + "</color>";
|
||||
}
|
||||
else if (percent > 0 && percent < 100)
|
||||
{
|
||||
result = "<color=yellow>" + result + "</color>";
|
||||
}
|
||||
else if (percent == 100)
|
||||
{
|
||||
result = "<color=green>" + result + "</color>";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cbc566d961d78f142a5699dc40f43462
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using SoulliesFramework.General;
|
||||
using SLSFramework.General;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Continentis.MainGame.Card
|
||||
@@ -38,7 +38,7 @@ namespace Continentis.MainGame.Card
|
||||
|
||||
public void RoundStart()
|
||||
{
|
||||
buffList.For(buff => buff.combatRoundTimeSubmodule?.UpdateModule());
|
||||
buffList.For(buff => buff.combatRoundTimeSubmodule?.Update());
|
||||
buffList.For(buff => buff.OnRoundStart());
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace Continentis.MainGame.Card
|
||||
|
||||
public void ActionStart()
|
||||
{
|
||||
buffList.For(buff => buff.combatActionTimeSubmodule?.UpdateModule());
|
||||
buffList.For(buff => buff.combatActionTimeSubmodule?.Update());
|
||||
buffList.For(buff => buff.OnActionStart());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using SLSFramework.General;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Continentis.MainGame.Card
|
||||
@@ -6,30 +7,27 @@ namespace Continentis.MainGame.Card
|
||||
public class ContentSubmodule : SubmoduleBase<CardLogicBase>
|
||||
{
|
||||
public List<string> keywords;
|
||||
public List<string> hintKeywords;
|
||||
|
||||
public string cardName;
|
||||
public Sprite cardSprite;
|
||||
public CardRarity cardRarity;
|
||||
public Rarity cardRarity;
|
||||
public CardType cardType;
|
||||
public string cardDescription;
|
||||
public string originalFunctionText;
|
||||
public string interpretedFunctionText;
|
||||
|
||||
public ContentSubmodule(CardLogicBase card) : base(card)
|
||||
{
|
||||
keywords = new List<string>();
|
||||
cardName = card.cardData.cardName;
|
||||
hintKeywords = new List<string>();
|
||||
cardName = card.cardData.displayName.Localize();
|
||||
cardSprite = card.cardData.cardSprite;
|
||||
cardDescription = card.cardData.cardDescription;
|
||||
originalFunctionText = card.cardData.functionText.Localize();
|
||||
cardRarity = card.cardData.cardRarity;
|
||||
cardType = card.cardData.cardType;
|
||||
//CardDescriptionInterpreter.InterpretDescription(card);
|
||||
//keywords = CardDescriptionInterpreter.GetKeywords(card.cardData.cardDescription);
|
||||
//Debug.Log($"Extracted Keywords: {string.Join(", ", keywords)}");
|
||||
}
|
||||
|
||||
public string GetFinalDescription()
|
||||
{
|
||||
//finalDescription = CardDescriptionInterpreter.InterpretDescription(card);
|
||||
return cardDescription;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
using Continentis.MainGame.Character;
|
||||
using SoftCircuits.Collections;
|
||||
using SLSFramework.General;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
@@ -8,6 +9,9 @@ namespace Continentis.MainGame.Card
|
||||
{
|
||||
public partial class EventSubmodule : SubmoduleBase<CardLogicBase>
|
||||
{
|
||||
public UnityAction<CharacterBase> onTargeting; //选中目标时
|
||||
public UnityAction onUntargeting; //取消选中目标时
|
||||
|
||||
public OrderedDictionary<string, EventUnit> onCombatStart; //战斗开始时
|
||||
public OrderedDictionary<string, EventUnit> onCombatEnd; //战斗结束时
|
||||
|
||||
@@ -25,6 +29,9 @@ namespace Continentis.MainGame.Card
|
||||
|
||||
public EventSubmodule(CardLogicBase card) : base(card)
|
||||
{
|
||||
onTargeting += card.TargetingEffect;
|
||||
onUntargeting = card.UntargetingEffect;
|
||||
|
||||
onCombatStart = new OrderedDictionary<string, EventUnit>();
|
||||
onCombatEnd = new OrderedDictionary<string, EventUnit>();
|
||||
|
||||
@@ -44,9 +51,6 @@ namespace Continentis.MainGame.Card
|
||||
|
||||
public partial class EventSubmodule
|
||||
{
|
||||
protected void SetUpDefaultEvents()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,11 @@ namespace Continentis.MainGame.Card
|
||||
{
|
||||
public partial class PlaySubmodule : SubmoduleBase<CardLogicBase>
|
||||
{
|
||||
public bool isDuringPlayEffect;
|
||||
|
||||
public PlaySubmodule(CardLogicBase card) : base(card)
|
||||
{
|
||||
|
||||
isDuringPlayEffect = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user