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.

CopyInfo.cs 23 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. using Protobuf;
  2. using System.Collections.Generic;
  3. using GameClass.GameObj;
  4. using System.Numerics;
  5. using Preparation.Utility;
  6. namespace Server
  7. {
  8. public static class CopyInfo
  9. {
  10. private static Protobuf.PlaceType ToPlaceType(Preparation.Utility.PlaceType place)
  11. {
  12. switch (place)
  13. {
  14. case Preparation.Utility.PlaceType.Window:
  15. return Protobuf.PlaceType.Window;
  16. case Preparation.Utility.PlaceType.EmergencyExit:
  17. return Protobuf.PlaceType.HiddenGate;
  18. case Preparation.Utility.PlaceType.Doorway:
  19. return Protobuf.PlaceType.Gate;
  20. case Preparation.Utility.PlaceType.Chest:
  21. return Protobuf.PlaceType.Chest;
  22. case Preparation.Utility.PlaceType.Door:
  23. return Protobuf.PlaceType.Door;
  24. case Preparation.Utility.PlaceType.Generator:
  25. return Protobuf.PlaceType.Classroom;
  26. case Preparation.Utility.PlaceType.Grass:
  27. return Protobuf.PlaceType.Grass;
  28. case Preparation.Utility.PlaceType.Wall:
  29. return Protobuf.PlaceType.Wall;
  30. case Preparation.Utility.PlaceType.Null:
  31. case Preparation.Utility.PlaceType.BirthPoint1:
  32. case Preparation.Utility.PlaceType.BirthPoint2:
  33. case Preparation.Utility.PlaceType.BirthPoint3:
  34. case Preparation.Utility.PlaceType.BirthPoint4:
  35. case Preparation.Utility.PlaceType.BirthPoint5:
  36. return Protobuf.PlaceType.Land;
  37. default:
  38. return Protobuf.PlaceType.NullPlaceType;
  39. }
  40. }
  41. private static Protobuf.PropType ToPropType(Preparation.Utility.PropType prop)
  42. {
  43. switch (prop)
  44. {
  45. case Preparation.Utility.PropType.Key3:
  46. return Protobuf.PropType.Key3;
  47. case Preparation.Utility.PropType.Key5:
  48. return Protobuf.PropType.Key5;
  49. case Preparation.Utility.PropType.Key6:
  50. return Protobuf.PropType.Key6;
  51. default:
  52. return Protobuf.PropType.NullPropType;
  53. }
  54. }
  55. private static Protobuf.PlayerState ToPlayerState(Preparation.Utility.PlayerStateType playerState)
  56. {
  57. switch (playerState)
  58. {
  59. case Preparation.Utility.PlayerStateType.IsMoving:
  60. case Preparation.Utility.PlayerStateType.Null:
  61. return PlayerState.Idle;
  62. case Preparation.Utility.PlayerStateType.IsAddicted:
  63. return PlayerState.Addicted;
  64. case Preparation.Utility.PlayerStateType.IsClimbingThroughWindows:
  65. return PlayerState.Climbing;
  66. case Preparation.Utility.PlayerStateType.IsDeceased:
  67. return PlayerState.Quit;
  68. case Preparation.Utility.PlayerStateType.IsEscaped:
  69. return PlayerState.Graduated;
  70. case Preparation.Utility.PlayerStateType.IsFixing:
  71. return PlayerState.Learning;
  72. case Preparation.Utility.PlayerStateType.IsLockingTheDoor:
  73. return PlayerState.Locking;
  74. case Preparation.Utility.PlayerStateType.IsOpeningTheChest:
  75. return PlayerState.OpeningAChest;
  76. case Preparation.Utility.PlayerStateType.IsRescued:
  77. return PlayerState.Rescued;
  78. case Preparation.Utility.PlayerStateType.IsRescuing:
  79. return PlayerState.Rescuing;
  80. case Preparation.Utility.PlayerStateType.IsStunned:
  81. return PlayerState.Stunned;
  82. case Preparation.Utility.PlayerStateType.IsSwinging:
  83. return PlayerState.Swinging;
  84. case Preparation.Utility.PlayerStateType.IsTreated:
  85. return PlayerState.Treated;
  86. case Preparation.Utility.PlayerStateType.IsTreating:
  87. return PlayerState.Treating;
  88. case Preparation.Utility.PlayerStateType.IsTryingToAttack:
  89. return PlayerState.Attacking;
  90. case Preparation.Utility.PlayerStateType.IsUsingSpecialSkill:
  91. return PlayerState.UsingSpecialSkill;
  92. default:
  93. return PlayerState.NullStatus;
  94. }
  95. }
  96. private static Protobuf.StudentBuffType ToStudentBuffType(Preparation.Utility.BuffType buffType)
  97. {
  98. switch (buffType)
  99. {
  100. case Preparation.Utility.BuffType.Null:
  101. default:
  102. return Protobuf.StudentBuffType.NullSbuffType;
  103. }
  104. }
  105. private static Protobuf.BulletType ToBulletType(Preparation.Utility.BulletType bulletType)
  106. {
  107. switch (bulletType)
  108. {
  109. case Preparation.Utility.BulletType.FlyingKnife:
  110. return Protobuf.BulletType.FlyingKnife;
  111. case Preparation.Utility.BulletType.CommonAttackOfGhost:
  112. return Protobuf.BulletType.CommonAttackOfTricker;
  113. default:
  114. return Protobuf.BulletType.NullBulletType;
  115. }
  116. }
  117. private static Protobuf.StudentType ToStudentType(Preparation.Utility.CharacterType characterType)
  118. {
  119. switch (characterType)
  120. {
  121. case Preparation.Utility.CharacterType.Athlete:
  122. return Protobuf.StudentType.Athlete;
  123. default:
  124. return Protobuf.StudentType.NullStudentType;
  125. }
  126. }
  127. private static Protobuf.TrickerType ToTrickerType(Preparation.Utility.CharacterType characterType)
  128. {
  129. switch (characterType)
  130. {
  131. case Preparation.Utility.CharacterType.Assassin:
  132. return Protobuf.TrickerType.Assassin;
  133. default:
  134. return Protobuf.TrickerType.NullTrickerType;
  135. }
  136. }
  137. public static MessageOfObj? Auto(GameObj gameObj)
  138. {
  139. if (gameObj.Type == Preparation.Utility.GameObjType.Character)
  140. {
  141. Character character = (Character)gameObj;
  142. if (character.IsGhost())
  143. return Tricker((Ghost)character);
  144. else return Student((Student)character);
  145. }
  146. else if (gameObj.Type == Preparation.Utility.GameObjType.Bullet)
  147. return Bullet((Bullet)gameObj);
  148. else if (gameObj.Type == Preparation.Utility.GameObjType.Prop)
  149. return Prop((Prop)gameObj);
  150. else if (gameObj.Type == Preparation.Utility.GameObjType.BombedBullet)
  151. return BombedBullet((BombedBullet)gameObj);
  152. else if (gameObj.Type == Preparation.Utility.GameObjType.PickedProp)
  153. return PickedProp((PickedProp)gameObj);
  154. else return null; //先写着防报错
  155. }
  156. public static MessageOfObj? Auto(MessageOfNews news)
  157. {
  158. MessageOfObj objMsg = new();
  159. objMsg.NewsMessage = news;
  160. return objMsg;
  161. }
  162. private static MessageOfObj? Student(Student player)
  163. {
  164. MessageOfObj msg = new MessageOfObj();
  165. if (player.IsGhost()) return null;
  166. msg.StudentMessage = new();
  167. msg.StudentMessage.X = player.Position.x;
  168. msg.StudentMessage.Y = player.Position.y;
  169. msg.StudentMessage.Speed = player.MoveSpeed;
  170. msg.StudentMessage.Determination = player.HP;
  171. msg.StudentMessage.Addiction = player.GamingAddiction;
  172. foreach (var keyValue in player.TimeUntilActiveSkillAvailable)
  173. msg.StudentMessage.TimeUntilSkillAvailable.Add(keyValue.Value);
  174. foreach (var Value in player.PropInventory)
  175. msg.StudentMessage.Prop.Add(ToPropType(Value.GetPropType()));
  176. msg.StudentMessage.Place = ToPlaceType(player.Place);
  177. msg.StudentMessage.Guid = player.ID;
  178. msg.StudentMessage.PlayerState = ToPlayerState(player.PlayerState);
  179. msg.StudentMessage.PlayerId = player.PlayerID;
  180. msg.StudentMessage.ViewRange = player.ViewRange;
  181. msg.StudentMessage.Radius = player.Radius;
  182. msg.StudentMessage.DangerAlert = (player.BgmDictionary.ContainsKey(BgmType.GhostIsComing)) ? player.BgmDictionary[BgmType.GhostIsComing] : 0;
  183. msg.StudentMessage.Score = player.Score;
  184. msg.StudentMessage.TreatProgress = player.DegreeOfTreatment;
  185. msg.StudentMessage.RescueProgress = player.TimeOfRescue;
  186. foreach (KeyValuePair<Preparation.Utility.BuffType, bool> kvp in player.Buff)
  187. {
  188. if (kvp.Value)
  189. msg.StudentMessage.Buff.Add(ToStudentBuffType(kvp.Key));
  190. }
  191. msg.StudentMessage.BulletType = ToBulletType(player.BulletOfPlayer);
  192. msg.StudentMessage.LearningSpeed = player.FixSpeed;
  193. msg.StudentMessage.TreatSpeed = player.TreatSpeed;
  194. msg.StudentMessage.FacingDirection = player.FacingDirection.Angle();
  195. msg.StudentMessage.StudentType = ToStudentType(player.CharacterType);
  196. return msg;
  197. }
  198. private static MessageOfObj? Tricker(Character player)
  199. {
  200. MessageOfObj msg = new MessageOfObj();
  201. if (!player.IsGhost()) return null;
  202. msg.TrickerMessage = new();
  203. msg.TrickerMessage.X = player.Position.x;
  204. msg.TrickerMessage.Y = player.Position.y;
  205. msg.TrickerMessage.Speed = player.MoveSpeed;
  206. foreach (var keyValue in player.TimeUntilActiveSkillAvailable)
  207. msg.TrickerMessage.TimeUntilSkillAvailable.Add(keyValue.Value);
  208. msg.TrickerMessage.Place = ToPlaceType(player.Place);
  209. foreach (var Value in player.PropInventory)
  210. msg.StudentMessage.Prop.Add(ToPropType(Value.GetPropType()));
  211. msg.TrickerMessage.TrickerType = ToTrickerType(player.CharacterType); // 下面写
  212. msg.TrickerMessage.Guid = player.ID;
  213. msg.TrickerMessage.Score = player.Score;
  214. msg.TrickerMessage.PlayerId = player.PlayerID;
  215. msg.TrickerMessage.ViewRange = player.ViewRange;
  216. msg.TrickerMessage.Radius = player.Radius;
  217. //msg.TrickerMessage.Buff[0] = ButcherBuffType.NullSbuffType; 下面写了
  218. foreach (KeyValuePair<Preparation.Utility.BuffType, bool> kvp in player.Buff)
  219. {
  220. if (kvp.Value)
  221. {
  222. switch (kvp.Key) // ButcherBuffType具体内容待定
  223. {
  224. case Preparation.Utility.BuffType.Spear:
  225. msg.TrickerMessage.Buff.Add(TrickerBuffType.NullTbuffType);
  226. break;
  227. case Preparation.Utility.BuffType.AddLIFE:
  228. msg.TrickerMessage.Buff.Add(TrickerBuffType.NullTbuffType);
  229. break;
  230. case Preparation.Utility.BuffType.Shield:
  231. msg.TrickerMessage.Buff.Add(TrickerBuffType.NullTbuffType);
  232. break;
  233. case Preparation.Utility.BuffType.AddSpeed:
  234. msg.TrickerMessage.Buff.Add(TrickerBuffType.NullTbuffType);
  235. break;
  236. default:
  237. break;
  238. }
  239. }
  240. }
  241. /*switch (player.Place)
  242. {
  243. case Preparation.Utility.PlaceType.Land:
  244. msg.TrickerMessage.Place = PlaceType.Land;
  245. break;
  246. case Preparation.Utility.PlaceType.Grass1:
  247. msg.TrickerMessage.Place = PlaceType.Grass;
  248. break;
  249. case Preparation.Utility.PlaceType.Grass2:
  250. msg.TrickerMessage.Place = PlaceType.Grass;
  251. break;
  252. case Preparation.Utility.PlaceType.Grass3:
  253. msg.TrickerMessage.Place = PlaceType.Grass;
  254. break;
  255. // case Preparation.Utility.PlaceType.Invisible:
  256. // msg.TrickerMessage.MessageOfHuman.Place = Communication.Proto.PlaceType.Invisible;
  257. // break;
  258. default:
  259. msg.TrickerMessage.Place = PlaceType.NullPlaceType;
  260. break;
  261. }*/
  262. //Character的储存方式可能得改,用enum type存道具和子弹,不应该用对象
  263. //现在懒得改了,有时间再重整一波
  264. /*if (player.PropInventory == null)
  265. msg.TrickerMessage.Prop = PropType.NullPropType;
  266. else
  267. {
  268. switch (player.PropInventory.GetPropType())
  269. {
  270. case Preparation.Utility.PropType.Gem:
  271. msg.TrickerMessage.Prop = PropType.NullPropType;
  272. break;
  273. case Preparation.Utility.PropType.addLIFE:
  274. msg.TrickerMessage.MessageOfHuman.Prop = Communication.Proto.PropType.AddLife;
  275. break;
  276. case Preparation.Utility.PropType.addSpeed:
  277. msg.TrickerMessage.MessageOfHuman.Prop = Communication.Proto.PropType.AddSpeed;
  278. break;
  279. case Preparation.Utility.PropType.Shield:
  280. msg.TrickerMessage.MessageOfHuman.Prop = Communication.Proto.PropType.Shield;
  281. break;
  282. case Preparation.Utility.PropType.Spear:
  283. msg.TrickerMessage.MessageOfHuman.Prop = Communication.Proto.PropType.Spear;
  284. break;
  285. default:
  286. msg.TrickerMessage.Prop = PropType.NullPropType;
  287. break;
  288. }
  289. }*/
  290. return msg;
  291. }
  292. private static MessageOfObj Bullet(Bullet bullet)
  293. {
  294. MessageOfObj msg = new MessageOfObj();
  295. msg.BulletMessage = new();
  296. msg.BulletMessage.X = bullet.Position.x;
  297. msg.BulletMessage.Y = bullet.Position.y;
  298. //msg.BulletMessage.FacingDirection = bullet.FacingDirection; // XY转double?
  299. msg.BulletMessage.Guid = bullet.ID;
  300. msg.BulletMessage.Team = PlayerType.NullPlayerType;
  301. msg.BulletMessage.Place = PlaceType.NullPlaceType;
  302. msg.BulletMessage.BombRange = 0;
  303. switch (bullet.TypeOfBullet)
  304. {
  305. case Preparation.Utility.BulletType.AtomBomb:
  306. msg.BulletMessage.Type = BulletType.AtomBomb;
  307. break;
  308. case Preparation.Utility.BulletType.OrdinaryBullet:
  309. msg.BulletMessage.Type = BulletType.OrdinaryBullet;
  310. break;
  311. case Preparation.Utility.BulletType.FastBullet:
  312. msg.BulletMessage.Type = BulletType.FastBullet;
  313. break;
  314. case Preparation.Utility.BulletType.LineBullet:
  315. msg.BulletMessage.Type = BulletType.LineBullet;
  316. break;
  317. default:
  318. msg.BulletMessage.Type = BulletType.NullBulletType;
  319. break;
  320. }
  321. //if (bullet.Parent != null)
  322. //msg.BulletMessage.MessageOfBullet.ParentTeamID = bullet.Parent.TeamID;
  323. /*switch (bullet.Place)
  324. {
  325. case Preparation.Utility.PlaceType.Null:
  326. msg.BulletMessage.MessageOfBullet.Place = Communication.Proto.PlaceType.Null;
  327. break;
  328. case Preparation.Utility.PlaceType.Grass:
  329. msg.BulletMessage.MessageOfBullet.Place = Communication.Proto.PlaceType.Grass;
  330. break;
  331. case Preparation.Utility.PlaceType.Grass:
  332. msg.BulletMessage.MessageOfBullet.Place = Communication.Proto.PlaceType.Grass;
  333. break;
  334. case Preparation.Utility.PlaceType.Grass:
  335. msg.BulletMessage.MessageOfBullet.Place = Communication.Proto.PlaceType.Grass;
  336. break;
  337. default:
  338. msg.BulletMessage.MessageOfBullet.Place = Communication.Proto.PlacccceType.NullPlaceType;
  339. break;
  340. }*/
  341. return msg;
  342. }
  343. private static MessageOfObj Prop(Prop prop)
  344. {
  345. MessageOfObj msg = new MessageOfObj();
  346. msg.PropMessage = new();
  347. //msg.PropMessage.Type = PropType.NullPropType; 下面写
  348. msg.PropMessage.X = prop.Position.x;
  349. msg.PropMessage.Y = prop.Position.y;
  350. msg.PropMessage.FacingDirection = 0;
  351. msg.PropMessage.Guid = 0;
  352. msg.PropMessage.Place = PlaceType.NullPlaceType;
  353. msg.PropMessage.Size = 0;
  354. msg.PropMessage.IsMoving = false;
  355. switch (prop.GetPropType())
  356. {
  357. /*case Preparation.Utility.PropType.Gem:
  358. msg.PropMessage.Type = PropType.Gem;
  359. break;
  360. case Preparation.Utility.PropType.addLIFE:
  361. msg.PropMessage.Type = PropType.AddLife;
  362. break;
  363. case Preparation.Utility.PropType.addSpeed:
  364. msg.PropMessage.Type = PropType.AddSpeed;
  365. break;
  366. case Preparation.Utility.PropType.Shield:
  367. msg.PropMessage.Type = PropType.Shield;
  368. break;
  369. case Preparation.Utility.PropType.Spear:
  370. msg.PropMessage.Type = PropType.Spear;
  371. break;*/
  372. default:
  373. msg.PropMessage.Type = PropType.NullPropType;
  374. break;
  375. }
  376. /*if(prop is Gem)
  377. {
  378. msg.PropMessage.MessageOfProp.Size = ((Gem)prop).Size;
  379. }
  380. else
  381. {
  382. msg.PropMessage.MessageOfProp.Size = 1;
  383. }
  384. switch (prop.Place)
  385. {
  386. case Preparation.Utility.PlaceType.Null:
  387. msg.PropMessage.MessageOfProp.Place = Communication.Proto.PlaceType.Null;
  388. break;
  389. case Preparation.Utility.PlaceType.Grass:
  390. msg.PropMessage.MessageOfProp.Place = Communication.Proto.PlaceType.Grass;
  391. break;
  392. case Preparation.Utility.PlaceType.Grass:
  393. msg.PropMessage.MessageOfProp.Place = Communication.Proto.PlaceType.Grass;
  394. break;
  395. case Preparation.Utility.PlaceType.Grass:
  396. msg.PropMessage.MessageOfProp.Place = Communication.Proto.PlaceType.Grass;
  397. break;
  398. default:
  399. msg.PropMessage.MessageOfProp.Place = Communication.Proto.PlacccceType.NullPlaceType;
  400. break;
  401. }*/
  402. return msg;
  403. }
  404. private static MessageOfObj BombedBullet(BombedBullet bombedBullet)
  405. {
  406. MessageOfObj msg = new MessageOfObj();
  407. msg.BombedBulletMessage = new();
  408. msg.BombedBulletMessage.X = bombedBullet.bulletHasBombed.Position.x;
  409. msg.BombedBulletMessage.Y = bombedBullet.bulletHasBombed.Position.y;
  410. //msg.BombedBulletMessage.FacingDirection = bombedBullet.FacingDirection; XY类型转double?
  411. msg.BombedBulletMessage.MappingId = bombedBullet.MappingID;
  412. msg.BombedBulletMessage.BombRange = BulletFactory.BulletRadius(bombedBullet.bulletHasBombed.TypeOfBullet); // 待确认
  413. switch (bombedBullet.bulletHasBombed.TypeOfBullet)
  414. {
  415. case Preparation.Utility.BulletType.OrdinaryBullet:
  416. msg.BombedBulletMessage.Type = BulletType.OrdinaryBullet;
  417. break;
  418. case Preparation.Utility.BulletType.AtomBomb:
  419. msg.BombedBulletMessage.Type = BulletType.AtomBomb;
  420. break;
  421. case Preparation.Utility.BulletType.FastBullet:
  422. msg.BombedBulletMessage.Type = BulletType.FastBullet;
  423. break;
  424. case Preparation.Utility.BulletType.LineBullet:
  425. msg.BombedBulletMessage.Type = BulletType.LineBullet;
  426. break;
  427. default:
  428. msg.BombedBulletMessage.Type = BulletType.NullBulletType;
  429. break;
  430. }
  431. return msg;
  432. }
  433. private static MessageOfObj PickedProp(PickedProp pickedProp)
  434. {
  435. MessageOfObj msg = new MessageOfObj(); // MessageOfObj中没有PickedProp
  436. /*msg.MessageOfPickedProp = new MessageOfPickedProp();
  437. msg.MessageOfPickedProp.MappingID = pickedProp.MappingID;
  438. msg.MessageOfPickedProp.X = pickedProp.PropHasPicked.Position.x;
  439. msg.MessageOfPickedProp.Y = pickedProp.PropHasPicked.Position.y;
  440. msg.MessageOfPickedProp.FacingDirection = pickedProp.PropHasPicked.FacingDirection;
  441. switch (pickedProp.PropHasPicked.GetPropType())
  442. {
  443. case Preparation.Utility.PropType.Gem:
  444. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.Gem;
  445. break;
  446. case Preparation.Utility.PropType.addLIFE:
  447. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.AddLife;
  448. break;
  449. case Preparation.Utility.PropType.addSpeed:
  450. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.AddSpeed;
  451. break;
  452. case Preparation.Utility.PropType.Shield:
  453. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.Shield;
  454. break;
  455. case Preparation.Utility.PropType.Spear:
  456. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.Spear;
  457. break;
  458. default:
  459. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.NullPropType;
  460. break;
  461. }*/
  462. return msg;
  463. }
  464. }
  465. }