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

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.BombedBullet:
  21. return BombedBullet((BombedBullet)gameObj);
  22. case Preparation.Utility.GameObjType.Generator:
  23. return Classroom((Generator)gameObj);
  24. case Preparation.Utility.GameObjType.Chest:
  25. return Chest((Chest)gameObj, time);
  26. case Preparation.Utility.GameObjType.Doorway:
  27. return Gate((Doorway)gameObj, time);
  28. case Preparation.Utility.GameObjType.EmergencyExit:
  29. if (((EmergencyExit)gameObj).CanOpen)
  30. return HiddenGate((EmergencyExit)gameObj);
  31. else return null;
  32. case Preparation.Utility.GameObjType.Door:
  33. return Door((Door)gameObj);
  34. case GameObjType.Item:
  35. return Prop((Item)gameObj);
  36. case Preparation.Utility.GameObjType.Gadget:
  37. return Prop((Gadget)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 = (int)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 = (int)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 = (int)player.MoveSpeed,
  100. TrickerType = Transformation.ToTrickerType(player.CharacterType),
  101. Guid = player.ID,
  102. Score = (int)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(Gadget 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 Prop(Item prop)
  160. {
  161. MessageOfObj msg = new()
  162. {
  163. PropMessage = new()
  164. {
  165. Type = Transformation.ToPropType(prop.GetPropType()),
  166. X = prop.Position.x,
  167. Y = prop.Position.y,
  168. FacingDirection = prop.FacingDirection.Angle(),
  169. Guid = prop.ID
  170. }
  171. };
  172. return msg;
  173. }
  174. private static MessageOfObj BombedBullet(BombedBullet bombedBullet)
  175. {
  176. MessageOfObj msg = new()
  177. {
  178. BombedBulletMessage = new()
  179. {
  180. Type = Transformation.ToBulletType(bombedBullet.bulletHasBombed.TypeOfBullet),
  181. X = bombedBullet.bulletHasBombed.Position.x,
  182. Y = bombedBullet.bulletHasBombed.Position.y,
  183. FacingDirection = bombedBullet.FacingDirection.Angle(),
  184. MappingId = bombedBullet.MappingID,
  185. BombRange = bombedBullet.bulletHasBombed.BulletBombRange
  186. }
  187. };
  188. // Debugger.Output(bombedBullet, bombedBullet.Place.ToString()+" "+bombedBullet.Position.ToString());
  189. return msg;
  190. }
  191. private static MessageOfObj Classroom(Generator generator)
  192. {
  193. MessageOfObj msg = new()
  194. {
  195. ClassroomMessage = new()
  196. {
  197. X = generator.Position.x,
  198. Y = generator.Position.y,
  199. Progress = generator.DegreeOfRepair
  200. }
  201. };
  202. return msg;
  203. }
  204. private static MessageOfObj Gate(Doorway doorway, int time)
  205. {
  206. MessageOfObj msg = new()
  207. {
  208. GateMessage = new()
  209. {
  210. X = doorway.Position.x,
  211. Y = doorway.Position.y
  212. }
  213. };
  214. int progress = ((doorway.OpenStartTime > 0) ? (time - doorway.OpenStartTime) : 0) + doorway.OpenDegree;
  215. msg.GateMessage.Progress = (progress > GameData.degreeOfOpenedDoorway) ? GameData.degreeOfOpenedDoorway : progress;
  216. return msg;
  217. }
  218. private static MessageOfObj HiddenGate(EmergencyExit Exit)
  219. {
  220. MessageOfObj msg = new()
  221. {
  222. HiddenGateMessage = new()
  223. {
  224. X = Exit.Position.x,
  225. Y = Exit.Position.y,
  226. Opened = Exit.IsOpen
  227. }
  228. };
  229. return msg;
  230. }
  231. private static MessageOfObj Door(Door door)
  232. {
  233. MessageOfObj msg = new()
  234. {
  235. DoorMessage = new()
  236. {
  237. X = door.Position.x,
  238. Y = door.Position.y,
  239. Progress = door.LockDegree,
  240. IsOpen = door.IsOpen
  241. }
  242. };
  243. return msg;
  244. }
  245. private static MessageOfObj Chest(Chest chest, int time)
  246. {
  247. MessageOfObj msg = new()
  248. {
  249. ChestMessage = new()
  250. {
  251. X = chest.Position.x,
  252. Y = chest.Position.y
  253. }
  254. };
  255. int progress = (chest.WhoOpen != null) ? ((time - chest.OpenStartTime) * chest.WhoOpen.SpeedOfOpenChest) : 0;
  256. msg.ChestMessage.Progress = (progress > GameData.degreeOfOpenedChest) ? GameData.degreeOfOpenedChest : progress;
  257. return msg;
  258. }
  259. }
  260. }