| @@ -20,8 +20,8 @@ service AvailableService | |||
| rpc SendMessage (SendMsg) returns (BoolRes); | |||
| // rpc GetMessage (IDMsg) returns (stream MsgRes); | |||
| rpc StartLearning (IDMsg) returns (BoolRes); // 开始修理机器 | |||
| rpc StartRescueMate (TreatAndRescueMsg) returns (BoolRes); // 开始救人 | |||
| rpc StartTreatMate (TreatAndRescueMsg) returns (BoolRes); | |||
| rpc StartRescueMate (IDMsg) returns (BoolRes); // 开始救人 | |||
| rpc StartTreatMate (IDMsg) returns (BoolRes); // 开始治疗 | |||
| rpc Attack (AttackMsg) returns (BoolRes); // 攻击 | |||
| rpc Graduate (IDMsg) returns (BoolRes); // 相当于逃跑 | |||
| rpc OpenDoor (IDMsg) returns (BoolRes); // 开门 | |||
| @@ -5,16 +5,17 @@ | |||
| xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||
| xmlns:local="clr-namespace:Installer" | |||
| mc:Ignorable="d" | |||
| Title="Installer" Height="450" Width="800"> | |||
| Title="Installer" Height="200" Window.SizeToContent="Width"> | |||
| <Grid> | |||
| <Grid.ColumnDefinitions> | |||
| <ColumnDefinition Width="40" /> | |||
| <ColumnDefinition Width="75" /> | |||
| <ColumnDefinition Width="75" /> | |||
| <ColumnDefinition Width="250" /> | |||
| <ColumnDefinition Width="75" /> | |||
| <ColumnDefinition Width="75" /> | |||
| <ColumnDefinition Width="*" /> | |||
| <ColumnDefinition Width="50" /> | |||
| <ColumnDefinition Width="25" /> | |||
| <ColumnDefinition Width="50" /> | |||
| <ColumnDefinition Width="1*" /> | |||
| <ColumnDefinition Width="1*" /> | |||
| <ColumnDefinition Width="40" /> | |||
| </Grid.ColumnDefinitions> | |||
| <Grid.RowDefinitions> | |||
| @@ -26,22 +27,44 @@ | |||
| <RowDefinition Height="20" /> | |||
| <RowDefinition Height="20" /> | |||
| <RowDefinition Height="20" /> | |||
| <RowDefinition Height="*" /> | |||
| <RowDefinition Height="20" /> | |||
| </Grid.RowDefinitions> | |||
| <TextBlock Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" Text="欢迎使用选手包" Visibility="{Binding InstIntroVis}"/> | |||
| <TextBlock Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="3" Text="你已经安装了选手包,请选择你要进行的操作" Visibility="{Binding EditIntroVis}"/> | |||
| <TextBlock Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="5" Text="{Binding Intro}" /> | |||
| <TextBlock Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="5" Text="{Binding RouteBoxIntro}"/> | |||
| <TextBox Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="5" Name="RouteTxtBox" Text="{Binding Route}" Visibility="{Binding RouteBoxVis}"/> | |||
| <Button Grid.Row="3" Grid.Column="6" Name="GetRouteBtn" Content="Browse..." Command="{Binding ClickBrowseCommand}" Visibility="{Binding RouteBoxVis}" /> | |||
| <Button Grid.Row="3" Grid.Column="7" Name="SetBtm" Content="Confirm" Command="{Binding ClickConfirmCommand}" Visibility="{Binding RouteBoxVis}"/> | |||
| <Button Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="2" Name="UpdateBtn" Content="{Binding UpdateBtnCont}" Command="{Binding ClickUpdateCommand}" Visibility="{Binding MenuVis}" /> | |||
| <Button Grid.Row="5" Grid.Column="2" Grid.ColumnSpan="2" Name="MoveBtn" Content="Move" Command="{Binding ClickMoveCommand}" Visibility="{Binding MenuVis}" /> | |||
| <Button Grid.Row="7" Grid.Column="2" Grid.ColumnSpan="2" Name="UninstBtn" Content="UnInstall" Command="{Binding ClickUninstCommand}" Visibility="{Binding MenuVis}" /> | |||
| <TextBlock Grid.Row="3" Grid.Column="4" Text="Processing" Grid.ColumnSpan="2" Visibility="{Binding ProgressVis}"/> | |||
| <ProgressBar Grid.Row="5" Grid.Column="2" Grid.ColumnSpan="6" Minimum="0" Maximum="100" Name="Progress" Visibility="{Binding ProgressVis}" IsIndeterminate="True"/> | |||
| <TextBlock Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" Text="将主体程序安装在:" Visibility="{Binding InstIntroVis}"/> | |||
| <TextBlock Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="3" Text="将主体程序移动到:" Visibility="{Binding MoveIntroVis}"/> | |||
| <TextBlock Grid.Row="4" Grid.Column="2" Grid.ColumnSpan="4" Text="操作完成!你可以继续操作或退出" Visibility="{Binding CompleteVis}"/> | |||
| <Button Grid.Row="6" Grid.Column="2" Name="BackBtn" Content="返回" Command="{Binding ClickBackCommand}" Visibility="{Binding CompleteVis}"/> | |||
| <Button Grid.Row="6" Grid.Column="4" Grid.ColumnSpan="2" Name="ExitBtn" Content="退出" Command="{Binding ClickExitCommand}" Visibility="{Binding CompleteVis}"/> | |||
| <TextBox Grid.Row="3" Grid.Column="1" Grid.ColumnSpan="3" Name="RouteTxtBox" Text="{Binding Route}" Visibility="{Binding RouteBoxVis}"/> | |||
| <Button Grid.Row="3" Grid.Column="4" Name="GetRouteBtn" Content="Browse..." Command="{Binding ClickBrowseCommand}" Visibility="{Binding RouteBoxVis}" /> | |||
| <Button Grid.Row="3" Grid.Column="5" Name="SetBtm" Content="Confirm" Command="{Binding ClickConfirmCommand}" Visibility="{Binding RouteBoxVis}"/> | |||
| <Button Grid.Row="3" Grid.Column="2" Name="UpdateBtn" Content="Update" Command="{Binding ClickUpdateCommand}" Visibility="{Binding EditIntroVis}" /> | |||
| <TextBlock Grid.Row="3" Grid.Column="1" Text="账号:" Visibility="{Binding LoginVis}" /> | |||
| <TextBlock Grid.Row="5" Grid.Column="1" Text="密码:" Visibility="{Binding LoginVis}" /> | |||
| <TextBox Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="4" Name="Username" Visibility="{Binding LoginVis}" Text="{Binding Username}" /> | |||
| <TextBox Grid.Row="5" Grid.Column="2" Grid.ColumnSpan="4" Name="Password" Visibility="{Binding LoginVis}" Text="{Binding Password}" /> | |||
| <Button Grid.Row="7" Grid.Column="1" Name="Login" Content="登录" Command="{Binding ClickLoginCommand}" Visibility="{Binding LoginVis}"/> | |||
| <Button Grid.Row="7" Grid.Column="2" Name="Launch" Content="{Binding LaunchBtnCont}" Command="{Binding ClickLaunchCommand}" Visibility="{Binding LoginVis}"/> | |||
| <Button Grid.Row="7" Grid.Column="4" Grid.ColumnSpan="2" Name="Edit" Content="修改文件" Command="{Binding ClickEditCommand}" Visibility="{Binding LoginVis}"/> | |||
| <TextBlock Grid.Row="6" Grid.Column="1" Text="用户名或密码错误!" Visibility="{Binding LoginFailVis}"/> | |||
| <Button Grid.Row="5" Grid.Column="2" Name="MoveBtn" Content="Move" Command="{Binding ClickMoveCommand}" Visibility="{Binding EditIntroVis}" /> | |||
| <TextBlock Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2" Text="你有已完成的比赛!" Visibility="{Binding MatchFinishedVis}"/> | |||
| <Button Grid.Row="3" Grid.Column="1" Name ="Upload" Content="上传代码" Command="{Binding ClickUploadCommand}" Visibility="{Binding WebVis}"/> | |||
| <Button Grid.Row="5" Grid.Column="1" Name="Download" Content="下载回放" Command="{Binding ClickDownloadCommand}" Visibility="{Binding WebVis}" /> | |||
| <Button Grid.Row="7" Grid.Column="1" Name="Replay" Content="打开回放" Command="{Binding ClickReplayCommand}" Visibility="{Binding WebVis}" /> | |||
| <Button Grid.Row="3" Grid.Column="3" Grid.ColumnSpan="2" Content="申请对战" Command="{Binding ClickRequestCommand}" Visibility="{Binding WebVis}" /> | |||
| <TextBox Grid.Row="4" Grid.Column="3" Grid.ColumnSpan="2" Text="{Binding Enemy}" Visibility="{Binding WebVis}" /> | |||
| <Button Grid.Row="6" Grid.Column="3" Grid.ColumnSpan="2" Content="退出登录" Command="{Binding ClickLogoutCommand}" Visibility="{Binding WebVis}" /> | |||
| <Button Grid.Row="7" Grid.Column="2" Name="UninstBtn" Content="UnInst" Command="{Binding ClickUninstCommand}" Visibility="{Binding EditIntroVis}" /> | |||
| </Grid> | |||
| </Window> | |||
| @@ -22,6 +22,9 @@ using System.Windows; | |||
| using System.Windows.Shapes; | |||
| //using System.Windows.Forms; | |||
| using MessageBox = System.Windows.MessageBox; | |||
| using Downloader; | |||
| namespace starter.viewmodel.settings | |||
| { | |||
| /// <summary> | |||
| @@ -32,27 +35,25 @@ namespace starter.viewmodel.settings | |||
| /// <summary> | |||
| /// downloader function | |||
| /// </summary> | |||
| private Downloader.Program.Data configData = new Downloader.Program.Data(""); | |||
| private Downloader.Program.Tencent_cos_download cloud = new Downloader.Program.Tencent_cos_download(); | |||
| private Data configData = new Data(""); | |||
| private Tencent_cos_download cloud = new Tencent_cos_download(); | |||
| private HttpClient client = new HttpClient(); | |||
| private WebConnect.Web web = new WebConnect.Web(); | |||
| /// <summary> | |||
| /// save settings | |||
| /// </summary> | |||
| public bool install() | |||
| { | |||
| if (Downloader.Program.Tencent_cos_download.CheckAlreadyDownload()) | |||
| if (Tencent_cos_download.CheckAlreadyDownload()) | |||
| { | |||
| MessageBoxResult repeatOption = MessageBox.Show($"文件已存在于{Downloader.Program.Data.FilePath},是否移动到新位置?", "重复安装", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel); | |||
| MessageBoxResult repeatOption = MessageBox.Show($"文件已存在于{Downloader.Program.Data.FilePath},是否移动到新位置?", "重复安装", MessageBoxButton.YesNo, MessageBoxImage.Warning, MessageBoxResult.No); | |||
| // ask if abort install, with warning sign, defalut no; | |||
| if (repeatOption == MessageBoxResult.Cancel) | |||
| if (repeatOption == MessageBoxResult.No) | |||
| { | |||
| return false; // 回到选择地址界面 | |||
| } | |||
| else if (repeatOption == MessageBoxResult.No) | |||
| { | |||
| System.Environment.Exit(0); | |||
| return false; | |||
| } | |||
| else | |||
| { | |||
| Downloader.Program.Tencent_cos_download.MoveProgram(Route); | |||
| @@ -61,11 +62,76 @@ namespace starter.viewmodel.settings | |||
| } | |||
| else | |||
| { | |||
| Downloader.Program.Data.ResetFilepath(Route); | |||
| Downloader.Program.Tencent_cos_download.DownloadAll(); | |||
| Data.ResetFilepath(Route); | |||
| Tencent_cos_download.DownloadAll(); | |||
| return true; | |||
| } | |||
| } | |||
| public int move() | |||
| { | |||
| return Tencent_cos_download.MoveProgram(Route); | |||
| } | |||
| ///<summary> | |||
| ///check for update | |||
| /// </summary> | |||
| static bool ProfileAvailable | |||
| { | |||
| get; set; | |||
| } | |||
| /// <summary> | |||
| /// 检查更新 | |||
| /// </summary> | |||
| /// <returns></returns> | |||
| public Status checkUpdate() | |||
| { | |||
| UpdateInfo updateInfo = Tencent_cos_download.Check(); | |||
| if (updateInfo.newFileCount == -1) | |||
| { | |||
| if (updateInfo.changedFileCount == -1) | |||
| { | |||
| return Status.error; | |||
| } | |||
| else | |||
| { | |||
| return Status.disconnected; | |||
| } | |||
| } | |||
| else | |||
| { | |||
| if (updateInfo.changedFileCount != 0 || updateInfo.newFileCount != 0) | |||
| { | |||
| Updates = "发现新版本" + updateInfo.status; | |||
| } | |||
| return Status.menu; | |||
| } | |||
| } | |||
| public void Login() | |||
| { | |||
| _ = web.LoginToEEsast(client, Username, Password); | |||
| } | |||
| public bool Update() | |||
| { | |||
| return Tencent_cos_download.Update(); | |||
| } | |||
| public int Uninst() | |||
| { | |||
| return Tencent_cos_download.DeleteAll(); | |||
| } | |||
| public bool Launch() | |||
| { | |||
| if (Tencent_cos_download.CheckAlreadyDownload()) | |||
| { | |||
| Process.Start(System.IO.Path.Combine(Data.FilePath, startName)); | |||
| return true; | |||
| } | |||
| else | |||
| { | |||
| MessageBox.Show($"文件还不存在,请安装主体文件", "文件不存在", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); | |||
| return false; | |||
| } | |||
| } | |||
| /// <summary> | |||
| /// Route of files | |||
| /// </summary> | |||
| @@ -73,24 +139,69 @@ namespace starter.viewmodel.settings | |||
| { | |||
| get | |||
| { | |||
| return Downloader.Program.Data.FilePath; | |||
| return Data.FilePath; | |||
| } | |||
| set | |||
| { | |||
| Downloader.Program.Data.FilePath = value; | |||
| Data.FilePath = value; | |||
| } | |||
| } | |||
| public string Username | |||
| { | |||
| get; set; | |||
| } | |||
| public string Password | |||
| { | |||
| get; set; | |||
| } | |||
| /// <summary> | |||
| /// if the route was set or is under editing | |||
| /// 关于更新的屏幕显示信息 | |||
| /// </summary> | |||
| public bool EditingRoute | |||
| private string updates; | |||
| public string Updates | |||
| { | |||
| get | |||
| { | |||
| return updates; | |||
| } | |||
| set | |||
| { | |||
| updates = value; | |||
| } | |||
| } | |||
| /// <summary> | |||
| /// 关于介绍的屏幕显示信息 | |||
| /// </summary> | |||
| public enum Status { newUser, menu, move, working, disconnected, error, successful, login, web }; | |||
| public Status status | |||
| { | |||
| get; set; | |||
| } | |||
| public bool Working | |||
| { | |||
| get; set; | |||
| } | |||
| ///< summary> | |||
| /// if already installed | |||
| /// </summary> | |||
| public bool installed | |||
| /// <summary> | |||
| /// if an update is planned | |||
| /// </summary> | |||
| public bool UpdatePlanned | |||
| { | |||
| get | |||
| { | |||
| return Program.UpdatePlanned; | |||
| } | |||
| } | |||
| public bool CombatCompleted | |||
| { | |||
| get | |||
| { | |||
| return false; | |||
| } | |||
| } | |||
| public bool LoginFailed | |||
| { | |||
| get; set; | |||
| } | |||
| @@ -102,9 +213,21 @@ namespace Downloader | |||
| { | |||
| static List<string> newFileName = new List<string>(); // 新文件名 | |||
| static List<string> updateFileName = new List<string>(); // 更新文件名 | |||
| static string ProgramName = "THUAI6"; // 要运行或下载的程序名称 | |||
| static string playerFolder = "player"; // 选手代码保存文件夹路径 | |||
| static string startName = "maintest.exe"; // 启动的程序名 | |||
| public static string ProgramName = "THUAI6"; // 要运行或下载的程序名称 | |||
| public static string playerFolder = "player"; // 选手代码保存文件夹路径 | |||
| public static string startName = "maintest.exe"; // 启动的程序名 | |||
| public struct UpdateInfo // 更新信息,包括新版本版本号、更改文件数和新文件数 | |||
| { | |||
| public string status; | |||
| public int changedFileCount; | |||
| public int newFileCount; | |||
| } | |||
| public static bool UpdatePlanned | |||
| { | |||
| get; set; | |||
| } | |||
| static int filenum = 0; // 总文件个数 | |||
| public class Data | |||
| @@ -283,13 +406,14 @@ namespace Downloader | |||
| } | |||
| } | |||
| private static void Check() | |||
| public static UpdateInfo Check() | |||
| { | |||
| string json, MD5, jsonName; | |||
| int newFile = 0, updateFile = 0; | |||
| newFileName.Clear(); | |||
| updateFileName.Clear(); | |||
| jsonName = "hash.json"; | |||
| UpdateInfo updateInfo; | |||
| Tencent_cos_download Downloader = new Tencent_cos_download(); | |||
| try | |||
| @@ -308,14 +432,18 @@ namespace Downloader | |||
| catch (CosClientException clientEx) | |||
| { | |||
| // 请求失败 | |||
| Console.WriteLine("CosClientException: " + clientEx.ToString() + Environment.NewLine); | |||
| return; | |||
| updateInfo.status = "ClientEx: " + clientEx.ToString(); | |||
| updateInfo.newFileCount = -1; | |||
| updateInfo.changedFileCount = 0; | |||
| return updateInfo; | |||
| } | |||
| catch (CosServerException serverEx) | |||
| { | |||
| // 请求失败 | |||
| Console.WriteLine("CosClientException: " + serverEx.ToString() + Environment.NewLine); | |||
| return; | |||
| updateInfo.status = "ServerEx: " + serverEx.ToString(); | |||
| updateInfo.newFileCount = -1; | |||
| updateInfo.changedFileCount = 0; | |||
| return updateInfo; | |||
| } | |||
| using (StreamReader r = new StreamReader(System.IO.Path.Combine(Data.FilePath, jsonName))) | |||
| @@ -334,22 +462,29 @@ namespace Downloader | |||
| newFile = newFileName.Count; | |||
| updateFile = updateFileName.Count; | |||
| filenum = newFile + updateFile; | |||
| Console.WriteLine("----------------------" + Environment.NewLine); | |||
| //Console.WriteLine("----------------------" + Environment.NewLine); | |||
| if (newFile + updateFile == 0) | |||
| { | |||
| Console.WriteLine("当前平台已是最新版本!" + Environment.NewLine); | |||
| updateInfo.status = "latest"; | |||
| updateInfo.newFileCount = 0; | |||
| updateInfo.changedFileCount = 0; | |||
| newFileName.Clear(); | |||
| updateFileName.Clear(); | |||
| } | |||
| else | |||
| { | |||
| Console.WriteLine($"发现{newFile}个新文件" + Environment.NewLine); | |||
| updateInfo.status = "old"; | |||
| //TODO:获取版本号 | |||
| updateInfo.newFileCount = newFile; | |||
| /* | |||
| foreach (string filename in newFileName) | |||
| { | |||
| Console.WriteLine(filename); | |||
| } | |||
| Console.WriteLine(Environment.NewLine + $"发现{updateFile}个文件更新" + Environment.NewLine); | |||
| */ | |||
| updateInfo.changedFileCount = updateFile; | |||
| /* | |||
| foreach (string filename in updateFileName) | |||
| { | |||
| Console.WriteLine(filename); | |||
| @@ -359,8 +494,23 @@ namespace Downloader | |||
| Console.WriteLine("下载取消!"); | |||
| else | |||
| Download(); | |||
| */ | |||
| UpdatePlanned = true; | |||
| } | |||
| return updateInfo; | |||
| } | |||
| public static bool Update() | |||
| { | |||
| if (UpdatePlanned) | |||
| { | |||
| Download(); | |||
| UpdatePlanned = false; | |||
| return true; | |||
| } | |||
| return false; | |||
| } | |||
| private static void Download() | |||
| { | |||
| Tencent_cos_download Downloader = new Tencent_cos_download(); | |||
| @@ -592,7 +742,7 @@ namespace Downloader | |||
| } | |||
| } | |||
| public static void DeleteAll() | |||
| public static int DeleteAll() | |||
| { | |||
| DirectoryInfo di = new DirectoryInfo(Data.FilePath); | |||
| DirectoryInfo player = new DirectoryInfo(System.IO.Path.GetFullPath(System.IO.Path.Combine(Data.FilePath, playerFolder))); | |||
| @@ -619,17 +769,17 @@ namespace Downloader | |||
| catch (UnauthorizedAccessException) | |||
| { | |||
| Console.WriteLine("权限不足,无法删除!"); | |||
| return; | |||
| return -2; | |||
| } | |||
| catch (DirectoryNotFoundException) | |||
| { | |||
| Console.WriteLine("文件夹没有找到,请检查是否已经手动更改路径"); | |||
| return; | |||
| return -3; | |||
| } | |||
| catch (IOException) | |||
| { | |||
| Console.WriteLine("文件已经打开,请关闭后再删除"); | |||
| return; | |||
| return -1; | |||
| } | |||
| string json2; | |||
| @@ -665,19 +815,20 @@ namespace Downloader | |||
| catch (UnauthorizedAccessException) | |||
| { | |||
| Console.WriteLine("权限不足,无法删除!"); | |||
| return; | |||
| return -2; | |||
| } | |||
| catch (DirectoryNotFoundException) | |||
| { | |||
| Console.WriteLine("文件夹没有找到,请检查是否已经手动更改路径"); | |||
| return; | |||
| return -3; | |||
| } | |||
| catch (IOException) | |||
| { | |||
| Console.WriteLine("文件已经打开,请关闭后再删除"); | |||
| return; | |||
| return -1; | |||
| } | |||
| Console.WriteLine($"删除成功!player文件夹中的文件已经放在{ProgramName}的根目录下"); | |||
| return 0; | |||
| } | |||
| public static void OverwriteHash(Dictionary<string, string> jsonDict) | |||
| @@ -687,7 +838,7 @@ namespace Downloader | |||
| File.WriteAllText(@System.IO.Path.Combine(Data.FilePath, "hash.json"), Contentjson); | |||
| } | |||
| public static void MoveProgram(string newPath) | |||
| public static int MoveProgram(string newPath) | |||
| { | |||
| DirectoryInfo newdi = new DirectoryInfo(newPath); | |||
| DirectoryInfo olddi = new DirectoryInfo(Data.FilePath); | |||
| @@ -714,6 +865,7 @@ namespace Downloader | |||
| file.MoveTo(System.IO.Path.Combine(Data.FilePath, file.Name)); | |||
| } | |||
| Console.WriteLine("移动失败!"); | |||
| return -2; | |||
| } | |||
| catch (IOException) | |||
| { | |||
| @@ -727,9 +879,11 @@ namespace Downloader | |||
| file.MoveTo(System.IO.Path.Combine(Data.FilePath, file.Name)); | |||
| } | |||
| Console.WriteLine("移动失败!"); | |||
| return -1; | |||
| } | |||
| Data.ResetFilepath(newPath); | |||
| Console.WriteLine("更改路径成功!"); | |||
| return 0; | |||
| } | |||
| public static async Task main(string[] args) | |||
| { | |||
| @@ -3,6 +3,9 @@ using starter.viewmodel.common; | |||
| using System; | |||
| using System.Windows; | |||
| using System.Windows.Forms; | |||
| using Downloader; | |||
| using MessageBox = System.Windows.MessageBox; | |||
| using System.Configuration; | |||
| namespace starter.viewmodel.settings | |||
| { | |||
| @@ -19,12 +22,111 @@ namespace starter.viewmodel.settings | |||
| { | |||
| if (Downloader.Program.Tencent_cos_download.CheckAlreadyDownload()) | |||
| { | |||
| Installed = true; | |||
| obj.checkUpdate(); | |||
| Status = SettingsModel.Status.login; | |||
| this.RaisePropertyChanged("WindowWidth"); | |||
| //TODO:在启动时立刻检查更新,确保选手启动最新版选手包 | |||
| //TODO:若有更新,将启动键改为更新键; | |||
| //TODO:相应地,使用login界面启动; | |||
| //TODO:结构:上方为登录框架,下方有“修改选手包”按钮 | |||
| } | |||
| else | |||
| { | |||
| Route = Environment.GetEnvironmentVariable("USERPROFILE") + "\\THUAI6"; | |||
| EditingRoute = true; | |||
| Status = SettingsModel.Status.newUser; | |||
| this.RaisePropertyChanged("WindowWidth"); | |||
| } | |||
| } | |||
| //TODO:参赛界面:包括上传参赛代码、申请对战 | |||
| //TODO:界面中应包含上次对战完成提示及下载回放按钮 | |||
| public int ExtraColumn | |||
| { | |||
| get | |||
| { | |||
| if (Status == SettingsModel.Status.newUser || Status == SettingsModel.Status.move) | |||
| return 75; | |||
| else | |||
| return 0; | |||
| } | |||
| } | |||
| public int WindowWidth | |||
| { | |||
| get | |||
| { | |||
| switch (Status) | |||
| { | |||
| case SettingsModel.Status.newUser: | |||
| return 505; | |||
| case SettingsModel.Status.move: | |||
| return 505; | |||
| case SettingsModel.Status.working: | |||
| return 435; | |||
| case SettingsModel.Status.successful: | |||
| return 435; | |||
| default: | |||
| return 355; | |||
| } | |||
| } | |||
| } | |||
| public SettingsModel.Status Status | |||
| { | |||
| get | |||
| { | |||
| return obj.status; | |||
| } | |||
| set | |||
| { | |||
| obj.status = value; | |||
| this.RaisePropertyChanged("ExtraColumn"); | |||
| this.RaisePropertyChanged("Intro"); | |||
| this.RaisePropertyChanged("RouteBoxIntro"); | |||
| this.RaisePropertyChanged("LoginVis"); | |||
| this.RaisePropertyChanged("MenuVis"); | |||
| this.RaisePropertyChanged("RouteBoxVis"); | |||
| this.RaisePropertyChanged("ProgressVis"); | |||
| this.RaisePropertyChanged("CompleteVis"); | |||
| } | |||
| } | |||
| public string Intro | |||
| { | |||
| get | |||
| { | |||
| switch (Status) | |||
| { | |||
| case SettingsModel.Status.newUser: | |||
| return "欢迎使用选手包,请选择你想要安装选手包的位置:"; | |||
| case SettingsModel.Status.menu: | |||
| return "你已经安装了选手包,请选择想要进行的操作:"; | |||
| case SettingsModel.Status.login: | |||
| return "使用EESAST账号登录"; | |||
| case SettingsModel.Status.web: | |||
| return "THUAI6 赛场:"; | |||
| case SettingsModel.Status.disconnected: | |||
| return "你可能没有连接到网络,无法下载/更新选手包"; | |||
| case SettingsModel.Status.error: | |||
| return "我们遇到了一些问题,请向[]反馈"; | |||
| default: | |||
| return ""; | |||
| } | |||
| } | |||
| } | |||
| public string RouteBoxIntro | |||
| { | |||
| get | |||
| { | |||
| switch (Status) | |||
| { | |||
| case SettingsModel.Status.newUser: | |||
| return "将主体程序安装在:"; | |||
| case SettingsModel.Status.move: | |||
| return "将主体程序移动到:"; | |||
| default: | |||
| return ""; | |||
| } | |||
| } | |||
| } | |||
| @@ -40,67 +142,106 @@ namespace starter.viewmodel.settings | |||
| this.RaisePropertyChanged("Route"); | |||
| } | |||
| } | |||
| public bool Installed | |||
| public string Username | |||
| { | |||
| get | |||
| { | |||
| return obj.installed; | |||
| return obj.Username; | |||
| } | |||
| set | |||
| { | |||
| obj.installed = value; | |||
| this.RaisePropertyChanged("Installed"); | |||
| this.RaisePropertyChanged("InstIntroVis"); | |||
| this.RaisePropertyChanged("EditIntroVis"); | |||
| this.RaisePropertyChanged("MoveIntroVis"); | |||
| obj.Username = value; | |||
| this.RaisePropertyChanged("Username"); | |||
| } | |||
| } | |||
| public bool EditingRoute | |||
| public string Password | |||
| { | |||
| get { return obj.Password; } | |||
| set | |||
| { | |||
| obj.Password = value; | |||
| this.RaisePropertyChanged("Password"); | |||
| } | |||
| } | |||
| public Visibility MenuVis | |||
| { | |||
| get | |||
| { | |||
| return obj.EditingRoute; | |||
| return Status == SettingsModel.Status.menu ? Visibility.Visible : Visibility.Collapsed; | |||
| } | |||
| set | |||
| } | |||
| public Visibility RouteBoxVis | |||
| { | |||
| get | |||
| { | |||
| obj.EditingRoute = value; | |||
| this.RaisePropertyChanged("EditingRoute"); | |||
| this.RaisePropertyChanged("MoveIntroVis"); | |||
| this.RaisePropertyChanged("RouteBoxVis"); | |||
| return (Status == SettingsModel.Status.newUser || Status == SettingsModel.Status.move) ? Visibility.Visible : Visibility.Collapsed; | |||
| } | |||
| } | |||
| public Visibility RouteBoxVis // if the route editing textbox is visible | |||
| public Visibility LoginVis | |||
| { | |||
| get | |||
| { | |||
| return obj.EditingRoute ? Visibility.Visible : Visibility.Collapsed; | |||
| return Status == SettingsModel.Status.login ? Visibility.Visible : Visibility.Collapsed; | |||
| } | |||
| } | |||
| /// <summary> | |||
| /// if the install/edit instruction can be seen | |||
| /// </summary> | |||
| public Visibility InstIntroVis | |||
| public Visibility ProgressVis | |||
| { | |||
| get | |||
| { | |||
| return Status == SettingsModel.Status.working ? Visibility.Visible : Visibility.Collapsed; | |||
| } | |||
| } | |||
| public Visibility CompleteVis | |||
| { | |||
| get | |||
| { | |||
| return obj.installed ? Visibility.Collapsed : Visibility.Visible; | |||
| return Status == SettingsModel.Status.successful ? Visibility.Visible : Visibility.Collapsed; | |||
| } | |||
| } | |||
| public Visibility EditIntroVis | |||
| public Visibility WebVis | |||
| { | |||
| get | |||
| { | |||
| return obj.installed ? Visibility.Visible : Visibility.Collapsed; | |||
| return Status == SettingsModel.Status.web ? Visibility.Visible : Visibility.Collapsed; | |||
| } | |||
| } | |||
| public Visibility MoveIntroVis | |||
| public Visibility LoginFailVis | |||
| { | |||
| get | |||
| { | |||
| if (obj.installed == true && obj.EditingRoute == true) | |||
| return Visibility.Visible; | |||
| return obj.LoginFailed ? Visibility.Visible : Visibility.Collapsed; | |||
| } | |||
| } | |||
| public Visibility MatchFinishedVis | |||
| { | |||
| get | |||
| { | |||
| return obj.CombatCompleted ? Visibility.Visible : Visibility.Collapsed; | |||
| } | |||
| } | |||
| public string UpdateBtnCont | |||
| { | |||
| get | |||
| { | |||
| return obj.UpdatePlanned ? "Update" : "Check Updates"; | |||
| } | |||
| } | |||
| public string UpdateInfo | |||
| { | |||
| get | |||
| { | |||
| if (obj.UpdatePlanned) | |||
| return obj.Updates; | |||
| else | |||
| return Visibility.Collapsed; | |||
| return ""; | |||
| } | |||
| } | |||
| public string LaunchBtnCont | |||
| { | |||
| get | |||
| { | |||
| return obj.UpdatePlanned ? "更新" : "启动"; | |||
| } | |||
| } | |||
| @@ -133,15 +274,175 @@ namespace starter.viewmodel.settings | |||
| { | |||
| clickConfirmCommand = new BaseCommand(new Action<object>(o => | |||
| { | |||
| if (obj.install()) | |||
| if (Status == SettingsModel.Status.newUser) | |||
| { | |||
| EditingRoute = false; | |||
| Installed = true; | |||
| Status = SettingsModel.Status.working; | |||
| if (obj.install()) | |||
| { | |||
| Status = SettingsModel.Status.menu; | |||
| } | |||
| } | |||
| else if (Status == SettingsModel.Status.move) | |||
| { | |||
| Status = SettingsModel.Status.working; | |||
| switch (obj.move()) | |||
| { | |||
| case -1: | |||
| MessageBox.Show("文件已打开或者目标路径下有同名文件!", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); | |||
| break; | |||
| case -2: | |||
| Status = SettingsModel.Status.error; | |||
| break; | |||
| } | |||
| } | |||
| })); | |||
| } | |||
| return clickConfirmCommand; | |||
| } | |||
| } | |||
| private BaseCommand clickUpdateCommand; | |||
| public BaseCommand ClickUpdateCommand | |||
| { | |||
| get | |||
| { | |||
| if (clickUpdateCommand == null) | |||
| { | |||
| clickUpdateCommand = new BaseCommand(new Action<object>(o => | |||
| { | |||
| if (obj.UpdatePlanned) | |||
| { | |||
| Status = SettingsModel.Status.working; | |||
| if (obj.Update()) | |||
| { | |||
| Status = SettingsModel.Status.successful; | |||
| this.RaisePropertyChanged("UpdateButtonCont"); | |||
| } | |||
| else | |||
| Status = SettingsModel.Status.error; | |||
| } | |||
| else | |||
| { | |||
| Status = SettingsModel.Status.working; | |||
| Status = obj.checkUpdate(); | |||
| this.RaisePropertyChanged("UpdateButtonCont"); | |||
| } | |||
| })); | |||
| } | |||
| return clickUpdateCommand; | |||
| } | |||
| } | |||
| private BaseCommand clickMoveCommand; | |||
| public BaseCommand ClickMoveCommand | |||
| { | |||
| get | |||
| { | |||
| if (clickMoveCommand == null) | |||
| { | |||
| clickMoveCommand = new BaseCommand(new Action<object>(o => | |||
| { | |||
| Status = SettingsModel.Status.move; | |||
| })); | |||
| } | |||
| return clickMoveCommand; | |||
| } | |||
| } | |||
| private BaseCommand clickUninstCommand; | |||
| public BaseCommand ClickUninstCommand | |||
| { | |||
| get | |||
| { | |||
| if (clickUninstCommand == null) | |||
| { | |||
| clickUninstCommand = new BaseCommand(new Action<object>(o => | |||
| { | |||
| Status = SettingsModel.Status.working; | |||
| switch (obj.Uninst()) | |||
| { | |||
| case -1: | |||
| Status = SettingsModel.Status.menu; | |||
| MessageBox.Show("文件已经打开,请关闭后再删除", "", MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK); | |||
| break; | |||
| case 0: | |||
| Status = SettingsModel.Status.successful; | |||
| break; | |||
| default: | |||
| Status = SettingsModel.Status.error; | |||
| break; | |||
| } | |||
| })); | |||
| } | |||
| return clickUninstCommand; | |||
| } | |||
| } | |||
| private BaseCommand clickLoginCommand; | |||
| public BaseCommand ClickLoginCommand | |||
| { | |||
| get | |||
| { | |||
| if (clickLoginCommand == null) | |||
| { | |||
| clickLoginCommand = new BaseCommand(new Action<object>(o => | |||
| { | |||
| obj.Login(); | |||
| this.RaisePropertyChanged("LoginFailVis"); | |||
| })); | |||
| } | |||
| return clickLoginCommand; | |||
| } | |||
| } | |||
| private BaseCommand clickLaunchCommand; | |||
| public BaseCommand ClickLaunchCommand | |||
| { | |||
| get | |||
| { | |||
| if (clickLaunchCommand == null) | |||
| { | |||
| clickLaunchCommand = new BaseCommand(new Action<object>(o => | |||
| { | |||
| if (!obj.Launch()) | |||
| { | |||
| Status = SettingsModel.Status.menu; | |||
| } | |||
| })); | |||
| } | |||
| return clickLaunchCommand; | |||
| } | |||
| } | |||
| private BaseCommand clickEditCommand; | |||
| public BaseCommand ClickEditCommand | |||
| { | |||
| get | |||
| { | |||
| if (clickEditCommand == null) | |||
| { | |||
| clickEditCommand = new BaseCommand(new Action<object>(o => | |||
| { | |||
| Status = SettingsModel.Status.menu; | |||
| })); | |||
| } | |||
| return clickEditCommand; | |||
| } | |||
| } | |||
| private BaseCommand clickLogoutCommand; | |||
| public BaseCommand ClickLogoutCommand | |||
| { | |||
| get | |||
| { | |||
| if (clickLogoutCommand == null) | |||
| { | |||
| clickLogoutCommand = new BaseCommand(new Action<object>(o => | |||
| { | |||
| Status = SettingsModel.Status.login; | |||
| })); | |||
| } | |||
| return clickLogoutCommand; | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -22,7 +22,7 @@ namespace Preparation.Utility | |||
| public const int cols = 50; // 列数 | |||
| public const int numOfBirthPoint = 5; | |||
| // public const int numOfGenerator = 9; | |||
| public const int numOfGenerator = 9; | |||
| public const int numOfChest = 8; | |||
| private const int numOfObjNotMap = 5; | |||
| @@ -15,6 +15,9 @@ namespace Server | |||
| [Option('p', "port", Required = true, HelpText = "Server listening port")] | |||
| public ushort ServerPort { get; set; } = 10086; | |||
| [Option('n', "playerNum", Required = false, HelpText = "The number of teams, 1 by defualt")] | |||
| public ushort playerNum { get; set; } = 1; | |||
| [Option('t', "teamCount", Required = false, HelpText = "The number of teams, 1 by defualt")] | |||
| public ushort TeamCount { get; set; } = 1; | |||
| @@ -9,7 +9,7 @@ namespace Server | |||
| public static class CopyInfo | |||
| { | |||
| private static Protobuf.PlaceType ToPlaceType(Preparation.Utility.PlaceType place) | |||
| public static Protobuf.PlaceType ToPlaceType(Preparation.Utility.PlaceType place) | |||
| { | |||
| switch (place) | |||
| { | |||
| @@ -44,7 +44,7 @@ namespace Server | |||
| return Protobuf.PlaceType.NullPlaceType; | |||
| } | |||
| } | |||
| private static Protobuf.PropType ToPropType(Preparation.Utility.PropType prop) | |||
| public static Protobuf.PropType ToPropType(Preparation.Utility.PropType prop) | |||
| { | |||
| switch (prop) | |||
| { | |||
| @@ -67,7 +67,31 @@ namespace Server | |||
| } | |||
| } | |||
| private static Protobuf.PlayerState ToPlayerState(Preparation.Utility.PlayerStateType playerState) | |||
| public static Preparation.Utility.PropType ToPropType(Protobuf.PropType prop) | |||
| { | |||
| switch (prop) | |||
| { | |||
| case Protobuf.PropType.AddSpeed: | |||
| return Preparation.Utility.PropType.AddSpeed; | |||
| case Protobuf.PropType.AddLifeOrAp: | |||
| return Preparation.Utility.PropType.AddLifeOrAp; | |||
| case Protobuf.PropType.AddHpOrAp: | |||
| return Preparation.Utility.PropType.AddHpOrAp; | |||
| case Protobuf.PropType.ShieldOrSpear: | |||
| return Preparation.Utility.PropType.ShieldOrSpear; | |||
| case Protobuf.PropType.Key3: | |||
| return Preparation.Utility.PropType.Key3; | |||
| case Protobuf.PropType.Key5: | |||
| return Preparation.Utility.PropType.Key5; | |||
| case Protobuf.PropType.Key6: | |||
| return Preparation.Utility.PropType.Key6; | |||
| default: | |||
| return Preparation.Utility.PropType.Null; | |||
| } | |||
| } | |||
| public static Protobuf.PlayerState ToPlayerState(Preparation.Utility.PlayerStateType playerState) | |||
| { | |||
| switch (playerState) | |||
| { | |||
| @@ -110,7 +134,7 @@ namespace Server | |||
| return PlayerState.NullStatus; | |||
| } | |||
| } | |||
| private static Protobuf.StudentBuffType ToStudentBuffType(Preparation.Utility.BuffType buffType) | |||
| public static Protobuf.StudentBuffType ToStudentBuffType(Preparation.Utility.BuffType buffType) | |||
| { | |||
| switch (buffType) | |||
| { | |||
| @@ -119,7 +143,7 @@ namespace Server | |||
| return Protobuf.StudentBuffType.NullSbuffType; | |||
| } | |||
| } | |||
| private static Protobuf.TrickerBuffType ToTrickerBuffType(Preparation.Utility.BuffType buffType) | |||
| public static Protobuf.TrickerBuffType ToTrickerBuffType(Preparation.Utility.BuffType buffType) | |||
| { | |||
| switch (buffType) | |||
| { | |||
| @@ -128,7 +152,7 @@ namespace Server | |||
| return Protobuf.TrickerBuffType.NullTbuffType; | |||
| } | |||
| } | |||
| private static Protobuf.BulletType ToBulletType(Preparation.Utility.BulletType bulletType) | |||
| public static Protobuf.BulletType ToBulletType(Preparation.Utility.BulletType bulletType) | |||
| { | |||
| switch (bulletType) | |||
| { | |||
| @@ -141,7 +165,7 @@ namespace Server | |||
| } | |||
| } | |||
| private static Protobuf.StudentType ToStudentType(Preparation.Utility.CharacterType characterType) | |||
| public static Protobuf.StudentType ToStudentType(Preparation.Utility.CharacterType characterType) | |||
| { | |||
| switch (characterType) | |||
| { | |||
| @@ -151,7 +175,18 @@ namespace Server | |||
| return Protobuf.StudentType.NullStudentType; | |||
| } | |||
| } | |||
| private static Protobuf.TrickerType ToTrickerType(Preparation.Utility.CharacterType characterType) | |||
| public static Preparation.Utility.CharacterType ToStudentType(Protobuf.StudentType characterType) | |||
| { | |||
| switch (characterType) | |||
| { | |||
| case Protobuf.StudentType.Athlete: | |||
| return Preparation.Utility.CharacterType.Athlete; | |||
| default: | |||
| return Preparation.Utility.CharacterType.Null; | |||
| } | |||
| } | |||
| public static Protobuf.TrickerType ToTrickerType(Preparation.Utility.CharacterType characterType) | |||
| { | |||
| switch (characterType) | |||
| { | |||
| @@ -162,6 +197,17 @@ namespace Server | |||
| } | |||
| } | |||
| public static Preparation.Utility.CharacterType ToTrickerType(Protobuf.TrickerType characterType) | |||
| { | |||
| switch (characterType) | |||
| { | |||
| case Protobuf.TrickerType.Assassin: | |||
| return Preparation.Utility.CharacterType.Assassin; | |||
| default: | |||
| return Preparation.Utility.CharacterType.Null; | |||
| } | |||
| } | |||
| public static MessageOfObj? Auto(GameObj gameObj) | |||
| { | |||
| switch (gameObj.Type) | |||
| @@ -20,14 +20,14 @@ namespace Server | |||
| protected readonly ArgumentOptions options; | |||
| private HttpSender? httpSender; | |||
| private object gameLock = new(); | |||
| private const int playerNum = 1; // 注意修改 | |||
| private int playerNum => options.playerNum; // 注意修改 | |||
| private MessageToClient currentGameInfo = new(); | |||
| private MessageOfObj currentMapMsg = new(); | |||
| private object newsLock = new(); | |||
| private List<MessageOfNews> currentNews = new(); | |||
| private SemaphoreSlim endGameSem = new(0); | |||
| protected readonly Game game; | |||
| private uint spectatorMinPlayerID = 2022; | |||
| private uint spectatorMinPlayerID = 2023; | |||
| private List<uint> spectatorList = new List<uint>(); | |||
| public int TeamCount => options.TeamCount; | |||
| protected long[] communicationToGameID; // 通信用的ID映射到游戏内的ID,通信中0-3为Student,4为Tricker | |||
| @@ -115,7 +115,7 @@ namespace Server | |||
| mwr?.Flush(); | |||
| if (options.ResultFileName != DefaultArgumentOptions.FileName) | |||
| SaveGameResult(options.ResultFileName + ".json"); | |||
| //SendGameResult(); | |||
| SendGameResult(); | |||
| this.endGameSem.Release(); | |||
| } | |||
| @@ -142,7 +142,7 @@ namespace Server | |||
| currentNews.Clear(); | |||
| } | |||
| currentGameInfo.GameState = gameState; | |||
| currentGameInfo.AllMessage = new(); // 还没写 | |||
| currentGameInfo.AllMessage = GetMessageOfAll(); | |||
| mwr?.WriteOne(currentGameInfo); | |||
| break; | |||
| case GameState.GameStart: | |||
| @@ -160,7 +160,7 @@ namespace Server | |||
| currentNews.Clear(); | |||
| } | |||
| currentGameInfo.GameState = gameState; | |||
| currentGameInfo.AllMessage = new(); // 还没写 | |||
| currentGameInfo.AllMessage = GetMessageOfAll(); // 还没写 | |||
| mwr?.WriteOne(currentGameInfo); | |||
| break; | |||
| default: | |||
| @@ -186,7 +186,14 @@ namespace Server | |||
| private int PlayerIDToTeamID(long playerID) | |||
| { | |||
| if (0 <= playerID && playerID < options.PlayerCountPerTeam) return 0; | |||
| if (playerID == options.PlayerCountPerTeam) return 1; | |||
| if (playerID == 4) return 1; | |||
| return -1; | |||
| } | |||
| private int PlayerTypeToTeamID(Protobuf.PlayerType playerType) | |||
| { | |||
| if (playerType == PlayerType.StudentPlayer) return 0; | |||
| if (playerType == PlayerType.TrickerPlayer) return 1; | |||
| return -1; | |||
| } | |||
| private uint GetBirthPointIdx(long playerID) // 获取出生点位置 | |||
| @@ -200,6 +207,35 @@ namespace Server | |||
| return false; | |||
| } | |||
| private MessageOfAll GetMessageOfAll() | |||
| { | |||
| MessageOfAll msg = new MessageOfAll(); | |||
| //msg.GameTime | |||
| msg.SubjectLeft = GameData.numOfGeneratorRequiredForRepair - (int)game.GameMap.NumOfRepairedGenerators; | |||
| //msg.StudentGraduated | |||
| //msg.StudentQuited | |||
| msg.StudentScore = 0; | |||
| msg.TrickerScore = 0; | |||
| game.GameMap.GameObjLockDict[GameObjType.Character].EnterReadLock(); | |||
| try | |||
| { | |||
| foreach (Character character in game.GameMap.GameObjDict[GameObjType.Character]) | |||
| { | |||
| if (!character.IsGhost()) msg.StudentScore += character.Score; | |||
| else msg.TrickerScore += character.Score; | |||
| } | |||
| } | |||
| finally | |||
| { | |||
| game.GameMap.GameObjLockDict[GameObjType.Character].ExitReadLock(); | |||
| } | |||
| //msg.GateOpened = | |||
| //msg.HiddenGateRefreshed = | |||
| //msg.HiddenGateOpened | |||
| return msg; | |||
| } | |||
| private Protobuf.PlaceType IntToPlaceType(uint n) | |||
| { | |||
| switch (n) | |||
| @@ -234,7 +270,9 @@ namespace Server | |||
| } | |||
| public override Task<BoolRes> TryConnection(IDMsg request, ServerCallContext context) | |||
| { | |||
| #if DEBUG | |||
| Console.WriteLine($"TryConnection ID: {request.PlayerId}"); | |||
| #endif | |||
| var onConnection = new BoolRes(); | |||
| lock (gameLock) | |||
| { | |||
| @@ -273,29 +311,15 @@ namespace Server | |||
| if (communicationToGameID[request.PlayerId] != GameObj.invalidID) //是否已经添加了该玩家 | |||
| return; | |||
| Preparation.Utility.CharacterType characterType = Preparation.Utility.CharacterType.Null; // 待修改 | |||
| Preparation.Utility.CharacterType characterType = Preparation.Utility.CharacterType.Null; | |||
| if (request.PlayerType == PlayerType.StudentPlayer) | |||
| { | |||
| switch (request.StudentType) | |||
| { | |||
| default: | |||
| characterType = Preparation.Utility.CharacterType.Athlete; | |||
| break; | |||
| } | |||
| } | |||
| characterType = CopyInfo.ToStudentType(request.StudentType); | |||
| else if (request.PlayerType == PlayerType.TrickerPlayer) | |||
| { | |||
| switch (request.TrickerType) | |||
| { | |||
| default: | |||
| characterType = Preparation.Utility.CharacterType.Assassin; | |||
| break; | |||
| } | |||
| } | |||
| characterType = CopyInfo.ToTrickerType(request.TrickerType); | |||
| lock (addPlayerLock) | |||
| { | |||
| Game.PlayerInitInfo playerInitInfo = new(GetBirthPointIdx(request.PlayerId), PlayerIDToTeamID(request.PlayerId), request.PlayerId, characterType); | |||
| Game.PlayerInitInfo playerInitInfo = new(GetBirthPointIdx(request.PlayerId), PlayerTypeToTeamID(request.PlayerType), request.PlayerId, characterType); | |||
| long newPlayerID = game.AddPlayer(playerInitInfo); | |||
| if (newPlayerID == GameObj.invalidID) | |||
| return; | |||
| @@ -326,6 +350,9 @@ namespace Server | |||
| public override Task<BoolRes> Attack(AttackMsg request, ServerCallContext context) | |||
| { | |||
| #if DEBUG | |||
| Console.WriteLine($"Attack ID: {request.PlayerId}"); | |||
| #endif | |||
| var gameID = communicationToGameID[request.PlayerId]; | |||
| game.Attack(gameID, request.Angle); | |||
| BoolRes boolRes = new(); | |||
| @@ -348,16 +375,6 @@ namespace Server | |||
| return Task.FromResult(moveRes); | |||
| } | |||
| public override Task<BoolRes> PickProp(PropMsg request, ServerCallContext context) | |||
| { | |||
| BoolRes boolRes = new(); | |||
| var gameID = communicationToGameID[request.PlayerId]; | |||
| if (request.PropType == Protobuf.PropType.NullPropType) | |||
| boolRes.ActSuccess = game.PickProp(gameID, Preparation.Utility.PropType.Null); | |||
| // 待修改 | |||
| return Task.FromResult(boolRes); | |||
| } | |||
| public override Task<BoolRes> SendMessage(SendMsg request, ServerCallContext context) | |||
| { | |||
| var boolRes = new BoolRes(); | |||
| @@ -388,31 +405,81 @@ namespace Server | |||
| #if DEBUG | |||
| Console.WriteLine(news.News); | |||
| #endif | |||
| //teamCommunicatonMsg[request.ToPlayerId].Enqueue(msg); | |||
| } | |||
| boolRes.ActSuccess = true; | |||
| return Task.FromResult(boolRes); | |||
| } | |||
| public override Task<BoolRes> PickProp(PropMsg request, ServerCallContext context) | |||
| { | |||
| #if DEBUG | |||
| Console.WriteLine($"PickProp ID: {request.PlayerId}"); | |||
| #endif | |||
| BoolRes boolRes = new(); | |||
| var gameID = communicationToGameID[request.PlayerId]; | |||
| boolRes.ActSuccess = game.PickProp(gameID, CopyInfo.ToPropType(request.PropType)); | |||
| return Task.FromResult(boolRes); | |||
| } | |||
| public override Task<BoolRes> UseProp(PropMsg request, ServerCallContext context) | |||
| { | |||
| return base.UseProp(request, context); | |||
| #if DEBUG | |||
| Console.WriteLine($"UseProp ID: {request.PlayerId}"); | |||
| #endif | |||
| BoolRes boolRes = new(); | |||
| var gameID = communicationToGameID[request.PlayerId]; | |||
| //boolRes.ActSuccess = game.UseProp(gameID, CopyInfo.ToPropType(request.PropType)); | |||
| return Task.FromResult(boolRes); | |||
| } | |||
| public override Task<BoolRes> ThrowProp(PropMsg request, ServerCallContext context) | |||
| { | |||
| #if DEBUG | |||
| Console.WriteLine($"ThrowProp ID: {request.PlayerId}"); | |||
| #endif | |||
| BoolRes boolRes = new(); | |||
| var gameID = communicationToGameID[request.PlayerId]; | |||
| //boolRes.ActSuccess = game.ThrowProp(gameID, CopyInfo.ToPropType(request.PropType)); | |||
| return Task.FromResult(boolRes); | |||
| } | |||
| public override Task<BoolRes> UseSkill(SkillMsg request, ServerCallContext context) | |||
| { | |||
| return base.UseSkill(request, context); | |||
| #if DEBUG | |||
| Console.WriteLine($"UseSkill ID: {request.PlayerId}"); | |||
| #endif | |||
| BoolRes boolRes = new(); | |||
| var gameID = communicationToGameID[request.PlayerId]; | |||
| //boolRes.ActSuccess = game.UseActiveSkill(gameID, CopyInfo.ToPropType(request.PropType)); | |||
| return Task.FromResult(boolRes); | |||
| } | |||
| public override Task<BoolRes> Graduate(IDMsg request, ServerCallContext context) | |||
| { | |||
| return base.Graduate(request, context); | |||
| #if DEBUG | |||
| Console.WriteLine($"Graduate ID: {request.PlayerId}"); | |||
| #endif | |||
| BoolRes boolRes = new(); | |||
| var gameID = communicationToGameID[request.PlayerId]; | |||
| boolRes.ActSuccess = game.Escape(gameID); | |||
| return Task.FromResult(boolRes); | |||
| } | |||
| public override Task<BoolRes> StartRescueMate(TreatAndRescueMsg request, ServerCallContext context) | |||
| { | |||
| return base.StartRescueMate(request, context); | |||
| #if DEBUG | |||
| Console.WriteLine($"StartRescueMate ID: {request.PlayerId}"); | |||
| #endif | |||
| BoolRes boolRes = new(); | |||
| var gameID = communicationToGameID[request.PlayerId]; | |||
| //boolRes.ActSuccess = game.Rescue(gameID); | |||
| return Task.FromResult(boolRes); | |||
| } | |||
| public override Task<BoolRes> StartTreatMate(TreatAndRescueMsg request, ServerCallContext context) | |||
| { | |||
| return base.StartTreatMate(request, context); | |||
| #if DEBUG | |||
| Console.WriteLine($"StartTreatMate ID: {request.PlayerId}"); | |||
| #endif | |||
| BoolRes boolRes = new(); | |||
| var gameID = communicationToGameID[request.PlayerId]; | |||
| //boolRes.ActSuccess = game.Treat(gameID); | |||
| return Task.FromResult(boolRes); | |||
| } | |||
| public override Task<BoolRes> StartLearning(IDMsg request, ServerCallContext context) | |||
| { | |||
| @@ -424,6 +491,71 @@ namespace Server | |||
| boolRes.ActSuccess = game.Fix(gameID); | |||
| return Task.FromResult(boolRes); | |||
| } | |||
| public override Task<BoolRes> StartOpenChest(IDMsg request, ServerCallContext context) | |||
| { | |||
| #if DEBUG | |||
| Console.WriteLine($"StartOpenChest ID: {request.PlayerId}"); | |||
| #endif | |||
| BoolRes boolRes = new(); | |||
| var gameID = communicationToGameID[request.PlayerId]; | |||
| boolRes.ActSuccess = game.OpenChest(gameID); | |||
| return Task.FromResult(boolRes); | |||
| } | |||
| public override Task<BoolRes> StartOpenGate(IDMsg request, ServerCallContext context) | |||
| { | |||
| #if DEBUG | |||
| Console.WriteLine($"StartOpenGate ID: {request.PlayerId}"); | |||
| #endif | |||
| BoolRes boolRes = new(); | |||
| var gameID = communicationToGameID[request.PlayerId]; | |||
| boolRes.ActSuccess = game.OpenDoorway(gameID); | |||
| return Task.FromResult(boolRes); | |||
| } | |||
| public override Task<BoolRes> OpenDoor(IDMsg request, ServerCallContext context) | |||
| { | |||
| #if DEBUG | |||
| Console.WriteLine($"OpenDoor ID: {request.PlayerId}"); | |||
| #endif | |||
| BoolRes boolRes = new(); | |||
| var gameID = communicationToGameID[request.PlayerId]; | |||
| boolRes.ActSuccess = game.LockOrOpenDoor(gameID); | |||
| return Task.FromResult(boolRes); | |||
| } | |||
| public override Task<BoolRes> CloseDoor(IDMsg request, ServerCallContext context) | |||
| { | |||
| #if DEBUG | |||
| Console.WriteLine($"CloseDoor ID: {request.PlayerId}"); | |||
| #endif | |||
| BoolRes boolRes = new(); | |||
| var gameID = communicationToGameID[request.PlayerId]; | |||
| boolRes.ActSuccess = game.LockOrOpenDoor(gameID); | |||
| return Task.FromResult(boolRes); | |||
| } | |||
| public override Task<BoolRes> EndAllAction(IDMsg request, ServerCallContext context) | |||
| { | |||
| #if DEBUG | |||
| Console.WriteLine($"EndAllAction ID: {request.PlayerId}"); | |||
| #endif | |||
| BoolRes boolRes = new(); | |||
| var gameID = communicationToGameID[request.PlayerId]; | |||
| boolRes.ActSuccess = game.Stop(gameID); | |||
| return Task.FromResult(boolRes); | |||
| } | |||
| public override Task<BoolRes> SkipWindow(IDMsg request, ServerCallContext context) | |||
| { | |||
| #if DEBUG | |||
| Console.WriteLine($"SkipWindow ID: {request.PlayerId}"); | |||
| #endif | |||
| BoolRes boolRes = new(); | |||
| var gameID = communicationToGameID[request.PlayerId]; | |||
| boolRes.ActSuccess = game.ClimbingThroughWindow(gameID); | |||
| return Task.FromResult(boolRes); | |||
| } | |||
| public GameServer(ArgumentOptions options) | |||
| { | |||