You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

MainWindow.xaml.cs 71 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using System.Diagnostics;
  16. using System.Windows.Threading;
  17. using Grpc.Core;
  18. using Protobuf;
  19. using Playback;
  20. using CommandLine;
  21. // 目前MainWindow还未复现的功能:
  22. // private void ReactToCommandline(),
  23. // private void ClickToSetMode(object sender, RoutedEventArgs e)
  24. // private void Bonus()
  25. namespace Client
  26. {
  27. /// <summary>
  28. /// Interaction logic for MainWindow.xaml
  29. /// </summary>
  30. public partial class MainWindow : Window
  31. {
  32. public MainWindow()
  33. {
  34. unitHeight = unitWidth = unit = 13;
  35. bonusflag = true;
  36. timer = new DispatcherTimer
  37. {
  38. Interval = new TimeSpan(50000) // 每50ms刷新一次
  39. };
  40. timer.Tick += new EventHandler(Refresh); // 定时器初始化
  41. InitializeComponent();
  42. timer.Start();
  43. SetStatusBar();
  44. isClientStocked = true;
  45. isPlaybackMode = false;
  46. drawPicLock = new();
  47. listOfProp = new List<MessageOfProp>();
  48. listOfHuman = new List<MessageOfStudent>();
  49. listOfButcher = new List<MessageOfTricker>();
  50. listOfBullet=new List<MessageOfBullet>();
  51. listOfBombedBullet = new List<MessageOfBombedBullet>();
  52. listOfAll = new List<MessageOfAll>();
  53. listOfChest = new List<MessageOfChest>();
  54. listOfClassroom = new List<MessageOfClassroom>();
  55. listOfDoor = new List<MessageOfDoor>();
  56. listOfGate = new List<MessageOfGate>();
  57. WindowStartupLocation = WindowStartupLocation.CenterScreen;
  58. //comInfo[0] = "127.0.0.1";
  59. //comInfo[1] = "8888";
  60. //comInfo[2] = "0";
  61. //comInfo[3] = "1";
  62. //comInfo[4] = "1";
  63. //ConnectToServer(comInfo);
  64. //OnReceive();
  65. ReactToCommandline();
  66. }
  67. private void SetStatusBar()
  68. {
  69. StatusBarsOfSurvivor = new StatusBarOfSurvivor[4];
  70. StatusBarsOfHunter = new StatusBarOfHunter(MainGrid, 3, 0);
  71. StatusBarsOfCircumstance = new StatusBarOfCircumstance(MainGrid, 1, 0);
  72. for (int i = 4; i < 8; i++)
  73. {
  74. StatusBarsOfSurvivor[i - 4] = new(MainGrid, i / 2 + 2, i % 2);
  75. }
  76. }
  77. // 获得地图信息,未更新数值
  78. private void GetMap(MessageOfMap obj)
  79. {
  80. int[,] map = new int[50, 50];
  81. try
  82. {
  83. for (int i = 0; i < 50; i++)
  84. {
  85. for (int j = 0; j < 50; j++)
  86. {
  87. map[i, j] = Convert.ToInt32(obj.Row[i].Col[j]) + 4;//与proto一致
  88. }
  89. }
  90. }
  91. catch
  92. {
  93. mapFlag = false;
  94. }
  95. finally
  96. {
  97. defaultMap = map;
  98. mapFlag = true;
  99. }
  100. }
  101. private void ReactToCommandline()
  102. {
  103. string[] args = Environment.GetCommandLineArgs();
  104. if (args.Length == 2)
  105. {
  106. Playback(args[1]);
  107. return;
  108. }
  109. _ = Parser.Default.ParseArguments<ArgumentOptions>(args).WithParsed(o =>
  110. { options = o; });
  111. if (options == null || options.cl == false)
  112. {
  113. OnReceive();
  114. }
  115. else
  116. {
  117. if (options.PlaybackFile == DefaultArgumentOptions.FileName)
  118. {
  119. try
  120. {
  121. OnReceive();
  122. string[] comInfo = new string[5];
  123. comInfo[0] = options.Ip;
  124. comInfo[1] = options.Port;
  125. comInfo[2] = options.PlayerID;
  126. comInfo[3] = options.PlayerType;
  127. comInfo[4] = options.Occupation;
  128. ConnectToServer(comInfo);
  129. }
  130. catch
  131. {
  132. OnReceive();
  133. }
  134. }
  135. else
  136. {
  137. Playback(options.PlaybackFile, options.PlaybackSpeed);
  138. }
  139. }
  140. }
  141. private void Playback(string fileName, double pbSpeed = 2.0)
  142. {
  143. var pbClient = new PlaybackClient(fileName, pbSpeed);
  144. int[,]? map;
  145. if ((map = pbClient.ReadDataFromFile(listOfProp, listOfHuman, listOfButcher, listOfBullet,listOfBombedBullet, listOfAll, listOfChest, listOfClassroom,listOfDoor, listOfGate, drawPicLock)) != null)
  146. {
  147. isClientStocked = false;
  148. isPlaybackMode = true;
  149. defaultMap = map;
  150. mapFlag = true;
  151. }
  152. else
  153. {
  154. MessageBox.Show("Failed to read the playback file!");
  155. isClientStocked = true;
  156. }
  157. }
  158. // 连接Server,comInfo[]的格式:0-ip 1- port 2-playerID 3-human/TrickerType 4-occupation
  159. private void ConnectToServer(string[] comInfo)
  160. {
  161. if (!isPlaybackMode)
  162. {
  163. if (comInfo.Length != 5)
  164. throw new Exception("注册信息有误!");
  165. playerID = Convert.ToInt64(comInfo[2]);
  166. Connect.Background = Brushes.Gray;
  167. string connect = new string(comInfo[0]);
  168. connect += ':';
  169. connect += comInfo[1];
  170. Channel channel = new Channel(connect, ChannelCredentials.Insecure);
  171. client = new AvailableService.AvailableServiceClient(channel);
  172. // 没判断连没连上
  173. PlayerMsg playerMsg = new PlayerMsg();
  174. playerMsg.PlayerId = playerID;
  175. playerType = Convert.ToInt64(comInfo[3]) switch
  176. {
  177. 0 => PlayerType.NullPlayerType,
  178. 1 => PlayerType.StudentPlayer,
  179. 2 => PlayerType.TrickerPlayer,
  180. };
  181. playerMsg.PlayerType=playerType;
  182. if (Convert.ToInt64(comInfo[3]) == 1)
  183. {
  184. humanOrButcher = true;
  185. }
  186. else if (Convert.ToInt64(comInfo[3]) == 2)
  187. {
  188. humanOrButcher = false;
  189. }
  190. if (playerType == PlayerType.StudentPlayer)
  191. {
  192. switch (Convert.ToInt64(comInfo[4]))
  193. {
  194. case 0:
  195. playerMsg.StudentType = StudentType.NullStudentType;
  196. break;
  197. case 1:
  198. playerMsg.StudentType = StudentType.Athlete;
  199. break;
  200. case 2:
  201. playerMsg.StudentType = StudentType._2;
  202. break;
  203. case 3:
  204. playerMsg.StudentType = StudentType._3;
  205. break;
  206. case 4:
  207. playerMsg.StudentType = StudentType._4;
  208. break;
  209. default:
  210. break;
  211. }
  212. }
  213. else if (playerType == PlayerType.TrickerPlayer)
  214. {
  215. switch (Convert.ToInt64(comInfo[4]))
  216. {
  217. case 0:
  218. playerMsg.TrickerType = TrickerType.NullTrickerType;
  219. break;
  220. case 1:
  221. playerMsg.TrickerType = TrickerType.Assassin;
  222. break;
  223. case 2:
  224. playerMsg.TrickerType = TrickerType._2;
  225. break;
  226. case 3:
  227. playerMsg.TrickerType = TrickerType._3;
  228. break;
  229. case 4:
  230. playerMsg.TrickerType = TrickerType._4;
  231. break;
  232. default:
  233. break;
  234. }
  235. }
  236. responseStream = client.AddPlayer(playerMsg);
  237. Connect.Background = Brushes.Transparent;
  238. isClientStocked = false;
  239. PorC.Content = "⏸";
  240. // 建立连接的同时加入人物
  241. }
  242. }
  243. // 绘制道具
  244. private void DrawProp(MessageOfProp data, string text)
  245. {
  246. TextBox icon = new()
  247. {
  248. FontSize = 10,
  249. Width = 20,
  250. Height = 20,
  251. Text = text,
  252. HorizontalAlignment = HorizontalAlignment.Left,
  253. VerticalAlignment = VerticalAlignment.Top,
  254. Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0),
  255. Background = Brushes.Transparent,
  256. BorderBrush = Brushes.Transparent,
  257. IsReadOnly = true
  258. };
  259. UpperLayerOfMap.Children.Add(icon);
  260. }
  261. private void ZoomMap()
  262. {
  263. for (int i = 0; i < 50; i++)
  264. {
  265. for (int j = 0; j < 50; j++)
  266. {
  267. if (mapPatches[i, j] != null)
  268. {
  269. mapPatches[i, j].Width = UpperLayerOfMap.ActualWidth / 50;
  270. mapPatches[i, j].Height = UpperLayerOfMap.ActualHeight / 50;
  271. mapPatches[i, j].HorizontalAlignment = HorizontalAlignment.Left;
  272. mapPatches[i, j].VerticalAlignment = VerticalAlignment.Top;
  273. mapPatches[i, j].Margin = new Thickness(UpperLayerOfMap.ActualWidth / 50 * j, UpperLayerOfMap.ActualHeight / 50 * i, 0, 0);
  274. }
  275. }
  276. }
  277. }
  278. private void DrawMap()
  279. {
  280. for (int i = 0; i < defaultMap.GetLength(0); i++)
  281. {
  282. for (int j = 0; j < defaultMap.GetLength(1); j++)
  283. {
  284. mapPatches[i, j] = new()
  285. {
  286. Width = unitWidth,
  287. Height = unitHeight,
  288. HorizontalAlignment = HorizontalAlignment.Left,
  289. VerticalAlignment = VerticalAlignment.Top,
  290. Margin = new Thickness(Width * (j), Height * (i), 0, 0)
  291. };
  292. // mapPatches[i, j].SetValue(Canvas.LeftProperty, (double)(Width / 65.5 * j));
  293. // mapPatches[i, j].SetValue(Canvas.TopProperty, (double)(Height / 56.5 * i)); // 用zoommap进行修改
  294. switch (defaultMap[i, j])
  295. {
  296. case 6:
  297. mapPatches[i, j].Fill = Brushes.Brown;
  298. mapPatches[i, j].Stroke = Brushes.Brown;
  299. break;//wall
  300. case 7:
  301. mapPatches[i, j].Fill = Brushes.Green;
  302. mapPatches[i, j].Stroke = Brushes.Green;
  303. break;//grass
  304. case 8:
  305. mapPatches[i, j].Fill = Brushes.LightPink;
  306. mapPatches[i, j].Stroke = Brushes.LightPink;
  307. break;//machine
  308. case 9:
  309. mapPatches[i, j].Fill = Brushes.LightSkyBlue;
  310. mapPatches[i, j].Stroke = Brushes.LightSkyBlue;
  311. break;//door
  312. case 10:
  313. foreach (var obj in listOfAll)
  314. {
  315. if(obj.HiddenGateRefreshed)
  316. {
  317. mapPatches[i, j].Fill = Brushes.LightSalmon;
  318. mapPatches[i, j].Stroke = Brushes.LightSalmon;
  319. }
  320. }
  321. break;//emergency
  322. case 11:
  323. mapPatches[i, j].Fill = Brushes.Gray;
  324. mapPatches[i, j].Stroke = Brushes.Gray;
  325. break;//window
  326. case 12:
  327. case 13:
  328. case 14:
  329. mapPatches[i, j].Fill = Brushes.Khaki;
  330. mapPatches[i, j].Stroke = Brushes.Khaki;
  331. break;//door
  332. case 15:
  333. mapPatches[i, j].Fill = Brushes.Orange;
  334. mapPatches[i, j].Stroke = Brushes.Orange;
  335. break;//chest
  336. default:
  337. break;
  338. }
  339. UnderLayerOfMap.Children.Add(mapPatches[i, j]);
  340. }
  341. }
  342. hasDrawed = true;
  343. }
  344. //三个参数分别为攻击者的位置,攻击方位角(窗口坐标)和攻击半径
  345. private void DrawLaser(Point source, double theta, double range, double Width) // 三个参数分别为攻击者的位置,攻击方位角(窗口坐标)和攻击半径
  346. {
  347. Point[] endPoint = new Point[4];
  348. Point target = new();
  349. target.X = source.X + range * Math.Cos(theta);
  350. target.Y = source.Y + range * Math.Sin(theta);
  351. endPoint[0].X = source.X + Width * Math.Cos(theta - Math.PI / 2);
  352. endPoint[0].Y = source.Y + Width * Math.Sin(theta - Math.PI / 2);
  353. endPoint[1].X = target.X + Width * Math.Cos(theta - Math.PI / 2);
  354. endPoint[1].Y = target.Y + Width * Math.Sin(theta - Math.PI / 2);
  355. endPoint[2].X = target.X + Width * Math.Cos(theta + Math.PI / 2);
  356. endPoint[2].Y = target.Y + Width * Math.Sin(theta + Math.PI / 2);
  357. endPoint[3].X = source.X + Width * Math.Cos(theta + Math.PI / 2);
  358. endPoint[3].Y = source.Y + Width * Math.Sin(theta + Math.PI / 2);
  359. Polygon laserIcon = new();
  360. laserIcon.Stroke = System.Windows.Media.Brushes.Red;
  361. laserIcon.Fill = System.Windows.Media.Brushes.Red;
  362. laserIcon.StrokeThickness = 2;
  363. laserIcon.HorizontalAlignment = HorizontalAlignment.Left;
  364. laserIcon.VerticalAlignment = VerticalAlignment.Top;
  365. PointCollection laserEndPoints = new();
  366. for (int i = 0; i < 4; i++)
  367. {
  368. laserEndPoints.Add(endPoint[i]);
  369. }
  370. laserIcon.Points = laserEndPoints;
  371. UpperLayerOfMap.Children.Add(laserIcon);
  372. }
  373. private async void OnReceive() // 已按照3.5版proto更新信息,但是左侧信息栏还未填充。log未更新,switch1,2,3更新log
  374. {
  375. try
  376. {
  377. while (responseStream != null && await responseStream.ResponseStream.MoveNext())
  378. {
  379. lock (drawPicLock) // 加锁是必要的,画图操作和接收信息操作不能同时进行,否则画图时foreach会有bug
  380. {
  381. listOfHuman.Clear();
  382. listOfButcher.Clear();
  383. listOfProp.Clear();
  384. listOfBombedBullet.Clear();
  385. listOfBullet.Clear();
  386. listOfAll.Clear();
  387. listOfChest.Clear();
  388. listOfClassroom.Clear();
  389. listOfDoor.Clear();
  390. listOfGate.Clear();
  391. MessageToClient content = responseStream.ResponseStream.Current;
  392. switch (content.GameState)
  393. {
  394. case GameState.GameStart:
  395. foreach (var obj in content.ObjMessage)
  396. {
  397. switch (obj.MessageOfObjCase)
  398. {
  399. case MessageOfObj.MessageOfObjOneofCase.StudentMessage:
  400. if (humanOrButcher && obj.StudentMessage.PlayerId == playerID)
  401. {
  402. human = obj.StudentMessage;
  403. }
  404. listOfHuman.Add(obj.StudentMessage);
  405. break;
  406. case MessageOfObj.MessageOfObjOneofCase.TrickerMessage:
  407. if (!humanOrButcher && obj.TrickerMessage.PlayerId == playerID)
  408. {
  409. butcher = obj.TrickerMessage;
  410. }
  411. listOfButcher.Add(obj.TrickerMessage);
  412. break;
  413. case MessageOfObj.MessageOfObjOneofCase.PropMessage:
  414. listOfProp.Add(obj.PropMessage);
  415. break;
  416. case MessageOfObj.MessageOfObjOneofCase.BombedBulletMessage:
  417. listOfBombedBullet.Add(obj.BombedBulletMessage);
  418. break;
  419. case MessageOfObj.MessageOfObjOneofCase.BulletMessage:
  420. listOfBullet.Add(obj.BulletMessage);
  421. break;
  422. case MessageOfObj.MessageOfObjOneofCase.ChestMessage:
  423. listOfChest.Add(obj.ChestMessage);
  424. break;
  425. case MessageOfObj.MessageOfObjOneofCase.ClassroomMessage:
  426. listOfClassroom.Add(obj.ClassroomMessage);
  427. break;
  428. case MessageOfObj.MessageOfObjOneofCase.DoorMessage:
  429. listOfDoor.Add(obj.DoorMessage);
  430. break;
  431. case MessageOfObj.MessageOfObjOneofCase.GateMessage:
  432. listOfGate.Add(obj.GateMessage);
  433. break;
  434. case MessageOfObj.MessageOfObjOneofCase.MapMessage:
  435. GetMap(obj.MapMessage);
  436. break;
  437. }
  438. }
  439. listOfAll.Add(content.AllMessage);
  440. break;
  441. case GameState.GameRunning:
  442. foreach (var obj in content.ObjMessage)
  443. {
  444. switch (obj.MessageOfObjCase)
  445. {
  446. case MessageOfObj.MessageOfObjOneofCase.StudentMessage:
  447. if (humanOrButcher && obj.StudentMessage.PlayerId == playerID)
  448. {
  449. human = obj.StudentMessage;
  450. }
  451. listOfHuman.Add(obj.StudentMessage);
  452. break;
  453. case MessageOfObj.MessageOfObjOneofCase.TrickerMessage:
  454. if (!humanOrButcher && obj.TrickerMessage.PlayerId == playerID)
  455. {
  456. butcher = obj.TrickerMessage;
  457. }
  458. listOfButcher.Add(obj.TrickerMessage);
  459. break;
  460. case MessageOfObj.MessageOfObjOneofCase.PropMessage:
  461. listOfProp.Add(obj.PropMessage);
  462. break;
  463. case MessageOfObj.MessageOfObjOneofCase.BombedBulletMessage:
  464. listOfBombedBullet.Add(obj.BombedBulletMessage);
  465. break;
  466. case MessageOfObj.MessageOfObjOneofCase.BulletMessage:
  467. listOfBullet.Add(obj.BulletMessage);
  468. break;
  469. case MessageOfObj.MessageOfObjOneofCase.ChestMessage:
  470. listOfChest.Add(obj.ChestMessage);
  471. break;
  472. case MessageOfObj.MessageOfObjOneofCase.ClassroomMessage:
  473. listOfClassroom.Add(obj.ClassroomMessage);
  474. break;
  475. case MessageOfObj.MessageOfObjOneofCase.DoorMessage:
  476. listOfDoor.Add(obj.DoorMessage);
  477. break;
  478. case MessageOfObj.MessageOfObjOneofCase.GateMessage:
  479. listOfGate.Add(obj.GateMessage);
  480. break;
  481. }
  482. }
  483. listOfAll.Add(content.AllMessage);
  484. break;
  485. case GameState.GameEnd:
  486. foreach (var obj in content.ObjMessage)
  487. {
  488. switch (obj.MessageOfObjCase)
  489. {
  490. case MessageOfObj.MessageOfObjOneofCase.StudentMessage:
  491. listOfHuman.Add(obj.StudentMessage);
  492. break;
  493. case MessageOfObj.MessageOfObjOneofCase.TrickerMessage:
  494. listOfButcher.Add(obj.TrickerMessage);
  495. break;
  496. case MessageOfObj.MessageOfObjOneofCase.PropMessage:
  497. listOfProp.Add(obj.PropMessage);
  498. break;
  499. case MessageOfObj.MessageOfObjOneofCase.BombedBulletMessage:
  500. listOfBombedBullet.Add(obj.BombedBulletMessage);
  501. break;
  502. case MessageOfObj.MessageOfObjOneofCase.BulletMessage:
  503. listOfBullet.Add(obj.BulletMessage);
  504. break;
  505. case MessageOfObj.MessageOfObjOneofCase.ChestMessage:
  506. listOfChest.Add(obj.ChestMessage);
  507. break;
  508. case MessageOfObj.MessageOfObjOneofCase.ClassroomMessage:
  509. listOfClassroom.Add(obj.ClassroomMessage);
  510. break;
  511. case MessageOfObj.MessageOfObjOneofCase.DoorMessage:
  512. listOfDoor.Add(obj.DoorMessage);
  513. break;
  514. case MessageOfObj.MessageOfObjOneofCase.GateMessage:
  515. listOfGate.Add(obj.GateMessage);
  516. break;
  517. }
  518. }
  519. listOfAll.Add(content.AllMessage);
  520. break;
  521. }
  522. }
  523. if (responseStream == null)
  524. {
  525. throw new Exception("Unconnected");
  526. }
  527. }
  528. }
  529. catch (Exception ex)
  530. {
  531. ErrorDisplayer error = new("Error: " + ex.ToString());
  532. error.Show();
  533. }
  534. }
  535. private int GetX(int x)
  536. {
  537. return x / 1000 + 1;
  538. }
  539. private int GetY(int y)
  540. {
  541. return y / 1000 + 1;
  542. }
  543. //待修改
  544. private bool CanSee(MessageOfStudent msg)
  545. {
  546. if (msg.PlayerState == PlayerState.Quit)
  547. return false;
  548. //if (playerID >= 2022 || teamID >= 2022)
  549. // return true;
  550. if (humanOrButcher && human != null)
  551. {
  552. if (human.Guid == msg.Guid) // 自己能看见自己
  553. return true;
  554. }
  555. if (msg.Place == PlaceType.Grass || msg.Place == PlaceType.Gate || msg.Place == PlaceType.HiddenGate)
  556. return false;
  557. if (msg.Place == PlaceType.Land || msg.Place == PlaceType.Classroom)
  558. return true;
  559. if (humanOrButcher && human != null)
  560. {
  561. if (msg.Place != human.Place)
  562. return false;
  563. }
  564. else if (!humanOrButcher && butcher != null)
  565. {
  566. if (msg.Place != butcher.Place)
  567. return false;
  568. }
  569. return true;
  570. }
  571. private bool CanSee(MessageOfTricker msg)
  572. {
  573. // if (playerID >= 2022 || teamID >= 2022)
  574. // return true;
  575. if (!humanOrButcher && butcher != null)
  576. {
  577. if (butcher.Guid == msg.Guid) // 自己能看见自己
  578. return true;
  579. }
  580. if (msg.Place == PlaceType.Grass || msg.Place == PlaceType.Gate || msg.Place == PlaceType.HiddenGate)
  581. return false;
  582. if (msg.Place == PlaceType.Land || msg.Place == PlaceType.Classroom)
  583. return true;
  584. if (humanOrButcher && human != null)
  585. {
  586. if (msg.Place != human.Place)
  587. return false;
  588. }
  589. else if (!humanOrButcher && butcher != null)
  590. {
  591. if (msg.Place != butcher.Place)
  592. return false;
  593. }
  594. return true;
  595. }
  596. private bool CanSee(MessageOfProp msg)
  597. {
  598. if (msg.Place == PlaceType.Land)
  599. return true;
  600. if (humanOrButcher && human != null)
  601. {
  602. if (msg.Place != human.Place)
  603. return false;
  604. }
  605. else if (!humanOrButcher && butcher != null)
  606. {
  607. if (msg.Place != butcher.Place)
  608. return false;
  609. }
  610. return true;
  611. }
  612. private bool CanSee(MessageOfBullet msg)
  613. {
  614. if (msg.Place == PlaceType.Land)
  615. return true;
  616. if (humanOrButcher && human != null)
  617. {
  618. if (msg.Place != human.Place)
  619. return false;
  620. }
  621. else if (!humanOrButcher && butcher != null)
  622. {
  623. if (msg.Place != butcher.Place)
  624. return false;
  625. }
  626. return true;
  627. }
  628. private void Refresh(object? sender, EventArgs e) // 已按照3.5版proto更新信息,circumstance栏未更新 log未更新
  629. {
  630. // Bonus();
  631. if (WindowState == WindowState.Maximized)
  632. MaxButton.Content = "❐";
  633. else
  634. MaxButton.Content = "🗖";
  635. if (StatusBarsOfSurvivor != null)
  636. for (int i = 4; i < 8; i++)
  637. {
  638. StatusBarsOfSurvivor[i - 4].SetFontSize(12 * UpperLayerOfMap.ActualHeight / 650);
  639. }
  640. if (StatusBarsOfHunter != null)
  641. StatusBarsOfHunter.SetFontSize(12 * UpperLayerOfMap.ActualHeight / 650);
  642. if (StatusBarsOfCircumstance != null)
  643. StatusBarsOfCircumstance.SetFontSize(12 * UpperLayerOfMap.ActualHeight / 650);
  644. // 完成窗口信息更新
  645. if (!isClientStocked)
  646. {
  647. unit = Math.Sqrt(UpperLayerOfMap.ActualHeight * UpperLayerOfMap.ActualWidth) / 50;
  648. unitHeight = UpperLayerOfMap.ActualHeight / 50;
  649. unitWidth = UpperLayerOfMap.ActualWidth / 50;
  650. try
  651. {
  652. // if (log != null)
  653. //{
  654. // string temp = "";
  655. // for (int i = 0; i < dataDict[GameObjType.Character].Count; i++)
  656. // {
  657. // temp += Convert.ToString(dataDict[GameObjType.Character][i].MessageOfCharacter.TeamID) + "\n";
  658. // }
  659. // log.Content = temp;
  660. // }
  661. UpperLayerOfMap.Children.Clear();
  662. // if ((communicator == null || !communicator.Client.IsConnected) && !isPlaybackMode)
  663. //{
  664. // UnderLayerOfMap.Children.Clear();
  665. // throw new Exception("Client is unconnected.");
  666. // }
  667. // else
  668. //{
  669. lock (drawPicLock) // 加锁是必要的,画图操作和接收信息操作不能同时进行
  670. {
  671. foreach (var data in listOfAll)
  672. {
  673. StatusBarsOfCircumstance.SetValue(data);
  674. }
  675. if (!hasDrawed && mapFlag)
  676. DrawMap();
  677. foreach (var data in listOfHuman)
  678. {
  679. StatusBarsOfSurvivor[data.PlayerId].SetValue(data);
  680. if (CanSee(data))
  681. {
  682. Ellipse icon = new()
  683. {
  684. Width = unitWidth,
  685. Height = unitHeight,
  686. HorizontalAlignment = HorizontalAlignment.Left,
  687. VerticalAlignment = VerticalAlignment.Top,
  688. Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0),
  689. Fill = Brushes.BlueViolet,
  690. };
  691. UpperLayerOfMap.Children.Add(icon);
  692. }
  693. }
  694. foreach (var data in listOfButcher)
  695. {
  696. StatusBarsOfHunter.SetValue(data);
  697. if (CanSee(data))
  698. {
  699. Ellipse icon = new()
  700. {
  701. Width = unitWidth,
  702. Height = unitHeight,
  703. HorizontalAlignment = HorizontalAlignment.Left,
  704. VerticalAlignment = VerticalAlignment.Top,
  705. Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0),
  706. Fill = Brushes.Chocolate,
  707. };
  708. UpperLayerOfMap.Children.Add(icon);
  709. }
  710. }
  711. foreach (var data in listOfProp)
  712. {
  713. if (CanSee(data))
  714. {
  715. switch (data.Type)
  716. {
  717. case PropType.Key3:
  718. DrawProp(data, "🔧");
  719. break;
  720. case PropType.Key5:
  721. DrawProp(data, "🛡");
  722. break;
  723. case PropType.Key6:
  724. DrawProp(data, "♥");
  725. break;
  726. case PropType.Ptype4:
  727. DrawProp(data, "⛸");
  728. break;
  729. default:
  730. DrawProp(data, "");
  731. break;
  732. }
  733. }
  734. }
  735. foreach (var data in listOfBullet)
  736. {
  737. if (CanSee(data))
  738. {
  739. Ellipse icon = new()
  740. {
  741. Width = 10,
  742. Height = 10,
  743. HorizontalAlignment = HorizontalAlignment.Left,
  744. VerticalAlignment = VerticalAlignment.Top,
  745. Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0),
  746. Fill = Brushes.Red
  747. };
  748. UpperLayerOfMap.Children.Add(icon);
  749. }
  750. }
  751. foreach (var data in listOfBombedBullet)
  752. {
  753. switch (data.Type)
  754. {
  755. case BulletType.FastBullet:
  756. {
  757. Ellipse icon = new();
  758. double bombRange = data.BombRange / 1000;
  759. icon.Width = bombRange * unitWidth;
  760. icon.Height = bombRange * unitHeight;
  761. icon.HorizontalAlignment = HorizontalAlignment.Left;
  762. icon.VerticalAlignment = VerticalAlignment.Top;
  763. icon.Margin = new Thickness(data.Y * unitWidth / 1000.0 - bombRange * unitWidth / 2, data.X * unitHeight / 1000.0 - bombRange * unitHeight / 2, 0, 0);
  764. icon.Fill = Brushes.Red;
  765. UpperLayerOfMap.Children.Add(icon);
  766. break;
  767. }
  768. case BulletType.AtomBomb:
  769. {
  770. Ellipse icon = new Ellipse();
  771. double bombRange = data.BombRange / 1000;
  772. icon.Width = bombRange * unitWidth;
  773. icon.Height = bombRange * unitHeight;
  774. icon.HorizontalAlignment = HorizontalAlignment.Left;
  775. icon.VerticalAlignment = VerticalAlignment.Top;
  776. icon.Margin = new Thickness(data.Y * unitWidth / 1000.0 - bombRange * unitWidth / 2, data.X * unitHeight / 1000.0 - bombRange * unitHeight / 2, 0, 0);
  777. icon.Fill = Brushes.Red;
  778. UpperLayerOfMap.Children.Add(icon);
  779. break;
  780. }
  781. case BulletType.OrdinaryBullet:
  782. {
  783. Ellipse icon = new Ellipse();
  784. double bombRange = data.BombRange / 1000;
  785. icon.Width = bombRange * unitWidth;
  786. icon.Height = bombRange * unitHeight;
  787. icon.HorizontalAlignment = HorizontalAlignment.Left;
  788. icon.VerticalAlignment = VerticalAlignment.Top;
  789. icon.Margin = new Thickness(data.Y * unitWidth / 1000.0 - bombRange * unitWidth / 2, data.X * unitHeight / 1000.0 - bombRange * unitHeight / 2, 0, 0);
  790. icon.Fill = Brushes.Red;
  791. UpperLayerOfMap.Children.Add(icon);
  792. break;
  793. }
  794. /*case BulletType.LineBullet:
  795. {
  796. double bombRange = data.BombRange / 1000;
  797. DrawLaser(new Point(data.Y * unitWidth / 1000.0, data.X * unitHeight / 1000.0), -data.FacingDirection + Math.PI / 2, bombRange * unitHeight, 0.5 * unitWidth);
  798. break;
  799. }*/
  800. default:
  801. break;
  802. }
  803. }
  804. foreach (var data in listOfClassroom)
  805. {
  806. TextBox icon = new()
  807. {
  808. FontSize = 10 * UpperLayerOfMap.ActualHeight / 650,
  809. Width = unitWidth,
  810. Height = unitHeight,
  811. Text = Convert.ToString(data.Progress),
  812. HorizontalAlignment = HorizontalAlignment.Left,
  813. VerticalAlignment = VerticalAlignment.Top,
  814. Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0),
  815. //Margin = new Thickness(25,25, 0, 0),
  816. Background = Brushes.Transparent,
  817. BorderBrush = Brushes.Transparent,
  818. IsReadOnly = true
  819. };
  820. UpperLayerOfMap.Children.Add(icon);
  821. }
  822. foreach(var data in listOfChest)
  823. {
  824. TextBox icon = new()
  825. {
  826. FontSize = 10 * UpperLayerOfMap.ActualHeight / 650,
  827. Width = unitWidth,
  828. Height = unitHeight,
  829. Text = Convert.ToString(data.Progress),
  830. HorizontalAlignment = HorizontalAlignment.Left,
  831. VerticalAlignment = VerticalAlignment.Top,
  832. Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0),
  833. //Margin = new Thickness(25,25, 0, 0),
  834. Background = Brushes.Transparent,
  835. BorderBrush = Brushes.Transparent,
  836. IsReadOnly = true
  837. };
  838. UpperLayerOfMap.Children.Add(icon);
  839. }
  840. foreach(var data in listOfGate)
  841. {
  842. TextBox icon = new()
  843. {
  844. FontSize = 10 * UpperLayerOfMap.ActualHeight / 650,
  845. Width = unitWidth,
  846. Height = unitHeight,
  847. Text = Convert.ToString(data.Progress),
  848. HorizontalAlignment = HorizontalAlignment.Left,
  849. VerticalAlignment = VerticalAlignment.Top,
  850. Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0),
  851. //Margin = new Thickness(25,25, 0, 0),
  852. Background = Brushes.Transparent,
  853. BorderBrush = Brushes.Transparent,
  854. IsReadOnly = true
  855. };
  856. UpperLayerOfMap.Children.Add(icon);
  857. }
  858. foreach(var data in listOfDoor)
  859. {
  860. TextBox icon = new()
  861. {
  862. FontSize = 10 * UpperLayerOfMap.ActualHeight / 650,
  863. Width = unitWidth,
  864. Height = unitHeight,
  865. HorizontalAlignment = HorizontalAlignment.Left,
  866. VerticalAlignment = VerticalAlignment.Top,
  867. Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0),
  868. //Margin = new Thickness(25,25, 0, 0),
  869. Background = Brushes.Transparent,
  870. BorderBrush = Brushes.Transparent,
  871. IsReadOnly = true
  872. };
  873. if (data.IsOpen)
  874. {
  875. icon.Text = Convert.ToString("开");
  876. }
  877. else
  878. {
  879. icon.Text = Convert.ToString("闭");
  880. }
  881. UpperLayerOfMap.Children.Add(icon);
  882. }
  883. //}
  884. ZoomMap();
  885. }
  886. }
  887. catch (Exception exc)
  888. {
  889. ErrorDisplayer error = new("Error: " + exc.ToString());
  890. error.Show();
  891. isClientStocked = true;
  892. PorC.Content = "▶";
  893. }
  894. }
  895. counter++;
  896. }
  897. // 键盘控制,未完善
  898. private void KeyBoardControl(object sender, KeyEventArgs e)
  899. {
  900. if (!isPlaybackMode)
  901. {
  902. if(Keyboard.Modifiers == ModifierKeys.Control)
  903. {
  904. switch (e.Key)
  905. {
  906. case Key.D0:
  907. PropMsg msgP0 = new()
  908. {
  909. PlayerId = playerID,
  910. PropType = PropType.Key3,
  911. };
  912. client.PickProp(msgP0);
  913. break;
  914. case Key.D1:
  915. PropMsg msgP1 = new()
  916. {
  917. PlayerId = playerID,
  918. PropType = PropType.Key5,
  919. };
  920. client.PickProp(msgP1);
  921. break;
  922. case Key.D2:
  923. PropMsg msgP2 = new()
  924. {
  925. PlayerId = playerID,
  926. PropType = PropType.Key6,
  927. };
  928. client.PickProp(msgP2);
  929. break;
  930. case Key.D3:
  931. PropMsg msgP3 = new()
  932. {
  933. PlayerId = playerID,
  934. PropType = PropType.Ptype4,
  935. };
  936. client.PickProp(msgP3);
  937. break;
  938. default:
  939. break;
  940. }
  941. }
  942. else if (Keyboard.Modifiers == ModifierKeys.Alt)
  943. {
  944. switch (e.Key)
  945. {
  946. case Key.D0:
  947. PropMsg msgP0 = new()
  948. {
  949. PlayerId = playerID,
  950. PropType = PropType.Key3,
  951. };
  952. client.UseProp(msgP0);
  953. break;
  954. case Key.D1:
  955. PropMsg msgP1 = new()
  956. {
  957. PlayerId = playerID,
  958. PropType = PropType.Key5,
  959. };
  960. client.UseProp(msgP1);
  961. break;
  962. case Key.D2:
  963. PropMsg msgP2 = new()
  964. {
  965. PlayerId = playerID,
  966. PropType = PropType.Key6,
  967. };
  968. client.UseProp(msgP2);
  969. break;
  970. case Key.D3:
  971. PropMsg msgP3 = new()
  972. {
  973. PlayerId = playerID,
  974. PropType = PropType.Ptype4,
  975. };
  976. client.UseProp(msgP3);
  977. break;
  978. default:
  979. break;
  980. }
  981. }
  982. else if(Keyboard.Modifiers == ModifierKeys.Shift)
  983. {
  984. switch (e.Key)
  985. {
  986. case Key.D0:
  987. PropMsg msgP0 = new()
  988. {
  989. PlayerId = playerID,
  990. PropType = PropType.Key3,
  991. };
  992. client.ThrowProp(msgP0);
  993. break;
  994. case Key.D1:
  995. PropMsg msgP1 = new()
  996. {
  997. PlayerId = playerID,
  998. PropType = PropType.Key5,
  999. };
  1000. client.ThrowProp(msgP1);
  1001. break;
  1002. case Key.D2:
  1003. PropMsg msgP2 = new()
  1004. {
  1005. PlayerId = playerID,
  1006. PropType = PropType.Key6,
  1007. };
  1008. client.ThrowProp(msgP2);
  1009. break;
  1010. case Key.D3:
  1011. PropMsg msgP3 = new()
  1012. {
  1013. PlayerId = playerID,
  1014. PropType = PropType.Ptype4,
  1015. };
  1016. client.ThrowProp(msgP3);
  1017. break;
  1018. default:
  1019. break;
  1020. }
  1021. }
  1022. else if (Keyboard.Modifiers == ModifierKeys.Windows)
  1023. {
  1024. switch (e.Key)
  1025. {
  1026. case Key.D0:
  1027. SkillMsg msgS0 = new()
  1028. {
  1029. PlayerId = playerID,
  1030. SkillId = 0,
  1031. };
  1032. client.UseSkill(msgS0);
  1033. break;
  1034. case Key.D1:
  1035. SkillMsg msgS1 = new()
  1036. {
  1037. PlayerId = playerID,
  1038. SkillId = 1,
  1039. };
  1040. client.UseSkill(msgS1);
  1041. break;
  1042. case Key.D2:
  1043. SkillMsg msgS2 = new()
  1044. {
  1045. PlayerId = playerID,
  1046. SkillId = 2,
  1047. };
  1048. client.UseSkill(msgS2);
  1049. break;
  1050. default:
  1051. break;
  1052. }
  1053. }
  1054. else
  1055. {
  1056. switch (e.Key)
  1057. {
  1058. case Key.W:
  1059. case Key.NumPad8:
  1060. MoveMsg msgW = new()
  1061. {
  1062. PlayerId = playerID,
  1063. TimeInMilliseconds = 50,
  1064. Angle = Math.PI
  1065. };
  1066. client.Move(msgW);
  1067. break;
  1068. case Key.S:
  1069. case Key.NumPad2:
  1070. MoveMsg msgS = new()
  1071. {
  1072. PlayerId = playerID,
  1073. TimeInMilliseconds = 50,
  1074. Angle = 0
  1075. };
  1076. client.Move(msgS);
  1077. break;
  1078. case Key.D:
  1079. case Key.NumPad6:
  1080. MoveMsg msgD = new()
  1081. {
  1082. PlayerId = playerID,
  1083. TimeInMilliseconds = 50,
  1084. Angle = Math.PI / 2
  1085. };
  1086. client.Move(msgD);
  1087. break;
  1088. case Key.A:
  1089. case Key.NumPad4:
  1090. MoveMsg msgA = new()
  1091. {
  1092. PlayerId = playerID,
  1093. TimeInMilliseconds = 50,
  1094. Angle = 3 * Math.PI / 2
  1095. };
  1096. client.Move(msgA);
  1097. break;
  1098. case Key.J:
  1099. AttackMsg msgJ = new()
  1100. {
  1101. PlayerId = playerID,
  1102. Angle = Math.PI
  1103. };
  1104. client.Attack(msgJ);
  1105. break;
  1106. case Key.K:
  1107. IDMsg msgK = new()
  1108. {
  1109. PlayerId = playerID,
  1110. };
  1111. client.StartLearning(msgK);
  1112. break;
  1113. case Key.R:
  1114. IDMsg msgR = new()
  1115. {
  1116. PlayerId = playerID,
  1117. };
  1118. client.StartRescueMate(msgR);
  1119. break;
  1120. case Key.T:
  1121. IDMsg msgT = new()
  1122. {
  1123. PlayerId = playerID,
  1124. };
  1125. client.StartTreatMate(msgT);
  1126. break;
  1127. case Key.G:
  1128. IDMsg msgG = new()
  1129. {
  1130. PlayerId = playerID,
  1131. };
  1132. client.Graduate(msgG);
  1133. break;
  1134. case Key.H:
  1135. IDMsg msgH = new()
  1136. {
  1137. PlayerId = playerID,
  1138. };
  1139. client.StartOpenGate(msgH);
  1140. break;
  1141. case Key.O:
  1142. IDMsg msgO = new()
  1143. {
  1144. PlayerId = playerID,
  1145. };
  1146. client.OpenDoor(msgO);
  1147. break;
  1148. case Key.P:
  1149. IDMsg msgP = new()
  1150. {
  1151. PlayerId = playerID,
  1152. };
  1153. client.CloseDoor(msgP);
  1154. break;
  1155. case Key.U:
  1156. IDMsg msgU = new()
  1157. {
  1158. PlayerId = playerID,
  1159. };
  1160. client.SkipWindow(msgU);
  1161. break;
  1162. case Key.I:
  1163. IDMsg msgI = new()
  1164. {
  1165. PlayerId = playerID,
  1166. };
  1167. client.StartOpenChest(msgI);
  1168. break;
  1169. case Key.E:
  1170. IDMsg msgE = new()
  1171. {
  1172. PlayerId = playerID,
  1173. };
  1174. client.EndAllAction(msgE);
  1175. break;
  1176. default:
  1177. break;
  1178. }
  1179. }
  1180. }
  1181. }
  1182. //鼠标双击
  1183. private void Attack(object sender, RoutedEventArgs e)
  1184. {
  1185. if (!isPlaybackMode)
  1186. {
  1187. if (humanOrButcher&&human != null)
  1188. {
  1189. AttackMsg msgJ = new()
  1190. {
  1191. PlayerId = playerID
  1192. };
  1193. double mouseY = Mouse.GetPosition(UpperLayerOfMap).X * 1000 / unitWidth;
  1194. double mouseX = Mouse.GetPosition(UpperLayerOfMap).Y * 1000 / unitHeight;
  1195. msgJ.Angle = Math.Atan2(mouseY - human.Y, mouseX - human.X);
  1196. client.Attack(msgJ);
  1197. }
  1198. if (!humanOrButcher && butcher != null)
  1199. {
  1200. AttackMsg msgJ = new()
  1201. {
  1202. PlayerId = playerID
  1203. };
  1204. double mouseY = Mouse.GetPosition(UpperLayerOfMap).X * 1000 / unitWidth;
  1205. double mouseX = Mouse.GetPosition(UpperLayerOfMap).Y * 1000 / unitHeight;
  1206. msgJ.Angle = Math.Atan2(mouseY - butcher.Y, mouseX - butcher.X);
  1207. client.Attack(msgJ);
  1208. }
  1209. }
  1210. }
  1211. // 之后需要修改,现在只具有修改按钮形状的功能,并不能实现暂停/继续
  1212. private void ClickToPauseOrContinue(object sender, RoutedEventArgs e)
  1213. {
  1214. if (!isClientStocked)
  1215. {
  1216. isClientStocked = true;
  1217. PorC.Content = "▶";
  1218. }
  1219. else
  1220. {
  1221. isClientStocked = false;
  1222. PorC.Content = "⏸";
  1223. }
  1224. }
  1225. // 未复现
  1226. private void ClickToConnect(object sender, RoutedEventArgs e)
  1227. {
  1228. }
  1229. // 窗口最大化、关闭、最小化、拖拽
  1230. private void ClickToMaxmize(object sender, RoutedEventArgs e)
  1231. {
  1232. if (WindowState != WindowState.Maximized)
  1233. WindowState = WindowState.Maximized;
  1234. else
  1235. WindowState = WindowState.Normal;
  1236. }
  1237. private void ClickToClose(object sender, RoutedEventArgs e)
  1238. {
  1239. Application.Current.Shutdown();
  1240. }
  1241. private void ClickToMinimize(object sender, RoutedEventArgs e)
  1242. {
  1243. WindowState = WindowState.Minimized;
  1244. }
  1245. private void DragWindow(object sender, RoutedEventArgs e)
  1246. {
  1247. DragMove();
  1248. }
  1249. // 寻求帮助、访问EESAST(部分功能未复原)
  1250. private void ClickForHelp(object sender, RoutedEventArgs e)
  1251. {
  1252. PleaseWait();
  1253. }
  1254. private void ClickToVisitEESAST(object sender, RoutedEventArgs e)
  1255. {
  1256. try
  1257. {
  1258. _ = Process.Start("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe", "https://eesast.com");
  1259. }
  1260. catch (Exception exc)
  1261. {
  1262. // ErrorDisplayer error = new("发生错误。以下是系统报告\n" + exc.ToString());
  1263. // error.Show();
  1264. }
  1265. }
  1266. // 配置连接(未复原)、我的AI(THUAI5未实现)、获取更新、天梯信息(可能需要网站协助)
  1267. private void ClickToSetConnect(object sender, RoutedEventArgs e)
  1268. {
  1269. // ConnectRegister crg = new();
  1270. // crg.Show();
  1271. }
  1272. private void ClickToEnterVS(object sender, RoutedEventArgs e)
  1273. {
  1274. // try
  1275. //{
  1276. // if (!File.Exists("VSRoute.txt"))
  1277. // {
  1278. // File.Create("VSRoute.txt");
  1279. // Exception ex = new("没有路径存储文件,已为您创建。请将VS路径输入该文件,并重新操作。");
  1280. // throw ex;
  1281. // }//创建路径文件
  1282. // using StreamReader sr = new("VSRoute.txt");
  1283. // _ = Process.Start(sr.ReadLine());
  1284. // }
  1285. // catch (Exception exc)
  1286. //{
  1287. // ErrorDisplayer error = new("发生错误。以下是系统报告:\n" + exc.ToString());
  1288. // error.Show();
  1289. // }
  1290. PleaseWait();
  1291. }
  1292. private void ClickForUpdate(object sender, RoutedEventArgs e)
  1293. {
  1294. PleaseWait();
  1295. }
  1296. private void ClickToCheckLadder(object sender, RoutedEventArgs e)
  1297. {
  1298. PleaseWait();
  1299. }
  1300. // 敬请期待函数
  1301. private void PleaseWait()
  1302. {
  1303. try
  1304. {
  1305. throw new Exception("敬请期待");
  1306. }
  1307. catch (Exception exc)
  1308. {
  1309. // ErrorDisplayer error = new(exc.Message);
  1310. // error.Show();
  1311. }
  1312. }
  1313. // 以下为Mainwindow自定义属性
  1314. private readonly DispatcherTimer timer; // 定时器
  1315. private long counter; // 预留的取时间变量
  1316. AvailableService.AvailableServiceClient client;
  1317. AsyncServerStreamingCall<MessageToClient>? responseStream;
  1318. private StatusBarOfSurvivor[] StatusBarsOfSurvivor;
  1319. private StatusBarOfHunter StatusBarsOfHunter;
  1320. private StatusBarOfCircumstance StatusBarsOfCircumstance;
  1321. private bool isClientStocked;
  1322. private bool isPlaybackMode;
  1323. private long playerID;
  1324. private PlayerType playerType;
  1325. private double unit;
  1326. private double unitHeight;
  1327. private double unitWidth;
  1328. private readonly Rectangle[,] mapPatches = new Rectangle[50, 50];
  1329. private List<MessageOfProp> listOfProp;
  1330. private List<MessageOfStudent> listOfHuman;
  1331. private List<MessageOfTricker> listOfButcher;
  1332. private List<MessageOfBullet> listOfBullet;
  1333. private List<MessageOfBombedBullet> listOfBombedBullet;
  1334. private List<MessageOfAll> listOfAll;
  1335. private List<MessageOfChest> listOfChest;
  1336. private List<MessageOfClassroom> listOfClassroom;
  1337. private List<MessageOfDoor> listOfDoor;
  1338. private List<MessageOfGate> listOfGate;
  1339. private object drawPicLock = new object();
  1340. private MessageOfStudent? human = null;
  1341. private MessageOfTricker? butcher = null;
  1342. private bool humanOrButcher;//true for human
  1343. private bool bonusflag;
  1344. private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