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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. using Protobuf;
  2. using System.Collections.Generic;
  3. using GameClass.GameObj;
  4. using System.Numerics;
  5. using Preparation.Utility;
  6. using Gaming;
  7. namespace Server
  8. {
  9. public static class CopyInfo
  10. {
  11. public static MessageOfObj? Auto(GameObj gameObj, int time)
  12. {
  13. switch (gameObj.Type)
  14. {
  15. case Preparation.Utility.GameObjType.Character:
  16. Character character = (Character)gameObj;
  17. if (character.IsGhost())
  18. return Tricker((Ghost)character);
  19. else return Student((Student)character);
  20. case Preparation.Utility.GameObjType.Bullet:
  21. return Bullet((Bullet)gameObj);
  22. case Preparation.Utility.GameObjType.Prop:
  23. return Prop((Prop)gameObj);
  24. case Preparation.Utility.GameObjType.BombedBullet:
  25. return BombedBullet((BombedBullet)gameObj);
  26. case Preparation.Utility.GameObjType.PickedProp:
  27. return PickedProp((PickedProp)gameObj);
  28. case Preparation.Utility.GameObjType.Generator:
  29. return Classroom((Generator)gameObj);
  30. case Preparation.Utility.GameObjType.Chest:
  31. return Chest((Chest)gameObj, time);
  32. case Preparation.Utility.GameObjType.Doorway:
  33. return Gate((Doorway)gameObj, time);
  34. case Preparation.Utility.GameObjType.EmergencyExit:
  35. if (((EmergencyExit)gameObj).CanOpen)
  36. return HiddenGate((EmergencyExit)gameObj);
  37. else return null;
  38. case Preparation.Utility.GameObjType.Door:
  39. return Door((Door)gameObj);
  40. default: return null;
  41. }
  42. }
  43. public static MessageOfObj? Auto(MessageOfNews news)
  44. {
  45. MessageOfObj objMsg = new()
  46. {
  47. NewsMessage = news
  48. };
  49. return objMsg;
  50. }
  51. private static MessageOfObj? Student(Student player)
  52. {
  53. if (player.IsGhost()) return null;
  54. MessageOfObj msg = new()
  55. {
  56. StudentMessage = new()
  57. {
  58. X = player.Position.x,
  59. Y = player.Position.y,
  60. Speed = player.MoveSpeed,
  61. Determination = player.HP,
  62. Addiction = player.GamingAddiction,
  63. Place = Transformation.ToPlaceType((Preparation.Utility.PlaceType)player.Place),
  64. Guid = player.ID,
  65. PlayerState = Transformation.ToPlayerState((PlayerStateType)player.PlayerState),
  66. PlayerId = player.PlayerID,
  67. ViewRange = player.ViewRange,
  68. Radius = player.Radius,
  69. DangerAlert = (player.BgmDictionary.ContainsKey(BgmType.GhostIsComing)) ? player.BgmDictionary[BgmType.GhostIsComing] : 0,
  70. Score = player.Score,
  71. TreatProgress = player.DegreeOfTreatment,
  72. RescueProgress = player.TimeOfRescue,
  73. BulletType = Transformation.ToBulletType((Preparation.Utility.BulletType)player.BulletOfPlayer),
  74. LearningSpeed = player.FixSpeed,
  75. TreatSpeed = player.TreatSpeed,
  76. FacingDirection = player.FacingDirection.Angle(),
  77. StudentType = Transformation.ToStudentType(player.CharacterType)
  78. }
  79. };
  80. foreach (var keyValue in player.TimeUntilActiveSkillAvailable)
  81. msg.StudentMessage.TimeUntilSkillAvailable.Add(keyValue.Value);
  82. for (int i = 0; i < GameData.maxNumOfSkill - player.TimeUntilActiveSkillAvailable.Count; ++i)
  83. msg.StudentMessage.TimeUntilSkillAvailable.Add(-1);
  84. foreach (var value in player.PropInventory)
  85. msg.StudentMessage.Prop.Add(Transformation.ToPropType(value.GetPropType()));
  86. foreach (KeyValuePair<Preparation.Utility.BuffType, bool> kvp in player.Buff)
  87. {
  88. if (kvp.Value)
  89. msg.StudentMessage.Buff.Add(Transformation.ToStudentBuffType(kvp.Key));
  90. }
  91. return msg;
  92. }
  93. private static MessageOfObj? Tricker(Character player)
  94. {
  95. if (!player.IsGhost()) return null;
  96. MessageOfObj msg = new()
  97. {
  98. TrickerMessage = new()
  99. {
  100. X = player.Position.x,
  101. Y = player.Position.y,
  102. Speed = player.MoveSpeed,
  103. Place = Transformation.ToPlaceType((Preparation.Utility.PlaceType)player.Place),
  104. TrickerType = Transformation.ToTrickerType(player.CharacterType),
  105. Guid = player.ID,
  106. Score = player.Score,
  107. PlayerId = player.PlayerID,
  108. ViewRange = player.ViewRange,
  109. Radius = player.Radius,
  110. PlayerState = Transformation.ToPlayerState((PlayerStateType)player.PlayerState),
  111. TrickDesire = (player.BgmDictionary.ContainsKey(BgmType.StudentIsApproaching)) ? player.BgmDictionary[BgmType.StudentIsApproaching] : 0,
  112. ClassVolume = (player.BgmDictionary.ContainsKey(BgmType.GeneratorIsBeingFixed)) ? player.BgmDictionary[BgmType.GeneratorIsBeingFixed] : 0,
  113. FacingDirection = player.FacingDirection.Angle(),
  114. BulletType = Transformation.ToBulletType((Preparation.Utility.BulletType)player.BulletOfPlayer)
  115. }
  116. };
  117. foreach (var keyValue in player.TimeUntilActiveSkillAvailable)
  118. msg.TrickerMessage.TimeUntilSkillAvailable.Add(keyValue.Value);
  119. for (int i = 0; i < GameData.maxNumOfSkill - player.TimeUntilActiveSkillAvailable.Count; ++i)
  120. msg.TrickerMessage.TimeUntilSkillAvailable.Add(-1);
  121. foreach (var value in player.PropInventory)
  122. msg.TrickerMessage.Prop.Add(Transformation.ToPropType(value.GetPropType()));
  123. foreach (KeyValuePair<Preparation.Utility.BuffType, bool> kvp in player.Buff)
  124. {
  125. if (kvp.Value)
  126. msg.TrickerMessage.Buff.Add(Transformation.ToTrickerBuffType(kvp.Key));
  127. }
  128. return msg;
  129. }
  130. private static MessageOfObj Bullet(Bullet bullet)
  131. {
  132. MessageOfObj msg = new()
  133. {
  134. BulletMessage = new()
  135. {
  136. X = bullet.Position.x,
  137. Y = bullet.Position.y,
  138. FacingDirection = bullet.FacingDirection.Angle(),
  139. Guid = bullet.ID,
  140. Team = (bullet.Parent.IsGhost()) ? PlayerType.TrickerPlayer : PlayerType.StudentPlayer,
  141. Place = Transformation.ToPlaceType((Preparation.Utility.PlaceType)bullet.Place),
  142. BombRange = bullet.BulletBombRange,
  143. Speed = bullet.Speed
  144. }
  145. };
  146. return msg;
  147. }
  148. private static MessageOfObj Prop(Prop prop)
  149. {
  150. MessageOfObj msg = new()
  151. {
  152. PropMessage = new()
  153. {
  154. Type = Transformation.ToPropType(prop.GetPropType()),
  155. X = prop.Position.x,
  156. Y = prop.Position.y,
  157. FacingDirection = prop.FacingDirection.Angle(),
  158. Guid = prop.ID,
  159. Place = Transformation.ToPlaceType((Preparation.Utility.PlaceType)prop.Place)
  160. }
  161. };
  162. return msg;
  163. }
  164. private static MessageOfObj BombedBullet(BombedBullet bombedBullet)
  165. {
  166. MessageOfObj msg = new()
  167. {
  168. BombedBulletMessage = new()
  169. {
  170. X = bombedBullet.bulletHasBombed.Position.x,
  171. Y = bombedBullet.bulletHasBombed.Position.y,
  172. FacingDirection = bombedBullet.FacingDirection.Angle(),
  173. MappingId = bombedBullet.MappingID,
  174. BombRange = bombedBullet.bulletHasBombed.BulletBombRange
  175. }
  176. };
  177. return msg;
  178. }
  179. private static MessageOfObj PickedProp(PickedProp pickedProp)
  180. {
  181. MessageOfObj msg = new MessageOfObj(); // MessageOfObj中没有PickedProp
  182. /*msg.MessageOfPickedProp = new MessageOfPickedProp();
  183. msg.MessageOfPickedProp.MappingID = pickedProp.MappingID;
  184. msg.MessageOfPickedProp.X = pickedProp.PropHasPicked.Position.x;
  185. msg.MessageOfPickedProp.Y = pickedProp.PropHasPicked.Position.y;
  186. msg.MessageOfPickedProp.FacingDirection = pickedProp.PropHasPicked.FacingDirection;*/
  187. return msg;
  188. }
  189. private static MessageOfObj Classroom(Generator generator)
  190. {
  191. MessageOfObj msg = new()
  192. {
  193. ClassroomMessage = new()
  194. {
  195. X = generator.Position.x,
  196. Y = generator.Position.y,
  197. Progress = generator.DegreeOfRepair
  198. }
  199. };
  200. return msg;
  201. }
  202. private static MessageOfObj Gate(Doorway doorway, int time)
  203. {
  204. MessageOfObj msg = new()
  205. {
  206. GateMessage = new()
  207. {
  208. X = doorway.Position.x,
  209. Y = doorway.Position.y
  210. }
  211. };
  212. int progress = ((doorway.OpenStartTime > 0) ? (time - doorway.OpenStartTime) : 0) + doorway.OpenDegree;
  213. msg.GateMessage.Progress = (progress > GameData.degreeOfOpenedDoorway) ? GameData.degreeOfOpenedDoorway : progress;
  214. return msg;
  215. }
  216. private static MessageOfObj HiddenGate(EmergencyExit Exit)
  217. {
  218. MessageOfObj msg = new()
  219. {
  220. HiddenGateMessage = new()
  221. {
  222. X = Exit.Position.x,
  223. Y = Exit.Position.y,
  224. Opened = Exit.IsOpen
  225. }
  226. };
  227. return msg;
  228. }
  229. private static MessageOfObj Door(Door door)
  230. {
  231. MessageOfObj msg = new()
  232. {
  233. DoorMessage = new()
  234. {
  235. X = door.Position.x,
  236. Y = door.Position.y,
  237. Progress = door.OpenOrLockDegree,
  238. IsOpen = door.IsOpen
  239. }
  240. };
  241. return msg;
  242. }
  243. private static MessageOfObj Chest(Chest chest, int time)
  244. {
  245. MessageOfObj msg = new()
  246. {
  247. ChestMessage = new()
  248. {
  249. X = chest.Position.x,
  250. Y = chest.Position.y
  251. }
  252. };
  253. int progress = (chest.OpenStartTime > 0) ? ((time - chest.OpenStartTime) * chest.WhoOpen.SpeedOfOpenChest) : 0;
  254. msg.ChestMessage.Progress = (progress > GameData.degreeOfOpenedChest) ? GameData.degreeOfOpenedChest : progress;
  255. return msg;
  256. }
  257. }
  258. }