Keltas.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 hellbound.AI;
  20. import java.util.Collections;
  21. import java.util.Set;
  22. import java.util.concurrent.ConcurrentHashMap;
  23. import ai.npc.AbstractNpcAI;
  24. import com.l2jserver.gameserver.model.L2Spawn;
  25. import com.l2jserver.gameserver.model.Location;
  26. import com.l2jserver.gameserver.model.actor.L2Npc;
  27. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  28. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  29. import com.l2jserver.gameserver.network.NpcStringId;
  30. import com.l2jserver.gameserver.network.clientpackets.Say2;
  31. /**
  32. * Manages Darion's Enforcer's and Darion's Executioner spawn/despawn
  33. * @author GKR
  34. */
  35. public final class Keltas extends AbstractNpcAI
  36. {
  37. // NPCs
  38. private static final int KELTAS = 22341;
  39. private static final int ENFORCER = 22342;
  40. private static final int EXECUTIONER = 22343;
  41. // Locations
  42. private static final Location[] ENFORCER_SPAWN_POINTS =
  43. {
  44. new Location(-24540, 251404, -3320),
  45. new Location(-24100, 252578, -3060),
  46. new Location(-24607, 252443, -3074),
  47. new Location(-23962, 252041, -3275),
  48. new Location(-24381, 252132, -3090),
  49. new Location(-23652, 251838, -3370),
  50. new Location(-23838, 252603, -3095),
  51. new Location(-23257, 251671, -3360),
  52. new Location(-27127, 251106, -3523),
  53. new Location(-27118, 251203, -3523),
  54. new Location(-27052, 251205, -3523),
  55. new Location(-26999, 250818, -3523),
  56. new Location(-29613, 252888, -3523),
  57. new Location(-29765, 253009, -3523),
  58. new Location(-29594, 252570, -3523),
  59. new Location(-29770, 252658, -3523),
  60. new Location(-27816, 252008, -3527),
  61. new Location(-27930, 252011, -3523),
  62. new Location(-28702, 251986, -3523),
  63. new Location(-27357, 251987, -3527),
  64. new Location(-28859, 251081, -3527),
  65. new Location(-28607, 250397, -3523),
  66. new Location(-28801, 250462, -3523),
  67. new Location(-29123, 250387, -3472),
  68. new Location(-25376, 252368, -3257),
  69. new Location(-25376, 252208, -3257)
  70. };
  71. private static final Location[] EXECUTIONER_SPAWN_POINTS =
  72. {
  73. new Location(-24419, 251395, -3340),
  74. new Location(-24912, 252160, -3310),
  75. new Location(-25027, 251941, -3300),
  76. new Location(-24127, 252657, -3058),
  77. new Location(-25120, 252372, -3270),
  78. new Location(-24456, 252651, -3060),
  79. new Location(-24844, 251614, -3295),
  80. new Location(-28675, 252008, -3523),
  81. new Location(-27943, 251238, -3523),
  82. new Location(-27827, 251984, -3523),
  83. new Location(-27276, 251995, -3523),
  84. new Location(-28769, 251955, -3523),
  85. new Location(-27969, 251073, -3523),
  86. new Location(-27233, 250938, -3523),
  87. new Location(-26835, 250914, -3523),
  88. new Location(-26802, 251276, -3523),
  89. new Location(-29671, 252781, -3527),
  90. new Location(-29536, 252831, -3523),
  91. new Location(-29419, 253214, -3523),
  92. new Location(-27923, 251965, -3523),
  93. new Location(-28499, 251882, -3527),
  94. new Location(-28194, 251915, -3523),
  95. new Location(-28358, 251078, -3527),
  96. new Location(-28580, 251071, -3527),
  97. new Location(-28492, 250704, -3523)
  98. };
  99. // Misc
  100. private L2MonsterInstance _spawnedKeltas = null;
  101. private final Set<L2Spawn> _spawnedMonsters = Collections.newSetFromMap(new ConcurrentHashMap<L2Spawn, Boolean>());
  102. public Keltas()
  103. {
  104. super(Keltas.class.getSimpleName(), "hellbound/AI");
  105. addKillId(KELTAS);
  106. addSpawnId(KELTAS);
  107. }
  108. private void spawnMinions()
  109. {
  110. for (Location loc : ENFORCER_SPAWN_POINTS)
  111. {
  112. final L2MonsterInstance minion = (L2MonsterInstance) addSpawn(ENFORCER, loc, false, 0, false);
  113. final L2Spawn spawn = minion.getSpawn();
  114. spawn.setRespawnDelay(60);
  115. spawn.setAmount(1);
  116. spawn.startRespawn();
  117. _spawnedMonsters.add(spawn);
  118. }
  119. for (Location loc : EXECUTIONER_SPAWN_POINTS)
  120. {
  121. final L2MonsterInstance minion = (L2MonsterInstance) addSpawn(EXECUTIONER, loc, false, 0, false);
  122. final L2Spawn spawn = minion.getSpawn();
  123. spawn.setRespawnDelay(80);
  124. spawn.setAmount(1);
  125. spawn.startRespawn();
  126. _spawnedMonsters.add(spawn);
  127. }
  128. }
  129. private void despawnMinions()
  130. {
  131. if (_spawnedMonsters.isEmpty())
  132. {
  133. return;
  134. }
  135. for (L2Spawn spawn : _spawnedMonsters)
  136. {
  137. spawn.stopRespawn();
  138. L2Npc minion = spawn.getLastSpawn();
  139. if ((minion != null) && !minion.isDead())
  140. {
  141. minion.deleteMe();
  142. }
  143. }
  144. _spawnedMonsters.clear();
  145. }
  146. @Override
  147. public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  148. {
  149. if (event.equalsIgnoreCase("despawn"))
  150. {
  151. final L2Npc keltas = _spawnedKeltas;
  152. if ((keltas != null) && !keltas.isDead())
  153. {
  154. broadcastNpcSay(keltas, Say2.NPC_SHOUT, NpcStringId.THAT_IS_IT_FOR_TODAYLETS_RETREAT_EVERYONE_PULL_BACK);
  155. keltas.deleteMe();
  156. keltas.getSpawn().decreaseCount(keltas);
  157. despawnMinions();
  158. }
  159. }
  160. return super.onAdvEvent(event, npc, player);
  161. }
  162. @Override
  163. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  164. {
  165. cancelQuestTimers("despawn");
  166. despawnMinions();
  167. return super.onKill(npc, killer, isSummon);
  168. }
  169. @Override
  170. public final String onSpawn(L2Npc npc)
  171. {
  172. _spawnedKeltas = (L2MonsterInstance) npc;
  173. broadcastNpcSay(_spawnedKeltas, Say2.NPC_SHOUT, NpcStringId.GUYS_SHOW_THEM_OUR_POWER);
  174. spawnMinions();
  175. startQuestTimer("despawn", 1800000, null, null);
  176. return super.onSpawn(npc);
  177. }
  178. }