DarkWaterDragon.java 9.5 KB

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