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

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