HellboundTown.java 16 KB

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