UrbanArea.java 15 KB

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