2025-10-23 00:49:44 -04:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using DynamicExpresso;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace Continentis.MainGame
|
|
|
|
|
{
|
|
|
|
|
public static partial class BuffTextInterpreter
|
|
|
|
|
{
|
|
|
|
|
private static readonly Interpreter TextInterpreter;
|
|
|
|
|
|
|
|
|
|
static BuffTextInterpreter()
|
|
|
|
|
{
|
|
|
|
|
TextInterpreter = new Interpreter();
|
2025-10-27 07:04:34 -04:00
|
|
|
DynamicTextInterpreter.InitializeInterpreter(ref TextInterpreter);
|
2025-10-23 00:49:44 -04:00
|
|
|
|
|
|
|
|
foreach (KeyValuePair<string, InterpretedKeyword> keyword in MainGameManager.Instance.keywordData.interpretedKeywords)
|
|
|
|
|
{
|
|
|
|
|
TextInterpreter.SetVariable(keyword.Key, keyword.Key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void InterpretText<T>(BuffBase<T> buff)
|
|
|
|
|
{
|
|
|
|
|
TextInterpreter.SetFunction("ParameterInt", new Func<string, string>((paramName) => GetParameterInt(buff, paramName, false)));
|
|
|
|
|
TextInterpreter.SetFunction("ParameterAbsInt", new Func<string, string>((paramName) => GetParameterInt(buff, paramName, true)));
|
|
|
|
|
TextInterpreter.SetFunction("ParameterPercent", new Func<string, string>((paramName) => GetParameterPercent(buff, paramName)));
|
|
|
|
|
TextInterpreter.SetFunction("ParameterFloat", new Func<string, string>((paramName) => GetParameterFloat(buff, paramName)));
|
|
|
|
|
TextInterpreter.SetFunction("ParameterString", new Func<string, string>((paramName) => GetParameterString(buff, paramName)));
|
2025-10-31 10:02:30 -04:00
|
|
|
|
2025-10-23 00:49:44 -04:00
|
|
|
string descriptionToParse = buff.contentSubmodule.originalFunctionText;
|
2025-10-27 07:04:34 -04:00
|
|
|
string result = DynamicTextInterpreter.Parse(TextInterpreter, descriptionToParse);
|
2025-10-23 00:49:44 -04:00
|
|
|
buff.contentSubmodule.interpretedFunctionText = result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static partial class BuffTextInterpreter
|
|
|
|
|
{
|
|
|
|
|
private static string GetParameterInt<T>(BuffBase<T> buff, string parameterName, bool isAbsolute)
|
|
|
|
|
{
|
|
|
|
|
if (buff.contentSubmodule.parameterGetters.TryGetValue(parameterName, out Func<string> getter))
|
|
|
|
|
{
|
|
|
|
|
int intValue = Convert.ToInt32(getter());
|
|
|
|
|
|
|
|
|
|
if (isAbsolute)
|
|
|
|
|
{
|
|
|
|
|
return Math.Abs(intValue).ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return intValue.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Debug.LogError($"无法找到参数获取器: {parameterName} 在 Buff: {buff.contentSubmodule.displayName}");
|
|
|
|
|
return "ERROR";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetParameterFloat<T>(BuffBase<T> buff, string parameterName)
|
|
|
|
|
{
|
|
|
|
|
if (buff.contentSubmodule.parameterGetters.TryGetValue(parameterName, out Func<string> getter))
|
|
|
|
|
{
|
|
|
|
|
return Convert.ToSingle(getter()).ToString(CultureInfo.InvariantCulture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Debug.LogError($"无法找到参数获取器: {parameterName} 在 Buff: {buff.contentSubmodule.displayName}");
|
|
|
|
|
return "ERROR";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetParameterPercent<T>(BuffBase<T> buff, string parameterName)
|
|
|
|
|
{
|
|
|
|
|
if (buff.contentSubmodule.parameterGetters.TryGetValue(parameterName, out Func<string> getter))
|
|
|
|
|
{
|
|
|
|
|
return Mathf.RoundToInt(Convert.ToSingle(getter()) * 100).ToString() + "%";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Debug.LogError($"无法找到参数获取器: {parameterName} 在 Buff: {buff.contentSubmodule.displayName}");
|
|
|
|
|
return "ERROR";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static string GetParameterString<T>(BuffBase<T> buff, string parameterName)
|
|
|
|
|
{
|
|
|
|
|
if (buff.contentSubmodule.parameterGetters.TryGetValue(parameterName, out Func<string> getter))
|
|
|
|
|
{
|
|
|
|
|
return getter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Debug.LogError($"无法找到参数获取器: {parameterName} 在 Buff: {buff.contentSubmodule.displayName}");
|
|
|
|
|
return "ERROR";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|