PailakaDevilsLegacy.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /*
  2. * Copyright (C) 2004-2014 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.PailakaDevilsLegacy;
  20. import java.util.List;
  21. import java.util.concurrent.CopyOnWriteArrayList;
  22. import quests.Q00129_PailakaDevilsLegacy.Q00129_PailakaDevilsLegacy;
  23. import ai.npc.AbstractNpcAI;
  24. import com.l2jserver.gameserver.ai.CtrlIntention;
  25. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  26. import com.l2jserver.gameserver.model.Location;
  27. import com.l2jserver.gameserver.model.actor.L2Attackable;
  28. import com.l2jserver.gameserver.model.actor.L2Character;
  29. import com.l2jserver.gameserver.model.actor.L2Npc;
  30. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  31. import com.l2jserver.gameserver.model.holders.SkillHolder;
  32. import com.l2jserver.gameserver.model.instancezone.InstanceWorld;
  33. import com.l2jserver.gameserver.model.quest.QuestState;
  34. import com.l2jserver.gameserver.model.zone.L2ZoneType;
  35. import com.l2jserver.gameserver.network.SystemMessageId;
  36. /**
  37. * Pailaka Devil's Legacy Instance zone.
  38. * @author St3eT
  39. */
  40. public final class PailakaDevilsLegacy extends AbstractNpcAI
  41. {
  42. protected class DIWorld extends InstanceWorld
  43. {
  44. L2Attackable _lematanNpc = null;
  45. List<L2Attackable> _followerslist = new CopyOnWriteArrayList<>();
  46. }
  47. // NPCs
  48. private static final int LEMATAN = 18633; // Lematan
  49. private static final int SURVIVOR = 32498; // Devil's Isle Survivor
  50. private static final int FOLLOWERS = 18634; // Lematan's Follower
  51. private static final int POWDER_KEG = 18622; // Powder Keg
  52. private static final int TREASURE_BOX = 32495; // Treasure Chest
  53. private static final int ADVENTURER2 = 32511; // Dwarf Adventurer
  54. // Items
  55. private static final int ANTIDOTE_POTION = 13048; // Pailaka Antidote
  56. private static final int DIVINE_POTION = 13049; // Divine Soul
  57. private static final int PAILAKA_KEY = 13150; // Pailaka All-Purpose Key
  58. private static final int SHIELD = 13032; // Pailaka Instant Shield
  59. private static final int DEFENCE_POTION = 13059; // Long-Range Defense Increasing Potion
  60. private static final int HEALING_POTION = 13033; // Quick Healing Potion
  61. // Skills
  62. private static final SkillHolder ENERGY = new SkillHolder(5712, 1); // Energy Ditch
  63. private static final SkillHolder BOOM = new SkillHolder(5714, 1); // Boom Up
  64. private static final SkillHolder AV_TELEPORT = new SkillHolder(4671, 1); // AV - Teleport
  65. // Locations
  66. private static final Location TELEPORT = new Location(76427, -219045, -3780);
  67. private static final Location LEMATAN_SPAWN = new Location(88108, -209252, -3744, 6425);
  68. private static final Location LEMATAN_PORT_POINT = new Location(86116, -209117, -3774);
  69. private static final Location LEMATAN_PORT = new Location(85000, -208699, -3336);
  70. private static final Location ADVENTURER_LOC = new Location(84983, -208736, -3336, 49915);
  71. private static final Location[] FOLLOWERS_LOC =
  72. {
  73. new Location(85067, -208943, -3336, 20106),
  74. new Location(84904, -208944, -3336, 10904),
  75. new Location(85062, -208538, -3336, 44884),
  76. new Location(84897, -208542, -3336, 52973),
  77. new Location(84808, -208633, -3339, 65039),
  78. new Location(84808, -208856, -3339, 0),
  79. new Location(85144, -208855, -3341, 33380),
  80. new Location(85139, -208630, -3339, 31777),
  81. };
  82. // Misc
  83. private static final int TEMPLATE_ID = 44;
  84. private static final int ZONE = 20109;
  85. private PailakaDevilsLegacy()
  86. {
  87. super(PailakaDevilsLegacy.class.getSimpleName(), "instances");
  88. addTalkId(SURVIVOR);
  89. addAttackId(POWDER_KEG, TREASURE_BOX, LEMATAN);
  90. addKillId(LEMATAN);
  91. addSpawnId(FOLLOWERS);
  92. addEnterZoneId(ZONE);
  93. addMoveFinishedId(LEMATAN);
  94. }
  95. @Override
  96. public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  97. {
  98. final InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  99. String htmltext = null;
  100. if (event.equals("enter"))
  101. {
  102. final QuestState qs = player.getQuestState(Q00129_PailakaDevilsLegacy.class.getSimpleName());
  103. enterInstance(player, "PailakaDevilsLegacy.xml");
  104. if (qs.isCond(1))
  105. {
  106. qs.setCond(2, true);
  107. htmltext = "32498-01.htm";
  108. }
  109. else
  110. {
  111. htmltext = "32498-02.htm";
  112. }
  113. }
  114. else if ((tmpworld != null) && (tmpworld instanceof DIWorld))
  115. {
  116. final DIWorld world = (DIWorld) tmpworld;
  117. switch (event)
  118. {
  119. case "FOLLOWER_CAST":
  120. {
  121. if ((world._lematanNpc != null) && !world._lematanNpc.isDead())
  122. {
  123. for (L2Attackable follower : world._followerslist)
  124. {
  125. follower.setTarget(world._lematanNpc);
  126. follower.doCast(ENERGY.getSkill());
  127. }
  128. startQuestTimer("FOLLOWER_CAST", 15000, world._lematanNpc, null);
  129. }
  130. break;
  131. }
  132. case "LEMATAN_TELEPORT":
  133. {
  134. ((L2Attackable) npc).clearAggroList();
  135. npc.disableCoreAI(false);
  136. npc.teleToLocation(LEMATAN_PORT);
  137. npc.getVariables().set("ON_SHIP", 1);
  138. npc.getSpawn().setLocation(LEMATAN_PORT);
  139. for (Location loc : FOLLOWERS_LOC)
  140. {
  141. final L2Attackable follower = (L2Attackable) addSpawn(FOLLOWERS, loc, false, 0, false, world.getInstanceId());
  142. follower.disableCoreAI(true);
  143. follower.setIsImmobilized(true);
  144. world._followerslist.add(follower);
  145. }
  146. startQuestTimer("FOLLOWER_CAST", 4000, world._lematanNpc, null);
  147. break;
  148. }
  149. case "TELEPORT":
  150. {
  151. player.teleToLocation(TELEPORT);
  152. break;
  153. }
  154. case "DELETE":
  155. {
  156. npc.deleteMe();
  157. break;
  158. }
  159. }
  160. }
  161. return htmltext;
  162. }
  163. @Override
  164. public final String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon)
  165. {
  166. final InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  167. if ((tmpworld != null) && (tmpworld instanceof DIWorld))
  168. {
  169. switch (npc.getId())
  170. {
  171. case POWDER_KEG:
  172. {
  173. if ((damage > 0) && npc.isScriptValue(0))
  174. {
  175. for (L2Character characters : npc.getKnownList().getKnownCharactersInRadius(600))
  176. {
  177. if ((characters != null) && characters.isMonster())
  178. {
  179. final L2Attackable monster = (L2Attackable) characters;
  180. monster.addDamageHate(npc, 0, 999);
  181. monster.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, npc);
  182. monster.reduceCurrentHp(500 + getRandom(0, 200), npc, BOOM.getSkill());
  183. }
  184. }
  185. npc.doCast(BOOM.getSkill());
  186. npc.setScriptValue(1);
  187. startQuestTimer("DELETE", 2000, npc, null);
  188. }
  189. break;
  190. }
  191. case LEMATAN:
  192. {
  193. if (npc.isScriptValue(0) && (npc.getCurrentHp() < (npc.getMaxHp() * 0.5)))
  194. {
  195. npc.disableCoreAI(true);
  196. npc.setScriptValue(1);
  197. npc.setIsRunning(true);
  198. npc.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, LEMATAN_PORT_POINT);
  199. }
  200. break;
  201. }
  202. case TREASURE_BOX:
  203. {
  204. if (npc.isScriptValue(0))
  205. {
  206. switch (getRandom(7))
  207. {
  208. case 0:
  209. case 1:
  210. {
  211. npc.dropItem(attacker, ANTIDOTE_POTION, getRandom(1, 10));
  212. break;
  213. }
  214. case 2:
  215. {
  216. npc.dropItem(attacker, DIVINE_POTION, getRandom(1, 5));
  217. break;
  218. }
  219. case 3:
  220. {
  221. npc.dropItem(attacker, PAILAKA_KEY, getRandom(1, 2));
  222. break;
  223. }
  224. case 4:
  225. {
  226. npc.dropItem(attacker, DEFENCE_POTION, getRandom(1, 7));
  227. break;
  228. }
  229. case 5:
  230. {
  231. npc.dropItem(attacker, SHIELD, getRandom(1, 10));
  232. break;
  233. }
  234. case 6:
  235. {
  236. npc.dropItem(attacker, HEALING_POTION, getRandom(1, 10));
  237. break;
  238. }
  239. }
  240. npc.setScriptValue(1);
  241. startQuestTimer("DELETE", 3000, npc, attacker);
  242. }
  243. break;
  244. }
  245. }
  246. }
  247. return super.onAttack(npc, attacker, damage, isSummon);
  248. }
  249. @Override
  250. public final String onKill(L2Npc npc, L2PcInstance player, boolean isSummon)
  251. {
  252. final InstanceWorld tmpworld = InstanceManager.getInstance().getWorld(npc.getInstanceId());
  253. if ((tmpworld != null) && (tmpworld instanceof DIWorld))
  254. {
  255. final DIWorld world = (DIWorld) tmpworld;
  256. if (world._followerslist != null)
  257. {
  258. for (L2Npc _follower : world._followerslist)
  259. {
  260. _follower.deleteMe();
  261. }
  262. world._followerslist.clear();
  263. }
  264. addSpawn(ADVENTURER2, ADVENTURER_LOC, false, 0, false, npc.getInstanceId());
  265. }
  266. return super.onKill(npc, player, isSummon);
  267. }
  268. @Override
  269. public String onEnterZone(L2Character character, L2ZoneType zone)
  270. {
  271. if ((character.isPlayer()) && !character.isDead() && !character.isTeleporting() && ((L2PcInstance) character).isOnline())
  272. {
  273. final InstanceWorld world = InstanceManager.getInstance().getWorld(character.getInstanceId());
  274. if ((world != null) && (world.getTemplateId() == TEMPLATE_ID))
  275. {
  276. startQuestTimer("TELEPORT", 1000, ((DIWorld) world)._lematanNpc, (L2PcInstance) character);
  277. }
  278. }
  279. return super.onEnterZone(character, zone);
  280. }
  281. @Override
  282. public void onMoveFinished(L2Npc npc)
  283. {
  284. if (npc.getLocation() == LEMATAN_PORT_POINT)
  285. {
  286. npc.doCast(AV_TELEPORT.getSkill());
  287. startQuestTimer("LEMATAN_TELEPORT", 2000, npc, null);
  288. }
  289. }
  290. private void enterInstance(L2PcInstance player, String template)
  291. {
  292. InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  293. if (world != null)
  294. {
  295. if (world instanceof DIWorld)
  296. {
  297. teleportPlayer(player, TELEPORT, world.getInstanceId());
  298. return;
  299. }
  300. player.sendPacket(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER);
  301. return;
  302. }
  303. world = new DIWorld();
  304. world.setInstanceId(InstanceManager.getInstance().createDynamicInstance(template));
  305. world.setTemplateId(TEMPLATE_ID);
  306. InstanceManager.getInstance().addWorld(world);
  307. world.addAllowed(player.getObjectId());
  308. teleportPlayer(player, TELEPORT, world.getInstanceId());
  309. ((DIWorld) world)._lematanNpc = (L2Attackable) addSpawn(LEMATAN, LEMATAN_SPAWN, false, 0, false, world.getInstanceId());
  310. _log.info("Pailaka Devils Legacy" + template + " Instance: " + world.getInstanceId() + " created by player: " + player.getName());
  311. }
  312. public static void main(String[] args)
  313. {
  314. new PailakaDevilsLegacy();
  315. }
  316. }