DarkWaterDragon.java 9.5 KB

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