L2SkillTeleport.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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.skills.l2skills;
  16. import java.util.logging.Level;
  17. import com.l2jserver.gameserver.datatables.MapRegionTable;
  18. import com.l2jserver.gameserver.instancemanager.GrandBossManager;
  19. import com.l2jserver.gameserver.model.L2Object;
  20. import com.l2jserver.gameserver.model.L2Skill;
  21. import com.l2jserver.gameserver.model.Location;
  22. import com.l2jserver.gameserver.model.actor.L2Character;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.model.entity.TvTEvent;
  25. import com.l2jserver.gameserver.network.SystemMessageId;
  26. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  27. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  28. import com.l2jserver.gameserver.templates.StatsSet;
  29. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  30. public class L2SkillTeleport extends L2Skill
  31. {
  32. private final String _recallType;
  33. private final Location _loc;
  34. public L2SkillTeleport(StatsSet set)
  35. {
  36. super(set);
  37. _recallType = set.getString("recallType", "");
  38. String coords = set.getString("teleCoords", null);
  39. if (coords != null)
  40. {
  41. String[] valuesSplit = coords.split(",");
  42. _loc = new Location(Integer.parseInt(valuesSplit[0]),
  43. Integer.parseInt(valuesSplit[1]),
  44. Integer.parseInt(valuesSplit[2]));
  45. }
  46. else
  47. _loc = null;
  48. }
  49. @Override
  50. public void useSkill(L2Character activeChar, L2Object[] targets)
  51. {
  52. if (activeChar instanceof L2PcInstance)
  53. {
  54. // Thanks nbd
  55. if (!TvTEvent.onEscapeUse(((L2PcInstance) activeChar).getObjectId()))
  56. {
  57. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  58. return;
  59. }
  60. if (activeChar.isAfraid())
  61. {
  62. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  63. return;
  64. }
  65. if (((L2PcInstance)activeChar).isCombatFlagEquipped())
  66. {
  67. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  68. return;
  69. }
  70. if (((L2PcInstance) activeChar).isInOlympiadMode())
  71. {
  72. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.THIS_ITEM_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT));
  73. return;
  74. }
  75. if (GrandBossManager.getInstance().getZone(activeChar) != null && !activeChar.isGM())
  76. {
  77. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.YOU_MAY_NOT_SUMMON_FROM_YOUR_CURRENT_LOCATION));
  78. return;
  79. }
  80. }
  81. try
  82. {
  83. for (L2Character target: (L2Character[]) targets)
  84. {
  85. if (target instanceof L2PcInstance)
  86. {
  87. L2PcInstance targetChar = (L2PcInstance) target;
  88. // Check to see if the current player target is in a festival.
  89. if (targetChar.isFestivalParticipant())
  90. {
  91. targetChar.sendMessage("You may not use an escape skill in a festival.");
  92. continue;
  93. }
  94. // Check to see if player is in jail
  95. if (targetChar.isInJail())
  96. {
  97. targetChar.sendMessage("You can not escape from jail.");
  98. continue;
  99. }
  100. // Check to see if player is in a duel
  101. if (targetChar.isInDuel())
  102. {
  103. targetChar.sendMessage("You cannot use escape skills during a duel.");
  104. continue;
  105. }
  106. if (targetChar != activeChar)
  107. {
  108. if (!TvTEvent.onEscapeUse(targetChar.getObjectId()))
  109. continue;
  110. if (targetChar.isInOlympiadMode())
  111. continue;
  112. if (GrandBossManager.getInstance().getZone(targetChar) != null)
  113. continue;
  114. if (targetChar.isCombatFlagEquipped())
  115. continue;
  116. }
  117. }
  118. Location loc = null;
  119. if (getSkillType() == L2SkillType.TELEPORT)
  120. {
  121. if (_loc != null)
  122. {
  123. // target is not player OR player is not flying or flymounted
  124. // TODO: add check for gracia continent coords
  125. if (!(target instanceof L2PcInstance)
  126. || !(target.isFlying() || ((L2PcInstance)target).isFlyingMounted()))
  127. loc = _loc;
  128. }
  129. }
  130. else
  131. {
  132. if (_recallType.equalsIgnoreCase("Castle"))
  133. loc = MapRegionTable.getInstance().getTeleToLocation(target, MapRegionTable.TeleportWhereType.Castle);
  134. else if (_recallType.equalsIgnoreCase("ClanHall"))
  135. loc = MapRegionTable.getInstance().getTeleToLocation(target, MapRegionTable.TeleportWhereType.ClanHall);
  136. else if (_recallType.equalsIgnoreCase("Fortress"))
  137. loc = MapRegionTable.getInstance().getTeleToLocation(target, MapRegionTable.TeleportWhereType.Fortress);
  138. else
  139. loc = MapRegionTable.getInstance().getTeleToLocation(target, MapRegionTable.TeleportWhereType.Town);
  140. }
  141. if (loc != null)
  142. {
  143. target.setInstanceId(0);
  144. if (target instanceof L2PcInstance)
  145. ((L2PcInstance)target).setIsIn7sDungeon(false);
  146. target.teleToLocation(loc, true);
  147. }
  148. }
  149. }
  150. catch (Exception e)
  151. {
  152. _log.log(Level.SEVERE, "", e);
  153. }
  154. }
  155. }