SummonMinions.java 7.5 KB

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