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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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, long 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, time);
  17. else return Student((Student)character, time);
  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, long time)
  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 = (int)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.ActiveSkillDictionary)
  78. {
  79. int progress = (int)((keyValue.Value.StartTime - time) + keyValue.Value.SkillCD);
  80. msg.StudentMessage.TimeUntilSkillAvailable.Add(progress < 0 ? 0 : progress);
  81. }
  82. for (int i = 0; i < GameData.maxNumOfSkill - player.ActiveSkillDictionary.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, long time)
  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 = (int)player.MoveSpeed,
  103. TrickerType = Transformation.ToTrickerType(player.CharacterType),
  104. Guid = player.ID,
  105. Score = (int)player.Score,
  106. PlayerId = player.PlayerID,
  107. ViewRange = player.ViewRange,
  108. Radius = player.Radius,
  109. PlayerState = Transformation.ToPlayerState((PlayerStateType)player.PlayerState),
  110. TrickDesire = (player.BgmDictionary.ContainsKey(BgmType.StudentIsApproaching)) ? player.BgmDictionary[BgmType.StudentIsApproaching] : 0,
  111. ClassVolume = (player.BgmDictionary.ContainsKey(BgmType.GeneratorIsBeingFixed)) ? player.BgmDictionary[BgmType.GeneratorIsBeingFixed] : 0,
  112. FacingDirection = player.FacingDirection.Angle(),
  113. BulletType = Transformation.ToBulletType((Preparation.Utility.BulletType)player.BulletOfPlayer)
  114. }
  115. };
  116. foreach (var keyValue in player.ActiveSkillDictionary)
  117. {
  118. int progress = (int)(keyValue.Value.SkillCD + (keyValue.Value.StartTime - time));
  119. msg.TrickerMessage.TimeUntilSkillAvailable.Add(progress < 0 ? 0 : progress);
  120. }
  121. for (int i = 0; i < GameData.maxNumOfSkill - player.ActiveSkillDictionary.Count; ++i)
  122. msg.TrickerMessage.TimeUntilSkillAvailable.Add(-1);
  123. foreach (var value in player.PropInventory)
  124. msg.TrickerMessage.Prop.Add(Transformation.ToPropType(value.GetPropType()));
  125. foreach (KeyValuePair<Preparation.Utility.BuffType, bool> kvp in player.Buff)
  126. {
  127. if (kvp.Value)
  128. msg.TrickerMessage.Buff.Add(Transformation.ToTrickerBuffType(kvp.Key));
  129. }
  130. return msg;
  131. }
  132. private static MessageOfObj Bullet(Bullet bullet)
  133. {
  134. MessageOfObj msg = new()
  135. {
  136. BulletMessage = new()
  137. {
  138. Type = Transformation.ToBulletType(bullet.TypeOfBullet),
  139. X = bullet.Position.x,
  140. Y = bullet.Position.y,
  141. FacingDirection = bullet.FacingDirection.Angle(),
  142. Guid = bullet.ID,
  143. Team = (bullet.Parent!.IsGhost()) ? PlayerType.TrickerPlayer : PlayerType.StudentPlayer,
  144. BombRange = bullet.BulletBombRange,
  145. Speed = bullet.Speed
  146. }
  147. };
  148. return msg;
  149. }
  150. private static MessageOfObj Prop(Gadget prop)
  151. {
  152. MessageOfObj msg = new()
  153. {
  154. PropMessage = new()
  155. {
  156. Type = Transformation.ToPropType(prop.GetPropType()),
  157. X = prop.Position.x,
  158. Y = prop.Position.y,
  159. FacingDirection = prop.FacingDirection.Angle(),
  160. Guid = prop.ID
  161. }
  162. };
  163. return msg;
  164. }
  165. private static MessageOfObj Prop(Item prop)
  166. {
  167. MessageOfObj msg = new()
  168. {
  169. PropMessage = new()
  170. {
  171. Type = Transformation.ToPropType(prop.GetPropType()),
  172. X = prop.Position.x,
  173. Y = prop.Position.y,
  174. FacingDirection = prop.FacingDirection.Angle(),
  175. Guid = prop.ID
  176. }
  177. };
  178. return msg;
  179. }
  180. private static MessageOfObj BombedBullet(BombedBullet bombedBullet)
  181. {
  182. MessageOfObj msg = new()
  183. {
  184. BombedBulletMessage = new()
  185. {
  186. Type = Transformation.ToBulletType(bombedBullet.bulletHasBombed.TypeOfBullet),
  187. X = bombedBullet.bulletHasBombed.Position.x,
  188. Y = bombedBullet.bulletHasBombed.Position.y,
  189. FacingDirection = bombedBullet.facingDirection.Angle(),
  190. MappingId = bombedBullet.MappingID,
  191. BombRange = bombedBullet.bulletHasBombed.BulletBombRange
  192. }
  193. };
  194. // Debugger.Output(bombedBullet, bombedBullet.Place.ToString()+" "+bombedBullet.Position.ToString());
  195. return msg;
  196. }
  197. private static MessageOfObj Classroom(Generator generator)
  198. {
  199. MessageOfObj msg = new()
  200. {
  201. ClassroomMessage = new()
  202. {
  203. X = generator.Position.x,
  204. Y = generator.Position.y,
  205. Progress = generator.DegreeOfRepair
  206. }
  207. };
  208. return msg;
  209. }
  210. private static MessageOfObj Gate(Doorway doorway, long time)
  211. {
  212. MessageOfObj msg = new()
  213. {
  214. GateMessage = new()
  215. {
  216. X = doorway.Position.x,
  217. Y = doorway.Position.y
  218. }
  219. };
  220. int progress = ((doorway.OpenStartTime > 0) ? ((int)(time - doorway.OpenStartTime)) : 0) + doorway.OpenDegree;
  221. msg.GateMessage.Progress = (progress > GameData.degreeOfOpenedDoorway) ? GameData.degreeOfOpenedDoorway : progress;
  222. return msg;
  223. }
  224. private static MessageOfObj HiddenGate(EmergencyExit Exit)
  225. {
  226. MessageOfObj msg = new()
  227. {
  228. HiddenGateMessage = new()
  229. {
  230. X = Exit.Position.x,
  231. Y = Exit.Position.y,
  232. Opened = Exit.IsOpen
  233. }
  234. };
  235. return msg;
  236. }
  237. private static MessageOfObj Door(Door door)
  238. {
  239. MessageOfObj msg = new()
  240. {
  241. DoorMessage = new()
  242. {
  243. X = door.Position.x,
  244. Y = door.Position.y,
  245. Progress = door.LockDegree,
  246. IsOpen = door.IsOpen
  247. }
  248. };
  249. return msg;
  250. }
  251. private static MessageOfObj Chest(Chest chest, long time)
  252. {
  253. MessageOfObj msg = new()
  254. {
  255. ChestMessage = new()
  256. {
  257. X = chest.Position.x,
  258. Y = chest.Position.y
  259. }
  260. };
  261. int progress = (chest.WhoOpen != null) ? (((int)(time - chest.OpenStartTime)) * chest.WhoOpen.SpeedOfOpenChest) : 0;
  262. msg.ChestMessage.Progress = (progress > GameData.degreeOfOpenedChest) ? GameData.degreeOfOpenedChest : progress;
  263. return msg;
  264. }
  265. }
  266. }