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 67 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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333
  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. string[] comInfo = new string[5];
  122. comInfo[0] = options.Ip;
  123. comInfo[1] = options.Port;
  124. comInfo[2] = options.PlayerID;
  125. comInfo[3] = options.PlayerType;
  126. comInfo[4] = options.Occupation;
  127. ConnectToServer(comInfo);
  128. OnReceive();
  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;//gate
  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.AddSpeed:
  727. DrawProp(data, "⛸");
  728. break;
  729. case PropType.AddHpOrAp:
  730. DrawProp(data, "♥");
  731. break;
  732. case PropType.AddLifeOrAp:
  733. DrawProp(data, "🏅");
  734. break;
  735. case PropType.ShieldOrSpear:
  736. DrawProp(data, "🛡");
  737. break;
  738. default:
  739. DrawProp(data, "");
  740. break;
  741. }
  742. }
  743. }
  744. foreach (var data in listOfBullet)
  745. {
  746. if (CanSee(data))
  747. {
  748. Ellipse icon = new()
  749. {
  750. Width = 10,
  751. Height = 10,
  752. HorizontalAlignment = HorizontalAlignment.Left,
  753. VerticalAlignment = VerticalAlignment.Top,
  754. Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0),
  755. Fill = Brushes.Red
  756. };
  757. UpperLayerOfMap.Children.Add(icon);
  758. }
  759. }
  760. foreach (var data in listOfBombedBullet)
  761. {
  762. switch (data.Type)
  763. {
  764. case BulletType.FastBullet:
  765. {
  766. Ellipse icon = new();
  767. double bombRange = data.BombRange / 1000;
  768. icon.Width = bombRange * unitWidth;
  769. icon.Height = bombRange * unitHeight;
  770. icon.HorizontalAlignment = HorizontalAlignment.Left;
  771. icon.VerticalAlignment = VerticalAlignment.Top;
  772. icon.Margin = new Thickness(data.Y * unitWidth / 1000.0 - bombRange * unitWidth / 2, data.X * unitHeight / 1000.0 - bombRange * unitHeight / 2, 0, 0);
  773. icon.Fill = Brushes.Red;
  774. UpperLayerOfMap.Children.Add(icon);
  775. break;
  776. }
  777. case BulletType.AtomBomb:
  778. {
  779. Ellipse icon = new Ellipse();
  780. double bombRange = data.BombRange / 1000;
  781. icon.Width = bombRange * unitWidth;
  782. icon.Height = bombRange * unitHeight;
  783. icon.HorizontalAlignment = HorizontalAlignment.Left;
  784. icon.VerticalAlignment = VerticalAlignment.Top;
  785. icon.Margin = new Thickness(data.Y * unitWidth / 1000.0 - bombRange * unitWidth / 2, data.X * unitHeight / 1000.0 - bombRange * unitHeight / 2, 0, 0);
  786. icon.Fill = Brushes.Red;
  787. UpperLayerOfMap.Children.Add(icon);
  788. break;
  789. }
  790. case BulletType.OrdinaryBullet:
  791. {
  792. Ellipse icon = new Ellipse();
  793. double bombRange = data.BombRange / 1000;
  794. icon.Width = bombRange * unitWidth;
  795. icon.Height = bombRange * unitHeight;
  796. icon.HorizontalAlignment = HorizontalAlignment.Left;
  797. icon.VerticalAlignment = VerticalAlignment.Top;
  798. icon.Margin = new Thickness(data.Y * unitWidth / 1000.0 - bombRange * unitWidth / 2, data.X * unitHeight / 1000.0 - bombRange * unitHeight / 2, 0, 0);
  799. icon.Fill = Brushes.Red;
  800. UpperLayerOfMap.Children.Add(icon);
  801. break;
  802. }
  803. /*case BulletType.LineBullet:
  804. {
  805. double bombRange = data.BombRange / 1000;
  806. DrawLaser(new Point(data.Y * unitWidth / 1000.0, data.X * unitHeight / 1000.0), -data.FacingDirection + Math.PI / 2, bombRange * unitHeight, 0.5 * unitWidth);
  807. break;
  808. }*/
  809. default:
  810. break;
  811. }
  812. }
  813. foreach (var data in listOfClassroom)
  814. {
  815. TextBox icon = new()
  816. {
  817. FontSize = 10 * UpperLayerOfMap.ActualHeight / 650,
  818. Width = unitWidth,
  819. Height = unitHeight,
  820. Text = Convert.ToString(data.Progress),
  821. HorizontalAlignment = HorizontalAlignment.Left,
  822. VerticalAlignment = VerticalAlignment.Top,
  823. Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0),
  824. //Margin = new Thickness(25,25, 0, 0),
  825. Background = Brushes.Transparent,
  826. BorderBrush = Brushes.Transparent,
  827. IsReadOnly = true
  828. };
  829. UpperLayerOfMap.Children.Add(icon);
  830. }
  831. foreach(var data in listOfChest)
  832. {
  833. TextBox icon = new()
  834. {
  835. FontSize = 10 * UpperLayerOfMap.ActualHeight / 650,
  836. Width = unitWidth,
  837. Height = unitHeight,
  838. Text = Convert.ToString(data.Progress),
  839. HorizontalAlignment = HorizontalAlignment.Left,
  840. VerticalAlignment = VerticalAlignment.Top,
  841. Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0),
  842. //Margin = new Thickness(25,25, 0, 0),
  843. Background = Brushes.Transparent,
  844. BorderBrush = Brushes.Transparent,
  845. IsReadOnly = true
  846. };
  847. UpperLayerOfMap.Children.Add(icon);
  848. }
  849. foreach(var data in listOfGate)
  850. {
  851. TextBox icon = new()
  852. {
  853. FontSize = 10 * UpperLayerOfMap.ActualHeight / 650,
  854. Width = unitWidth,
  855. Height = unitHeight,
  856. Text = Convert.ToString(data.Progress),
  857. HorizontalAlignment = HorizontalAlignment.Left,
  858. VerticalAlignment = VerticalAlignment.Top,
  859. Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0),
  860. //Margin = new Thickness(25,25, 0, 0),
  861. Background = Brushes.Transparent,
  862. BorderBrush = Brushes.Transparent,
  863. IsReadOnly = true
  864. };
  865. UpperLayerOfMap.Children.Add(icon);
  866. }
  867. foreach(var data in listOfDoor)
  868. {
  869. TextBox icon = new()
  870. {
  871. FontSize = 10 * UpperLayerOfMap.ActualHeight / 650,
  872. Width = unitWidth,
  873. Height = unitHeight,
  874. HorizontalAlignment = HorizontalAlignment.Left,
  875. VerticalAlignment = VerticalAlignment.Top,
  876. Margin = new Thickness(data.Y * unitWidth / 1000.0 - unitWidth / 2, data.X * unitHeight / 1000.0 - unitHeight / 2, 0, 0),
  877. //Margin = new Thickness(25,25, 0, 0),
  878. Background = Brushes.Transparent,
  879. BorderBrush = Brushes.Transparent,
  880. IsReadOnly = true
  881. };
  882. if (data.IsOpen)
  883. {
  884. icon.Text = Convert.ToString("开");
  885. }
  886. else
  887. {
  888. icon.Text = Convert.ToString("闭");
  889. }
  890. UpperLayerOfMap.Children.Add(icon);
  891. }
  892. //}
  893. ZoomMap();
  894. }
  895. }
  896. catch (Exception exc)
  897. {
  898. ErrorDisplayer error = new("Error: " + exc.ToString());
  899. error.Show();
  900. isClientStocked = true;
  901. PorC.Content = "▶";
  902. }
  903. }
  904. counter++;
  905. }
  906. // 键盘控制,未完善
  907. private void KeyBoardControl(object sender, KeyEventArgs e)
  908. {
  909. if (!isPlaybackMode)
  910. {
  911. switch (e.Key)
  912. {
  913. case Key.W:
  914. case Key.NumPad8:
  915. MoveMsg msgW = new()
  916. {
  917. PlayerId = playerID,
  918. TimeInMilliseconds = 50,
  919. Angle = Math.PI
  920. };
  921. client.Move(msgW);
  922. break;
  923. case Key.S:
  924. case Key.NumPad2:
  925. MoveMsg msgS = new()
  926. {
  927. PlayerId = playerID,
  928. TimeInMilliseconds = 50,
  929. Angle = 0
  930. };
  931. client.Move(msgS);
  932. break;
  933. case Key.D:
  934. case Key.NumPad6:
  935. MoveMsg msgD = new()
  936. {
  937. PlayerId = playerID,
  938. TimeInMilliseconds = 50,
  939. Angle = Math.PI / 2
  940. };
  941. client.Move(msgD);
  942. break;
  943. case Key.A:
  944. case Key.NumPad4:
  945. MoveMsg msgA = new()
  946. {
  947. PlayerId = playerID,
  948. TimeInMilliseconds = 50,
  949. Angle = 3 * Math.PI / 2
  950. };
  951. client.Move(msgA);
  952. break;
  953. case Key.J:
  954. AttackMsg msgJ = new()
  955. {
  956. PlayerId = playerID,
  957. Angle = Math.PI
  958. };
  959. client.Attack(msgJ);
  960. break;
  961. case Key.K:
  962. IDMsg msgK = new()
  963. {
  964. PlayerId = playerID,
  965. };
  966. client.StartLearning(msgK);
  967. break;
  968. case Key.R:
  969. TreatAndRescueMsg msgR = new()
  970. {
  971. PlayerId = playerID,
  972. };
  973. client.StartRescueMate(msgR);
  974. break;
  975. case Key.T:
  976. TreatAndRescueMsg msgT = new()
  977. {
  978. PlayerId = playerID,
  979. };
  980. client.StartTreatMate(msgT);
  981. break;
  982. case Key.G:
  983. IDMsg msgG = new()
  984. {
  985. PlayerId = playerID,
  986. };
  987. client.Graduate(msgG);
  988. break;
  989. case Key.H:
  990. IDMsg msgH = new()
  991. {
  992. PlayerId = playerID,
  993. };
  994. client.StartOpenGate(msgH);
  995. break;
  996. case Key.O:
  997. IDMsg msgO = new()
  998. {
  999. PlayerId = playerID,
  1000. };
  1001. client.OpenDoor(msgO);
  1002. break;
  1003. case Key.P:
  1004. IDMsg msgP = new()
  1005. {
  1006. PlayerId = playerID,
  1007. };
  1008. client.CloseDoor(msgP);
  1009. break;
  1010. case Key.U:
  1011. IDMsg msgU = new()
  1012. {
  1013. PlayerId = playerID,
  1014. };
  1015. client.SkipWindow(msgU);
  1016. break;
  1017. case Key.I:
  1018. IDMsg msgI = new()
  1019. {
  1020. PlayerId = playerID,
  1021. };
  1022. client.StartOpenChest(msgI);
  1023. break;
  1024. case Key.E:
  1025. IDMsg msgE = new()
  1026. {
  1027. PlayerId = playerID,
  1028. };
  1029. client.EndAllAction(msgE);
  1030. break;
  1031. case Key.F:
  1032. PropMsg msgF = new()
  1033. {
  1034. PlayerId = playerID,
  1035. PropType= PropType.NullPropType,
  1036. };
  1037. client.PickProp(msgF);
  1038. break;
  1039. case Key.C:
  1040. PropMsg msgC = new()
  1041. {
  1042. PlayerId = playerID,
  1043. PropType = PropType.NullPropType,
  1044. };
  1045. client.ThrowProp(msgC);
  1046. break;
  1047. case Key.V:
  1048. PropMsg msgV = new()
  1049. {
  1050. PlayerId = playerID,
  1051. PropType = PropType.NullPropType,
  1052. };
  1053. client.UseProp(msgV);
  1054. break;
  1055. case Key.B:
  1056. SkillMsg msgB = new()
  1057. {
  1058. PlayerId = playerID,
  1059. SkillId = 0,
  1060. };
  1061. client.UseSkill(msgB);
  1062. break;
  1063. case Key.N:
  1064. SkillMsg msgN = new()
  1065. {
  1066. PlayerId = playerID,
  1067. SkillId = 1,
  1068. };
  1069. client.UseSkill(msgN);
  1070. break;
  1071. case Key.M:
  1072. SkillMsg msgM = new()
  1073. {
  1074. PlayerId = playerID,
  1075. SkillId = 2,
  1076. };
  1077. client.UseSkill(msgM);
  1078. break;
  1079. default:
  1080. break;
  1081. }
  1082. }
  1083. }
  1084. //鼠标双击
  1085. private void Attack(object sender, RoutedEventArgs e)
  1086. {
  1087. if (!isPlaybackMode)
  1088. {
  1089. if (humanOrButcher&&human != null)
  1090. {
  1091. AttackMsg msgJ = new()
  1092. {
  1093. PlayerId = playerID
  1094. };
  1095. double mouseY = Mouse.GetPosition(UpperLayerOfMap).X * 1000 / unitWidth;
  1096. double mouseX = Mouse.GetPosition(UpperLayerOfMap).Y * 1000 / unitHeight;
  1097. msgJ.Angle = Math.Atan2(mouseY - human.Y, mouseX - human.X);
  1098. client.Attack(msgJ);
  1099. }
  1100. if (!humanOrButcher && butcher != null)
  1101. {
  1102. AttackMsg msgJ = new()
  1103. {
  1104. PlayerId = playerID
  1105. };
  1106. double mouseY = Mouse.GetPosition(UpperLayerOfMap).X * 1000 / unitWidth;
  1107. double mouseX = Mouse.GetPosition(UpperLayerOfMap).Y * 1000 / unitHeight;
  1108. msgJ.Angle = Math.Atan2(mouseY - butcher.Y, mouseX - butcher.X);
  1109. client.Attack(msgJ);
  1110. }
  1111. }
  1112. }
  1113. // 之后需要修改,现在只具有修改按钮形状的功能,并不能实现暂停/继续
  1114. private void ClickToPauseOrContinue(object sender, RoutedEventArgs e)
  1115. {
  1116. if (!isClientStocked)
  1117. {
  1118. isClientStocked = true;
  1119. PorC.Content = "▶";
  1120. }
  1121. else
  1122. {
  1123. isClientStocked = false;
  1124. PorC.Content = "⏸";
  1125. }
  1126. }
  1127. // 未复现
  1128. private void ClickToConnect(object sender, RoutedEventArgs e)
  1129. {
  1130. }
  1131. // 窗口最大化、关闭、最小化、拖拽
  1132. private void ClickToMaxmize(object sender, RoutedEventArgs e)
  1133. {
  1134. if (WindowState != WindowState.Maximized)
  1135. WindowState = WindowState.Maximized;
  1136. else
  1137. WindowState = WindowState.Normal;
  1138. }
  1139. private void ClickToClose(object sender, RoutedEventArgs e)
  1140. {
  1141. Application.Current.Shutdown();
  1142. }
  1143. private void ClickToMinimize(object sender, RoutedEventArgs e)
  1144. {
  1145. WindowState = WindowState.Minimized;
  1146. }
  1147. private void DragWindow(object sender, RoutedEventArgs e)
  1148. {
  1149. DragMove();
  1150. }
  1151. // 寻求帮助、访问EESAST(部分功能未复原)
  1152. private void ClickForHelp(object sender, RoutedEventArgs e)
  1153. {
  1154. PleaseWait();
  1155. }
  1156. private void ClickToVisitEESAST(object sender, RoutedEventArgs e)
  1157. {
  1158. try
  1159. {
  1160. _ = Process.Start("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe", "https://eesast.com");
  1161. }
  1162. catch (Exception exc)
  1163. {
  1164. // ErrorDisplayer error = new("发生错误。以下是系统报告\n" + exc.ToString());
  1165. // error.Show();
  1166. }
  1167. }
  1168. // 配置连接(未复原)、我的AI(THUAI5未实现)、获取更新、天梯信息(可能需要网站协助)
  1169. private void ClickToSetConnect(object sender, RoutedEventArgs e)
  1170. {
  1171. // ConnectRegister crg = new();
  1172. // crg.Show();
  1173. }
  1174. private void ClickToEnterVS(object sender, RoutedEventArgs e)
  1175. {
  1176. // try
  1177. //{
  1178. // if (!File.Exists("VSRoute.txt"))
  1179. // {
  1180. // File.Create("VSRoute.txt");
  1181. // Exception ex = new("没有路径存储文件,已为您创建。请将VS路径输入该文件,并重新操作。");
  1182. // throw ex;
  1183. // }//创建路径文件
  1184. // using StreamReader sr = new("VSRoute.txt");
  1185. // _ = Process.Start(sr.ReadLine());
  1186. // }
  1187. // catch (Exception exc)
  1188. //{
  1189. // ErrorDisplayer error = new("发生错误。以下是系统报告:\n" + exc.ToString());
  1190. // error.Show();
  1191. // }
  1192. PleaseWait();
  1193. }
  1194. private void ClickForUpdate(object sender, RoutedEventArgs e)
  1195. {
  1196. PleaseWait();
  1197. }
  1198. private void ClickToCheckLadder(object sender, RoutedEventArgs e)
  1199. {
  1200. PleaseWait();
  1201. }
  1202. // 敬请期待函数
  1203. private void PleaseWait()
  1204. {
  1205. try
  1206. {
  1207. throw new Exception("敬请期待");
  1208. }
  1209. catch (Exception exc)
  1210. {
  1211. // ErrorDisplayer error = new(exc.Message);
  1212. // error.Show();
  1213. }
  1214. }
  1215. // 以下为Mainwindow自定义属性
  1216. private readonly DispatcherTimer timer; // 定时器
  1217. private long counter; // 预留的取时间变量
  1218. AvailableService.AvailableServiceClient client;
  1219. AsyncServerStreamingCall<MessageToClient>? responseStream;
  1220. private StatusBarOfSurvivor[] StatusBarsOfSurvivor;
  1221. private StatusBarOfHunter StatusBarsOfHunter;
  1222. private StatusBarOfCircumstance StatusBarsOfCircumstance;
  1223. private bool isClientStocked;
  1224. private bool isPlaybackMode;
  1225. private long playerID;
  1226. private PlayerType playerType;
  1227. private double unit;
  1228. private double unitHeight;
  1229. private double unitWidth;
  1230. private readonly Rectangle[,] mapPatches = new Rectangle[50, 50];
  1231. private List<MessageOfProp> listOfProp;
  1232. private List<MessageOfStudent> listOfHuman;
  1233. private List<MessageOfTricker> listOfButcher;
  1234. private List<MessageOfBullet> listOfBullet;
  1235. private List<MessageOfBombedBullet> listOfBombedBullet;
  1236. private List<MessageOfAll> listOfAll;
  1237. private List<MessageOfChest> listOfChest;
  1238. private List<MessageOfClassroom> listOfClassroom;
  1239. private List<MessageOfDoor> listOfDoor;
  1240. private List<MessageOfGate> listOfGate;
  1241. private object drawPicLock = new object();
  1242. private MessageOfStudent? human = null;
  1243. private MessageOfTricker? butcher = null;
  1244. private bool humanOrButcher;//true for human
  1245. private bool bonusflag;
  1246. private bool mapFlag = false;
  1247. private bool hasDrawed = false;
  1248. public int[,] defaultMap = new int[,] {{ 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 },
  1249. { 6,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