DarkWaterDragon.java 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * Copyright (C) 2004-2013 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 ai.individual;
  20. import java.util.Map;
  21. import java.util.Set;
  22. import javolution.util.FastSet;
  23. import ai.npc.AbstractNpcAI;
  24. import com.l2jserver.gameserver.ai.CtrlIntention;
  25. import com.l2jserver.gameserver.datatables.NpcTable;
  26. import com.l2jserver.gameserver.model.actor.L2Attackable;
  27. import com.l2jserver.gameserver.model.actor.L2Character;
  28. import com.l2jserver.gameserver.model.actor.L2Npc;
  29. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  30. import com.l2jserver.util.L2FastMap;
  31. /**
  32. * Dark Water Dragon's AI.
  33. */
  34. public class DarkWaterDragon extends AbstractNpcAI
  35. {
  36. private static final int DRAGON = 22267;
  37. private static final int SHADE1 = 22268;
  38. private static final int SHADE2 = 22269;
  39. private static final int FAFURION = 18482;
  40. private static final int DETRACTOR1 = 22270;
  41. private static final int DETRACTOR2 = 22271;
  42. private static Set<Integer> SECOND_SPAWN = new FastSet<>(); // Used to track if second Shades were already spawned
  43. private static Set<Integer> MY_TRACKING_SET = new FastSet<>(); // Used to track instances of npcs
  44. private static Map<Integer, L2PcInstance> ID_MAP = new L2FastMap<>(true); // Used to track instances of npcs
  45. private DarkWaterDragon(String name, String descr)
  46. {
  47. super(name, descr);
  48. int[] mobs =
  49. {
  50. DRAGON,
  51. SHADE1,
  52. SHADE2,
  53. FAFURION,
  54. DETRACTOR1,
  55. DETRACTOR2
  56. };
  57. registerMobs(mobs, QuestEventType.ON_KILL, QuestEventType.ON_SPAWN, QuestEventType.ON_ATTACK);
  58. MY_TRACKING_SET.clear();
  59. SECOND_SPAWN.clear();
  60. }
  61. @Override
  62. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  63. {
  64. if (npc != null)
  65. {
  66. if (event.equalsIgnoreCase("first_spawn")) // timer to start timer "1"
  67. {
  68. startQuestTimer("1", 40000, npc, null, true); // spawns detractor every 40 seconds
  69. }
  70. else if (event.equalsIgnoreCase("second_spawn")) // timer to start timer "2"
  71. {
  72. startQuestTimer("2", 40000, npc, null, true); // spawns detractor every 40 seconds
  73. }
  74. else if (event.equalsIgnoreCase("third_spawn")) // timer to start timer "3"
  75. {
  76. startQuestTimer("3", 40000, npc, null, true); // spawns detractor every 40 seconds
  77. }
  78. else if (event.equalsIgnoreCase("fourth_spawn")) // timer to start timer "4"
  79. {
  80. startQuestTimer("4", 40000, npc, null, true); // spawns detractor every 40 seconds
  81. }
  82. else if (event.equalsIgnoreCase("1")) // spawns a detractor
  83. {
  84. addSpawn(DETRACTOR1, (npc.getX() + 100), (npc.getY() + 100), npc.getZ(), 0, false, 40000);
  85. }
  86. else if (event.equalsIgnoreCase("2")) // spawns a detractor
  87. {
  88. addSpawn(DETRACTOR2, (npc.getX() + 100), (npc.getY() - 100), npc.getZ(), 0, false, 40000);
  89. }
  90. else if (event.equalsIgnoreCase("3")) // spawns a detractor
  91. {
  92. addSpawn(DETRACTOR1, (npc.getX() - 100), (npc.getY() + 100), npc.getZ(), 0, false, 40000);
  93. }
  94. else if (event.equalsIgnoreCase("4")) // spawns a detractor
  95. {
  96. addSpawn(DETRACTOR2, (npc.getX() - 100), (npc.getY() - 100), npc.getZ(), 0, false, 40000);
  97. }
  98. else if (event.equalsIgnoreCase("fafurion_despawn")) // Fafurion Kindred disappears and drops reward
  99. {
  100. cancelQuestTimer("fafurion_poison", npc, null);
  101. cancelQuestTimer("1", npc, null);
  102. cancelQuestTimer("2", npc, null);
  103. cancelQuestTimer("3", npc, null);
  104. cancelQuestTimer("4", npc, null);
  105. MY_TRACKING_SET.remove(npc.getObjectId());
  106. player = ID_MAP.remove(npc.getObjectId());
  107. if (player != null)
  108. {
  109. ((L2Attackable) npc).doItemDrop(NpcTable.getInstance().getTemplate(18485), player);
  110. }
  111. npc.deleteMe();
  112. }
  113. else if (event.equalsIgnoreCase("fafurion_poison")) // Reduces Fafurions hp like it is poisoned
  114. {
  115. if (npc.getCurrentHp() <= 500)
  116. {
  117. cancelQuestTimer("fafurion_despawn", npc, null);
  118. cancelQuestTimer("first_spawn", npc, null);
  119. cancelQuestTimer("second_spawn", npc, null);
  120. cancelQuestTimer("third_spawn", npc, null);
  121. cancelQuestTimer("fourth_spawn", npc, null);
  122. cancelQuestTimer("1", npc, null);
  123. cancelQuestTimer("2", npc, null);
  124. cancelQuestTimer("3", npc, null);
  125. cancelQuestTimer("4", npc, null);
  126. MY_TRACKING_SET.remove(npc.getObjectId());
  127. ID_MAP.remove(npc.getObjectId());
  128. }
  129. npc.reduceCurrentHp(500, npc, null); // poison kills Fafurion if he is not healed
  130. }
  131. }
  132. return super.onAdvEvent(event, npc, player);
  133. }
  134. @Override
  135. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon)
  136. {
  137. int npcId = npc.getId();
  138. int npcObjId = npc.getObjectId();
  139. if (npcId == DRAGON)
  140. {
  141. if (!MY_TRACKING_SET.contains(npcObjId)) // this allows to handle multiple instances of npc
  142. {
  143. MY_TRACKING_SET.add(npcObjId);
  144. // Spawn first 5 shades on first attack on Dark Water Dragon
  145. L2Character originalAttacker = isSummon ? attacker.getSummon() : attacker;
  146. spawnShade(originalAttacker, SHADE1, npc.getX() + 100, npc.getY() + 100, npc.getZ());
  147. spawnShade(originalAttacker, SHADE2, npc.getX() + 100, npc.getY() - 100, npc.getZ());
  148. spawnShade(originalAttacker, SHADE1, npc.getX() - 100, npc.getY() + 100, npc.getZ());
  149. spawnShade(originalAttacker, SHADE2, npc.getX() - 100, npc.getY() - 100, npc.getZ());
  150. spawnShade(originalAttacker, SHADE1, npc.getX() - 150, npc.getY() + 150, npc.getZ());
  151. }
  152. else if ((npc.getCurrentHp() < (npc.getMaxHp() / 2.0)) && !(SECOND_SPAWN.contains(npcObjId)))
  153. {
  154. SECOND_SPAWN.add(npcObjId);
  155. // Spawn second 5 shades on half hp of on Dark Water Dragon
  156. L2Character originalAttacker = isSummon ? attacker.getSummon() : attacker;
  157. spawnShade(originalAttacker, SHADE2, npc.getX() + 100, npc.getY() + 100, npc.getZ());
  158. spawnShade(originalAttacker, SHADE1, npc.getX() + 100, npc.getY() - 100, npc.getZ());
  159. spawnShade(originalAttacker, SHADE2, npc.getX() - 100, npc.getY() + 100, npc.getZ());
  160. spawnShade(originalAttacker, SHADE1, npc.getX() - 100, npc.getY() - 100, npc.getZ());
  161. spawnShade(originalAttacker, SHADE2, npc.getX() - 150, npc.getY() + 150, npc.getZ());
  162. }
  163. }
  164. return super.onAttack(npc, attacker, damage, isSummon);
  165. }
  166. @Override
  167. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  168. {
  169. int npcId = npc.getId();
  170. int npcObjId = npc.getObjectId();
  171. if (npcId == DRAGON)
  172. {
  173. MY_TRACKING_SET.remove(npcObjId);
  174. SECOND_SPAWN.remove(npcObjId);
  175. L2Attackable faf = (L2Attackable) addSpawn(FAFURION, npc.getX(), npc.getY(), npc.getZ(), 0, false, 0); // spawns Fafurion Kindred when Dard Water Dragon is dead
  176. ID_MAP.put(faf.getObjectId(), killer);
  177. }
  178. else if (npcId == FAFURION)
  179. {
  180. cancelQuestTimer("fafurion_poison", npc, null);
  181. cancelQuestTimer("fafurion_despawn", npc, null);
  182. cancelQuestTimer("first_spawn", npc, null);
  183. cancelQuestTimer("second_spawn", npc, null);
  184. cancelQuestTimer("third_spawn", npc, null);
  185. cancelQuestTimer("fourth_spawn", npc, null);
  186. cancelQuestTimer("1", npc, null);
  187. cancelQuestTimer("2", npc, null);
  188. cancelQuestTimer("3", npc, null);
  189. cancelQuestTimer("4", npc, null);
  190. MY_TRACKING_SET.remove(npcObjId);
  191. ID_MAP.remove(npcObjId);
  192. }
  193. return super.onKill(npc, killer, isSummon);
  194. }
  195. @Override
  196. public String onSpawn(L2Npc npc)
  197. {
  198. int npcId = npc.getId();
  199. int npcObjId = npc.getObjectId();
  200. if (npcId == FAFURION)
  201. {
  202. if (!MY_TRACKING_SET.contains(npcObjId))
  203. {
  204. MY_TRACKING_SET.add(npcObjId);
  205. // Spawn 4 Detractors on spawn of Fafurion
  206. int x = npc.getX();
  207. int y = npc.getY();
  208. addSpawn(DETRACTOR2, x + 100, y + 100, npc.getZ(), 0, false, 40000);
  209. addSpawn(DETRACTOR1, x + 100, y - 100, npc.getZ(), 0, false, 40000);
  210. addSpawn(DETRACTOR2, x - 100, y + 100, npc.getZ(), 0, false, 40000);
  211. addSpawn(DETRACTOR1, x - 100, y - 100, npc.getZ(), 0, false, 40000);
  212. startQuestTimer("first_spawn", 2000, npc, null); // timer to delay timer "1"
  213. startQuestTimer("second_spawn", 4000, npc, null); // timer to delay timer "2"
  214. startQuestTimer("third_spawn", 8000, npc, null); // timer to delay timer "3"
  215. startQuestTimer("fourth_spawn", 10000, npc, null); // timer to delay timer "4"
  216. startQuestTimer("fafurion_poison", 3000, npc, null, true); // Every three seconds reduces Fafurions hp like it is poisoned
  217. startQuestTimer("fafurion_despawn", 120000, npc, null); // Fafurion Kindred disappears after two minutes
  218. }
  219. }
  220. return super.onSpawn(npc);
  221. }
  222. public void spawnShade(L2Character attacker, int npcId, int x, int y, int z)
  223. {
  224. final L2Npc shade = addSpawn(npcId, x, y, z, 0, false, 0);
  225. shade.setRunning();
  226. ((L2Attackable) shade).addDamageHate(attacker, 0, 999);
  227. shade.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker);
  228. }
  229. public static void main(String[] args)
  230. {
  231. new DarkWaterDragon(DarkWaterDragon.class.getSimpleName(), "ai");
  232. }
  233. }