using System.Collections;
using Milimoe.FunGame.Core.Library.Common.Addon;
using Milimoe.FunGame.Core.Library.Constant;
using Milimoe.FunGame.Core.Service;
namespace Milimoe.FunGame.Core.Api.Utility
{
public class GameModuleLoader
{
///
/// 适用于客户端的模组集
///
public Dictionary Modules { get; } = [];
///
/// 适用于服务器的模组集
///
public Dictionary ServerModules { get; } = [];
///
/// 游戏地图集
///
public Dictionary Maps { get; } = [];
///
/// 角色表
///
public Dictionary Characters { get; } = [];
///
/// 技能表
///
public Dictionary Skills { get; } = [];
///
/// 物品表
///
public Dictionary Items { get; } = [];
///
/// 客户端模组与服务器模组的关联字典
///
public Dictionary AssociatedServers { get; } = [];
///
/// 已加载的模组DLL名称对应的路径
///
public static Dictionary ModuleFilePaths => new(AddonManager.ModuleFilePaths);
private GameModuleLoader() { }
///
/// 传入 类型来创建指定端的模组读取器
/// runtime = 时,仅读取
/// runtime = 时,都会读取,并且生成关联字典
/// 都会读取
///
/// 传入 类型来创建指定端的模组读取器
/// 用于构建
/// 其他需要传入给插件初始化的对象
///
public static GameModuleLoader LoadGameModules(FunGameInfo.FunGame runtime, Hashtable delegates, params object[] otherobjs)
{
GameModuleLoader loader = new();
if (runtime == FunGameInfo.FunGame.FunGame_Desktop)
{
AddonManager.LoadGameModules(loader.Modules, loader.Characters, loader.Skills, loader.Items, delegates, otherobjs);
AddonManager.LoadGameMaps(loader.Maps, otherobjs);
}
else if (runtime == FunGameInfo.FunGame.FunGame_Server)
{
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;
}
///
/// 获取对应名称的模组实例
/// 如果需要取得服务器模组的实例,请调用
///
///
///
public GameModule this[string name]
{
get
{
return Modules[name];
}
set
{
Modules.TryAdd(name, value);
}
}
///
/// 获取对应名称的服务器模组实例
///
///
///
public GameModuleServer GetServerMode(string name)
{
return ServerModules[name];
}
///
/// 获取对应名称的游戏地图
///
///
///
public GameMap GetGameMap(string name)
{
return Maps[name];
}
}
}