MoveToLocationAirShip.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.network.clientpackets;
  20. import com.l2jserver.gameserver.ai.CtrlIntention;
  21. import com.l2jserver.gameserver.instancemanager.AirShipManager;
  22. import com.l2jserver.gameserver.model.L2World;
  23. import com.l2jserver.gameserver.model.Location;
  24. import com.l2jserver.gameserver.model.VehiclePathPoint;
  25. import com.l2jserver.gameserver.model.actor.instance.L2AirShipInstance;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.network.SystemMessageId;
  28. public class MoveToLocationAirShip extends L2GameClientPacket
  29. {
  30. private static final String _C__D0_38_MOVETOLOCATIONAIRSHIP = "[C] D0:38 MoveToLocationAirShip";
  31. public static final int MIN_Z = -895;
  32. public static final int MAX_Z = 6105;
  33. public static final int STEP = 300;
  34. private int _command;
  35. private int _param1;
  36. private int _param2 = 0;
  37. @Override
  38. protected void readImpl()
  39. {
  40. _command = readD();
  41. _param1 = readD();
  42. if (_buf.remaining() > 0)
  43. {
  44. _param2 = readD();
  45. }
  46. }
  47. @Override
  48. protected void runImpl()
  49. {
  50. final L2PcInstance activeChar = getClient().getActiveChar();
  51. if (activeChar == null)
  52. {
  53. return;
  54. }
  55. if (!activeChar.isInAirShip())
  56. {
  57. return;
  58. }
  59. final L2AirShipInstance ship = activeChar.getAirShip();
  60. if (!ship.isCaptain(activeChar))
  61. {
  62. return;
  63. }
  64. int z = ship.getZ();
  65. switch (_command)
  66. {
  67. case 0:
  68. if (!ship.canBeControlled())
  69. {
  70. return;
  71. }
  72. if (_param1 < L2World.GRACIA_MAX_X)
  73. {
  74. ship.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new Location(_param1, _param2, z));
  75. }
  76. break;
  77. case 1:
  78. if (!ship.canBeControlled())
  79. {
  80. return;
  81. }
  82. ship.getAI().setIntention(CtrlIntention.AI_INTENTION_ACTIVE);
  83. break;
  84. case 2:
  85. if (!ship.canBeControlled())
  86. {
  87. return;
  88. }
  89. if (z < L2World.GRACIA_MAX_Z)
  90. {
  91. z = Math.min(z + STEP, L2World.GRACIA_MAX_Z);
  92. ship.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new Location(ship.getX(), ship.getY(), z));
  93. }
  94. break;
  95. case 3:
  96. if (!ship.canBeControlled())
  97. {
  98. return;
  99. }
  100. if (z > L2World.GRACIA_MIN_Z)
  101. {
  102. z = Math.max(z - STEP, L2World.GRACIA_MIN_Z);
  103. ship.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new Location(ship.getX(), ship.getY(), z));
  104. }
  105. break;
  106. case 4:
  107. if (!ship.isInDock() || ship.isMoving())
  108. {
  109. return;
  110. }
  111. final VehiclePathPoint[] dst = AirShipManager.getInstance().getTeleportDestination(ship.getDockId(), _param1);
  112. if (dst == null)
  113. {
  114. return;
  115. }
  116. // Consume fuel, if needed
  117. final int fuelConsumption = AirShipManager.getInstance().getFuelConsumption(ship.getDockId(), _param1);
  118. if (fuelConsumption > 0)
  119. {
  120. if (fuelConsumption > ship.getFuel())
  121. {
  122. activeChar.sendPacket(SystemMessageId.THE_AIRSHIP_CANNOT_TELEPORT);
  123. return;
  124. }
  125. ship.setFuel(ship.getFuel() - fuelConsumption);
  126. }
  127. ship.executePath(dst);
  128. break;
  129. }
  130. }
  131. @Override
  132. public String getType()
  133. {
  134. return _C__D0_38_MOVETOLOCATIONAIRSHIP;
  135. }
  136. }