UrbanArea.java 14 KB

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