DarkWaterDragon.java 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 = {DRAGON, SHADE1, SHADE2, FAFURION, DETRACTOR1, DETRACTOR2};
  40. this.registerMobs(mobs, QuestEventType.ON_KILL, QuestEventType.ON_SPAWN, QuestEventType.ON_ATTACK);
  41. myTrackingSet.clear();
  42. secondSpawn.clear();
  43. }
  44. @Override
  45. public String onAdvEvent (String event, L2Npc npc, L2PcInstance player)
  46. {
  47. if (npc != null)
  48. {
  49. if (event.equalsIgnoreCase("first_spawn")) //timer to start timer "1"
  50. {
  51. this.startQuestTimer("1",40000, npc, null, true); //spawns detractor every 40 seconds
  52. }
  53. else if (event.equalsIgnoreCase("second_spawn")) //timer to start timer "2"
  54. {
  55. this.startQuestTimer("2",40000, npc, null, true); //spawns detractor every 40 seconds
  56. }
  57. else if (event.equalsIgnoreCase("third_spawn")) //timer to start timer "3"
  58. {
  59. this.startQuestTimer("3",40000, npc, null, true); //spawns detractor every 40 seconds
  60. }
  61. else if (event.equalsIgnoreCase("fourth_spawn")) //timer to start timer "4"
  62. {
  63. this.startQuestTimer("4",40000, npc, null, true); //spawns detractor every 40 seconds
  64. }
  65. else if (event.equalsIgnoreCase("1")) //spawns a detractor
  66. {
  67. this.addSpawn(DETRACTOR1,(npc.getX()+100),(npc.getY()+100),npc.getZ(),0,false,40000);
  68. }
  69. else if (event.equalsIgnoreCase("2")) //spawns a detractor
  70. {
  71. this.addSpawn(DETRACTOR2,(npc.getX()+100),(npc.getY()-100),npc.getZ(),0,false,40000);
  72. }
  73. else if (event.equalsIgnoreCase("3")) //spawns a detractor
  74. {
  75. this.addSpawn(DETRACTOR1,(npc.getX()-100),(npc.getY()+100),npc.getZ(),0,false,40000);
  76. }
  77. else if (event.equalsIgnoreCase("4")) //spawns a detractor
  78. {
  79. this.addSpawn(DETRACTOR2,(npc.getX()-100),(npc.getY()-100),npc.getZ(),0,false,40000);
  80. }
  81. else if (event.equalsIgnoreCase("fafurion_despawn")) //Fafurion Kindred disappears and drops reward
  82. {
  83. this.cancelQuestTimer("fafurion_poison", npc, null);
  84. this.cancelQuestTimer("1", npc, null);
  85. this.cancelQuestTimer("2", npc, null);
  86. this.cancelQuestTimer("3", npc, null);
  87. this.cancelQuestTimer("4", npc, null);
  88. myTrackingSet.remove(npc.getObjectId());
  89. player = _idmap.remove(npc.getObjectId());
  90. if(player != null) //You never know ...
  91. ((L2Attackable)npc).doItemDrop(NpcTable.getInstance().getTemplate(18485), player);
  92. npc.deleteMe();
  93. }
  94. else if (event.equalsIgnoreCase("fafurion_poison")) //Reduces Fafurions hp like it is poisoned
  95. {
  96. if (npc.getCurrentHp() <= 500)
  97. {
  98. this.cancelQuestTimer("fafurion_despawn", npc, null);
  99. this.cancelQuestTimer("first_spawn", npc, null);
  100. this.cancelQuestTimer("second_spawn", npc, null);
  101. this.cancelQuestTimer("third_spawn", npc, null);
  102. this.cancelQuestTimer("fourth_spawn", npc, null);
  103. this.cancelQuestTimer("1", npc, null);
  104. this.cancelQuestTimer("2", npc, null);
  105. this.cancelQuestTimer("3", npc, null);
  106. this.cancelQuestTimer("4", npc, null);
  107. myTrackingSet.remove(npc.getObjectId());
  108. _idmap.remove(npc.getObjectId());
  109. }
  110. npc.reduceCurrentHp(500, npc, null); //poison kills Fafurion if he is not healed
  111. }
  112. }
  113. return super.onAdvEvent(event,npc,player);
  114. }
  115. @Override
  116. public String onAttack (L2Npc npc, L2PcInstance attacker, int damage, boolean isPet)
  117. {
  118. int npcId = npc.getNpcId();
  119. int npcObjId = npc.getObjectId();
  120. if (npcId == DRAGON)
  121. {
  122. if (!myTrackingSet.contains(npcObjId)) //this allows to handle multiple instances of npc
  123. {
  124. myTrackingSet.add(npcObjId);
  125. //Spawn first 5 shades on first attack on Dark Water Dragon
  126. L2Character originalAttacker = isPet? attacker.getPet(): attacker;
  127. spawnShade(originalAttacker, SHADE1, npc.getX() + 100, npc.getY() + 100, npc.getZ());
  128. spawnShade(originalAttacker, SHADE2, npc.getX() + 100, npc.getY() - 100, npc.getZ());
  129. spawnShade(originalAttacker, SHADE1, npc.getX() - 100, npc.getY() + 100, npc.getZ());
  130. spawnShade(originalAttacker, SHADE2, npc.getX() - 100, npc.getY() - 100, npc.getZ());
  131. spawnShade(originalAttacker, SHADE1, npc.getX() - 150, npc.getY() + 150, npc.getZ());
  132. }
  133. else if (npc.getCurrentHp() < (npc.getMaxHp() / 2.0) && !(secondSpawn.contains(npcObjId)))
  134. {
  135. secondSpawn.add(npcObjId);
  136. //Spawn second 5 shades on half hp of on Dark Water Dragon
  137. L2Character originalAttacker = isPet? attacker.getPet(): attacker;
  138. spawnShade(originalAttacker, SHADE2, npc.getX() + 100, npc.getY() + 100, npc.getZ());
  139. spawnShade(originalAttacker, SHADE1, npc.getX() + 100, npc.getY() - 100, npc.getZ());
  140. spawnShade(originalAttacker, SHADE2, npc.getX() - 100, npc.getY() + 100, npc.getZ());
  141. spawnShade(originalAttacker, SHADE1, npc.getX() - 100, npc.getY() - 100, npc.getZ());
  142. spawnShade(originalAttacker, SHADE2, npc.getX() - 150, npc.getY() + 150, npc.getZ());
  143. }
  144. }
  145. return super.onAttack(npc, attacker, damage, isPet);
  146. }
  147. @Override
  148. public String onKill (L2Npc npc, L2PcInstance killer, boolean isPet)
  149. {
  150. int npcId = npc.getNpcId();
  151. int npcObjId = npc.getObjectId();
  152. if (npcId == DRAGON)
  153. {
  154. myTrackingSet.remove(npcObjId);
  155. secondSpawn.remove(npcObjId);
  156. L2Attackable faf = (L2Attackable) this.addSpawn(FAFURION,npc.getX(),npc.getY(),npc.getZ(),0,false,0); //spawns Fafurion Kindred when Dard Water Dragon is dead
  157. _idmap.put(faf.getObjectId(),killer);
  158. }
  159. else if (npcId == FAFURION)
  160. {
  161. this.cancelQuestTimer("fafurion_poison", npc, null);
  162. this.cancelQuestTimer("fafurion_despawn", npc, null);
  163. this.cancelQuestTimer("first_spawn", npc, null);
  164. this.cancelQuestTimer("second_spawn", npc, null);
  165. this.cancelQuestTimer("third_spawn", npc, null);
  166. this.cancelQuestTimer("fourth_spawn", npc, null);
  167. this.cancelQuestTimer("1", npc, null);
  168. this.cancelQuestTimer("2", npc, null);
  169. this.cancelQuestTimer("3", npc, null);
  170. this.cancelQuestTimer("4", npc, null);
  171. myTrackingSet.remove(npcObjId);
  172. _idmap.remove(npcObjId);
  173. }
  174. return super.onKill(npc,killer,isPet);
  175. }
  176. @Override
  177. public String onSpawn (L2Npc npc)
  178. {
  179. int npcId = npc.getNpcId();
  180. int npcObjId = npc.getObjectId();
  181. if (npcId == FAFURION)
  182. {
  183. if (!myTrackingSet.contains(npcObjId))
  184. {
  185. myTrackingSet.add(npcObjId);
  186. //Spawn 4 Detractors on spawn of Fafurion
  187. int x = npc.getX();
  188. int y = npc.getY();
  189. this.addSpawn(DETRACTOR2,x+100,y+100,npc.getZ(),0,false,40000);
  190. this.addSpawn(DETRACTOR1,x+100,y-100,npc.getZ(),0,false,40000);
  191. this.addSpawn(DETRACTOR2,x-100,y+100,npc.getZ(),0,false,40000);
  192. this.addSpawn(DETRACTOR1,x-100,y-100,npc.getZ(),0,false,40000);
  193. this.startQuestTimer("first_spawn",2000, npc, null); //timer to delay timer "1"
  194. this.startQuestTimer("second_spawn",4000, npc, null); //timer to delay timer "2"
  195. this.startQuestTimer("third_spawn",8000, npc, null); //timer to delay timer "3"
  196. this.startQuestTimer("fourth_spawn",10000, npc, null); //timer to delay timer "4"
  197. this.startQuestTimer("fafurion_poison",3000, npc, null, true); //Every three seconds reduces Fafurions hp like it is poisoned
  198. this.startQuestTimer("fafurion_despawn",120000, npc, null); //Fafurion Kindred disappears after two minutes
  199. }
  200. }
  201. return super.onSpawn(npc);
  202. }
  203. public void spawnShade(L2Character attacker, int npcId, int x, int y, int z)
  204. {
  205. final L2Npc shade = addSpawn(npcId,x,y,z,0,false,0);
  206. shade.setRunning();
  207. ((L2Attackable)shade).addDamageHate(attacker,0,999);
  208. shade.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker);
  209. }
  210. public static void main(String[] args)
  211. {
  212. // Quest class and state definition
  213. new DarkWaterDragon(-1,"DarkWaterDragon","ai");
  214. }
  215. }