Q00511_AwlUnderFoot.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. /*
  2. * Copyright (C) 2004-2015 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 quests.Q00511_AwlUnderFoot;
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import com.l2jserver.gameserver.ThreadPoolManager;
  23. import com.l2jserver.gameserver.enums.QuestSound;
  24. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  25. import com.l2jserver.gameserver.model.L2Party;
  26. import com.l2jserver.gameserver.model.Location;
  27. import com.l2jserver.gameserver.model.actor.L2Npc;
  28. import com.l2jserver.gameserver.model.actor.L2Playable;
  29. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  30. import com.l2jserver.gameserver.model.actor.instance.L2RaidBossInstance;
  31. import com.l2jserver.gameserver.model.entity.Fort;
  32. import com.l2jserver.gameserver.model.entity.Instance;
  33. import com.l2jserver.gameserver.model.holders.SkillHolder;
  34. import com.l2jserver.gameserver.model.instancezone.InstanceWorld;
  35. import com.l2jserver.gameserver.model.quest.Quest;
  36. import com.l2jserver.gameserver.model.quest.QuestState;
  37. import com.l2jserver.gameserver.model.quest.State;
  38. import com.l2jserver.gameserver.network.SystemMessageId;
  39. import com.l2jserver.gameserver.util.Util;
  40. /**
  41. * Awl Under Foot (511)
  42. * @author Gigiikun
  43. */
  44. public final class Q00511_AwlUnderFoot extends Quest
  45. {
  46. protected class FAUWorld extends InstanceWorld
  47. {
  48. }
  49. public static class FortDungeon
  50. {
  51. private final int INSTANCEID;
  52. private long _reEnterTime = 0;
  53. public FortDungeon(int iId)
  54. {
  55. INSTANCEID = iId;
  56. }
  57. public int getInstanceId()
  58. {
  59. return INSTANCEID;
  60. }
  61. public long getReEnterTime()
  62. {
  63. return _reEnterTime;
  64. }
  65. public void setReEnterTime(long time)
  66. {
  67. _reEnterTime = time;
  68. }
  69. }
  70. private class spawnRaid implements Runnable
  71. {
  72. private final FAUWorld _world;
  73. public spawnRaid(FAUWorld world)
  74. {
  75. _world = world;
  76. }
  77. @Override
  78. public void run()
  79. {
  80. try
  81. {
  82. int spawnId;
  83. if (_world.getStatus() == 0)
  84. {
  85. spawnId = RAIDS1[getRandom(RAIDS1.length)];
  86. }
  87. else if (_world.getStatus() == 1)
  88. {
  89. spawnId = RAIDS2[getRandom(RAIDS2.length)];
  90. }
  91. else
  92. {
  93. spawnId = RAIDS3[getRandom(RAIDS3.length)];
  94. }
  95. L2Npc raid = addSpawn(spawnId, 53319, 245814, -6576, 0, false, 0, false, _world.getInstanceId());
  96. if (raid instanceof L2RaidBossInstance)
  97. {
  98. ((L2RaidBossInstance) raid).setUseRaidCurse(false);
  99. }
  100. }
  101. catch (Exception e)
  102. {
  103. _log.warning("Fortress AwlUnderFoot Raid Spawn error: " + e);
  104. }
  105. }
  106. }
  107. private static final boolean debug = false;
  108. private static final long REENTERTIME = 14400000;
  109. private static final long RAID_SPAWN_DELAY = 120000;
  110. private final Map<Integer, FortDungeon> _fortDungeons = new HashMap<>(21);
  111. // QUEST ITEMS
  112. private static final int DL_MARK = 9797;
  113. // REWARDS
  114. private static final int KNIGHT_EPALUETTE = 9912;
  115. // MONSTER TO KILL -- Only last 3 Raids (lvl ordered) give DL_MARK
  116. protected static final int[] RAIDS1 =
  117. {
  118. 25572,
  119. 25575,
  120. 25578
  121. };
  122. protected static final int[] RAIDS2 =
  123. {
  124. 25579,
  125. 25582,
  126. 25585,
  127. 25588
  128. };
  129. protected static final int[] RAIDS3 =
  130. {
  131. 25589,
  132. 25592,
  133. 25593
  134. };
  135. // Skill
  136. private static final SkillHolder RAID_CURSE = new SkillHolder(5456, 1);
  137. public Q00511_AwlUnderFoot()
  138. {
  139. super(511, Q00511_AwlUnderFoot.class.getSimpleName(), "instances");
  140. _fortDungeons.put(35666, new FortDungeon(22));
  141. _fortDungeons.put(35698, new FortDungeon(23));
  142. _fortDungeons.put(35735, new FortDungeon(24));
  143. _fortDungeons.put(35767, new FortDungeon(25));
  144. _fortDungeons.put(35804, new FortDungeon(26));
  145. _fortDungeons.put(35835, new FortDungeon(27));
  146. _fortDungeons.put(35867, new FortDungeon(28));
  147. _fortDungeons.put(35904, new FortDungeon(29));
  148. _fortDungeons.put(35936, new FortDungeon(30));
  149. _fortDungeons.put(35974, new FortDungeon(31));
  150. _fortDungeons.put(36011, new FortDungeon(32));
  151. _fortDungeons.put(36043, new FortDungeon(33));
  152. _fortDungeons.put(36081, new FortDungeon(34));
  153. _fortDungeons.put(36118, new FortDungeon(35));
  154. _fortDungeons.put(36149, new FortDungeon(36));
  155. _fortDungeons.put(36181, new FortDungeon(37));
  156. _fortDungeons.put(36219, new FortDungeon(38));
  157. _fortDungeons.put(36257, new FortDungeon(39));
  158. _fortDungeons.put(36294, new FortDungeon(40));
  159. _fortDungeons.put(36326, new FortDungeon(41));
  160. _fortDungeons.put(36364, new FortDungeon(42));
  161. for (int i : _fortDungeons.keySet())
  162. {
  163. addStartNpc(i);
  164. addTalkId(i);
  165. }
  166. addKillId(RAIDS1);
  167. addKillId(RAIDS2);
  168. addKillId(RAIDS3);
  169. for (int i = 25572; i <= 25595; i++)
  170. {
  171. addAttackId(i);
  172. }
  173. }
  174. private String checkConditions(L2PcInstance player)
  175. {
  176. if (debug)
  177. {
  178. return null;
  179. }
  180. L2Party party = player.getParty();
  181. if (party == null)
  182. {
  183. return "FortressWarden-03.htm";
  184. }
  185. if (party.getLeader() != player)
  186. {
  187. return getHtm(player.getHtmlPrefix(), "FortressWarden-04.htm").replace("%leader%", party.getLeader().getName());
  188. }
  189. for (L2PcInstance partyMember : party.getMembers())
  190. {
  191. final QuestState st = getQuestState(partyMember, false);
  192. if ((st == null) || (st.getInt("cond") < 1))
  193. {
  194. return getHtm(player.getHtmlPrefix(), "FortressWarden-05.htm").replace("%player%", partyMember.getName());
  195. }
  196. if (!Util.checkIfInRange(1000, player, partyMember, true))
  197. {
  198. return getHtm(player.getHtmlPrefix(), "FortressWarden-06.htm").replace("%player%", partyMember.getName());
  199. }
  200. }
  201. return null;
  202. }
  203. private String checkFortCondition(L2PcInstance player, L2Npc npc, boolean isEnter)
  204. {
  205. Fort fortress = npc.getFort();
  206. FortDungeon dungeon = _fortDungeons.get(npc.getId());
  207. if ((player == null) || (fortress == null) || (dungeon == null))
  208. {
  209. return "FortressWarden-01.htm";
  210. }
  211. if ((player.getClan() == null) || (player.getClan().getFortId() != fortress.getResidenceId()))
  212. {
  213. return "FortressWarden-01.htm";
  214. }
  215. else if (fortress.getFortState() == 0)
  216. {
  217. return "FortressWarden-02a.htm";
  218. }
  219. else if (fortress.getFortState() == 2)
  220. {
  221. return "FortressWarden-02b.htm";
  222. }
  223. else if (isEnter && (dungeon.getReEnterTime() > System.currentTimeMillis()))
  224. {
  225. return "FortressWarden-07.htm";
  226. }
  227. L2Party party = player.getParty();
  228. if (party == null)
  229. {
  230. return "FortressWarden-03.htm";
  231. }
  232. for (L2PcInstance partyMember : party.getMembers())
  233. {
  234. if ((partyMember.getClan() == null) || (partyMember.getClan().getFortId() == 0) || (partyMember.getClan().getFortId() != fortress.getResidenceId()))
  235. {
  236. return getHtm(player.getHtmlPrefix(), "FortressWarden-05.htm").replace("%player%", partyMember.getName());
  237. }
  238. }
  239. return null;
  240. }
  241. protected String enterInstance(L2PcInstance player, String template, int[] coords, FortDungeon dungeon, String ret)
  242. {
  243. // check for existing instances for this player
  244. InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  245. // existing instance
  246. if (world != null)
  247. {
  248. if (!(world instanceof FAUWorld))
  249. {
  250. player.sendPacket(SystemMessageId.YOU_HAVE_ENTERED_ANOTHER_INSTANT_ZONE_THEREFORE_YOU_CANNOT_ENTER_CORRESPONDING_DUNGEON);
  251. return "";
  252. }
  253. teleportPlayer(player, coords, world.getInstanceId());
  254. return "";
  255. }
  256. // New instance
  257. if (ret != null)
  258. {
  259. return ret;
  260. }
  261. ret = checkConditions(player);
  262. if (ret != null)
  263. {
  264. return ret;
  265. }
  266. L2Party party = player.getParty();
  267. int instanceId = InstanceManager.getInstance().createDynamicInstance(template);
  268. Instance ins = InstanceManager.getInstance().getInstance(instanceId);
  269. ins.setSpawnLoc(new Location(player));
  270. world = new FAUWorld();
  271. world.setInstanceId(instanceId);
  272. world.setTemplateId(dungeon.getInstanceId());
  273. world.setStatus(0);
  274. dungeon.setReEnterTime(System.currentTimeMillis() + REENTERTIME);
  275. InstanceManager.getInstance().addWorld(world);
  276. _log.info("Fortress AwlUnderFoot started " + template + " Instance: " + instanceId + " created by player: " + player.getName());
  277. ThreadPoolManager.getInstance().scheduleGeneral(new spawnRaid((FAUWorld) world), RAID_SPAWN_DELAY);
  278. // teleport players
  279. if (player.getParty() == null)
  280. {
  281. teleportPlayer(player, coords, instanceId);
  282. world.addAllowed(player.getObjectId());
  283. }
  284. else
  285. {
  286. for (L2PcInstance partyMember : party.getMembers())
  287. {
  288. teleportPlayer(partyMember, coords, instanceId);
  289. world.addAllowed(partyMember.getObjectId());
  290. getQuestState(partyMember, true);
  291. }
  292. }
  293. return getHtm(player.getHtmlPrefix(), "FortressWarden-08.htm").replace("%clan%", player.getClan().getName());
  294. }
  295. @Override
  296. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  297. {
  298. String htmltext = event;
  299. if (event.equalsIgnoreCase("enter"))
  300. {
  301. int[] tele = new int[3];
  302. tele[0] = 53322;
  303. tele[1] = 246380;
  304. tele[2] = -6580;
  305. return enterInstance(player, "fortdungeon.xml", tele, _fortDungeons.get(npc.getId()), checkFortCondition(player, npc, true));
  306. }
  307. QuestState st = getQuestState(player, true);
  308. if (event.equalsIgnoreCase("FortressWarden-10.htm"))
  309. {
  310. if (st.isCond(0))
  311. {
  312. st.startQuest();
  313. }
  314. }
  315. else if (event.equalsIgnoreCase("FortressWarden-15.htm"))
  316. {
  317. st.exitQuest(true, true);
  318. }
  319. return htmltext;
  320. }
  321. @Override
  322. public String onAttack(L2Npc npc, L2PcInstance player, int damage, boolean isSummon)
  323. {
  324. L2Playable attacker = (isSummon ? player.getSummon() : player);
  325. if ((attacker.getLevel() - npc.getLevel()) >= 9)
  326. {
  327. if ((attacker.getBuffCount() > 0) || (attacker.getDanceCount() > 0))
  328. {
  329. npc.setTarget(attacker);
  330. npc.doSimultaneousCast(RAID_CURSE.getSkill());
  331. }
  332. else if (player.getParty() != null)
  333. {
  334. for (L2PcInstance pmember : player.getParty().getMembers())
  335. {
  336. if ((pmember.getBuffCount() > 0) || (pmember.getDanceCount() > 0))
  337. {
  338. npc.setTarget(pmember);
  339. npc.doSimultaneousCast(RAID_CURSE.getSkill());
  340. }
  341. }
  342. }
  343. }
  344. return super.onAttack(npc, player, damage, isSummon);
  345. }
  346. @Override
  347. public String onKill(L2Npc npc, L2PcInstance player, boolean isSummon)
  348. {
  349. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  350. if (tmpworld instanceof FAUWorld)
  351. {
  352. FAUWorld world = (FAUWorld) tmpworld;
  353. if (Util.contains(RAIDS3, npc.getId()))
  354. {
  355. if (player.getParty() != null)
  356. {
  357. for (L2PcInstance pl : player.getParty().getMembers())
  358. {
  359. rewardPlayer(pl);
  360. }
  361. }
  362. else
  363. {
  364. rewardPlayer(player);
  365. }
  366. Instance instanceObj = InstanceManager.getInstance().getInstance(world.getInstanceId());
  367. instanceObj.setDuration(360000);
  368. instanceObj.removeNpcs();
  369. }
  370. else
  371. {
  372. world.incStatus();
  373. ThreadPoolManager.getInstance().scheduleGeneral(new spawnRaid(world), RAID_SPAWN_DELAY);
  374. }
  375. }
  376. return null;
  377. }
  378. @Override
  379. public String onTalk(L2Npc npc, L2PcInstance player)
  380. {
  381. String htmltext = Quest.getNoQuestMsg(player);
  382. final QuestState st = getQuestState(player, true);
  383. String ret = checkFortCondition(player, npc, false);
  384. if (ret != null)
  385. {
  386. return ret;
  387. }
  388. else if (st != null)
  389. {
  390. int npcId = npc.getId();
  391. int cond = 0;
  392. if (st.getState() == State.CREATED)
  393. {
  394. st.set("cond", "0");
  395. }
  396. else
  397. {
  398. cond = st.getInt("cond");
  399. }
  400. if (_fortDungeons.containsKey(npcId) && (cond == 0))
  401. {
  402. if (player.getLevel() >= 60)
  403. {
  404. htmltext = "FortressWarden-09.htm";
  405. }
  406. else
  407. {
  408. htmltext = "FortressWarden-00.htm";
  409. st.exitQuest(true);
  410. }
  411. }
  412. else if (_fortDungeons.containsKey(npcId) && (cond > 0) && (st.getState() == State.STARTED))
  413. {
  414. long count = st.getQuestItemsCount(DL_MARK);
  415. if ((cond == 1) && (count > 0))
  416. {
  417. htmltext = "FortressWarden-14.htm";
  418. st.takeItems(DL_MARK, -1);
  419. st.rewardItems(KNIGHT_EPALUETTE, count);
  420. }
  421. else if ((cond == 1) && (count == 0))
  422. {
  423. htmltext = "FortressWarden-10.htm";
  424. }
  425. }
  426. }
  427. return htmltext;
  428. }
  429. private void rewardPlayer(L2PcInstance player)
  430. {
  431. QuestState st = getQuestState(player, false);
  432. if (st.isCond(1))
  433. {
  434. st.giveItems(DL_MARK, 140);
  435. st.playSound(QuestSound.ITEMSOUND_QUEST_ITEMGET);
  436. }
  437. }
  438. private void teleportPlayer(L2PcInstance player, int[] coords, int instanceId)
  439. {
  440. player.setInstanceId(instanceId);
  441. player.teleToLocation(coords[0], coords[1], coords[2]);
  442. }
  443. }