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