Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

更新: EconomicsAPI 渐变色消息支持 物品消息 #138

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Economics.RPG/RPG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public RPG(Main game) : base(game)

public override void Initialize()
{
Config = ConfigHelper.LoadConfig<Config>(PATH);
Config = ConfigHelper.LoadConfig<Config>(PATH, Config);
Config.Init();
PlayerLevelManager = new();
PlayerHooks.PlayerPermission += PlayerHooks_PlayerPermission;
Expand Down
9 changes: 9 additions & 0 deletions Economics.Skill/Skill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,17 @@ public override void Initialize()
GetDataHandlers.PlayerMana.Register(OnMP);
GetDataHandlers.NewProjectile.Register(OnNewProj);
EconomicsAPI.Events.PlayerHandler.OnPlayerKillNpc += OnKillNpc;
EconomicsAPI.Events.PlayerHandler.OnPlayerCountertop += OnPlayerCountertop;
GeneralHooks.ReloadEvent += e => LoadConfig();
}

private void OnPlayerCountertop(PlayerCountertopArgs args)
{
var skill = PlayerSKillManager.QuerySkill(args.Player.Name);
var msg = skill.Any() ? string.Join(",", skill.Select(x => x.Skill == null ? "无效技能" : x.Skill.Name)) : "无";
args.Messages.Add(new($"绑定技能: {msg}", 12));
}

private void OnUpdate(EventArgs args)
{
TimerCount++;
Expand Down
19 changes: 17 additions & 2 deletions EconomicsAPI/Utils/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,37 @@
using Rests;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using TerrariaApi.Server;
using TShockAPI;

namespace EconomicsAPI.Utils;

public class Helper
{
//代码来自于CaiLib
private static readonly Regex Regex = new(@"\[(?<type>[^\]]+):(?<id>\d+)\]");
public static string GetGradientText(string text)
{
string result = "";
//匹配物品消息
var matchs = Regex.Matches(text);
var chat = matchs.Select(x => x.Groups).ToDictionary(x => x[1].Index, x => x);
var info = Terraria.UI.Chat.ChatManager.ParseMessage(text, Color.White);
var colors = Economics.Setting.GradientColor;
var fullIndex = 1;
var index = 0;
foreach (var item in info)
{
var index = 0;
for(int i = 0; i< item.Text.Length; i++)
{
fullIndex++;
if (chat.TryGetValue(fullIndex - 1, out var group) && group != null)
{
result += item.TextOriginal;
fullIndex += item.Text.Length + 1;
break;
}
else
if (index >= colors.Count)
{
result += item.Text[i];
Expand All @@ -32,9 +45,11 @@
{
result += Economics.Setting.GradientColor[index].SFormat(item.Text[i]);
}

index++;
}
}
Console.WriteLine(result);
return result;
}
/// <summary>
Expand Down Expand Up @@ -64,16 +79,16 @@
if (!m.IsStatic)
{
var instance = types.TryGetValue(x, out var obj) && obj != null ? obj : Activator.CreateInstance(x);
types[x] = instance;

Check warning on line 82 in EconomicsAPI/Utils/Helper.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference assignment.
var method = instance?.GetType().GetMethod(m.Name, flag);
if (method != null)
{
methods.Add(method, (instance, attribute));

Check warning on line 86 in EconomicsAPI/Utils/Helper.cs

View workflow job for this annotation

GitHub Actions / build

Argument of type '(object? instance, T attribute)' cannot be used for parameter 'value' of type '(object, T)' in 'void Dictionary<MethodInfo, (object, T)>.Add(MethodInfo key, (object, T) value)' due to differences in the nullability of reference types.
}
}
else
{
methods.Add(m, (null, attribute));

Check warning on line 91 in EconomicsAPI/Utils/Helper.cs

View workflow job for this annotation

GitHub Actions / build

Argument of type '(object?, T attribute)' cannot be used for parameter 'value' of type '(object, T)' in 'void Dictionary<MethodInfo, (object, T)>.Add(MethodInfo key, (object, T) value)' due to differences in the nullability of reference types.
}
}
}
Expand Down
Loading