From 0c4ea422cf1632167b37f65611e9bd2374ee0321 Mon Sep 17 00:00:00 2001 From: Mili Date: Mon, 5 Sep 2022 00:15:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FunGame.Core.Api/Interface/Interface.cs | 2 +- FunGame.Core.Api/Model/Entity/Item.cs | 1 + FunGame.Core.Api/Model/Entity/Skill.cs | 1 + FunGame.Core.Api/Model/Entity/User.cs | 5 +- FunGame.Core.Api/Model/Enum/CommonEnums.cs | 2 +- FunGame.Core.Api/Util/AssemblyHelper.cs | 59 ++++++++++++++-------- FunGame.Desktop/Utils/WebHelper.cs | 2 +- 7 files changed, 45 insertions(+), 27 deletions(-) diff --git a/FunGame.Core.Api/Interface/Interface.cs b/FunGame.Core.Api/Interface/Interface.cs index e382cfc..23955b2 100644 --- a/FunGame.Core.Api/Interface/Interface.cs +++ b/FunGame.Core.Api/Interface/Interface.cs @@ -33,6 +33,6 @@ namespace FunGame.Core.Api.Interface public interface ServerInterface { - public string ServerNotice(); + public string DBConnection(); } } diff --git a/FunGame.Core.Api/Model/Entity/Item.cs b/FunGame.Core.Api/Model/Entity/Item.cs index e484e90..71a8645 100644 --- a/FunGame.Core.Api/Model/Entity/Item.cs +++ b/FunGame.Core.Api/Model/Entity/Item.cs @@ -14,6 +14,7 @@ namespace FunGame.Core.Api.Model.Entity public decimal Price { get; set; } public char Key { get; set; } public bool Active { get; set; } + public bool Enable { get; set; } public Character? Character { get; set; } = null; } } diff --git a/FunGame.Core.Api/Model/Entity/Skill.cs b/FunGame.Core.Api/Model/Entity/Skill.cs index d3d8737..05a3691 100644 --- a/FunGame.Core.Api/Model/Entity/Skill.cs +++ b/FunGame.Core.Api/Model/Entity/Skill.cs @@ -13,5 +13,6 @@ namespace FunGame.Core.Api.Model.Entity public string Describe { get; set; } = ""; public char Key { get; set; } public bool Active { get; set; } + public bool Enable { get; set; } } } diff --git a/FunGame.Core.Api/Model/Entity/User.cs b/FunGame.Core.Api/Model/Entity/User.cs index a87f7ff..13a7c77 100644 --- a/FunGame.Core.Api/Model/Entity/User.cs +++ b/FunGame.Core.Api/Model/Entity/User.cs @@ -20,8 +20,9 @@ namespace FunGame.Core.Api.Model.Entity public bool IsEnable { get; set; } = false; public int OnlineState { get; set; } = 0; public string Roomid { get; set; } = ""; - public int Credits { get; set; } = 0; - public int Material { get; set; } = 0; + public decimal Credits { get; set; } = 0; + public decimal Materials { get; set; } = 0; + public decimal GameTime { get; set; } = 0; public UserStatistics? Statistics { get; set; } = null; public Stock? Stock { get; set; } = null; diff --git a/FunGame.Core.Api/Model/Enum/CommonEnums.cs b/FunGame.Core.Api/Model/Enum/CommonEnums.cs index 11948d6..1dcf206 100644 --- a/FunGame.Core.Api/Model/Enum/CommonEnums.cs +++ b/FunGame.Core.Api/Model/Enum/CommonEnums.cs @@ -90,7 +90,7 @@ namespace FunGame.Core.Api.Model.Enum public enum InterfaceMethod { RemoteServerIP = 1, - ServerNotice = 2 + DBConnection = 2 } #endregion diff --git a/FunGame.Core.Api/Util/AssemblyHelper.cs b/FunGame.Core.Api/Util/AssemblyHelper.cs index c7a3520..a17b116 100644 --- a/FunGame.Core.Api/Util/AssemblyHelper.cs +++ b/FunGame.Core.Api/Util/AssemblyHelper.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using System.Reflection; using System.Diagnostics; using FunGame.Core.Api.Model.Enum; +using System.Data.Common; namespace FunGame.Core.Api.Util { @@ -13,6 +14,7 @@ namespace FunGame.Core.Api.Util /// 在FunGame.Core.Api中添加新接口和新实现时,需要: /// 1、在这里定义类名和方法名 /// 2、在FunGame.Core.Api.Model.Enum.CommonEnums里同步添加InterfaceType和InterfaceMethod + /// 3、在GetClassName(int)、GetMethodName(int)中添加switch分支 /// public class AssemblyHelper { @@ -26,7 +28,38 @@ namespace FunGame.Core.Api.Util * 定义方法名 */ public const string RemoteServerIP = "RemoteServerIP"; - public const string ServerNotice = "ServerNotice"; + public const string DBConnection = "DBConnection"; + + /// + /// 获取实现类类名(xxInterfaceImpl) + /// + /// 接口代号 + /// + private string GetClassName(int Interface) + { + return Interface switch + { + (int)CommonEnums.InterfaceType.ClientConnectInterface => ClientConnectInterface + Implement, + (int)CommonEnums.InterfaceType.ServerInterface => ServerInterface + Implement, + _ => "", + }; + } + + /// + /// 获取方法名 + /// + /// 方法代号 + /// + private string GetMethodName(int Method) + { + // 通过AssemblyHelperType来获取方法名 + return Method switch + { + (int)CommonEnums.InterfaceMethod.RemoteServerIP => RemoteServerIP, + (int)CommonEnums.InterfaceMethod.DBConnection => DBConnection, + _ => "", + }; + } /** * 定义需要反射的DLL @@ -55,17 +88,12 @@ namespace FunGame.Core.Api.Util /// /// 获取FunGame.Core.dll中接口的实现方法 /// - /// 类名 + /// 接口代号 /// private Type? GetFunGameCoreImplement(int Interface) { // 通过类名获取获取命名空间+类名称 - string ClassName = Interface switch - { - (int)CommonEnums.InterfaceType.ClientConnectInterface => ClientConnectInterface + Implement, - (int)CommonEnums.InterfaceType.ServerInterface => ServerInterface + Implement, - _ => "", - }; + string ClassName = GetClassName(Interface); List? Classes = null; if (Assembly != null) { @@ -80,21 +108,8 @@ namespace FunGame.Core.Api.Util else return null; } - private string GetMethodName(int Method) - { - // 通过AssemblyHelperType来获取方法名 - switch (Method) - { - case (int)CommonEnums.InterfaceMethod.RemoteServerIP: - return RemoteServerIP; - case (int)CommonEnums.InterfaceMethod.ServerNotice: - return ServerNotice; - } - return ""; - } - /// - /// 获取FUNGAME.CORE.DLL中指定方法的返回值 + /// 公开方法:获取FUNGAME.CORE.DLL中指定方法的返回值 /// /// 接口代号 /// 方法代号 diff --git a/FunGame.Desktop/Utils/WebHelper.cs b/FunGame.Desktop/Utils/WebHelper.cs index 0f879ea..bce8813 100644 --- a/FunGame.Desktop/Utils/WebHelper.cs +++ b/FunGame.Desktop/Utils/WebHelper.cs @@ -231,7 +231,7 @@ namespace FunGame.Desktop.Utils break; case (int)SocketEnums.Type.HeartBeat: buffer = new byte[2048]; - buffer = Config.DEFAULT_ENCODING.GetBytes(Convert.ToString(MakeMessage((int)SocketEnums.Type.HeartBeat, ">> 心跳检测"))); + buffer = Config.DEFAULT_ENCODING.GetBytes(Convert.ToString(MakeMessage((int)SocketEnums.Type.HeartBeat, "心跳检测"))); if (socket.Send(buffer) > 0) { WaitHeartBeat = Task.Run(() =>