Guest User

Untitled

a guest
Oct 1st, 2016
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.40 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.l2jfrozen.gameserver.model.actor.instance;
  17.  
  18. import com.l2jfrozen.gameserver.model.L2Character;
  19. import com.l2jfrozen.gameserver.model.L2Object;
  20. import com.l2jfrozen.gameserver.network.L2GameClient;
  21. import com.l2jfrozen.gameserver.network.serverpackets.ActionFailed;
  22. import com.l2jfrozen.gameserver.network.serverpackets.ExColosseumFenceInfoPacket;
  23. import com.l2jfrozen.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 int xMin;
  31. private int xMax;
  32. private int yMin;
  33. private int yMax;
  34.  
  35. public L2FenceInstance(int objectId, int type, int width, int length, int x, int y)
  36. {
  37. super(objectId);
  38. _type = type;
  39. _width = width;
  40. _length = length;
  41.  
  42. xMin = x - width / 2;
  43. xMax = x + width / 2;
  44. yMin = y - length / 2;
  45. yMax = y + length / 2;
  46. }
  47.  
  48. public boolean isBetween(int x, int y, int tx, int ty)
  49. {
  50. if (x < xMin && tx < xMin)
  51. return false;
  52.  
  53. if (x > xMax && tx > xMax)
  54. return false;
  55.  
  56. if (y < yMin && ty < yMin)
  57. return false;
  58.  
  59. if (y > yMax && ty > yMax)
  60. return false;
  61.  
  62. if (x > xMin && tx > xMin && x < xMax && tx < xMax && y > yMin && ty > yMin && y < yMax && ty < yMax)
  63. return false;
  64.  
  65. 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))
  66. return true;
  67.  
  68. return false;
  69. }
  70.  
  71. private boolean crossLinePart(int x1, int y1, int x2, int y2, int x3, int y3, int x4, int y4)
  72. {
  73. float[] result = intersection(x1, y1, x2, y2, x3, y3, x4, y4);
  74.  
  75. if (result == null)
  76. return false;
  77.  
  78. float xCross = result[0];
  79. float yCross = result[1];
  80.  
  81. if (xCross <= xMax && xCross >= xMin || yCross <= yMax && yCross >= yMin)
  82. return true;
  83.  
  84. return false;
  85. }
  86.  
  87. private static float[] intersection(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
  88. {
  89. float d = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4);
  90. if (d == 0)
  91. return null;
  92.  
  93. float xi = ((x3 - x4) * (x1 * y2 - y1 * x2) - (x1 - x2) * (x3 * y4 - y3 * x4)) / d;
  94. float yi = ((y3 - y4) * (x1 * y2 - y1 * x2) - (y1 - y2) * (x3 * y4 - y3 * x4)) / d;
  95.  
  96. float[] result = new float[2];
  97. result[0] = xi;
  98. result[1] = yi;
  99. return result;
  100. }
  101.  
  102. @Override
  103. public void sendInfo(L2PcInstance activeChar)
  104. {
  105. activeChar.sendPacket(new ExColosseumFenceInfoPacket(this));
  106. }
  107.  
  108. public int getType()
  109. {
  110. return _type;
  111. }
  112.  
  113. public int getWidth()
  114. {
  115. return _width;
  116. }
  117.  
  118. public int getLength()
  119. {
  120. return _length;
  121. }
  122.  
  123. @Override
  124. public boolean isAutoAttackable(L2Character attacker)
  125. {
  126. return false;
  127. }
  128.  
  129. @Override
  130. public void onActionShift(L2GameClient client)
  131. {
  132. L2PcInstance player = client.getActiveChar();
  133. if (player == null)
  134. return;
  135.  
  136. if (player.isGM())
  137. {
  138. player.setTarget(this);
  139. MyTargetSelected my = new MyTargetSelected(getObjectId(), 0);
  140. player.sendPacket(my);
  141. }
  142. else
  143. player.sendPacket(ActionFailed.STATIC_PACKET);
  144. }
  145. }
Advertisement
Add Comment
Please, Sign In to add comment