Chamber.java 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /*
  2. * Copyright (C) 2004-2014 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack 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 DataPack 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 instances.ChambersOfDelusion;
  20. import java.util.Calendar;
  21. import java.util.concurrent.ScheduledFuture;
  22. import java.util.logging.Level;
  23. import com.l2jserver.Config;
  24. import com.l2jserver.gameserver.ThreadPoolManager;
  25. import com.l2jserver.gameserver.ai.CtrlIntention;
  26. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  27. import com.l2jserver.gameserver.model.L2Object;
  28. import com.l2jserver.gameserver.model.L2Party;
  29. import com.l2jserver.gameserver.model.L2World;
  30. import com.l2jserver.gameserver.model.Location;
  31. import com.l2jserver.gameserver.model.actor.L2Npc;
  32. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  33. import com.l2jserver.gameserver.model.entity.Instance;
  34. import com.l2jserver.gameserver.model.holders.SkillHolder;
  35. import com.l2jserver.gameserver.model.instancezone.InstanceWorld;
  36. import com.l2jserver.gameserver.model.quest.Quest;
  37. import com.l2jserver.gameserver.model.quest.QuestState;
  38. import com.l2jserver.gameserver.model.skills.Skill;
  39. import com.l2jserver.gameserver.network.NpcStringId;
  40. import com.l2jserver.gameserver.network.SystemMessageId;
  41. import com.l2jserver.gameserver.network.clientpackets.Say2;
  42. import com.l2jserver.gameserver.network.serverpackets.Earthquake;
  43. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  44. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  45. import com.l2jserver.gameserver.util.Util;
  46. /**
  47. * Chambers of Delusion superclass.
  48. * @author GKR
  49. */
  50. public abstract class Chamber extends Quest
  51. {
  52. protected class CDWorld extends InstanceWorld
  53. {
  54. protected int currentRoom;
  55. protected final L2Party partyInside;
  56. protected final ScheduledFuture<?> _banishTask;
  57. protected ScheduledFuture<?> _roomChangeTask;
  58. protected CDWorld(L2Party party)
  59. {
  60. currentRoom = 0;
  61. partyInside = party;
  62. _banishTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new BanishTask(), 60000, 60000);
  63. }
  64. protected L2Party getPartyInside()
  65. {
  66. return partyInside;
  67. }
  68. protected void scheduleRoomChange(boolean bossRoom)
  69. {
  70. final Instance inst = InstanceManager.getInstance().getInstance(getInstanceId());
  71. final long nextInterval = bossRoom ? 60000L : (ROOM_CHANGE_INTERVAL + getRandom(ROOM_CHANGE_RANDOM_TIME)) * 1000L;
  72. // Schedule next room change only if remaining time is enough
  73. if ((inst.getInstanceEndTime() - System.currentTimeMillis()) > nextInterval)
  74. {
  75. _roomChangeTask = ThreadPoolManager.getInstance().scheduleGeneral(new ChangeRoomTask(), nextInterval - 5000);
  76. }
  77. }
  78. protected void stopBanishTask()
  79. {
  80. _banishTask.cancel(true);
  81. }
  82. protected void stopRoomChangeTask()
  83. {
  84. _roomChangeTask.cancel(true);
  85. }
  86. protected class BanishTask implements Runnable
  87. {
  88. @Override
  89. public void run()
  90. {
  91. final Instance inst = InstanceManager.getInstance().getInstance(getInstanceId());
  92. if ((inst == null) || ((inst.getInstanceEndTime() - System.currentTimeMillis()) < 60000))
  93. {
  94. _banishTask.cancel(false);
  95. }
  96. else
  97. {
  98. for (int objId : inst.getPlayers())
  99. {
  100. final L2PcInstance pl = L2World.getInstance().getPlayer(objId);
  101. if ((pl != null) && pl.isOnline())
  102. {
  103. if ((partyInside == null) || !pl.isInParty() || (partyInside != pl.getParty()))
  104. {
  105. exitInstance(pl);
  106. }
  107. }
  108. }
  109. }
  110. }
  111. }
  112. protected class ChangeRoomTask implements Runnable
  113. {
  114. @Override
  115. public void run()
  116. {
  117. try
  118. {
  119. earthQuake(CDWorld.this);
  120. Thread.sleep(5000);
  121. changeRoom(CDWorld.this);
  122. }
  123. catch (Exception e)
  124. {
  125. _log.log(Level.WARNING, getClass().getSimpleName() + " ChangeRoomTask exception : " + e.getMessage(), e);
  126. }
  127. }
  128. }
  129. }
  130. // Items
  131. private static final int ENRIA = 4042;
  132. private static final int ASOFE = 4043;
  133. private static final int THONS = 4044;
  134. private static final int LEONARD = 9628;
  135. private static final int DELUSION_MARK = 15311;
  136. // NPCs
  137. private final int ENTRANCE_GATEKEEPER;
  138. private final int ROOM_GATEKEEPER_FIRST;
  139. private final int ROOM_GATEKEEPER_LAST;
  140. private final int AENKINEL;
  141. private final int BOX;
  142. // Skills
  143. private static final SkillHolder SUCCESS_SKILL = new SkillHolder(5758, 1);
  144. private static final SkillHolder FAIL_SKILL = new SkillHolder(5376, 4);
  145. private static final int ROOM_CHANGE_INTERVAL = 480; // 8 min
  146. private static final int ROOM_CHANGE_RANDOM_TIME = 120; // 2 min
  147. // Instance restart time
  148. private static final int RESET_HOUR = 6;
  149. private static final int RESET_MIN = 30;
  150. // Following values vary between scripts
  151. private final int INSTANCEID;
  152. private final String INSTANCE_TEMPLATE;
  153. protected Location[] ROOM_ENTER_POINTS;
  154. protected Chamber(int questId, String name, String descr, int instanceId, String instanceTemplateName, int entranceGKId, int roomGKFirstId, int roomGKLastId, int aenkinelId, int boxId)
  155. {
  156. super(questId, name, descr);
  157. INSTANCEID = instanceId;
  158. INSTANCE_TEMPLATE = instanceTemplateName;
  159. ENTRANCE_GATEKEEPER = entranceGKId;
  160. ROOM_GATEKEEPER_FIRST = roomGKFirstId;
  161. ROOM_GATEKEEPER_LAST = roomGKLastId;
  162. AENKINEL = aenkinelId;
  163. BOX = boxId;
  164. addStartNpc(ENTRANCE_GATEKEEPER);
  165. addTalkId(ENTRANCE_GATEKEEPER);
  166. for (int i = ROOM_GATEKEEPER_FIRST; i <= ROOM_GATEKEEPER_LAST; i++)
  167. {
  168. addStartNpc(i);
  169. addTalkId(i);
  170. }
  171. addKillId(AENKINEL);
  172. addAttackId(BOX);
  173. addSpellFinishedId(BOX);
  174. addEventReceivedId(BOX);
  175. }
  176. private boolean isBigChamber()
  177. {
  178. return ((INSTANCEID == 131) || (INSTANCEID == 132));
  179. }
  180. private boolean isBossRoom(CDWorld world)
  181. {
  182. return (world.currentRoom == (ROOM_ENTER_POINTS.length - 1));
  183. }
  184. private boolean checkConditions(L2PcInstance player)
  185. {
  186. final L2Party party = player.getParty();
  187. if (party == null)
  188. {
  189. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.NOT_IN_PARTY_CANT_ENTER));
  190. return false;
  191. }
  192. if (party.getLeader() != player)
  193. {
  194. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ONLY_PARTY_LEADER_CAN_ENTER));
  195. return false;
  196. }
  197. for (L2PcInstance partyMember : party.getMembers())
  198. {
  199. if (partyMember.getLevel() < 80)
  200. {
  201. final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_LEVEL_REQUIREMENT_NOT_SUFFICIENT);
  202. sm.addPcName(partyMember);
  203. party.broadcastPacket(sm);
  204. return false;
  205. }
  206. if (!Util.checkIfInRange(1000, player, partyMember, true))
  207. {
  208. final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_LOCATION_THAT_CANNOT_BE_ENTERED);
  209. sm.addPcName(partyMember);
  210. party.broadcastPacket(sm);
  211. return false;
  212. }
  213. if (isBigChamber())
  214. {
  215. final long reentertime = InstanceManager.getInstance().getInstanceTime(partyMember.getObjectId(), INSTANCEID);
  216. if (System.currentTimeMillis() < reentertime)
  217. {
  218. final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_MAY_NOT_REENTER_YET);
  219. sm.addPcName(partyMember);
  220. party.broadcastPacket(sm);
  221. return false;
  222. }
  223. }
  224. }
  225. return true;
  226. }
  227. private void markRestriction(InstanceWorld world)
  228. {
  229. if (world instanceof CDWorld)
  230. {
  231. final Calendar reenter = Calendar.getInstance();
  232. final Calendar now = Calendar.getInstance();
  233. reenter.set(Calendar.MINUTE, RESET_MIN);
  234. reenter.set(Calendar.HOUR_OF_DAY, RESET_HOUR);
  235. if (reenter.before(now))
  236. {
  237. reenter.add(Calendar.DAY_OF_WEEK, 1);
  238. }
  239. final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.INSTANT_ZONE_S1_RESTRICTED);
  240. sm.addString(InstanceManager.getInstance().getInstanceIdName(world.getTemplateId()));
  241. // set instance reenter time for all allowed players
  242. for (int objectId : world.getAllowed())
  243. {
  244. final L2PcInstance player = L2World.getInstance().getPlayer(objectId);
  245. if ((player != null) && player.isOnline())
  246. {
  247. InstanceManager.getInstance().setInstanceTime(objectId, world.getTemplateId(), reenter.getTimeInMillis());
  248. player.sendPacket(sm);
  249. }
  250. }
  251. }
  252. }
  253. protected void changeRoom(CDWorld world)
  254. {
  255. final L2Party party = world.getPartyInside();
  256. final Instance inst = InstanceManager.getInstance().getInstance(world.getInstanceId());
  257. if ((party == null) || (inst == null))
  258. {
  259. return;
  260. }
  261. int newRoom = world.currentRoom;
  262. // Do nothing, if there are raid room of Sqare or Tower Chamber
  263. if (isBigChamber() && isBossRoom(world))
  264. {
  265. return;
  266. }
  267. // Teleport to raid room 10 min or lesser before instance end time for Tower and Square Chambers
  268. else if (isBigChamber() && ((inst.getInstanceEndTime() - System.currentTimeMillis()) < 600000))
  269. {
  270. newRoom = ROOM_ENTER_POINTS.length - 1;
  271. }
  272. // 10% chance for teleport to raid room if not here already for Northern, Southern, Western and Eastern Chambers
  273. else if (!isBigChamber() && !isBossRoom(world) && (getRandom(100) < 10))
  274. {
  275. newRoom = ROOM_ENTER_POINTS.length - 1;
  276. }
  277. else
  278. {
  279. while (newRoom == world.currentRoom) // otherwise teleport to another room, except current
  280. {
  281. newRoom = getRandom(ROOM_ENTER_POINTS.length - 1);
  282. }
  283. }
  284. for (L2PcInstance partyMember : party.getMembers())
  285. {
  286. if (world.getInstanceId() == partyMember.getInstanceId())
  287. {
  288. partyMember.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  289. partyMember.teleToLocation(ROOM_ENTER_POINTS[newRoom], true);
  290. }
  291. }
  292. world.currentRoom = newRoom;
  293. // Do not schedule room change for Square and Tower Chambers, if raid room is reached
  294. if (isBigChamber() && isBossRoom(world))
  295. {
  296. inst.setDuration((int) ((inst.getInstanceEndTime() - System.currentTimeMillis()) + 1200000)); // Add 20 min to instance time if raid room is reached
  297. for (L2Npc npc : inst.getNpcs())
  298. {
  299. if (npc.getId() == ROOM_GATEKEEPER_LAST)
  300. {
  301. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npc.getId(), NpcStringId.N21_MINUTES_ARE_ADDED_TO_THE_REMAINING_TIME_IN_THE_INSTANT_ZONE));
  302. }
  303. }
  304. }
  305. else
  306. {
  307. world.scheduleRoomChange(false);
  308. }
  309. }
  310. private void enter(CDWorld world)
  311. {
  312. final L2Party party = world.getPartyInside();
  313. if (party == null)
  314. {
  315. return;
  316. }
  317. for (L2PcInstance partyMember : party.getMembers())
  318. {
  319. final QuestState st = getQuestState(partyMember, true);
  320. if (st.hasQuestItems(DELUSION_MARK))
  321. {
  322. st.takeItems(DELUSION_MARK, -1);
  323. }
  324. if (party.isLeader(partyMember))
  325. {
  326. st.giveItems(DELUSION_MARK, 1);
  327. }
  328. // Save location for teleport back into main hall
  329. st.set("return_point", Integer.toString(partyMember.getX()) + ";" + Integer.toString(partyMember.getY()) + ";" + Integer.toString(partyMember.getZ()));
  330. partyMember.setInstanceId(world.getInstanceId());
  331. world.addAllowed(partyMember.getObjectId());
  332. }
  333. changeRoom(world);
  334. }
  335. protected void earthQuake(CDWorld world)
  336. {
  337. final L2Party party = world.getPartyInside();
  338. if (party == null)
  339. {
  340. return;
  341. }
  342. for (L2PcInstance partyMember : party.getMembers())
  343. {
  344. if (world.getInstanceId() == partyMember.getInstanceId())
  345. {
  346. partyMember.sendPacket(new Earthquake(partyMember.getX(), partyMember.getY(), partyMember.getZ(), 20, 10));
  347. }
  348. }
  349. }
  350. protected int enterInstance(L2PcInstance player)
  351. {
  352. int instanceId = 0;
  353. // check for existing instances for this player
  354. InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  355. // existing instance
  356. if (world != null)
  357. {
  358. if (!(world instanceof CDWorld))
  359. {
  360. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER));
  361. return 0;
  362. }
  363. final CDWorld currentWorld = (CDWorld) world;
  364. teleportPlayer(player, ROOM_ENTER_POINTS[currentWorld.currentRoom], world.getInstanceId());
  365. return instanceId;
  366. }
  367. // New instance
  368. if (!checkConditions(player))
  369. {
  370. return 0;
  371. }
  372. final L2Party party = player.getParty();
  373. instanceId = InstanceManager.getInstance().createDynamicInstance(INSTANCE_TEMPLATE);
  374. world = new CDWorld(party);
  375. world.setInstanceId(instanceId);
  376. world.setTemplateId(INSTANCEID);
  377. world.setStatus(0);
  378. InstanceManager.getInstance().addWorld(world);
  379. _log.info("Chamber Of Delusion started " + INSTANCE_TEMPLATE + " Instance: " + instanceId + " created by player: " + player.getName());
  380. enter((CDWorld) world);
  381. return instanceId;
  382. }
  383. protected void exitInstance(L2PcInstance player)
  384. {
  385. if ((player == null) || !player.isOnline() || (player.getInstanceId() == 0))
  386. {
  387. return;
  388. }
  389. final Instance inst = InstanceManager.getInstance().getInstance(player.getInstanceId());
  390. Location ret = inst.getSpawnLoc();
  391. final QuestState st = getQuestState(player, false);
  392. if (st != null)
  393. {
  394. String return_point = st.get("return_point");
  395. if (return_point != null)
  396. {
  397. String[] coords = return_point.split(";");
  398. if (coords.length == 3)
  399. {
  400. try
  401. {
  402. int x = Integer.parseInt(coords[0]);
  403. int y = Integer.parseInt(coords[1]);
  404. int z = Integer.parseInt(coords[2]);
  405. ret.setLocation(new Location(x, y, z));
  406. }
  407. catch (Exception e)
  408. {
  409. }
  410. }
  411. }
  412. }
  413. teleportPlayer(player, ret, 0);
  414. final InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  415. if (world != null)
  416. {
  417. world.removeAllowed((player.getObjectId()));
  418. }
  419. }
  420. @Override
  421. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  422. {
  423. String htmltext = "";
  424. final InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  425. if ((player != null) && (tmpworld != null) && (tmpworld instanceof CDWorld) && (npc.getId() >= ROOM_GATEKEEPER_FIRST) && (npc.getId() <= ROOM_GATEKEEPER_LAST))
  426. {
  427. final CDWorld world = (CDWorld) tmpworld;
  428. QuestState st = getQuestState(player, false);
  429. if (st == null)
  430. {
  431. st = newQuestState(player);
  432. }
  433. // Change room from dialog
  434. else if (event.equals("next_room"))
  435. {
  436. if (player.getParty() == null)
  437. {
  438. htmltext = getHtm(player.getHtmlPrefix(), "data/scripts/instances/ChambersOfDelusion/no_party.html");
  439. }
  440. else if (player.getParty().getLeaderObjectId() != player.getObjectId())
  441. {
  442. htmltext = getHtm(player.getHtmlPrefix(), "data/scripts/instances/ChambersOfDelusion/no_leader.html");
  443. }
  444. else if (hasQuestItems(player, DELUSION_MARK))
  445. {
  446. st.takeItems(DELUSION_MARK, 1);
  447. world.stopRoomChangeTask();
  448. changeRoom(world);
  449. }
  450. else
  451. {
  452. htmltext = getHtm(player.getHtmlPrefix(), "data/scripts/instances/ChambersOfDelusion/no_item.html");
  453. }
  454. }
  455. else if (event.equals("go_out"))
  456. {
  457. if (player.getParty() == null)
  458. {
  459. htmltext = getHtm(player.getHtmlPrefix(), "data/scripts/instances/ChambersOfDelusion/no_party.html");
  460. }
  461. else if (player.getParty().getLeaderObjectId() != player.getObjectId())
  462. {
  463. htmltext = getHtm(player.getHtmlPrefix(), "data/scripts/instances/ChambersOfDelusion/no_leader.html");
  464. }
  465. else
  466. {
  467. final Instance inst = InstanceManager.getInstance().getInstance(world.getInstanceId());
  468. world.stopRoomChangeTask();
  469. world.stopBanishTask();
  470. for (L2PcInstance partyMember : player.getParty().getMembers())
  471. {
  472. exitInstance(partyMember);
  473. }
  474. inst.setEmptyDestroyTime(0);
  475. }
  476. }
  477. else if (event.equals("look_party"))
  478. {
  479. if ((player.getParty() != null) && (player.getParty() == world.getPartyInside()))
  480. {
  481. player.teleToLocation(ROOM_ENTER_POINTS[world.currentRoom], false);
  482. }
  483. }
  484. }
  485. return htmltext;
  486. }
  487. @Override
  488. public String onAttack(final L2Npc npc, final L2PcInstance attacker, final int damage, final boolean isPet, final Skill skill)
  489. {
  490. if (!npc.isBusy() && (npc.getCurrentHp() < (npc.getMaxHp() / 10)))
  491. {
  492. npc.setBusy(true);
  493. if (getRandom(100) < 25) // 25% chance to reward
  494. {
  495. if (getRandom(100) < 33)
  496. {
  497. npc.dropItem(attacker, ENRIA, (int) (3 * Config.RATE_QUEST_DROP));
  498. }
  499. if (getRandom(100) < 50)
  500. {
  501. npc.dropItem(attacker, THONS, (int) (4 * Config.RATE_QUEST_DROP));
  502. }
  503. if (getRandom(100) < 50)
  504. {
  505. npc.dropItem(attacker, ASOFE, (int) (4 * Config.RATE_QUEST_DROP));
  506. }
  507. if (getRandom(100) < 16)
  508. {
  509. npc.dropItem(attacker, LEONARD, (int) (2 * Config.RATE_QUEST_DROP));
  510. }
  511. npc.broadcastEvent("SCE_LUCKY", 2000, null);
  512. npc.doCast(SUCCESS_SKILL.getSkill());
  513. }
  514. else
  515. {
  516. npc.broadcastEvent("SCE_DREAM_FIRE_IN_THE_HOLE", 2000, null);
  517. }
  518. }
  519. return super.onAttack(npc, attacker, damage, isPet, skill);
  520. }
  521. @Override
  522. public String onEventReceived(String eventName, L2Npc sender, L2Npc receiver, L2Object reference)
  523. {
  524. switch (eventName)
  525. {
  526. case "SCE_LUCKY":
  527. receiver.setBusy(true);
  528. receiver.doCast(SUCCESS_SKILL.getSkill());
  529. break;
  530. case "SCE_DREAM_FIRE_IN_THE_HOLE":
  531. receiver.setBusy(true);
  532. receiver.doCast(FAIL_SKILL.getSkill());
  533. break;
  534. }
  535. return null;
  536. }
  537. @Override
  538. public String onKill(L2Npc npc, L2PcInstance player, boolean isPet)
  539. {
  540. final InstanceWorld tmpworld = InstanceManager.getInstance().getPlayerWorld(player);
  541. if ((tmpworld != null) && (tmpworld instanceof CDWorld))
  542. {
  543. final CDWorld world = (CDWorld) tmpworld;
  544. final Instance inst = InstanceManager.getInstance().getInstance(world.getInstanceId());
  545. if (isBigChamber())
  546. {
  547. markRestriction(world); // Set reenter restriction
  548. if ((inst.getInstanceEndTime() - System.currentTimeMillis()) > 300000)
  549. {
  550. inst.setDuration(300000); // Finish instance in 5 minutes
  551. }
  552. }
  553. else
  554. {
  555. world.stopRoomChangeTask();
  556. world.scheduleRoomChange(true);
  557. }
  558. inst.spawnGroup("boxes");
  559. }
  560. return super.onKill(npc, player, isPet);
  561. }
  562. @Override
  563. public String onSpellFinished(L2Npc npc, L2PcInstance player, Skill skill)
  564. {
  565. if ((npc.getId() == BOX) && ((skill.getId() == 5376) || (skill.getId() == 5758)) && !npc.isDead())
  566. {
  567. npc.doDie(player);
  568. }
  569. return super.onSpellFinished(npc, player, skill);
  570. }
  571. @Override
  572. public String onTalk(L2Npc npc, L2PcInstance player)
  573. {
  574. int npcId = npc.getId();
  575. QuestState st = getQuestState(player, false);
  576. if (st == null)
  577. {
  578. st = newQuestState(player);
  579. }
  580. if (npcId == ENTRANCE_GATEKEEPER)
  581. {
  582. enterInstance(player);
  583. }
  584. return "";
  585. }
  586. }