添加错误日志记录;添加物品使用次数参数

This commit is contained in:
风吹落的叶子 2025-07-06 16:55:26 +08:00
parent a641e8ce6f
commit a989b8b56d
Signed by: yeziuku
GPG Key ID: E4B3256511E76470
3 changed files with 11 additions and 5 deletions

View File

@ -1631,7 +1631,7 @@ namespace Milimoe.FunGame.Server.Controller
Guid itemGuid = DataRequest.GetDictionaryJsonObject<Guid>(requestData, "itemGuid"); Guid itemGuid = DataRequest.GetDictionaryJsonObject<Guid>(requestData, "itemGuid");
long userid = DataRequest.GetDictionaryJsonObject<long>(requestData, "userid"); long userid = DataRequest.GetDictionaryJsonObject<long>(requestData, "userid");
Character[] targets = DataRequest.GetDictionaryJsonObject<Character[]>(requestData, "targets") ?? []; Character[] targets = DataRequest.GetDictionaryJsonObject<Character[]>(requestData, "targets") ?? [];
long useCount = DataRequest.GetDictionaryJsonObject<long>(requestData, "useCount"); int useCount = DataRequest.GetDictionaryJsonObject<int>(requestData, "useCount");
GeneralEventArgs eventArgs = new(itemGuid, userid, targets, useCount); GeneralEventArgs eventArgs = new(itemGuid, userid, targets, useCount);
FunGameSystem.ServerPluginLoader?.OnBeforeUseItemEvent(this, eventArgs); FunGameSystem.ServerPluginLoader?.OnBeforeUseItemEvent(this, eventArgs);
@ -1646,13 +1646,12 @@ namespace Milimoe.FunGame.Server.Controller
User? user = SQLHelper.GetUserById(userid, true); User? user = SQLHelper.GetUserById(userid, true);
if (user != null && user.Inventory.Items.FirstOrDefault(i => i.Guid == itemGuid) is Item item) if (user != null && user.Inventory.Items.FirstOrDefault(i => i.Guid == itemGuid) is Item item)
{ {
// 暂定标准实现是传这个参数,作用目标和使用数量 // 暂定标准实现是传这个参数,作用目标
Dictionary<string, object> args = new() Dictionary<string, object> args = new()
{ {
{ "targets", targets }, { "targets", targets }
{ "useCount", useCount }
}; };
bool used = item.UseItem(user, args); bool used = item.UseItem(user, useCount, args);
if (used) if (used)
{ {
SQLHelper.UpdateInventory(user.Inventory); SQLHelper.UpdateInventory(user.Inventory);

View File

@ -72,6 +72,7 @@ namespace Milimoe.FunGame.Server.Services
{ {
Console.WriteLine("\r" + GetPrefix(InvokeMessageType.Error, LogLevel.Error) + e.Message + "\n" + e.StackTrace); Console.WriteLine("\r" + GetPrefix(InvokeMessageType.Error, LogLevel.Error) + e.Message + "\n" + e.StackTrace);
Type(); Type();
TXTHelper.AppendErrorLog(e);
} }
public static void Write(string msg, InvokeMessageType type = InvokeMessageType.System, LogLevel level = LogLevel.Info, bool useLevel = true) public static void Write(string msg, InvokeMessageType type = InvokeMessageType.System, LogLevel level = LogLevel.Info, bool useLevel = true)

View File

@ -1,5 +1,6 @@
using Microsoft.Extensions.Logging.Abstractions; using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Logging.Console; using Microsoft.Extensions.Logging.Console;
using Milimoe.FunGame.Core.Api.Utility;
namespace Milimoe.FunGame.WebAPI.Services namespace Milimoe.FunGame.WebAPI.Services
{ {
@ -20,6 +21,11 @@ namespace Milimoe.FunGame.WebAPI.Services
textWriter.WriteLine($"{colorLevel}{timestamp} {level}/[{category}] {message}"); textWriter.WriteLine($"{colorLevel}{timestamp} {level}/[{category}] {message}");
} }
textWriter.Write("\x1b[0m\r> "); textWriter.Write("\x1b[0m\r> ");
if (logEntry.Exception != null)
{
TXTHelper.AppendErrorLog(logEntry.Exception);
}
} }
private static string GetColorCode(LogLevel logLevel) private static string GetColorCode(LogLevel logLevel)