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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. using Protobuf;
  2. using System.Collections.Generic;
  3. using GameClass.GameObj;
  4. /*
  5. namespace Server
  6. {
  7. public static class CopyInfo
  8. {
  9. public static MessageToClient.Types.GameObjMessage? Auto(GameObj gameObj)
  10. {
  11. if (gameObj.Type == Preparation.Utility.GameObjType.Character)
  12. return Player((Character)gameObj);
  13. else if (gameObj.Type == Preparation.Utility.GameObjType.Bullet)
  14. return Bullet((Bullet)gameObj);
  15. else if (gameObj.Type == Preparation.Utility.GameObjType.Prop)
  16. return Prop((Prop)gameObj);
  17. else if (gameObj.Type == Preparation.Utility.GameObjType.BombedBullet)
  18. return BombedBullet((BombedBullet)gameObj);
  19. else if (gameObj.Type == Preparation.Utility.GameObjType.PickedProp)
  20. return PickedProp((PickedProp)gameObj);
  21. else return null; //先写着防报错
  22. }
  23. private static MessageToClient.Types.GameObjMessage Player(Character player)
  24. {
  25. MessageToClient.Types.GameObjMessage msg = new MessageToClient.Types.GameObjMessage();
  26. msg.MessageOfCharacter = new MessageOfCharacter();
  27. msg.MessageOfCharacter.X = player.Position.x;
  28. msg.MessageOfCharacter.Y = player.Position.y;
  29. msg.MessageOfCharacter.AttackRange = player.AttackRange;
  30. msg.MessageOfCharacter.BulletNum = player.BulletNum;
  31. msg.MessageOfCharacter.CanMove = player.CanMove;
  32. msg.MessageOfCharacter.CD = player.CD;
  33. msg.MessageOfCharacter.GemNum = player.GemNum;
  34. msg.MessageOfCharacter.Guid = player.ID;
  35. msg.MessageOfCharacter.IsResetting = player.IsResetting;
  36. msg.MessageOfCharacter.Life = player.HP;
  37. msg.MessageOfCharacter.LifeNum = player.DeathCount + 1;
  38. msg.MessageOfCharacter.Radius = player.Radius;
  39. msg.MessageOfCharacter.Speed = player.MoveSpeed;
  40. msg.MessageOfCharacter.TimeUntilCommonSkillAvailable = player.TimeUntilCommonSkillAvailable;
  41. msg.MessageOfCharacter.TeamID = player.TeamID;
  42. msg.MessageOfCharacter.PlayerID = player.PlayerID;
  43. msg.MessageOfCharacter.IsInvisible = player.IsInvisible;
  44. msg.MessageOfCharacter.FacingDirection = player.FacingDirection;
  45. //应该要发队伍分数,这里先发个人分数
  46. msg.MessageOfCharacter.Score = player.Score;
  47. //这条暂时没啥用
  48. msg.MessageOfCharacter.TimeUntilUltimateSkillAvailable = 0;
  49. msg.MessageOfCharacter.Vampire = player.Vampire;
  50. foreach (KeyValuePair<Preparation.Utility.BuffType, bool> kvp in player.Buff)
  51. {
  52. if (kvp.Value)
  53. {
  54. switch(kvp.Key)
  55. {
  56. case Preparation.Utility.BuffType.Spear:
  57. msg.MessageOfCharacter.Buff.Add(BuffType.SpearBuff);
  58. break;
  59. case Preparation.Utility.BuffType.AddLIFE:
  60. msg.MessageOfCharacter.Buff.Add(BuffType.AddLife);
  61. break;
  62. case Preparation.Utility.BuffType.Shield:
  63. msg.MessageOfCharacter.Buff.Add(BuffType.ShieldBuff);
  64. break;
  65. case Preparation.Utility.BuffType.AddSpeed:
  66. msg.MessageOfCharacter.Buff.Add(BuffType.MoveSpeed);
  67. break;
  68. default:
  69. break;
  70. }
  71. }
  72. }
  73. switch (player.Place)
  74. {
  75. case Preparation.Utility.PlacccceType.Land:
  76. msg.MessageOfCharacter.Place = Communication.Proto.PlacccceType.Land;
  77. break;
  78. case Preparation.Utility.PlacccceType.Grass1:
  79. msg.MessageOfCharacter.Place = Communication.Proto.PlacccceType.Grass1;
  80. break;
  81. case Preparation.Utility.PlacccceType.Grass2:
  82. msg.MessageOfCharacter.Place = Communication.Proto.PlacccceType.Grass2;
  83. break;
  84. case Preparation.Utility.PlacccceType.Grass3:
  85. msg.MessageOfCharacter.Place = Communication.Proto.PlacccceType.Grass3;
  86. break;
  87. // case Preparation.Utility.PlacccceType.Invisible:
  88. // msg.MessageOfCharacter.Place = Communication.Proto.PlacccceType.Invisible;
  89. // break;
  90. default:
  91. msg.MessageOfCharacter.Place = Communication.Proto.PlacccceType.NullPlaceType;
  92. break;
  93. }
  94. //Character的储存方式可能得改,用enum type存道具和子弹,不应该用对象
  95. //现在懒得改了,有时间再重整一波
  96. if (player.PropInventory == null)
  97. msg.MessageOfCharacter.Prop = Communication.Proto.PropType.NullPropType;
  98. else
  99. {
  100. switch (player.PropInventory.GetPropType())
  101. {
  102. case Preparation.Utility.PropType.Gem:
  103. msg.MessageOfCharacter.Prop = Communication.Proto.PropType.Gem;
  104. break;
  105. case Preparation.Utility.PropType.addLIFE:
  106. msg.MessageOfCharacter.Prop = Communication.Proto.PropType.AddLife;
  107. break;
  108. case Preparation.Utility.PropType.addSpeed:
  109. msg.MessageOfCharacter.Prop = Communication.Proto.PropType.AddSpeed;
  110. break;
  111. case Preparation.Utility.PropType.Shield:
  112. msg.MessageOfCharacter.Prop = Communication.Proto.PropType.Shield;
  113. break;
  114. case Preparation.Utility.PropType.Spear:
  115. msg.MessageOfCharacter.Prop = Communication.Proto.PropType.Spear;
  116. break;
  117. default:
  118. msg.MessageOfCharacter.Prop = Communication.Proto.PropType.NullPropType;
  119. break;
  120. }
  121. }
  122. switch (player.PassiveSkillType)
  123. {
  124. case Preparation.Utility.PassiveSkillType.RecoverAfterBattle:
  125. msg.MessageOfCharacter.PassiveSkillType = Communication.Proto.PassiveSkillType.RecoverAfterBattle;
  126. break;
  127. case Preparation.Utility.PassiveSkillType.SpeedUpWhenLeavingGrass:
  128. msg.MessageOfCharacter.PassiveSkillType = Communication.Proto.PassiveSkillType.SpeedUpWhenLeavingGrass;
  129. break;
  130. case Preparation.Utility.PassiveSkillType.Vampire:
  131. msg.MessageOfCharacter.PassiveSkillType = Communication.Proto.PassiveSkillType.Vampire;
  132. break;
  133. default:
  134. msg.MessageOfCharacter.PassiveSkillType = Communication.Proto.PassiveSkillType.NullPassiveSkillType;
  135. break;
  136. }
  137. switch (player.CommonSkillType)
  138. {
  139. case Preparation.Utility.ActiveSkillType.BecomeAssassin:
  140. msg.MessageOfCharacter.ActiveSkillType = Communication.Proto.ActiveSkillType.BecomeAssassin;
  141. break;
  142. case Preparation.Utility.ActiveSkillType.BecomeVampire:
  143. msg.MessageOfCharacter.ActiveSkillType = Communication.Proto.ActiveSkillType.BecomeVampire;
  144. break;
  145. case Preparation.Utility.ActiveSkillType.NuclearWeapon:
  146. msg.MessageOfCharacter.ActiveSkillType = Communication.Proto.ActiveSkillType.NuclearWeapon;
  147. break;
  148. case Preparation.Utility.ActiveSkillType.SuperFast:
  149. msg.MessageOfCharacter.ActiveSkillType = Communication.Proto.ActiveSkillType.SuperFast;
  150. break;
  151. default:
  152. msg.MessageOfCharacter.ActiveSkillType = Communication.Proto.ActiveSkillType.NullActiveSkillType;
  153. break;
  154. }
  155. switch (player.BulletOfPlayer)
  156. {
  157. case Preparation.Utility.BulletType.AtomBomb:
  158. msg.MessageOfCharacter.BulletType = Communication.Proto.BulletType.AtomBomb;
  159. break;
  160. case Preparation.Utility.BulletType.OrdinaryBullet:
  161. msg.MessageOfCharacter.BulletType = Communication.Proto.BulletType.OrdinaryBullet;
  162. break;
  163. case Preparation.Utility.BulletType.FastBullet:
  164. msg.MessageOfCharacter.BulletType = Communication.Proto.BulletType.FastBullet;
  165. break;
  166. case Preparation.Utility.BulletType.LineBullet:
  167. msg.MessageOfCharacter.BulletType = Communication.Proto.BulletType.LineBullet;
  168. break;
  169. default:
  170. msg.MessageOfCharacter.BulletType = Communication.Proto.BulletType.NullBulletType;
  171. break;
  172. }
  173. return msg;
  174. }
  175. private static MessageToClient.Types.GameObjMessage Bullet(Bullet bullet)
  176. {
  177. MessageToClient.Types.GameObjMessage msg = new MessageToClient.Types.GameObjMessage();
  178. msg.MessageOfBullet = new MessageOfBullet();
  179. msg.MessageOfBullet.FacingDirection = bullet.FacingDirection;
  180. msg.MessageOfBullet.Guid = bullet.ID;
  181. msg.MessageOfBullet.BombRange = BulletFactory.BulletBombRange(bullet.TypeOfBullet);
  182. switch (bullet.TypeOfBullet)
  183. {
  184. case Preparation.Utility.BulletType.AtomBomb:
  185. msg.MessageOfBullet.Type = Communication.Proto.BulletType.AtomBomb;
  186. break;
  187. case Preparation.Utility.BulletType.OrdinaryBullet:
  188. msg.MessageOfBullet.Type = Communication.Proto.BulletType.OrdinaryBullet;
  189. break;
  190. case Preparation.Utility.BulletType.FastBullet:
  191. msg.MessageOfBullet.Type = Communication.Proto.BulletType.FastBullet;
  192. break;
  193. case Preparation.Utility.BulletType.LineBullet:
  194. msg.MessageOfBullet.Type = Communication.Proto.BulletType.LineBullet;
  195. break;
  196. default:
  197. msg.MessageOfBullet.Type = Communication.Proto.BulletType.NullBulletType;
  198. break;
  199. }
  200. msg.MessageOfBullet.X = bullet.Position.x;
  201. msg.MessageOfBullet.Y = bullet.Position.y;
  202. if (bullet.Parent != null)
  203. msg.MessageOfBullet.ParentTeamID = bullet.Parent.TeamID;
  204. switch (bullet.Place)
  205. {
  206. case Preparation.Utility.PlacccceType.Land:
  207. msg.MessageOfBullet.Place = Communication.Proto.PlacccceType.Land;
  208. break;
  209. case Preparation.Utility.PlacccceType.Grass1:
  210. msg.MessageOfBullet.Place = Communication.Proto.PlacccceType.Grass1;
  211. break;
  212. case Preparation.Utility.PlacccceType.Grass2:
  213. msg.MessageOfBullet.Place = Communication.Proto.PlacccceType.Grass2;
  214. break;
  215. case Preparation.Utility.PlacccceType.Grass3:
  216. msg.MessageOfBullet.Place = Communication.Proto.PlacccceType.Grass3;
  217. break;
  218. default:
  219. msg.MessageOfBullet.Place = Communication.Proto.PlacccceType.NullPlaceType;
  220. break;
  221. }
  222. return msg;
  223. }
  224. private static MessageToClient.Types.GameObjMessage Prop(Prop prop)
  225. {
  226. MessageToClient.Types.GameObjMessage msg = new MessageToClient.Types.GameObjMessage();
  227. msg.MessageOfProp = new MessageOfProp();
  228. msg.MessageOfProp.FacingDirection = prop.FacingDirection;
  229. msg.MessageOfProp.Guid = prop.ID;
  230. msg.MessageOfProp.IsMoving = prop.IsMoving;
  231. switch (prop.GetPropType())
  232. {
  233. case Preparation.Utility.PropType.Gem:
  234. msg.MessageOfProp.Type = Communication.Proto.PropType.Gem;
  235. break;
  236. case Preparation.Utility.PropType.addLIFE:
  237. msg.MessageOfProp.Type = Communication.Proto.PropType.AddLife;
  238. break;
  239. case Preparation.Utility.PropType.addSpeed:
  240. msg.MessageOfProp.Type = Communication.Proto.PropType.AddSpeed;
  241. break;
  242. case Preparation.Utility.PropType.Shield:
  243. msg.MessageOfProp.Type = Communication.Proto.PropType.Shield;
  244. break;
  245. case Preparation.Utility.PropType.Spear:
  246. msg.MessageOfProp.Type = Communication.Proto.PropType.Spear;
  247. break;
  248. default:
  249. msg.MessageOfProp.Type = Communication.Proto.PropType.NullPropType;
  250. break;
  251. }
  252. msg.MessageOfProp.X = prop.Position.x;
  253. msg.MessageOfProp.Y = prop.Position.y;
  254. if(prop is Gem)
  255. {
  256. msg.MessageOfProp.Size = ((Gem)prop).Size;
  257. }
  258. else
  259. {
  260. msg.MessageOfProp.Size = 1;
  261. }
  262. switch (prop.Place)
  263. {
  264. case Preparation.Utility.PlacccceType.Land:
  265. msg.MessageOfProp.Place = Communication.Proto.PlacccceType.Land;
  266. break;
  267. case Preparation.Utility.PlacccceType.Grass1:
  268. msg.MessageOfProp.Place = Communication.Proto.PlacccceType.Grass1;
  269. break;
  270. case Preparation.Utility.PlacccceType.Grass2:
  271. msg.MessageOfProp.Place = Communication.Proto.PlacccceType.Grass2;
  272. break;
  273. case Preparation.Utility.PlacccceType.Grass3:
  274. msg.MessageOfProp.Place = Communication.Proto.PlacccceType.Grass3;
  275. break;
  276. default:
  277. msg.MessageOfProp.Place = Communication.Proto.PlacccceType.NullPlaceType;
  278. break;
  279. }
  280. return msg;
  281. }
  282. private static MessageToClient.Types.GameObjMessage BombedBullet(BombedBullet bombedBullet)
  283. {
  284. MessageToClient.Types.GameObjMessage msg = new MessageToClient.Types.GameObjMessage();
  285. msg.MessageOfBombedBullet = new MessageOfBombedBullet();
  286. msg.MessageOfBombedBullet.FacingDirection = bombedBullet.bulletHasBombed.FacingDirection;
  287. msg.MessageOfBombedBullet.X = bombedBullet.bulletHasBombed.Position.x;
  288. msg.MessageOfBombedBullet.Y = bombedBullet.bulletHasBombed.Position.y;
  289. msg.MessageOfBombedBullet.MappingID = bombedBullet.MappingID;
  290. msg.MessageOfBombedBullet.BombRange = BulletFactory.BulletBombRange(bombedBullet.bulletHasBombed.TypeOfBullet);
  291. switch (bombedBullet.bulletHasBombed.TypeOfBullet)
  292. {
  293. case Preparation.Utility.BulletType.OrdinaryBullet:
  294. msg.MessageOfBombedBullet.Type = Communication.Proto.BulletType.OrdinaryBullet;
  295. break;
  296. case Preparation.Utility.BulletType.AtomBomb:
  297. msg.MessageOfBombedBullet.Type = Communication.Proto.BulletType.AtomBomb;
  298. break;
  299. case Preparation.Utility.BulletType.FastBullet:
  300. msg.MessageOfBombedBullet.Type = Communication.Proto.BulletType.FastBullet;
  301. break;
  302. case Preparation.Utility.BulletType.LineBullet:
  303. msg.MessageOfBombedBullet.Type = Communication.Proto.BulletType.LineBullet;
  304. break;
  305. default:
  306. msg.MessageOfBombedBullet.Type = Communication.Proto.BulletType.NullBulletType;
  307. break;
  308. }
  309. return msg;
  310. }
  311. private static MessageToClient.Types.GameObjMessage PickedProp(PickedProp pickedProp)
  312. {
  313. MessageToClient.Types.GameObjMessage msg = new MessageToClient.Types.GameObjMessage();
  314. msg.MessageOfPickedProp = new MessageOfPickedProp();
  315. msg.MessageOfPickedProp.MappingID = pickedProp.MappingID;
  316. msg.MessageOfPickedProp.X = pickedProp.PropHasPicked.Position.x;
  317. msg.MessageOfPickedProp.Y = pickedProp.PropHasPicked.Position.y;
  318. msg.MessageOfPickedProp.FacingDirection = pickedProp.PropHasPicked.FacingDirection;
  319. switch (pickedProp.PropHasPicked.GetPropType())
  320. {
  321. case Preparation.Utility.PropType.Gem:
  322. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.Gem;
  323. break;
  324. case Preparation.Utility.PropType.addLIFE:
  325. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.AddLife;
  326. break;
  327. case Preparation.Utility.PropType.addSpeed:
  328. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.AddSpeed;
  329. break;
  330. case Preparation.Utility.PropType.Shield:
  331. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.Shield;
  332. break;
  333. case Preparation.Utility.PropType.Spear:
  334. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.Spear;
  335. break;
  336. default:
  337. msg.MessageOfPickedProp.Type = Communication.Proto.PropType.NullPropType;
  338. break;
  339. }
  340. return msg;
  341. }
  342. }
  343. }*/
  344. // 等Preparation完成再写