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