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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. Type = Transformation.ToBulletType(bullet.TypeOfBullet),
  137. X = bullet.Position.x,
  138. Y = bullet.Position.y,
  139. FacingDirection = bullet.FacingDirection.Angle(),
  140. Guid = bullet.ID,
  141. Team = (bullet.Parent!.IsGhost()) ? PlayerType.TrickerPlayer : PlayerType.StudentPlayer,
  142. Place = Transformation.ToPlaceType((Preparation.Utility.PlaceType)bullet.Place),
  143. BombRange = bullet.BulletBombRange,
  144. Speed = bullet.Speed
  145. }
  146. };
  147. return msg;
  148. }
  149. private static MessageOfObj Prop(Prop prop)
  150. {
  151. MessageOfObj msg = new()
  152. {
  153. PropMessage = new()
  154. {
  155. Type = Transformation.ToPropType(prop.GetPropType()),
  156. X = prop.Position.x,
  157. Y = prop.Position.y,
  158. FacingDirection = prop.FacingDirection.Angle(),
  159. Guid = prop.ID,
  160. Place = Transformation.ToPlaceType((Preparation.Utility.PlaceType)prop.Place)
  161. }
  162. };
  163. return msg;
  164. }
  165. private static MessageOfObj BombedBullet(BombedBullet bombedBullet)
  166. {
  167. MessageOfObj msg = new()
  168. {
  169. BombedBulletMessage = new()
  170. {
  171. Type = Transformation.ToBulletType(bombedBullet.bulletHasBombed.TypeOfBullet),
  172. X = bombedBullet.bulletHasBombed.Position.x,
  173. Y = bombedBullet.bulletHasBombed.Position.y,
  174. FacingDirection = bombedBullet.FacingDirection.Angle(),
  175. MappingId = bombedBullet.MappingID,
  176. BombRange = bombedBullet.bulletHasBombed.BulletBombRange
  177. }
  178. };
  179. // Debugger.Output(bombedBullet, bombedBullet.Place.ToString()+" "+bombedBullet.Position.ToString());
  180. return msg;
  181. }
  182. private static MessageOfObj PickedProp(PickedProp pickedProp)
  183. {
  184. MessageOfObj msg = new MessageOfObj(); // MessageOfObj中没有PickedProp
  185. /*msg.MessageOfPickedProp = new MessageOfPickedProp();
  186. msg.MessageOfPickedProp.MappingID = pickedProp.MappingID;
  187. msg.MessageOfPickedProp.X = pickedProp.PropHasPicked.Position.x;
  188. msg.MessageOfPickedProp.Y = pickedProp.PropHasPicked.Position.y;
  189. msg.MessageOfPickedProp.FacingDirection = pickedProp.PropHasPicked.FacingDirection;*/
  190. return msg;
  191. }
  192. private static MessageOfObj Classroom(Generator generator)
  193. {
  194. MessageOfObj msg = new()
  195. {
  196. ClassroomMessage = new()
  197. {
  198. X = generator.Position.x,
  199. Y = generator.Position.y,
  200. Progress = generator.DegreeOfRepair
  201. }
  202. };
  203. return msg;
  204. }
  205. private static MessageOfObj Gate(Doorway doorway, int time)
  206. {
  207. MessageOfObj msg = new()
  208. {
  209. GateMessage = new()
  210. {
  211. X = doorway.Position.x,
  212. Y = doorway.Position.y
  213. }
  214. };
  215. int progress = ((doorway.OpenStartTime > 0) ? (time - doorway.OpenStartTime) : 0) + doorway.OpenDegree;
  216. msg.GateMessage.Progress = (progress > GameData.degreeOfOpenedDoorway) ? GameData.degreeOfOpenedDoorway : progress;
  217. return msg;
  218. }
  219. private static MessageOfObj HiddenGate(EmergencyExit Exit)
  220. {
  221. MessageOfObj msg = new()
  222. {
  223. HiddenGateMessage = new()
  224. {
  225. X = Exit.Position.x,
  226. Y = Exit.Position.y,
  227. Opened = Exit.IsOpen
  228. }
  229. };
  230. return msg;
  231. }
  232. private static MessageOfObj Door(Door door)
  233. {
  234. MessageOfObj msg = new()
  235. {
  236. DoorMessage = new()
  237. {
  238. X = door.Position.x,
  239. Y = door.Position.y,
  240. Progress = door.OpenOrLockDegree,
  241. IsOpen = door.IsOpen
  242. }
  243. };
  244. return msg;
  245. }
  246. private static MessageOfObj Chest(Chest chest, int time)
  247. {
  248. MessageOfObj msg = new()
  249. {
  250. ChestMessage = new()
  251. {
  252. X = chest.Position.x,
  253. Y = chest.Position.y
  254. }
  255. };
  256. int progress = (chest.OpenStartTime > 0) ? ((time - chest.OpenStartTime) * chest.WhoOpen!.SpeedOfOpenChest) : 0;
  257. msg.ChestMessage.Progress = (progress > GameData.degreeOfOpenedChest) ? GameData.degreeOfOpenedChest : progress;
  258. return msg;
  259. }
  260. }
  261. }