From 146b42bff3b3add10d809e7943db2dfa62a4f812 Mon Sep 17 00:00:00 2001 From: milimoe Date: Sun, 7 Sep 2025 22:42:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=A7=BB=E5=8A=A8=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E7=9B=AE=E6=A0=87=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Desktop/GameMapTesting/GameMapController.cs | 43 +++-- Desktop/GameMapTesting/GameMapTesting.cs | 55 ++++-- Desktop/GameMapTesting/GameMapViewer.xaml | 48 ++++++ Desktop/GameMapTesting/GameMapViewer.xaml.cs | 166 +++++++++++++++++-- 4 files changed, 266 insertions(+), 46 deletions(-) diff --git a/Desktop/GameMapTesting/GameMapController.cs b/Desktop/GameMapTesting/GameMapController.cs index 63534fb..bc8149e 100644 --- a/Desktop/GameMapTesting/GameMapController.cs +++ b/Desktop/GameMapTesting/GameMapController.cs @@ -13,11 +13,12 @@ namespace Milimoe.FunGame.Testing.Desktop.GameMapTesting public bool TeamMode => _game?.TeamMode ?? false; // 输入请求器实例 - private readonly UserInputRequester _characterSelectionRequester = new(); + private readonly UserInputRequester _characterSelectionRequester = new(); + private readonly UserInputRequester _targetGridSelectionRequester = new(); private readonly UserInputRequester _actionTypeRequester = new(); private readonly UserInputRequester> _targetSelectionRequester = new(); - private readonly UserInputRequester _skillSelectionRequester = new(); - private readonly UserInputRequester _itemSelectionRequester = new(); + private readonly UserInputRequester _skillSelectionRequester = new(); + private readonly UserInputRequester _itemSelectionRequester = new(); private readonly UserInputRequester _continuePromptRequester = new(); // 用于“按任意键继续”提示 public async Task WriteLine(string str = "") => await UI.AppendDebugLog(str); @@ -73,7 +74,7 @@ namespace Milimoe.FunGame.Testing.Desktop.GameMapTesting await UI.InvokeAsync(() => UI.SetPredictCharacter(name, ht)); } - public async Task RequestCharacterSelection(List availableCharacters) + public async Task RequestCharacterSelection(List availableCharacters) { await WriteLine("请选择你想玩的角色。"); return await _characterSelectionRequester.RequestInput( @@ -89,6 +90,14 @@ namespace Milimoe.FunGame.Testing.Desktop.GameMapTesting ); } + public async Task RequestTargetGridSelection(Character character, Grid currentGrid, List selectable) + { + await WriteLine($"请选择一个目标地点。"); + return await _targetGridSelectionRequester.RequestInput( + async (callback) => await UI.InvokeAsync(() => UI.ShowTargetGridSelectionUI(character, currentGrid, selectable, callback)) + ); + } + public async Task> RequestTargetSelection(Character character, ISkill skill, List enemys, List teammates) { List selectable = skill.GetSelectableTargets(character, enemys, teammates); @@ -103,19 +112,19 @@ namespace Milimoe.FunGame.Testing.Desktop.GameMapTesting public async Task RequestSkillSelection(Character character, List availableSkills) { await WriteLine($"请为 {character.NickName} 选择一个技能。"); - long? skillId = await _skillSelectionRequester.RequestInput( + Skill? skill = await _skillSelectionRequester.RequestInput( async (callback) => await UI.InvokeAsync(() => UI.ShowSkillSelectionUI(character, callback)) ); - return skillId.HasValue ? availableSkills.FirstOrDefault(s => s.Id == skillId.Value) : null; + return availableSkills.Any(s => s == skill) ? skill : null; } public async Task RequestItemSelection(Character character, List availableItems) { await WriteLine($"请为 {character.NickName} 选择一个物品。"); - long? itemId = await _itemSelectionRequester.RequestInput( + Item? item = await _itemSelectionRequester.RequestInput( async (callback) => await UI.InvokeAsync(() => UI.ShowItemSelectionUI(character, callback)) ); - return itemId.HasValue ? availableItems.FirstOrDefault(i => i.Id == itemId.Value) : null; + return availableItems.Any(i => i == item) ? item : null; } public async Task RequestContinuePrompt(string message) @@ -137,9 +146,9 @@ namespace Milimoe.FunGame.Testing.Desktop.GameMapTesting // --- GameMapViewer 调用这些方法来解决 UI 输入 --- - public async Task ResolveCharacterSelection(long characterId) + public async Task ResolveCharacterSelection(Character? character) { - _characterSelectionRequester.ResolveInput(characterId); + _characterSelectionRequester.ResolveInput(character); await UI.InvokeAsync(() => UI.HideCharacterSelectionPrompt()); } @@ -155,15 +164,21 @@ namespace Milimoe.FunGame.Testing.Desktop.GameMapTesting await UI.InvokeAsync(() => UI.HideTargetSelectionUI()); } - public async Task ResolveSkillSelection(long skillId) + public async Task ResolveTargetGridSelection(Grid? grid) { - _skillSelectionRequester.ResolveInput(skillId); + _targetGridSelectionRequester.ResolveInput(grid); + await UI.InvokeAsync(() => UI.HideTargetGridSelectionUI()); + } + + public async Task ResolveSkillSelection(Skill? skill) + { + _skillSelectionRequester.ResolveInput(skill); await UI.InvokeAsync(() => UI.HideSkillSelectionUI()); } - public async Task ResolveItemSelection(long itemId) + public async Task ResolveItemSelection(Item? item) { - _itemSelectionRequester.ResolveInput(itemId); + _itemSelectionRequester.ResolveInput(item); await UI.InvokeAsync(() => UI.HideItemSelectionUI()); } diff --git a/Desktop/GameMapTesting/GameMapTesting.cs b/Desktop/GameMapTesting/GameMapTesting.cs index 268e3df..f6f6809 100644 --- a/Desktop/GameMapTesting/GameMapTesting.cs +++ b/Desktop/GameMapTesting/GameMapTesting.cs @@ -59,11 +59,16 @@ namespace Milimoe.FunGame.Testing.Desktop.GameMapTesting c.Level = clevel; c.NormalAttack.Level = mlevel; FunGameService.AddCharacterSkills(c, 1, slevel, slevel); - Skill 疾风步 = new 疾风步(c) + Skill skill = new 疾风步(c) { Level = slevel }; - c.Skills.Add(疾风步); + c.Skills.Add(skill); + Skill passive = new 征服者(c) + { + Level = 1 + }; + c.Skills.Add(passive); characters.Add(c); } @@ -75,11 +80,11 @@ namespace Milimoe.FunGame.Testing.Desktop.GameMapTesting // 询问玩家需要选择哪个角色 (通过UI界面选择) Character? player = null; - long selectedPlayerId = await Controller.RequestCharacterSelection(characters); // 异步等待UI选择 - await Controller.ResolveCharacterSelection(selectedPlayerId); - if (selectedPlayerId != -1) + Character? selectedPlayer = await Controller.RequestCharacterSelection(characters); // 异步等待UI选择 + await Controller.ResolveCharacterSelection(selectedPlayer); + if (selectedPlayer != null) { - player = characters.FirstOrDefault(c => c.Id == selectedPlayerId); + player = characters.FirstOrDefault(c => c == selectedPlayer); if (player != null) { await Controller.WriteLine($"选择了 [ {player} ]!"); @@ -303,6 +308,13 @@ namespace Milimoe.FunGame.Testing.Desktop.GameMapTesting await Controller.WriteLine($"=== 回合 {i++} ==="); await Controller.WriteLine("现在是 [ " + characterToAct + " ] 的回合!"); + // 获取该角色当前位置 + if (_gamingQueue.Map != null) + { + Grid? currentGrid = _gamingQueue.Map.GetCharacterCurrentGrid(characterToAct); + if (currentGrid != null) _gamingQueue.CustomData["currentGrid"] = currentGrid; + } + bool isGameEnd = await _gamingQueue.ProcessTurnAsync(characterToAct); if (isGameEnd) @@ -472,17 +484,32 @@ namespace Milimoe.FunGame.Testing.Desktop.GameMapTesting private async Task GamingQueue_SelectTargetGrid(GamingQueue queue, Character character, List enemys, List teammates, GameMap map) { - // 目前,格子选择未直接绑定到UI按钮。 - // 如果“移动”动作被完全实现,这里需要一个UI提示来选择目标格子。 - // 为简化,目前返回一个空Grid。 - await Task.CompletedTask; // 模拟异步操作 - return Grid.Empty; + if (!IsPlayer_OnlyTest(queue, character) || _gamingQueue is null || _gamingQueue.Map is null) return Grid.Empty; + + Grid current = Grid.Empty; + if (_gamingQueue.CustomData.TryGetValue("currentGrid", out object? currentGrid) && currentGrid is Grid grid) + { + current = grid; + } + if (current == Grid.Empty) + { + return current; + } + + // 通过UI请求目标选择 + Grid? selectedTargetGrid = await Controller.RequestTargetGridSelection( + character, + current, + _gamingQueue.Map.GetGridsByRange(current, character.MOV) + ); + await Controller.ResolveTargetGridSelection(selectedTargetGrid); + + return selectedTargetGrid ?? Grid.Empty; } private async Task GamingQueue_CharacterMove(GamingQueue queue, Character actor, Grid grid) { await Controller.UpdateCharacterPositionsOnMap(); - await Task.CompletedTask; } private async Task GamingQueue_QueueUpdated(GamingQueue queue, List characters, Character character, double hardnessTime, QueueUpdatedReason reason, string msg) @@ -521,7 +548,7 @@ namespace Milimoe.FunGame.Testing.Desktop.GameMapTesting // 通过UI请求物品选择 Item? selectedItem = await Controller.RequestItemSelection(character, items); - await Controller.ResolveItemSelection(selectedItem?.Id ?? 0); + await Controller.ResolveItemSelection(selectedItem); return selectedItem; } @@ -552,7 +579,7 @@ namespace Milimoe.FunGame.Testing.Desktop.GameMapTesting // 通过UI请求技能选择 Skill? selectedSkill = await Controller.RequestSkillSelection(character, skills); - await Controller.ResolveSkillSelection(selectedSkill?.Id ?? 0); + await Controller.ResolveSkillSelection(selectedSkill); return selectedSkill; } diff --git a/Desktop/GameMapTesting/GameMapViewer.xaml b/Desktop/GameMapTesting/GameMapViewer.xaml index 40cbf54..7387991 100644 --- a/Desktop/GameMapTesting/GameMapViewer.xaml +++ b/Desktop/GameMapTesting/GameMapViewer.xaml @@ -542,6 +542,54 @@ + + + + + + + + + + + + + + + + + + + + + +