PailakaDevilsLegacy.java 10 KB

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