ScrollOfEscape.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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 net.sf.l2j.gameserver.handler.itemhandlers;
  16. import net.sf.l2j.Config;
  17. import net.sf.l2j.gameserver.GameTimeController;
  18. import net.sf.l2j.gameserver.ThreadPoolManager;
  19. import net.sf.l2j.gameserver.ai.CtrlIntention;
  20. import net.sf.l2j.gameserver.datatables.MapRegionTable;
  21. import net.sf.l2j.gameserver.datatables.SkillTable;
  22. import net.sf.l2j.gameserver.handler.IItemHandler;
  23. import net.sf.l2j.gameserver.instancemanager.CastleManager;
  24. import net.sf.l2j.gameserver.instancemanager.ClanHallManager;
  25. import net.sf.l2j.gameserver.instancemanager.FortManager;
  26. import net.sf.l2j.gameserver.instancemanager.GrandBossManager;
  27. import net.sf.l2j.gameserver.model.L2ItemInstance;
  28. import net.sf.l2j.gameserver.model.L2Skill;
  29. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  30. import net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance;
  31. import net.sf.l2j.gameserver.model.entity.TvTEvent;
  32. import net.sf.l2j.gameserver.network.SystemMessageId;
  33. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  34. import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  35. import net.sf.l2j.gameserver.network.serverpackets.SetupGauge;
  36. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  37. /**
  38. * This class ...
  39. *
  40. * @version $Revision: 1.2.2.3.2.5 $ $Date: 2005/03/27 15:30:07 $
  41. */
  42. public class ScrollOfEscape implements IItemHandler
  43. {
  44. // all the items ids that this handler knowns
  45. private static final int[] ITEM_IDS =
  46. {
  47. 736, 1830, 1829, 1538, 3958, 5858,
  48. 5859, 7117, 7118, 7119, 7120, 7121,
  49. 7122, 7123, 7124, 7125, 7126, 7127,
  50. 7128, 7129, 7130, 7131, 7132, 7133,
  51. 7134, 7135, 7554, 7555, 7556, 7557,
  52. 7558, 7559, 7618, 7619, 9716, 10129,
  53. 10130, 10650
  54. };
  55. /**
  56. *
  57. * @see net.sf.l2j.gameserver.handler.IItemHandler#useItem(net.sf.l2j.gameserver.model.actor.instance.L2PlayableInstance, net.sf.l2j.gameserver.model.L2ItemInstance)
  58. */
  59. public void useItem(L2PlayableInstance playable, L2ItemInstance item)
  60. {
  61. if (!(playable instanceof L2PcInstance))
  62. return;
  63. L2PcInstance activeChar = (L2PcInstance) playable;
  64. // Thanks nbd
  65. if (!TvTEvent.onEscapeUse(activeChar.getObjectId()))
  66. {
  67. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  68. return;
  69. }
  70. if (activeChar.isMovementDisabled() || activeChar.isMuted() || activeChar.isAlikeDead() || activeChar.isAllSkillsDisabled())
  71. return;
  72. if (activeChar.isSitting())
  73. {
  74. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANT_MOVE_SITTING));
  75. return;
  76. }
  77. if (GrandBossManager.getInstance().getZone(activeChar) != null && !activeChar.isGM())
  78. {
  79. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  80. //activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_USE_SCROLL_OF_ESCAPE_INSIDE_BOSS_ZONE));
  81. // SystemMessage doesn't exist ??!
  82. activeChar.sendMessage("Cant summon target inside boss zone.");
  83. return;
  84. }
  85. if (activeChar.isInOlympiadMode())
  86. {
  87. activeChar.sendPacket(new SystemMessage(SystemMessageId.THIS_ITEM_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT));
  88. return;
  89. }
  90. // Check to see if the player is in a festival.
  91. if (activeChar.isFestivalParticipant())
  92. {
  93. activeChar.sendMessage("You may not use an escape skill in a festival.");
  94. return;
  95. }
  96. // Check to see if player is in jail
  97. if (activeChar.isInJail())
  98. {
  99. activeChar.sendMessage("You can not escape from jail.");
  100. return;
  101. }
  102. // Check to see if player is in a duel
  103. if (activeChar.isInDuel())
  104. {
  105. activeChar.sendMessage("You cannot use escape skills during a duel.");
  106. return;
  107. }
  108. //activeChar.abortCast();
  109. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  110. //SoE Animation section
  111. activeChar.setTarget(activeChar);
  112. // Modified by Tempy - 28 Jul 05 \\
  113. // Check if this is a blessed scroll, if it is then shorten the cast time.
  114. int itemId = item.getItemId();
  115. int escapeSkill = (itemId == 1538 || itemId == 5858 || itemId == 5859 || itemId == 3958 || itemId == 10130) ? 2036 : 2013;
  116. if (!activeChar.destroyItem("Consume", item.getObjectId(), 1, null, false))
  117. return;
  118. activeChar.disableAllSkills();
  119. L2Skill skill = SkillTable.getInstance().getInfo(escapeSkill, 1);
  120. MagicSkillUse msu = new MagicSkillUse(activeChar, escapeSkill, 1, skill.getHitTime(), 0);
  121. activeChar.broadcastPacket(msu);
  122. SetupGauge sg = new SetupGauge(0, skill.getHitTime());
  123. activeChar.sendPacket(sg);
  124. //End SoE Animation section
  125. SystemMessage sm = new SystemMessage(SystemMessageId.S1_DISAPPEARED);
  126. sm.addItemName(item);
  127. activeChar.sendPacket(sm);
  128. EscapeFinalizer ef = new EscapeFinalizer(activeChar, itemId);
  129. // continue execution later
  130. activeChar.setSkillCast(ThreadPoolManager.getInstance().scheduleEffect(ef, skill.getHitTime()));
  131. activeChar.setSkillCastEndTime(10 + GameTimeController.getGameTicks() + skill.getHitTime() / GameTimeController.MILLIS_IN_TICK);
  132. }
  133. static class EscapeFinalizer implements Runnable
  134. {
  135. private L2PcInstance _activeChar;
  136. private int _itemId;
  137. EscapeFinalizer(L2PcInstance activeChar, int itemId)
  138. {
  139. _activeChar = activeChar;
  140. _itemId = itemId;
  141. }
  142. public void run()
  143. {
  144. if (_activeChar.isDead())
  145. return;
  146. _activeChar.enableAllSkills();
  147. _activeChar.setIsIn7sDungeon(false);
  148. try
  149. {
  150. if ((_itemId == 1830 || _itemId == 5859) && CastleManager.getInstance().getCastleByOwner(_activeChar.getClan()) != null) // escape to castle if own's one
  151. {
  152. _activeChar.teleToLocation(MapRegionTable.TeleportWhereType.Castle);
  153. }
  154. else if ((_itemId == 10129 || _itemId == 10130) && FortManager.getInstance().getFortByOwner(_activeChar.getClan()) != null) // escape to fortress if own's one
  155. {
  156. _activeChar.teleToLocation(MapRegionTable.TeleportWhereType.Fortress);
  157. }
  158. else if ((_itemId == 1829 || _itemId == 5858) && _activeChar.getClan() != null && ClanHallManager.getInstance().getClanHallByOwner(_activeChar.getClan()) != null) // escape to clan hall if own's one
  159. {
  160. _activeChar.teleToLocation(MapRegionTable.TeleportWhereType.ClanHall);
  161. }
  162. else if (_itemId == 5858) // do nothing
  163. {
  164. //_activeChar.sendPacket(new SystemMessage(SystemMessageId.CLAN_HAS_NO_CLAN_HALL));
  165. _activeChar.sendMessage("Your clan does not own a clanhall.");
  166. return;
  167. }
  168. else if (_itemId == 5859) // do nothing
  169. {
  170. _activeChar.sendMessage("Your clan does not own a castle.");
  171. return;
  172. }
  173. else if (_itemId == 10130) // do nothing
  174. {
  175. _activeChar.sendMessage("Your clan does not own a fortress.");
  176. return;
  177. }
  178. else
  179. {
  180. if (_itemId < 7117)
  181. _activeChar.teleToLocation(MapRegionTable.TeleportWhereType.Town);
  182. else
  183. {
  184. switch (_itemId)
  185. {
  186. case 7117:
  187. _activeChar.teleToLocation(-84318, 244579, -3730, true); // Talking Island
  188. break;
  189. case 7554:
  190. _activeChar.teleToLocation(-84318, 244579, -3730, true); // Talking Island quest scroll
  191. break;
  192. case 7118:
  193. _activeChar.teleToLocation(46934, 51467, -2977, true); // Elven Village
  194. break;
  195. case 7555:
  196. _activeChar.teleToLocation(46934, 51467, -2977, true); // Elven Village quest scroll
  197. break;
  198. case 7119:
  199. _activeChar.teleToLocation(9745, 15606, -4574, true); // Dark Elven Village
  200. break;
  201. case 7556:
  202. _activeChar.teleToLocation(9745, 15606, -4574, true); // Dark Elven Village quest scroll
  203. break;
  204. case 7120:
  205. _activeChar.teleToLocation(-44836, -112524, -235, true); // Orc Village
  206. break;
  207. case 7557:
  208. _activeChar.teleToLocation(-44836, -112524, -235, true); // Orc Village quest scroll
  209. break;
  210. case 7121:
  211. _activeChar.teleToLocation(115113, -178212, -901, true); // Dwarven Village
  212. break;
  213. case 7558:
  214. _activeChar.teleToLocation(115113, -178212, -901, true); // Dwarven Village quest scroll
  215. break;
  216. case 7122:
  217. _activeChar.teleToLocation(-80826, 149775, -3043, true); // Gludin Village
  218. break;
  219. case 7123:
  220. _activeChar.teleToLocation(-12678, 122776, -3116, true); // Gludio Castle Town
  221. break;
  222. case 7124:
  223. _activeChar.teleToLocation(15670, 142983, -2705, true); // Dion Castle Town
  224. break;
  225. case 7125:
  226. _activeChar.teleToLocation(17836, 170178, -3507, true); // Floran
  227. break;
  228. case 7126:
  229. _activeChar.teleToLocation(83400, 147943, -3404, true); // Giran Castle Town
  230. break;
  231. case 7559:
  232. _activeChar.teleToLocation(83400, 147943, -3404, true); // Giran Castle Town quest scroll
  233. break;
  234. case 7127:
  235. _activeChar.teleToLocation(105918, 109759, -3207, true); // Hardin's Private Academy
  236. break;
  237. case 7128:
  238. _activeChar.teleToLocation(111409, 219364, -3545, true); // Heine
  239. break;
  240. case 7129:
  241. _activeChar.teleToLocation(82956, 53162, -1495, true); // Oren Castle Town
  242. break;
  243. case 7130:
  244. _activeChar.teleToLocation(85348, 16142, -3699, true); // Ivory Tower
  245. break;
  246. case 7131:
  247. _activeChar.teleToLocation(116819, 76994, -2714, true); // Hunters Village
  248. break;
  249. case 7132:
  250. _activeChar.teleToLocation(146331, 25762, -2018, true); // Aden Castle Town
  251. break;
  252. case 7133:
  253. _activeChar.teleToLocation(147928, -55273, -2734, true); // Goddard Castle Town
  254. break;
  255. case 7134:
  256. _activeChar.teleToLocation(43799, -47727, -798, true); // Rune Castle Town
  257. break;
  258. case 7135:
  259. _activeChar.teleToLocation(87331, -142842, -1317, true); // Schuttgart Castle Town
  260. break;
  261. case 7618:
  262. _activeChar.teleToLocation(149864, -81062, -5618, true); // Ketra Orc Village
  263. break;
  264. case 7619:
  265. _activeChar.teleToLocation(108275, -53785, -2524, true); // Varka Silenos Village
  266. break;
  267. case 9716:
  268. _activeChar.teleToLocation(-117251, 46771, 360, true); // Kamael Village
  269. break;
  270. default:
  271. _activeChar.teleToLocation(MapRegionTable.TeleportWhereType.Town);
  272. break;
  273. }
  274. }
  275. }
  276. }
  277. catch (Throwable e)
  278. {
  279. if (Config.DEBUG)
  280. e.printStackTrace();
  281. }
  282. }
  283. }
  284. /**
  285. *
  286. * @see net.sf.l2j.gameserver.handler.IItemHandler#getItemIds()
  287. */
  288. public int[] getItemIds()
  289. {
  290. return ITEM_IDS;
  291. }
  292. }