Advertisement
tedlol

error

Aug 31st, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.51 KB | None | 0 0
  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 quests.Q727_HopeWithinTheDarkness;
  16.  
  17. import com.l2jserver.gameserver.ai.CtrlIntention;
  18. import com.l2jserver.gameserver.ThreadPoolManager;
  19. import com.l2jserver.gameserver.instancemanager.FortManager;
  20. import com.l2jserver.gameserver.instancemanager.GlobalVariablesManager;
  21. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  22. import com.l2jserver.gameserver.instancemanager.InstanceManager.InstanceWorld;
  23. import com.l2jserver.gameserver.model.L2Party;
  24. import com.l2jserver.gameserver.model.Location;
  25. import com.l2jserver.gameserver.model.actor.L2Attackable;
  26. import com.l2jserver.gameserver.model.actor.L2Character;
  27. import com.l2jserver.gameserver.model.actor.L2Npc;
  28. import com.l2jserver.gameserver.model.actor.L2Playable;
  29. import com.l2jserver.gameserver.model.actor.instance.L2QuestGuardInstance;
  30. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  31. import com.l2jserver.gameserver.model.entity.Castle;
  32. import com.l2jserver.gameserver.model.entity.Fort;
  33. import com.l2jserver.gameserver.model.entity.Instance;
  34. import com.l2jserver.gameserver.model.quest.Quest;
  35. import com.l2jserver.gameserver.model.quest.QuestState;
  36. import com.l2jserver.gameserver.model.quest.State;
  37. import com.l2jserver.gameserver.network.NpcStringId;
  38. import com.l2jserver.gameserver.network.SystemMessageId;
  39. import com.l2jserver.gameserver.network.clientpackets.Say2;
  40. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  41. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  42. import com.l2jserver.gameserver.model.holders.SkillHolder;
  43. import com.l2jserver.gameserver.util.Util;
  44. //import com.l2jserver.util.Rnd;
  45.  
  46. //import java.lang.Math;
  47. import java.util.Arrays;
  48. import java.util.Collection;
  49. import java.util.HashMap;
  50. import java.util.Map;
  51. import javolution.util.FastMap;
  52.  
  53. public final class Q727_HopeWithinTheDarkness extends Quest
  54. {
  55.  
  56. private class CAUWorld extends InstanceWorld
  57. {
  58. public boolean underAttack = false;
  59. public boolean allMonstersDead = true;
  60. }
  61.  
  62. public static class CastleDungeon
  63. {
  64. private final int INSTANCEID;
  65. private final int _wardenId;
  66.  
  67. public CastleDungeon(int iId, int wardenId)
  68. {
  69. INSTANCEID = iId;
  70. _wardenId = wardenId;
  71. }
  72.  
  73. public int getInstanceId()
  74. {
  75. return INSTANCEID;
  76. }
  77.  
  78. public long getReEnterTime()
  79. {
  80. String tmp = GlobalVariablesManager.getInstance().getStoredVariable ("Castle_dungeon_" + Integer.toString(_wardenId));
  81.  
  82. return tmp == null ? 0 : Long.parseLong(tmp);
  83. }
  84.  
  85. public void setReEnterTime(long time)
  86. {
  87. GlobalVariablesManager.getInstance().storeVariable("Castle_dungeon_" + Integer.toString(_wardenId), Long.toString(time));
  88. }
  89. }
  90.  
  91. private static final String qn = "727_HopeWithinTheDarkness";
  92. private static final boolean debug = false;
  93. private static final boolean CHECK_FOR_CONTRACT = false;
  94. private static final long REENTER_INTERVAL = 14400000;
  95. private static final long INITIAL_SPAWN_DELAY = 120000; //Spawn NPC's and 1'st Wave bosses (2 min)
  96. private static final long WAVE_SPAWN_DELAY = 480000; //Spawn next wave's bosses (8 min)
  97. private static final long PRIVATE_SPAWN_DELAY = 180000; //Spawn monsters (3 min after boss had been spawned)
  98.  
  99. private Map<Integer, CastleDungeon> _castleDungeons = new HashMap<>(21);
  100.  
  101. // REWARDS
  102. private static final int KNIGHT_EPALUETTE = 9912;
  103.  
  104. //NPC's
  105. private static final int NPC_KNIGHT = 36562;
  106. private static final int NPC_RANGER = 36563;
  107. private static final int NPC_MAGE = 36564;
  108. private static final int NPC_WARRIOR = 36565;
  109.  
  110. private static final int[] BOSSES = { 25653, 25654, 25655};
  111. private static final int[] MONSTERS = { 25656, 25657, 25658 };
  112.  
  113.  
  114. //Spawns
  115. private static final int[][] BOSSES_FIRST_WAVE =
  116. {
  117. {BOSSES[0], 50943, -12224, -9321 ,32768}
  118. };
  119.  
  120. private static final int[][] BOSSES_SECOND_WAVE =
  121. {
  122. {BOSSES[1], 50943, -12224, -9321 ,32768}
  123. };
  124.  
  125. private static final int[][] BOSSES_THIRD_WAVE =
  126. {
  127. {BOSSES[2], 50943, -12004, -9321, 32768},
  128. {BOSSES[2], 50943, -12475, -9321, 32768}
  129. };
  130.  
  131. private static final int[][] MONSTERS_FIRST_WAVE =
  132. {
  133. {MONSTERS[0], 50343, -12552, -9388, 32768},
  134. {MONSTERS[0], 50344, -12340, -9380, 32768},
  135. {MONSTERS[0], 50341, -12134, -9381, 32768},
  136. {MONSTERS[0], 50342, -11917, -9389, 32768},
  137. {MONSTERS[0], 50476, -12461, -9392, 32768},
  138. {MONSTERS[0], 50481, -12021, -9390, 32768},
  139. {MONSTERS[0], 50605, -12407, -9392, 32768},
  140. {MONSTERS[0], 50602, -12239, -9380, 32768},
  141. {MONSTERS[0], 50606, -12054, -9390, 32768}
  142. };
  143.  
  144. private static final int[][] MONSTERS_SECOND_WAVE =
  145. {
  146. {MONSTERS[1], 50343, -12552, -9388, 32768},
  147. {MONSTERS[1], 50344, -12340, -9380, 32768},
  148. {MONSTERS[1], 50341, -12134, -9381, 32768},
  149. {MONSTERS[1], 50342, -11917, -9389, 32768},
  150. {MONSTERS[1], 50476, -12461, -9392, 32768},
  151. {MONSTERS[1], 50481, -12021, -9390, 32768},
  152. {MONSTERS[1], 50605, -12407, -9392, 32768},
  153. {MONSTERS[1], 50602, -12239, -9380, 32768},
  154. {MONSTERS[1], 50606, -12054, -9390, 32768}
  155. };
  156.  
  157. private static final int[][] MONSTERS_THIRD_WAVE =
  158. {
  159. {MONSTERS[1], 50343, -12552, -9388, 32768},
  160. {MONSTERS[1], 50344, -12340, -9380, 32768},
  161. {MONSTERS[1], 50341, -12134, -9381, 32768},
  162. {MONSTERS[1], 50342, -11917, -9389, 32768},
  163. {MONSTERS[2], 50476, -12461, -9392, 32768},
  164. {MONSTERS[2], 50481, -12021, -9390, 32768},
  165. {MONSTERS[2], 50605, -12407, -9392, 32768},
  166. {MONSTERS[2], 50602, -12239, -9380, 32768},
  167. {MONSTERS[2], 50606, -12054, -9390, 32768}
  168. };
  169.  
  170. //NPCs'_SPAWNS (id, x, y, z, heading)
  171. private static final int[][] NPCS =
  172. {
  173. { NPC_WARRIOR, 49093, -12077, -9395, 0 },
  174. { NPC_RANGER, 49094, -12238, -9386, 0 },
  175. { NPC_MAGE, 49093, -12401, -9388, 0 },
  176. { NPC_KNIGHT, 49232, -12239, -9386, 0 }
  177. };
  178.  
  179. //Strings
  180. private static final NpcStringId[] NPC_INJURED_FSTRINGID = { NpcStringId.YOUR_MIND_IS_GOING_BLANK, NpcStringId.YOUR_MIND_IS_GOING_BLANK };
  181. private static final NpcStringId[] NPC_DIE_FSTRINGID = { NpcStringId.I_CANT_STAND_IT_ANYMORE_AAH, NpcStringId.I_CANT_STAND_IT_ANYMORE_AAH, NpcStringId.KYAAAK, NpcStringId.GASP_HOW_CAN_THIS_BE};
  182. private static final NpcStringId NPC_WIN_FSTRINGID = NpcStringId.YOUVE_DONE_IT_WE_BELIEVED_IN_YOU_WARRIOR_WE_WANT_TO_SHOW_OUR_SINCERITY_THOUGH_IT_IS_SMALL_PLEASE_GIVE_ME_SOME_OF_YOUR_TIME;
  183. private static final NpcStringId BOSS_DIE_FSTRINGID = NpcStringId.HOW_DARE_YOU;
  184. private static final NpcStringId[] BOSS_SPAWN_FSTRINGID = { NpcStringId.ILL_RIP_THE_FLESH_FROM_YOUR_BONES, NpcStringId.ILL_RIP_THE_FLESH_FROM_YOUR_BONES, NpcStringId.YOULL_FLOUNDER_IN_DELUSION_FOR_THE_REST_OF_YOUR_LIFE };
  185.  
  186.  
  187. //Buffs
  188. private static Map<Integer, SkillHolder> NPC_BUFFS = new FastMap<Integer, SkillHolder>();
  189. private static final SkillHolder RAID_CURSE = new SkillHolder(5456, 1);
  190.  
  191. private String checkEnterConditions(L2PcInstance player, L2Npc npc)
  192. {
  193. if (debug)
  194. return null;
  195.  
  196. Castle castle = npc.getCastle();
  197. CastleDungeon dungeon = _castleDungeons.get(npc.getNpcId());
  198. boolean haveContract = false;
  199.  
  200. if (player == null || castle == null || dungeon == null)
  201. return "CastleWarden-03.htm";
  202.  
  203. //check if castle have contract with fortress
  204. if (CHECK_FOR_CONTRACT)
  205. {
  206. for (Fort fort : FortManager.getInstance().getForts())
  207. {
  208. if (fort.getCastleId() == castle.getCastleId())
  209. {
  210. haveContract = true;
  211. break;
  212. }
  213. }
  214.  
  215. if (!haveContract)
  216. return "CastleWarden-13a.htm";
  217. }
  218.  
  219. QuestState st = player.getQuestState(qn);
  220.  
  221. //check if player have quest
  222. if (st == null || st.getInt("cond") < 1)
  223. {
  224. //check if player is from clan, that owns castle
  225. if (player.getClan() == null || player.getClan().getCastleId() != castle.getCastleId())
  226. return "CastleWarden-08.htm";
  227.  
  228. if (player.getLevel() >= 80)
  229. return "CastleWarden-06.htm";
  230.  
  231. return "CastleWarden-07.htm";
  232. }
  233.  
  234. L2Party party = player.getParty();
  235.  
  236. if (party == null)
  237. return "CastleWarden-09.htm";
  238.  
  239. if (party.getLeader() != player)
  240. return getHtm(player.getHtmlPrefix(), "CastleWarden-10.htm").replace("%leader%", party.getLeader().getName());
  241.  
  242. for (L2PcInstance partyMember : party.getMembers())
  243. {
  244. st = partyMember.getQuestState(qn);
  245.  
  246. //check if each party member has quest
  247. if (st == null || st.getInt("cond") < 1)
  248. return getHtm(player.getHtmlPrefix(), "CastleWarden-12.htm").replace("%player%", partyMember.getName());
  249.  
  250. if (player.getClan() == null || player.getClan().getCastleId() != castle.getCastleId())
  251. return getHtm(player.getHtmlPrefix(), "CastleWarden-11.htm").replace("%player%", partyMember.getName());
  252.  
  253. //check if each party member not very far from leader
  254. if (!Util.checkIfInRange(1000, player, partyMember, true))
  255. return getHtm(player.getHtmlPrefix(), "CastleWarden-17.htm").replace("%player%", partyMember.getName());
  256. }
  257.  
  258. if (dungeon.getReEnterTime() > System.currentTimeMillis())
  259. return "CastleWarden-18.htm";
  260.  
  261. return null;
  262. }
  263.  
  264. private void teleportPlayer(L2PcInstance player, Location loc, int instanceId)
  265. {
  266. player.setInstanceId(instanceId);
  267. player.teleToLocation(loc, instanceId);
  268. }
  269.  
  270. protected String enterInstance(L2PcInstance player, String template,Location loc, CastleDungeon dungeon, String ret)
  271. {
  272. //check for existing instances for this player
  273. InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  274. //existing instance
  275. if (world != null)
  276. {
  277. if (!(world instanceof CAUWorld))
  278. {
  279. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER));
  280. return "";
  281. }
  282. teleportPlayer(player, loc, world.instanceId);
  283. return "";
  284. }
  285. //New instance
  286. if (ret != null)
  287. return ret;
  288.  
  289. L2Party party = player.getParty();
  290. int instanceId = InstanceManager.getInstance().createDynamicInstance(template);
  291. Instance ins = InstanceManager.getInstance().getInstance(instanceId);
  292. ins.setSpawnLoc(new Location(player));
  293. world = new CAUWorld();
  294. world.instanceId = instanceId;
  295. world.templateId = dungeon.getInstanceId();
  296. world.status = 0;
  297. dungeon.setReEnterTime(System.currentTimeMillis() + REENTER_INTERVAL);
  298. InstanceManager.getInstance().addWorld(world);
  299. _log.info("Castle HopeWithinTheDarkness started " + template + " Instance: " + instanceId + " created by player: " + player.getName());
  300. ThreadPoolManager.getInstance().scheduleGeneral(new spawnNpcs((CAUWorld) world), INITIAL_SPAWN_DELAY);
  301.  
  302. // teleport players
  303. if (player.getParty() == null)
  304. {
  305. return "CastleWarden-09.htm";
  306. }
  307. else if ((player.getParty() != null))
  308. {
  309. for (L2PcInstance partyMember : party.getMembers())
  310. {
  311. teleportPlayer(partyMember, loc, instanceId);
  312. world.allowed.add(partyMember.getObjectId());
  313. if (partyMember.getQuestState(qn) == null)
  314. newQuestState(partyMember);
  315.  
  316. partyMember.getQuestState(qn).set("cond", "2");
  317. }
  318. }
  319. return getHtm(player.getHtmlPrefix(), "CastleWarden-13.htm").replace("%clan%", player.getClan().getName());
  320. }
  321.  
  322. //Spawns npc's and bosses
  323. private class spawnNpcs implements Runnable
  324. {
  325. private CAUWorld _world;
  326.  
  327. public spawnNpcs(CAUWorld world)
  328. {
  329. _world = world;
  330. }
  331.  
  332. @Override
  333. public void run()
  334. {
  335. try
  336. {
  337. if (_world.status == 0)
  338. {
  339. for(int[] spawn : NPCS)
  340. addSpawn(spawn[0], spawn[1], spawn[2], spawn[3], spawn[4], false, 0, false, _world.instanceId);
  341. for(int[] spawn : BOSSES_FIRST_WAVE)
  342. addSpawn(spawn[0], spawn[1], spawn[2], spawn[3], spawn[4], false, 0, false, _world.instanceId);
  343.  
  344. ThreadPoolManager.getInstance().scheduleGeneral(new spawnNpcs(_world), WAVE_SPAWN_DELAY);
  345. ThreadPoolManager.getInstance().scheduleGeneral(new spawnPrivates(_world), PRIVATE_SPAWN_DELAY);
  346. }
  347. else if (_world.status == 1)
  348. {
  349. for(int[] spawn : BOSSES_SECOND_WAVE)
  350. addSpawn(spawn[0], spawn[1], spawn[2], spawn[3], spawn[4], false, 0, false, _world.instanceId);
  351.  
  352. ThreadPoolManager.getInstance().scheduleGeneral(new spawnNpcs(_world), WAVE_SPAWN_DELAY);
  353. ThreadPoolManager.getInstance().scheduleGeneral(new spawnPrivates(_world), PRIVATE_SPAWN_DELAY);
  354. }
  355. else if (_world.status == 2)
  356. {
  357. for(int[] spawn : BOSSES_THIRD_WAVE)
  358. addSpawn(spawn[0], spawn[1], spawn[2], spawn[3], spawn[4], false, 0, false, _world.instanceId);
  359.  
  360. ThreadPoolManager.getInstance().scheduleGeneral(new spawnPrivates(_world), PRIVATE_SPAWN_DELAY);
  361. }
  362. }
  363. catch (Exception e)
  364. {
  365. _log.warning("Castle HopeWithinTheDarkness NPC Spawn error: " + e);
  366. }
  367. }
  368. }
  369.  
  370. //Spawns monsters (minions)
  371. private class spawnPrivates implements Runnable
  372. {
  373. private CAUWorld _world;
  374.  
  375. public spawnPrivates(CAUWorld world)
  376. {
  377. _world = world;
  378. }
  379.  
  380. @Override
  381. public void run()
  382. {
  383. try
  384. {
  385. if (_world.status == 0)
  386. {
  387. for(int[] spawn : MONSTERS_FIRST_WAVE)
  388. addSpawn(spawn[0],spawn[1],spawn[2],spawn[3],spawn[4],false,0,false, _world.instanceId);
  389.  
  390. _world.underAttack = true;
  391. }
  392. else if (_world.status == 1)
  393. {
  394. for(int[] spawn : MONSTERS_SECOND_WAVE)
  395. addSpawn(spawn[0],spawn[1],spawn[2],spawn[3],spawn[4],false,0,false, _world.instanceId);
  396. }
  397. else if (_world.status == 2)
  398. {
  399. for(int[] spawn : MONSTERS_THIRD_WAVE)
  400. addSpawn(spawn[0],spawn[1],spawn[2],spawn[3],spawn[4],false,0,false, _world.instanceId);
  401. }
  402.  
  403. _world.status++;
  404. }
  405. catch (Exception e)
  406. {
  407. _log.warning("Castle HopeWithinTheDarkness Monster Spawn error: " + e);
  408. }
  409. }
  410. }
  411.  
  412. //Manages win event
  413. private class Win implements Runnable
  414. {
  415. private CAUWorld _world;
  416. private L2PcInstance _player;
  417.  
  418. public Win(CAUWorld world, L2PcInstance player)
  419. {
  420. _world = world;
  421. _player = player;
  422. }
  423.  
  424. @Override
  425. public void run()
  426. {
  427. try
  428. {
  429. if (_world.status == 4)
  430. {
  431. _world.underAttack = false;
  432.  
  433. Instance inst = InstanceManager.getInstance().getInstance(_world.instanceId);
  434.  
  435. for (L2Npc _npc : inst.getNpcs())
  436. {
  437.  
  438. if (_npc != null && (_npc.getNpcId() >= NPC_KNIGHT && _npc.getNpcId() <= NPC_WARRIOR))
  439. {
  440. cancelQuestTimer("check_for_foes", _npc, null);
  441. cancelQuestTimer("buff", _npc, null);
  442.  
  443. if (_npc.getNpcId() == NPC_KNIGHT)
  444. _npc.broadcastPacket(new NpcSay(_npc.getObjectId(), Say2.SHOUT, _npc.getNpcId(), NPC_WIN_FSTRINGID));
  445. }
  446. }
  447.  
  448. if (_player != null)
  449. {
  450. L2Party party = _player.getParty();
  451.  
  452. if (party == null)
  453. rewardPlayer(_player);
  454. else
  455. {
  456. for (L2PcInstance partyMember : party.getMembers())
  457. {
  458. if (partyMember != null && partyMember.getInstanceId() == _player.getInstanceId())
  459. rewardPlayer(partyMember);
  460. }
  461. }
  462. }
  463. }
  464. }
  465. catch (Exception e)
  466. {
  467. _log.warning("Win manage error: " + e);
  468. }
  469. }
  470. }
  471.  
  472. private void rewardPlayer(L2PcInstance player)
  473. {
  474. QuestState st = player.getQuestState(qn);
  475. if (st != null && st.getInt("cond") == 2)
  476. st.set("cond", "3");
  477. }
  478.  
  479. @Override
  480. public String onAdvEvent (String event, L2Npc npc, L2PcInstance player)
  481. {
  482. String htmltext = event;
  483. if (event.equalsIgnoreCase("enter"))
  484. {
  485. int[] tele = new int[3];
  486. tele[0] = 48163;
  487. tele[1] = -12195;
  488. tele[2] = -9140;
  489.  
  490. //htmltext = checkEnterConditions(player, npc);
  491.  
  492. return enterInstance(player, "castlepailaka.xml", tele, _castleDungeons.get(npc.getNpcId()), checkEnterConditions(player, npc));
  493. }
  494.  
  495. else if (event.equalsIgnoreCase("suicide"))
  496. {
  497. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  498. tmpworld.status = 5;
  499. Instance inst = InstanceManager.getInstance().getInstance(npc.getInstanceId());
  500. if (inst != null)
  501. {
  502. for (L2Npc _npc : inst.getNpcs())
  503. {
  504. if (_npc != null && (_npc.getNpcId() >= NPC_KNIGHT && _npc.getNpcId() <= NPC_WARRIOR))
  505. {
  506. cancelQuestTimer("check_for_foes", _npc, null);
  507. cancelQuestTimer("buff", _npc, null);
  508.  
  509. if (!_npc.isDead())
  510. _npc.doDie(null);
  511. }
  512. }
  513.  
  514. //Destroy instance after 5 minutes
  515. inst.setDuration(5 * 60000);
  516. inst.setEmptyDestroyTime(0);
  517. }
  518.  
  519. return null;
  520. }
  521.  
  522. else if (event.equalsIgnoreCase("buff"))
  523. {
  524. Collection<L2PcInstance> players = npc.getKnownList().getKnownPlayers().values();
  525. for (L2PcInstance pl : players)
  526. {
  527. if (pl != null && Util.checkIfInRange(75, npc, pl, false) && NPC_BUFFS.get(npc.getNpcId()) != null)
  528. {
  529. npc.setTarget(pl);
  530. npc.doCast(NPC_BUFFS.get(npc.getNpcId()).getSkill());
  531. }
  532. }
  533. startQuestTimer("buff", 120000, npc, null);
  534. return null;
  535. }
  536.  
  537. else if (event.equalsIgnoreCase("check_for_foes"))
  538. {
  539. if (npc.getAI().getIntention() != CtrlIntention.AI_INTENTION_ATTACK)
  540. {
  541. for (L2Character foe : npc.getKnownList().getKnownCharactersInRadius(npc.getAggroRange()))
  542. {
  543. if (foe instanceof L2Attackable && !(foe instanceof L2QuestGuardInstance))
  544. {
  545. ((L2QuestGuardInstance) npc).addDamageHate(foe, 0, 999);
  546. ((L2QuestGuardInstance) npc).getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, foe, null);
  547. }
  548. }
  549. }
  550.  
  551. startQuestTimer("check_for_foes", 5000, npc, null);
  552. return null;
  553. }
  554.  
  555. QuestState st = player.getQuestState(qn);
  556. if (st == null)
  557. st = newQuestState(player);
  558.  
  559. int cond = st.getInt("cond");
  560. if (event.equalsIgnoreCase("CastleWarden-05.htm"))
  561. {
  562. if (cond == 0)
  563. {
  564. st.set("cond","1");
  565. st.setState(State.STARTED);
  566. st.playSound("ItemSound.quest_accept");
  567. }
  568. }
  569. else if (event.equalsIgnoreCase("CastleWarden-15.htm"))
  570. {
  571. st.playSound("ItemSound.quest_finish");
  572. st.exitQuest(true);
  573. }
  574. return htmltext;
  575. }
  576.  
  577. @Override
  578. public String onFirstTalk (L2Npc npc, L2PcInstance player)
  579. {
  580. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(player.getInstanceId());
  581. if (tmpworld instanceof CAUWorld)
  582. {
  583. CAUWorld world = (CAUWorld) tmpworld;
  584.  
  585. if (world.underAttack)
  586. return "Victim-02.htm";
  587.  
  588. else if (world.status == 4)
  589. return "Victim-03.htm";
  590.  
  591. else
  592. return "Victim-01.htm";
  593. }
  594.  
  595. return null;
  596. }
  597.  
  598. @Override
  599. public String onTalk (L2Npc npc, L2PcInstance player)
  600. {
  601. String htmltext = Quest.getNoQuestMsg(player);
  602. QuestState st = player.getQuestState(qn);
  603.  
  604. if (npc.getNpcId() >= NPC_KNIGHT && npc.getNpcId() <= NPC_WARRIOR)
  605. {
  606. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(player.getInstanceId());
  607. if (tmpworld != null && tmpworld instanceof CAUWorld)
  608. {
  609. CAUWorld world = (CAUWorld) tmpworld;
  610.  
  611. world.allowed.remove(world.allowed.indexOf(player.getObjectId()));
  612. final Instance inst = InstanceManager.getInstance().getInstance(world.instanceId);
  613. teleportPlayer(player, inst.getSpawnLoc(), 0);
  614. return null;
  615. }
  616. }
  617.  
  618. if (player.getClan() == null || npc.getCastle() == null || player.getClan().getCastleId() != npc.getCastle().getCastleId())
  619. return "CastleWarden-03.htm";
  620.  
  621. else if (st != null)
  622. {
  623. int npcId = npc.getNpcId();
  624. int cond = 0;
  625. if (st.getState() == State.CREATED)
  626. st.set("cond","0");
  627. else
  628. cond = st.getInt("cond");
  629. if (_castleDungeons.containsKey(npcId) && cond == 0)
  630. {
  631. if (player.getLevel() >= 80)
  632. htmltext = "CastleWarden-01.htm";
  633. else
  634. {
  635. htmltext = "CastleWarden-04.htm";
  636. st.exitQuest(true);
  637. }
  638. }
  639. else if (_castleDungeons.containsKey(npcId) && cond > 0 && st.getState() == State.STARTED)
  640. {
  641. if (cond == 1)
  642. {
  643. htmltext = "CastleWarden-15.htm";
  644. }
  645. else if (cond == 3)
  646. {
  647. st.playSound("ItemSound.quest_finish");
  648. st.giveItems(KNIGHT_EPALUETTE, 159);
  649. st.exitQuest(true);
  650. htmltext = "CastleWarden-16.htm";
  651. }
  652. }
  653. }
  654. return htmltext;
  655. }
  656.  
  657. @Override
  658. public String onAttack(L2Npc npc,L2PcInstance player, int damage, boolean isPet)
  659. {
  660. if (npc.getNpcId() >= NPC_KNIGHT && npc.getNpcId() <= NPC_WARRIOR)
  661. {
  662. if (npc.getCurrentHp() <= npc.getMaxHp() * 0.1)
  663. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.ALL, npc.getNpcId(), NPC_INJURED_FSTRINGID[1]));
  664. else if (npc.getCurrentHp() <= npc.getMaxHp() * 0.4)
  665. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.ALL, npc.getNpcId(), NPC_INJURED_FSTRINGID[0]));
  666.  
  667. return null;
  668. }
  669.  
  670. if (player != null)
  671. {
  672. L2Playable attacker = (isPet ? player.getPet() : player);
  673. if (attacker.getLevel() - npc.getLevel() >= 9)
  674. {
  675. if (attacker.getBuffCount() > 0 || attacker.getDanceCount() > 0)
  676. {
  677. npc.setTarget(attacker);
  678. npc.doSimultaneousCast(RAID_CURSE.getSkill());
  679. }
  680. else if (player.getParty() != null)
  681. for(L2PcInstance pmember : player.getParty().getMembers())
  682. {
  683. if (pmember.getBuffCount() > 0 || pmember.getDanceCount() > 0)
  684. {
  685. npc.setTarget(pmember);
  686. npc.doSimultaneousCast(RAID_CURSE.getSkill());
  687. }
  688. }
  689. }
  690. }
  691. return super.onAttack(npc, player, damage, isPet);
  692. }
  693.  
  694. @Override
  695. public String onKill(L2Npc npc, L2PcInstance player, boolean isPet)
  696. {
  697. if (npc.getNpcId() >= NPC_KNIGHT && npc.getNpcId() <= NPC_WARRIOR)
  698. {
  699. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.ALL, npc.getNpcId(), NPC_DIE_FSTRINGID[npc.getNpcId() - 36562]));
  700.  
  701. //All other friendly NPC's do suicide - start timer
  702. startQuestTimer("suicide", 1500, npc, null);
  703. cancelQuestTimer("check_for_foes", npc, null);
  704. cancelQuestTimer("buff", npc, null);
  705. return null;
  706. }
  707.  
  708.  
  709. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  710. if (tmpworld instanceof CAUWorld)
  711. {
  712. CAUWorld world = (CAUWorld) tmpworld;
  713. if (Util.contains(BOSSES, npc.getNpcId()))
  714. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.ALL, npc.getNpcId(), BOSS_DIE_FSTRINGID));
  715.  
  716. if (tmpworld.status == 3 && (Util.contains(BOSSES, npc.getNpcId()) || Util.contains(MONSTERS, npc.getNpcId())))
  717. {
  718. world.allMonstersDead = true;
  719. Instance inst = InstanceManager.getInstance().getInstance(tmpworld.instanceId);
  720.  
  721. if (inst != null)
  722. {
  723. for (L2Npc _npc : inst.getNpcs())
  724. {
  725. if (_npc != null && !_npc.isDead() && (Util.contains(BOSSES, _npc.getNpcId()) || Util.contains(MONSTERS, _npc.getNpcId())))
  726. {
  727. world.allMonstersDead = false;
  728. break;
  729. }
  730.  
  731. }
  732.  
  733.  
  734. if (world.allMonstersDead)
  735. {
  736. tmpworld.status = 4;
  737.  
  738. //Destroy instance after 5 minutes
  739. inst.setDuration(5 * 60000);
  740. inst.setEmptyDestroyTime(0);
  741. ThreadPoolManager.getInstance().scheduleGeneral(new Win(world, player), 1500);
  742. }
  743. }
  744. }
  745. }
  746.  
  747. return null;
  748. }
  749.  
  750. @Override
  751. public final String onSpawn(L2Npc npc)
  752. {
  753. //buff players every two minutes, check for foes in aggro range
  754. if (npc.getNpcId() >= NPC_KNIGHT && npc.getNpcId() <= NPC_WARRIOR)
  755. {
  756. startQuestTimer("buff", 120000, npc, null);
  757. startQuestTimer("check_for_foes", 120000, npc, null);
  758.  
  759. if (npc.getNpcId() == NPC_KNIGHT)
  760. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.ALL, npc.getNpcId(), NpcStringId.WARRIORS_HAVE_YOU_COME_TO_HELP_THOSE_WHO_ARE_IMPRISONED_HERE));
  761. }
  762.  
  763. else if (Arrays.binarySearch(BOSSES, npc.getNpcId()) >= 0)
  764. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.ALL, npc.getNpcId(), BOSS_SPAWN_FSTRINGID[Arrays.binarySearch(BOSSES, npc.getNpcId())]));
  765.  
  766. return null;
  767. }
  768.  
  769. public Q727_HopeWithinTheDarkness(int questId, String name, String descr)
  770. {
  771. super(questId, name, descr);
  772. _castleDungeons.put(36403, new CastleDungeon(80, 36403));
  773. _castleDungeons.put(36404, new CastleDungeon(81, 36404));
  774. _castleDungeons.put(36405, new CastleDungeon(82, 36405));
  775. _castleDungeons.put(36406, new CastleDungeon(83, 36406));
  776. _castleDungeons.put(36407, new CastleDungeon(84, 36407));
  777. _castleDungeons.put(36408, new CastleDungeon(85, 36408));
  778. _castleDungeons.put(36409, new CastleDungeon(86, 36409));
  779. _castleDungeons.put(36410, new CastleDungeon(87, 36410));
  780. _castleDungeons.put(36411, new CastleDungeon(88, 36411));
  781.  
  782. NPC_BUFFS.put(NPC_KNIGHT, new SkillHolder(5970, 1));
  783. NPC_BUFFS.put(NPC_RANGER, new SkillHolder(5971, 1));
  784. NPC_BUFFS.put(NPC_MAGE, new SkillHolder(5972, 1));
  785. NPC_BUFFS.put(NPC_WARRIOR, new SkillHolder(5973, 1));
  786.  
  787. for(int i : _castleDungeons.keySet())
  788. {
  789. addStartNpc(i);
  790. addTalkId(i);
  791. }
  792.  
  793. for (int i = NPC_KNIGHT; i <= NPC_WARRIOR; i++)
  794. {
  795. addSpawnId(i);
  796. addKillId(i);
  797. addAttackId(i);
  798. addTalkId(i);
  799. addFirstTalkId(i);
  800. }
  801.  
  802. for(int i : BOSSES)
  803. {
  804. addSpawnId(i);
  805. addKillId(i);
  806. addAttackId(i);
  807. }
  808.  
  809. for(int i : MONSTERS)
  810. {
  811. addKillId(i);
  812. addAttackId(i);
  813. }
  814.  
  815. }
  816.  
  817. public static void main(String[] args)
  818. {
  819. // now call the constructor (starts up the)
  820. new Q727_HopeWithinTheDarkness(727, qn, "Hope Within The Darkness");
  821. }
  822. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement