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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. Place = Transformation.ToPlaceType((Preparation.Utility.PlaceType)player.Place),
  62. Guid = player.ID,
  63. PlayerState = Transformation.ToPlayerState((PlayerStateType)player.PlayerState),
  64. PlayerId = player.PlayerID,
  65. ViewRange = player.ViewRange,
  66. Radius = player.Radius,
  67. DangerAlert = (player.BgmDictionary.ContainsKey(BgmType.GhostIsComing)) ? player.BgmDictionary[BgmType.GhostIsComing] : 0,
  68. Score = player.Score,
  69. TreatProgress = player.DegreeOfTreatment,
  70. RescueProgress = player.TimeOfRescue,
  71. BulletType = Transformation.ToBulletType((Preparation.Utility.BulletType)player.BulletOfPlayer),
  72. LearningSpeed = player.FixSpeed,
  73. TreatSpeed = player.TreatSpeed,
  74. FacingDirection = player.FacingDirection.Angle(),
  75. StudentType = Transformation.ToStudentType(player.CharacterType)
  76. }
  77. };
  78. foreach (var keyValue in player.TimeUntilActiveSkillAvailable)
  79. msg.StudentMessage.TimeUntilSkillAvailable.Add(keyValue.Value);
  80. for (int i = 0; i < GameData.maxNumOfSkill - player.TimeUntilActiveSkillAvailable.Count; ++i)
  81. msg.StudentMessage.TimeUntilSkillAvailable.Add(-1);
  82. foreach (var value in player.PropInventory)
  83. msg.StudentMessage.Prop.Add(Transformation.ToPropType(value.GetPropType()));
  84. foreach (KeyValuePair<Preparation.Utility.BuffType, bool> kvp in player.Buff)
  85. {
  86. if (kvp.Value)
  87. msg.StudentMessage.Buff.Add(Transformation.ToStudentBuffType(kvp.Key));
  88. }
  89. return msg;
  90. }
  91. private static MessageOfObj? Tricker(Character player)
  92. {
  93. if (!player.IsGhost()) return null;
  94. MessageOfObj msg = new()
  95. {
  96. TrickerMessage = new()
  97. {
  98. X = player.Position.x,
  99. Y = player.Position.y,
  100. Speed = player.MoveSpeed,
  101. Place = Transformation.ToPlaceType((Preparation.Utility.PlaceType)player.Place),
  102. TrickerType = Transformation.ToTrickerType(player.CharacterType),
  103. Guid = player.ID,
  104. Score = player.Score,
  105. PlayerId = player.PlayerID,
  106. ViewRange = player.ViewRange,
  107. Radius = player.Radius,
  108. PlayerState = Transformation.ToPlayerState((PlayerStateType)player.PlayerState),
  109. TrickDesire = (player.BgmDictionary.ContainsKey(BgmType.StudentIsApproaching)) ? player.BgmDictionary[BgmType.StudentIsApproaching] : 0,
  110. ClassVolume = (player.BgmDictionary.ContainsKey(BgmType.GeneratorIsBeingFixed)) ? player.BgmDictionary[BgmType.GeneratorIsBeingFixed] : 0,
  111. FacingDirection = player.FacingDirection.Angle(),
  112. BulletType = Transformation.ToBulletType((Preparation.Utility.BulletType)player.BulletOfPlayer)
  113. }
  114. };
  115. foreach (var keyValue in player.TimeUntilActiveSkillAvailable)
  116. msg.TrickerMessage.TimeUntilSkillAvailable.Add(keyValue.Value);
  117. for (int i = 0; i < GameData.maxNumOfSkill - player.TimeUntilActiveSkillAvailable.Count; ++i)
  118. msg.TrickerMessage.TimeUntilSkillAvailable.Add(-1);
  119. foreach (var value in player.PropInventory)
  120. msg.TrickerMessage.Prop.Add(Transformation.ToPropType(value.GetPropType()));
  121. foreach (KeyValuePair<Preparation.Utility.BuffType, bool> kvp in player.Buff)
  122. {
  123. if (kvp.Value)
  124. msg.TrickerMessage.Buff.Add(Transformation.ToTrickerBuffType(kvp.Key));
  125. }
  126. return msg;
  127. }
  128. private static MessageOfObj Bullet(Bullet bullet)
  129. {
  130. MessageOfObj msg = new()
  131. {
  132. BulletMessage = new()
  133. {
  134. Type = Transformation.ToBulletType(bullet.TypeOfBullet),
  135. X = bullet.Position.x,
  136. Y = bullet.Position.y,
  137. FacingDirection = bullet.FacingDirection.Angle(),
  138. Guid = bullet.ID,
  139. Team = (bullet.Parent!.IsGhost()) ? PlayerType.TrickerPlayer : PlayerType.StudentPlayer,
  140. Place = Transformation.ToPlaceType((Preparation.Utility.PlaceType)bullet.Place),
  141. BombRange = bullet.BulletBombRange,
  142. Speed = bullet.Speed
  143. }
  144. };
  145. return msg;
  146. }
  147. private static MessageOfObj Prop(Prop prop)
  148. {
  149. MessageOfObj msg = new()
  150. {
  151. PropMessage = new()
  152. {
  153. Type = Transformation.ToPropType(prop.GetPropType()),
  154. X = prop.Position.x,
  155. Y = prop.Position.y,
  156. FacingDirection = prop.FacingDirection.Angle(),
  157. Guid = prop.ID,
  158. Place = Transformation.ToPlaceType((Preparation.Utility.PlaceType)prop.Place)
  159. }
  160. };
  161. return msg;
  162. }
  163. private static MessageOfObj BombedBullet(BombedBullet bombedBullet)
  164. {
  165. MessageOfObj msg = new()
  166. {
  167. BombedBulletMessage = new()
  168. {
  169. Type = Transformation.ToBulletType(bombedBullet.bulletHasBombed.TypeOfBullet),
  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. // Debugger.Output(bombedBullet, bombedBullet.Place.ToString()+" "+bombedBullet.Position.ToString());
  178. return msg;
  179. }
  180. private static MessageOfObj PickedProp(PickedProp pickedProp)
  181. {
  182. MessageOfObj msg = new MessageOfObj(); // MessageOfObj中没有PickedProp
  183. /*msg.MessageOfPickedProp = new MessageOfPickedProp();
  184. msg.MessageOfPickedProp.MappingID = pickedProp.MappingID;
  185. msg.MessageOfPickedProp.X = pickedProp.PropHasPicked.Position.x;
  186. msg.MessageOfPickedProp.Y = pickedProp.PropHasPicked.Position.y;
  187. msg.MessageOfPickedProp.FacingDirection = pickedProp.PropHasPicked.FacingDirection;*/
  188. return msg;
  189. }
  190. private static MessageOfObj Classroom(Generator generator)
  191. {
  192. MessageOfObj msg = new()
  193. {
  194. ClassroomMessage = new()
  195. {
  196. X = generator.Position.x,
  197. Y = generator.Position.y,
  198. Progress = generator.DegreeOfRepair
  199. }
  200. };
  201. return msg;
  202. }
  203. private static MessageOfObj Gate(Doorway doorway, int time)
  204. {
  205. MessageOfObj msg = new()
  206. {
  207. GateMessage = new()
  208. {
  209. X = doorway.Position.x,
  210. Y = doorway.Position.y
  211. }
  212. };
  213. int progress = ((doorway.OpenStartTime > 0) ? (time - doorway.OpenStartTime) : 0) + doorway.OpenDegree;
  214. msg.GateMessage.Progress = (progress > GameData.degreeOfOpenedDoorway) ? GameData.degreeOfOpenedDoorway : progress;
  215. return msg;
  216. }
  217. private static MessageOfObj HiddenGate(EmergencyExit Exit)
  218. {
  219. MessageOfObj msg = new()
  220. {
  221. HiddenGateMessage = new()
  222. {
  223. X = Exit.Position.x,
  224. Y = Exit.Position.y,
  225. Opened = Exit.IsOpen
  226. }
  227. };
  228. return msg;
  229. }
  230. private static MessageOfObj Door(Door door)
  231. {
  232. MessageOfObj msg = new()
  233. {
  234. DoorMessage = new()
  235. {
  236. X = door.Position.x,
  237. Y = door.Position.y,
  238. Progress = door.OpenOrLockDegree,
  239. IsOpen = door.IsOpen
  240. }
  241. };
  242. return msg;
  243. }
  244. private static MessageOfObj Chest(Chest chest, int time)
  245. {
  246. MessageOfObj msg = new()
  247. {
  248. ChestMessage = new()
  249. {
  250. X = chest.Position.x,
  251. Y = chest.Position.y
  252. }
  253. };
  254. int progress = (chest.OpenStartTime > 0) ? ((time - chest.OpenStartTime) * chest.WhoOpen!.SpeedOfOpenChest) : 0;
  255. msg.ChestMessage.Progress = (progress > GameData.degreeOfOpenedChest) ? GameData.degreeOfOpenedChest : progress;
  256. return msg;
  257. }
  258. }
  259. }