SummonMinions.java 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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.group_template;
  16. import gnu.trove.TIntHashSet;
  17. import gnu.trove.TIntObjectHashMap;
  18. import javolution.util.FastList;
  19. import javolution.util.FastMap;
  20. import com.l2jserver.gameserver.ai.CtrlIntention;
  21. import com.l2jserver.gameserver.model.actor.L2Attackable;
  22. import com.l2jserver.gameserver.model.actor.L2Npc;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  25. import com.l2jserver.util.Rnd;
  26. public class SummonMinions extends L2AttackableAIScript
  27. {
  28. private static int HasSpawned;
  29. private static TIntHashSet myTrackingSet = new TIntHashSet(); //Used to track instances of npcs
  30. private FastMap<Integer, FastList<L2PcInstance>> _attackersList = new FastMap<Integer, FastList<L2PcInstance>>().shared();
  31. private static final TIntObjectHashMap<int[]> MINIONS = new TIntObjectHashMap<int[]>();
  32. static
  33. {
  34. MINIONS.put(20767,new int[]{20768,20769,20770}); //Timak Orc Troop
  35. //MINIONS.put(22030,new Integer[]{22045,22047,22048}); //Ragna Orc Shaman
  36. //MINIONS.put(22032,new Integer[]{22036}); //Ragna Orc Warrior - summons shaman but not 22030 ><
  37. //MINIONS.put(22038,new Integer[]{22037}); //Ragna Orc Hero
  38. MINIONS.put(21524,new int[]{21525}); //Blade of Splendor
  39. MINIONS.put(21531,new int[]{21658}); //Punishment of Splendor
  40. MINIONS.put(21539,new int[]{21540}); //Wailing of Splendor
  41. MINIONS.put(22257,new int[]{18364,18364}); //Island Guardian
  42. MINIONS.put(22258,new int[]{18364,18364}); //White Sand Mirage
  43. MINIONS.put(22259,new int[]{18364,18364}); //Muddy Coral
  44. MINIONS.put(22260,new int[]{18364,18364}); //Kleopora
  45. MINIONS.put(22261,new int[]{18365,18365}); //Seychelles
  46. MINIONS.put(22262,new int[]{18365,18365}); //Naiad
  47. MINIONS.put(22263,new int[]{18365,18365}); //Sonneratia
  48. MINIONS.put(22264,new int[]{18366,18366}); //Castalia
  49. MINIONS.put(22265,new int[]{18366,18366}); //Chrysocolla
  50. MINIONS.put(22266,new int[]{18366,18366}); //Pythia
  51. MINIONS.put(22774,new int[]{22768,22768}); // Tanta Lizardman Summoner
  52. }
  53. public SummonMinions(int questId, String name, String descr)
  54. {
  55. super(questId, name, descr);
  56. int[] temp =
  57. {
  58. 20767, 21524, 21531, 21539, 22257, 22258, 22259, 22260, 22261, 22262, 22263, 22264, 22265, 22266, 22774
  59. };
  60. this.registerMobs(temp, QuestEventType.ON_ATTACK, QuestEventType.ON_KILL);
  61. }
  62. @Override
  63. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet)
  64. {
  65. int npcId = npc.getNpcId();
  66. int npcObjId = npc.getObjectId();
  67. if (MINIONS.containsKey(npcId))
  68. {
  69. if (!myTrackingSet.contains(npcObjId)) //this allows to handle multiple instances of npc
  70. {
  71. synchronized (myTrackingSet)
  72. {
  73. myTrackingSet.add(npcObjId);
  74. }
  75. HasSpawned = npcObjId;
  76. }
  77. if (HasSpawned == npcObjId)
  78. {
  79. switch (npcId)
  80. {
  81. case 22030: //mobs that summon minions only on certain hp
  82. case 22032:
  83. case 22038:
  84. {
  85. if (npc.getCurrentHp() < (npc.getMaxHp() / 2.0))
  86. {
  87. HasSpawned = 0;
  88. if (Rnd.get(100) < 33) //mobs that summon minions only on certain chance
  89. {
  90. int[] minions = MINIONS.get(npcId);
  91. for (int val : minions)
  92. {
  93. L2Attackable newNpc = (L2Attackable) this.addSpawn(val, (npc.getX() + Rnd.get(-150, 150)), (npc.getY() + Rnd.get(-150, 150)), npc.getZ(), 0, false, 0);
  94. newNpc.setRunning();
  95. newNpc.addDamageHate(attacker, 0, 999);
  96. newNpc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker);
  97. }
  98. minions = null;
  99. }
  100. }
  101. break;
  102. }
  103. case 22257:
  104. case 22258:
  105. case 22259:
  106. case 22260:
  107. case 22261:
  108. case 22262:
  109. case 22263:
  110. case 22264:
  111. case 22265:
  112. case 22266:
  113. {
  114. if (isPet)
  115. attacker = (attacker).getPet().getOwner();
  116. if (attacker.getParty() != null)
  117. {
  118. for (L2PcInstance member : attacker.getParty().getPartyMembers())
  119. {
  120. if (_attackersList.get(npcObjId) == null)
  121. {
  122. FastList<L2PcInstance> player = new FastList<L2PcInstance>();
  123. player.add(member);
  124. _attackersList.put(npcObjId,player);
  125. }
  126. else if (!_attackersList.get(npcObjId).contains(member))
  127. _attackersList.get(npcObjId).add(member);
  128. }
  129. }
  130. else
  131. {
  132. if (_attackersList.get(npcObjId) == null)
  133. {
  134. FastList<L2PcInstance> player = new FastList<L2PcInstance>();
  135. player.add(attacker);
  136. _attackersList.put(npcObjId,player);
  137. }
  138. else if (!_attackersList.get(npcObjId).contains(attacker))
  139. _attackersList.get(npcObjId).add(attacker);
  140. }
  141. if ((attacker.getParty() != null && attacker.getParty().getMemberCount() > 2)||_attackersList.get(npcObjId).size() > 2) //Just to make sure..
  142. {
  143. HasSpawned = 0;
  144. for (int val : MINIONS.get(npcId))
  145. {
  146. L2Attackable newNpc = (L2Attackable) this.addSpawn(val, npc.getX() + Rnd.get(-150, 150), npc.getY() + Rnd.get(-150, 150), npc.getZ(), 0, false, 0);
  147. newNpc.setRunning();
  148. newNpc.addDamageHate(attacker, 0, 999);
  149. newNpc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker);
  150. }
  151. }
  152. break;
  153. }
  154. default: //mobs without special conditions
  155. {
  156. HasSpawned = 0;
  157. if (npcId != 20767)
  158. {
  159. for (int val : MINIONS.get(npcId))
  160. {
  161. L2Attackable newNpc = (L2Attackable) this.addSpawn(val, npc.getX() + Rnd.get(-150, 150), npc.getY() + Rnd.get(-150, 150), npc.getZ(), 0, false, 0);
  162. newNpc.setRunning();
  163. newNpc.addDamageHate(attacker, 0, 999);
  164. newNpc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, attacker);
  165. }
  166. }
  167. else
  168. {
  169. for (int val : MINIONS.get(npcId))
  170. {
  171. this.addSpawn(val, (npc.getX() + Rnd.get(-100, 100)), (npc.getY() + Rnd.get(-100, 100)), npc.getZ(), 0, false, 0);
  172. }
  173. }
  174. if (npcId == 20767)
  175. {
  176. npc.broadcastPacket(new NpcSay(npcObjId, 0, npcId, 1000294)); // Come out, you children of darkness!
  177. }
  178. break;
  179. }
  180. }
  181. }
  182. }
  183. return super.onAttack(npc, attacker, damage, isPet);
  184. }
  185. @Override
  186. public String onKill(L2Npc npc, L2PcInstance killer, boolean isPet)
  187. {
  188. int npcId = npc.getNpcId();
  189. int npcObjId = npc.getObjectId();
  190. if (MINIONS.containsKey(npcId))
  191. {
  192. synchronized (myTrackingSet)
  193. {
  194. myTrackingSet.remove(npcObjId);
  195. }
  196. }
  197. if (_attackersList.get(npcObjId) != null)
  198. {
  199. _attackersList.get(npcObjId).clear();
  200. }
  201. return super.onKill(npc, killer, isPet);
  202. }
  203. public static void main(String[] args)
  204. {
  205. // now call the constructor (starts up the ai)
  206. new SummonMinions(-1, "SummonMinions", "ai");
  207. }
  208. }