MoveToLocationAirShip.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. package com.l2jserver.gameserver.network.clientpackets;
  16. import com.l2jserver.gameserver.TaskPriority;
  17. import com.l2jserver.gameserver.ai.CtrlIntention;
  18. import com.l2jserver.gameserver.instancemanager.AirShipManager;
  19. import com.l2jserver.gameserver.model.L2CharPosition;
  20. import com.l2jserver.gameserver.model.L2World;
  21. import com.l2jserver.gameserver.model.VehiclePathPoint;
  22. import com.l2jserver.gameserver.model.actor.instance.L2AirShipInstance;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  26. public class MoveToLocationAirShip extends L2GameClientPacket
  27. {
  28. public static final int MIN_Z = -895;
  29. public static final int MAX_Z = 6105;
  30. public static final int STEP = 300;
  31. private static final String _C__D0_38_MOVETOLOCATIONAIRSHIP = "[C] D0:38 MoveToLocationAirShip";
  32. private int _command;
  33. private int _param1;
  34. private int _param2 = 0;
  35. public TaskPriority getPriority()
  36. {
  37. return TaskPriority.PR_HIGH;
  38. }
  39. @Override
  40. protected void readImpl()
  41. {
  42. _command = readD();
  43. _param1 = readD();
  44. if (_buf.remaining() > 0)
  45. _param2 = readD();
  46. }
  47. @Override
  48. protected void runImpl()
  49. {
  50. final L2PcInstance activeChar = getClient().getActiveChar();
  51. if (activeChar == null)
  52. return;
  53. if (!activeChar.isInAirShip())
  54. return;
  55. final L2AirShipInstance ship = activeChar.getAirShip();
  56. if (!ship.isCaptain(activeChar))
  57. return;
  58. int z = ship.getZ();
  59. switch (_command)
  60. {
  61. case 0:
  62. if (!ship.canBeControlled())
  63. return;
  64. if (_param1 < L2World.GRACIA_MAX_X)
  65. ship.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(_param1, _param2, z, 0));
  66. break;
  67. case 1:
  68. if (!ship.canBeControlled())
  69. return;
  70. ship.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  71. break;
  72. case 2:
  73. if (!ship.canBeControlled())
  74. return;
  75. if (z < L2World.GRACIA_MAX_Z)
  76. {
  77. z = Math.min(z + STEP, L2World.GRACIA_MAX_Z);
  78. ship.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(ship.getX(), ship.getY(), z, 0));
  79. }
  80. break;
  81. case 3:
  82. if (!ship.canBeControlled())
  83. return;
  84. if (z > L2World.GRACIA_MIN_Z)
  85. {
  86. z = Math.max(z - STEP, L2World.GRACIA_MIN_Z);
  87. ship.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(ship.getX(), ship.getY(), z, 0));
  88. }
  89. break;
  90. case 4:
  91. if (!ship.isInDock() || ship.isMoving())
  92. return;
  93. final VehiclePathPoint[] dst = AirShipManager.getInstance().getTeleportDestination(ship.getDockId(), _param1);
  94. if (dst == null)
  95. return;
  96. // Consume fuel, if needed
  97. final int fuelConsumption = AirShipManager.getInstance().getFuelConsumption(ship.getDockId(), _param1);
  98. if (fuelConsumption > 0)
  99. {
  100. if (fuelConsumption > ship.getFuel())
  101. {
  102. activeChar.sendPacket(new SystemMessage(SystemMessageId.THE_AIRSHIP_CANNOT_TELEPORT));
  103. return;
  104. }
  105. ship.setFuel(ship.getFuel() - fuelConsumption);
  106. }
  107. ship.executePath(dst);
  108. break;
  109. }
  110. }
  111. /* (non-Javadoc)
  112. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  113. */
  114. @Override
  115. public String getType()
  116. {
  117. return _C__D0_38_MOVETOLOCATIONAIRSHIP;
  118. }
  119. }