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