Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.17 KB | None | 0 0
  1. class Soccer
  2. {
  3. private RoomItem[] gates;
  4. private Room room;
  5. private List<RoomItem> balls;
  6.  
  7. public Soccer(Room room)
  8. {
  9. this.room = room;
  10. this.gates = new RoomItem[4];
  11. this.balls = new List<RoomItem>();
  12. }
  13.  
  14. internal void OnCycle()
  15. {
  16. // balls.OnCycle();
  17.  
  18. foreach (RoomItem ball in balls)
  19. {
  20. if (ball != null)
  21. {
  22. if (ball.ballIsMoving)
  23. {
  24. MoveBallProcess(ball);
  25. }
  26. }
  27. }
  28. }
  29. internal void AddBall(RoomItem item)
  30. {
  31. balls.Add( item);
  32. }
  33.  
  34. internal void RemoveBall(RoomItem itemID)
  35. {
  36. balls.Remove(itemID);
  37. }
  38.  
  39. internal void OnUserWalk(RoomUser User)
  40. {
  41. foreach (RoomItem ball in balls)
  42. {
  43. if (User == null)
  44. return;
  45.  
  46. if (ball == null)
  47. return;
  48.  
  49. if (User.SetX == ball.GetX && User.SetY == ball.GetY && User.GoalX == ball.GetX && User.GoalY == ball.GetY)
  50. {
  51. Point userPoint = new Point(User.X, User.Y);
  52. ball.ExtraData = "55";
  53. ball.ballIsMoving = true;
  54. ball._iBallValue = 1;
  55. MoveBall(ball, User.GetClient(), userPoint);
  56. }
  57. else if (User.X == ball.GetX && User.Y == ball.GetY)
  58. {
  59. Point userPoint = new Point(User.SetX, User.SetY);
  60. ball.ExtraData = "55";
  61. ball.ballIsMoving = true;
  62. ball._iBallValue = 1;
  63. MoveBall(ball, User.GetClient(), userPoint);
  64. }
  65. else
  66. {
  67. if (User.GoalX == ball.GetX && User.GoalY == ball.GetY)
  68. return;
  69.  
  70. if (User.SetX == ball.GetX && User.SetY == ball.GetY && User.IsWalking && (User.X != User.GoalX || User.Y != User.GoalY))
  71. {
  72. var _comeDirection = ComeDirection.GetComeDirection(new Point(User.X, User.Y), ball.Coordinate);
  73. if (_comeDirection != IComeDirection.Null)
  74. {
  75. int NewX = User.SetX;
  76. int NewY = User.SetY;
  77.  
  78. ComeDirection.GetNewCoords(_comeDirection, ref NewX, ref NewY);
  79. if (ball.GetRoom().GetGameMap().ValidTile(NewX, NewY))
  80. {
  81. ball.ExtraData = "11";
  82. MoveBall(ball, User.GetClient(), NewX, NewY);
  83. }
  84. }
  85. }
  86. }
  87. }
  88. }
  89.  
  90. internal void RegisterGate(RoomItem item)
  91. {
  92. if (gates[0] == null)
  93. {
  94. item.team = Team.blue;
  95. gates[0] = item;
  96. }
  97. else if (gates[1] == null)
  98. {
  99. item.team = Team.red;
  100. gates[1] = item;
  101. }
  102. else if (gates[2] == null)
  103. {
  104. item.team = Team.green;
  105. gates[2] = item;
  106. }
  107. else if (gates[3] == null)
  108. {
  109. item.team = Team.yellow;
  110. gates[3] = item;
  111. }
  112. }
  113.  
  114. internal void UnRegisterGate(RoomItem item)
  115. {
  116. switch (item.team)
  117. {
  118. case Team.blue:
  119. {
  120. gates[0] = null;
  121. break;
  122. }
  123. case Team.red:
  124. {
  125. gates[1] = null;
  126. break;
  127. }
  128. case Team.green:
  129. {
  130. gates[2] = null;
  131. break;
  132. }
  133. case Team.yellow:
  134. {
  135. gates[3] = null;
  136. break;
  137. }
  138. }
  139. }
  140.  
  141. internal void onGateRemove(RoomItem item)
  142. {
  143. switch (item.GetBaseItem().InteractionType)
  144. {
  145. case InteractionType.footballgoalred:
  146. case InteractionType.footballcounterred:
  147. {
  148.  
  149. room.GetGameManager().RemoveFurnitureFromTeam(item, Team.red);
  150. break;
  151. }
  152. case InteractionType.footballgoalgreen:
  153. case InteractionType.footballcountergreen:
  154. {
  155. room.GetGameManager().RemoveFurnitureFromTeam(item, Team.green);
  156. break;
  157. }
  158. case InteractionType.footballgoalblue:
  159. case InteractionType.footballcounterblue:
  160. {
  161. room.GetGameManager().RemoveFurnitureFromTeam(item, Team.blue);
  162. break;
  163. }
  164. case InteractionType.footballgoalyellow:
  165. case InteractionType.footballcounteryellow:
  166. {
  167. room.GetGameManager().RemoveFurnitureFromTeam(item, Team.yellow);
  168. break;
  169. }
  170. }
  171. }
  172.  
  173.  
  174. internal bool MoveBall(RoomItem item, GameClient mover, int newX, int newY)
  175. {
  176. if (item == null || item.GetBaseItem() == null)
  177. return false;
  178.  
  179. if (item.ballIsMoving)
  180. {
  181. if (item.ExtraData == "55" || item.ExtraData == "44")
  182. {
  183. int randomValue = new Random().Next(1, 7);
  184. if (randomValue != 5)
  185. {
  186. if (!room.GetGameMap().itemCanBePlacedHere(newX, newY))
  187. return false;
  188. }
  189. }
  190. }
  191. else
  192. {
  193. if (!room.GetGameMap().itemCanBePlacedHere(newX, newY))
  194. return false;
  195. }
  196.  
  197. Point oldRoomCoord = item.Coordinate;
  198. Double NewZ = room.GetGameMap().Model.SqFloorHeight[newX, newY];
  199.  
  200.  
  201. ServerMessage Message = new ServerMessage(95);
  202. Message.AppendUInt(item.Id);
  203. Message.AppendUInt(3508);
  204. Message.AppendInt32(item.Coordinate.X);
  205. Message.AppendInt32(item.Coordinate.Y);
  206. Message.AppendInt32(newX);
  207. Message.AppendInt32(newY);
  208. Message.AppendUInt(4);
  209. Message.AppendStringWithBreak(NewZ.ToString());
  210. Message.AppendStringWithBreak("H11");
  211. Message.AppendInt32(-1);
  212. Message.AppendInt32(0);
  213. room.SendMessage(Message);
  214.  
  215. ServerMessage mMessage = new ServerMessage();
  216. mMessage.Init(230); // Cf
  217. mMessage.AppendInt32(item.Coordinate.X);
  218. mMessage.AppendInt32(item.Coordinate.Y);
  219. mMessage.AppendInt32(newX);
  220. mMessage.AppendInt32(newY);
  221. mMessage.AppendInt32(1);
  222. mMessage.AppendUInt(item.Id);
  223. mMessage.AppendStringWithBreak(item.GetZ.ToString().Replace(',', '.'));
  224. mMessage.AppendStringWithBreak(NewZ.ToString().Replace(',', '.'));
  225. mMessage.AppendUInt(0);
  226. room.SendMessage(mMessage);
  227.  
  228. if (oldRoomCoord.X == newX && oldRoomCoord.Y == newY)
  229. return false;
  230.  
  231. item.SetState(newX, newY, item.GetZ, Gamemap.GetAffectedTiles(item.GetBaseItem().Length, item.GetBaseItem().Width, newX, newY, item.Rot));
  232.  
  233. return false;
  234. }
  235.  
  236.  
  237. internal void MoveBall(RoomItem item, GameClient client, Point user)
  238. {
  239. try
  240. {
  241. item.comeDirection = ComeDirection.GetComeDirection(user, item.Coordinate);
  242.  
  243. if (item.comeDirection != IComeDirection.Null)
  244. {
  245. // item.ballMover = client;
  246. MoveBallProcess(item);
  247. }
  248. }
  249. catch { }
  250. }
  251.  
  252. internal void MoveBallProcess(RoomItem item)
  253. {
  254. int tryes = 0;
  255. int newX = item.Coordinate.X;
  256. int newY = item.Coordinate.Y;
  257. int resetX;
  258. int resetY;
  259.  
  260. while (tryes < 3)
  261. {
  262. if (room == null)
  263. {
  264. if (room.GetGameMap() == null)
  265. {
  266. return;
  267. }
  268. }
  269.  
  270. //for (int i = 1; i < 7; i++)
  271. {
  272. if (item.comeDirection == IComeDirection.Null)
  273. {
  274. item.ballIsMoving = false;
  275. break;
  276. }
  277.  
  278. resetX = newX;
  279. resetY = newY;
  280.  
  281. ComeDirection.GetNewCoords(item.comeDirection, ref newX, ref newY);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement