Advertisement
Guest User

Untitled

a guest
Sep 14th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1. package l2s.gameserver.network.l2.c2s;
  2.  
  3. import l2s.gameserver.data.BoatHolder;
  4. import l2s.gameserver.geodata.GeoEngine;
  5. import l2s.gameserver.model.Player;
  6. import l2s.gameserver.model.entity.boat.Boat;
  7. import l2s.gameserver.utils.Location;
  8.  
  9. public class ValidatePosition extends L2GameClientPacket
  10. {
  11. private final Location _loc = new Location();
  12.  
  13. private int _boatId;
  14. private Location _lastClientPosition;
  15. private Location _lastServerPosition;
  16.  
  17. /**
  18. * packet type id 0x48
  19. * format: cddddd
  20. */
  21. @Override
  22. protected void readImpl()
  23. {
  24. _loc.x = readD();
  25. _loc.y = readD();
  26. _loc.z = readD();
  27. _loc.h = readD();
  28. _boatId = readD();
  29. }
  30.  
  31. @Override
  32. protected void runImpl()
  33. {
  34. Player activeChar = getClient().getActiveChar();
  35. if(activeChar == null)
  36. return;
  37.  
  38. if(activeChar.isTeleporting() || activeChar.isInObserverMode())
  39. return;
  40.  
  41. _lastClientPosition = activeChar.getLastClientPosition();
  42. _lastServerPosition = activeChar.getLastServerPosition();
  43.  
  44. if(_lastClientPosition == null)
  45. _lastClientPosition = activeChar.getLoc();
  46. if(_lastServerPosition == null)
  47. _lastServerPosition = activeChar.getLoc();
  48.  
  49. if(activeChar.getX() == 0 && activeChar.getY() == 0 && activeChar.getZ() == 0)
  50. {
  51. correctPosition(activeChar);
  52. return;
  53. }
  54.  
  55. if(activeChar.isInFlyingTransform())
  56. {
  57. // Π’ Π»ΠµΡ‚Π°Ρ�Ρ‰ΠµΠΉ Ρ‚Ρ€Π°Π½Ρ�Ρ„ΠΎΡ€ΠΌΠµ Π½ΠµΠ»Ρ�Π·Ρ� Π½Π°Ρ…ΠΎΠ΄ΠΈΡ‚Ρ�Ρ�Ρ� Π½Π° Ρ‚ΠµΡ€Ρ€ΠΈΡ‚ΠΎΡ€ΠΈΠΈ Aden
  58. if(_loc.x > -166168)
  59. {
  60. activeChar.setTransform(null);
  61. return;
  62. }
  63.  
  64. // Π’ Π»ΠµΡ‚Π°Ρ�Ρ‰ΠµΠΉ Ρ‚Ρ€Π°Π½Ρ�Ρ„ΠΎΡ€ΠΌΠµ Π½ΠµΠ»Ρ�Π·Ρ� Π»ΠµΡ‚Π°Ρ‚Ρ� Π½ΠΈΠ¶Πµ, Ρ‡ΠµΠΌ 0, ΠΈ Π²Ρ‹Ρ�Πµ, Ρ‡ΠµΠΌ 6000
  65. if(_loc.z <= 0 || _loc.z >= 6000)
  66. {
  67. activeChar.teleToLocation(activeChar.getLoc().setZ(Math.min(5950, Math.max(50, _loc.z))));
  68. return;
  69. }
  70. }
  71.  
  72. double diff = activeChar.getDistance(_loc.x, _loc.y);
  73. int dz = Math.abs(_loc.z - activeChar.getZ());
  74. int h = _lastServerPosition.z - activeChar.getZ();
  75.  
  76. if(_boatId > 0)
  77. {
  78. Boat boat = BoatHolder.getInstance().getBoat(_boatId);
  79. if(boat != null && activeChar.getBoat() == boat)
  80. {
  81. activeChar.setHeading(_loc.h);
  82. boat.validateLocationPacket(activeChar);
  83. }
  84. activeChar.setLastClientPosition(_loc.setH(activeChar.getHeading()));
  85. activeChar.setLastServerPosition(activeChar.getLoc());
  86. return;
  87. }
  88.  
  89. // Π•Ρ�Π»ΠΈ ΠΌΡ‹ ΡƒΠ¶Πµ ΠΏΠ°Π΄Π°ΠµΠΌ, Ρ‚ΠΎ ΠΎΡ‚ΠΊΠ»Ρ�Ρ‡Π°ΠµΠΌ Π²Ρ�Πµ Π²Π°Π»ΠΈΠ΄ΠµΠΉΡ‚Ρ‹
  90. if(activeChar.isFalling())
  91. {
  92. diff = 0;
  93. dz = 0;
  94. h = 0;
  95. }
  96.  
  97. if(h > activeChar.getBaseStats().getSafeFallHeight()) // Π�ΠΎΠΊΠ° ΠΏΠ°Π΄Π°ΠµΠΌ, Π²Ρ‹Ρ�ΠΎΡ‚Ρƒ Π½Πµ ΠΊΠΎΡ€Ρ€ΠµΠΊΡ‚ΠΈΡ€ΡƒΠµΠΌ
  98. {
  99. activeChar.falling(h);
  100. }
  101. else if(dz >= (activeChar.isFlying() ? 1024 : 512))
  102. {
  103. if(activeChar.getIncorrectValidateCount() >= 3)
  104. activeChar.teleToClosestTown();
  105. else
  106. {
  107. activeChar.teleToLocation(activeChar.getLoc());
  108. activeChar.setIncorrectValidateCount(activeChar.getIncorrectValidateCount() + 1);
  109. }
  110. }
  111. else if(dz >= 256)
  112. {
  113. activeChar.validateLocation(0);
  114. }
  115. else if(_loc.z < -30000 || _loc.z > 30000)
  116. {
  117. if(activeChar.getIncorrectValidateCount() >= 3)
  118. activeChar.teleToClosestTown();
  119. else
  120. {
  121. correctPosition(activeChar);
  122. activeChar.setIncorrectValidateCount(activeChar.getIncorrectValidateCount() + 1);
  123. }
  124. }
  125. else if(diff > 1024)
  126. {
  127. if(activeChar.getIncorrectValidateCount() >= 3)
  128. activeChar.teleToClosestTown();
  129. else
  130. {
  131. activeChar.teleToLocation(activeChar.getLoc());
  132. activeChar.setIncorrectValidateCount(activeChar.getIncorrectValidateCount() + 1);
  133. }
  134. }
  135. else if(diff > 256)
  136. {
  137. //TODO Ρ€ΠµΠ°Π»ΠΈΠ·ΠΎΠ²Π°Ρ‚Ρ� NetPing ΠΈ Π²Ρ‹Ρ‡ΠΈΡ�Π»Ρ�Ρ‚Ρ� ΠΏΡ€ΠµΠ΄ΠµΠ»Ρ�Π½ΠΎΠµ ΠΎΡ‚ΠΊΠ»ΠΎΠ½ΠµΠ½ΠΈΠµ ΠΈΡ�Ρ…ΠΎΠ΄Ρ� ΠΈΠ· ΠΏΠΈΠ½Π³Π° ΠΏΠΎ Ρ„ΠΎΡ€ΠΌΡƒΠ»Πµ: 16 + (ping * activeChar.getMoveSpeed()) / 1000
  138. activeChar.validateLocation(1);
  139. }
  140. else
  141. activeChar.setIncorrectValidateCount(0);
  142.  
  143. activeChar.setLastClientPosition(_loc.setH(activeChar.getHeading()));
  144. activeChar.setLastServerPosition(activeChar.getLoc());
  145. }
  146.  
  147. private void correctPosition(Player activeChar)
  148. {
  149. if(activeChar.isGM())
  150. {
  151. activeChar.sendMessage("Server loc: " + activeChar.getLoc());
  152. activeChar.sendMessage("Correcting position...");
  153. }
  154. if(_lastServerPosition.x != 0 && _lastServerPosition.y != 0 && _lastServerPosition.z != 0)
  155. {
  156. if(GeoEngine.getNSWE(_lastServerPosition.x, _lastServerPosition.y, _lastServerPosition.z, activeChar.getGeoIndex()) == GeoEngine.NSWE_ALL)
  157. activeChar.teleToLocation(_lastServerPosition);
  158. else
  159. activeChar.teleToClosestTown();
  160. }
  161. else if(_lastClientPosition.x != 0 && _lastClientPosition.y != 0 && _lastClientPosition.z != 0)
  162. {
  163. if(GeoEngine.getNSWE(_lastClientPosition.x, _lastClientPosition.y, _lastClientPosition.z, activeChar.getGeoIndex()) == GeoEngine.NSWE_ALL)
  164. activeChar.teleToLocation(_lastClientPosition);
  165. else
  166. activeChar.teleToClosestTown();
  167. }
  168. else
  169. activeChar.teleToClosestTown();
  170. }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement