HellboundTown.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. /*
  2. * Copyright (C) 2004-2013 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.HellboundTown;
  20. import java.util.concurrent.ScheduledFuture;
  21. import com.l2jserver.gameserver.ThreadPoolManager;
  22. import com.l2jserver.gameserver.instancemanager.HellboundManager;
  23. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  24. import com.l2jserver.gameserver.model.L2Party;
  25. import com.l2jserver.gameserver.model.Location;
  26. import com.l2jserver.gameserver.model.actor.L2Npc;
  27. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  28. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  29. import com.l2jserver.gameserver.model.actor.instance.L2QuestGuardInstance;
  30. import com.l2jserver.gameserver.model.effects.L2Effect;
  31. import com.l2jserver.gameserver.model.entity.Instance;
  32. import com.l2jserver.gameserver.model.holders.SkillHolder;
  33. import com.l2jserver.gameserver.model.instancezone.InstanceWorld;
  34. import com.l2jserver.gameserver.model.quest.Quest;
  35. import com.l2jserver.gameserver.model.skills.L2Skill;
  36. import com.l2jserver.gameserver.network.NpcStringId;
  37. import com.l2jserver.gameserver.network.SystemMessageId;
  38. import com.l2jserver.gameserver.network.clientpackets.Say2;
  39. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  40. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  41. import com.l2jserver.gameserver.util.Util;
  42. /**
  43. * Urban Area instance zone.
  44. * @author GKR
  45. */
  46. public class HellboundTown extends Quest
  47. {
  48. protected class TownWorld extends InstanceWorld
  49. {
  50. protected L2MonsterInstance spawnedAmaskari;
  51. protected ScheduledFuture<?> activeAmaskariCall = null;
  52. public boolean isAmaskariDead = false;
  53. }
  54. private static final String qn = "HellboundTown";
  55. private static final int INSTANCEID = 2;
  56. private static final NpcStringId[] NPCSTRING_ID =
  57. {
  58. NpcStringId.INVADER,
  59. NpcStringId.YOU_HAVE_DONE_WELL_IN_FINDING_ME_BUT_I_CANNOT_JUST_HAND_YOU_THE_KEY
  60. };
  61. private static final NpcStringId[] NATIVES_NPCSTRING_ID =
  62. {
  63. NpcStringId.THANK_YOU_FOR_SAVING_ME,
  64. NpcStringId.GUARDS_ARE_COMING_RUN,
  65. NpcStringId.NOW_I_CAN_ESCAPE_ON_MY_OWN
  66. };
  67. private static final int TOMBSTONE = 32343;
  68. private static final int KANAF = 32346;
  69. private static final int KEYMASTER = 22361;
  70. private static final int AMASKARI = 22449;
  71. private static final int DOWNTOWN_NATIVE = 32358;
  72. private static final int TOWN_GUARD = 22359;
  73. private static final int TOWN_PATROL = 22360;
  74. private static final Location AMASKARI_SPAWN_POINT = new Location(19424, 253360, -2032, 16860);
  75. private static final Location ENTRY_POINT = new Location(14117, 255434, -2016);
  76. protected static final Location EXIT_POINT = new Location(16262, 283651, -9700);
  77. private static final SkillHolder STONE = new SkillHolder(4616, 1);
  78. private static final int KEY = 9714;
  79. public HellboundTown(int questId, String name, String descr)
  80. {
  81. super(questId, name, descr);
  82. addFirstTalkId(DOWNTOWN_NATIVE);
  83. addStartNpc(KANAF);
  84. addStartNpc(DOWNTOWN_NATIVE);
  85. addTalkId(KANAF);
  86. addTalkId(DOWNTOWN_NATIVE);
  87. addAttackId(TOWN_GUARD);
  88. addAttackId(KEYMASTER);
  89. addAggroRangeEnterId(TOWN_GUARD);
  90. addKillId(AMASKARI);
  91. addSpawnId(DOWNTOWN_NATIVE);
  92. addSpawnId(TOWN_GUARD);
  93. addSpawnId(TOWN_PATROL);
  94. addSpawnId(KEYMASTER);
  95. }
  96. @Override
  97. public final String onFirstTalk(L2Npc npc, L2PcInstance player)
  98. {
  99. if (npc.getFirstEffect(STONE.getSkill()) == null)
  100. {
  101. return "32358-02.htm";
  102. }
  103. return "32358-01.htm";
  104. }
  105. @Override
  106. public String onTalk(L2Npc npc, L2PcInstance player)
  107. {
  108. String htmltext = null;
  109. if (npc.getId() == KANAF)
  110. {
  111. htmltext = checkConditions(player);
  112. if (htmltext == null)
  113. {
  114. enterInstance(player, "HellboundTown.xml");
  115. }
  116. }
  117. else if (npc.getId() == TOMBSTONE)
  118. {
  119. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  120. if ((tmpworld != null) && (tmpworld instanceof TownWorld))
  121. {
  122. TownWorld world = (TownWorld) tmpworld;
  123. L2Party party = player.getParty();
  124. if (party == null)
  125. {
  126. htmltext = "32343-02.htm";
  127. }
  128. else if (npc.isBusy())
  129. {
  130. htmltext = "32343-02c.htm";
  131. }
  132. else if (player.getInventory().getInventoryItemCount(KEY, -1, false) >= 1)
  133. {
  134. for (L2PcInstance partyMember : party.getMembers())
  135. {
  136. if (!Util.checkIfInRange(300, npc, partyMember, true))
  137. {
  138. return "32343-02b.htm";
  139. }
  140. }
  141. if (player.destroyItemByItemId("Quest", KEY, 1, npc, true))
  142. {
  143. npc.setBusy(true);
  144. // destroy instance after 5 min
  145. Instance inst = InstanceManager.getInstance().getInstance(world.getInstanceId());
  146. inst.setDuration(5 * 60000);
  147. inst.setEmptyDestroyTime(0);
  148. ThreadPoolManager.getInstance().scheduleGeneral(new ExitInstance(party, world), 285000);
  149. htmltext = "32343-02d.htm";
  150. }
  151. }
  152. else
  153. {
  154. htmltext = "32343-02a.htm";
  155. }
  156. }
  157. }
  158. return htmltext;
  159. }
  160. @Override
  161. public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  162. {
  163. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  164. if ((tmpworld != null) && (tmpworld instanceof TownWorld))
  165. {
  166. TownWorld world = (TownWorld) tmpworld;
  167. if (npc.getId() == DOWNTOWN_NATIVE)
  168. {
  169. if (event.equalsIgnoreCase("rebuff") && !world.isAmaskariDead)
  170. {
  171. STONE.getSkill().getEffects(npc, npc);
  172. }
  173. else if (event.equalsIgnoreCase("break_chains"))
  174. {
  175. if ((npc.getFirstEffect(STONE.getSkill()) == null) || world.isAmaskariDead)
  176. {
  177. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npc.getId(), NATIVES_NPCSTRING_ID[0]));
  178. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npc.getId(), NATIVES_NPCSTRING_ID[2]));
  179. }
  180. else
  181. {
  182. cancelQuestTimer("rebuff", npc, null);
  183. for (L2Effect e : npc.getAllEffects())
  184. {
  185. if (e.getSkill() == STONE.getSkill())
  186. {
  187. e.exit();
  188. }
  189. }
  190. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npc.getId(), NATIVES_NPCSTRING_ID[0]));
  191. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npc.getId(), NATIVES_NPCSTRING_ID[1]));
  192. HellboundManager.getInstance().updateTrust(10, true);
  193. npc.scheduleDespawn(3000);
  194. // Try to call Amaskari
  195. if ((world.spawnedAmaskari != null) && !world.spawnedAmaskari.isDead() && (getRandom(1000) < 25) && Util.checkIfInRange(5000, npc, world.spawnedAmaskari, false))
  196. {
  197. if (world.activeAmaskariCall != null)
  198. {
  199. world.activeAmaskariCall.cancel(true);
  200. }
  201. world.activeAmaskariCall = ThreadPoolManager.getInstance().scheduleGeneral(new CallAmaskari(npc), 25000);
  202. }
  203. }
  204. }
  205. }
  206. }
  207. return null;
  208. }
  209. @Override
  210. public final String onSpawn(L2Npc npc)
  211. {
  212. if (npc.getId() == DOWNTOWN_NATIVE)
  213. {
  214. ((L2QuestGuardInstance) npc).setPassive(true);
  215. ((L2QuestGuardInstance) npc).setAutoAttackable(false);
  216. STONE.getSkill().getEffects(npc, npc);
  217. startQuestTimer("rebuff", 357000, npc, null);
  218. }
  219. else if ((npc.getId() == TOWN_GUARD) || (npc.getId() == KEYMASTER))
  220. {
  221. npc.setBusy(false);
  222. npc.setBusyMessage("");
  223. }
  224. return super.onSpawn(npc);
  225. }
  226. @Override
  227. public String onAggroRangeEnter(L2Npc npc, L2PcInstance player, boolean isSummon)
  228. {
  229. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  230. if ((tmpworld != null) && (tmpworld instanceof TownWorld))
  231. {
  232. TownWorld world = (TownWorld) tmpworld;
  233. if (!npc.isBusy())
  234. {
  235. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npc.getId(), NPCSTRING_ID[0]));
  236. npc.setBusy(true);
  237. if ((world.spawnedAmaskari != null) && !world.spawnedAmaskari.isDead() && (getRandom(1000) < 25) && Util.checkIfInRange(1000, npc, world.spawnedAmaskari, false))
  238. {
  239. if (world.activeAmaskariCall != null)
  240. {
  241. world.activeAmaskariCall.cancel(true);
  242. }
  243. world.activeAmaskariCall = ThreadPoolManager.getInstance().scheduleGeneral(new CallAmaskari(npc), 25000);
  244. }
  245. }
  246. }
  247. return super.onAggroRangeEnter(npc, player, isSummon);
  248. }
  249. @Override
  250. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon, L2Skill skill)
  251. {
  252. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  253. if ((tmpworld != null) && (tmpworld instanceof TownWorld))
  254. {
  255. TownWorld world = (TownWorld) tmpworld;
  256. if (!world.isAmaskariDead && !(npc.getBusyMessage().equalsIgnoreCase("atk") || npc.isBusy()))
  257. {
  258. int msgId;
  259. int range;
  260. switch (npc.getId())
  261. {
  262. case TOWN_GUARD:
  263. msgId = 0;
  264. range = 1000;
  265. break;
  266. case KEYMASTER:
  267. msgId = 1;
  268. range = 5000;
  269. break;
  270. default:
  271. msgId = -1;
  272. range = 0;
  273. }
  274. if (msgId >= 0)
  275. {
  276. npc.broadcastPacket(new NpcSay(npc.getObjectId(), Say2.NPC_ALL, npc.getId(), NPCSTRING_ID[msgId]));
  277. }
  278. npc.setBusy(true);
  279. npc.setBusyMessage("atk");
  280. if ((world.spawnedAmaskari != null) && !world.spawnedAmaskari.isDead() && (getRandom(1000) < 25) && Util.checkIfInRange(range, npc, world.spawnedAmaskari, false))
  281. {
  282. if (world.activeAmaskariCall != null)
  283. {
  284. world.activeAmaskariCall.cancel(true);
  285. }
  286. world.activeAmaskariCall = ThreadPoolManager.getInstance().scheduleGeneral(new CallAmaskari(npc), 25000);
  287. }
  288. }
  289. }
  290. return super.onAttack(npc, attacker, damage, isSummon, skill);
  291. }
  292. @Override
  293. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  294. {
  295. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  296. if ((tmpworld != null) && (tmpworld instanceof TownWorld))
  297. {
  298. TownWorld world = (TownWorld) tmpworld;
  299. world.isAmaskariDead = true;
  300. }
  301. return super.onKill(npc, killer, isSummon);
  302. }
  303. private String checkConditions(L2PcInstance player)
  304. {
  305. if (HellboundManager.getInstance().getLevel() < 10)
  306. {
  307. return "32346-lvl.htm";
  308. }
  309. if (player.getParty() == null)
  310. {
  311. return "32346-party.htm";
  312. }
  313. return null;
  314. }
  315. private boolean checkTeleport(L2PcInstance player)
  316. {
  317. L2Party party = player.getParty();
  318. if (party == null)
  319. {
  320. return false;
  321. }
  322. if (player.getObjectId() != party.getLeaderObjectId())
  323. {
  324. player.sendPacket(SystemMessageId.ONLY_PARTY_LEADER_CAN_ENTER);
  325. return false;
  326. }
  327. for (L2PcInstance partyMember : party.getMembers())
  328. {
  329. if (partyMember.getLevel() < 78)
  330. {
  331. final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_LEVEL_REQUIREMENT_NOT_SUFFICIENT);
  332. sm.addPcName(partyMember);
  333. party.broadcastPacket(sm);
  334. return false;
  335. }
  336. if (!Util.checkIfInRange(1000, player, partyMember, true))
  337. {
  338. final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_LOCATION_THAT_CANNOT_BE_ENTERED);
  339. sm.addPcName(partyMember);
  340. party.broadcastPacket(sm);
  341. return false;
  342. }
  343. if (InstanceManager.getInstance().getPlayerWorld(player) != null)
  344. {
  345. final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER);
  346. sm.addPcName(partyMember);
  347. party.broadcastPacket(sm);
  348. return false;
  349. }
  350. }
  351. return true;
  352. }
  353. private int enterInstance(L2PcInstance player, String template)
  354. {
  355. int instanceId = 0;
  356. // check for existing instances for this player
  357. InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  358. // existing instance
  359. if (world != null)
  360. {
  361. if (!(world instanceof TownWorld))
  362. {
  363. player.sendPacket(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER);
  364. return 0;
  365. }
  366. teleportPlayer(player, ENTRY_POINT, world.getInstanceId());
  367. return world.getInstanceId();
  368. }
  369. if (!checkTeleport(player))
  370. {
  371. return 0;
  372. }
  373. instanceId = InstanceManager.getInstance().createDynamicInstance(template);
  374. world = new TownWorld();
  375. world.setInstanceId(instanceId);
  376. world.setTemplateId(INSTANCEID);
  377. world.setStatus(0);
  378. InstanceManager.getInstance().addWorld(world);
  379. _log.info("Hellbound Town started " + template + " Instance: " + instanceId + " created by player: " + player.getName());
  380. for (L2PcInstance partyMember : player.getParty().getMembers())
  381. {
  382. teleportPlayer(partyMember, ENTRY_POINT, instanceId);
  383. world.addAllowed(partyMember.getObjectId());
  384. }
  385. ((TownWorld) world).spawnedAmaskari = (L2MonsterInstance) addSpawn(AMASKARI, AMASKARI_SPAWN_POINT, false, 0, false, instanceId);
  386. return instanceId;
  387. }
  388. private static class CallAmaskari implements Runnable
  389. {
  390. private final L2Npc _caller;
  391. public CallAmaskari(L2Npc caller)
  392. {
  393. _caller = caller;
  394. }
  395. @Override
  396. public void run()
  397. {
  398. if ((_caller != null) && !_caller.isDead())
  399. {
  400. InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(_caller.getInstanceId());
  401. if ((tmpworld != null) && (tmpworld instanceof TownWorld))
  402. {
  403. TownWorld world = (TownWorld) tmpworld;
  404. if ((world.spawnedAmaskari != null) && !world.spawnedAmaskari.isDead())
  405. {
  406. world.spawnedAmaskari.teleToLocation(_caller.getX(), _caller.getY(), _caller.getZ());
  407. world.spawnedAmaskari.broadcastPacket(new NpcSay(world.spawnedAmaskari.getObjectId(), Say2.NPC_ALL, world.spawnedAmaskari.getId(), NpcStringId.ILL_MAKE_YOU_FEEL_SUFFERING_LIKE_A_FLAME_THAT_IS_NEVER_EXTINGUISHED));
  408. }
  409. }
  410. }
  411. }
  412. }
  413. private class ExitInstance implements Runnable
  414. {
  415. private final L2Party _party;
  416. private final TownWorld _world;
  417. public ExitInstance(L2Party party, TownWorld world)
  418. {
  419. _party = party;
  420. _world = world;
  421. }
  422. @Override
  423. public void run()
  424. {
  425. if ((_party != null) && (_world != null))
  426. {
  427. for (L2PcInstance partyMember : _party.getMembers())
  428. {
  429. if ((partyMember != null) && !partyMember.isDead())
  430. {
  431. _world.removeAllowed(partyMember.getObjectId());
  432. teleportPlayer(partyMember, EXIT_POINT, 0);
  433. }
  434. }
  435. }
  436. }
  437. }
  438. public static void main(String[] args)
  439. {
  440. new HellboundTown(-1, qn, "instances");
  441. }
  442. }