StakatoNest.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 java.util.List;
  17. import com.l2jserver.gameserver.ai.CtrlIntention;
  18. import com.l2jserver.gameserver.datatables.SkillTable;
  19. import com.l2jserver.gameserver.model.L2Object;
  20. import com.l2jserver.gameserver.model.L2Skill;
  21. import com.l2jserver.gameserver.model.actor.L2Attackable;
  22. import com.l2jserver.gameserver.model.actor.L2Npc;
  23. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  26. import com.l2jserver.gameserver.util.Broadcast;
  27. import com.l2jserver.gameserver.util.Util;
  28. import com.l2jserver.util.Rnd;
  29. public class StakatoNest extends L2AttackableAIScript
  30. {
  31. // List of all mobs just for register
  32. private static final int[] _stakato_mobs = { 18793, 18794, 18795, 18796, 18797, 18798, 22617, 22618, 22619, 22620, 22621, 22622, 22623, 22624, 22625, 22626, 22627, 22628, 22629, 22630, 22631, 22632, 22633, 25667 };
  33. // Coocons
  34. private static final int[] _cocoons = { 18793, 18794, 18795, 18796, 18797, 18798 };
  35. // Cannibalistic Stakato Leader
  36. private static final int _stakato_leader = 22625;
  37. // Spike Stakato Nurse
  38. private static final int _stakato_nurse = 22630;
  39. // Spike Stakato Nurse (Changed)
  40. private static final int _stakato_nurse_2 = 22631;
  41. // Spiked Stakato Baby
  42. private static final int _stakato_baby = 22632;
  43. // Spiked Stakato Captain
  44. private static final int _stakato_captain = 22629;
  45. // Female Spiked Stakato
  46. private static final int _stakato_female = 22620;
  47. // Male Spiked Stakato
  48. private static final int _stakato_male = 22621;
  49. // Male Spiked Stakato (Changed)
  50. private static final int _stakato_male_2 = 22622;
  51. // Spiked Stakato Guard
  52. private static final int _stakato_guard = 22619;
  53. // Cannibalistic Stakato Chief
  54. private static final int _stakato_chief = 25667;
  55. // Growth Accelerator
  56. private static final int _growth_accelerator = 2905;
  57. // Small Stakato Cocoon
  58. private static final int _small_cocoon = 14833;
  59. // Large Stakato Cocoon
  60. private static final int _large_cocoon = 14834;
  61. @Override
  62. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isPet)
  63. {
  64. L2MonsterInstance _mob = (L2MonsterInstance) npc;
  65. if ((_mob.getNpcId() == _stakato_leader) && (Rnd.get(1000) < 100) && (_mob.getCurrentHp() < (_mob.getMaxHp() * 0.3)))
  66. {
  67. L2MonsterInstance _follower = checkMinion(npc);
  68. if (_follower != null)
  69. {
  70. double _hp = _follower.getCurrentHp();
  71. if (_hp > (_follower.getMaxHp() * 0.3))
  72. {
  73. _mob.abortAttack();
  74. _mob.abortCast();
  75. _mob.setHeading(Util.calculateHeadingFrom(_mob, _follower));
  76. _mob.doCast(SkillTable.getInstance().getInfo(4484, 1));
  77. _mob.setCurrentHp(_mob.getCurrentHp() + _hp);
  78. _follower.doDie(_follower);
  79. _follower.deleteMe();
  80. }
  81. }
  82. }
  83. return super.onAttack(npc, attacker, damage, isPet);
  84. }
  85. @Override
  86. public String onKill(L2Npc npc, L2PcInstance killer, boolean isPet)
  87. {
  88. L2MonsterInstance _minion = checkMinion(npc);
  89. if (npc.getNpcId() == _stakato_nurse && _minion != null)
  90. {
  91. Broadcast.toSelfAndKnownPlayers(npc, new MagicSkillUse(npc, 2046, 1, 1000, 0));
  92. for (int i = 0; i < 3; i++)
  93. {
  94. L2Npc _spawned = addSpawn(_stakato_captain, _minion, true);
  95. attackPlayer(killer, _spawned);
  96. }
  97. }
  98. else if (npc.getNpcId() == _stakato_baby)
  99. {
  100. L2MonsterInstance _leader = ((L2MonsterInstance) npc).getLeader();
  101. if(_leader != null && !_leader.isDead())
  102. {
  103. startQuestTimer("nurse_change", 5000, _leader, killer);
  104. }
  105. }
  106. else if (npc.getNpcId() == _stakato_male && _minion != null)
  107. {
  108. Broadcast.toSelfAndKnownPlayers(npc, new MagicSkillUse(npc, 2046, 1, 1000, 0));
  109. for (int i = 0; i < 3; i++)
  110. {
  111. L2Npc _spawned = addSpawn(_stakato_guard, _minion, true);
  112. attackPlayer(killer, _spawned);
  113. }
  114. }
  115. else if (npc.getNpcId() == _stakato_female)
  116. {
  117. L2MonsterInstance _leader = ((L2MonsterInstance) npc).getLeader();
  118. if(_leader != null && !_leader.isDead())
  119. {
  120. startQuestTimer("male_change", 5000, _leader, killer);
  121. }
  122. }
  123. else if (npc.getNpcId() == _stakato_chief)
  124. {
  125. if (killer.isInParty())
  126. {
  127. List<L2PcInstance> party = killer.getParty().getPartyMembers();
  128. for (L2PcInstance member : party)
  129. giveCocoon(member, npc);
  130. }
  131. else
  132. giveCocoon(killer, npc);
  133. }
  134. return super.onKill(npc, killer, isPet);
  135. }
  136. @Override
  137. public String onSkillSee(L2Npc npc, L2PcInstance caster, L2Skill skill, L2Object[] targets, boolean isPet)
  138. {
  139. if (Util.contains(_cocoons, npc.getNpcId()) && Util.contains(targets, npc) && skill.getId() == _growth_accelerator)
  140. {
  141. npc.doDie(caster);
  142. L2Npc _spawned = addSpawn(_stakato_chief, npc.getX(), npc.getY(), npc.getZ(), Util.calculateHeadingFrom(npc, caster), false, 0, true);
  143. attackPlayer(caster, _spawned);
  144. }
  145. return super.onSkillSee(npc, caster, skill, targets, isPet);
  146. }
  147. @Override
  148. public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  149. {
  150. if ((npc == null) || (player == null))
  151. return null;
  152. if(npc.isDead())
  153. return null;
  154. if (event.equalsIgnoreCase("nurse_change"))
  155. {
  156. npc.getSpawn().decreaseCount(npc);
  157. npc.deleteMe();
  158. L2Npc _spawned = addSpawn(_stakato_nurse_2, npc.getX(), npc.getY(), npc.getZ(), npc.getHeading(), false, 0, true);
  159. attackPlayer(player, _spawned);
  160. }
  161. else if (event.equalsIgnoreCase("male_change"))
  162. {
  163. npc.getSpawn().decreaseCount(npc);
  164. npc.deleteMe();
  165. L2Npc _spawned = addSpawn(_stakato_male_2, npc.getX(), npc.getY(), npc.getZ(), npc.getHeading(), false, 0, true);
  166. attackPlayer(player, _spawned);
  167. }
  168. return null;
  169. }
  170. public StakatoNest(int questId, String name, String descr)
  171. {
  172. super(questId, name, descr);
  173. this.registerMobs(_stakato_mobs);
  174. }
  175. public static void main(String[] args)
  176. {
  177. new StakatoNest(-1, "StakatoNestAI", "ai");
  178. }
  179. private L2MonsterInstance checkMinion(L2Npc npc)
  180. {
  181. L2MonsterInstance mob = (L2MonsterInstance) npc;
  182. if (mob.hasMinions())
  183. {
  184. List<L2MonsterInstance> _minion = mob.getMinionList().getSpawnedMinions();
  185. if ((_minion != null) && !_minion.isEmpty() && (_minion.get(0) != null) && !_minion.get(0).isDead())
  186. return _minion.get(0);
  187. }
  188. return null;
  189. }
  190. private void attackPlayer(L2PcInstance player, L2Npc npc)
  191. {
  192. if (npc != null && player != null)
  193. {
  194. ((L2Attackable) npc).setIsRunning(true);
  195. ((L2Attackable) npc).addDamageHate(player, 0, 999);
  196. ((L2Attackable) npc).getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, player);
  197. }
  198. }
  199. private void giveCocoon(L2PcInstance player, L2Npc npc)
  200. {
  201. if (Rnd.get(100) > 80)
  202. player.addItem("StakatoCocoon", _large_cocoon, 1, npc, true);
  203. else
  204. player.addItem("StakatoCocoon", _small_cocoon, 1, npc, true);
  205. }
  206. }