diff --git a/Api/Utility/GameModuleLoader.cs b/Api/Utility/GameModuleLoader.cs index 63868cc..e05a694 100644 --- a/Api/Utility/GameModuleLoader.cs +++ b/Api/Utility/GameModuleLoader.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; using Milimoe.FunGame.Core.Library.Common.Addon; using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Service; @@ -37,12 +37,17 @@ namespace Milimoe.FunGame.Core.Api.Utility /// public Dictionary Items { get; } = []; + /// + /// 客户端模组与服务器模组的关联字典 + /// + public Dictionary AssociatedServers { get; } = []; + private GameModuleLoader() { } /// /// 传入 类型来创建指定端的模组读取器 /// runtime = 时,仅读取 - /// runtime = 时,仅读取 + /// runtime = 时,都会读取,并且生成关联字典 /// 都会读取 /// /// 传入 类型来创建指定端的模组读取器 @@ -59,7 +64,16 @@ namespace Milimoe.FunGame.Core.Api.Utility } else if (runtime == FunGameInfo.FunGame.FunGame_Server) { - AddonManager.LoadGameModulesForServer(loader.ServerModules, loader.Characters, loader.Skills, loader.Items, delegates, otherobjs); + AddonManager.LoadGameModulesForServer(loader.Modules, loader.ServerModules, loader.Characters, loader.Skills, loader.Items, delegates, otherobjs); + foreach (GameModule module in loader.Modules.Values) + { + // AssociatedServerModuleName 已经存包含 IsConnectToOtherServerModule 的判断,因此无需重复判断 + if (loader.ServerModules.TryGetValue(module.AssociatedServerModuleName, out GameModuleServer? server) && server != null) + { + loader.AssociatedServers.Add(module, server); + } + else loader.AssociatedServers.Add(module, null); // 服务器获取GameModuleServer时需要判断是否存在模组。 + } AddonManager.LoadGameMaps(loader.Maps, otherobjs); } return loader; diff --git a/Docs/FunGame.Core.xml b/Docs/FunGame.Core.xml index 47f76f0..2877a40 100644 --- a/Docs/FunGame.Core.xml +++ b/Docs/FunGame.Core.xml @@ -386,11 +386,16 @@ 物品表 + + + 客户端模组与服务器模组的关联字典 + + 传入 类型来创建指定端的模组读取器 runtime = 时,仅读取 - runtime = 时,仅读取 + runtime = 时,都会读取,并且生成关联字典 都会读取 传入 类型来创建指定端的模组读取器 @@ -1940,6 +1945,11 @@ 使用switch块分类处理 + + + 注意:服务器模组的名称必须和模组名称相同。除非你指定了 + + 地图:必须继承基类: @@ -1986,6 +1996,11 @@ 地图作者 + + + 长度 + + 宽度 @@ -2001,6 +2016,27 @@ 格子大小 + + + 格子集 + + + + + 使用坐标获取格子,0号格子的坐标是(0, 0),如果你还有高度的话,则是(0, 0, 0) + + + + + + + + + 使用坐标获取格子,从0号开始 + + + + 加载标记 @@ -2059,6 +2095,16 @@ 适用的房间模式 + + + 是否连接其他的服务器模组 + + + + + 如果将 设置为true,那么此属性必须指定一个存在的服务器模组的 名称。 + + 包含了一些常用方法的控制器 @@ -2126,6 +2172,11 @@ Config对象 + + + 关联的服务器模组名称 + + 绑定事件。在后触发 @@ -2201,7 +2252,8 @@ - 模组名称 + 服务器模组的名称 + 如果服务器模组配合一个相关联的模组使用,那么它们的 名称必须相同。 @@ -2281,6 +2333,41 @@ + + + 格子编号 + + + + + 格子在地图中的x坐标 + + + + + 格子在地图中的y坐标 + + + + + 格子在地图中的z坐标 + + + + + 是谁站在这格子上? + + + + + 此格子目前受到了什么影响?或者它有什么技能… + + + + + 此格子呈现的颜色(默认为 ) + + 模组名称 @@ -3011,11 +3098,12 @@ - + 从modules目录加载所有适用于服务器的模组 + diff --git a/Library/Common/Addon/Example/ExampleGameModule.cs b/Library/Common/Addon/Example/ExampleGameModule.cs index 49ab2f1..fcb4da5 100644 --- a/Library/Common/Addon/Example/ExampleGameModule.cs +++ b/Library/Common/Addon/Example/ExampleGameModule.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; using Milimoe.FunGame.Core.Api.Transmittal; using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Entity; @@ -16,11 +16,16 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon.Example public class ExampleGameModuleConstant { public static GameModuleDepend GameModuleDepend => _depends; + public const string ExampleGameModule = "fungame.example.gamemodule"; + public const string ExampleMap = "fungame.example.gamemap"; + public const string ExampleCharacter = "fungame.example.character"; + public const string ExampleSkill = "fungame.example.skill"; + public const string ExampleItem = "fungame.example.item"; - private static readonly string[] Maps = ["Example GameMap"]; - private static readonly string[] Characters = ["Example CharacterModule"]; - private static readonly string[] Skills = ["Example SkillModule"]; - private static readonly string[] Items = ["Example ItemModule"]; + private static readonly string[] Maps = [ExampleMap]; + private static readonly string[] Characters = [ExampleCharacter]; + private static readonly string[] Skills = [ExampleSkill]; + private static readonly string[] Items = [ExampleItem]; private static readonly GameModuleDepend _depends = new(Maps, Characters, Skills, Items); } @@ -30,7 +35,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon.Example /// public class ExampleGameModule : GameModule, IGamingUpdateInfoEvent { - public override string Name => "FunGame Example GameModule"; + public override string Name => ExampleGameModuleConstant.ExampleGameModule; public override string Description => "My First GameModule"; @@ -44,6 +49,14 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon.Example public override RoomType RoomType => RoomType.Mix; + public ExampleGameModule() + { + // 构造函数中可以指定模组连接到哪个模组服务器。 + // 如果你使用自己的,保持默认即可:删除下面两行,并将模组服务器的名称设置为与此模组的名称相同 + IsConnectToOtherServerModule = true; + AssociatedServerModuleName = ExampleGameModuleConstant.ExampleGameModule; + } + protected Gaming? Instance; protected Room room = General.HallInstance; protected List users = []; @@ -97,7 +110,10 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon.Example /// public class ExampleGameModuleServer : GameModuleServer { - public override string Name => "FunGame Example GameModule"; + /// + /// 注意:服务器模组的名称必须和模组名称相同。除非你指定了 + /// + public override string Name => ExampleGameModuleConstant.ExampleGameModule; public override string Description => "My First GameModule"; @@ -245,7 +261,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon.Example /// public class ExampleGameMap : GameMap { - public override string Name => "Example GameMap"; + public override string Name => ExampleGameModuleConstant.ExampleMap; public override string Description => "My First GameMap"; @@ -253,9 +269,11 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon.Example public override string Author => "FunGamer"; + public override float Length => 12.0f; + public override float Width => 12.0f; - public override float Height => 12.0f; + public override float Height => 6.0f; public override float Size => 4.0f; } @@ -265,7 +283,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon.Example /// public class ExampleCharacterModule : CharacterModule { - public override string Name => "Example CharacterModule"; + public override string Name => ExampleGameModuleConstant.ExampleCharacter; public override string Description => "My First CharacterModule"; @@ -301,7 +319,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon.Example /// public class ExampleSkillModule : SkillModule { - public override string Name => "Example SkillModule"; + public override string Name => ExampleGameModuleConstant.ExampleSkill; public override string Description => "My First SkillModule"; @@ -328,7 +346,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon.Example /// public class ExampleItemModule : ItemModule { - public override string Name => "Example ItemModule"; + public override string Name => ExampleGameModuleConstant.ExampleItem; public override string Description => "My First ItemModule"; diff --git a/Library/Common/Addon/Example/ExamplePlugin.cs b/Library/Common/Addon/Example/ExamplePlugin.cs index 33ab8a5..5b43418 100644 --- a/Library/Common/Addon/Example/ExamplePlugin.cs +++ b/Library/Common/Addon/Example/ExamplePlugin.cs @@ -9,7 +9,7 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon.Example /// public class ExamplePlugin : Plugin, ILoginEvent { - public override string Name => "FunGame Example Plugin"; + public override string Name => "fungame.example.plugin"; public override string Description => "My First Plugin"; diff --git a/Library/Common/Addon/GameMap.cs b/Library/Common/Addon/GameMap.cs index 0900f04..8a8c754 100644 --- a/Library/Common/Addon/GameMap.cs +++ b/Library/Common/Addon/GameMap.cs @@ -1,4 +1,4 @@ -using Milimoe.FunGame.Core.Interface.Addons; +using Milimoe.FunGame.Core.Interface.Addons; namespace Milimoe.FunGame.Core.Library.Common.Addon { @@ -24,6 +24,11 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon /// public abstract string Author { get; } + /// + /// 长度 + /// + public abstract float Length { get; } + /// /// 宽度 /// @@ -39,6 +44,27 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon /// public abstract float Size { get; } + /// + /// 格子集 + /// + public Dictionary Grids { get; } = []; + + /// + /// 使用坐标获取格子,0号格子的坐标是(0, 0),如果你还有高度的话,则是(0, 0, 0) + /// + /// + /// + /// + /// + public Grid this[float x, float y, float z = 0] => Grids.Values.Where(g => g.X == x && g.Y == y && g.Z == z).FirstOrDefault(); + + /// + /// 使用坐标获取格子,从0号开始 + /// + /// + /// + public Grid this[int id] => Grids[id]; + /// /// 加载标记 /// @@ -60,6 +86,17 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon { // 地图加载后,不允许再次加载此地图 IsLoaded = true; + // 生成格子 + for (float x = 0; x < Length; x++) + { + for (float y = 0; y< Width; y++) + { + for (float z = 0; z < Height; z++) + { + Grids.Add(Grids.Count, new(Grids.Count, x, y, z)); + } + } + } // 如果加载后需要执行代码,请重写AfterLoad方法 AfterLoad(); } diff --git a/Library/Common/Addon/GameModule.cs b/Library/Common/Addon/GameModule.cs index f94528f..e6d42f0 100644 --- a/Library/Common/Addon/GameModule.cs +++ b/Library/Common/Addon/GameModule.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; using Milimoe.FunGame.Core.Controller; using Milimoe.FunGame.Core.Interface; using Milimoe.FunGame.Core.Interface.Addons; @@ -45,6 +45,20 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon /// public abstract RoomType RoomType { get; } + /// + /// 是否连接其他的服务器模组 + /// + public bool IsConnectToOtherServerModule { get; set; } = false; + + /// + /// 如果将 设置为true,那么此属性必须指定一个存在的服务器模组的 名称。 + /// + public string AssociatedServerModuleName + { + get => IsConnectToOtherServerModule ? _AssociatedServerModuleName : Name; + set => _AssociatedServerModuleName = value; + } + /// /// 包含了一些常用方法的控制器 /// @@ -152,6 +166,11 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon /// protected FunGameConfig Config = new(); + /// + /// 关联的服务器模组名称 + /// + private string _AssociatedServerModuleName = ""; + /// /// 绑定事件。在后触发 /// diff --git a/Library/Common/Addon/GameModuleServer.cs b/Library/Common/Addon/GameModuleServer.cs index c244e64..731ea82 100644 --- a/Library/Common/Addon/GameModuleServer.cs +++ b/Library/Common/Addon/GameModuleServer.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; using Milimoe.FunGame.Core.Controller; using Milimoe.FunGame.Core.Entity; using Milimoe.FunGame.Core.Interface.Addons; @@ -10,7 +10,8 @@ namespace Milimoe.FunGame.Core.Library.Common.Addon public abstract class GameModuleServer : IGameModuleServer { /// - /// 模组名称 + /// 服务器模组的名称 + /// 如果服务器模组配合一个相关联的模组使用,那么它们的 名称必须相同。 /// public abstract string Name { get; } diff --git a/Library/Common/Addon/Grid.cs b/Library/Common/Addon/Grid.cs new file mode 100644 index 0000000..ccaa4db --- /dev/null +++ b/Library/Common/Addon/Grid.cs @@ -0,0 +1,43 @@ +using System.Drawing; +using Milimoe.FunGame.Core.Entity; + +namespace Milimoe.FunGame.Core.Library.Common.Addon +{ + public struct Grid(int id, float x, float y, float z) + { + /// + /// 格子编号 + /// + public int Id { get; } = id; + + /// + /// 格子在地图中的x坐标 + /// + public float X { get; } = x; + + /// + /// 格子在地图中的y坐标 + /// + public float Y { get; } = y; + + /// + /// 格子在地图中的z坐标 + /// + public float Z { get; } = z; + + /// + /// 是谁站在这格子上? + /// + public Dictionary Characters { get; set; } = []; + + /// + /// 此格子目前受到了什么影响?或者它有什么技能… + /// + public Dictionary Skills { get; set; } = []; + + /// + /// 此格子呈现的颜色(默认为 ) + /// + public Color Color { get; set; } = Color.Gray; + } +} diff --git a/Service/AddonManager.cs b/Service/AddonManager.cs index 3110929..af13f15 100644 --- a/Service/AddonManager.cs +++ b/Service/AddonManager.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; using System.Reflection; using Milimoe.FunGame.Core.Interface.Addons; using Milimoe.FunGame.Core.Library.Common.Addon; @@ -99,15 +99,16 @@ namespace Milimoe.FunGame.Core.Service /// 从modules目录加载所有适用于服务器的模组 /// /// + /// /// /// /// /// /// /// - internal static Dictionary LoadGameModulesForServer(Dictionary modules, Dictionary characters, Dictionary skills, Dictionary items, Hashtable delegates, params object[] otherobjs) + internal static Dictionary LoadGameModulesForServer(Dictionary modules, Dictionary servers, Dictionary characters, Dictionary skills, Dictionary items, Hashtable delegates, params object[] otherobjs) { - if (!Directory.Exists(ReflectionSet.GameModuleFolderPath)) return modules; + if (!Directory.Exists(ReflectionSet.GameModuleFolderPath)) return servers; string[] dlls = Directory.GetFiles(ReflectionSet.GameModuleFolderPath, "*.dll"); @@ -117,7 +118,7 @@ namespace Milimoe.FunGame.Core.Service foreach (Type type in assembly.GetTypes().AsEnumerable().Where(type => typeof(IAddon).IsAssignableFrom(type))) { - if (type.IsSubclassOf(typeof(GameModuleServer))) + if (type.IsSubclassOf(typeof(GameModule))) { AddAddonInstances(type, modules, (instance) => { @@ -129,6 +130,18 @@ namespace Milimoe.FunGame.Core.Service return false; }); } + else if (type.IsSubclassOf(typeof(GameModuleServer))) + { + AddAddonInstances(type, servers, (instance) => + { + if (instance.Load(otherobjs)) + { + instance.Controller = new(instance, delegates); + return true; + } + return false; + }); + } else if (type.IsSubclassOf(typeof(CharacterModule))) { AddAddonInstances(type, characters, (instance) => instance.Load(otherobjs)); @@ -144,7 +157,7 @@ namespace Milimoe.FunGame.Core.Service } } - return modules; + return servers; } /// @@ -192,4 +205,4 @@ namespace Milimoe.FunGame.Core.Service } } } -} \ No newline at end of file +}