Files
2026-08-28 19:44:46 +08:00

33 lines
4.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 长期项目约定(FunGame.Server-v3)
## 架构方向:一切皆模组(Everything is a Module)
用户确定的设计理念:游戏逻辑由房间内生效的模组定义,服务器仅负责核心队列计算与转发。
**核心是"多玩家联机"**:GameModule 本质是封装网络层在 GamingQueue 之上的"游戏模式模组";c/s/IModule 那套只是内容层。
### 已敲定的分叉(2026-08-26 讨论,2026-08-27 修正)
- **GameModule = 游戏模式模组(核心抽象,参考 v2 设计)**:参考 FunGame.Core **v2 分支** `Interface/Base/Addons/IGameModule.cs`、`IGameModuleServer.cs`、`Library/Common/Addon/GameModule(Server).cs`、`ExampleGameModule.cs`、`GamingObject.cs`,及旧版 `C:\milimoe\fungame.server` 的 `ServerModel` 路由(`SocketMessageType.Gaming` → `NowGamingServer.GamingMessageHandler(this, type, data)` → 结果 `Send` 回客户端)。
- 服务器侧 `IGameModuleServer`:`GamingMessageHandler(model, type, data)` **switch-case 处理 GamingType**(Connect/PickCharacter/Skill/Item/...);`StartServer(GamingObject)` 建房即返回、为每房间建 Worker(玩家/角色/状态);`SendGamingMessage` 广播;模组为单例、`GamingObjects` 管所有进行中对局。
- 客户端侧 `IGameModule`:实现全部 `IGaming*EventHandler`(局内事件就是模组接口面)+ `StartGame(Gaming instance)` + `GameModuleDepend` 声明内容依赖 + `RoomType`/`MaxUsers`/`DefaultMap`。
- **内容层(c/s/IModule)= 纯内容**:角色/技能/物品/Effect 模组(`ICharacterModule` 等 + `Factory.OpenFactory` 显式注册,沿用 `SkillModule.Load()` 与 `EffectHookCache.ScanAllAssemblies()`),GameModule 通过 `GameModuleDepend` 依赖它们。
- **行为/跨模式逻辑**:后续事件订阅模组(全局 Effect / 房间事件总线),非本期重点。
- **热重载**:GameModule 逻辑开局锁定;内容模组可热重载。
- v3 现有 `IServerPlugin.HandleGamingMessage(IGameSession, string type, data)` = v2 `GamingMessageHandler` 的薄版;`gaming.action` 尚未接路由(M7 候选"玩家局内决策接入"即此)。
### 硬约束
- **只改 FunGame.Server-v3,不修改 FunGame.Core 源码**。
- 服务器核心收敛为:薄路由/转发 + 对局会话(`IGameSession`)+ 模组生命周期(解析房间 GameModule 并编排)。
### 迁移路线(绞杀者)
1. ✅ Contracts:`IGameModuleServer` + `GameModuleDepend`(GamingType/RoomType 复用 Core 枚举);扩展 `IGameSession`(Characters/BroadcastAsync/EndGameAsync)。
2. ✅ 标准近战 GameModule(`modules/FunGame.Server.Modules.Melee`):StartGameAsync 建 MixGamingQueue + HandleGamingMessage switch-case(Connect/PickCharacter/Surrender)。
3. ✅ Host:`PluginKind.GameModuleServer` + `modules/games` 目录;`GetGameModule`;`CreateGameFromModule`/`GetGameOfClient`;`gaming.action` 路由;RoomStart 优先 GameModule;GameModulesController modes 纳入。
4. ⏳ 玩家局内决策接入(Attack/Skill/Item/Move 驱动队列)、客户端侧 GameModule(webui)、老 `IServerPlugin` 退役。
### 引擎扩展点备忘(FunGame.Core,只读参考)
- Core 已到 #174:Effect 虚钩子为 **Context 模式**(`OnTurnStart(TurnContext)`/`OnEffectGained(HookContext)` 等),经 `GamingQueue.EffectDispatch.Trigger*` 分发(按角色/全队列);`GamingType`/`RoomType` 枚举在 `Library/Constant/TypeEnum.cs`。
- `MixGamingQueue`/`TeamGamingQueue` 是内置规则(死亡竞赛/组队)。
- `IGameEventHandler` 局内事件当前未在对局循环派发(v3);v2 中它是 GameModule 的接口面。
- `EventCenter` 是探索/活动系统(Stores 可复用为房间 KV)。
- **Oshima 引用不拷贝**:内容权威源 = Testing-v3 独立库 `C:\milimoe\FunGame.Testing-v3\OshimaGameModules\OshimaGameModules.csproj`(最先适配 Core v3);Server-v3 的 `FunGame.Server.Modules.Oshima` 只保留包装层并 ProjectReference 它(CopyModulesToHost 同时复制 `OshimaGameModules.dll` 到 modules/*/_staging)。内容改动只改 Testing-v3,Server 重新 build 即跟随。
- 本地可编译:dotnet 10.0.400 可用。