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

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