StakatoNest.java 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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 ai.group_template;
  20. import java.util.List;
  21. import ai.npc.AbstractNpcAI;
  22. import com.l2jserver.gameserver.datatables.SkillData;
  23. import com.l2jserver.gameserver.model.L2Object;
  24. import com.l2jserver.gameserver.model.actor.L2Npc;
  25. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.model.skills.Skill;
  28. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  29. import com.l2jserver.gameserver.util.Broadcast;
  30. import com.l2jserver.gameserver.util.Util;
  31. /**
  32. * Stakato Nest AI.
  33. * @author Gnacik
  34. */
  35. public final class StakatoNest extends AbstractNpcAI
  36. {
  37. // @formatter:off
  38. // List of all mobs just for register
  39. private static final int[] STAKATO_MOBS =
  40. {
  41. 18793, 18794, 18795, 18796, 18797, 18798, 22617, 22618, 22619, 22620,
  42. 22621, 22622, 22623, 22624, 22625, 22626, 22627, 22628, 22629, 22630,
  43. 22631, 22632, 22633, 25667
  44. };
  45. // Coocons
  46. private static final int[] COCOONS =
  47. {
  48. 18793, 18794, 18795, 18796, 18797, 18798
  49. };
  50. // @formatter:on
  51. // Cannibalistic Stakato Leader
  52. private static final int STAKATO_LEADER = 22625;
  53. // Spike Stakato Nurse
  54. private static final int STAKATO_NURSE = 22630;
  55. // Spike Stakato Nurse (Changed)
  56. private static final int STAKATO_NURSE_2 = 22631;
  57. // Spiked Stakato Baby
  58. private static final int STAKATO_BABY = 22632;
  59. // Spiked Stakato Captain
  60. private static final int STAKATO_CAPTAIN = 22629;
  61. // Female Spiked Stakato
  62. private static final int STAKATO_FEMALE = 22620;
  63. // Male Spiked Stakato
  64. private static final int STAKATO_MALE = 22621;
  65. // Male Spiked Stakato (Changed)
  66. private static final int STAKATO_MALE_2 = 22622;
  67. // Spiked Stakato Guard
  68. private static final int STAKATO_GUARD = 22619;
  69. // Cannibalistic Stakato Chief
  70. private static final int STAKATO_CHIEF = 25667;
  71. // Growth Accelerator
  72. private static final int GROWTH_ACCELERATOR = 2905;
  73. // Small Stakato Cocoon
  74. private static final int SMALL_COCOON = 14833;
  75. // Large Stakato Cocoon
  76. private static final int LARGE_COCOON = 14834;
  77. private StakatoNest()
  78. {
  79. super(StakatoNest.class.getSimpleName(), "ai/group_template");
  80. registerMobs(STAKATO_MOBS);
  81. }
  82. @Override
  83. public String onAttack(L2Npc npc, L2PcInstance attacker, int damage, boolean isSummon)
  84. {
  85. final L2MonsterInstance mob = (L2MonsterInstance) npc;
  86. if ((mob.getId() == STAKATO_LEADER) && (getRandom(1000) < 100) && (mob.getCurrentHp() < (mob.getMaxHp() * 0.3)))
  87. {
  88. final L2MonsterInstance _follower = checkMinion(npc);
  89. if (_follower != null)
  90. {
  91. double _hp = _follower.getCurrentHp();
  92. if (_hp > (_follower.getMaxHp() * 0.3))
  93. {
  94. mob.abortAttack();
  95. mob.abortCast();
  96. mob.setHeading(Util.calculateHeadingFrom(mob, _follower));
  97. mob.doCast(SkillData.getInstance().getSkill(4484, 1));
  98. mob.setCurrentHp(mob.getCurrentHp() + _hp);
  99. _follower.doDie(_follower);
  100. _follower.deleteMe();
  101. }
  102. }
  103. }
  104. return super.onAttack(npc, attacker, damage, isSummon);
  105. }
  106. @Override
  107. public String onKill(L2Npc npc, L2PcInstance killer, boolean isSummon)
  108. {
  109. final L2MonsterInstance monster;
  110. switch (npc.getId())
  111. {
  112. case STAKATO_NURSE:
  113. monster = checkMinion(npc);
  114. if (monster != null)
  115. {
  116. Broadcast.toSelfAndKnownPlayers(npc, new MagicSkillUse(npc, 2046, 1, 1000, 0));
  117. for (int i = 0; i < 3; i++)
  118. {
  119. L2Npc spawned = addSpawn(STAKATO_CAPTAIN, monster, true);
  120. addAttackPlayerDesire(spawned, killer);
  121. }
  122. }
  123. break;
  124. case STAKATO_BABY:
  125. monster = ((L2MonsterInstance) npc).getLeader();
  126. if ((monster != null) && !monster.isDead())
  127. {
  128. startQuestTimer("nurse_change", 5000, monster, killer);
  129. }
  130. break;
  131. case STAKATO_MALE:
  132. monster = checkMinion(npc);
  133. if (monster != null)
  134. {
  135. Broadcast.toSelfAndKnownPlayers(npc, new MagicSkillUse(npc, 2046, 1, 1000, 0));
  136. for (int i = 0; i < 3; i++)
  137. {
  138. L2Npc spawned = addSpawn(STAKATO_GUARD, monster, true);
  139. addAttackPlayerDesire(spawned, killer);
  140. }
  141. }
  142. break;
  143. case STAKATO_FEMALE:
  144. monster = ((L2MonsterInstance) npc).getLeader();
  145. if ((monster != null) && !monster.isDead())
  146. {
  147. startQuestTimer("male_change", 5000, monster, killer);
  148. }
  149. break;
  150. case STAKATO_CHIEF:
  151. if (killer.isInParty())
  152. {
  153. List<L2PcInstance> party = killer.getParty().getMembers();
  154. for (L2PcInstance member : party)
  155. {
  156. giveCocoon(member, npc);
  157. }
  158. }
  159. else
  160. {
  161. giveCocoon(killer, npc);
  162. }
  163. break;
  164. }
  165. return super.onKill(npc, killer, isSummon);
  166. }
  167. @Override
  168. public String onSkillSee(L2Npc npc, L2PcInstance caster, Skill skill, L2Object[] targets, boolean isSummon)
  169. {
  170. if (Util.contains(COCOONS, npc.getId()) && Util.contains(targets, npc) && (skill.getId() == GROWTH_ACCELERATOR))
  171. {
  172. npc.doDie(caster);
  173. final L2Npc spawned = addSpawn(STAKATO_CHIEF, npc.getX(), npc.getY(), npc.getZ(), Util.calculateHeadingFrom(npc, caster), false, 0, true);
  174. addAttackPlayerDesire(spawned, caster);
  175. }
  176. return super.onSkillSee(npc, caster, skill, targets, isSummon);
  177. }
  178. @Override
  179. public final String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  180. {
  181. if ((npc == null) || (player == null) || npc.isDead())
  182. {
  183. return null;
  184. }
  185. int npcId = 0;
  186. switch (event)
  187. {
  188. case "nurse_change":
  189. npcId = STAKATO_NURSE_2;
  190. break;
  191. case "male_change":
  192. npcId = STAKATO_MALE_2;
  193. break;
  194. }
  195. if (npcId > 0)
  196. {
  197. npc.getSpawn().decreaseCount(npc);
  198. npc.deleteMe();
  199. final L2Npc spawned = addSpawn(npcId, npc.getX(), npc.getY(), npc.getZ(), npc.getHeading(), false, 0, true);
  200. addAttackPlayerDesire(spawned, player);
  201. }
  202. return super.onAdvEvent(event, npc, player);
  203. }
  204. private static L2MonsterInstance checkMinion(L2Npc npc)
  205. {
  206. final L2MonsterInstance mob = (L2MonsterInstance) npc;
  207. if (mob.hasMinions())
  208. {
  209. final List<L2MonsterInstance> minion = mob.getMinionList().getSpawnedMinions();
  210. if ((minion != null) && !minion.isEmpty() && (minion.get(0) != null) && !minion.get(0).isDead())
  211. {
  212. return minion.get(0);
  213. }
  214. }
  215. return null;
  216. }
  217. private static void giveCocoon(L2PcInstance player, L2Npc npc)
  218. {
  219. player.addItem("StakatoCocoon", ((getRandom(100) > 80) ? LARGE_COCOON : SMALL_COCOON), 1, npc, true);
  220. }
  221. public static void main(String[] args)
  222. {
  223. new StakatoNest();
  224. }
  225. }