Advertisement
Guest User

Untitled

a guest
Jun 10th, 2020
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15.  
  16. package com.l2jrcore.gameserver.model.actor.instance;
  17.  
  18. import com.l2jrcore.gameserver.model.L2Character;
  19. import com.l2jrcore.gameserver.model.L2Object;
  20. import com.l2jrcore.gameserver.network.L2GameClient;
  21. import com.l2jrcore.gameserver.network.serverpackets.ActionFailed;
  22. import com.l2jrcore.gameserver.network.serverpackets.ExColosseumFenceInfoPacket;
  23. import com.l2jrcore.gameserver.network.serverpackets.MyTargetSelected;
  24.  
  25. public final class L2FenceInstance extends L2Object
  26. {
  27. private int _type;
  28. private int _width;
  29. private int _length;
  30. private final int _height;
  31. private int xMin;
  32. private int xMax;
  33. private int yMin;
  34. private int yMax;
  35.  
  36. public L2FenceInstance(int objectId, int type, int width, int length, int height, int x, int y)
  37. {
  38. super(objectId);
  39. _type = type;
  40. _width = width;
  41. _length = length;
  42. _height = height;
  43.  
  44. xMin = x - width / 2;
  45. xMax = x + width / 2;
  46. yMin = y - length / 2;
  47. yMax = y + length / 2;
  48. }
  49.  
  50. public boolean isBetween(int x, int y, int tx, int ty)
  51. {
  52. if (x < xMin && tx < xMin)
  53. return false;
  54.  
  55. if (x > xMax && tx > xMax)
  56. return false;
  57.  
  58. if (y < yMin && ty < yMin)
  59. return false;
  60.  
  61. if (y > yMax && ty > yMax)
  62. return false;
  63.  
  64. if (x > xMin && tx > xMin && x < xMax && tx < xMax && y > yMin && ty > yMin && y < yMax && ty < yMax)
  65. return false;
  66.  
  67. if (crossLinePart(xMin, yMin, xMax, yMin, x, y, tx, ty) || crossLinePart(xMax, yMin, xMax, yMax, x, y, tx, ty) || crossLinePart(xMax, yMax, xMin, yMax, x, y, tx, ty) || crossLinePart(xMin, yMax, xMin, yMin, x, y, tx, ty))
  68. return true;
  69.  
  70. return false;
  71. }
  72.  
  73. private boolean crossLinePart(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
  74. {
  75. float[] result = intersection(x1, y1, x2, y2, x3, y3, x4, y4);
  76.  
  77. if (result == null)
  78. return false;
  79.  
  80. float xCross = result[0];
  81. float yCross = result[1];
  82.  
  83. if (xCross <= xMax && xCross >= xMin || yCross <= yMax && yCross >= yMin)
  84. return true;
  85.  
  86. return false;
  87. }
  88.  
  89. private static float[] intersection(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
  90. {
  91. float d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
  92. if (d == 0)
  93. return null;
  94.  
  95. float xi = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d;
  96. float yi = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d;
  97.  
  98. float[] result = new float[2];
  99. result[0] = xi;
  100. result[1] = yi;
  101. return result;
  102. }
  103.  
  104. @Override
  105. public void sendInfo(L2PcInstance player)
  106. {
  107. player.sendPacket(new ExColosseumFenceInfoPacket(this));
  108. }
  109.  
  110.  
  111. public int getType()
  112. {
  113. return _type;
  114. }
  115.  
  116. public int getWidth()
  117. {
  118. return _width;
  119. }
  120.  
  121. public int getLength()
  122. {
  123. return _length;
  124. }
  125.  
  126. public int getHeight()
  127. {
  128. return _height;
  129. }
  130.  
  131. @Override
  132. public boolean isAutoAttackable(L2Character attacker)
  133. {
  134. return false;
  135. }
  136.  
  137. @Override
  138. public void onActionShift(L2GameClient client)
  139. {
  140. L2PcInstance player = client.getActiveChar();
  141. if (player == null)
  142. return;
  143.  
  144. if (player.isGM())
  145. {
  146. player.setTarget(this);
  147. MyTargetSelected my = new MyTargetSelected(getObjectId(), 0);
  148. player.sendPacket(my);
  149. }
  150. else
  151. player.sendPacket(ActionFailed.STATIC_PACKET);
  152. }
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement