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. using Preparation.Interface;
  6. namespace Server
  7. {
  8. public static class CopyInfo
  9. {
  10. public static MessageOfObj? Auto(GameObj gameObj, long time)
  11. {
  12. switch (gameObj.Type)
  13. {
  14. case Preparation.Utility.GameObjType.Character:
  15. Character character = (Character)gameObj;
  16. if (character.IsGhost())
  17. return Tricker((Ghost)character, time);
  18. else return Student((Student)character, time);
  19. case Preparation.Utility.GameObjType.Bullet:
  20. return Bullet((Bullet)gameObj);
  21. case Preparation.Utility.GameObjType.BombedBullet:
  22. return BombedBullet((BombedBullet)gameObj);
  23. case Preparation.Utility.GameObjType.Generator:
  24. return Classroom((Generator)gameObj);
  25. case Preparation.Utility.GameObjType.Chest:
  26. return Chest((Chest)gameObj, time);
  27. case Preparation.Utility.GameObjType.Doorway:
  28. return Gate((Doorway)gameObj, time);
  29. case Preparation.Utility.GameObjType.EmergencyExit:
  30. if (((EmergencyExit)gameObj).CanOpen)
  31. return HiddenGate((EmergencyExit)gameObj);
  32. else return null;
  33. case Preparation.Utility.GameObjType.Door:
  34. return Door((Door)gameObj);
  35. case GameObjType.Item:
  36. return Prop((Item)gameObj);
  37. case Preparation.Utility.GameObjType.Gadget:
  38. return Prop((Gadget)gameObj);
  39. default: return null;
  40. }
  41. }
  42. public static MessageOfObj? Auto(MessageOfNews news)
  43. {
  44. MessageOfObj objMsg = new()
  45. {
  46. NewsMessage = news
  47. };
  48. return objMsg;
  49. }
  50. private static MessageOfObj? Student(Student player, long time)
  51. {
  52. if (player.IsGhost()) return null;
  53. MessageOfObj msg = new()
  54. {
  55. StudentMessage = new()
  56. {
  57. X = player.Position.x,
  58. Y = player.Position.y,
  59. Speed = player.MoveSpeed,
  60. Determination = (int)player.HP,
  61. Addiction = player.GamingAddiction,
  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 = (int)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.ActiveSkillDictionary)
  79. msg.StudentMessage.TimeUntilSkillAvailable.Add(keyValue.Value.SkillCD.GetRemainingTime());
  80. for (int i = 0; i < GameData.maxNumOfSkill - player.ActiveSkillDictionary.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, long time)
  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 = (int)player.MoveSpeed,
  101. TrickerType = Transformation.ToTrickerType(player.CharacterType),
  102. Guid = player.ID,
  103. Score = (int)player.Score,
  104. PlayerId = player.PlayerID,
  105. ViewRange = player.ViewRange,
  106. Radius = player.Radius,
  107. PlayerState = Transformation.ToPlayerState((PlayerStateType)player.PlayerState),
  108. TrickDesire = (player.BgmDictionary.ContainsKey(BgmType.StudentIsApproaching)) ? player.BgmDictionary[BgmType.StudentIsApproaching] : 0,
  109. ClassVolume = (player.BgmDictionary.ContainsKey(BgmType.GeneratorIsBeingFixed)) ? player.BgmDictionary[BgmType.GeneratorIsBeingFixed] : 0,
  110. FacingDirection = player.FacingDirection.Angle(),
  111. BulletType = Transformation.ToBulletType((Preparation.Utility.BulletType)player.BulletOfPlayer)
  112. }
  113. };
  114. foreach (var keyValue in player.ActiveSkillDictionary)
  115. msg.TrickerMessage.TimeUntilSkillAvailable.Add(keyValue.Value.SkillCD.GetRemainingTime());
  116. for (int i = 0; i < GameData.maxNumOfSkill - player.ActiveSkillDictionary.Count; ++i)
  117. msg.TrickerMessage.TimeUntilSkillAvailable.Add(-1);
  118. foreach (var value in player.PropInventory)
  119. msg.TrickerMessage.Prop.Add(Transformation.ToPropType(value.GetPropType()));
  120. foreach (KeyValuePair<Preparation.Utility.BuffType, bool> kvp in player.Buff)
  121. {
  122. if (kvp.Value)
  123. msg.TrickerMessage.Buff.Add(Transformation.ToTrickerBuffType(kvp.Key));
  124. }
  125. return msg;
  126. }
  127. private static MessageOfObj Bullet(Bullet bullet)
  128. {
  129. MessageOfObj msg = new()
  130. {
  131. BulletMessage = new()
  132. {
  133. Type = Transformation.ToBulletType(bullet.TypeOfBullet),
  134. X = bullet.Position.x,
  135. Y = bullet.Position.y,
  136. FacingDirection = bullet.FacingDirection.Angle(),
  137. Guid = bullet.ID,
  138. Team = (bullet.Parent!.IsGhost()) ? PlayerType.TrickerPlayer : PlayerType.StudentPlayer,
  139. BombRange = bullet.BulletBombRange,
  140. Speed = bullet.Speed
  141. }
  142. };
  143. return msg;
  144. }
  145. private static MessageOfObj Prop(Gadget prop)
  146. {
  147. MessageOfObj msg = new()
  148. {
  149. PropMessage = new()
  150. {
  151. Type = Transformation.ToPropType(prop.GetPropType()),
  152. X = prop.Position.x,
  153. Y = prop.Position.y,
  154. FacingDirection = prop.FacingDirection.Angle(),
  155. Guid = prop.ID
  156. }
  157. };
  158. return msg;
  159. }
  160. private static MessageOfObj Prop(Item prop)
  161. {
  162. MessageOfObj msg = new()
  163. {
  164. PropMessage = new()
  165. {
  166. Type = Transformation.ToPropType(prop.GetPropType()),
  167. X = prop.Position.x,
  168. Y = prop.Position.y,
  169. FacingDirection = prop.FacingDirection.Angle(),
  170. Guid = prop.ID
  171. }
  172. };
  173. return msg;
  174. }
  175. private static MessageOfObj BombedBullet(BombedBullet bombedBullet)
  176. {
  177. MessageOfObj msg = new()
  178. {
  179. BombedBulletMessage = new()
  180. {
  181. Type = Transformation.ToBulletType(bombedBullet.bulletHasBombed.TypeOfBullet),
  182. X = bombedBullet.bulletHasBombed.Position.x,
  183. Y = bombedBullet.bulletHasBombed.Position.y,
  184. FacingDirection = bombedBullet.facingDirection.Angle(),
  185. MappingId = bombedBullet.MappingID,
  186. BombRange = bombedBullet.bulletHasBombed.BulletBombRange
  187. }
  188. };
  189. // Debugger.Output(bombedBullet, bombedBullet.Place.ToString()+" "+bombedBullet.Position.ToString());
  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, long 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) ? ((int)(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.LockDegree,
  241. IsOpen = door.IsOpen
  242. }
  243. };
  244. return msg;
  245. }
  246. private static MessageOfObj Chest(Chest chest, long time)
  247. {
  248. return new()
  249. {
  250. ChestMessage = new()
  251. {
  252. X = chest.Position.x,
  253. Y = chest.Position.y,
  254. Progress = (int)(chest.OpenProgress.GetNonNegativeProgressDouble(time) * GameData.degreeOfOpenedChest)
  255. }
  256. };
  257. }
  258. }
  259. }