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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. using Protobuf;
  2. using System.Collections.Generic;
  3. using GameClass.GameObj;
  4. namespace Server
  5. {
  6. public static class CopyInfo
  7. {
  8. // 下面赋值为0的大概率是还没写完 2023-03-03
  9. public static MessageOfObj? Auto(GameObj gameObj)
  10. {
  11. if (gameObj.Type == Preparation.Utility.GameObjType.Character)
  12. {
  13. Character character = (Character)gameObj;
  14. if (character.IsGhost())
  15. return Tricker((Character)character);
  16. else return Student((Character)character);
  17. }
  18. else if (gameObj.Type == Preparation.Utility.GameObjType.Bullet)
  19. return Bullet((Bullet)gameObj);
  20. else if (gameObj.Type == Preparation.Utility.GameObjType.Prop)
  21. return Prop((Prop)gameObj);
  22. else if (gameObj.Type == Preparation.Utility.GameObjType.BombedBullet)
  23. return BombedBullet((BombedBullet)gameObj);
  24. else if (gameObj.Type == Preparation.Utility.GameObjType.PickedProp)
  25. return PickedProp((PickedProp)gameObj);
  26. else return null; //先写着防报错
  27. }
  28. private static MessageOfObj? Student(Character player)
  29. {
  30. MessageOfObj msg = new MessageOfObj();
  31. if (player.IsGhost()) return null;
  32. msg.StudentMessage = new();
  33. msg.StudentMessage.X = player.Position.x;
  34. msg.StudentMessage.Y = player.Position.y;
  35. msg.StudentMessage.Speed = player.MoveSpeed;
  36. msg.StudentMessage.Determination = player.HP;
  37. //msg.StudentMessage.FailNum = 0;
  38. foreach (var keyValue in player.TimeUntilActiveSkillAvailable)
  39. msg.StudentMessage.TimeUntilSkillAvailable.Add(keyValue.Value);
  40. //msg.StudentMessage.StudentType; // 下面写
  41. msg.StudentMessage.Guid = player.ID;
  42. // msg.StudentMessage.State = player.PlayerState;
  43. msg.StudentMessage.FailTime = 0;
  44. msg.StudentMessage.EmoTime = 0;
  45. msg.StudentMessage.PlayerId = 0;
  46. msg.StudentMessage.ViewRange = 0;
  47. msg.StudentMessage.Radius = 0;
  48. msg.StudentMessage.Damage = 0;
  49. msg.StudentMessage.DangerAlert = 0;
  50. msg.StudentMessage.Score = 0;
  51. msg.StudentMessage.TreatProgress = 0;
  52. msg.StudentMessage.RescueProgress = 0;
  53. foreach (KeyValuePair<Preparation.Utility.BuffType, bool> kvp in player.Buff)
  54. {
  55. if (kvp.Value)
  56. {
  57. switch (kvp.Key) // StudentBuffType具体内容待定
  58. {
  59. case Preparation.Utility.BuffType.Spear:
  60. msg.StudentMessage.Buff.Add(StudentBuffType.NullSbuffType);
  61. break;
  62. case Preparation.Utility.BuffType.AddLIFE:
  63. msg.StudentMessage.Buff.Add(StudentBuffType.NullSbuffType);
  64. break;
  65. case Preparation.Utility.BuffType.Shield:
  66. msg.StudentMessage.Buff.Add(StudentBuffType.NullSbuffType);
  67. break;
  68. case Preparation.Utility.BuffType.AddSpeed:
  69. msg.StudentMessage.Buff.Add(StudentBuffType.NullSbuffType);
  70. break;
  71. default:
  72. break;
  73. }
  74. }
  75. }
  76. //Character的储存方式可能得改,用enum type存道具和子弹,不应该用对象
  77. //现在懒得改了,有时间再重整一波
  78. if (player.PropInventory == null)
  79. msg.StudentMessage.Prop.Add(PropType.NullPropType);
  80. else
  81. {
  82. switch (player.PropInventory.GetPropType())
  83. {
  84. case Preparation.Utility.PropType.Gem:
  85. msg.StudentMessage.Prop.Add(PropType.NullPropType);
  86. break;
  87. /*case Preparation.Utility.PropType.addLIFE:
  88. msg.StudentMessage.MessageOfHuman.Prop = Communication.Proto.PropType.AddLife;
  89. break;
  90. case Preparation.Utility.PropType.addSpeed:
  91. msg.StudentMessage.MessageOfHuman.Prop = Communication.Proto.PropType.AddSpeed;
  92. break;
  93. case Preparation.Utility.PropType.Shield:
  94. msg.StudentMessage.MessageOfHuman.Prop = Communication.Proto.PropType.Shield;
  95. break;
  96. case Preparation.Utility.PropType.Spear:
  97. msg.StudentMessage.MessageOfHuman.Prop = Communication.Proto.PropType.Spear;
  98. break;
  99. default:
  100. msg.StudentMessage.Prop = PropType.NullPropType;
  101. break;*/
  102. }
  103. }
  104. return msg;
  105. }
  106. private static MessageOfObj? Tricker(Character player)
  107. {
  108. MessageOfObj msg = new MessageOfObj();
  109. if (!player.IsGhost()) return null;
  110. msg.TrickerMessage = new();
  111. msg.TrickerMessage.X = player.Position.x;
  112. msg.TrickerMessage.Y = player.Position.y;
  113. msg.TrickerMessage.Speed = player.MoveSpeed;
  114. msg.TrickerMessage.Damage = 0;
  115. msg.TrickerMessage.TimeUntilSkillAvailable = 0;
  116. //msg.TrickerMessage.Place = 0; 下面写了
  117. //msg.TrickerMessage.Prop = PropType.NullPropType; // 下面写
  118. msg.TrickerMessage.TrickerType = TrickerType.NullTrickerType; // 下面写
  119. msg.TrickerMessage.Guid = 0;
  120. msg.TrickerMessage.Movable = false;
  121. msg.TrickerMessage.PlayerId = 0;
  122. msg.TrickerMessage.ViewRange = 0;
  123. msg.TrickerMessage.Radius = 0;
  124. //msg.TrickerMessage.Buff[0] = ButcherBuffType.NullSbuffType; 下面写了
  125. foreach (KeyValuePair<Preparation.Utility.BuffType, bool> kvp in player.Buff)
  126. {
  127. if (kvp.Value)
  128. {
  129. switch (kvp.Key) // ButcherBuffType具体内容待定
  130. {
  131. case Preparation.Utility.BuffType.Spear:
  132. msg.TrickerMessage.Buff.Add(TrickerBuffType.NullTbuffType);
  133. break;
  134. case Preparation.Utility.BuffType.AddLIFE:
  135. msg.TrickerMessage.Buff.Add(TrickerBuffType.NullTbuffType);
  136. break;
  137. case Preparation.Utility.BuffType.Shield:
  138. msg.TrickerMessage.Buff.Add(TrickerBuffType.NullTbuffType);
  139. break;
  140. case Preparation.Utility.BuffType.AddSpeed:
  141. msg.TrickerMessage.Buff.Add(TrickerBuffType.NullTbuffType);
  142. break;
  143. default:
  144. break;
  145. }
  146. }
  147. }
  148. /*switch (player.Place)
  149. {
  150. case Preparation.Utility.PlaceType.Land:
  151. msg.TrickerMessage.Place = PlaceType.Land;
  152. break;
  153. case Preparation.Utility.PlaceType.Grass1:
  154. msg.TrickerMessage.Place = PlaceType.Grass;
  155. break;
  156. case Preparation.Utility.PlaceType.Grass2:
  157. msg.TrickerMessage.Place = PlaceType.Grass;
  158. break;
  159. case Preparation.Utility.PlaceType.Grass3:
  160. msg.TrickerMessage.Place = PlaceType.Grass;
  161. break;
  162. // case Preparation.Utility.PlaceType.Invisible:
  163. // msg.TrickerMessage.MessageOfHuman.Place = Communication.Proto.PlaceType.Invisible;
  164. // break;
  165. default:
  166. msg.TrickerMessage.Place = PlaceType.NullPlaceType;
  167. break;
  168. }*/
  169. //Character的储存方式可能得改,用enum type存道具和子弹,不应该用对象
  170. //现在懒得改了,有时间再重整一波
  171. /*if (player.PropInventory == null)
  172. msg.TrickerMessage.Prop = PropType.NullPropType;
  173. else
  174. {
  175. switch (player.PropInventory.GetPropType())
  176. {
  177. case Preparation.Utility.PropType.Gem:
  178. msg.TrickerMessage.Prop = PropType.NullPropType;
  179. break;
  180. case Preparation.Utility.PropType.addLIFE:
  181. msg.TrickerMessage.MessageOfHuman.Prop = Communication.Proto.PropType.AddLife;
  182. break;
  183. case Preparation.Utility.PropType.addSpeed:
  184. msg.TrickerMessage.MessageOfHuman.Prop = Communication.Proto.PropType.AddSpeed;
  185. break;
  186. case Preparation.Utility.PropType.Shield:
  187. msg.TrickerMessage.MessageOfHuman.Prop = Communication.Proto.PropType.Shield;
  188. break;
  189. case Preparation.Utility.PropType.Spear:
  190. msg.TrickerMessage.MessageOfHuman.Prop = Communication.Proto.PropType.Spear;
  191. break;
  192. default:
  193. msg.TrickerMessage.Prop = PropType.NullPropType;
  194. break;
  195. }
  196. }*/
  197. return msg;
  198. }
  199. private static MessageOfObj Bullet(Bullet bullet)
  200. {
  201. MessageOfObj msg = new MessageOfObj();
  202. msg.BulletMessage = new();
  203. msg.BulletMessage.X = bullet.Position.x;
  204. msg.BulletMessage.Y = bullet.Position.y;
  205. //msg.BulletMessage.FacingDirection = bullet.FacingDirection; // XY转double?
  206. msg.BulletMessage.Guid = bullet.ID;
  207. msg.BulletMessage.Team = PlayerType.NullPlayerType;
  208. msg.BulletMessage.Place = PlaceType.NullPlaceType;
  209. msg.BulletMessage.BombRange = 0;
  210. switch (bullet.TypeOfBullet)
  211. {
  212. case Preparation.Utility.BulletType.AtomBomb:
  213. msg.BulletMessage.Type = BulletType.AtomBomb;
  214. break;
  215. case Preparation.Utility.BulletType.OrdinaryBullet:
  216. msg.BulletMessage.Type = BulletType.OrdinaryBullet;
  217. break;
  218. case Preparation.Utility.BulletType.FastBullet:
  219. msg.BulletMessage.Type = BulletType.FastBullet;
  220. break;
  221. case Preparation.Utility.BulletType.LineBullet:
  222. msg.BulletMessage.Type = BulletType.LineBullet;
  223. break;
  224. default:
  225. msg.BulletMessage.Type = BulletType.NullBulletType;
  226. break;
  227. }
  228. //if (bullet.Parent != null)
  229. //msg.BulletMessage.MessageOfBullet.ParentTeamID = bullet.Parent.TeamID;
  230. /*switch (bullet.Place)
  231. {
  232. case Preparation.Utility.PlaceType.Null:
  233. msg.BulletMessage.MessageOfBullet.Place = Communication.Proto.PlaceType.Null;
  234. break;
  235. case Preparation.Utility.PlaceType.Grass:
  236. msg.BulletMessage.MessageOfBullet.Place = Communication.Proto.PlaceType.Grass;
  237. break;
  238. case Preparation.Utility.PlaceType.Grass:
  239. msg.BulletMessage.MessageOfBullet.Place = Communication.Proto.PlaceType.Grass;
  240. break;
  241. case Preparation.Utility.PlaceType.Grass:
  242. msg.BulletMessage.MessageOfBullet.Place = Communication.Proto.PlaceType.Grass;
  243. break;
  244. default:
  245. msg.BulletMessage.MessageOfBullet.Place = Communication.Proto.PlacccceType.NullPlaceType;
  246. break;
  247. }*/
  248. return msg;
  249. }
  250. private static MessageOfObj Prop(Prop prop)
  251. {
  252. MessageOfObj msg = new MessageOfObj();
  253. msg.PropMessage = new();
  254. //msg.PropMessage.Type = PropType.NullPropType; 下面写
  255. msg.PropMessage.X = prop.Position.x;
  256. msg.PropMessage.Y = prop.Position.y;
  257. msg.PropMessage.FacingDirection = 0;
  258. msg.PropMessage.Guid = 0;
  259. msg.PropMessage.Place = PlaceType.NullPlaceType;
  260. msg.PropMessage.Size = 0;
  261. msg.PropMessage.IsMoving = false;
  262. switch (prop.GetPropType())
  263. {
  264. /*case Preparation.Utility.PropType.Gem:
  265. msg.PropMessage.Type = PropType.Gem;
  266. break;
  267. case Preparation.Utility.PropType.addLIFE:
  268. msg.PropMessage.Type = PropType.AddLife;
  269. break;
  270. case Preparation.Utility.PropType.addSpeed:
  271. msg.PropMessage.Type = PropType.AddSpeed;
  272. break;
  273. case Preparation.Utility.PropType.Shield:
  274. msg.PropMessage.Type = PropType.Shield;
  275. break;
  276. case Preparation.Utility.PropType.Spear:
  277. msg.PropMessage.Type = PropType.Spear;
  278. break;*/
  279. default:
  280. msg.PropMessage.Type = PropType.NullPropType;
  281. break;
  282. }
  283. /*if(prop is Gem)
  284. {
  285. msg.PropMessage.MessageOfProp.Size = ((Gem)prop).Size;
  286. }
  287. else
  288. {
  289. msg.PropMessage.MessageOfProp.Size = 1;
  290. }
  291. switch (prop.Place)
  292. {
  293. case Preparation.Utility.PlaceType.Null:
  294. msg.PropMessage.MessageOfProp.Place = Communication.Proto.PlaceType.Null;
  295. break;
  296. case Preparation.Utility.PlaceType.Grass:
  297. msg.PropMessage.MessageOfProp.Place = Communication.Proto.PlaceType.Grass;
  298. break;
  299. case Preparation.Utility.PlaceType.Grass:
  300. msg.PropMessage.MessageOfProp.Place = Communication.Proto.PlaceType.Grass;
  301. break;
  302. case Preparation.Utility.PlaceType.Grass:
  303. msg.PropMessage.MessageOfProp.Place = Communication.Proto.PlaceType.Grass;
  304. break;
  305. default:
  306. msg.PropMessage.MessageOfProp.Place = Communication.Proto.PlacccceType.NullPlaceType;
  307. break;
  308. }*/
  309. return msg;
  310. }
  311. private static MessageOfObj BombedBullet(BombedBullet bombedBullet)
  312. {
  313. MessageOfObj msg = new MessageOfObj();
  314. msg.BombedBulletMessage = new();
  315. msg.BombedBulletMessage.X = bombedBullet.bulletHasBombed.Position.x;
  316. msg.BombedBulletMessage.Y = bombedBullet.bulletHasBombed.Position.y;
  317. //msg.BombedBulletMessage.FacingDirection = bombedBullet.FacingDirection; XY类型转double?
  318. msg.BombedBulletMessage.MappingId = bombedBullet.MappingID;
  319. msg.BombedBulletMessage.BombRange = BulletFactory.BulletRadius(bombedBullet.bulletHasBombed.TypeOfBullet); // 待确认
  320. switch (bombedBullet.bulletHasBombed.TypeOfBullet)
  321. {
  322. case Preparation.Utility.BulletType.OrdinaryBullet:
  323. msg.BombedBulletMessage.Type = BulletType.OrdinaryBullet;
  324. break;
  325. case Preparation.Utility.BulletType.AtomBomb:
  326. msg.BombedBulletMessage.Type = BulletType.AtomBomb;
  327. break;
  328. case Preparation.Utility.BulletType.FastBullet:
  329. msg.BombedBulletMessage.Type = BulletType.FastBullet;
  330. break;
  331. case Preparation.Utility.BulletType.LineBullet:
  332. msg.BombedBulletMessage.Type = BulletType.LineBullet;
  333. break;
  334. default:
  335. msg.BombedBulletMessage.Type = BulletType.NullBulletType;
  336. break;
  337. }
  338. return msg;
  339. }
  340. private static MessageOfObj PickedProp(PickedProp pickedProp)
  341. {
  342. MessageOfObj msg = new MessageOfObj(); // MessageOfObj中没有PickedProp
  343. /*msg.MessageOfPickedProp = new MessageOfPickedProp();
  344. msg.MessageOfPickedProp.MappingID = pickedProp.MappingID;
  345. msg.MessageOfPickedProp.X = pickedProp.PropHasPicked.Position.x;
  346. msg.MessageOfPickedProp.Y = pickedProp.PropHasPicked.Position.y;
  347. msg.MessageOfPickedProp.FacingDirection = pickedProp.PropHasPicked.FacingDirection;
  348. switch (pickedProp.PropHasPicked.GetPropType())
  349. {
  350. case Preparation.Utility.PropType.Gem:
  351. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.Gem;
  352. break;
  353. case Preparation.Utility.PropType.addLIFE:
  354. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.AddLife;
  355. break;
  356. case Preparation.Utility.PropType.addSpeed:
  357. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.AddSpeed;
  358. break;
  359. case Preparation.Utility.PropType.Shield:
  360. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.Shield;
  361. break;
  362. case Preparation.Utility.PropType.Spear:
  363. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.Spear;
  364. break;
  365. default:
  366. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.NullPropType;
  367. break;
  368. }*/
  369. return msg;
  370. }
  371. }
  372. }