mirror of
https://github.com/project-redbud/FunGame-Desktop.git
synced 2025-04-20 12:09:34 +08:00
完善GameMode和GameMap的运用
This commit is contained in:
parent
760c81e0ae
commit
54ca623c7f
@ -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<List<Room>>("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<User> ReadyPlayerList = request.GetResult<List<User>>("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<User> NotReadyPlayerList = request.GetResult<List<User>>("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<User> ReadyPlayerList = request.GetResult<List<User>>("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<User> NotReadyPlayerList = request.GetResult<List<User>>("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<Room> CreateRoomAsync(string RoomType, string Password = "")
|
||||
public async Task<Room> 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;
|
||||
|
@ -261,7 +261,7 @@ namespace Milimoe.FunGame.Desktop.Controller
|
||||
{
|
||||
// 游戏即将开始
|
||||
Room room = General.HallInstance;
|
||||
List<User> users = new();
|
||||
List<User> users = [];
|
||||
if (ServerMessage.Length > 0) room = ServerMessage.GetParam<Room>(0) ?? General.HallInstance;
|
||||
if (ServerMessage.Length > 1) users = ServerMessage.GetParam<List<User>>(1) ?? users;
|
||||
Main.UpdateUI(MainInvokeType.StartGame, room, users);
|
||||
|
@ -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
|
||||
/// </summary>
|
||||
private void EndGame(Room room, List<User> users)
|
||||
{
|
||||
Visible = true;
|
||||
// test
|
||||
WritelnGameInfo("===== TEST =====");
|
||||
SetButtonEnableIfLogon(true, ClientState.InRoom);
|
||||
@ -840,14 +847,20 @@ namespace Milimoe.FunGame.Desktop.UI
|
||||
/// <param name="RoomType"></param>
|
||||
/// <param name="Password"></param>
|
||||
/// <returns></returns>
|
||||
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));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -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
|
||||
/// </summary>
|
||||
/// <param name="room"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<Room> InvokeController_CreateRoom(string RoomType, string Password = "")
|
||||
public async Task<Room> 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")
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user