From 54ca623c7f0842b65894c03f612cc6c722b83b8b Mon Sep 17 00:00:00 2001 From: milimoe Date: Tue, 28 Nov 2023 23:23:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84GameMode=E5=92=8CGameMap?= =?UTF-8?q?=E7=9A=84=E8=BF=90=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FunGame.Desktop/Controller/MainController.cs | 76 ++++++++----------- .../Controller/RunTimeController.cs | 2 +- FunGame.Desktop/UI/Main/Main.cs | 37 +++++++-- 3 files changed, 63 insertions(+), 52 deletions(-) diff --git a/FunGame.Desktop/Controller/MainController.cs b/FunGame.Desktop/Controller/MainController.cs index d8ac075..741888b 100644 --- a/FunGame.Desktop/Controller/MainController.cs +++ b/FunGame.Desktop/Controller/MainController.cs @@ -9,31 +9,17 @@ using Milimoe.FunGame.Desktop.UI; namespace Milimoe.FunGame.Desktop.Controller { - public class MainController + public class MainController(Main main) { - private readonly Main Main; private readonly Session Usercfg = RunTime.Session; - private readonly DataRequest ChatRequest; - private readonly DataRequest CreateRoomRequest; - private readonly DataRequest MatchRoomRequest; - private readonly DataRequest GetRoomPlayerCountRequest; - private readonly DataRequest UpdateRoomRequest; - private readonly DataRequest IntoRoomRequest; - private readonly DataRequest QuitRoomRequest; - private readonly DataRequest StartGameRequest; - - public MainController(Main main) - { - Main = main; - ChatRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_Chat); - CreateRoomRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_CreateRoom); - MatchRoomRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_MatchRoom); - GetRoomPlayerCountRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Room_GetRoomPlayerCount); - UpdateRoomRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_UpdateRoom); - IntoRoomRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_IntoRoom); - QuitRoomRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_QuitRoom); - StartGameRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_StartGame); - } + private readonly DataRequest ChatRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_Chat); + private readonly DataRequest CreateRoomRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_CreateRoom); + private readonly DataRequest MatchRoomRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_MatchRoom); + private readonly DataRequest GetRoomPlayerCountRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Room_GetRoomPlayerCount); + private readonly DataRequest UpdateRoomRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_UpdateRoom); + private readonly DataRequest IntoRoomRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_IntoRoom); + private readonly DataRequest QuitRoomRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_QuitRoom); + private readonly DataRequest StartGameRequest = RunTime.NewLongRunningDataRequest(DataRequestType.Main_StartGame); #region 公开方法 @@ -67,7 +53,7 @@ namespace Milimoe.FunGame.Desktop.Controller if (key == Usercfg.LoginKey) { Usercfg.LoginKey = Guid.Empty; - Main.UpdateUI(MainInvokeType.LogOut, msg ?? ""); + main.UpdateUI(MainInvokeType.LogOut, msg ?? ""); return true; } } @@ -76,8 +62,8 @@ namespace Milimoe.FunGame.Desktop.Controller } catch (Exception e) { - Main.ShowMessage(ShowMessageType.Error, "无法登出您的账号,请联系服务器管理员。", "登出失败", 5); - Main.GetMessage(e.GetErrorInfo()); + main.ShowMessage(ShowMessageType.Error, "无法登出您的账号,请联系服务器管理员。", "登出失败", 5); + main.GetMessage(e.GetErrorInfo()); } return false; } @@ -96,7 +82,7 @@ namespace Milimoe.FunGame.Desktop.Controller } catch (Exception e) { - Main.GetMessage(e.GetErrorInfo(), TimeType.None); + main.GetMessage(e.GetErrorInfo(), TimeType.None); return false; } } @@ -112,13 +98,13 @@ namespace Milimoe.FunGame.Desktop.Controller if (UpdateRoomRequest.Result == RequestResult.Success) { list = UpdateRoomRequest.GetResult>("rooms") ?? new(); - Main.UpdateUI(MainInvokeType.UpdateRoom, list); + main.UpdateUI(MainInvokeType.UpdateRoom, list); } else throw new CanNotIntoRoomException(); } catch (Exception e) { - Main.GetMessage(e.GetErrorInfo(), TimeType.None); + main.GetMessage(e.GetErrorInfo(), TimeType.None); } return result; @@ -134,7 +120,7 @@ namespace Milimoe.FunGame.Desktop.Controller } catch (Exception e) { - Main.GetMessage(e.GetErrorInfo(), TimeType.None); + main.GetMessage(e.GetErrorInfo(), TimeType.None); return 0; } } @@ -154,19 +140,19 @@ namespace Milimoe.FunGame.Desktop.Controller if (result) { Config.FunGame_isInRoom = true; - Main.GetMessage("[ " + Usercfg.LoginUser.Username + " ] 准备完毕。"); + main.GetMessage("[ " + Usercfg.LoginUser.Username + " ] 准备完毕。"); } List ReadyPlayerList = request.GetResult>("ready") ?? new(); - if (ReadyPlayerList.Count > 0) Main.GetMessage("已准备的玩家:" + string.Join(", ", ReadyPlayerList.Select(u => u.Username))); + if (ReadyPlayerList.Count > 0) main.GetMessage("已准备的玩家:" + string.Join(", ", ReadyPlayerList.Select(u => u.Username))); List NotReadyPlayerList = request.GetResult>("notready") ?? new(); - if (NotReadyPlayerList.Count > 0) Main.GetMessage("仍未准备的玩家:" + string.Join(", ", NotReadyPlayerList.Select(u => u.Username))); + if (NotReadyPlayerList.Count > 0) main.GetMessage("仍未准备的玩家:" + string.Join(", ", NotReadyPlayerList.Select(u => u.Username))); } request.Dispose(); return result; } catch (Exception e) { - Main.GetMessage(e.GetErrorInfo(), TimeType.None); + main.GetMessage(e.GetErrorInfo(), TimeType.None); return false; } } @@ -186,19 +172,19 @@ namespace Milimoe.FunGame.Desktop.Controller if (result) { Config.FunGame_isInRoom = false; - Main.GetMessage("[ " + Usercfg.LoginUser.Username + " ] 已取消准备。"); + main.GetMessage("[ " + Usercfg.LoginUser.Username + " ] 已取消准备。"); } List ReadyPlayerList = request.GetResult>("ready") ?? new(); - if (ReadyPlayerList.Count > 0) Main.GetMessage("已准备的玩家:" + string.Join(", ", ReadyPlayerList.Select(u => u.Username))); + if (ReadyPlayerList.Count > 0) main.GetMessage("已准备的玩家:" + string.Join(", ", ReadyPlayerList.Select(u => u.Username))); List NotReadyPlayerList = request.GetResult>("notready") ?? new(); - if (NotReadyPlayerList.Count > 0) Main.GetMessage("仍未准备的玩家:" + string.Join(", ", NotReadyPlayerList.Select(u => u.Username))); + if (NotReadyPlayerList.Count > 0) main.GetMessage("仍未准备的玩家:" + string.Join(", ", NotReadyPlayerList.Select(u => u.Username))); } request.Dispose(); return result; } catch (Exception e) { - Main.GetMessage(e.GetErrorInfo(), TimeType.None); + main.GetMessage(e.GetErrorInfo(), TimeType.None); return false; } } @@ -225,18 +211,20 @@ namespace Milimoe.FunGame.Desktop.Controller } catch (Exception e) { - Main.GetMessage(e.GetErrorInfo(), TimeType.None); + main.GetMessage(e.GetErrorInfo(), TimeType.None); return result; } } - public async Task CreateRoomAsync(string RoomType, string Password = "") + public async Task CreateRoomAsync(string RoomType, string GameMode, string GameMap, string Password = "") { Room room = General.HallInstance; try { CreateRoomRequest.AddRequestData("roomtype", RoomType); + CreateRoomRequest.AddRequestData("gamemode", GameMode); + CreateRoomRequest.AddRequestData("gamemap", GameMap); CreateRoomRequest.AddRequestData("master", Usercfg.LoginUser); CreateRoomRequest.AddRequestData("password", Password); await CreateRoomRequest.SendRequestAsync(); @@ -247,7 +235,7 @@ namespace Milimoe.FunGame.Desktop.Controller } catch (Exception e) { - Main.GetMessage(e.GetErrorInfo(), TimeType.None); + main.GetMessage(e.GetErrorInfo(), TimeType.None); } return room; @@ -270,7 +258,7 @@ namespace Milimoe.FunGame.Desktop.Controller } catch (Exception e) { - Main.GetMessage(e.GetErrorInfo(), TimeType.None); + main.GetMessage(e.GetErrorInfo(), TimeType.None); } return result; @@ -290,7 +278,7 @@ namespace Milimoe.FunGame.Desktop.Controller } catch (Exception e) { - Main.GetMessage(e.GetErrorInfo(), TimeType.None); + main.GetMessage(e.GetErrorInfo(), TimeType.None); return false; } } @@ -309,7 +297,7 @@ namespace Milimoe.FunGame.Desktop.Controller } catch (Exception e) { - Main.GetMessage(e.GetErrorInfo(), TimeType.None); + main.GetMessage(e.GetErrorInfo(), TimeType.None); } return false; diff --git a/FunGame.Desktop/Controller/RunTimeController.cs b/FunGame.Desktop/Controller/RunTimeController.cs index dfebea0..25467f1 100644 --- a/FunGame.Desktop/Controller/RunTimeController.cs +++ b/FunGame.Desktop/Controller/RunTimeController.cs @@ -261,7 +261,7 @@ namespace Milimoe.FunGame.Desktop.Controller { // 游戏即将开始 Room room = General.HallInstance; - List users = new(); + List users = []; if (ServerMessage.Length > 0) room = ServerMessage.GetParam(0) ?? General.HallInstance; if (ServerMessage.Length > 1) users = ServerMessage.GetParam>(1) ?? users; Main.UpdateUI(MainInvokeType.StartGame, room, users); diff --git a/FunGame.Desktop/UI/Main/Main.cs b/FunGame.Desktop/UI/Main/Main.cs index f3c34ba..84252cf 100644 --- a/FunGame.Desktop/UI/Main/Main.cs +++ b/FunGame.Desktop/UI/Main/Main.cs @@ -1,6 +1,7 @@ using System.Diagnostics; using Milimoe.FunGame.Core.Api.Utility; using Milimoe.FunGame.Core.Entity; +using Milimoe.FunGame.Core.Library.Common.Addon; using Milimoe.FunGame.Core.Library.Common.Event; using Milimoe.FunGame.Core.Library.Constant; using Milimoe.FunGame.Core.Library.Exception; @@ -483,6 +484,11 @@ namespace Milimoe.FunGame.Desktop.UI await Task.Delay(1000); } WritelnGameInfo("房间 [ " + room.Roomid + " (" + PlayerCount + "人" + RoomSet.GetTypeString(room.RoomType) + ") ] 的游戏正式开始!"); + if (RunTime.GameModeLoader?.Modes.ContainsKey(room.GameMode) ?? false) + { + RunTime.GameModeLoader[room.GameMode].StartUI(); + Visible = false; // 隐藏主界面 + } }); SetButtonEnableIfLogon(false, ClientState.InRoom); } @@ -492,6 +498,7 @@ namespace Milimoe.FunGame.Desktop.UI /// private void EndGame(Room room, List users) { + Visible = true; // test WritelnGameInfo("===== TEST ====="); SetButtonEnableIfLogon(true, ClientState.InRoom); @@ -840,14 +847,20 @@ namespace Milimoe.FunGame.Desktop.UI /// /// /// - private async Task CreateRoom_Handler(string RoomType, string Password = "") + private async Task CreateRoom_Handler(string RoomType, string GameMode, string GameMap, string Password = "") { if (Usercfg.InRoom.Roomid != "-1") { ShowMessage(ShowMessageType.Warning, "已在房间中,无法创建房间。"); return; } - Room room = await InvokeController_CreateRoom(RoomType, Password); + GameMode? mode = RunTime.GameModeLoader?.Modes.Values.FirstOrDefault() ?? default; + if (mode is null) + { + ShowMessage(ShowMessageType.Error, ">> 缺少" + Config.FunGame_RoomType + "所需的模组,无法创建房间。"); + return; + } + Room room = await InvokeController_CreateRoom(RoomType, GameMode, GameMap, Password); if (MainController is not null && room.Roomid != "-1") { await MainController.UpdateRoomAsync(); @@ -1038,7 +1051,13 @@ namespace Milimoe.FunGame.Desktop.UI ShowMessage(ShowMessageType.Warning, "请勾选你要创建的房间类型!"); return; } - TaskUtility.NewTask(() => CreateRoom_Handler(Config.FunGame_RoomType, password)); + GameMode? mode = RunTime.GameModeLoader?.Modes.Values.FirstOrDefault() ?? default; + if (mode is null) + { + ShowMessage(ShowMessageType.Error, ">> 缺少" + Config.FunGame_RoomType + "所需的模组,无法创建房间。"); + return; + } + TaskUtility.NewTask(() => CreateRoom_Handler(Config.FunGame_RoomType, mode.Name, mode.DefaultMap, password)); } /// @@ -1474,14 +1493,18 @@ namespace Milimoe.FunGame.Desktop.UI case Constant.FunGame_CreateMix: if (Usercfg.InRoom.Roomid == "-1") { - TaskUtility.NewTask(() => CreateRoom_Handler(RoomSet.Mix)); + GameMode? mode = RunTime.GameModeLoader?.Modes.Values.FirstOrDefault() ?? default; + if (mode != null) TaskUtility.NewTask(() => CreateRoom_Handler(RoomSet.Mix, mode.Name, mode.DefaultMap)); + else WritelnGameInfo(">> 缺少" + RoomSet.GetTypeString(RoomType.Mix) + "所需的模组,无法创建房间。"); } else WritelnGameInfo(">> 先退出当前房间才可以创建房间。"); break; case Constant.FunGame_CreateTeam: if (Usercfg.InRoom.Roomid == "-1") { - TaskUtility.NewTask(() => CreateRoom_Handler(RoomSet.Team)); + GameMode? mode = RunTime.GameModeLoader?.Modes.Values.FirstOrDefault() ?? default; + if (mode != null) TaskUtility.NewTask(() => CreateRoom_Handler(RoomSet.Team, mode.Name, mode.DefaultMap)); + else WritelnGameInfo(">> 缺少" + RoomSet.GetTypeString(RoomType.Team) + "所需的模组,无法创建房间。"); } else WritelnGameInfo(">> 先退出当前房间才可以创建房间。"); break; @@ -1808,7 +1831,7 @@ namespace Milimoe.FunGame.Desktop.UI /// /// /// - public async Task InvokeController_CreateRoom(string RoomType, string Password = "") + public async Task InvokeController_CreateRoom(string RoomType, string GameMode, string GameMap, string Password = "") { RoomEventArgs EventArgs = new(RoomType, Password); Room room = General.HallInstance; @@ -1819,7 +1842,7 @@ namespace Milimoe.FunGame.Desktop.UI RunTime.PluginLoader?.OnBeforeCreateRoomEvent(this, EventArgs); if (EventArgs.Cancel) return room; - room = MainController is null ? room : await MainController.CreateRoomAsync(RoomType, Password); + room = MainController is null ? room : await MainController.CreateRoomAsync(RoomType, GameMode, GameMap, Password); if (room.Roomid != "-1") {