PailakaSongOfIceAndFire.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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.PailakaSongOfIceAndFire;
  20. import ai.npc.AbstractNpcAI;
  21. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  22. import com.l2jserver.gameserver.model.Location;
  23. import com.l2jserver.gameserver.model.actor.L2Character;
  24. import com.l2jserver.gameserver.model.actor.L2Npc;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.instancezone.InstanceWorld;
  27. import com.l2jserver.gameserver.model.zone.L2ZoneType;
  28. import com.l2jserver.gameserver.network.NpcStringId;
  29. import com.l2jserver.gameserver.network.SystemMessageId;
  30. import com.l2jserver.gameserver.network.clientpackets.Say2;
  31. /**
  32. * Pailaka Song of Ice and Fire Instance zone.
  33. * @author Gnacik, St3eT
  34. */
  35. public final class PailakaSongOfIceAndFire extends AbstractNpcAI
  36. {
  37. protected class PSoIWorld extends InstanceWorld
  38. {
  39. }
  40. // NPCs
  41. private static final int ADLER1 = 32497;
  42. private static final int GARGOS = 18607;
  43. private static final int BLOOM = 18616;
  44. private static final int BOTTLE = 32492;
  45. private static final int BRAZIER = 32493;
  46. // Items
  47. private static final int FIRE_ENHANCER = 13040;
  48. private static final int WATER_ENHANCER = 13041;
  49. private static final int SHIELD_POTION = 13032;
  50. private static final int HEAL_POTION = 13033;
  51. // Location
  52. private static final Location TELEPORT = new Location(-52875, 188232, -4696);
  53. // Misc
  54. private static final int TEMPLATE_ID = 43;
  55. private static final int ZONE = 20108;
  56. private PailakaSongOfIceAndFire()
  57. {
  58. super(PailakaSongOfIceAndFire.class.getSimpleName(), "instances");
  59. addStartNpc(ADLER1);
  60. addTalkId(ADLER1);
  61. addAttackId(BOTTLE, BRAZIER);
  62. addExitZoneId(ZONE);
  63. addSeeCreatureId(GARGOS);
  64. addSpawnId(BLOOM);
  65. addKillId(BLOOM);
  66. }
  67. private void enterInstance(L2PcInstance player, String template)
  68. {
  69. InstanceWorld world = InstanceManager.getInstance().getPlayerWorld(player);
  70. if (world != null)
  71. {
  72. if (world instanceof PSoIWorld)
  73. {
  74. teleportPlayer(player, TELEPORT, world.getInstanceId());
  75. return;
  76. }
  77. player.sendPacket(SystemMessageId.ALREADY_ENTERED_ANOTHER_INSTANCE_CANT_ENTER);
  78. return;
  79. }
  80. world = new PSoIWorld();
  81. world.setInstanceId(InstanceManager.getInstance().createDynamicInstance(template));
  82. world.setTemplateId(TEMPLATE_ID);
  83. InstanceManager.getInstance().addWorld(world);
  84. world.addAllowed(player.getObjectId());
  85. teleportPlayer(player, TELEPORT, world.getInstanceId());
  86. _log.info("Pailaka Song of Ice and Fire" + template + " Instance: " + world.getInstanceId() + " created by player: " + player.getName());
  87. }
  88. @Override
  89. public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  90. {
  91. switch (event)
  92. {
  93. case "enter":
  94. {
  95. enterInstance(player, "PailakaSongOfIceAndFire.xml");
  96. break;
  97. }
  98. case "GARGOS_LAUGH":
  99. {
  100. broadcastNpcSay(npc, Say2.NPC_SHOUT, NpcStringId.OHHOHOH);
  101. break;
  102. }
  103. case "TELEPORT":
  104. {
  105. teleportPlayer(player, TELEPORT, player.getInstanceId());
  106. break;
  107. }
  108. case "DELETE":
  109. {
  110. if (npc != null)
  111. {
  112. npc.deleteMe();
  113. }
  114. break;
  115. }
  116. case "BLOOM_TIMER":
  117. {
  118. startQuestTimer("BLOOM_TIMER2", getRandom(2, 4) * 60 * 1000, npc, null);
  119. break;
  120. }
  121. case "BLOOM_TIMER2":
  122. {
  123. npc.setInvisible(!npc.isInvisible());
  124. startQuestTimer("BLOOM_TIMER", 5000, npc, null);
  125. break;
  126. }
  127. }
  128. return super.onAdvEvent(event, npc, player);
  129. }
  130. @Override
  131. public final String onAttack(L2Npc npc, L2PcInstance player, int damage, boolean isSummon)
  132. {
  133. if ((damage > 0) && npc.isScriptValue(0))
  134. {
  135. switch (getRandom(6))
  136. {
  137. case 0:
  138. {
  139. if (npc.getId() == BOTTLE)
  140. {
  141. npc.dropItem(player, WATER_ENHANCER, getRandom(1, 6));
  142. }
  143. break;
  144. }
  145. case 1:
  146. {
  147. if (npc.getId() == BRAZIER)
  148. {
  149. npc.dropItem(player, FIRE_ENHANCER, getRandom(1, 6));
  150. }
  151. break;
  152. }
  153. case 2:
  154. case 3:
  155. {
  156. npc.dropItem(player, SHIELD_POTION, getRandom(1, 10));
  157. break;
  158. }
  159. case 4:
  160. case 5:
  161. {
  162. npc.dropItem(player, HEAL_POTION, getRandom(1, 10));
  163. break;
  164. }
  165. }
  166. npc.setScriptValue(1);
  167. startQuestTimer("DELETE", 3000, npc, null);
  168. }
  169. return super.onAttack(npc, player, damage, isSummon);
  170. }
  171. @Override
  172. public final String onKill(L2Npc npc, L2PcInstance player, boolean isSummon)
  173. {
  174. npc.dropItem(player, getRandomBoolean() ? SHIELD_POTION : HEAL_POTION, getRandom(1, 7));
  175. return super.onKill(npc, player, isSummon);
  176. }
  177. @Override
  178. public String onExitZone(L2Character character, L2ZoneType zone)
  179. {
  180. if ((character.isPlayer()) && !character.isDead() && !character.isTeleporting() && ((L2PcInstance) character).isOnline())
  181. {
  182. final InstanceWorld world = InstanceManager.getInstance().getWorld(character.getInstanceId());
  183. if ((world != null) && (world.getTemplateId() == TEMPLATE_ID))
  184. {
  185. startQuestTimer("TELEPORT", 1000, null, (L2PcInstance) character);
  186. }
  187. }
  188. return super.onExitZone(character, zone);
  189. }
  190. @Override
  191. public String onSeeCreature(L2Npc npc, L2Character creature, boolean isSummon)
  192. {
  193. if (npc.isScriptValue(0) && creature.isPlayer())
  194. {
  195. npc.setScriptValue(1);
  196. startQuestTimer("GARGOS_LAUGH", 1000, npc, creature.getActingPlayer());
  197. }
  198. return super.onSeeCreature(npc, creature, isSummon);
  199. }
  200. @Override
  201. public String onSpawn(L2Npc npc)
  202. {
  203. npc.setInvisible(true);
  204. startQuestTimer("BLOOM_TIMER", 1000, npc, null);
  205. return super.onSpawn(npc);
  206. }
  207. public static void main(String[] args)
  208. {
  209. new PailakaSongOfIceAndFire();
  210. }
  211. }