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 22 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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.CommonAttackOfGhost;
  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. public static MessageOfObj? Auto(GameObj gameObj)
  128. {
  129. if (gameObj.Type == Preparation.Utility.GameObjType.Character)
  130. {
  131. Character character = (Character)gameObj;
  132. if (character.IsGhost())
  133. return Tricker((Ghost)character);
  134. else return Student((Student)character);
  135. }
  136. else if (gameObj.Type == Preparation.Utility.GameObjType.Bullet)
  137. return Bullet((Bullet)gameObj);
  138. else if (gameObj.Type == Preparation.Utility.GameObjType.Prop)
  139. return Prop((Prop)gameObj);
  140. else if (gameObj.Type == Preparation.Utility.GameObjType.BombedBullet)
  141. return BombedBullet((BombedBullet)gameObj);
  142. else if (gameObj.Type == Preparation.Utility.GameObjType.PickedProp)
  143. return PickedProp((PickedProp)gameObj);
  144. else return null; //先写着防报错
  145. }
  146. private static MessageOfObj? Student(Student player)
  147. {
  148. MessageOfObj msg = new MessageOfObj();
  149. if (player.IsGhost()) return null;
  150. msg.StudentMessage = new();
  151. msg.StudentMessage.X = player.Position.x;
  152. msg.StudentMessage.Y = player.Position.y;
  153. msg.StudentMessage.Speed = player.MoveSpeed;
  154. msg.StudentMessage.Determination = player.HP;
  155. msg.StudentMessage.Addiction = player.GamingAddiction;
  156. foreach (var keyValue in player.TimeUntilActiveSkillAvailable)
  157. msg.StudentMessage.TimeUntilSkillAvailable.Add(keyValue.Value);
  158. foreach (var Value in player.PropInventory)
  159. msg.StudentMessage.Prop.Add(ToPropType(Value.GetPropType()));
  160. msg.StudentMessage.Place = ToPlaceType(player.Place);
  161. //msg.StudentMessage.StudentType; // 下面写
  162. msg.StudentMessage.Guid = player.ID;
  163. msg.StudentMessage.State = ToPlayerState(player.PlayerState);
  164. msg.StudentMessage.PlayerId = player.PlayerID;
  165. msg.StudentMessage.ViewRange = player.ViewRange;
  166. msg.StudentMessage.Radius = player.Radius;
  167. msg.StudentMessage.DangerAlert = (player.BgmDictionary.ContainsKey(BgmType.GhostIsComing)) ? player.BgmDictionary[BgmType.GhostIsComing] : 0;
  168. msg.StudentMessage.Score = player.Score;
  169. msg.StudentMessage.TreatProgress = player.DegreeOfTreatment;
  170. msg.StudentMessage.RescueProgress = player.TimeOfRescue;
  171. foreach (KeyValuePair<Preparation.Utility.BuffType, bool> kvp in player.Buff)
  172. {
  173. if (kvp.Value)
  174. msg.StudentMessage.Buff.Add(ToStudentBuffType(kvp.Key));
  175. }
  176. msg.StudentMessage.BulletType = ToBulletType(player.BulletOfPlayer);
  177. msg.StudentMessage.LearningSpeed = player.FixSpeed;
  178. msg.StudentMessage.TreatSpeed = player.TreatSpeed;
  179. msg.StudentMessage.FacingDirection = player.FacingDirection.Angle();
  180. msg.StudentMessage.StudentType = ToStudentType(player.CharacterType);
  181. return msg;
  182. }
  183. private static MessageOfObj? Tricker(Character player)
  184. {
  185. MessageOfObj msg = new MessageOfObj();
  186. if (!player.IsGhost()) return null;
  187. msg.TrickerMessage = new();
  188. msg.TrickerMessage.X = player.Position.x;
  189. msg.TrickerMessage.Y = player.Position.y;
  190. msg.TrickerMessage.Speed = player.MoveSpeed;
  191. msg.TrickerMessage.Damage = 0;
  192. foreach (var keyValue in player.TimeUntilActiveSkillAvailable)
  193. msg.StudentMessage.TimeUntilSkillAvailable.Add(keyValue.Value);
  194. //msg.TrickerMessage.Place = 0; 下面写了
  195. //msg.TrickerMessage.Prop = PropType.NullPropType; // 下面写
  196. msg.TrickerMessage.TrickerType = TrickerType.NullTrickerType; // 下面写
  197. msg.TrickerMessage.Guid = 0;
  198. msg.TrickerMessage.Movable = false;
  199. msg.TrickerMessage.PlayerId = 0;
  200. msg.TrickerMessage.ViewRange = 0;
  201. msg.TrickerMessage.Radius = 0;
  202. //msg.TrickerMessage.Buff[0] = ButcherBuffType.NullSbuffType; 下面写了
  203. foreach (KeyValuePair<Preparation.Utility.BuffType, bool> kvp in player.Buff)
  204. {
  205. if (kvp.Value)
  206. {
  207. switch (kvp.Key) // ButcherBuffType具体内容待定
  208. {
  209. case Preparation.Utility.BuffType.Spear:
  210. msg.TrickerMessage.Buff.Add(TrickerBuffType.NullTbuffType);
  211. break;
  212. case Preparation.Utility.BuffType.AddLIFE:
  213. msg.TrickerMessage.Buff.Add(TrickerBuffType.NullTbuffType);
  214. break;
  215. case Preparation.Utility.BuffType.Shield:
  216. msg.TrickerMessage.Buff.Add(TrickerBuffType.NullTbuffType);
  217. break;
  218. case Preparation.Utility.BuffType.AddSpeed:
  219. msg.TrickerMessage.Buff.Add(TrickerBuffType.NullTbuffType);
  220. break;
  221. default:
  222. break;
  223. }
  224. }
  225. }
  226. /*switch (player.Place)
  227. {
  228. case Preparation.Utility.PlaceType.Land:
  229. msg.TrickerMessage.Place = PlaceType.Land;
  230. break;
  231. case Preparation.Utility.PlaceType.Grass1:
  232. msg.TrickerMessage.Place = PlaceType.Grass;
  233. break;
  234. case Preparation.Utility.PlaceType.Grass2:
  235. msg.TrickerMessage.Place = PlaceType.Grass;
  236. break;
  237. case Preparation.Utility.PlaceType.Grass3:
  238. msg.TrickerMessage.Place = PlaceType.Grass;
  239. break;
  240. // case Preparation.Utility.PlaceType.Invisible:
  241. // msg.TrickerMessage.MessageOfHuman.Place = Communication.Proto.PlaceType.Invisible;
  242. // break;
  243. default:
  244. msg.TrickerMessage.Place = PlaceType.NullPlaceType;
  245. break;
  246. }*/
  247. //Character的储存方式可能得改,用enum type存道具和子弹,不应该用对象
  248. //现在懒得改了,有时间再重整一波
  249. /*if (player.PropInventory == null)
  250. msg.TrickerMessage.Prop = PropType.NullPropType;
  251. else
  252. {
  253. switch (player.PropInventory.GetPropType())
  254. {
  255. case Preparation.Utility.PropType.Gem:
  256. msg.TrickerMessage.Prop = PropType.NullPropType;
  257. break;
  258. case Preparation.Utility.PropType.addLIFE:
  259. msg.TrickerMessage.MessageOfHuman.Prop = Communication.Proto.PropType.AddLife;
  260. break;
  261. case Preparation.Utility.PropType.addSpeed:
  262. msg.TrickerMessage.MessageOfHuman.Prop = Communication.Proto.PropType.AddSpeed;
  263. break;
  264. case Preparation.Utility.PropType.Shield:
  265. msg.TrickerMessage.MessageOfHuman.Prop = Communication.Proto.PropType.Shield;
  266. break;
  267. case Preparation.Utility.PropType.Spear:
  268. msg.TrickerMessage.MessageOfHuman.Prop = Communication.Proto.PropType.Spear;
  269. break;
  270. default:
  271. msg.TrickerMessage.Prop = PropType.NullPropType;
  272. break;
  273. }
  274. }*/
  275. return msg;
  276. }
  277. private static MessageOfObj Bullet(Bullet bullet)
  278. {
  279. MessageOfObj msg = new MessageOfObj();
  280. msg.BulletMessage = new();
  281. msg.BulletMessage.X = bullet.Position.x;
  282. msg.BulletMessage.Y = bullet.Position.y;
  283. //msg.BulletMessage.FacingDirection = bullet.FacingDirection; // XY转double?
  284. msg.BulletMessage.Guid = bullet.ID;
  285. msg.BulletMessage.Team = PlayerType.NullPlayerType;
  286. msg.BulletMessage.Place = PlaceType.NullPlaceType;
  287. msg.BulletMessage.BombRange = 0;
  288. switch (bullet.TypeOfBullet)
  289. {
  290. case Preparation.Utility.BulletType.AtomBomb:
  291. msg.BulletMessage.Type = BulletType.AtomBomb;
  292. break;
  293. case Preparation.Utility.BulletType.OrdinaryBullet:
  294. msg.BulletMessage.Type = BulletType.OrdinaryBullet;
  295. break;
  296. case Preparation.Utility.BulletType.FastBullet:
  297. msg.BulletMessage.Type = BulletType.FastBullet;
  298. break;
  299. case Preparation.Utility.BulletType.LineBullet:
  300. msg.BulletMessage.Type = BulletType.LineBullet;
  301. break;
  302. default:
  303. msg.BulletMessage.Type = BulletType.NullBulletType;
  304. break;
  305. }
  306. //if (bullet.Parent != null)
  307. //msg.BulletMessage.MessageOfBullet.ParentTeamID = bullet.Parent.TeamID;
  308. /*switch (bullet.Place)
  309. {
  310. case Preparation.Utility.PlaceType.Null:
  311. msg.BulletMessage.MessageOfBullet.Place = Communication.Proto.PlaceType.Null;
  312. break;
  313. case Preparation.Utility.PlaceType.Grass:
  314. msg.BulletMessage.MessageOfBullet.Place = Communication.Proto.PlaceType.Grass;
  315. break;
  316. case Preparation.Utility.PlaceType.Grass:
  317. msg.BulletMessage.MessageOfBullet.Place = Communication.Proto.PlaceType.Grass;
  318. break;
  319. case Preparation.Utility.PlaceType.Grass:
  320. msg.BulletMessage.MessageOfBullet.Place = Communication.Proto.PlaceType.Grass;
  321. break;
  322. default:
  323. msg.BulletMessage.MessageOfBullet.Place = Communication.Proto.PlacccceType.NullPlaceType;
  324. break;
  325. }*/
  326. return msg;
  327. }
  328. private static MessageOfObj Prop(Prop prop)
  329. {
  330. MessageOfObj msg = new MessageOfObj();
  331. msg.PropMessage = new();
  332. //msg.PropMessage.Type = PropType.NullPropType; 下面写
  333. msg.PropMessage.X = prop.Position.x;
  334. msg.PropMessage.Y = prop.Position.y;
  335. msg.PropMessage.FacingDirection = 0;
  336. msg.PropMessage.Guid = 0;
  337. msg.PropMessage.Place = PlaceType.NullPlaceType;
  338. msg.PropMessage.Size = 0;
  339. msg.PropMessage.IsMoving = false;
  340. switch (prop.GetPropType())
  341. {
  342. /*case Preparation.Utility.PropType.Gem:
  343. msg.PropMessage.Type = PropType.Gem;
  344. break;
  345. case Preparation.Utility.PropType.addLIFE:
  346. msg.PropMessage.Type = PropType.AddLife;
  347. break;
  348. case Preparation.Utility.PropType.addSpeed:
  349. msg.PropMessage.Type = PropType.AddSpeed;
  350. break;
  351. case Preparation.Utility.PropType.Shield:
  352. msg.PropMessage.Type = PropType.Shield;
  353. break;
  354. case Preparation.Utility.PropType.Spear:
  355. msg.PropMessage.Type = PropType.Spear;
  356. break;*/
  357. default:
  358. msg.PropMessage.Type = PropType.NullPropType;
  359. break;
  360. }
  361. /*if(prop is Gem)
  362. {
  363. msg.PropMessage.MessageOfProp.Size = ((Gem)prop).Size;
  364. }
  365. else
  366. {
  367. msg.PropMessage.MessageOfProp.Size = 1;
  368. }
  369. switch (prop.Place)
  370. {
  371. case Preparation.Utility.PlaceType.Null:
  372. msg.PropMessage.MessageOfProp.Place = Communication.Proto.PlaceType.Null;
  373. break;
  374. case Preparation.Utility.PlaceType.Grass:
  375. msg.PropMessage.MessageOfProp.Place = Communication.Proto.PlaceType.Grass;
  376. break;
  377. case Preparation.Utility.PlaceType.Grass:
  378. msg.PropMessage.MessageOfProp.Place = Communication.Proto.PlaceType.Grass;
  379. break;
  380. case Preparation.Utility.PlaceType.Grass:
  381. msg.PropMessage.MessageOfProp.Place = Communication.Proto.PlaceType.Grass;
  382. break;
  383. default:
  384. msg.PropMessage.MessageOfProp.Place = Communication.Proto.PlacccceType.NullPlaceType;
  385. break;
  386. }*/
  387. return msg;
  388. }
  389. private static MessageOfObj BombedBullet(BombedBullet bombedBullet)
  390. {
  391. MessageOfObj msg = new MessageOfObj();
  392. msg.BombedBulletMessage = new();
  393. msg.BombedBulletMessage.X = bombedBullet.bulletHasBombed.Position.x;
  394. msg.BombedBulletMessage.Y = bombedBullet.bulletHasBombed.Position.y;
  395. //msg.BombedBulletMessage.FacingDirection = bombedBullet.FacingDirection; XY类型转double?
  396. msg.BombedBulletMessage.MappingId = bombedBullet.MappingID;
  397. msg.BombedBulletMessage.BombRange = BulletFactory.BulletRadius(bombedBullet.bulletHasBombed.TypeOfBullet); // 待确认
  398. switch (bombedBullet.bulletHasBombed.TypeOfBullet)
  399. {
  400. case Preparation.Utility.BulletType.OrdinaryBullet:
  401. msg.BombedBulletMessage.Type = BulletType.OrdinaryBullet;
  402. break;
  403. case Preparation.Utility.BulletType.AtomBomb:
  404. msg.BombedBulletMessage.Type = BulletType.AtomBomb;
  405. break;
  406. case Preparation.Utility.BulletType.FastBullet:
  407. msg.BombedBulletMessage.Type = BulletType.FastBullet;
  408. break;
  409. case Preparation.Utility.BulletType.LineBullet:
  410. msg.BombedBulletMessage.Type = BulletType.LineBullet;
  411. break;
  412. default:
  413. msg.BombedBulletMessage.Type = BulletType.NullBulletType;
  414. break;
  415. }
  416. return msg;
  417. }
  418. private static MessageOfObj PickedProp(PickedProp pickedProp)
  419. {
  420. MessageOfObj msg = new MessageOfObj(); // MessageOfObj中没有PickedProp
  421. /*msg.MessageOfPickedProp = new MessageOfPickedProp();
  422. msg.MessageOfPickedProp.MappingID = pickedProp.MappingID;
  423. msg.MessageOfPickedProp.X = pickedProp.PropHasPicked.Position.x;
  424. msg.MessageOfPickedProp.Y = pickedProp.PropHasPicked.Position.y;
  425. msg.MessageOfPickedProp.FacingDirection = pickedProp.PropHasPicked.FacingDirection;
  426. switch (pickedProp.PropHasPicked.GetPropType())
  427. {
  428. case Preparation.Utility.PropType.Gem:
  429. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.Gem;
  430. break;
  431. case Preparation.Utility.PropType.addLIFE:
  432. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.AddLife;
  433. break;
  434. case Preparation.Utility.PropType.addSpeed:
  435. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.AddSpeed;
  436. break;
  437. case Preparation.Utility.PropType.Shield:
  438. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.Shield;
  439. break;
  440. case Preparation.Utility.PropType.Spear:
  441. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.Spear;
  442. break;
  443. default:
  444. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.NullPropType;
  445. break;
  446. }*/
  447. return msg;
  448. }
  449. }
  450. }