DarkWaterDragon.java 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package ai.individual;
  16. import javolution.util.FastMap;
  17. import javolution.util.FastSet;
  18. import ai.group_template.L2AttackableAIScript;
  19. import com.l2jserver.gameserver.ai.CtrlIntention;
  20. import com.l2jserver.gameserver.datatables.NpcTable;
  21. import com.l2jserver.gameserver.model.actor.L2Attackable;
  22. import com.l2jserver.gameserver.model.actor.L2Character;
  23. import com.l2jserver.gameserver.model.actor.L2Npc;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. public class DarkWaterDragon extends L2AttackableAIScript
  26. {
  27. private static final int DRAGON = 22267;
  28. private static final int SHADE1 = 22268;
  29. private static final int SHADE2 = 22269;
  30. private static final int FAFURION = 18482;
  31. private static final int DETRACTOR1 = 22270;
  32. private static final int DETRACTOR2 = 22271;
  33. private static FastSet<Integer> secondSpawn = new FastSet<Integer>(); // Used to track if second Shades were already spawned
  34. private static FastSet<Integer> myTrackingSet = new FastSet<Integer>(); // Used to track instances of npcs
  35. private static FastMap<Integer, L2PcInstance> _idmap = new FastMap<Integer, L2PcInstance>().shared(); // Used to track instances of npcs
  36. public DarkWaterDragon(int id, String name, String descr)
  37. {
  38. super(id, name, descr);
  39. int[] mobs =
  40. {
  41. DRAGON, SHADE1, SHADE2, FAFURION, DETRACTOR1, DETRACTOR2
  42. };
  43. registerMobs(mobs, QuestEventType.ON_KILL, QuestEventType.ON_SPAWN, QuestEventType.ON_ATTACK);
  44. myTrackingSet.clear();
  45. secondSpawn.clear();
  46. }
  47. @Override
  48. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  49. {
  50. if (npc != null)
  51. {
  52. if (event.equalsIgnoreCase("first_spawn")) // timer to start timer "1"
  53. {
  54. startQuestTimer("1", 40000, npc, null, true); // spawns detractor every 40 seconds
  55. }
  56. else if (event.equalsIgnoreCase("second_spawn")) // timer to start timer "2"
  57. {
  58. startQuestTimer("2", 40000, npc, null, true); // spawns detractor every 40 seconds
  59. }
  60. else if (event.equalsIgnoreCase("third_spawn")) // timer to start timer "3"
  61. {
  62. startQuestTimer("3", 40000, npc, null, true); // spawns detractor every 40 seconds
  63. }
  64. else if (event.equalsIgnoreCase("fourth_spawn")) // timer to start timer "4"
  65. {
  66. startQuestTimer("4", 40000, npc, null, true); // spawns detractor every 40 seconds
  67. }
  68. else if (event.equalsIgnoreCase("1")) // spawns a detractor
  69. {
  70. addSpawn(DETRACTOR1, (npc.getX() + 100), (npc.getY() + 100), npc.getZ(), 0, false, 40000);
  71. }
  72. else if (event.equalsIgnoreCase("2")) // spawns a detractor
  73. {
  74. addSpawn(DETRACTOR2, (npc.getX() + 100), (npc.getY() - 100), npc.getZ(), 0, false, 40000);
  75. }
  76. else if (event.equalsIgnoreCase("3")) // spawns a detractor
  77. {
  78. addSpawn(DETRACTOR1, (npc.getX() - 100), (npc.getY() + 100), npc.getZ(), 0, false, 40000);
  79. }
  80. else if (event.equalsIgnoreCase("4")) // spawns a detractor
  81. {
  82. addSpawn(DETRACTOR2, (npc.getX() - 100), (npc.getY() - 100), npc.getZ(), 0, false, 40000);
  83. }
  84. else if (event.equalsIgnoreCase("fafurion_despawn")) // Fafurion Kindred disappears and drops reward
  85. {
  86. cancelQuestTimer("fafurion_poison", npc, null);
  87. cancelQuestTimer("1", npc, null);
  88. cancelQuestTimer("2", npc, null);
  89. cancelQuestTimer("3", npc, null);
  90. cancelQuestTimer("4", npc, null);
  91. myTrackingSet.remove(npc.getObjectId());
  92. player = _idmap.remove(npc.getObjectId());
  93. if (player != null) // You never know ...
  94. ((L2Attackable) npc).doItemDrop(NpcTable.getInstance().getTemplate(18485), player);
  95. npc.deleteMe();
  96. }
  97. else if (event.equalsIgnoreCase("fafurion_poison")) // Reduces Fafurions hp like it is poisoned
  98. {
  99. if (npc.getCurrentHp() <= 500)
  100. {
  101. cancelQuestTimer("fafurion_despawn", npc, null);
  102. cancelQuestTimer("first_spawn", npc, null);
  103. cancelQuestTimer("second_spawn", npc, null);
  104. cancelQuestTimer("third_spawn", npc, null);
  105. cancelQuestTimer("fourth_spawn", npc, null);
  106. cancelQuestTimer("1", npc, null);
  107. cancelQuestTimer("2", npc, null);
  108. cancelQuestTimer("3", npc, null);
  109. cancelQuestTimer("4", npc, null);
  110. myTrackingSet.remove(npc.getObjectId());
  111. _idmap.remove(npc.getObjectId());
  112. }
  113. npc.reduceCurrentHp(500, npc, null); // poison kills Fafurion if he is not healed
  114. }
  115. }
  116. return super.onAdvEvent(event, npc, player);
  117. }
  118. @Override
  119. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet)
  120. {
  121. int npcId = npc.getNpcId();
  122. int npcObjId = npc.getObjectId();
  123. if (npcId == DRAGON)
  124. {
  125. if (!myTrackingSet.contains(npcObjId)) // this allows to handle multiple instances of npc
  126. {
  127. myTrackingSet.add(npcObjId);
  128. // Spawn first 5 shades on first attack on Dark Water Dragon
  129. L2Character originalAttacker = isPet ? attacker.getPet() : attacker;
  130. spawnShade(originalAttacker, SHADE1, npc.getX() + 100, npc.getY() + 100, npc.getZ());
  131. spawnShade(originalAttacker, SHADE2, npc.getX() + 100, npc.getY() - 100, npc.getZ());
  132. spawnShade(originalAttacker, SHADE1, npc.getX() - 100, npc.getY() + 100, npc.getZ());
  133. spawnShade(originalAttacker, SHADE2, npc.getX() - 100, npc.getY() - 100, npc.getZ());
  134. spawnShade(originalAttacker, SHADE1, npc.getX() - 150, npc.getY() + 150, npc.getZ());
  135. }
  136. else if (npc.getCurrentHp() < (npc.getMaxHp() / 2.0) && !(secondSpawn.contains(npcObjId)))
  137. {
  138. secondSpawn.add(npcObjId);
  139. // Spawn second 5 shades on half hp of on Dark Water Dragon
  140. L2Character originalAttacker = isPet ? attacker.getPet() : attacker;
  141. spawnShade(originalAttacker, SHADE2, npc.getX() + 100, npc.getY() + 100, npc.getZ());
  142. spawnShade(originalAttacker, SHADE1, npc.getX() + 100, npc.getY() - 100, npc.getZ());
  143. spawnShade(originalAttacker, SHADE2, npc.getX() - 100, npc.getY() + 100, npc.getZ());
  144. spawnShade(originalAttacker, SHADE1, npc.getX() - 100, npc.getY() - 100, npc.getZ());
  145. spawnShade(originalAttacker, SHADE2, npc.getX() - 150, npc.getY() + 150, npc.getZ());
  146. }
  147. }
  148. return super.onAttack(npc, attacker, damage, isPet);
  149. }
  150. @Override
  151. public String onKill(L2Npc npc, L2PcInstance killer, boolean isPet)
  152. {
  153. int npcId = npc.getNpcId();
  154. int npcObjId = npc.getObjectId();
  155. if (npcId == DRAGON)
  156. {
  157. myTrackingSet.remove(npcObjId);
  158. secondSpawn.remove(npcObjId);
  159. L2Attackable faf = (L2Attackable) addSpawn(FAFURION, npc.getX(), npc.getY(), npc.getZ(), 0, false, 0); // spawns Fafurion Kindred when Dard Water Dragon is dead
  160. _idmap.put(faf.getObjectId(), killer);
  161. }
  162. else if (npcId == FAFURION)
  163. {
  164. cancelQuestTimer("fafurion_poison", npc, null);
  165. cancelQuestTimer("fafurion_despawn", npc, null);
  166. cancelQuestTimer("first_spawn", npc, null);
  167. cancelQuestTimer("second_spawn", npc, null);
  168. cancelQuestTimer("third_spawn", npc, null);
  169. cancelQuestTimer("fourth_spawn", npc, null);
  170. cancelQuestTimer("1", npc, null);
  171. cancelQuestTimer("2", npc, null);
  172. cancelQuestTimer("3", npc, null);
  173. cancelQuestTimer("4", npc, null);
  174. myTrackingSet.remove(npcObjId);
  175. _idmap.remove(npcObjId);
  176. }
  177. return super.onKill(npc, killer, isPet);
  178. }
  179. @Override
  180. public String onSpawn(L2Npc npc)
  181. {
  182. int npcId = npc.getNpcId();
  183. int npcObjId = npc.getObjectId();
  184. if (npcId == FAFURION)
  185. {
  186. if (!myTrackingSet.contains(npcObjId))
  187. {
  188. myTrackingSet.add(npcObjId);
  189. // Spawn 4 Detractors on spawn of Fafurion
  190. int x = npc.getX();
  191. int y = npc.getY();
  192. addSpawn(DETRACTOR2, x + 100, y + 100, npc.getZ(), 0, false, 40000);
  193. addSpawn(DETRACTOR1, x + 100, y - 100, npc.getZ(), 0, false, 40000);
  194. addSpawn(DETRACTOR2, x - 100, y + 100, npc.getZ(), 0, false, 40000);
  195. addSpawn(DETRACTOR1, x - 100, y - 100, npc.getZ(), 0, false, 40000);
  196. startQuestTimer("first_spawn", 2000, npc, null); // timer to delay timer "1"
  197. startQuestTimer("second_spawn", 4000, npc, null); // timer to delay timer "2"
  198. startQuestTimer("third_spawn", 8000, npc, null); // timer to delay timer "3"
  199. startQuestTimer("fourth_spawn", 10000, npc, null); // timer to delay timer "4"
  200. startQuestTimer("fafurion_poison", 3000, npc, null, true); // Every three seconds reduces Fafurions hp like it is poisoned
  201. startQuestTimer("fafurion_despawn", 120000, npc, null); // Fafurion Kindred disappears after two minutes
  202. }
  203. }
  204. return super.onSpawn(npc);
  205. }
  206. public void spawnShade(L2Character attacker, int npcId, int x, int y, int z)
  207. {
  208. final L2Npc shade = addSpawn(npcId, x, y, z, 0, false, 0);
  209. shade.setRunning();
  210. ((L2Attackable) shade).addDamageHate(attacker, 0, 999);
  211. shade.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker);
  212. }
  213. public static void main(String[] args)
  214. {
  215. // Quest class and state definition
  216. new DarkWaterDragon(-1, "DarkWaterDragon", "ai");
  217. }
  218. }